Any UniStaker fees accruing when no one is staking would be lost #333
Labels
3 (High Risk)
Assets can be stolen/lost/compromised directly
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#L755
Vulnerability details
Description
When fees are added to the UniStaker,
notifyRewardAmount()
is called.It sets
scaledRewardRate
so that the total pending fees would be split uniformally over the next 30 days.rewardEndTime
is set tonow + 30 days
, whilelastCheckpointTime = now
Suppose there's no stakers when the first rewards are sent to the UniStaker, for example since yield is zero right now. Some time passes and the first staker joins. All interactions with beneficiaries including
stake()
run the following line to update global rewards:Which is:
The first line updates the total unlocked reward/token:
In case
totalStaked
is zero, it returns the original checkpoint without accounting for the new rewards.The second line updates
lastCheckpointTime
:Note that it would update regardless if
totalStaked==0
. Therefore, it would store the current timestamp inlastCheckpointTime
.At this point, the tokens weren't distributed, but
lastCheckpointTime
is updated. So in the future, the accumulation of tokens inrewardPerTokenAccumulated()
will never include the days when there weren't any stakers.This results in loss of fees which are permanently stuck in the contract, whenver there are no stakers. That could be at any part of the contract's lifetime.
Impact
Permanent freeze of yield which currently belongs to the Uniswap governance.
Proof of Concept
claimFees()
to get fees and give rewards, before the first stake deposits into UniStaker.Tools Used
Manual audit
Recommended Mitigation Steps
Consider not advancing
lastCheckpointTime
in casetotalStaked == 0
in_checkpointGlobalReward()
.Assessed type
Math
The text was updated successfully, but these errors were encountered: