Reward distributed when totalStaked==0 is lost #112
Labels
3 (High Risk)
Assets can be stolen/lost/compromised directly
bug
Something isn't working
duplicate-369
edited-by-warden
🤖_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/main/src/UniStaker.sol#L230
https://github.com/code-423n4/2024-02-uniswap-foundation/blob/main/src/UniStaker.sol#L577-L582
Vulnerability details
Impact
When the
totalStaked
is reduced to 0 before the reward distribution period ends, the remaining reward may become locked indefinitely within the balance of theUniStaker
contract.In another scenario, if users are inactive and do not stake in
UniStaker
while the reward distributions continue regularly, any rewards distributed during that period where users did not stake will remain locked and unrecoverable.When
totalStaked == 0
, therewardPerTokenAccumulatedCheckpoint
value does not get updated.In the case of new rewards come after
REWARD_DURATION
period, the remaining reward (from period wheretotalStaked == 0
) has no effect on thescaledRewardRate
value.Moreover, in described scenarios where
totalStaked
is 0,UniStaker
lacks the mechanism to retrieve or rescue these locked rewards. Consequently, any such rewards will remain inaccessible indefinitely.Proof of Concept
Poc 1
Consider the following scenario:
1000 UNI
.10 WETH
comes.1000 UNI
, resulting intotalStaked
becoming 0.UniStaker
contract still holds3 WETH
from the reward distribution.1000 UNI
and a new reward of10 WETH
comes. After another 30 days (REWARD_DURATION
), Alice claims the reward of10 WETH
.3 WETH
from the previous distribution remains stuck in the contract, unable to be claimed or rescued.Poc 2
Consider the following scenario:
UniStaker
, the reward distribution occurs regularly with10 WETH
initially and another10 WETH
after 7 days.REWARD_DURATION
), withdraws herUNI
, and proceeds to claim the reward. However, to her dismay, she receives0 WETH
as a reward.UniStaker
.To launch the PoCs place the
PoC
contract presented below into thetest/UniStaker.t.sol
file and issue the following commands.Tools Used
Manual review.
Recommended Mitigation Steps
Possible mitigation is to add
rescue()
function toUniStaker
.Additionally, to check
totalStaked > 0
insidenotifyRewardAmount()
.Assessed type
Other
The text was updated successfully, but these errors were encountered: