In the PerpetualVault contract's withdrawal process, there is a bug in the execution fee refund logic where the wrong deposit ID (counter instead of depositId) is used to determine the refund recipient and amount. This can result in refunds being sent to the wrong users or being lost entirely.
The bug occurs in the _handleReturn function where the execution fee refund logic incorrectly uses counter instead of the actual depositId of the withdrawal:
Initial withdraw function stores depositId in flowData
_handleReturn correctly retrieves depositId from flowData
But the refund logic incorrectly switches to using the global counter variable
Execution fee refunds may be sent to the wrong users (owners of the latest deposit instead of the withdrawing deposit)
Incorrect refund amounts may be calculated and sent
Refunds may fail entirely if depositInfo[counter] has been cleared
Users withdrawing their deposits may lose their execution fee refunds
Unauthorized users may receive refunds they're not entitled to
Manual code review
Fix the refund logic in _handleReturn to consistently use the correct depositId:
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.