Closed sherlock-admin closed 9 months ago
1 comment(s) were left on this issue during the judging contest.
takarez commented:
invalid because { no specific damage mentioned by watson like precision lost or anything}
Invalid, for different collateral decimals, their prices also have different decimals. For example: eth decimal is 18 so that the price is based on 1e6, btc decimal is 18 so that the price is based on 1e16 to insurance colMintAmount is based on 1e6 .
uint256 colMintAmount = _getMintAmount(reserve, user.depositBalance[collateral], reserve.initialMortgageRate); maxMintAmount += colMintAmount;
dany.armstrong90
high
There is no consideration about difference of decimals of JUSD and collaterals in JUSDBank.
Summary
JUSDBank
uses several collaterals. But there is no consideration about the case that decimals of collaterals are different each other and the case that the decimals of collaterals and JUSD are different. In such cases, there could be large error in the calculation.Vulnerability Detail
JUSDBank records the amount of collaterals without converting decimals. For example,
JUSDBank.sol#_deposit
function is the following.As can be seen,
L256
records the amount of collateral transferred inL254
todepositBalance
without converting decimal. JUSDBank also records the amount of borrowed JUSD without converting decimal. For example,JUSDBank.sol#_borrow
function is the following.As can be seen
L276
records the amount of JUSD transferred inL282
totoBorrowBalance
without converting decimal, where decimal oftRate
inL275
is 18.JUSDView.sol#_isAccountSafe
function estimates the safety of account using the amount of JUSDtoBorrowBalance
and the amount of collateraldepositBalance
which are recorded as above.In
L84
,amount
isuser.depositBalance[collateral]
ofL105
and the decimals ofgetAssetPrice()
andrate
are 18. Thus, the decimals ofdepositAmount
inL84
,colAmount
inL05
andmaxMintAmount
inL106
are equal to the decimal of collateral.But the decimals of collaterals are different each other. For instance, from the test code, we can see that the decimal of BTC is 8, decimal of eth is 18 and deciaml of JUSD is 6, where BTC and eth are used as collaterals. Thus, it turns out to be that
L106
adds collaterals of different decimals andL92
compares values of different decimals.Impact
This issue causes serious damage to the JUSDBank.
Code Snippet
https://github.com/sherlock-audit/2023-12-jojo-exchange-update/blob/main/smart-contract-EVM/src/JUSDBank.sol#L256 https://github.com/sherlock-audit/2023-12-jojo-exchange-update/blob/main/smart-contract-EVM/src/JUSDView.sol#L106
Tool used
Manual Review
Recommendation
The decimals of collaterals and JUSD should be converted to 18 when recording the amount of them.