Incorrect refund id usage in _handlereturn function
The _handleReturn function incorrectly uses counter instead of depositId when processing refunds, leading to potential issues with accurate gas fee refunds for users.
The issue occurs in the _handleReturn function within the PerpetualVault contract. Specifically, when handling refunds, the code uses counter to access depositInfo:
This is problematic because counter always points to the most recent deposit, while depositId refers to the specific deposit being processed. If a user withdraws funds from an older deposit, counter won't match their deposit, leading to incorrect refund calculations or no refund at all.
Users may experience issues with gas fee refunds, including missing refunds or receiving the wrong amount.
Manual Review
Replace counter with depositId in the refund logic to ensure the correct deposit is referenced:
This change aligns the refund logic with the rest of the function, which already uses depositId correctly.
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.