StakingRewards reward rate can be dragged out and diluted
The StakingRewards contract's notifyRewardAmount function recalculates the reward rate by spreading the remaining rewards plus any new deposit over a fresh rewardsDuration period. A malicious actor could call notifyRewardAmount with zero rewards to repeatedly dilute the reward rate and drag out rewards for all stakers.
Submitted by cccz
Similar to https://github.com/code-423n4/2022-02-concur-findings/issues/183.
if (block.timestamp >= periodFinish) {
rewardRate = reward.div(rewardsDuration);
} else {
uint256 remaining = periodFinish.sub(block.timestamp);
uint256 leftover = remaining.mul(rewardRate);
rewardRate = reward.add(leftover).div(rewardsDuration);
}
The StakingRewards.notifyRewardAmount function receives a reward amount and extends the current reward end time to now + rewardsDuration. It rebases the currently remaining rewards + the new rewards (reward + leftover) over this new rewardsDuration period. This can lead to a dilution of the reward rate and rewards being dragged out forever by malicious new reward deposits.
Proof of Concept
Imagine the current rewardRate is 1000 rewards / rewardsDuration.
20% of the rewardsDuration passed, i.e., now = lastUpdateTime + 20% * rewardsDuration.
A malicious actor notifies the contract with a reward of 0: notifyRewardAmount(0).
Then the new rewardRate = (reward + leftover) / rewardsDuration = (0 + 800) / rewardsDuration = 800 / rewardsDuration.
The rewardRate just dropped by 20%. This can be repeated infinitely. After another 20% of reward time passed, they trigger notifyRewardAmount(0) to reduce it by another 20% again: rewardRate = (0 + 640) / rewardsDuration = 640 / rewardsDuration.
Recommended Mitigation Steps
The rewardRate should never decrease by a notifyRewardAmount call. Consider not extending the reward payouts by rewardsDuration on every call. periodFinish probably shouldn’t change at all, the rewardRate should just increase by rewardRate += reward / (periodFinish - block.timestamp).
Alternatively, consider keeping the rewardRate constant but extend periodFinish time by += reward / rewardRate.
MiguelBits (Y2K Finance) disputed
Admin privilege issue that would allow the admin to dilute current rewards. Medium severity due to loss of yield for all depositors from dilution of
rewardRate.
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 notifyRewardAmount function always resets the reward period and recalculates rewardRate from remaining plus new rewards, so even a zero-reward call reduces the rate.
Impact
All depositors could lose yield because the reward rate is diluted and rewards are dragged out; the judge rated this medium severity, and the project disputed it as an admin privilege issue.
What the attacker needed
Ability to call notifyRewardAmount; rewards period already running
The fix
The rewardRate should never decrease from a notifyRewardAmount call; either keep periodFinish unchanged and increase rewardRate, or keep rewardRate constant and extend periodFinish.
How it was found
- Wait until 20% of the rewardsDuration has passed since the last update.
- Call notifyRewardAmount with a reward amount of zero.
- Observe the rewardRate drop by 20%.
- Repeat after another 20% of the reward period to reduce the rate again.
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 staking contract pays out rewards at a certain speed. Each time someone adds new rewards, the contract recalculates that speed by spreading all remaining rewards over a full new period. If someone adds zero new rewards, the speed still gets recalculated and drops, so everyone earns more slowly. Repeating this makes rewards last much longer than intended.
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.