Skip to content

fix: prevent division by zero in quoteCollateral#1111

Open
Kubudak90 wants to merge 1 commit into
compound-finance:mainfrom
Kubudak90:fix/1104-quoteCollateral-div-by-zero
Open

fix: prevent division by zero in quoteCollateral#1111
Kubudak90 wants to merge 1 commit into
compound-finance:mainfrom
Kubudak90:fix/1104-quoteCollateral-div-by-zero

Conversation

@Kubudak90

Copy link
Copy Markdown

Summary

Fixes #1104

This PR adds two defensive checks to prevent division by zero in the quoteCollateral function:

Changes

  1. Tighten storeFrontPriceFactor validation in constructor (all three Comet variants):

    • Changed > FACTOR_SCALE to >= FACTOR_SCALE
    • When storeFrontPriceFactor == FACTOR_SCALE, the discountFactor can reach FACTOR_SCALE, causing assetPriceDiscounted to become zero
  2. Add zero-price guard in quoteCollateral (all three Comet variants):

    • Added if (assetPriceDiscounted == 0) revert BadPrice(); before the discounted price is used as a divisor
    • Prevents division by zero panic when calculating collateral asset quantities

Affected contracts

  • contracts/Comet.sol
  • contracts/CometWithExtendedAssetList.sol
  • contracts/ScrollComet.sol

- Change storeFrontPriceFactor check from > to >= FACTOR_SCALE to prevent
discountFactor from reaching FACTOR_SCALE, which would make assetPriceDiscounted
zero and cause division by zero downstream.

- Add explicit zero-check on assetPriceDiscounted before it's used as a divisor
in collateral asset quantity calculations.

Fixes compound-finance#1104
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant