Users can claim extremely large rewards or lock rewards from LpGauge due to uninitialised poolLastUpdate variable
The LpGauge contract's poolLastUpdate variable was never initialised, so it defaulted to zero. A user who staked before the gauge was initialised could be credited with an enormous share of rewards, letting them claim most available governance tokens or block everyone else from claiming.
Submitted by scaraven
Impact
A user can claim all of the available governance tokens or prevent any rewards from being claimed in LpGauge.sol if sufficient time is left between deploying the contract and initialising it in the StakerVault.sol contract by calling initalizeLPGauge() OR if a new LPGauge contract is deployed and added to StakerVault using prepareLPGauge.
Inside LPGauge.sol when calling _poolCheckPoint(), the lastUpdated variable is not initalised so defaults to a value of 0, therefore if the user has managed to stake tokens in the StakerVault then the calculated poolStakedIntegral will be very large (as block.timestamp is very large). Therefore a user can mint most current available governance tokens for themselves when they claim their rewards (or prevent any governance tokens from being claimed).
Proof of Concept
- LP Gauge and StakerVault contracts are deployed
- Before the
initializeLpGauge(), user A will stake 1 token withstakeFor()thereby increasing_poolTotalStakedby 1. As thelpgaugeaddress is equal to the zero address,_userCheckPoint()will not be called andpoolLastUpdatewill remain at 0. - The user can then directly call
_userCheckPoint()and be allocated a very large number of shares. This works becausepoolLastUpdateis 0 but the staked amount in the vault is larger than 0 - Once
initializeLPGauge()is called, the user can then callclaimRewards()and receive a very large portion of tokens or ifpoolStakedIntegralexceeds the mint limit set byMinter.solthen no one else can claim governance tokens from the lpGauge.
OR
- A new LP Gauge contract is deployed and added to the vault using
prepareGauge(). Follow steps 2 to 4.
Recommended Mitigation Steps
Initialise poolLastUpdate in the constructor
Alex the Entreprenerd (judge) decreased severity to Medium and commented:
The warden has identified a way to exploit the uninitialized value for the variable
poolLastUpdateBecause this is contingent on setup, and the impact is theft of rewards, I believe Medium Severity to be more appropriate.
Hi, correct me if I am wrong but there is a second scenario where this situation can be exploited as outlined in my report. If governance deploy a new LPGauge they must do it through
prepareLPGauge()asinitializeLpGauge()will revert. This introduces a significant delay (3 days if I’m correct) before the LPGauge can actually be initialised withexecuteLPGauge(). Therefore a user can easily monitor this contract and callpoolCheckpoint()as soon as soon asprepareLPGauge()is called and the contract has no way to prevent this.
Alex the Entreprenerd (judge) commented:
@scaraven
I don’t see any enforced delay in
initializeLpGauge
_setConfigbypasses the need for aMIN_DELAYMeaning the exploit is not practical for the first gauge
For Gauge that needs to be substituted, that will indeed require a 3 day wait period,
_poolCheckpointcan only be effective after the first deposit has happened as well, see: https://github.com/code-423n4/2022-05-backd-findings/issues/100 Which effects how initial rewards are calculated.Due to the math being off it may be necessary to influence
uint256 currentRate = inflationManager.getLpRateForStakerVault(address(stakerVault));This, the need for a second gauge, and the race condition between the first depositor and other depositors are external conditions, leading me to believe that Medium Severity is appropriate
Cool, thanks for taking the time to explain
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the poolLastUpdate state variable was never set in the constructor, so the first checkpoint computed an integral over the whole history of the chain instead of since deployment.
Impact
A user could take most of the available governance tokens, or if the integral exceeds the mint limit, no one could claim rewards from that gauge; the judge noted the first-gauge path is impractical and that a substituted gauge needs a three-day wait plus a first deposit, so severity was reduced to Medium.
What the attacker needed
Stake before gauge initialisation; gauge deployed but not yet initialised; or a replacement gauge in its wait period
How it was found
- Deploy the LP Gauge and StakerVault contracts.
- Before the gauge is initialised, stake a small amount through stakeFor so the pool total is above zero while the gauge address is still the zero address.
- Call the user checkpoint directly so the user is allocated a very large number of shares.
- After the gauge is initialised, call claimRewards to receive a very large portion of the tokens, or push the integral past the mint limit so nobody can claim.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A smart contract keeps a running total of rewards owed to stakers. To do that it records the last time it updated, but here that starting time was left blank, which the system reads as zero, i.e. the very beginning of time. Anyone who staked before the gauge was properly set up was therefore treated as having staked for an enormous period and got a huge share of the rewards.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.