Open hats-bug-reporter[bot] opened 1 year ago
The totalAssets()
is used in convertToShares
& convertToAssets
of osToken. if we include treasuryAssets
to the totalAssets
the convertTo...
functions will return different value before and after the updateState
call.
Github username: @milotruck Submission hash (on-chain): 0x786d7a93c9d40afe7674d19aff3460c615ed5e222bb9b87ae4989a3eaf492c81 Severity: low
Description:
Bug Description
In
OsToken.sol
, thetotalAssets()
function calculates the current total amount of assets as follows:OsToken.sol#L84-L90
As seen from above, the
treasuryAssets
is subtracted from_totalAssets + profitAccrued
to calculate the total amount of assets.However, this contradicts the
updateState()
function, which does not subtracttreasuryAssets
from_totalAssets
:OsToken.sol#L261-L262
OsToken.sol#L299
Therefore, as long as
treasuryAssets
is non-zero, the value returned bytotalAssets()
will actually be smaller than the total asset amount afterupdateState()
is called, making it incorrect.Attack Scenario
Assume that a vault has the following state:
_totalAssets = 10 ether
profitAccrued = 1 ether
feePercent = 500
, which is 5%.When
totalAssets()
is called, it will return:treasuryAssets = 1 ether * 500 / 10_000 = 5e16
_totalAssets + profitAccrued - treasuryAssets = 10 ether + 1 ether - 5e16 = 11e18 - 5e16
When
updateState()
is called,_totalAssets
is updated to:_totalAssets + profitAccrued = 11 ether
profitAccrued
is also reset to 0 afterupdateState()
is called.Now, since
profitAccrued = 0
,totalAssets()
will return a different value:treasuryAssets = 0 * 500 / 10_000 = 0
_totalAssets + profitAccrued - treasuryAssets = 11 ether + 0 - 0 = 11e18
As
totalAssets()
incorrectly excludestreasuryAssets
, its return value was5e16
smaller beforeupdateState()
is called.Impact
As
totalAssets()
incorrectly excludestreasuryAssets
, it cannot be used to accurately determine the total amount of assets forOsToken
.This could potentially have more severe impacts if other contracts rely on
totalAssets()
for calculations, as its return value can change in a single transaction by callingupdateState()
.Recommended Mitigation
Consider including
treasuryAssets
in the value returned bytotalAssets()
, which is consistent with the logic in theupdateState()
function:OsToken.sol#L84-L90