Protocol operation and collateral value calculation assume that the tokens have 18 decimals, this can cause issue when the collateral is token that have lower or higher decimals.
When calculating health factor, protocol call getAccountInformation
, protocol eventually loop over collaterals and used getUsdValue
for every collateral to get the usd value :
https://github.com/Cyfrin/2023-07-foundry-defi-stablecoin/blob/main/src/DSCEngine.sol#L349-L359
https://github.com/Cyfrin/2023-07-foundry-defi-stablecoin/blob/main/src/DSCEngine.sol#L361-L367
However, the PRECISION
used is 10e18
, this can cause issue if the collateral used is not 18 decimals token.
getTokenAmountFromUsd
also calculate the token amount that will be seized in liquidation and use the same assumption:
https://github.com/Cyfrin/2023-07-foundry-defi-stablecoin/blob/main/src/DSCEngine.sol#L339-L348
This will cause protocol completely broken when working with non 18 decimals token.
Manual review
Consider to add mechanism to scale the getTokenAmountFromUsd
and getUsdValue
based on collateral token decimals.
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.