Skip to content
Business logic Audit finding Advanced

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.

scaraven Follow

Originally disclosed on Code4rena

Submitted by scaraven

https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/tokenomics/LpGauge.sol#L115-L119

https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/StakerVault.sol#L326-L328

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

  1. LP Gauge and StakerVault contracts are deployed
  2. Before the initializeLpGauge(), user A will stake 1 token with stakeFor() thereby increasing _poolTotalStaked by 1. As the lpgauge address is equal to the zero address, _userCheckPoint() will not be called and poolLastUpdate will remain at 0.
  3. The user can then directly call _userCheckPoint() and be allocated a very large number of shares. This works because poolLastUpdate is 0 but the staked amount in the vault is larger than 0
  4. Once initializeLPGauge() is called, the user can then call claimRewards() and receive a very large portion of tokens or if poolStakedIntegral exceeds the mint limit set by Minter.sol then no one else can claim governance tokens from the lpGauge.

OR

  1. 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

danhper (Backd) confirmed

Alex the Entreprenerd (judge) decreased severity to Medium and commented:

The warden has identified a way to exploit the uninitialized value for the variable poolLastUpdate

Because this is contingent on setup, and the impact is theft of rewards, I believe Medium Severity to be more appropriate.

scaraven (warden) commented:

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() as initializeLpGauge() will revert. This introduces a significant delay (3 days if I’m correct) before the LPGauge can actually be initialised with executeLPGauge(). Therefore a user can easily monitor this contract and call poolCheckpoint() as soon as soon as prepareLPGauge() 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

_setConfig bypasses the need for a MIN_DELAY

Meaning 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, _poolCheckpoint can 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

scaraven (warden) commented:

Cool, thanks for taking the time to explain


The original report as published on Code4rena, by scaraven. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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

  1. Deploy the LP Gauge and StakerVault contracts.
  2. 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.
  3. Call the user checkpoint directly so the user is allocated a very large number of shares.
  4. 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.

More by scaraven

View all

6 more disclosed reports, best first.

More from Backd Tokenomics contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.