Flawed validation on order admissions for opposing sides when failure is predictable
The router's projected-position calculation counted expired full CLOSE orders as if they would still execute, so it admitted an opposing-side OPEN order whose failure was already predictable. The trader then lost the reserved execution bounty to the keeper when the OPEN failed with MUST_CLOSE_OPPOSING.
Originally disclosed on Immunefi
- Disclosed after under an hour
#98253 [SC-Insight] Flawed validation on order admissions for opposing sides when failure is predictable
Submitted on Nov 6th 2026 at 10:51:38 UTC by @blackgrease for Audit Competition | Plether
- Report ID: #98253
- Report Type: Smart Contract
- Report severity: Insight
- Target: https://github.com/immunefi-team/audit-comp-plether/tree/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/src
- Impacts:
Description
OrderLiquidationBatchLogic._queuedPosition() incorrectly accounts for expired full CLOSE orders when validating opposing-side OPEN orders. This allows an OPEN order to be accepted even though its execution failure is already predictable - unnecessarily exposing the trader to a loss of their execution bounty.
Root Cause
The Router calculates an account's projected position by processing its pending orders. However, OrderLiquidationBatchLogic._queuedPosition() subtracts the size of a pending CLOSE without checking whether its execution deadline has passed.
function _queuedPosition(
IOrderLiquidationBatchHost host,
ICfdEngineCore engine,
address account
) private view returns (QueuedPositionView memory queuedPosition) {
//--SNIP---
if (pending.isClose) {
if (queuedPosition.exists && pending.side == queuedPosition.side) {
queuedPosition.size =
queuedPosition.size > pending.sizeDelta ? queuedPosition.size - pending.sizeDelta : 0;
if (queuedPosition.size == 0) {
queuedPosition.exists = false;
}
//--SNIP---
}
When a full close order has expired, it can no longer execute successfully, meaning the projection is provably inaccurate. However, the Router still assumes the expired order will close the existing position. _validatedOpenBounty() accepts the opposing-side OPEN based on the incorrect projection.
When the expired CLOSE is cleared from the queue, the existing position remains unchanged and the OPEN predictably fails with MUST_CLOSE_OPPOSING - as a trader cannot hold two opposing sides at the same time.
Example Scenario
- Alice holds a 10,000-unit SHORT.
- Alice queues a full SHORT close with a 20 second execution window.
- The deadline passes. The close is still Pending in the queue because expiry requires an on-chain cleanup transaction.
- Alice submits a LONG open. The Router projects the expired close as successful, so it accepts the LONG and reserves an execution bounty.
- A keeper expires the SHORT close (zero bounty; the SHORT remains open), then attempts the LONG.
- The LONG fails with
MUST_CLOSE_OPPOSING, causing Alice to unfavourably lose the LONG's execution bounty to the keeper - despite the order being unexecutable at submission.
Although the protocol acknowledges that an opposing-side OPEN may fail if a preceding CLOSE fails, this case differs because the CLOSE has already expired before the OPEN is submitted. The resulting OPEN failure is therefore predictable at admission and could have been prevented through proper validation, avoiding an unnecessary bounty loss.
Impact
Logic flaw resulting in loss of execution bounty: Insufficient validation allows an OPEN order to be accepted even though the protocol already knows its execution will fail. Consequently, the trader unnecessarily loses their execution bounty, as the keeper still performs its assigned task.
An order whose execution failure can be predicted prior should not be allowed to enter into the orderbook. The protocol already has rigourous input validation to prevent orders that will ultimately fail from being accepted.
Recommendations
Update _queuedPosition() to check the execution deadlines of pending orders when calculating an account's projected position. Orders that have already expired should be excluded from the calculation.
This prevents the Router from admitting opposing-side OPEN orders based on CLOSE orders that can no longer execute successfully.
Link to Proof of Concept
https://gist.github.com/blackgrease/40e526835399d8cd8a5bd6299dd4009c
Proof of Concept
The PoC in the private gist link - https://gist.github.com/blackgrease/40e526835399d8cd8a5bd6299dd4009c - reproduces the issue.
The PoC:
- Confirms that an opposing-side OPEN is rejected when an existing position has no pending CLOSE.
- Queues a CLOSE, lets it expire, and verifies that the expired order remains pending.
- Demonstrates that the Router incorrectly admits an opposing-side OPEN based on the expired CLOSE.
- Expires the CLOSE and verifies that the original position remains unchanged.
- Attempts to execute the OPEN and confirms it fails with
MUST_CLOSE_OPPOSING, causing the trader to lose the reserved execution bounty to the keeper. - Confirms that opposing-side OPEN admission is correctly rejected after cleanup.
Instructions to run:
- In the project root:
- Run with:
forge test --mt testPoC_ExpiredCloseAdmitsOpposingOpenAndPaysKeeperOnFailure --root packages/perps --threads 1 -vvvv
- Run with:
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the projected-position helper subtracts pending CLOSE sizes without checking whether those orders have passed their execution deadline.
Impact
A trader could lose their execution bounty on an order the protocol should have rejected at admission, though the loss is limited to that bounty.
What the attacker needed
A funded trading account; ability to queue and expire orders; a keeper to expire and execute
The fix
The projected-position calculation should exclude pending orders whose execution deadline has already passed.
How it was found
- Hold a short position and queue a full close with a short execution window.
- Let the deadline pass while the close stays pending in the queue.
- Submit an opposing open order, which the router accepts and reserves a bounty for.
- Have a keeper expire the close, then attempt the open, which fails with MUST_CLOSE_OPPOSING.
- Observe the trader losing the reserved execution bounty to the keeper.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A trader can queue orders that a keeper later executes. The system checks new orders against the position it expects after pending orders run. Here it forgot that a pending close order had already timed out and could never run, so it wrongly believed the position would be closed and accepted an opposite order that could not succeed. The trader paid a bounty for an order that was doomed from the start.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.