The PerpetualVault contract does not account for GMX's position fees when calculating position sizes. These fees reduce the collateral amount while maintaining the same position size, causing the effective leverage to increase over time. This "leverage drift" exposes positions to higher liquidation risk than intended.
When increasing positions on GMX, fees are deducted from the collateral amount during order execution. This happens in ExecuteOrderUtils.processOrder()
(OrderHandler: 0xe68CAAACdf6439628DFD2fe624847602991A31eB), specifically in the IncreasePositionUtil.processCollateral()
function:
getPositionFees() calculates the total fees associated with a position in a market and subtract it from collateralDeltaAmount
Also, note that unlike withdraw, deposit doesn't have the _settle() step before increasing positions
On the other hand, the position size remains unchanged during this process:
The PerpetualVault contract calculates position sizes without considering these fees:
Consider a position with:
Initial deposit: 100 USDC
Target leverage: 2x
Position size: 200 USDC
Initial leverage: 200/100 = 2x
After fees of 1 USDC:
Remaining collateral: 99 USDC
Position size: 200 USDC (unchanged)
Actual leverage: 200/99 ≈ 2.02x
The leverage drift increases liquidation risk by making positions more leveraged than intended, potentially leading to unexpected liquidations. Additionally, it creates risk management issues, as the vault's actual exposure may exceed its stated parameters.
Manual Review
Adjust position size calculations to account for fees, similar to how it's done in PerpetualVault::_withdraw
.
Please read the CodeHawks documentation to know which submissions are valid. If you disagree, provide a coded PoC and explain the real likelihood and the detailed impact on the mainnet without any supposition (if, it could, etc) to prove your point.
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.