# Bad debt isn't cleared when `earningsAccumulator` is lower than a fixed-pool bad debt

In Interest Rate Model, clearBadDebt skips clearing fixed-pool bad debt when earningsAccumulator is slightly lower than the debt, leaving bad debt uncleared and risking bank run.

- Payout: Contest reward
- Severity: medium
- Program: Interest Rate Model
- Credited: mahdikarimi
- Disclosed: 2024-04-06
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2024-04-interest-rate-model-judging/issues/66
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-04-interest-rate-model%3AM-1
- Tags: domain:web3 impact:dos impact:funds-loss kind:contest platform:sherlock sev:medium technique:source-review vuln:business-logic vuln:liquidation

**Target:** Market contract clearBadDebt function
**Root cause:** clearBadDebt only clears a fixed-pool bad debt if earningsAccumulator >= badDebt; otherwise it skips clearing entirely instead of clearing the maximum possible amount.
**Steps:**
1. Liquidate a loan with more debt than collateral, leaving bad debt in a fixed pool.
2. Call clearBadDebt(borrower) when earningsAccumulator is slightly less than the bad debt (e.g., 0.95 ETH vs 1 ETH).
3. Observe that the condition `accumulator >= badDebt` fails, so no bad debt is cleared.
4. The bad debt remains in the market, causing a discrepancy between tracked and actual funds.
**How found:** Manual code review of the clearBadDebt function, noticing the strict inequality condition that prevents partial clearing.
**Exploitation:** An attacker cannot directly profit; the flaw is a design issue where bad debt accumulates over time, potentially causing a bank run as lenders lose confidence and the last users cannot withdraw.
**Insight:** When reviewing liquidation or bad debt clearing logic, check whether partial clearing is supported; a strict `>=` condition can leave bad debt uncleared when the accumulator is slightly short.
