If ADL occurs right before finalization of a withdrawal, all funds from the ADL will be wrongly send to the withdrawer.
In order for a user to withdraw from vault, there is decrease order which when executed will trigger GmxProxy::afterOrderExecution() which internally calls PerpetualVault::afterOrderExecution(). The following snippet from PerpetualVault::afterOrderExecution() handles what should happen next:
We save the prevCollateralBalance based on the output of decrease order and Gamma keeper should call runNextAction() to finalize withdrawal and calculate how much collateral token should the user get.
In runNextAction() we have the following logic to handle withdrawal:
All index tokens would be swapped to collateral token and then in _finalize() we have
If ADL happens before finalizing withdrawal, all funds from the ADL wont be accounted in prevCollateralBalance and will be accounted as withdrawn from the decrease order. This is incorrect and withrawer will get much more collateral token than what he should.
Wrong withdraw amount for one user and loss of funds for all other users.
Manual review
Consider explicitly handling this scenario and update nextAction.data if needed when ADL occurs.
Likelihood: Low, when ADL with profit happen just before a nextAction.FINALIZE and FLOW.WITHDRAW Impact: High, the withdrawing user receives all the delivery with the tokens.
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.