Core Contracts

Regnum Aurum Acquisition Corp
HardhatReal World AssetsNFT
77,280 USDC
View results
Submission Details
Severity: medium
Invalid

Precision Loss in Health Factor Calculation

Summary

The calculateHealthFactor() function’s integer division truncates small collateral values to a health factor of 0, risking false liquidations. This medium-impact, medium-likelihood issue assumes collateralValue is in WAD (1e18); if in RAY (1e27), it may not apply, but precision loss still threatens fairness.

Vulnerability Details

The function scales collateralThreshold (WAD) by 1e18 and divides by userDebt (RAY, 1e27), losing precision. Example:

NFT value 1000e18 (WAD), liquidationThreshold = 80_00, debt 1e27 (RAY).
collateralThreshold = 800e18, (800e18 * 1e18) / 1e27 = 0.
Health factor 0 triggers liquidation despite sufficient collateral (1000e18 > 800e18).
User loses 1000 crvUSD unfairly.

Impact

Users face unjust liquidations (e.g., 1000 crvUSD lost), a medium-impact issue. The medium likelihood occurs with small collateral or large debt, a common edge case that could unfairly penalize borrowers.

Tools Used

Static Analysis Tools: Slither to detect precision loss in division.
Manual Code Review: To analyze scaling in calculateHealthFactor().
Testing Frameworks: Foundry to test edge cases with small values.

Recommendations

Adjust to RAY precision (assuming WAD input):

function calculateHealthFactor(address userAddress) public view returns (uint256) {
uint256 collateralValue = getUserCollateralValue(userAddress);
uint256 userDebt = getUserDebt(userAddress);
if (userDebt < 1) return type(uint256).max;
uint256 collateralThreshold = collateralValue.percentMul(liquidationThreshold);
return (collateralThreshold * 1e27) / (userDebt * 1e9); // RAY precision
}
Updates

Lead Judging Commences

inallhonesty Lead Judge 3 months ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

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