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

DOS function inflate() if inflationIntervalsElapsed is too large #652

Closed
code423n4 opened this issue Jan 3, 2023 · 9 comments
Closed

DOS function inflate() if inflationIntervalsElapsed is too large #652

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

Comments

@code423n4
Copy link
Contributor

Lines of code

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

Vulnerability details

Impact

Whenever working with for loop on EVM, gas consumption should be taken care. If the loop is unbounded, it can consume gas even more than block gas limit and effectively DOS the functionality.

It is noticed that RewardsPool.getInflationAmt() calculate newTotalSupply by looping through inflationIntervalsElapsed. If it is too long since last update, inflationIntervalsElapsed can become too large and cause out of gas. Also, function getInflationAmt() is used in inflate() so inflate() will be DOS too.

Proof of Concept

Function getInflationAmt() used a unbounded loop

function getInflationAmt() public view returns (uint256 currentTotalSupply, uint256 newTotalSupply) {
    ProtocolDAO dao = ProtocolDAO(getContractAddress("ProtocolDAO"));
    uint256 inflationRate = dao.getInflationIntervalRate();
    uint256 inflationIntervalsElapsed = getInflationIntervalsElapsed();
    currentTotalSupply = dao.getTotalGGPCirculatingSupply();
    newTotalSupply = currentTotalSupply;

    // Compute inflation for total inflation intervals elapsed
    for (uint256 i = 0; i < inflationIntervalsElapsed; i++) { 
        // @audit out of gas if too long not update
        newTotalSupply = newTotalSupply.mulWadDown(inflationRate);
    }
    return (currentTotalSupply, newTotalSupply);
}

Tools Used

Manual Review

Recommended Mitigation Steps

Consider adding a constant max value for inflationIntervalsElapsed so it cannot get too large and cause DOS.

@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 3, 2023
code423n4 added a commit that referenced this issue Jan 3, 2023
C4-Staff added a commit that referenced this issue Jan 6, 2023
@GalloDaSballo
Copy link

Best because code snippet, but could have been improved via gas math or a test

@c4-judge c4-judge added the primary issue Highest quality submission among a set of duplicates label Jan 8, 2023
@c4-judge
Copy link
Contributor

c4-judge commented Jan 8, 2023

GalloDaSballo marked the issue as primary issue

@emersoncloud
Copy link

duplicate of #132

@c4-judge
Copy link
Contributor

GalloDaSballo marked the issue as partial-25

@c4-judge c4-judge added the partial-25 Incomplete articulation of vulnerability; eligible for partial credit only (25%) label Jan 17, 2023
@0xju1ie
Copy link

0xju1ie commented Jan 18, 2023

dupe of #139

@0xju1ie 0xju1ie added sponsor duplicate Sponsor deemed duplicate and removed sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") labels Jan 18, 2023
@c4-judge
Copy link
Contributor

GalloDaSballo marked the issue as duplicate of #139

@c4-judge c4-judge added duplicate-139 and removed primary issue Highest quality submission among a set of duplicates labels Jan 26, 2023
@c4-judge c4-judge reopened this Jan 29, 2023
@c4-judge c4-judge removed partial-25 Incomplete articulation of vulnerability; eligible for partial credit only (25%) duplicate-139 labels Jan 29, 2023
@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-653 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 #653

@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-653 QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax sponsor duplicate Sponsor deemed duplicate
Projects
None yet
Development

No branches or pull requests

5 participants