DeFiFoundry
50,000 USDC
View results
Submission Details
Severity: low
Invalid

ExecutionFees is not refunded when user withdraws when the positionIsClosed

Summary

withdrawers are forced to pay the executionFees even though the positionIsClosed (currentPositionKey == 0 ) and no GMX call is needed.

Vulnerability Details

When a user tries to withdraw his shares when the positionIsClosed , there are no calls to GMX done but still paying the executionFees.

Since ,in _withdraw() there is no effort made to refund the executionFees , the users lose those fonds forever.

https://github.com/CodeHawks-Contests/2025-02-gamma/blob/84b9da452fc84762378481fa39b4087b10bab5e0/contracts/PerpetualVault.sol#L1095-L1097

if (positionIsClosed) {
=> _handleReturn(0, true, false);
} else if (_isLongOneLeverage(beenLong)) { // beenLong && leverage == BASIS_POINTS_DIVISOR

in the => code , false is passed as the refundFees parameter and hence no refund is done when the positionIsClosed.

Same bug can be seen ,when the vault is completely liquidated.code

Impact

ExecutionFees is not refunded when user withdraws when the positionIsClosed

Tools Used

Manual

Recommendations

change to
_handleReturn(0, true, true);

Updates

Lead Judging Commences

n0kto Lead Judge 5 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

invalid_withdraw_positionIsClosed_does_not_refund_fees

No fee needed in _payExecutionFee when position is closed. Make a PoC if you disagree.

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.