Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetInflationAmount can run out of gas #477

Closed
code423n4 opened this issue Jan 2, 2023 · 4 comments
Closed

GetInflationAmount can run out of gas #477

code423n4 opened this issue Jan 2, 2023 · 4 comments
Labels
bug Something isn't working downgraded by judge Judge downgraded the risk level of this issue duplicate-710 edited-by-warden QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax

Comments

@code423n4
Copy link
Contributor

code423n4 commented Jan 2, 2023

Lines of code

https://github.com/code-423n4/2022-12-gogopool/blob/main/contracts/contract/RewardsPool.sol#L74

Vulnerability details

Impact

The loop within getInflationAmount can run out of gas, irreversibly breaking the contract

Proof of Concept

Currently, the function startRewardsCycle calls inflate which then calls getInflationAmount in order to receive the inflated supply. However, during the function getInflationAmount it loops over all inflationIntervalsElapsed, which is in most cases 28 days, when called regularly. However, if startRewardsCycle is not called regularly, this means that inflationIntervalStartTime is not updated regularly: addUint(keccak256("RewardsPool.InflationIntervalStartTime"), inflationIntervalElapsedSeconds); this will then eventually lead to to a DoS where the loop runs out of gas for (uint256 i = 0; i < inflationIntervalsElapsed; i++) { due to too many elapsed inflation intervals.

Tools Used

VSCode

Recommended Mitigation Steps

Currently, there is no easy solution. One could implement pagination for the loop to prevent this issue, however, this would need a larger logic change. Therefore our recommendation is to a) keep an eye on the duration time and b) eventually use chainlink automation to call startRewardsCycle every 28 days.

Eventually, one could also set an upper limit of inflationIntervalsElapsed and if this limit is exceeded, simply exceed e.g. 50 loops.

https://docs.chain.link/chainlink-automation/introduction

*This is the first contest i took part, therefore my submissions might not be ideal yet, if there are any questions feel free to contact me directly in discord :-)

** While this issue initially was assessed as HIGH, we think that MEDIUM is here more appropriate because we do not see this happening in production (it would take quite some weeks of forgetting to call the function), however, the code itself is still vulnerable for this issue and in our opinion this is what counts.

@code423n4 code423n4 added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working labels Jan 2, 2023
code423n4 added a commit that referenced this issue Jan 2, 2023
C4-Staff added a commit that referenced this issue Jan 6, 2023
@c4-judge
Copy link
Contributor

c4-judge commented Jan 8, 2023

GalloDaSballo marked the issue as duplicate of #139

@c4-judge
Copy link
Contributor

GalloDaSballo marked the issue as not a duplicate

@c4-judge c4-judge added QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax downgraded by judge Judge downgraded the risk level of this issue duplicate-710 and removed 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value labels Jan 29, 2023
@c4-judge
Copy link
Contributor

Duplicate of #710

@GalloDaSballo
Copy link

L

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working downgraded by judge Judge downgraded the risk level of this issue duplicate-710 edited-by-warden QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax
Projects
None yet
Development

No branches or pull requests

3 participants