Skip to content
Business logic Audit finding Advanced

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

The market coordinator could set the staleAfter risk parameter to an arbitrarily large value because there was no validation. This allowed them to open a delta-neutral position, wait for the price to move, withdraw collateral from the losing side, and then close the winning side to steal all market collateral.

panprog Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-08-perennial-v2-update-3-judging/issues/58

Found by

panprog Summary The README states the following:

Q: Please list any known issues and explicitly state the acceptable risks for each known issue. Coordinators are given broad control over the parameters of the markets they coordinate. The protocol parameter is designed to prevent situations where parameters are set to malicious steal funds. If the coordinator can operate within the bounds of reasonable protocol parameters to negatively affect markets we would like to know about it

Market coordinator can set staleAfter risk parameter to any value (there is no validation at all). If set to a huge amount, he can steal all market collateral by abusing the price commited long time ago to open huge position which is already in bad debt using current price, when the current price is already very far away from the last commited price.

Root Cause No staleAfter validation in RiskParameter: https://github.com/sherlock-audit/2024-08-perennial-v2-update-3/blob/main/perennial-v2/packages/perennial/contracts/types/RiskParameter.sol#L132-L162

Internal pre-conditions

  • Malicious market coordinator

External pre-conditions

  • Last commited price differs from current price by more than margin requirement

Attack Path

  1. Coordinator opens huge long position + huge short position of the same size from 2 accounts (delta neutral portfolio)

... 2. Situation happens: no transactions for a long time and current price deviates away from last commited price by more than margin amount (such situation is very easily possible when the market is not super active, during quick price moves just a few minutes without transactions are enough for such price move). 3. Coordinator sets very large staleAfter value (e.g. uint24.max) and minimum margin and maintenance requirements 4. Coordinator withdraws max collateral from either long or short position (depending on whether current price is more or less than last commited price) 5. Next oracle version is commited (with current price), making the coordinator's position with collateral withdrawn go into bad debt. 6. Coordinator closes the other position, withdrawing all profit from it (collateral withdrawn from bad debt position + collateral withdrawn from closing the other position = initial collateral of both positions + bad debt) 7. The bad debt of the losing position is the profit of 2 combined positions, if positions are large enough, the bad debt will be greater than all market collateral, thus the user steals all of it.

If needed, the attack can be repeated until all market collateral is stolen.

Impact All market collateral stolen. The severity is "High" even with market move pre-condition, because large staleAfter amount allows to wait enough time for the price to move away, and even in active live markets there are often large periods of inactivity (lack of market transactions and lack of new price commits since there are no requests).

PoC Not needed.

Mitigation Add sanity check for staleAfter risk parameter.

Discussion

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/equilibria-xyz/perennial-v2/pull/463

The original report as published on Sherlock, by panprog. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the lack of validation on the staleAfter parameter in RiskParameter, allowing it to be set to an extremely large value.

Impact

All market collateral could be stolen, and the attack can be repeated until all collateral is gone.

What the attacker needed

Malicious market coordinator; Price deviates from last committed price; Period of no transactions

The fix

The protocol team fixed this issue by adding a sanity check for the staleAfter risk parameter.

How it was found

  1. Coordinator opens a huge long position and a huge short position of the same size from two accounts.
  2. No transactions occur for a long time and the current price deviates from the last committed price by more than the margin requirement.
  3. Coordinator sets a very large staleAfter value and minimum margin and maintenance requirements.
  4. Coordinator withdraws maximum collateral from either the long or short position, depending on price movement.
  5. Next oracle version is committed with the current price, causing the position with withdrawn collateral to go into bad debt.
  6. Coordinator closes the other position, withdrawing all profit, which equals the initial collateral plus the bad debt, potentially stealing all market collateral.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A market coordinator is someone who manages settings for a trading market. They could set a timer called staleAfter to a very large number, which meant the system would accept very old prices. By opening two opposite trades and waiting for the price to change, they could take money from the market.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by panprog

View all

66 more disclosed reports, best first.

More from Perennial V2 Update #3

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.