Ineffective loop in FjordStaking::_checkEpochRollover
because the same pendingRewardsPerToken
is used for every iteration.
FjordStaking::_checkEpochRollover
has a loop that isn't effective for more than 1 iterations. Since pendingRewardsPerToken
is used for every iteration to be added in rewardPerToken[lastEpochRewarded]
to produce rewardPerToken[i]
.
This becomes ineffective because the pendingRewards will run out after 1 epoch because it has been streamed to user's unclaimed reward. Meanwhile other staker who has staked after that 1 epoch will not receive any reward due to this miscalculation.
Example Scenario :
State:
pendingRewards = 50e18
totalStaked = 200e18
totalRewards = 1000e18
lastEpochRewarded = 3
currentEpoch = 6
rewardPerToken[3] = 10e18
Scenario:
pendingRewardsPerToken = 0.25e18 (50e18 * 1e18 / 200e18)
totalRewards = 1050e18 (1000e18 + 50e18)
i = 4 (3 + 1)
rewardPerToken[4] = 10.25e18 (10e18 rewardPerToken[3]) + 0.25e18(pendingRewardsPerToken)
rewardPerToken[5] = 10.25e18 (10e18 rewardPerToken[3]) + 0.25e18(pendingRewardsPerToken)
As we can see, rewardPerToken[4] and rewardPerToken[5] has the same rewardPerToken or there is no value added at all. So the user who staked at 4 epoch will get no reward at all because rewardPerToken for 5th epoch is the same for 4th epoch with no value added.
User will not get the reward of what they staked at certain condition and this breaks the whole stake mechanism of the protocol.
Manual Review
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.