# A trader close to liquidation risks being liquidated by trying to reduce her position

Perennial deducts taker fee from collateral immediately on closeTake while position reduction settles later, making a near-liquidation trader instantly liquidatable when trying to reduce leverage.

- Payout: Contest reward
- Severity: medium
- Program: Perennial
- Credited: cergyk
- Disclosed: 2023-05-05
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2023-05-perennial-judging/issues/76
- Library page: https://bugbountylibrary.com/r/sherlock%3A2023-05-perennial%3AM-9
- Tags: domain:web3 impact:funds-loss kind:contest platform:sherlock sev:medium tech:solidity technique:source-review vuln:accounting-error vuln:fee-bypass vuln:liquidation

**Target:** Product.sol closeTake/closeMake collateral accounting
**Root cause:** Taker fee is deducted from collateral immediately on close, but the position reduction only applies at next settlement, and maintenanceInvariant is not enforced on close, so collateral drops below maintenance before the position shrinks.
**Steps:**
1. Open a 50x taker position: 100 DSU collateral, 5000 DSU notional (maintenance factor 2%).
2. Call `closeTake(1000)` to reduce position.
3. Observe 1 DSU taker fee deducted immediately from collateral.
4. Position reduction not applied until next oracle version, so collateral now below maintenance threshold.
5. Liquidator closes position, charging liquidation fee (~250 DSU) plus taker fee on settlement.
**How found:** Code reading of closeTake/closeMake showed maintenanceInvariant not enforced on close and taker fee deducted immediately while position changes settle later — an inconsistency in collateral handling timing.
**Exploitation:** A liquidator monitors for accounts pushed below maintenance by the immediate fee deduction after a close call and liquidates them, collecting the liquidation fee even though the position was already being closed (noop close).
**Insight:** When auditing perp/derivative protocols, check whether fees and collateral changes are applied at the same time as position changes; a fee charged synchronously against a position that settles asynchronously can flip a healthy account into liquidation.
