Wrong trading pricing calculations
An agent could manipulate trading prices by creating many tiny orders at arbitrary prices and matching them with another account, which skewed the hourly average price used for funding rates and fair price. This allowed a malicious agent to manipulate the market.
Submitted by 0xsanson, also found by shw
In the Pricing contract, an agent can manipulate the trading prices by spamming a high amount of trades.
Indeed an agent can create a high amount of orders at an arbitrary price and with a near-zero amount (so the agent doesn’t even need large funds); next he/she pairs the orders with another account and calls Trader.executeTrade; now every order calls a Pricing.recordTrade using the arbitrary price set by the agent.
Since the trades are all made in the same hour, by the way hourlyTracerPrices[currentHour] is calculated, it skews the average price towards the price set by the agent. This arbitrary value is used to calculate the fundingRates and the fairPrice, allowing a malicious agent the ability to manipulate the market.
Recommend passing the fillAmount parameter to recordTrade(...), and calculate hourlyTracerPrices[currentHour].trades summing fillAmount instead of 1 every trade.
Issue is valid, and there appear to be a few other issues that reference similar problems.
The Trader contract will have a whitelist allowing only select relayers to push orders on chain. As long as off chain order books have sufficient liquidity, this issue is then mitigated as users can’t just arbitrarily match orders and send them in, they must be matched on a book with liquidity. To alter the price you would then need to eat through significant liquidity (increasing the cost of this attack).
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 hourly average price calculation counted each trade equally regardless of its size, so many tiny trades could skew the average.
Impact
The manipulated average price is used to calculate funding rates and fair price, allowing a malicious agent to manipulate the market; however, a whitelist of relayers and sufficient off-chain liquidity could mitigate the attack by increasing its cost.
What the attacker needed
Ability to create orders; a second account to pair orders; trades within the same hour
The fix
The recommendation is to pass the fill amount to recordTrade and sum fill amounts instead of counting each trade as one.
How it was found
- Create many orders at an arbitrary price with a near-zero amount.
- Pair the orders with another account and call `Trader.executeTrade`.
- Each order calls `Pricing.recordTrade` using the arbitrary price.
- Because all trades occur in the same hour, the hourly average price is skewed towards the attacker's price.
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.
In this trading system, prices are partly set by averaging recent trades. An attacker could make lots of tiny trades at a price they choose, which pulled the average towards their price. That fake average then affected funding rates and the fair price, letting them manipulate 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.