The _withdraw() function in the PerpetualVault.sol sets nextAction when handling withdrawals but does not properly reset it in all cases. This can lead to unexpected transactions, including unintended swaps, if nextAction is executed later without proper reinitialization.
_withdraw()Code Snippet:
If _withdraw() determines that a swap is needed, it sets nextAction.selector to SWAP_ACTION.
However, there is no explicit reset of nextAction in case of an error, manual cancellation, or when _handleReturn() is called directly.
If the function exits early or another operation is triggered before execution, nextAction remains set, causing unintended actions when executeNextAction() is later called.
Delayed Execution:
A user withdraws but does not complete the action chain.
nextAction remains in memory and executes when another function triggers executeNextAction().
Unintended Swap Execution:
If another user interacts with the contract while nextAction is set, they may inadvertently execute a swap that was never intended for them.
Exploitable State Pollution:
Malicious actors could manipulate the contract state by triggering _withdraw(), intentionally leaving nextAction set, and then waiting for another user to unknowingly execute it.
User Funds at Risk: Swaps can be unintentionally executed, resulting in unwanted asset conversions.
State Corruption: If nextAction persists between different user transactions, it can cross-contaminate actions between different users.
Exploitable Attack Vector: Attackers could force the execution of incorrect swaps, affecting liquidity and trading strategies.
A test case demonstrating the issue:
Manuel, Foundry
Explicitly Reset nextAction after every execution:
This ensures nextAction does not persist unexpectedly.
Validate nextAction Before Execution
Add a require check to verify that nextAction belongs to the caller before executing.
Introduce a Cancellation Mechanism
Allow users to explicitly cancel their nextAction if they do not wish to proceed.
There is no real proof, concrete root cause, specific impact, or enough details in those submissions. Examples include: "It could happen" without specifying when, "If this impossible case happens," "Unexpected behavior," etc. Make a Proof of Concept (PoC) using external functions and realistic parameters. Do not test only the internal function where you think you found something.
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.