15,000 USDC
View results
Submission Details
Severity: medium

In `_calculateHealthFactor()`, division before multiplication can cause precision loss

Summary

In _calculateHealthFactor(), division before multiplication is done. To avoid precision loss, division in solidity should always be done at the end.

Vulnerability Details

The current code looks like this:

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

This effectively results in return of the value (((collateralValueInUsd * LIQUIDATION_THRESHOLD) / LIQUIDATION_PRECISION) * 1e18) / totalDscMinted.

The multiplication with 1e18 should be done first.

Impact

Loss of precision and incorrect health factor calculation.

Tools Used

Manual review

Recommendations

Perform the calculation in one step and return ((collateralValueInUsd * LIQUIDATION_THRESHOLD) * 1e18) / totalDscMinted / LIQUIDATION_PRECISION;.

Support

FAQs

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