DeFiFoundry
50,000 USDC
View results
Submission Details
Severity: high
Valid

The `_handleReturn` function uses incorrect deposit ID for execution fee refund

Summary

The _handleReturn function uses incorrect deposit ID for execution fee refund

Vulnerability Details

contracts/PerpetualVault.sol#L1129

When executing the refund logic, it first checks the balance of depositId with depositInfo[depositId].executionFee > usedFee, but then sends the funds to depositInfo[counter].owner.

if (refundFee) {
uint256 usedFee = callbackGasLimit * tx.gasprice;
if (depositInfo[depositId].executionFee > usedFee) { // @audit depositInfo[counter] -> depositInfo[depositId]
try IGmxProxy(gmxProxy).refundExecutionFee(depositInfo[counter].owner, depositInfo[counter].executionFee - usedFee) {} catch {}
}
}

Impact

This causes users to lose funds.

Tools Used

Recommendations


Recommended fix:

if (refundFee) {
uint256 usedFee = callbackGasLimit * tx.gasprice;
if (depositInfo[depositId].executionFee > usedFee) {
try IGmxProxy(gmxProxy).refundExecutionFee(depositInfo[depositId].owner, depositInfo[depositId].executionFee - usedFee) {} catch {}
}
}
Updates

Lead Judging Commences

n0kto Lead Judge 6 months ago
Submission Judgement Published
Validated
Assigned finding tags:

finding_counter_invalid_during_handleReturn

Likelihood: Medium/High, when withdraw on a 1x vault. Impact: High, the fees will be distributed to the last depositor and not the withdrawer.

Support

FAQs

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