The refundFee can be returned to the wrong address (stolen) via front-running of withdrawals
In PerpetualVault::_handleReturn(), there is an optional returning of the refund fee to the depositor, in case the actual executionFee surpasses the usedFee (calculated based on the gas usage in the transaction). This is done by sending native tokens to the deposit's owner via the GmxProxy contract. The returning of fees is executed chiefly as part of the withdrawal flow.
The issue is that the owner of the deposit is determined with depositInfo[counter] instead of depositInfo[depositId], which always returns the owner of the latest deposit. This leaves the door for a front-running attack, in which the malicious actor could front-run a legitimate withdrawal request by depositing themselves and receiving the refund fee from the real owner of the original deposit.
User A deposits 1000 USDC and sends 0.001 ETH as msg.value, in order to cover the executionFee.
The remaining (unused) refund fee is 0.0005 ETH.
User A submits a withdrawal transaction request (transaction is still in the memory pool)
User B front-runs them by submitting a deposit request for 1000 USDC and a higher gas price.
counter is updated to User B's deposit.
User A's withdrawal is finally processed, at which point the 0.0005 ETH is sent to User B's address.
High - funds could be stolen from users relatively easily. Likelihood - lower, as the refunded amounts are likely not to be too large to attract huge interest. Also, the attacked would need to invest in the Vault for the lockTime period, before being able to withdraw their funds themselves.
Manual review.
Return the refund fee to the owner of the deposit with depositId instead of counter:
Likelihood: Medium/High, when withdraw on a 1x vault. Impact: High, the fees will be distributed to the last depositor and not the withdrawer.
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.