Submitted by rscodes
First, lets reference how the rewards are calculated when a 2nd incentive is introduced while another incentive is still within its rewardsDuration period.
In MultiFeeDistribution.sols _notifyReward function:
This will cause rewards from the initial incentive to be delayed and spread out across the 2nd incentives period and initial stakers will have wrong amount of claimable rewards during the timestamps all the way until the 2nd incentives rewardsDuration ends. Other than delays, the original staker could also possibly permanently lose some of their deserved reward tokens, as described further below in 2nd way of exploit section.
The symbol diagram below demonstrates the scenario ran in the foundry test:
Console Output:
Explanation:
Lets examine Alices balance at the end of 30 days: 12500 ether = 5000 ether + 2500 ether + 5000 ether = A + B/2 + C/2.
However, the rightful amount of rewards her balance should be at day 30 is: A + B + C/2 = 15000 ether. The remaining 15000 ether - 12500 ether = 2500 ether that Alice is entitled to claim at day 30, will only be given throughout days 30 to 45.
This is very unfair to Alice who has staked her tokens since the beginning of the first incentive, and now she has to wait longer for the rewards from the first incentive which is a high opportunity cost incurred for her.
This is made worse if the incentive given at the 2nd wave is significantly smaller than the original amount in wave 1, because it means she will have to wait longer for her significant rewards from the 1st wave; all because of the 2nd wave of small and insignificant incentive.
Referencing the same scenario in the Proof of Code section. A malicious staker can choose to stake anytime between day 30 to day 45 and because of that, Alice can permanently lose some of her rewards.
Example:
Overall Disclaimer: The example above of the 2nd incentive being introduced at exactly halfway (15 days) of the 1st incentives duration was just used as an example. This bug still exists as long as the 2nd incentive is introduced at any point of time throughout the 1st incentives duration, causing the respective portion to be spread across the wrong period.
We can use a queue-like list to store rewards and their respective periodFinish, as well as a counter that we can increment when rewards[rewardCounter].periodFinish < block.timestamp.
rewards[i].rewardsPerSecond is meant to be distributed between the timeframe of rewards[i-1].periodFinish to rewards[i].periodFinish only.
Foundry, VSCode
Math
amarcu (LoopFi) confirmed
0xAlix2 (warden) commented:
Koolex (judge) decreased severity to Medium and commented:
