DeFiFoundry
60,000 USDC
View results
Submission Details
Severity: low
Invalid

`getPrice` can return `0` value, leads to div by zero error

GitHub https://github.com/Cyfrin/2024-07-zaros/blob/d687fe96bb7ace8652778797052a38763fbcbb1b/src/external/chainlink/ChainlinkUtil.sol#L26-L72

Summary

In ChainlinkUtil, when the getPrice function is called to query the provided Chainlink Price Feed for the margin collateral oracle price, there is no explicit check for the price being equal to zero. Consequently, getPrice can return 0.

The problem arises when deductAccountMargin is called. This function calls marginCollateralConfiguration.getPrice() to obtain the collateral's USD price, which is saved in ctx.marginCollateralPriceUsdX18. This value is then passed to withdrawMarginUsd. Within withdrawMarginUsd, a division occurs: UD60x18 requiredMarginInCollateralX18 = amountUsdX18.div(ctx.marginCollateralPriceUsdX18);. This can lead to a division by zero error.

Impact

A division by zero error will occur, which, in newer versions of Solidity, will cause the transaction to revert. This can lead to a temporary DoS for the liquidateAccounts and fillMarketOrder functions.

Recommendation

Do note that if (answer <= minAnswer || answer >= maxAnswer) { check doesn't stop the price from returning 0 because minAnswer is int192 datatype and can save negative values, so for fixing this issue add a check in getPrice to handle the case where answer is equal to zero. This early return with a proper error will prevent the division by zero case.

In ChainlinkUtil:

if (answer == 0) {
revert Errors.InvalidOracleReturn();
}
Updates

Lead Judging Commences

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

Appeal created

0xtheblackpanther Submitter
10 months ago
inallhonesty Lead Judge
10 months ago
inallhonesty Lead Judge 9 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.