getUsdValue returns incorrect value for collateral with different decimals than 18.
getUsdValue returns usd value for collateral in 18 decimals:
Firstly, this function gets collateral price from Chainlink, the price is in 8 decimals;
Then the price is multiplied by ADDITIONAL_FEED_PRECISION (1e10), to make price in 18 decimals;
Price is multiplied by amount (in wei), we then get the collateral value in (collateral decimals + 18) decimals;
Lastly, the collateral value is divided by PRECISION (1e18) to make the collateral value in 18 decimals.
This works for collateral with 18 decimals, for example, assuming weth price is 2000e8, amount is 2e18, we can get collateral value is 4000e18 (2000e8 * 1e10 * 2e18 / 1e18).
However, it does not works for collateral with different decimals, in the case of wbtc, its decimals is 8, assume wbtc price is 20000e8, amount is 2e8, we can get collateral value is 0.000004e18 (20000e8 * 1e10 * 2e8 / 1e18), and this is apparently wrong.
Incorrect collateral value can lead to incorrect health factor, then incorrect amount of DCS tokens can be minted, protocol will become insolvent.
Mannual Review
In the calculation, because the collateral value we get in step 3 is in (collateral decimals + 18) decimals, so it should be divided by collateral decimals intead of 1e18. For example, wbtc's collateral value in the example above should be calculated as: 20000e8 * 1e10 * 2e8 / 1e8 = 40000e18.
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.