You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on May 26, 2023. It is now read-only.
Comptroller.withdrawRewards: totalFrozen subtracted two times from totalStaked
Summary
In Comptroller.withdrawRewards, userManagerState.totalFrozen is subtracted two times from totalStaked, leading to a wrong inflation index or even a broken system because the calculation underflows.
Vulnerability Detail
_getUserManagerState calculates the totalStaked like this:
When userManagerState.totalFrozen() is sufficiently large, this can lead to an underflow, meaning that withdrawRewards (and therefore UserManager.stake, UserManager.unstake, and UserManager.withdrawRewards) can never be executed, which bricks the system. But even if it does not underflow, the following update of gInflationIndex will use a wrong value.
Lambda
medium
Comptroller.withdrawRewards: totalFrozen subtracted two times from totalStaked
Summary
In
Comptroller.withdrawRewards
,userManagerState.totalFrozen
is subtracted two times fromtotalStaked
, leading to a wrong inflation index or even a broken system because the calculation underflows.Vulnerability Detail
_getUserManagerState
calculates thetotalStaked
like this:totalStaked
is therefore already set tototalStaked - totalFrozen
. However, inwithdrawRewards
, the following calculation is performed:totalFrozen
is therefore subtracted fromtotalStaked
again, meaning we have:Impact
When
userManagerState.totalFrozen()
is sufficiently large, this can lead to an underflow, meaning thatwithdrawRewards
(and thereforeUserManager.stake
,UserManager.unstake
, andUserManager.withdrawRewards
) can never be executed, which bricks the system. But even if it does not underflow, the following update ofgInflationIndex
will use a wrong value.Code Snippet
https://github.com/sherlock-audit/2022-10-union-finance/blob/main/union-v2-contracts/contracts/token/Comptroller.sol#L260
Tool used
Manual Review
Recommendation
Do not subtract
totalFrozen
a second time.duplicate of #26
The text was updated successfully, but these errors were encountered: