You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Unnecessary precision loss in _calculateHealthFactor
Severity
Low Risk
Relevant GitHub Links
2023-07-foundry-defi-stablecoin/src/DSCEngine.sol
Lines 330 to 331 in d1c5501
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.
The text was updated successfully, but these errors were encountered: