ADL operations do not have any slippage protection
ADL orders created by the ADL keeper have no slippage protection, allowing unlimited price impact. An attacker could cause a user to receive much less than expected, turning a large gain into a loss.
Source: https://github.com/sherlock-audit/2023-02-gmx-judging/issues/143
Found by
Breeje, IllIllI
Summary
ADL operations do not have any slippage protection
Vulnerability Detail
ADL orders, generated by the ADL keeper, are forced to allow unlimited slippage, which means the user may get a lot less than they deserve.
Impact
There may be a large price impact associated with the ADL order, causing the user's large gain to become a loss, if the price impact factor is large enough, which may be the case if the price suddenly spikes up a lot, and there are many ADL operations after a lot of users exit their positions.
Code Snippet
Any price is allowed, and the minimum output amount is set to zero:
// File: gmx-synthetics/contracts/adl/AdlUtils.sol : AdlUtils.createAdlOrder() #1
141
142 Order.Numbers memory numbers = Order.Numbers(
143 Order.OrderType.MarketDecrease, // orderType
144 Order.DecreasePositionSwapType.NoSwap, // decreasePositionSwapType
145 params.sizeDeltaUsd, // sizeDeltaUsd
146 0, // initialCollateralDeltaAmount
147 0, // triggerPrice
148 @> position.isLong() ? 0 : type(uint256).max, // acceptablePrice
149 0, // executionFee
150 0, // callbackGasLimit
151 @> 0, // minOutputAmount
152 params.updatedAtBlock // updatedAtBlock
153: );
The only checks after the ADL order completes are related to global metrics, not position-specific ones.
Tool used
Manual Review
Recommendation
Introduce a MAX_POSITION_IMPACT_FACTOR_FOR_ADL, similar to MAX_POSITION_IMPACT_FACTOR_FOR_LIQUIDATIONS
Discussion
xvi10
The maximum price impact is capped by the MAX_POSITION_IMPACT_FACTOR value
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
The ADL order sets acceptablePrice to the extreme (0 for longs, max uint for shorts) and minOutputAmount to 0, so no slippage check is performed.
Impact
A user could suffer a large price impact, turning a gain into a loss, especially if the price spikes and many ADL operations occur; however, the maximum price impact is capped by MAX_POSITION_IMPACT_FACTOR.
What the attacker needed
ADL keeper triggers an ADL order; price impact factor is large enough
The fix
Introduce a MAX_POSITION_IMPACT_FACTOR_FOR_ADL similar to MAX_POSITION_IMPACT_FACTOR_FOR_LIQUIDATIONS.
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.
When a position is automatically reduced (ADL), the system accepts any price, so the user might get a worse deal than they should. This is like selling something without a minimum price, so someone else could buy it very cheaply.
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.