# Anyone can steal all funds from the `market` due to incorrect health accounting for pending pnl from difference of intent price and market price when multiple intents are used.

Health check only accounts for the current intent's pending PnL, ignoring other pending intents, letting an attacker stack intents to drain the market.

- 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/28
- Library page: https://bugbountylibrary.com/r/sherlock%3A2025-01-perennial-v2-4-update%3AH-1
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:sherlock sev:high technique:source-review vuln:accounting-error vuln:business-logic

**Target:** Perennial V2 market contract (intent settlement and health check)
**Root cause:** InvariantLib.validate adjusts collateral only for the current intent (newGuarantee), ignoring PnL from other pending intents for the same account.
**Steps:**
1. Deposit collateral into account1 and account2.
2. Sign an intent from account1 with a price far above oracle (within maxPriceDeviation) and a position.
3. Submit the intent via account2 using `market.update`; health check passes because only this intent's PnL is considered.
4. Repeat signing and submitting the same intent multiple times within the same epoch; each passes health check individually.
5. Settle all intents; account1 ends with negative collateral and account2 with inflated profit.
6. Withdraw the inflated profit from account2, draining the market.
**How found:** Researcher noticed that health check only accounts for the current intent's price adjustment, not all pending intents, and realized multiple intents could bypass the check.
**Exploitation:** Attacker creates multiple intents with favorable price deviation, submits them via a second account, and after settlement withdraws the accumulated profit from the second account, leaving the first account with bad debt and stealing market funds.
**Insight:** When a health check adjusts collateral for pending orders, ensure it aggregates all pending orders for the account, not just the one being processed; otherwise, multiple small pending losses can be hidden.

