The _checkEpochRollover
function in the FjordStaking
contract incorrectly distributes rewards across multiple epochs. This results in the same reward per token being assigned to all epochs between lastEpochRewarded + 1
and currentEpoch - 1
in a case where we have more than one epoch pending. This issue can lead to unfair reward allocation among stakers.
The vulnerability is located in the _checkEpochRollover
function of the FjordStaking
contract:
The loop in the _checkEpochRollover
function that updates the rewardPerToken
for each epoch between lastEpochRewarded + 1
and currentEpoch - 1
uses the same value for pendingRewardsPerToken
. This value is calculated once and added to rewardPerToken[lastEpochRewarded]
for each iteration. As a result, all epochs in the range receive the same reward per token, which does not accurately reflect the rewards that should be distributed for each epoch individually.
Consider the following scenario:
lastEpochRewarded
is 5.
currentEpoch
is 10.
pendingRewardsPerToken
is calculated as 100.
The loop will set rewardPerToken
for epochs 6, 7, 8, and 9 to the same value:
This results in rewardPerToken[6]
, rewardPerToken[7]
, rewardPerToken[8]
, and rewardPerToken[9]
all being set to rewardPerToken[5] + 100
.
The incorrect reward distribution can lead to several issues:
Unfair Reward Allocation: Stakers who participated in different epochs may receive the same rewards, regardless of the actual staking activity and rewards generated in each epoch. This can result in unfair reward allocation among stakers.
Undermined Staking Mechanism: The integrity of the staking mechanism is compromised, as the rewards do not accurately reflect the staking activity in each epoch.
Potential Disputes: Users may dispute the reward distribution, leading to a loss of trust in the staking contract and the overall ecosystem.
Manual Code Review
To ensure that rewards are distributed correctly across multiple epochs, the logic in the _checkEpochRollover
function should be adjusted to account for the rewards that should be distributed for each epoch individually.
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.