# Profitable liquidations and accumulation of bad debt due to earnings accumulator not being triggered before liquidating

Market.liquidate() previews collateral without accruing the earnings accumulator, so liquidatees keep extra shares and profit from their own liquidation while bad debt persists.

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

**Target:** Lending market liquidate() / Auditor.checkLiquidation()
**Root cause:** liquidate() computes collateral via totalAssets() before calling accrueAccumulatedEarnings(), so lendersAssets and expired-maturity penaltyRate instantly inflate the liquidatee's share value after the collateral preview, leaving leftover collateral.
**Steps:**
1. Deploy Market; ALICE deposits 10_000 ether and borrows at maturity ~78% LTV.
2. Skip past maturity so penaltyRate accrues into earningsAccumulator.
3. Call `market.liquidate(ALICE, type(uint256).max, market)` without prior accrual.
4. Observe ALICE retains ~774e18 collateral and 157e18 debt instead of 0/0.
5. ALICE repays and redeems, netting more than pre-liquidation collateral-minus-debt (802e18 -> 1556e18).
**How found:** Code reading of liquidate()/checkLiquidation() revealed totalAssets() used before accrueAccumulatedEarnings(); Foundry PoC confirmed liquidatee profit.
**Exploitation:** Liquidatee waits for liquidation; because collateral preview ignores the accumulator, the seized amount is understated and the borrower keeps shares that then appreciate, extracting value from LPs; alternatively leftover dust collateral blocks handleBadDebt() so bad debt accumulates.
**Escalation:** Repeated liquidations each leak value; bad debt never cleared since liquidatee always retains some shares.
**Insight:** In lending markets with smoothed earnings accumulators, check whether liquidation/health-factor math reads totalAssets() before accruing pending interest or penalties; any preview-then-accrue ordering lets the borrower capture the delta.
