Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unnecessary precision loss in _calculateHealthFactor #505

Open
codehawks-bot opened this issue Aug 5, 2023 · 0 comments
Open

Unnecessary precision loss in _calculateHealthFactor #505

codehawks-bot opened this issue Aug 5, 2023 · 0 comments

Comments

@codehawks-bot
Copy link

Unnecessary precision loss in _calculateHealthFactor

Severity

Low Risk

Relevant GitHub Links

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

Summary

Due to division before multiplication precision loss may cause _calculateHealthFactor to return slightly inaccurate results.

Vulnerability Details

_calculateHealthFactor breaks up the health factor calculation into 2 lines both of which involve a division. Each one can result in a small amount of token losses. This can be reduced by refactoring both lines into 1 and completing the division last.

Impact

Due to collateralValueInUsd having 18 decimals the actual value of tokens lost will be minimal. However as the calculation does not need division to be done twice I believe the code should be refactored to reduce these losses.

Tools Used

Manual Review

Recommendation

Combine the last 2 lines into 1 and complete the division last to minimise precision loss.

return ((collateralValueInUsd * LIQUIDATION_THRESHOLD * 1e18) / (totalDscMinted * LIQUIDATION_PRECISION);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants