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.
Incorrect inflation index due to incorrect calculation of totalStaked
Summary
The gInflationIndex in Comptroller.sol variable could be incorrect due to totalFrozen being subtracted from the totalStaked twice in the withdrawRewards function.
Vulnerability Detail
In the withdrawRewards function of Comptroller.sol, the _getUserManagerState function is called which will return totalStaked and totalFrozen values. The totalStaked returned by _getUserManagerState is calculated by subtracting the userManager.totalFrozen from the userManager.totalStaked and the totalFrozen returned is the userManager.totalFrozen. The withdrawRewards function will then calculate a new totalStaked value by subtracting userManagerState.totalFrozen from the userManagerState.totalStaked and use this new value in the _getInflationIndexNew function to get a new value for gInflationIndex.
Impact
The gInflationIndex variable could be updated incorrectly which could lead to incorrect reward calculations.
In the withdrawRewards function, the totalStaked used to claculate the new inflationIndex is calculated as the userManagerState's totalStaked - totalFrozen again.
Tool used
Manual Review
Recommendation
In the withdrawRewards function, do not subtract totalFrozen from the totalStaked again.
dipp
high
Incorrect inflation index due to incorrect calculation of
totalStaked
Summary
The
gInflationIndex
inComptroller.sol
variable could be incorrect due tototalFrozen
being subtracted from thetotalStaked
twice in thewithdrawRewards
function.Vulnerability Detail
In the
withdrawRewards
function ofComptroller.sol
, the_getUserManagerState
function is called which will return totalStaked and totalFrozen values. The totalStaked returned by _getUserManagerState is calculated by subtracting the userManager.totalFrozen from the userManager.totalStaked and the totalFrozen returned is the userManager.totalFrozen. ThewithdrawRewards
function will then calculate a new totalStaked value by subtracting userManagerState.totalFrozen from the userManagerState.totalStaked and use this new value in the_getInflationIndexNew
function to get a new value forgInflationIndex
.Impact
The
gInflationIndex
variable could be updated incorrectly which could lead to incorrect reward calculations.Code Snippet
Comptroller.sol:_getUserManagerState#L306-L316:
The
getUserManagerState
function gets the userManager's totalFrozen and calculates the totalStaked as the userManager's totalStaked - its totalFrozen.Comptroller.sol:withdrawRewards#L260-L264:
In the
withdrawRewards
function, the totalStaked used to claculate the new inflationIndex is calculated as the userManagerState's totalStaked - totalFrozen again.Tool used
Manual Review
Recommendation
In the
withdrawRewards
function, do not subtract totalFrozen from the totalStaked again.Duplicate of #26
The text was updated successfully, but these errors were encountered: