15,000 USDC
View results
Submission Details
Severity: medium

Precision loss may occur when calculating health factor

Summary

collateralAdjustedForThreshold calculation can lose precision when collateralValueInUsd * LIQUIDATION_THRESHOLD is not exactly divisible by LIQUIDATION_PRECISION. The resulting value would roundoff to the lowest value and would lead to precision loss since decimals are not handled in Solidity.

Vulnerability Details

uint256 collateralAdjustedForThreshold = (collateralValueInUsd * LIQUIDATION_THRESHOLD) / LIQUIDATION_PRECISION;
return (collateralAdjustedForThreshold * 1e18) / totalDscMinted;

For example, for collateralValueInUsd = 267, collateralAdjustedForThreshold = 133 when the actual value should be 133.5.

Impact

Calculated health factor will be lower than the real value.

Tools Used

Manual review

Recommendations

We multiply 1e18 with collateralAdjustedForThreshold. Instead, first multiply and calculate the entire numerator before dividing:

+return (collateralValueInUsd * LIQUIDATION_THRESHOLD * 1e18) / (totalDscMinted * LIQUIDATION_PRECISION);
-uint256 collateralAdjustedForThreshold = (collateralValueInUsd * LIQUIDATION_THRESHOLD) / LIQUIDATION_PRECISION;
-return (collateralAdjustedForThreshold * 1e18) / totalDscMinted;

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.