The RAAC protocol has a staking feature through the gauges it provides. With every call, the rewards for a user who has staked are updated through the updateReward modifier.
The way a gauge accrues rewards is by keeping track of all the rewardPerToken accrued. If the current rewardPerToken is 10e18, whenever a new staker joins, 10e18 should be assigned to their state.rewardPerTokenPaid.
This ensures that gauges accurately track how many rewards have been accrued for each individual user.
However, a problem arises when a user makes their very first stake.
For a new user, rewards are calculated first without taking into account the current rewardPerToken. This will make them immediatily eligible for rewards. Also if a user stakes four years after the contract is deployed, they will accrue all the rewards emitted during this entire timespan.
Inflated user rewards – Users who stake late can unfairly claim rewards they did not earn.
Loss for the protocol – This results in unintended reward distribution, effectively draining funds.
Manual review
Add an if statement to check whether this is the user's first stake (state.rewardPerTokenPaid == 0).
If it is, calculate earned using the new rewardPerTokenStored.
If it is not, proceed with the current implementation.
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.