When underlying collateral tokens are paused, orders can't be canceled
When a collateral token is paused, cancelling an order fails because the refund transfer reverts, so the order cannot be cancelled. An attacker could place large market increase orders before a pause, then choose to cancel or let execution proceed after unpause based on price movement, gaining a free option at the expense of the counterparty.
Source: https://github.com/sherlock-audit/2023-02-gmx-judging/issues/167
Found by
IllIllI
Summary
When underlying collateral tokens are paused (e.g. USDC), orders can't be canceled, and will be executed immediately after unpause
Vulnerability Detail
Part of canceling an order is the sending back of the tokens provided. If the token is paused, the sending back will revert, preventing the cancellation.
Impact
If the order was a market increase order, the user gets a free look into future prices, and can decide after the token unpauses, whether to cancel the order or not, at the expense of the other side of the trade.
Code Snippet
For market orders, if the order reverts (e.g. due to the token being paused), the error handler attempts to cancel the order so that the user doesn't get to keep the block number (and therefore the price) that they submitted at:
// File: gmx-synthetics/contracts/exchange/OrderHandler.sol : OrderHandler._handleOrderError() #1
233 Order.Props memory order = OrderStoreUtils.get(dataStore, key);
234 bool isMarketOrder = BaseOrderUtils.isMarketOrder(order.orderType());
235
236 if (isMarketOrder) {
237 @> OrderUtils.cancelOrder(
238 dataStore,
239 eventEmitter,
240 orderVault,
241 key,
242 msg.sender,
243 startingGas,
244 reason,
245 reasonBytes
246 );
247: } else {
For market increase or swap orders, canceling the order sends back the collateral in the same transaction as the cancel.
An attacker can write a bot that front-runs token pauses, and submits very large increase orders. By the time the keeper gets to execute the order, the token will be paused, and when it tries to cancel, the cancel will revert. The attacker can watch the price movement during the pause, and if the potential position has a gain, let the keeper execute the order when the token gets unpaused. If the potential position has a loss, the bot can back-run the pause with a cancel, and prevent the keeper from opening the original position.
Tool used
Manual Review
Recommendation
Do not send the collateral back during the cancel - have another separate 'claim' function for it
Discussion
xvi10
This should be a very rare case, for the current scope this feature will not be added
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 cancel function refunds collateral in the same transaction, so a paused token makes the refund revert and blocks cancellation.
Impact
The attacker could get a free look at future prices and choose whether to cancel or execute after unpause, at the expense of the other side of the trade; the maintainer notes this is a very rare case.
What the attacker needed
Collateral token can be paused; attacker can front-run token pauses; keeper executes orders
The fix
The collateral should not be sent back during cancel; instead a separate claim function should handle the refund.
How it was found
- Attacker writes a bot that front-runs token pauses and submits very large increase orders.
- The token becomes paused before the keeper executes the order.
- The keeper tries to cancel the order, but the cancel reverts because the refund transfer fails.
- Attacker watches price movement during the pause.
- If the position would gain, attacker lets the keeper execute after unpause; if it would lose, attacker back-runs the pause with a cancel.
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.
Some tokens can be 'paused' by their issuer, meaning transfers stop working. Here, cancelling an order requires sending the user's tokens back, so if the token is paused the cancel fails. An attacker could exploit this to place a big order just before a pause and later decide whether to keep it or cancel it, depending on how prices moved.
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.