Skip to content

fix: prevent division by zero in quoteCollateral()#1105

Open
Kubudak90 wants to merge 1 commit into
compound-finance:mainfrom
Kubudak90:fix-1104-storeFrontPriceFactor-check
Open

fix: prevent division by zero in quoteCollateral()#1105
Kubudak90 wants to merge 1 commit into
compound-finance:mainfrom
Kubudak90:fix-1104-storeFrontPriceFactor-check

Conversation

@Kubudak90

@Kubudak90 Kubudak90 commented Apr 3, 2026

Copy link
Copy Markdown

Summary

Fixes #1104

Applies two-layer protection against divide-by-zero in quoteCollateral():

  1. Constructor validation (line 138): Change to to reject storeFrontPriceFactor == FACTOR_SCALE
  2. Runtime guard (line 1281): Add check before division

Problem

When storeFrontPriceFactor == FACTOR_SCALE (1e18) and liquidationFactor == 0:

  • discountFactor = FACTOR_SCALE * (1e18 - 0) / 1e18 = FACTOR_SCALE
  • assetPriceDiscounted = assetPrice * (1e18 - 1e18) / 1e18 = 0
  • Division by zero in quoteCollateral() line 1287

This permanently disables collateral sales for that market since the config is immutable.

Solution

Two-layer defense:

  1. Prevent invalid configuration at deployment time
  2. Add runtime guard as defense-in-depth

Checklist

  • Bug fix (non-breaking change which fixes an issue)
  • New feature
  • Breaking change
  • Requires documentation update

Testing

@Kubudak90 Kubudak90 force-pushed the fix-1104-storeFrontPriceFactor-check branch from 1c14427 to c174ec5 Compare April 4, 2026 19:29
…-finance#1104

Apply two-layer protection against divide-by-zero:
1. Constructor: Change storeFrontPriceFactor validation from > to >= FACTOR_SCALE
2. Runtime: Add guard check for assetPriceDiscounted == 0 before division

This prevents permanent disabling of collateral sales when:
- storeFrontPriceFactor == FACTOR_SCALE (1e18) AND
- liquidationFactor == 0 for any collateral asset
@Kubudak90 Kubudak90 force-pushed the fix-1104-storeFrontPriceFactor-check branch from c174ec5 to c306cf6 Compare April 4, 2026 19:33
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.

quoteCollateral() divides by zero when storeFrontPriceFactor == FACTOR_SCALE and liquidationFactor == 0

1 participant