The contracts' source code and deployment scripts show that the FjordPoints contract will likely be deployed before FjordStaking. If these deployment transactions are mined in separate blocks, the value of FjordPoints' lastDistribution maybe less than FjordStaking's startTime. This discrepancy creates a time window where an attacker could quickly stake and unstake FJO tokens to steal points.
Consider the following:
FjordPoints was deployed at 00:00:00, and FjordStaking was deployed at 00:00:15.
A user stakes FJO tokens on the 7th day of the first epoch at 23:00:45.
At the time of staking, both the staking and points contracts are in epoch 1.
The user unstakes 15 seconds later, at 00:00:00.
At the time of unstaking, the staking contract is still in epoch 1 (hence unstaking is possible), but the points contract has already transitioned to epoch 2, and points were distributed taking the user's stake into account.
The user then calls FjordPoints.claimPoints() and successfully walks away with both FJO tokens and the points they effectively stole.
This scenario illustrates how the difference in deployment times can be exploited to steal rewards.
Manual review, Foundry tests
To address this issue, consider the following options:
Synchronize Epoch Start Times:
Deploy both contracts within a single transaction, or
Implement a setter function to manually set the epoch start time.
Introduce a Cooldown Period:
Prevent immediate unstaking by introducing a cooldown period that exceeds the timestamp difference between the contract deployments.
Implement Gradual Reward Distribution:
Distribute rewards gradually, based on the proportion of time that tokens were staked.
Impact: High - Users are getting an unreasonable amount of points through exploiting a vulnerability Likelihood: Low - Most of the times, when using the script, all deployment tx will get processed in the same block. But, there is a small chance for them to be processed in different blocks.
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.