# When bad debt is accumulated, the loss is not shared amongst all suppliers, instead the last to withdraw will experience a huge loss

Lending pool doesn't socialize bad debt; first suppliers withdraw at full rate, leaving last withdrawer with severe loss.

- Payout: Audit contest
- Severity: high
- Program: New Scope
- Found by: A2-security
- Disclosed: 2024-06-27
- Write-up quality: 7/10
- Original: https://github.com/sherlock-audit/2024-06-new-scope-judging/issues/275
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-06-new-scope%3AH-7
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:sherlock sev:high tech:evm tech:solidity technique:source-review vuln:business-logic vuln:liquidation

**Target:** lending pool supply/withdraw logic (SupplyLogic.sol)
**Root cause:** Withdrawal amount is computed as shares * liquidityIndex without accounting for accumulated bad debt, so the loss is not distributed across suppliers.
**Steps:**
1. Alice supplies 268 tokenA collateral; Bob and supplierOfTokenB each supply 50 tokenB
2. Alice borrows 100 tokenB against collateral
3. Oracle price drops so position is liquidatable and in bad debt
4. Liquidator repays only 64 tokenB, taking all collateral
5. Bob withdraws his full 50 tokenB with zero loss
6. supplierOfTokenB can only withdraw ~13 tokenB; full withdrawal reverts
**How found:** Reasoned that bad debt should be socialized; inspected SupplyLogic withdraw math and noticed shares*liquidityIndex ignores bad debt, then built a PoC with two equal suppliers and a bad-debt liquidation.
**Exploitation:** After a bad-debt liquidation, the first supplier to withdraw redeems shares at the unadjusted liquidityIndex and exits whole, draining the pool; the last supplier absorbs the entire shortfall.
**Insight:** In lending pools, check whether the share-to-asset exchange rate is reduced after a bad-debt liquidation; if not, first-withdrawer advantage lets suppliers front-run the loss.

