In the PerpetualVault contract, there is a critical issue in the withdrawal cancellation flow that causes the entire operation to fail. When a withdrawal operation is initiated while an open position exists, the contract follows a specific sequence: settling outstanding fees, updating the position state, and queuing the operation for later execution by the keeper. For the flow to be canceled, the order is canceled first by calling cancelOrder() , and then the flow is canceled by calling cancelFlow().
The root cause lies in the implementation of the cancellation flow. When the withdrawal needs to be canceled, the _cancelFlow() function is called, which sets the flow state to LIQUIDATION and updates nextAction.selector to FINALIZE. However, it critically fails to set the required data in NextAction that the _finalize() function expects to decode. This oversight causes the finalization step to revert when the keeper attempts to execute the queued action through runNextAction().
This implementation flaw prevents the proper completion of withdrawal cancellations, potentially leaving the contract in an inconsistent state and affecting user operations. Also, suppose a malicious user tries to execute some malicious operation, the keeper will be unable to halt its execution seeing as the flow cannot be cancelled in this case.
A user initiates a withdrawal with an open position
Contract processes initial withdrawal steps:
Settles outstanding fees
Updates position state
Adds withdrawal to nextAction queue
Keeper attempts to cancel the withdrawal:
Calls cancelOrder()
Calls _cancelFlow()
Flow state changes to LIQUIDATION
nextAction.selector is set to FINALIZE
No data is set for finalization
Keeper calls runNextAction()
_finalize() attempts to decode non-existent data
Transaction reverts, leaving cancellation incomplete
Modify the _cancelFlow() function to properly set the required data for finalization:
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.