The PerpetualVault::afterLiquidationExecution
function is triggered by the gmxProxy
contract when a liquidation callback is received from GMX
. However, the function fails to set isPositionClosed
to true
when a position is liquidated during the deposit
or withdraw
flow, potentially causing unintended protocol behavior.
current state, beenLong == true, leverage == 10_000, positionIsClose == false
User calls the withdraw function, nextAction.selector is set to NextActionSelector.WITHDRAW_ACTION.
The position get liquidated and afterLiquidationExecution
gets called.
as the current flow is withdraw so the nextAction
stays the same.
keeper calls the runNext
function which calls the _withdraw
function
The _withdraw function checks if the positionIsClosed
is true or false.
As the positionIsClosed is currently false and _isLongOneLeverage(beenLong)
is true, causing the protocol to place a MarketSwap
order with swapAmount as 0 leading to an error from the GMX as the position has been liquidated.
When withdrawing collateral tokens, the protocol bypasses the (positionIsClosed == true)
check, which can result in incorrect fund transfers or prevent users from retrieving their funds.
Manual Review
Add a mechanism in the afterLiquidationExecution
function to allocate isPositionClose
to be true when the flow is withdraw
and deposit
.
"// keep the positionIsClosed value so that let the keeper be able to create an order again with the liquidated fund" Liquidation can send some remaining tokens. No real impact here.
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.