Loss of reward tokens when totalStaked
remains 0
#76
Labels
2 (Med Risk)
Assets not at direct risk, but function/availability of the protocol could be impacted or leak value
bug
Something isn't working
duplicate-369
🤖_06_group
AI based duplicate group recommendation
unsatisfactory
does not satisfy C4 submission criteria; not eligible for awards
Lines of code
https://github.com/code-423n4/2024-02-uniswap-foundation/blob/5298812a129f942555466ebaa6ea9a2af4be0ccc/src/UniStaker.sol#L230
Vulnerability details
Impact
The UniStaker contract uses an accumulator to represent the overall reward accrued to all stakers. This accumulator value is stored in
rewardPerTokenAccumulatedCheckpoint
state variable.This is how this variable gets updated:
It can be seen that when
totalStaked
is0
thenrewardPerTokenAccumulatedCheckpoint
value is not updated, i.e, rewards don't accrue. For the entire duration whentotalStaked
remains0
therewardPerTokenAccumulatedCheckpoint
isn't updated.Hence the to-be-distributed reward token amount (
scaledRewardRate
*duration
) for that duration gets locked inside the UniStaker contract forever. This amount can neither be claimed by any future stakers nor can it be recovered by the protocol owners. Hence resulting in permanent loss of reward funds.Consider this scenario in which:
In worst case if noone stakes in UniStaker for entire 30 day duration then all the reward tokens gets stuck in the contract.
A more likely scenario would be if the reward yield of UniStaker is low and no user wants to stake for those low rewards. These rewards should ideally be utilized in future to further boost the reward yield when users get interested in staking again.
Proof of Concept
Tools Used
Foundry
Recommended Mitigation Steps
Consider allocating the unaccrued yield in a separate state variable and utilize it to boost rewards when
totalStaked
becomes non-zero.Assessed type
Context
The text was updated successfully, but these errors were encountered: