Skip to content
Business logic Audit finding Advanced

Missing owner check in retryPositionProtectionClose lets anyone block the owner's amend and freeze a position's margin

The permissionless retryPositionProtectionClose function shares its precondition with the owner-only amend function, so anyone can re-queue a failing protected close before the owner amends. This keeps the protection in a triggered state, blocking the owner's amend and freezing the position's margin for as long as the attacker keeps paying.

itsactuallyomar Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

#99800 [SC-High] Missing owner check in retryPositionProtectionClose lets anyone block the owner's amend and freeze a position's margin

Submitted on Nov 15th 2026 at 10:35:50 UTC by @itsactuallyomar for Audit Competition | Plether

Description

Brief/Intro

PositionProtectionBook.retryPositionProtectionClose has no owner check, and it needs the same state as the owner's remedy for a failed protected close, amendLatchedPositionProtectionCloseLimits: both require the protection to be Latched with no pending order, and only the amend is owner-only. When a stop-loss close fails because the market gapped past the trader's own price ceiling, anyone whose transaction lands first can re-queue the same failing close before the owner's amend. The protection is then Triggered again, the amend reverts, and cancel, cancel-and-close and an ordinary close are unavailable by design while a protection is triggered. In the PoC, the owner of a 10,000,000 USDG LONG who uses the documented single-call amend cannot amend for 24 hours (57 hours across a weekend), so the position stays open and its margin (974,045.71 USDG at the end of the 24-hour lock) cannot be withdrawn, while the attacker pays USD 2,481.74 of gas per day at 0.02 gwei.

Vulnerability Details

The owner's remedy and the retry need the same state

The owner's remedy, PositionProtectionBook.sol:315-328:

Solidity
function amendLatchedPositionProtectionCloseLimits(
    uint64 protectionId,
    PositionProtectionTypes.CloseFinancialLimits calldata limits
) external nonReentrant {
    StoredProtection storage protection = _ownedActiveProtection(protectionId, msg.sender);
    if (protection.status != PositionProtectionTypes.PositionProtectionStatus.Latched) {
        revert OrderRouter__ProtectionNotLatched();
    }
    if (IPositionProtectionRouterHost(ROUTER).pendingOrderCounts(msg.sender) != 0) {
        revert OrderRouter__PendingOrdersExist();
    }
    _setCloseLimits(protection, limits);
    _emitCloseLimitsUpdated(protection);
}

The retry, PositionProtectionBook.sol:382-406, callable by anyone:

Solidity
function retryPositionProtectionClose(
    uint64 protectionId
) external nonReentrant returns (uint64 linkedOrderId) {
    StoredProtection storage protection = _activeProtection(protectionId);
    if (protection.status != PositionProtectionTypes.PositionProtectionStatus.Latched) {
        revert OrderRouter__ProtectionNotLatched();
    }
    _requireMatchingPosition(protection);

    IPositionProtectionRouterHost router = IPositionProtectionRouterHost(ROUTER);
    if (router.pendingOrderCounts(protection.account) != 0) {
        revert OrderRouter__PendingOrdersExist();
    }
    // ... :396-399 (linked-order check, expected order id)
    linkedOrderId = IPositionProtectionCloseAttemptHost(ROUTER)
        .commitProtectionCloseAttempt(protectionId, protection.account, protection.side, protection.size);
    // ... :402-404 (host-response check)
    _recordCloseAttempt(protection, linkedOrderId);
}

_ownedActiveProtection reverts OrderRouter__Unauthorized for anyone but the protection's account (:983-991). _activeProtection, which the retry uses, only checks that the protection is the account's active one (:993-999).

The cycle

  1. A keeper triggers the protection. The Book queues a close of the whole position (an attempt) whose request copies the trader's stored ceilings, with a zero bounty and the full execution window (router/OrderLiquidationBatchLogic.sol:670-677). _recordCloseAttempt sets Triggered (PositionProtectionBook.sol:573).
  2. The market is past the ceiling, so executing the attempt fails with ConstraintViolation. Inside the executor's call, settleOrderFromSidecar (OrderRouter.sol:292-312) passes the failed attempt to handleFailedProtectionAttempt (:324-329), which sets Latched because side and size still match (PositionProtectionBook.sol:662-667), and _deleteOrder decrements pendingOrderCounts (router/OrderRouterBase.sol:122-141).
  3. The protection is now Latched with no pending order. That is the precondition of both functions, so whoever transacts first decides. A retry queues a new attempt with the same stored ceilings and sets Triggered with one pending order, and the owner's amend that follows reverts OrderRouter__ProtectionNotLatched (:320-322).
  4. The new attempt fails the same way while the market stays past the ceiling, and the cycle repeats. Neither the retry nor _recordCloseAttempt (:564-577) counts or limits retries.

The attacker can run the cycle in two ways, both in the PoC: (A) a bare retryPositionProtectionClose sent right after each failed keeper execution, or (B) a contract that executes the attempt itself and retries in the same transaction, so that the protection is Triggered with one pending order at every transaction boundary.

The other exits are closed by design once a protection has triggered

  • Cancellation accepts only PendingOpen or Armed (PositionProtectionBook.sol:414-419).
  • cancelPositionProtectionAndCommitClose accepts only Armed (:346-348).
  • An ordinary close through commitOrder reverts OrderRouter__ProtectionActive while a protection is active (router/OrderLiquidationBatchLogic.sol:313-315).

This is documented (CANONICAL_ENTRYPOINTS.md:142-144): "Once a trigger is recorded, neither the owner nor a keeper may replace or cancel it." The attacker does not cause these three reverts. They are why the amend is the owner's remedy.

While the position is open, its margin stays in MarginClearinghouse: a withdrawal reverts MarginClearinghouse__InsufficientFreeEquity unless the remaining equity covers all locked margin (MarginClearinghouse.sol:467-470).

The intended order is amend, then retry

  • IPositionProtectionActions.sol:32: "Lets the owner change close limits after a failed attempt relatches, before a fresh retry."
  • packages/perps-aa-client/README.md:204-205: "buildAmendLatchedProtectionCloseLimitsAction lets the owner change the close limits of a Latched protection before a permissionless retry."
  • CANONICAL_ENTRYPOINTS.md:145-147: "The owner may amend the close ceilings of a Latched protection with PositionProtectionBook.amendLatchedPositionProtectionCloseLimits(uint64,CloseFinancialLimits) when the account has no pending Router order. This changes the limits used for a future retry".
  • The team's reply to MED-9 ("Keepers can retry protection closes without the trader's financial limits") in audits/plether-ai-audit-report-2026-10-26.pdf, the finding whose fix made the trader's ceilings persist across retries: "Only the owner may amend the retained ceilings while protection is Latched; keepers cannot relax them." and "Tight limits may prevent execution until conditions improve or the owner amends them."
  • DEPLOYMENT.md:419-421, guidance for keeper operators: "A conservative worker retries expiry failures only after confirming the account has no pending orders, queue capacity is available, and valid execution data is obtainable. Investigate planner, constraint, or other persistent failures before retrying; do not continuously queue the same failing attempt." This is practice for honest keepers. The contract does not enforce it, and anyone can call the retry.
  • The team test test_ProtectionCloseLimits_OnlyOwnerCanAmendLatchedLimitsForNextRetry (test/perps/spec/trader/PositionProtection.t.sol:986-996) runs that order: the owner amends, a third party retries, and the owner's second amend then reverts.

Impact Details

Selected impact: Temporary freezing of funds for at least 24 hours.

Setup. The PoC deploys the production contracts of packages/perps/src the way the release script does, with release parameters. Junior LPs deposit 11,500,000 USDG and Senior LPs 39,990,000 USDG, and six background traders hold positions. The victim, an EOA, opens a LONG of 10,000,000 USDG notional at 10x (1,000,000 USDG margin, plus 100,000 USDG free collateral). It protects the LONG with a stop-loss at basket 1.0100 and a 5 bp stop-limit: maxExecutionNotionalAssets is the notional at 1.0105, set from the trader's close policy as CANONICAL_ENTRYPOINTS.md:121-125 instructs. In the PoC's authored price path, at a US data release the basket gaps 30 bp, from 1.0095 to 1.0125, in one tick, then trends to 1.0170 without returning under 1.0105. Every attempt fails on the ceiling.

Results (unmodified code, Forge 1.5.1, 9 of 9 tests pass). Costs are at 0.02 gwei and USD 1,837.76 per ETH (measured 2026-11-14). The figure in brackets is at the 0.01 gwei floor. The PoC asserts frozen margin / cost >= 100 in A, B and C.

A: keeper present, attacker back-runs B: attacker executes and retries atomically C: weekend, keeper present
Lock, first failure to the owner's first successful amend 86,400 s (24 h) 86,400 s (24 h) 205,200 s (57 h, Fri 13:30:01 to Sun 22:30:01 UTC)
Attacker transactions 86,400 retries 86,400 execute + retry 205,200 retries
Owner amends sent after them / reverted ProtectionNotLatched 86,400 / 86,400 86,400 / 86,400 205,200 / 205,200
Transaction boundaries checked 259,199 172,800, each Triggered with one pending order 615,599
Attacker cost USD 2,481.74 (1,240.87) USD 7,475.71 (3,737.85) USD 5,894.14 (2,947.07)
Frozen position margin at the end of the lock USD 974,045.71 USD 974,045.71 USD 972,782.72
Frozen / cost 392 (784) 130 (260) 165 (330)
  • Withdrawals during the lock (executed in A, B, C and a 10-minute test): the clearinghouse balance is 1,084,628.540764 USDG and the locked buckets total 984,628.940764 USDG. withdraw of the position margin (974,629.042503 USDG) and withdraw(free + 1) both revert MarginClearinghouse__InsufficientFreeEquity. Only the free balance, 99,999.6 USDG, can be withdrawn.
  • The attacker holds the lock. When it stops, the owner's very next amend succeeds, the close fills and the owner withdraws its whole balance.
  • Without the attacker (control), the owner amends in its next transaction and the close fills 1 s after the first failure, at basket 1.01250016. The owner's custody goes from 1,084,628.540764 USDG at the first failure to 1,026,969.584688 USDG, a loss of 57,658.96 USDG. After the 24 h lock the exit is at 1.01700022 and custody is 981,919.525152 USDG, a loss of 102,709.02 USDG. The extra 45,050.06 USDG is specific to this price path.
  • The weekend. C holds through the FAD window before the close (1,800 executions), the 48 h FX closure (172,800 keeper executions with no Pyth payload) and the Sunday reopen. Against a keeper that executes in every block while the market is closed, C costs USD 20,784.61 (ratio 46).
  • Busy queue. Other traders' orders ahead of the attempt do not help the owner. executeOrderBatch lets one attacker transaction execute them, then the attempt, then retry: 10 batches, 27 other orders executed, 10 of 10 amends reverted.
  • Keeper cost. In A the keeper executes every attempt the attacker queues: 86,400 executions failed and relatched, each using up to 918,665 metered gas.
  • B's assumptions. B's cost includes two assumptions stated in the PoC header: a real six-feed Pyth payload of at most 4,400 bytes, and at most 500,000 extra gas for real Pyth verification. The Pyth fee is priced at MockPyth's 1 wei. Without the verification allowance B uses 1,854,075 gas per transaction. A and C carry no Pyth payload.

Limits. The lock lasts only while the market stays beyond the victim's ceiling and the attacker keeps paying. In test_lockEndsWhenBasketReturnsInsideCeiling, once the basket returns to 1.0104, inside the 1.0105 ceiling, the keeper's next execution fills the attempt the attacker queued, 600 s after the first failure, and the attacker's next retry reverts OrderRouter__ProtectionNotFound.

The attack needs its transactions ordered first: in A and C the attacker's retry must land between the keeper's failed execution and the owner's next transaction, and in B the attacker's execution must come before any other execution of the attempt. Arbitrum One orders transactions by priority fee within 125 ms rounds, so against an owner who pays a priority fee the attacker must out-bid it on every transaction. The PoC sets the order by construction and prices every transaction at the base fee, with no priority fee.

An owner that executes the attempt and amends in one transaction escapes (test_batchingOwnerWinsOneRace_escapes: closed 4 s after the first failure). An owner using the documented single-call amend does not, even after winning the execution race, when the attacker's retry lands before its amend (test_eoaOwnerWinsExecutionRace_attackerBackruns_amendStillReverts: 10 of 10 amends reverted).

Protections created in the Plether web app sign unlimited ceilings. The victims are traders who set a finite ceiling, as CANONICAL_ENTRYPOINTS.md:121-125 instructs: "Set the limits from the trader's intended close policy; integrations must not assume an implicit unlimited default."

Known issues.

  • The known issue "AI scan findings (October 15, 2026)" includes "Protection trigger bounty is paid before a zero-bounty close is executed" (audits/scan-plether-fi-plether-core-d4541b49.md:542). Its cause is a trigger caller who collects the trigger bounty and abandons the close, and its end state (a triggered protection cannot be cancelled) is the design rule this report leaves unchanged. Here, the attacker re-queues every failed close to keep the owner's amend out of reach, an entry point added after the scan by the MED-9 fix.
  • SECURITY.md "Router and keeper limitations" (known issue #6) records that users cannot cancel queued intents and that protection liveness depends on keepers appending retries, which covers missing retries. This report is about hostile retries. The fix below leaves the permissionless retry, the irreversible trigger and the cancellation rules unchanged.

Recommendation

Let the owner amend while an attempt is live. The amended ceilings then apply from the next attempt:

Diff
--- a/packages/perps/src/PositionProtectionBook.sol
+++ b/packages/perps/src/PositionProtectionBook.sol
@@ -317,12 +317,12 @@
         PositionProtectionTypes.CloseFinancialLimits calldata limits
     ) external nonReentrant {
         StoredProtection storage protection = _ownedActiveProtection(protectionId, msg.sender);
-        if (protection.status != PositionProtectionTypes.PositionProtectionStatus.Latched) {
+        if (
+            protection.status != PositionProtectionTypes.PositionProtectionStatus.Latched
+                && protection.status != PositionProtectionTypes.PositionProtectionStatus.Triggered
+        ) {
             revert OrderRouter__ProtectionNotLatched();
         }
-        if (IPositionProtectionRouterHost(ROUTER).pendingOrderCounts(msg.sender) != 0) {
-            revert OrderRouter__PendingOrdersExist();
-        }
         _setCloseLimits(protection, limits);
         _emitCloseLimitsUpdated(protection);
     }

The owner check stays. A live attempt keeps the ceilings it was committed with, because they are copied into its request at commit (router/OrderLiquidationBatchLogic.sol:674-677). "A live child cannot be changed" (IPositionProtectionActions.sol:33) stays true.

With the diff applied, in every test that prints it, the owner's first amend lands 0 s after the first failure and the position closes 2 s after it. All seven attack tests fail: six at their lock assertion (for example A: no owner amend succeeded while the attacker was active: 2 != 0), and the busy-queue test with OrderRouter__ProtectionNotFound(), because the amended attempt fills inside the attacker's batch. The control and the batching-owner tests pass.

In the team's test/perps/spec/trader/PositionProtection.t.sol, 104 of 104 tests pass on unmodified code and 103 of 104 under the fix. The one failure is test_ProtectionCloseLimits_OnlyOwnerCanAmendLatchedLimitsForNextRetry, at its expectation that the amend reverts while a retried attempt is live (:994-996), which is the behaviour the fix changes. That expectation would be updated, together with CANONICAL_ENTRYPOINTS.md:145-147 ("when the account has no pending Router order"), IPositionProtectionActions.sol:32 and packages/perps-aa-client/README.md:204-205.

Proof of Concept: steps, tests, expected output and notes

Steps

  1. Junior LPs deposit 11,500,000 USDG and Senior LPs 39,990,000 USDG, and six background traders open positions, all through the public entry points.
  2. Mon 2026-11-09 13:00 UTC: the victim, an EOA, opens a LONG of 10,000,000 USDG notional at 10x (1,000,000 USDG margin, plus 100,000 USDG free collateral) at basket 1.0060. It creates a stop-loss at 1.0100 with maxExecutionNotionalAssets set to the notional at 1.0105 (a 5 bp stop-limit).
  3. Tue 13:30:00 UTC: the basket gaps 30 bp, from 1.0095 to 1.0125, and a keeper triggers the stop. The basket then trends to 1.0170 without returning under 1.0105, so every close attempt fails with ConstraintViolation and relatches.
  4. The attacker runs the cycle. In A and C a keeper executes each attempt at the earliest moment the code allows, and the attacker sends retryPositionProtectionClose in the next block. In B the attacker's contract executes each attempt itself and retries in the same transaction.
  5. After every attacker transaction, the owner sends amendLatchedPositionProtectionCloseLimits, and it reverts OrderRouter__ProtectionNotLatched. The protection's status and the account's pending-order count are asserted at every transaction boundary.
  6. At the end of the lock, the test executes the owner's withdrawals and asserts frozen margin / attacker cost >= 100. It then stops the attacker: the owner's next amend succeeds, the close fills and the owner withdraws its whole balance.

Timing follows the code. Outside a frozen market, an order executes only in a block after its commit block, on a price published after its commit time (OrderRouterExecutionSidecar.sol:447-452, PletherOracle.sol:610-614). With four 250 ms blocks per second, one cycle takes one second.

What each test proves

  • test_A_keeperPresent_attackerBackruns_24h: with an honest keeper executing every attempt, the attacker's bare retry after each failure keeps the owner's amend reverting for 24 h (86,400 of 86,400). The margin stays locked, and the owner gets out only after the attacker stops.
  • test_B_atomic_noWindow_24h: when the attacker executes and retries in one transaction, the amend's precondition holds at none of the 172,800 transaction boundaries over 24 h.
  • test_C_weekend_keeperPresent_attackerBackruns_57h: as A, from Friday 13:30:01 UTC through the FX closure and the Sunday reopen, 57 h.
  • test_fundsFrozen_withdrawalsDuringLock: during a lock, withdrawing the position margin, or one unit more than the free balance, reverts MarginClearinghouse__InsufficientFreeEquity. Only the free balance pays out.
  • test_control_noAttacker_ownerAmendsAndExits: without the attacker, the owner amends in its next transaction and the close fills 1 s after the first failure.
  • test_eoaOwnerWinsExecutionRace_attackerBackruns_amendStillReverts: an EOA owner that executes its own attempt first still cannot amend when the attacker's retry lands before its next transaction, an order the test sets by construction (10 of 10).
  • test_busyQueue_attackerBatchesThroughOtherOrders: other traders' orders ahead of the attempt do not stop the attacker. executeOrderBatch executes them, then the attempt, then retries.
  • test_lockEndsWhenBasketReturnsInsideCeiling: the bound. When the basket returns inside the ceiling, the keeper fills the attempt the attacker queued, and the attacker's next retry reverts.
  • test_batchingOwnerWinsOneRace_escapes: the limitation. An owner that executes, amends and retries in one transaction escapes.

Output (unmodified code, Forge 1.5.1; selected lines, verbatim)

Text
Ran 3 tests for test/perps/poc/ProtectionRetryLock.t.sol:ProtectionRetryLockAtomicTest
[PASS] test_B_atomic_noWindow_24h() (gas: 3780042)
Logs:
  B: owner amends that succeeded while the attacker was active 0
  B: clearinghouse balance (6 dec) 1084628540764
  B: position margin (6 dec) 974629042503
  B: total locked buckets (6 dec) 984628940764
  B: free balance above the locked buckets (6 dec) 99999600000
  B: withdraw(position margin) reverted MarginClearinghouse__InsufficientFreeEquity
  B: withdraw(free + 1) reverted; withdraw(free) paid out (6 dec) 99999600000
  B: attacker execute + retry transactions 86400
  B: owner amends sent after them / reverted ProtectionNotLatched 86400 86400
  B: transaction boundaries checked, each Triggered with one pending order 172800
  B: attacker cost, US cents at 0.02 gwei 747571
  B: frozen position margin, US cents 97404571
  B: frozen / cost at 0.02 gwei (integer) 130
  B: owner's first successful amend, seconds after the first failure 86400

[PASS] test_busyQueue_attackerBatchesThroughOtherOrders() (gas: 56922236)
Logs:
  BUSY QUEUE: owner amends that succeeded while the attacker was active 0
  BUSY QUEUE: attacker batch transactions / other traders' orders they executed 10 27
  BUSY QUEUE: owner amends that reverted ProtectionNotLatched 10

[PASS] test_eoaOwnerWinsExecutionRace_attackerBackruns_amendStillReverts() (gas: 11194797)
Logs:
  EOA RACE: owner amends that succeeded while the attacker was active 0
  EOA RACE: execution races won by the owner / amends that reverted 10 10

Suite result: ok. 3 passed; 0 failed; 0 skipped; finished in 138.39s (138.35s CPU time)

Ran 1 test for test/perps/poc/ProtectionRetryLock.t.sol:ProtectionRetryLockBasketReturnTest
[PASS] test_lockEndsWhenBasketReturnsInsideCeiling() (gas: 717593921)
Logs:
  RETURN: owner amends that succeeded while the attacker was active 0
  RETURN: attacker back-runs / owner amends that reverted ProtectionNotLatched 600 600
  RETURN: the attacker's next retry reverted OrderRouter__ProtectionNotFound
  RETURN: basket from Tue 13:40:01 UTC (8 dec) 101040000
  RETURN: seconds from the first failure to the close 600
  RETURN: fill price of the close (8 dec) 101040415

Ran 1 test for test/perps/poc/ProtectionRetryLock.t.sol:ProtectionRetryLockBatchingOwnerTest
[PASS] test_batchingOwnerWinsOneRace_escapes() (gas: 5698643)
Logs:
  BATCHING OWNER: attacker cycles before the owner's batch 3
  BATCHING OWNER: closed, seconds after the first failure 4

Ran 3 tests for test/perps/poc/ProtectionRetryLock.t.sol:ProtectionRetryLockKeeperPresentTest
[PASS] test_A_keeperPresent_attackerBackruns_24h() (gas: 3860704)
Logs:
  A: owner amends that succeeded while the attacker was active 0
  BY DESIGN for any triggered protection: cancel, cancel-and-close, close order each revert (3 of 3)
  A: clearinghouse balance (6 dec) 1084628540764
  A: position margin (6 dec) 974629042503
  A: total locked buckets (6 dec) 984628940764
  A: free balance above the locked buckets (6 dec) 99999600000
  A: withdraw(position margin) reverted MarginClearinghouse__InsufficientFreeEquity
  A: withdraw(free + 1) reverted; withdraw(free) paid out (6 dec) 99999600000
  A: attacker back-run retries 86400
  A: owner amends sent after them / reverted ProtectionNotLatched 86400 86400
  A: keeper executions that failed and relatched 86400
  A: transaction boundaries checked 259199
  A: metered execution gas, keeper execution, max (the keeper's cost) 918665
  A: attacker cost, US cents at 0.02 gwei 248174
  A: attacker cost, US cents at 0.01 gwei 124087
  A: frozen position margin, US cents 97404571
  A: frozen / cost at 0.02 gwei (integer) 392
  A: owner's first successful amend, seconds after the first failure 86400
  A: exit basket after the lock (8 dec) 101700022
  A: owner's USDG custody when the lock started / after the exit (6 dec) 1084628540764 981919525152

[PASS] test_control_noAttacker_ownerAmendsAndExits() (gas: 1838361)
Logs:
  CONTROL: seconds from the first failure to the fill 1
  CONTROL: exit basket (8 dec) 101250016
  CONTROL: after the exit the owner withdrew its whole clearinghouse balance (6 dec) 1026969584688
  CONTROL: owner's USDG custody when the lock started / after the exit (6 dec) 1084628540764 1026969584688

[PASS] test_fundsFrozen_withdrawalsDuringLock() (gas: 719982359)
Logs:
  FUNDS: owner amends that succeeded while the attacker was active 0
  FUNDS: clearinghouse balance (6 dec) 1084628540764
  FUNDS: position margin (6 dec) 974629042503
  FUNDS: total locked buckets (6 dec) 984628940764
  FUNDS: free balance above the locked buckets (6 dec) 99999600000
  FUNDS: withdraw(position margin) reverted MarginClearinghouse__InsufficientFreeEquity
  FUNDS: withdraw(free + 1) reverted; withdraw(free) paid out (6 dec) 99999600000
  FUNDS: owner's first successful amend, seconds after the first failure 600

Suite result: ok. 3 passed; 0 failed; 0 skipped; finished in 144.89s (144.86s CPU time)

Ran 1 test for test/perps/poc/ProtectionRetryLock.t.sol:ProtectionRetryLockWeekendTest
[PASS] test_C_weekend_keeperPresent_attackerBackruns_57h() (gas: 3811165)
Logs:
  C: owner amends that succeeded while the attacker was active 0
  C: clearinghouse balance (6 dec) 1084628540764
  C: position margin (6 dec) 974629042503
  C: total locked buckets (6 dec) 984628940764
  C: free balance above the locked buckets (6 dec) 99999600000
  C: withdraw(position margin) reverted MarginClearinghouse__InsufficientFreeEquity
  C: withdraw(free + 1) reverted; withdraw(free) paid out (6 dec) 99999600000
  C: attacker back-run retries 205200
  C: owner amends sent after them / reverted ProtectionNotLatched 205200 205200
  C: keeper executions that failed and relatched 205200
  C: of which in the frozen market (no Pyth payload, Engine mark replay) 172800
  C: lock executions by regime: live Friday / FAD 28798 1800
  C: lock executions by regime: closed / after the reopen 172800 1801
  C: transaction boundaries checked 615599
  C: attacker cost, US cents at 0.02 gwei 589414
  C: attacker cost, US cents at 0.01 gwei 294707
  C: frozen position margin, US cents 97278272
  C: frozen / cost at 0.02 gwei (integer) 165
  C, keeper in every block while frozen: attacker cost, US cents at 0.02 gwei 2078461
  C, keeper in every block while frozen: frozen / cost at 0.02 gwei (integer) 46
  C: owner's first successful amend, seconds after the first failure 205200
  C: seconds from the first failure (Fri 13:30:01 UTC) to the owner's first successful amend 205200

Suite result: ok. 1 passed; 0 failed; 0 skipped; finished in 298.06s (298.00s CPU time)

Ran 5 test suites in 582.40s (582.25s CPU time): 9 tests passed, 0 failed, 0 skipped (9 total tests)

Result with the recommended fix applied

Bash
git apply fix.diff   # fix.diff = the diff in the Recommendation section, saved at the repository root
forge test --root packages/perps --match-path test/perps/poc/ProtectionRetryLock.t.sol -vv --threads 1

The owner's first amend lands 0 s after the first failure and the position closes 2 s after it. All seven attack tests fail, and the control and the batching-owner tests pass (selected lines, verbatim):

Text
[FAIL: B: no owner amend succeeded while the attacker was active: 2 != 0] test_B_atomic_noWindow_24h() (gas: 20283)
  B: owner amends that succeeded while the attacker was active 2
  B: first successful owner amend, seconds after the first failure 0
  B: position closed, seconds after the first failure 2
  B: attacker transactions until then 3
[FAIL: OrderRouter__ProtectionNotFound()] test_busyQueue_attackerBatchesThroughOtherOrders() (gas: 20525893)
[FAIL: race: no owner amend succeeded: 2 != 0] test_eoaOwnerWinsExecutionRace_attackerBackruns_amendStillReverts() (gas: 4519805)
[FAIL: RETURN: no owner amend succeeded while the attacker was active: 2 != 0] test_lockEndsWhenBasketReturnsInsideCeiling() (gas: 3961967)
[PASS] test_batchingOwnerWinsOneRace_escapes() (gas: 5697458)
[FAIL: A: no owner amend succeeded while the attacker was active: 2 != 0] test_A_keeperPresent_attackerBackruns_24h() (gas: 20112)
  A: owner amends that succeeded while the attacker was active 2
  A: first successful owner amend, seconds after the first failure 0
  A: position closed, seconds after the first failure 2
  A: attacker transactions until then 2
[PASS] test_control_noAttacker_ownerAmendsAndExits() (gas: 1837176)
[FAIL: FUNDS: no owner amend succeeded while the attacker was active: 2 != 0] test_fundsFrozen_withdrawalsDuringLock() (gas: 3965998)
[FAIL: C: no owner amend succeeded while the attacker was active: 2 != 0] test_C_weekend_keeperPresent_attackerBackruns_57h() (gas: 19826)

Ran 5 test suites in 261.82ms (260.41ms CPU time): 2 tests passed, 7 failed, 0 skipped (9 total tests)

Notes on the PoC file: fixture, scenario, cost model, cheat codes and assumptions

Text
=====================================================================================================================
Anyone can re-queue a failed protection close before the owner's amend can land: the owner's only remedy for a
gapped stop-limit is kept unreachable, and the position margin stays frozen, for as long as the attacker repeats it.
=====================================================================================================================

RUN (from the repository root, Forge 1.5.1; peak memory: A or B alone ~1.2 GB, C alone ~2.2 GB, the file ~3.1 GB):
  forge test --root package

The original report as published on Immunefi, by itsactuallyomar. 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

Likely the retry function lacks an owner check while sharing the same Latched-with-no-pending-order precondition as the owner-only amend, letting anyone re-trigger the protection before the owner acts.

Impact

The owner's amend is blocked and the position's margin is frozen for at least 24 hours (57 hours across a weekend) while the market stays beyond the ceiling and the attacker keeps paying; the lock ends once the basket returns inside the ceiling or the attacker stops.

What the attacker needed

Victim sets a finite close ceiling; market gaps past the ceiling; attacker out-bids owner on ordering; attacker pays gas continuously

The fix

The amend should be allowed while an attempt is live (Triggered as well as Latched) and the pending-order check removed, so amended ceilings apply from the next attempt.

How it was found

  1. The victim opens a leveraged LONG and sets a stop-loss with a finite price ceiling.
  2. The market gaps past the ceiling, so the keeper's close attempt fails and the protection becomes Latched.
  3. The attacker sends retryPositionProtectionClose before the owner's amend, re-queuing the failing close and setting the protection to Triggered.
  4. The owner's amend then reverts with ProtectionNotLatched, and the cycle repeats while the market stays past the ceiling.
  5. The position stays open and its margin cannot be withdrawn until the attacker stops.

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 stop-loss, but when the market jumped past their chosen price the close failed and the protection entered a waiting state. In that state only the owner can adjust the price limits, and only if no order is pending. Because a public retry function can queue a new order first, an attacker can keep the owner from ever adjusting the limits, so the position stays open and its margin cannot be withdrawn.

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 by itsactuallyomar

View all

1 more disclosed report, best first.

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.