# Liquidation of PartyA will fail due to underflow errors

Liquidation of PartyA reverts with underflow when PartyB's allocated balance is less than the profitable quote's PnL, blocking liquidation and stranding assets.

- Payout: Contest reward
- Severity: high
- Program: Symmetrical
- Credited: bin2chen
- Disclosed: 2023-06-05
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2023-06-symmetrical-judging/issues/241
- Library page: https://bugbountylibrary.com/r/sherlock%3A2023-06-symmetrical%3AH-8
- Tags: domain:web3 impact:dos impact:funds-loss kind:contest platform:sherlock sev:high tech:solidity technique:source-review vuln:accounting-error vuln:dos vuln:liquidation

**Target:** LiquidationFacetImpl.liquidatePositionsPartyA (Solidity contract)
**Root cause:** When a quote is profitable for PartyA, the code subtracts the full PnL amount from partyBAllocatedBalances without capping it to the available balance, causing an unsigned integer underflow and revert.
**Steps:**
1. PartyB has partyBAllocatedBalances[partyB][partyA] = 1000 USD.
2. A quote's price spikes so getValueOfQuoteForPartyA returns hasMadeProfit=true with amount=3000 USD.
3. Call liquidatePositionsPartyA(partyA, [quoteId]) triggering the NORMAL/LATE/OVERDUE branch.
4. Execution reaches `partyBAllocatedBalances[quote.partyB][partyA] -= amount` (3000 > 1000) and reverts on underflow.
**How found:** Code review of the liquidation accounting: noticed the profit branch subtracts `amount` from an unsigned balance without checking it against the current allocated balance, then constructed a numeric example where PnL exceeds the balance.
**Exploitation:** Attacker (or any PartyB) keeps allocated balance below the unrealized profit of an underwater PartyA position; when liquidation is attempted the subtraction underflows and reverts, so liquidation never completes and the creditor cannot receive liquidated assets.
**Insight:** In liquidation/settlement accounting, any subtraction of a computed PnL from a per-party balance must be clamped to the available balance; a profitable position can exceed the counterparty's allocated funds and revert the whole liquidation, so check every `-=` on user balances against its source.
