This repository has been archived by the owner on Sep 24, 2023. It is now read-only.
IllIllI - Collateral tokens that cannot be automatically swapped to the PnL token, cannot have slippage applied to them #144
Labels
IllIllI
medium
Collateral tokens that cannot be automatically swapped to the PnL token, cannot have slippage applied to them
Summary
Collateral tokens that cannot be automatically swapped to the PnL token, cannot have slippage applied to them, since the
minOutputAmount
is in units of the output token, not the secondary token.Vulnerability Detail
If a user's order uses the
Order.DecreasePositionSwapType.SwapCollateralTokenToPnlToken
flag, it's possible for the swap to fail (e.g. because the token is paused), and in such cases, the collateral token is sent back as-is, without being converted to the PnL token. In such cases, it's not possible for the code, as it is written, to support slippage in such scenarios, because there is only one order slippage argument,minOutputAmount
, and it's in units of the PnL token, not the collateral token.Impact
A user that has a resting order open with the flag set, so that they can take profit at the appropriate time, will be forced to incur any price impact slippage present, even if they had specified a valid
minOutputAmount
that would otherwise have prevented the sub-optimal execution.Code Snippet
If the swap goes through, the
secondaryOutputAmount
is cleared and added to the outputAmount, but if the swap fails, it's kept as thevalues.output.secondaryOutputAmount
:https://github.com/sherlock-audit/2023-02-gmx/blob/main/gmx-synthetics/contracts/position/DecreasePositionCollateralUtils.sol#L383-L413
And is sent separately, with no slippage checks.
Tool used
Manual Review
Recommendation
Convert the USD value of
secondaryOutputAmount
tooutputAmount
, and ensure that the slippage checks against that totalThe text was updated successfully, but these errors were encountered: