We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Low Risk
2023-07-foundry-defi-stablecoin/src/DSCEngine.sol
Lines 330 to 331 in d1c5501
Precision loss
To avoid loss in precision, perform multiplication before division.
function _calculateHealthFactor(uint256 totalDscMinted, uint256 collateralValueInUsd) internal pure returns (uint256) { if (totalDscMinted == 0) return type(uint256).max; uint256 collateralAdjustedForThreshold = (collateralValueInUsd * LIQUIDATION_THRESHOLD) / 100; return (collateralAdjustedForThreshold * 1e18) / totalDscMinted; }
Division before multiplication can lead to truncation and give an incorrect output.
Manual review
function _calculateHealthFactor(uint256 totalDscMinted, uint256 collateralValueInUsd) internal pure returns (uint256) { if (totalDscMinted == 0) return type(uint256).max; // Multiply first to prevent truncation, then divide return (collateralValueInUsd * LIQUIDATION_THRESHOLD * 1e18) / (totalDscMinted * 100); }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Precision loss
Severity
Low Risk
Relevant GitHub Links
2023-07-foundry-defi-stablecoin/src/DSCEngine.sol
Lines 330 to 331 in d1c5501
Summary
Precision loss
Vulnerability Details
To avoid loss in precision, perform multiplication before division.
Impact
2023-07-foundry-defi-stablecoin/src/DSCEngine.sol
Lines 330 to 331 in d1c5501
Division before multiplication can lead to truncation and give an incorrect output.
Tools Used
Manual review
Recommendations
The text was updated successfully, but these errors were encountered: