If rewards are distributed before users start staking, a portion of the reward will become permanently stuck #131
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/5a2761c8277541a24bc551fbd624413b384bea94/src/UniStaker.sol#L754-L755
Vulnerability details
The
UniStaker._checkpointGlobalReward
function is used to update therewardPerTokenAccumulatedCheckpoint
and thelastCheckpointTime
storage variables.The issue arises from the fact that the
rewardPerTokenAccumulated
function returns an old value iftotalStaked == 0
so therewardPerTokenAccumulatedCheckpoint
will not be updated in this case. However, thelastTimeRewardDistributed
function returnsblock.timestamp
if rewards are streaming at the moment so thelastCheckpointTime
value might be updated. It means that if the contract is notified about the reward before the first user stakes, a portion of the reward becomes permanently stuck.Impact
The portion of the reward will be permanently stuck if the contract is notified about the reward before the first user stakes.
Proof of Concept
The test below illustrates that the rewards streamed before the first user stakes are not distributed to anyone and become inaccessible.
Tools Used
Manual Review
Recommended Mitigation Steps
Perhaps, the fairest solution is to pause rewards streaming while
totalStaked == 0
. However, this solution requires additional logic and might be prone to new errors. The easiest way to prevent unnecessary funds loss is to ensure that the first staker will stake UNI tokens right after the contract deploying.Assessed type
Other
The text was updated successfully, but these errors were encountered: