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

RewardsPool.inflate sets wrong value to RewardsPool.InflationIntervalStartTime variable #239

Closed
code423n4 opened this issue Dec 29, 2022 · 6 comments
Labels
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 downgraded by judge Judge downgraded the risk level of this issue duplicate-648 partial-50 Incomplete articulation of vulnerability; eligible for partial credit only (50%) sponsor disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue

Comments

@code423n4
Copy link
Contributor

Lines of code

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

Vulnerability details

Impact

RewardsPool.inflate sets wrong value to RewardsPool.InflationIntervalStartTime variable. As result inflation logic will be broken and GGP token will inflate much faster than it was expected.

Proof of Concept

GGP token has limited total supply that is minted on deploy.
But at the beginning not all tokens are available. Token amount should inflate during the time to distribute its total supply.

To increase amount of tokens in circulation RewardsPool.startRewardsCycle function is called.
This function then calls inflate function.

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

	function inflate() internal {
		ProtocolDAO dao = ProtocolDAO(getContractAddress("ProtocolDAO"));
		uint256 inflationIntervalElapsedSeconds = (block.timestamp - getInflationIntervalStartTime());
		(uint256 currentTotalSupply, uint256 newTotalSupply) = getInflationAmt();


		TokenGGP ggp = TokenGGP(getContractAddress("TokenGGP"));
		if (newTotalSupply > ggp.totalSupply()) {
			revert MaximumTokensReached();
		}


		uint256 newTokens = newTotalSupply - currentTotalSupply;


		emit GGPInflated(newTokens);


		dao.setTotalGGPCirculatingSupply(newTotalSupply);


		addUint(keccak256("RewardsPool.InflationIntervalStartTime"), inflationIntervalElapsedSeconds);
		setUint(keccak256("RewardsPool.RewardsCycleTotalAmt"), newTokens);
	}

This function calculates how many periods has passed since last inflate and then increases token's total supply.
It uses getInflationIntervalStartTime function to know when inflation was done last time. getInflationIntervalStartTime function just checks InflationIntervalStartTime variable.

Later inflate function is updating InflationIntervalStartTime variable to provide time when last inflation was done.
addUint(keccak256("RewardsPool.InflationIntervalStartTime"), inflationIntervalElapsedSeconds);
The problem is that inflationIntervalElapsedSeconds is set instead of block.timestamp.
inflationIntervalElapsedSeconds is a time in seconds between the last inflation was done. It's not a timestamp.
As a result when inflate will be called next time, then getInflationAmt function will calculate new tokens incorrectly and will distribute all total supply more faster.

Example.
1.RewardsPool is deployed at time 1000. Then InflationIntervalStartTime == 1000.
2.Inflation interval is 10.
3.inflate is called for first time at time 1010. As result price has increased once. InflationIntervalStartTime == inflationIntervalElapsedSeconds == 10.
4.inflate is called next time at time 1020. inflationIntervalElapsedSeconds = 1020 - 10 = 1010. And price has changed 101 times instead of 1 as getInflationAmt function decided that 101 period has passed since last inflation.

Tools Used

VsCode

Recommended Mitigation Steps

Set block.timestamp to inflationIntervalElapsedSeconds variable.

@code423n4 code423n4 added 3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working labels Dec 29, 2022
code423n4 added a commit that referenced this issue Dec 29, 2022
C4-Staff added a commit that referenced this issue Jan 6, 2023
@GalloDaSballo
Copy link

Should be dup of #648 but something is off, will double check and keep separate for now

@0xju1ie
Copy link

0xju1ie commented Jan 13, 2023

I think the warden is confused. The InflationIntervalStartTime is added to, not set.

According to the code their example should be the following:
Example.
1.RewardsPool is deployed at time 1000. Then InflationIntervalStartTime == 1000.
2.Inflation interval is 10.
3.inflate is called for first time at time 1010. As result price has increased once. inflationIntervalElapsedSeconds == 10, InflationIntervalStartTime == 1010 .
4.inflate is called next time at time 1020. inflationIntervalElapsedSeconds = 1020 - 1010 = 10.

@0xju1ie 0xju1ie added the sponsor disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue label Jan 13, 2023
@GalloDaSballo
Copy link

I believe that despite the grammar mistake, the warden has found a dup of #648

Because they didn't show the end conclusion, am awarding half

@c4-judge
Copy link
Contributor

GalloDaSballo marked the issue as duplicate of #648

@c4-judge c4-judge added duplicate-648 partial-50 Incomplete articulation of vulnerability; eligible for partial credit only (50%) labels Jan 29, 2023
@c4-judge
Copy link
Contributor

GalloDaSballo marked the issue as partial-50

@c4-judge
Copy link
Contributor

GalloDaSballo changed the severity to 2 (Med Risk)

@c4-judge c4-judge added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value downgraded by judge Judge downgraded the risk level of this issue and removed 3 (High Risk) Assets can be stolen/lost/compromised directly labels Jan 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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 downgraded by judge Judge downgraded the risk level of this issue duplicate-648 partial-50 Incomplete articulation of vulnerability; eligible for partial credit only (50%) sponsor disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue
Projects
None yet
Development

No branches or pull requests

4 participants