During swapping process, the slippage parameter is hardcoded to fixed value. So at times of high volatility, the swapping might fail causing problems at different functionalities of the protocol.
Let's take example of GMXDeposit.sol
. After depositing the funds, if the one of the afterDepositChecks
fails then the processDeposit
would stop at the moment and would go to catch condition shown below where self.status
is assigned value GMXTypes.Status.Deposit_Failed
:
https://github.com/Cyfrin/2023-10-SteadeFi/blob/main/contracts/strategy/gmx/GMXDeposit.sol#L170C3-L186C6
As deposit function cannot be further continued due to failure in after deposit checks, so to withdraw liquidity from GMX ,first processDepositFailure
is called then further processDepositFailureLiquidityWithdrawal
is called to repay the borrowed loan amount. In processDepositFailureLiquidityWithdrawal
, swapping between tokenA and tokenB occurs to Adjust amount to repay for both tokens due to slight differences from liqudiity withdrawal and swaps. The problem is while swapping the slippage parameter is set to a fixed number - self.minSlippage
at :
https://github.com/Cyfrin/2023-10-SteadeFi/blob/main/contracts/strategy/gmx/GMXDeposit.sol#L307
which is assigned a fixed percentage of 1% at:
https://github.com/Cyfrin/2023-10-SteadeFi/blob/main/scripts/strategy/gmx/deploy-strategy-gmx.ts#L65
which is further assigned at the time of construction at GMXVault,sol
:
https://github.com/Cyfrin/2023-10-SteadeFi/blob/main/contracts/strategy/gmx/GMXVault.sol#L82
The swappers used for swapping of tokens are Uniswap and TraderJoe. The auto slippage percentage of Uniswap ranges from 0.5% - 5% . So , due to setting hardcoded slippage causes two problems:
During high volatility times, swap might fail automatically, as the slippage% would be >1%
During low volatility times when slippage is <1% , it would lead to unnecessary loss of funds.
Unexpected revert caused by hardcoded slippage during high volatility times
Manual review,
Reference Article: https://dacian.me/defi-slippage-attacks#heading-hard-coded-slippage-may-freeze-user-funds
Take in slippage parameter as the processDepositFailure
function and add necessary checks for the same.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.