A critical accounting error exists in the afterOrderExecution callback when processing GMX MarketDecrease orders. The miscalculation of prevCollateralBalance leads to systematic underpayment of withdrawal amounts to users. This vulnerability stems from incorrect ordering of balance adjustment operations after receiving funds from GMX.
When closing positions via MarketDecrease orders:
GMX returns collateral via orderResultData.outputAmount
Contract balance automatically increases before callback execution
prevCollateralBalance calculation attempts to track pre-operation state
The calculation assumes outputAmount was added to the balance after this line. However:
GMX transfers outputAmount before triggering callback
collateralToken.balanceOf() already includes outputAmount
Subtracting outputAmount creates an artificial undercount
Withdrawal calculations use inflated "previous" balance
Users receive less collateral than entitled
Protocol accrues unaccounted funds through systematic underpayment
manual review
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.