# Liquidations are temporarily blocked if user's pending position close amount is greater than the latest position size.

Perennial V2.4 blocks liquidations when a user's pending close amount exceeds latest position size, delaying liquidation and risking bad debt.

- Payout: Audit contest
- Severity: medium
- Program: Perennial
- Found by: panprog
- Disclosed: 2025-01-14
- Write-up quality: 7/10
- Original: https://github.com/sherlock-audit/2025-01-perennial-v2-4-update-judging/issues/33
- Library page: https://bugbountylibrary.com/r/sherlock%3A2025-01-perennial-v2-4-update%3AM-3
- Tags: area:web3 domain:web3 impact:dos impact:funds-loss kind:contest platform:sherlock sev:medium technique:source-review vuln:business-logic

**Target:** Perennial V2 core contracts, InvariantLib.sol
**Root cause:** InvariantLib enforces that pending negative orders cannot exceed latest position magnitude for non-intent orders, but liquidation orders are non-intent and cannot satisfy this when pending close already exceeds position size.
**Steps:**
1. User opens long position of size 10.
2. User submits Intent to fully close position (pending close = 10).
3. User submits Intent to open long 10 again (pending open = 10).
4. User submits Intent to partially close size 1 (pending close = 11).
5. Price drops, user becomes liquidatable.
6. Liquidation attempts revert due to `pendingLocal.neg().gt(latestPositionLocal.magnitude())` check in InvariantLib.
7. Liquidation only possible after pending close order settles, potentially after bad debt accrues.
**How found:** Code review of InvariantLib's validation logic for pending orders, noticing that liquidation orders are treated as normal orders and cannot satisfy the condition when pending close exceeds position size.
**Exploitation:** An attacker (or any user) can intentionally create a state where pending close exceeds latest position, preventing liquidations during price drops, allowing bad debt to accumulate and harming market solvency.
**Insight:** When designing liquidation mechanisms, ensure that liquidation orders are exempt from constraints that could be violated by existing pending orders, especially when pending orders can exceed current position size.

