ADL issue causes incorrect collateral token withdrawal amounts
When an ADL (Assume Debt and Liquidity) event occurs right before finalizing a withdrawal, the system incorrectly calculates the amount of collateral tokens a user should receive. This can result in users getting more funds than they should, causing financial losses for others.
The withdrawal process involves a series of steps. First, a decrease order is executed, which triggers GmxProxy::afterOrderExecution()
. This in turn calls PerpetualVault::afterOrderExecution()
. The code snippet below shows how the collateral balance is recorded before finalization:
The runNextAction()
function handles finalization. It swaps index tokens to collateral tokens and calls _finalize()
:
In _finalize()
, the collateral token balance is checked again to determine how much to return:
The issue arises when ADL occurs before finalization. In _handleReturn()
, the calculation assumes all collateral tokens come from the withdrawal, ignoring any changes caused by ADL:
This leads to overpayment because the system doesn't account for the additional funds introduced by ADL.
Users may receive more collateral tokens than they should, causing financial losses for others due to incorrect collateral accounting.
Manual Review
Track collateral changes caused by ADL events
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.