BaseRewardPool’s rewardPerTokenStored can be inflated and rewards can be stolen
The first user to stake a tiny amount (1 wei) can inflate the rewardPerTokenStored value because the reward calculation divides by totalSupply, which is then only 1 wei. This allows that user to withdraw inflated rewards and drain the reward pool.
Originally disclosed on Code4rena
Submitted by sorrynotsorry
Impact
The first user who calls BaseRewardPool’s stake() function with 1 wei can inflate the rewardPerTokenStored. And the same user can call withdraw and drain the rewards.
Proof of Concept
When a user call stake() with 1 wei, it updates the _totalSupply as 1 wei and the rewards through updateReward modifier. This modifier calls rewardPerToken() to assign the return to rewardPerTokenStored and assigns it to the account via userRewardPerTokenPaid[account] = rewardPerTokenStored; rewardPerToken() formula is as below;
function rewardPerToken() public view returns (uint256) {
if (totalSupply() == 0) {
return rewardPerTokenStored;
}
return
rewardPerTokenStored.add(
lastTimeRewardApplicable().sub(lastUpdateTime).mul(rewardRate).mul(1e18).div(
totalSupply()
)
);
}
Since it depends on the denominator as totalSupply(), the whole multiplying will be divided by 1 wei which will inflate the rewardPerTokenStored astronomically. And there is no obstacle for the user to withdraw it in the withdraw function.
Recommended Mitigation Steps
The team might consider to add boundries to reward the stakers to be consistent inside the limits.
solvetony (veToken Finance) acknowledged, but disagreed with severity and commented:
This is the rare case when only one staker in the pool.
Alex the Entreprenerd (judge) decreased severity to Medium and commented:
This report would have heavily benefited by a coded POC.
I’m pasting my raw data from terminal (typos and stuff included)
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 reward calculation divides by totalSupply without a minimum stake or check, so when totalSupply is 1 wei the reward per token becomes extremely large.
Impact
The first staker could inflate rewards and drain the reward pool, but the team noted this only happens when there is a single staker in the pool.
What the attacker needed
Be the first staker; stake only 1 wei
The fix
The team should add boundaries to reward stakers to keep rewards within consistent limits.
How it was found
- Call stake() with 1 wei as the first staker.
- The updateReward modifier calls rewardPerToken(), which divides by totalSupply (1 wei), inflating rewardPerTokenStored.
- Call withdraw() to drain the inflated rewards.
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, rewards are shared among all stakers based on how much they have staked. If someone is the first to stake a very tiny amount, the maths that calculates rewards per token can produce a huge number because it divides by that tiny amount. That person can then take out more rewards than they should, stealing from the reward pool.
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.