# When account is liquidated (protected), liquidator can increase account's position to any value up to `2**62 - 1` breaking all market accounting and stealing all market funds.

Liquidation path dropped the position-must-decrease check, letting a liquidator inflate a pending-close account's position to 2**62-1 and drain market funds via price swing.

- Payout: Audit contest
- Severity: high
- Program: Perennial
- Found by: panprog
- Disclosed: 2025-01-14
- Write-up quality: 8/10
- Original: https://github.com/sherlock-audit/2025-01-perennial-v2-4-update-judging/issues/32
- Library page: https://bugbountylibrary.com/r/sherlock%3A2025-01-perennial-v2-4-update%3AH-4
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:sherlock sev:high tech:evm tech:solidity technique:source-review vuln:accounting-error vuln:business-logic vuln:liquidation

**Target:** Perennial V2 core Market liquidation / InvariantLib
**Root cause:** Liquidation invariant only checks pending.negative == latestPosition.magnitude instead of enforcing that the position strictly decreases; collateral and size checks are skipped during liquidation.
**Steps:**
1. Open tiny long from account1 with minimal collateral and tiny maker position from account2.
2. Wait until position is liquidatable (or force it by closing and withdrawing collateral).
3. Just before the position becomes liquidatable, fully close it so pending.negative == latestPosition.magnitude.
4. Call liquidation `update(user, 0, POSITION2_USER, 0, 0, true)` with POSITION2_USER = 2**62-1 to inflate the position.
5. Await committed price for the epoch of position increase (or commit himself), then commit a different price 1 second later.
6. In the same tx, withdraw all market collateral from whichever account is now hugely profitable.
7. Result: all market funds stolen.
**How found:** Code review of InvariantLib liquidation check: noticed the previous 'position must decrease' enforcement was removed, leaving only the pending.negative == magnitude equality, which a pending-close account already satisfies, allowing arbitrary position increase.
**Exploitation:** Liquidator inflates a pending-close account's position to max uint62; a 1-second price change then produces enormous PnL for the liquidated account or maker, and the attacker withdraws all market collateral in the same transaction.
**Escalation:** Chained with self-forced liquidation and price-commit timing to convert the inflated position into a full market drain.
**Insight:** When a safety invariant is refactored, check whether the replacement condition is an equality that a benign pre-state already satisfies — a pending-close account trivially matches pending.neg == magnitude, so the guard becomes a no-op for exactly the accounts an attacker controls.

## Proof of concept (copied exactly from the original report)

**Liquidation call increasing position to POSITION2_USER**

```
await market
    .connect(userC)
    ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, POSITION2_USER, 0, 0, true)
```

