# Market coordinator can set `staleAfter` to a huge value allowing anyone to steal all market collateral when there are no transactions for some time

Market coordinator sets staleAfter to uint24.max, letting a delta-neutral position go into bad debt on a stale price and drain all market collateral.

- Payout: Audit contest
- Severity: high
- Program: Perennial
- Found by: panprog
- Disclosed: 2024-08-17
- Write-up quality: 7/10
- Original: https://github.com/sherlock-audit/2024-08-perennial-v2-update-3-judging/issues/58
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-08-perennial-v2-update-3%3AH-6
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:sherlock sev:high tech:evm technique:source-review vuln:access-control vuln:business-logic vuln:oracle-manipulation

**Target:** Perennial V2 market RiskParameter / oracle price commit
**Root cause:** RiskParameter.sol performs no validation on staleAfter, so a coordinator can set it to an arbitrarily large value, allowing positions to be settled against a very old committed price.
**Steps:**
1. Coordinator opens equal-size huge long and short positions from two accounts (delta neutral).
2. Wait until no transactions occur and current price deviates from last committed price beyond margin requirement.
3. Set `staleAfter` to `uint24.max` and minimum `margin`/`maintenance` requirements.
4. Withdraw max collateral from the position on the losing side of the price move.
5. Next oracle version commits current price, pushing the withdrawn position into bad debt.
6. Close the profitable position, withdrawing its profit plus the withdrawn collateral; bad debt exceeds market collateral and drains it.
7. Repeat until all market collateral is stolen.
**How found:** Code review of RiskParameter.sol revealed staleAfter had no bounds check; reasoned that a huge value lets settlement use a stale price, enabling bad-debt creation against a delta-neutral position.
**Exploitation:** Coordinator abuses parameter control plus stale oracle price: delta-neutral portfolio, withdraw collateral from losing leg, let new price commit create bad debt larger than market collateral, then close winning leg to extract funds.
**Escalation:** Attack repeatable until entire market collateral is drained; large staleAfter lets attacker wait for favorable price deviation even in active markets.
**Insight:** When a privileged role controls risk parameters, check every parameter for missing bounds; staleAfter/oracle-staleness limits are a lever to force settlement against outdated prices and manufacture bad debt.

