The FjordStaking contract uses two variables to track staked amounts: totalStaked and newStaked. The inconsistent updating of these variables can lead to potential discrepancies in the total staked amount, affecting reward calculations and overall contract integrity.
if (latestEpoch > currentEpoch) {
//Time to rollover
currentEpoch = latestEpoch;
Let's consider a scenario to illustrate the potential inconsistency:
Current state:
totalStaked = 1000
newStaked = 0
currentEpoch = 10
User A stakes 100 tokens:
newStaked becomes 100
totalStaked remains 1000
User B unstakes 50 tokens from the current epoch:
newStaked becomes 50 (100 - 50)
totalStaked remains 1000
User C unstakes 200 tokens from a previous epoch:
totalStaked becomes 800 (1000 - 200)
newStaked remains 50
Epoch rolls over:
totalStaked becomes 850 (800 + 50)
newStaked resets to 0
The issue here is that the contract treats staking and unstaking differently based on the epoch, and it updates different variables (totalStaked or newStaked) depending on the situation. The actual total staked amount at any given time is split between totalStaked and newStaked, making it harder to get an accurate total.
If rewards are calculated based on totalStaked before an epoch rollover, they won't account for the newStaked amount.
errors in tracking of staked amounts, leading to more unreliable reward calculations.
Use only totalStaked and update it consistently in all functions. Remove newStaked entirely.
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.