Incorrect internal accounting led to insolvency
Early claimants earn more rewards, while late claimants may receive none due to insufficient contract funds
_checkEpochRollover calculates the new epoch rewards before updating totalStaked, causing that value to be overinflated. Early users can claim more rewards, leaving some users unable to claim any as the contract will be emptied.
_checkEpochRollover is called during an epoch to calculate the new rewards for each epoch. The pendingRewardsPerToken value is multiplied by the user's balance to calculate their rewards for that epoch. pendingRewardsPerToken calculation boils down to pendingRewards / totalStaked.
Later, _checkEpochRollover updates totalStaked:
The vulnerability here is that totalStaked is used to calculate user rewards, but it's updated after the rewards are calculated. This means that an epoch's rewards are calculated without accounting for the new stakes from the last epoch. Essentially, if users stake in epoch X, epoch X+1 rewards are calculated based on the totalStake in X-1 (not counting withdrawals). However, that user would receive rewards for X+1 since they staked before the epoch began.
Example:
| prerequisites | values |
|---|---|
| Rewards per epoch | 1000e18 |
totalStake |
100e18 |
| Current epoch | 2 |
User1 was the only staker for epoch 2, so they claim all of the rewards.
User2 stakes 100e18 tokens mid-epoch, so they would be able to earn rewards from epoch 3 and onward.
Epoch 3 starts, and _checkEpochRollover is triggered, calculating the new pendingRewardsPerToken to be:
totalStaked gets increased to 200.
Epoch 3 starts with no new rewards added.
Currently, both users have stakes of 100 tokens and are able to claim 1000 reward tokens each, but there are only 1000 tokens inside the contract.
totalStaked is increased after the rewards are calculated.
Manual review.
Compute the new totalStaked before calculating rewards.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.