When a user stakes tokens, they should typically not be allowed to claim points for that same epoch. This ensures that users earn points based on a full epoch of staking rather than potentially manipulating the system to stake and immediately claim rewards without fully participating in the staking period. The more epochs that have passed without stakers, the first staker would get all the points from them. The user can stake, claim, and unstake and they will still get the points from all the unstaked epochs.
If an epoch passes without any stakers, the system still accumulates points for that epoch. The first user to stake in the current epoch will claim points from the previous epoch, even though they did not stake during that period
https://github.com/Cyfrin/2024-08-fjord/blob/main/src/FjordPoints.sol#L229C4-L249C1
The if (totalStaked == 0) {````return;````} checks that if there are no stakes do not calculate, but if another epoch comes and there is a staker, that check will pass and calculate Points, when a second user comes to stake they will be blocked by the if (block.timestamp < lastDistribution + EPOCH_DURATION) { return; } since the first staker updates the lastDistribution that means the previous points will be calculated for the first staker.
Copy the Poc and paste it inside the test/unit/points.t.sol
Output:
In Fjord users should not be able to earn points for staking and claiming points within the same epoch.
The first user to stake in an epoch where there were no previous stakers can claim all the points from the previous epochs. This means that if a user stakes immediately after an epoch begins, they can unfairly claim all the rewards from all the last unstaked epochs, even though they had no stake during that period.
Knowledgeable users could exploit this vulnerability by monitoring the staking contract and deliberately staking immediately then unstake after an epoch with no stakers to maximize their rewards unfairly.
I don't know if the users are allowed to claim the last epochs Points but they should at least be shared if that's the case.
Manual review
Modify the reward distribution logic to exclude epochs with a zero total staked amount from being considered in point calculations. Points should only be calculated and distributed for epochs where there was an active stake.
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.