StakingRewards: Significant loss of precision possible
The reward rate per second is calculated with rounding down, which over a long duration can cause a large portion of intended rewards to remain undistributed. An attacker could exploit this to cause stakers to lose a significant amount of rewards.
Submitted by Lambda
In notifyRewardAmount, the reward rate per second is calculated. This calculation rounds down, which can lead to situations where significantly less rewards are paid out to stakers, because the effect of the rounding is multiplied by the duration.
Proof Of Concept
Let’s say we have a rewardsDuration of 4 years, i.e. 126144000 seconds. We assume the rewardRate is currently ß and notifyRewardAmount is called with the reward amount 252287999. Because the calculation rounds down, rewardRate will be 1. After the 4 years, the user have received 126144000 reward tokens. However, 126143999 (i.e., almost 50%) of the reward tokens that were intended to be distributed to the stakers were not distributed, resulting in monetary loss for all stakers.
Recommended Mitigation Steps
You could accumulate the differences that occur due to rounding and let the users claim them in the end according to their shares.
MiguelBits (Y2K Finance) acknowledged
While it’s an edge case, the numbers used in the POC are reasonable if we consider small token decimals (eg. EURS with 2 decimals).
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 rate per second is computed with integer division that rounds down, and the remainder is not accounted for, so the error accumulates over the reward duration.
Impact
Stakers could lose a significant portion of their intended rewards, up to almost 50% in the given example, resulting in monetary loss.
What the attacker needed
Long rewards duration; small reward amount relative to duration
The fix
The differences from rounding should be accumulated and users should be able to claim them according to their shares.
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.
When a staking contract distributes rewards, it calculates how many tokens to give out per second. If that number is rounded down, the small error gets multiplied over a long time, so a large amount of rewards never gets paid. This means stakers receive less than they should.