collateralDeltaAmount for PnL Mismatches GMX’s Realization, Causing Small Over/Under-AdjustmentsDescription:
In the PerpetualVault.sol contract’s _withdraw function, the collateralDeltaAmount for partial GMX position withdrawals is pre-adjusted based on the proportional PnL (vaultReader.getPnl(curPositionKey, prices, sizeDeltaInUsd)). For negative PnL, it subtracts the loss from collateralDeltaAmount before submitting the decrease order to GMX. However, GMX realizes PnL during the decrease operation itself, adjusting the collateral returned. This pre-adjustment can lead to a mismatch, as the contract anticipates the PnL impact, while GMX applies it independently, potentially double-counting losses or misaligning with volatile market conditions.
Impact:
Minor Over/Under-Adjustments: For negative PnL, pre-subtracting the loss may reduce the withdrawal amount more than necessary if GMX also deducts it, causing users to receive slightly less than entitled. For positive PnL, no pre-adjustment occurs, relying on GMX’s realization, which is correct but inconsistent with the negative case, leading to small discrepancies.
No Vault Drain: The vault doesn’t lose funds beyond the position’s value, as GMX ensures correct final adjustments, but users may experience minor underpayments (e.g., a few USDC).
User Trust: Small inaccuracies in withdrawal amounts could erode confidence, though the financial impact is limited and doesn’t compromise vault integrity.
Recommended Mitigation:
Remove the pre-adjustment of collateralDeltaAmount for PnL, allowing GMX to handle PnL realization fully during the decrease operation, ensuring alignment with actual outcomes:
Fix:
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.