This repository has been archived by the owner on Dec 10, 2023. It is now read-only.
IllIllI - Swaps associated with position orders will use the wrong price #240
Labels
High
A valid High severity issue
Reward
A payout will be made for this issue
Sponsor Confirmed
The sponsor acknowledged this issue is valid
Will Fix
The sponsor confirmed this issue will be fixed
IllIllI
high
Swaps associated with position orders will use the wrong price
Summary
Swaps of tokens gained via position orders will use the wrong price as the latest price
Vulnerability Detail
In the previous iteration of the code, the
getLatestPrice()
function returned the secondary price, and fell back to the primary price if the secondary price didn't exist. In the current version of the code,getLatestPrice()
returns the custom price if one exists, which may be the trigger price or the maximized price. This price is used not only for the execution of the order, but also now for the swaps of the tokens after the order executes.Impact
If, for example, the order is a market increase order, the custom price is set to the maximized price for the execution which means the liquidity taker got fewer shares than the maker gave. When those shares are swapped, that maximized price is still used, whereas if the swap had been done as a separate order, no custom price would be consulted. The two methods of doing swaps get different prices, which leads to arbitrage opportunities.
Code Snippet
Normal swap orders never have an exact price set:
https://github.com/sherlock-audit/2023-04-gmx/blob/main/gmx-synthetics/contracts/order/BaseOrderUtils.sol#L203-L212
but swaps after the order will use the price set during the position-altering portion of the order:
https://github.com/sherlock-audit/2023-04-gmx/blob/main/gmx-synthetics/contracts/swap/SwapUtils.sol#L178-L189
Tool used
Manual Review
Recommendation
Introduce a flag to the
getLatestPrice()
function, indicating whether to use the custom price if it existsThe text was updated successfully, but these errors were encountered: