Part 2

Zaros
PerpetualsDEXFoundrySolidity
70,000 USDC
View results
Submission Details
Severity: high
Invalid

Missing Zero-Check for Vault Asset Value Leading to Division by Zero Vulnerability in `UsdTokenSwapConfig::getPremiumDiscountFactor`

Summary

The function UsdTokenSwapConfig::getPremiumDiscountFactor calculates the premium or discount factor based on a vault's debt-to-assets ratio, but it lacks an essential check to ensure that the vaultAssetsValueUsdX18 is not zero before performing a division operation. The absence of this validation can lead to a division-by-zero error, causing the contract to revert or behave unexpectedly.

Vulnerability Details

The function attempts to divide vaultDebtUsdX18 by vaultAssetsValueUsdX18 in the line:

UD60x18 vaultDebtTvlRatioAbs = vaultDebtUsdX18.abs().intoUD60x18().div(vaultAssetsValueUsdX18);

If vaultAssetsValueUsdX18 is zero, a division by zero will occur, leading to an exception or faulty calculations. This vulnerability could be exploited in cases where the vaultAssetsValueUsdX18 is improperly set to zero.

Impact

If vaultAssetsValueUsdX18 is zero, it can result in a runtime error (division by zero), potentially halting the contract's execution. This could lead to unhandled exceptions, denial of service, or incorrect calculations for vaults, potentially resulting in financial losses or system instability.

Tools Used

Manual code review

Recommendations

Add a validation check at the beginning of the function to ensure vaultAssetsValueUsdX18 is greater than zero before performing any division operations.

if (vaultAssetsValueUsdX18.isZero()) {
revert Errors.InvalidVaultAssetsValue();
}

This would prevent the division by zero error and ensure that the calculations are only performed with valid inputs.

Updates

Lead Judging Commences

inallhonesty Lead Judge 4 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

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