Skip to content
Business logic Audit finding Intermediate

Slippage is not respected if PnL swap associated with a decrease order fails

When a decrease order's PnL swap fails, the contract transfers the output tokens directly to the user without checking slippage. An attacker could receive fewer tokens than expected if the swap fails due to large price impact or a paused market.

IllIllI Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-02-gmx-judging/issues/159

Found by

IllIllI

Summary

After a position has been decreased, the user has an option to convert the PnL token to any other token via a swap.

Vulnerability Detail

If the swap fails (which is where the slippage is checked), the tokens are sent directly to the user, without checking whether there was slippage

Impact

A user will get back fewer tokens than they expect, if there was a large price impact, and the subsequent swap fails due to e.g. the market being temporarily disabled, or the swap impact being too large, or a token being swapped through is paused

Code Snippet

Funds are sent back directly, without checking for slippage:

Solidity
// File: gmx-synthetics/contracts/order/DecreaseOrderUtils.sol : DecreaseOrderUtils._handleSwapError()   #1

168            emit SwapUtils.SwapReverted(reason, reasonBytes);
169    
170            MarketToken(payable(order.market())).transferOut(
171                result.outputToken,
172                order.receiver(),
173 @>             result.outputAmount,
174                order.shouldUnwrapNativeToken()
175            );
176:       }

https://github.com/sherlock-audit/2023-02-gmx/blob/main/gmx-synthetics/contracts/order/DecreaseOrderUtils.sol#L168-L176

Tool used

Manual Review

Recommendation

Calculate whether the USD value of outputToken is equivalent to the minOutputAmount expected by the order, and revert if it's less than required

Discussion

xvi10

Fix in https://github.com/gmx-io/gmx-synthetics/pull/108

The original report as published on Sherlock, by IllIllI. 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 error-handling path for a failed swap bypasses the slippage check and transfers the output amount directly.

Impact

A user could receive fewer tokens than expected if the swap fails due to large price impact or a temporarily disabled market.

What the attacker needed

A decrease order with a PnL swap; the swap fails (e.g. market disabled)

The fix

The code should calculate whether the USD value of the output token meets the minimum output amount and revert if it does not; a fix was later linked.

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.

Slippage is the difference between the price you expect and the price you actually get. In this system, when you close a position, the profit or loss is swapped into another token, and the swap checks that you get at least a minimum amount. If that swap fails, the code sends you the tokens anyway without checking the minimum, so you might get less than you agreed to.

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 IllIllI

View all

119 more disclosed reports, best first.

More from GMX Update

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.