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

The depositor unintendly loses the execution fee paid and will never get refunded.

Summary

Unlike withdraw() , deposit() assumes that the sender knows whether the position is closed or opened prior, because protocol is not refunding the executionFees in case the position is closed.

But there can be a scenerio when the position is open and a sender calls deposit() with some msg.value as executionFees. When the transaction is still in txn pool , the keeper immediately calls run() for closing the position to automate the foreseen risk. Since the keeper for sure prirotise this txn, it will get executed prior to the deposit().

Even though the withdraw() takes care of this scenerio effectively the deposit() lacks this implementaion.

Vulnerability Details

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

function deposit(uint256 amount) external nonReentrant payable {
......
=> if (positionIsClosed) {
MarketPrices memory prices;
_mint(counter, amount, false, prices);
_finalize(hex'');
} else {
_payExecutionFee(counter, true);
// mint share token in the NextAction to involve off-chain price data and improve security
nextAction.selector = NextActionSelector.INCREASE_ACTION;
nextAction.data = abi.encode(beenLong);
}

When the position is closed no refunding of the executionFees is made.

Impact

The depositor unintendly loses the execution fee paid and will never get refunded.

Tools Used

Manual

Recommendations

Implement like withdraw() by refunding the executionFees if the position is Closed.

Updates

Lead Judging Commences

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

finding_no_refund_when_deposit_just_after_a_keeper_close_position

Likelihood: Low, send a deposit with execution fees but a “run” keeper is made just before to close the position. Impact: Low/Medium, no refund of the execution fee, althought they were no need for them.

Support

FAQs

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