Skip to content
Business logic Audit finding Intermediate

User can steal all rewards due to checkpoint after transfer

The StakerVault contract updates user reward checkpoints after transferring balances, allowing a user to repeatedly transfer tokens between accounts and claim maximum rewards each time. An attacker could drain all reward tokens from the contract.

0xDjango Follow

Originally disclosed on Code4rena

Submitted by 0xDjango, also found by unforgiven

StakerVault.sol#L112-L119

I believe this to be a high severity vulnerability that is potentially included in the currently deployed StakerVault.sol contract also. The team will be contacted immediately following the submission of this report.

In StakerVault.sol, the user checkpoints occur AFTER the balances are updated in the transfer() function. The user checkpoints update the amount of rewards claimable by the user. Since their rewards will be updated after transfer, a user can send funds between their own accounts and repeatedly claim maximum rewards since the pool’s inception.

In every actionable function except transfer() of StakerVault.sol, a call to ILpGauge(lpGauge).userCheckpoint() is correctly made BEFORE the action effects.

Proof of Concept

Assume a certain period of time has passed since the pool’s inception. For easy accounting, assume poolStakedIntegral of LpGauge.sol equals 1. The poolStakedIntegral is used to keep track of the current reward rate.

Steps:

  • Account A stakes 1000 LP tokens. balances[A] += 1000
  • In the same stakeFor() function, userCheckpoint() was already called so A will already have perUserShare[A] set correctly based on their previously 0 balance and the current poolStakedIntegral.
  • Account A can immediately send all balance to Account B via transfer().
  • Since the checkpoint occurs after the transfer, B’s balance will increase and then perUserShare[B] will be updated. The calculation for perUserShare looks as follows.
perUserShare[user] += (
            (stakerVault.stakedAndActionLockedBalanceOf(user)).scaledMul(
                (poolStakedIntegral_ - perUserStakedIntegral[user])
            )
        );

Assuming Account B is new to the protocol, their perUserStakedIntegral[user] will default to 0.

perUserShare[B] += 1000 * (1 - 0) = 1000

  • B is able to call claimRewards() and mint all 1000 reward tokens.
  • B then calls transfer() and sends all 1000 staked tokens to Account C.
  • Same calculation occurs, and C can claim all 1000 reward tokens.
  • This process can be repeated until the contract is drained of reward tokens.

Recommended Mitigation Steps

In StakerVault.transfer(), move the call to ILpGauge(lpGauge).userCheckpoint() to before the balances are updated.

chase-manning (Backd) confirmed and resolved


The original report as published on Code4rena, by 0xDjango. 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

The transfer function updates balances before calling the reward checkpoint, so the checkpoint uses the new balance instead of the old one.

Impact

An attacker could drain all reward tokens from the contract.

What the attacker needed

A staking account with LP tokens; ability to create multiple accounts

The fix

The transfer function should call the reward checkpoint before updating balances.

How it was found

  1. Account A stakes 1000 LP tokens, which triggers a checkpoint for A.
  2. Account A transfers all 1000 tokens to Account B.
  3. Because the checkpoint happens after the transfer, Account B's reward share is calculated using the new balance and a default per-user integral of zero.
  4. Account B claims all 1000 reward tokens.
  5. Account B transfers the 1000 tokens to Account C, and the same calculation lets C claim all 1000 reward tokens.
  6. The process is repeated until the contract runs out of reward tokens.

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.

In a staking contract, users earn rewards based on how long they hold tokens. The contract is supposed to record a user's reward balance before their token balance changes. Here, it records the reward balance after a transfer, so a user can move tokens to a fresh account and claim rewards again as if they had held those tokens since the beginning. By repeating this, they can take all the rewards that belong to everyone.

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 0xDjango

View all

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