Skip to content
Business logic Audit finding Advanced

Unprivileged attacker can permanently pre-empt the owner-only amendLatchedPositionProtectionCloseLimits remedy, locking a trader out of their triggered TP/SL position

A permissionless retry function can move a latched position protection back to triggered with a fresh pending order, and anyone can also terminate the current attempt, so an attacker can keep the protection out of the latched-with-empty-queue state the owner-only amend function requires. This permanently blocks the trader from amending, cancelling or closing the position, leaving it exposed to price moves and liquidation.

nullvault Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

#97615 [SC-High] Unprivileged attacker can permanently pre-empt the owner-only amendLatchedPositionProtectionCloseLimits remedy, locking a trader out of their triggered TP/SL position

Submitted on Nov 2nd 2026 at 14:28:50 UTC by @nullvault for Audit Competition | Plether

Description

Summary

When a triggered protection close attempt fails or expires, the protection goes Triggered -> Latched. The trader's only documented remedy for unfillable close ceilings is the owner-only amendLatchedPositionProtectionCloseLimits. It is callable only while the protection is Latched AND the account has zero pending orders. retryPositionProtectionClose is permissionless and immediately moves the protection back to Triggered with a new pending child. Terminating the current attempt is also permissionless: oracle-free after its deadline (executeOrder(id, []), or clearInvalidOrders([id]) which works on non-head ids), or inside the window with public Pyth data so the attempt fails on the trader's own ceiling. An attacker can do both steps in one transaction, every window. At no transaction boundary is the protection Latched with an empty queue, so the owner's amend can never succeed. A triggered protection cannot be cancelled or replaced, and the active protection blocks any ordinary close. The trader cannot exit, reduce, or re-parameterise the position for as long as the attacker keeps paying ~1.13M gas per window, while the position stays exposed to price moves and liquidation.

Target

Plether perps, commit a82d4fefb02768e5b3bddcc97dee371eee24fea8, packages/perps/src/** — PositionProtectionBook.sol, OrderRouterExecutionSidecar.sol, OrderRecoverySidecar.sol, router/OrderLiquidationBatchLogic.sol

Relationship to Cecuro MED-9 (known issue) - why this is new

Cecuro MED-9 (keepers can retry protection closes without the trader's financial limits, Acknowledged) was about retries IGNORING the trader's limits. The post-audit remediation (commit 8a2853f, PR #124 eadc5c58) retains the trader's ceilings on every attempt and adds amendLatchedPositionProtectionCloseLimits. This report does NOT re-raise MED-9 — here the limits are enforced correctly. The bug is in the NEW remedy added by the fix: the escape hatch it promises can be made unreachable by any third party. It is post-audit code, absent from every prior report.

Root cause

  • PositionProtectionBook.sol:315-328 amendLatchedPositionProtectionCloseLimits: owner-only; requires status==Latched (:320) AND pendingOrderCounts(owner)==0 (:323).
  • PositionProtectionBook.sol:382-405 retryPositionProtectionClose: PERMISSIONLESS; Latched->Triggered with a fresh pending child. No owner-priority window, no cooldown.
  • PositionProtectionBook.sol:637-675 handleFailedProtectionAttempt: any failed/expired attempt on an unchanged position relatches (:665-667).
  • OrderRouterExecutionSidecar.sol:371-392: anyone can terminate an attempt after executionDeadline as Expired without oracle data.
  • OrderRecoverySidecar.sol:67-115 clearInvalidOrders: same oracle-free expiry, for non-head ids too.
  • router/OrderLiquidationBatchLogic.sol:657-680 _protectionCloseRequest: every retry copies the same stored ceilings; window = maxExecutionWindowSeconds.
  • PositionProtectionBook.sol:408-418 _cancel, :341-346 cancelPositionProtectionAndCommitClose: only from PendingOpen/Armed. Triggered/Latched cannot be cancelled.
  • router/OrderLiquidationBatchLogic.sol:313-314 OrderRouter__ProtectionActive: an ordinary close is rejected while protection is active.

The design gives the owner exactly one remedy and gates it on a state a permissionless actor controls; the actor can skip that state atomically.

Preconditions

  1. A trader has a TP/SL protection whose retained close ceilings are unfillable at execution time (the case the remediation explicitly anticipates). Realistic example (PoC Variant C): trader caps maxExecutionNotionalAssets at exactly size x TP price (9,000 USDG in the fixture); TP triggers; price moves back 5% before the post-commit execution tick; a recovered price does not cancel the latched mandate (SECURITY.md:547-552), so every attempt now exceeds the cap with ConstraintViolation.
  2. Attacker: no role, no capital, no position. Pyth update data is public (Hermes). Variants A and D need no oracle data at all.

Attack (one transaction per window)

  • Variant A (oracle-free): at executionDeadline+1, executeOrder(attemptId, []) -> Expired, Latched. Then retryPositionProtectionClose(protectionId) -> Triggered.
  • Variant B/C (in-window): executeOrder(attemptId, pythData) -> ConstraintViolation -> Latched. Then retry in same tx.
  • Variant D (non-head): as A but via clearInvalidOrders([attemptId]).

Impact

The owner cannot amend (OrderRouter__ProtectionNotLatched), cancel (OrderRouter__ProtectionNotArmed), or close/reduce (OrderRouter__ProtectionActive). The position and its backing margin are stuck for as long as the attacker continues (PoC: 1,417 consecutive windows, >24h), remaining exposed to adverse moves; the attacker can continue until the trader is liquidated. Cost to attacker: measured 1,134,664 gas per expiry+retry cycle, ~one per 61s => ~1.6B gas/day (~0.016-0.032 ETH/day at typical Arbitrum fees).

Recommended fix (any one)

  1. Owner-priority window: store relatchedAt; allow non-owners to retry only after relatchedAt + ownerAmendWindow.
  2. Allow the owner to amend while Triggered.
  3. Extend cancelPositionProtectionAndCommitClose to Latched/Triggered so the owner can replace the mandate with an ordinary close.
  4. Owner-only retryWithLimits(protectionId, limits) combined with (1).

Proof of Concept

File: packages/perps/test/poc/LatchedAmendGrief.t.sol, extends the repo's PositionProtectionTest fixture. 6/6 PASS (local Foundry, no fork): test_PoC_ExpiryRetry_LocksOwnerOutFor24h (1417 cycles, 86437s), test_PoC_PythFailRetry_LocksOwnerOut (241 cycles), test_PoC_RealisticCeiling_PriceBounce_LocksOwnerOut (241 cycles), test_PoC_ClearInvalidOrdersRetry_LocksOwnerOut (119 cycles), test_PoC_SingleCycleGas (1,134,664 gas/cycle), and control test_Control_RealisticCeiling_NoGriefer_OwnerAmendsAndExits (owner amends and exits when no attacker, proving the lock-out is solely attacker-caused). Run from packages/perps with FOUNDRY_GAS_LIMIT=18446744073709551615 (needed only because the 24h loop exceeds forge's default 2^30 per-test gas budget).

The original report as published on Immunefi, by nullvault. Images and videos are our own copies; raw HTML is shown as text. View it on Immunefi.

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

The owner-only amend remedy requires a latched state with no pending orders, but both the retry and the termination of an attempt are permissionless, so a third party can atomically skip that state every window.

Impact

The trader cannot amend, cancel, close or reduce the position for as long as the attacker keeps paying gas, so the position and its margin stay exposed to adverse price moves and could be liquidated.

What the attacker needed

A triggered TP/SL with unfillable ceilings; attacker needs no role or capital; attacker pays gas each window

The fix

The report recommends an owner-priority window before non-owners may retry, allowing the owner to amend while triggered, extending cancellation to latched and triggered states, or an owner-only retry with limits.

How it was found

  1. Wait until the current protection close attempt reaches its execution deadline.
  2. Terminate the attempt without oracle data so it expires and the protection becomes latched.
  3. Immediately call the permissionless retry so the protection returns to triggered with a new pending order.
  4. Repeat every window so the protection is never latched with an empty queue.

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 set up an automatic take-profit or stop-loss, and when it triggered the order could not be filled because of the trader's own price limit, so the system parked it in a 'latched' state. The only way out is a function the owner can call, but it only works when nothing is pending. Because anyone can restart the attempt and anyone can end it, an attacker can keep the system busy so the owner's fix never becomes available, and the trader cannot close the position.

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.

More from Plether

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.