# Bad debt (shortfall) liquidation leaves liquidated user in a negative collateral balance which can cause bank run and loss of funds for the last users to withdraw

Bad-debt liquidation leaves the liquidated account with negative collateral that is never socialized, so early withdrawers drain funds and last withdrawers lose out.

- Payout: Contest reward
- Severity: medium
- Program: Perennial
- Credited: WATCHPUG
- Disclosed: 2023-07-17
- Write-up quality: 7/10
- Original: https://github.com/sherlock-audit/2023-07-perennial-judging/issues/72
- Library page: https://bugbountylibrary.com/r/sherlock%3A2023-07-perennial%3AM-4
- Tags: domain:web3 impact:dos impact:funds-loss kind:contest platform:sherlock sev:medium tech:solidity technique:source-review vuln:accounting-error vuln:liquidation

**Target:** Perennial V2 Market.sol liquidation / collateral accounting
**Root cause:** Liquidation allows an account to end with negative collateral (shortfall) that is never reset to zero or socialized across counterparties, so total user collateral exceeds actual protocol funds.
**Steps:**
1. Set up market with two makers (50 maker each, 500 collateral) and a taker long=10 with 10 collateral at price $100.
2. Drop oracle price to $90 and liquidate the taker, paying a $10 liquidation fee.
3. Observe liquidated account collateral becomes -$100 while makers each gain $50 (550 each).
4. Total user collateral = $1100 but protocol funds = $1000.
5. First maker withdraws $550 successfully; second maker can only withdraw $450, losing $100.
**How found:** Reasoned about the accounting invariant that sum of user collateral should equal protocol funds; noticed liquidation permits negative collateral that is never socialized, breaking the invariant.
**Exploitation:** After any bad-debt liquidation, users race to withdraw before the shortfall is realized; the first withdrawers are made whole from the pool while the last withdrawers absorb the loss.
**Escalation:** Large bad debt amplifies the shortfall, triggering a bank run across all market participants.
**Insight:** Check whether liquidation can leave an account with negative collateral and whether that shortfall is socialized; if not, sum-of-collateral vs actual-funds invariant breaks and enables a withdrawal race.
