In StabilityBranch
there is a function getAmountOfAssetOut
used to calculate the amount of assets to be received in a swap based on the input USD amount, its current price and the premium or discount to be applied. However, the calculation is wrong.
In StabilityBranch
there is a function getAmountOfAssetOut
used to calculate the amount of assets to be received in a swap based on the input USD amount, its current price and the premium or discount to be applied. However, the calculation is wrong.
Let's take a look at that line:
As we know indexToken
can have any decimals value that is less than or equal to 18. Let's say that our indexToken
is with 6 decimals. We expect that the vaultAssetsUsdX18
will be a value in base 18.
IERC4626(vault.indexToken).totalAssets()
will return a value in 6 decimals (for example 1e6)
indexPriceX18
will be a value in 18 decimals (for example 1e18)
vaultAssetsUsdX18
will be equal to 1e6 x 1e18 / 1e18 = 1e6 -> the value is not in 18 decimals.
The whole calculation below that line becomes wrong.
Wrongly calculated amount of asset out leading to confusion and wrong fetched values.
Manual Review
Convert the IERC4626(vault.indexToken).totalAssets()
first to an 18 decimal value before performing the calculation to ensure that all indexToken
s with decimals less than or equal to 18 will work correctly.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.