# Market coordinator can steal all market collateral by abusing very low value of `scale`

Perennial market coordinator sets takerFee.scale to 1, making proportional fees quadratic in order size, forcing a large taker into bad debt and draining all market collateral.

- Payout: Audit contest
- Severity: high
- Program: Perennial
- Found by: panprog
- Disclosed: 2024-08-17
- Write-up quality: 8/10
- Original: https://github.com/sherlock-audit/2024-08-perennial-v2-update-3-judging/issues/40
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-08-perennial-v2-update-3%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 risk parameters / fee accounting
**Root cause:** Proportional and adiabatic fees multiply by order_size/scale, so a tiny scale makes fees quadratic and unbounded; scale is only validated against a scaleLimit derived from makerLimit, which itself is unconstrained.
**Steps:**
1. Coordinator opens large maker position and settles it.
2. Coordinator opens large taker position (unsettled) via another account.
3. Coordinator calls `updateRiskParameter` with `makerLimit=1000000`, `takerFee.scale=1000000`, `takerFee.proportionalFee` at max.
4. Next oracle version settles taker with huge fee: taker goes into bad debt, maker gains more than total market collateral.
5. Coordinator withdraws maker profit, draining all market collateral.
**How found:** Read the fee formula `change.abs().mul(price).muldiv(change.abs(), scale).mul(fee)` and noticed fee scales with order_size/scale; then checked RiskParameter validation and saw scaleLimit depends only on unconstrained makerLimit and efficiencyLimit, allowing scale=1.
**Exploitation:** Malicious coordinator pre-positions as maker, opens a large pending taker position, then lowers makerLimit and takerFee.scale to 1000000 (or raises efficiencyLimit) so the pending taker settles with a fee exceeding 100% of notional. The resulting bad debt is socialized to the maker side, which the coordinator controls, yielding profit greater than total collateral that he withdraws. Steps 3-5 can be one transaction.
**Escalation:** If the market is part of a vault, forcing a re-balance charges huge fees making vault collateral negative; repeated re-balances drain most vault funds.
**Insight:** When a fee or penalty formula divides by a configurable parameter, check whether that parameter's lower bound is itself derived from another unconstrained parameter; a quadratic fee term (size^2/scale) can exceed 100% and be weaponized by a privileged role to force bad debt.

