# Intent orders are guaranteed to execute, but fees from these orders are not accounted in collateral, allowing user to withdraw all collateral ignoring these pending fees.

Intent orders guarantee execution but pending fees aren't counted in collateral, letting attacker open/close, withdraw all, and claim referral fees as bad debt.

- 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/31
- Library page: https://bugbountylibrary.com/r/sherlock%3A2025-01-perennial-v2-4-update%3AH-3
- 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

**Target:** Perennial V2 market contract (update/checkpoint logic)
**Root cause:** Trade fees are only applied to collateral when advancing checkpoints after epoch price commit, but Intent orders are guaranteed (invalidation=0) and allow full close even with pending open, so fees remain pending and excluded from margin checks.
**Steps:**
1. Fund account1 and account2.
2. Account1 creates two Intents: open position and close position, with account3 as originator/referral.
3. Account2 executes both intents (open then close) in one transaction.
4. Withdraw all collateral from account1 and account2; pending fees ignored so full amount returned.
5. Wait for epoch price commit.
6. Call `market.claimFee(account3)` to collect referral fees, leaving account1 with bad debt.
**How found:** Observed that Intent orders are guaranteed (invalidation=0) and fees are only applied at checkpoint advancement after price commit; hypothesized that pending fees are excluded from collateral checks, allowing full withdrawal before fees are realized.
**Exploitation:** Attacker uses flash loan to fund accounts, executes open/close via Intents in one tx, withdraws all collateral (fees pending and not deducted), then after price commit claims referral fees via controlled originator, stealing market funds as bad debt.
**Escalation:** Can be repeated or scaled with flash loans; all market funds at risk.
**Insight:** When orders are guaranteed but fees are settled later, check if pending fees are included in margin/maintenance calculations; look for discrepancies between guaranteed execution and deferred accounting.

