Skip to content
Business logic Audit finding Advanced

Permissionless retry of unchanged failing closeLimits eliminates the sole amendLatchedPositionProtectionCloseLimits window, keeping margin unclosable

A permissionless retry function lets any third party flip a latched position-protection record back to triggered with the same unfulfillable close limits, so the owner never gets a chance to widen those limits. An attacker can repeat this in a loop, keeping the trader's position and collateral margin frozen for over 24 hours while carry fees keep accruing.

dikanevn Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

#98965 [SC-High] Permissionless retry of unchanged failing closeLimits eliminates the sole amendLatchedPositionProtectionCloseLimits window, keeping margin unclosable

Submitted on Nov 11th 2026 at 07:47:30 UTC by @dikanevn for Audit Competition | Plether

Description

1. Summary

  • Protocol: Plether
  • Repository: https://github.com/immunefi-team/audit-comp-plether (commit a82d4fefb02768e5b3bddcc97dee371eee24fea8)
  • Asset: packages/perps/src/PositionProtectionBook.sol, packages/perps/src/router/OrderLiquidationBatchLogic.sol
  • Severity: High
  • Impact: High — Temporary freezing of funds for at least 24 hours (continuous locking of trader position and collateral margin in Triggered status for over 24 hours via atomic expireOrder + retryPositionProtectionClose loops, with ongoing carry accrual and persistent market risk)
  • Weakness Type (CWE): CWE-840 (Business Logic Errors), CWE-754 (Improper Check for Unusual or Exceptional Conditions)
  • Vulnerable Code Location: packages/perps/src/PositionProtectionBook.sol:382-406 (retryPositionProtectionClose)

1.1. Vulnerability Details

In the position protection subsystem (PositionProtectionBook.sol), once a take-profit or stop-loss trigger fires (status == Triggered), a deferred full-close order is enqueued with user-defined financial constraints closeLimits (maxExecutionNotionalAssets, maxGrossAccountDebitAssets, maxActionChargeAssets, maxExplicitFeesAssets). If the execution attempt fails (e.g., due to price slippage, VPI movements, or accumulated carry which grows monotonically and cannot revert on its own, yielding TerminalReason.ConstraintViolation) or expires due to timeout, the protection transitions into the Latched status, retaining the exact same closeLimits.

To allow traders to escape a deadlock caused by unexecutable limits, the MED-9 fix introduced amendLatchedPositionProtectionCloseLimits, which allows only the position owner to widen closeLimits provided that status == Latched and pendingOrderCounts(msg.sender) == 0. The protocol's entire recovery model (as reflected in SECURITY.md:547–552, 1356–1359) assumes passive idle liveness — namely, that in the absence of keeper execution, the position will linger in Latched, the owner will comfortably update their limits, and an operator alert triggered by an extended Latched duration will wake up a keeper.

In reality, the opposite occurs: retryPositionProtectionClose remains completely permissionless (no msg.sender == protection.account check, no check of the previous failure reason, and no check verifying whether closeLimits were actually amended). Any arbitrary third-party address can instantly transition the protection from Latched back to Triggered, enqueuing a new zero-bounty order in OrderRouter with the stale, unfulfillable closeLimits for the full maxExecutionWindowSeconds window (default 60 seconds, up to 1 hours). In doing so, an attacker completely eliminates the sole Latched window (as well as preventing operator alerts on a "long Latched" state).

While the protection remains in Triggered or Latched status, the position owner is completely locked out of managing their capital:

  • They cannot update limits via amendLatchedPositionProtectionCloseLimits (reverts with OrderRouter__ProtectionNotLatched()).
  • They cannot cancel the protection via cancelPositionProtection / cancelPositionProtectionAndCommitClose or replace it via replacePositionProtection (reverts with OrderRouter__ProtectionNotArmed()).
  • They cannot submit a standard manual close order via OrderRouter.commitOrder (reverts with OrderRouter__ProtectionActive()).
  • They cannot close the position directly through CfdEngine — their collateral margin remains trapped inside the position.

On Arbitrum, an attacker asserts continuous control using a multicall contract: either waiting for the default 60-second executionDeadline to elapse (a zero-bounty order offers no incentive for third-party keepers to execute early) and atomically calling OrderRouter.expireOrder(linkedOrderId) (Triggered -> Latched) immediately followed by PositionProtectionBook.retryPositionProtectionClose(protectionId) (Latched -> Triggered), or through an executeOrder + retryPositionProtectionClose sequence within a single transaction (since a failure due to ConstraintViolation does not revert execution, but transitions the status to Latched). Consequently, the Latched state collapses within a single transaction without existing for a single block or millisecond. As a result, the trader's position and collateral margin remain continuously frozen for more than 24 hours: the trader is completely stripped of the ability to close the trade or salvage their remaining equity, while the position remains subject to market risk and monotonic carry fee erosion.


2. Root Cause Analysis

2.1. Protection Lifecycle After Trigger and Status Deadlock

Following TP/SL activation (triggerPositionProtection -> activate), the StoredProtection record transitions into Triggered, and a child close order is submitted to OrderRouter with executionBountyAssets = 0. When the child order fails (e.g., with ConstraintViolation or Expired), OrderRouter._settleTerminalBounty (line 328) or expireMismatchedOrderFromSidecar (line 226) invokes PositionProtectionBook.handleFailedProtectionAttempt (PositionProtectionBook.sol:637-675):

Solidity
        delete _attemptProtectionIds[orderId];
        retained = _positionMatches(protection);
        emit PositionProtectionCloseAttemptFailed(protectionId, account, orderId, reason, retained);
        if (retained) {
            protection.status = PositionProtectionTypes.PositionProtectionStatus.Latched;
            return true;
        }

While the protection remains active (_activeProtectionIds[account] == protectionId, which holds true for both Triggered and Latched), the trader is entirely locked out of managing their position:

  1. Cancellation and replacement are blocked (PositionProtectionBook.sol:270-277, 341-348, 408-419):
Solidity
if (
    status != PositionProtectionTypes.PositionProtectionStatus.PendingOpen
        && status != PositionProtectionTypes.PositionProtectionStatus.Armed
) {
    revert OrderRouter__ProtectionNotArmed();
}

(cancelPositionProtectionAndCommitClose strictly requires Armed).

  1. Manual closing through OrderRouter is blocked (OrderLiquidationBatchLogic.sol:131-136, 313-315):
Solidity
if (enforceProtectionLock && host.positionProtectionBook().activePositionProtectionId(account) != 0) {
    revert OrderRouter__ProtectionActive();
}

During user-initiated commitOrder calls, enforceProtectionLock is unconditionally set to true.

  1. Updating closeLimits is strictly restricted to the Latched status (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 protocol's only designated exit path when constraints are violated is to await the Latched status and widen limits via amendLatchedPositionProtectionCloseLimits.

2.2. Lack of closeLimits Precondition in retryPositionProtectionClose

Although permissionless retrying in retryPositionProtectionClose (PositionProtectionBook.sol:382-406) was intended to preserve liveness, the function retrieves _activeProtection(protectionId) without enforcing any precondition verifying that closeLimits have been amended after an execution/constraint failure (or following an expired retry):

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();
        }

        if (protection.linkedOrderId == 0 || _attemptProtectionIds[protection.linkedOrderId] != 0) {
            revert PositionProtectionBook__InvalidLinkedOrder();
        }
        uint64 expectedOrderId = router.nextCommitId();
        linkedOrderId = IPositionProtectionCloseAttemptHost(ROUTER)
            .commitProtectionCloseAttempt(protectionId, protection.account, protection.side, protection.size);
        if (linkedOrderId != expectedOrderId) {
            revert PositionProtectionBook__InvalidHostResponse();
        }
        _recordCloseAttempt(protection, linkedOrderId);
    }

Subsequently, OrderLiquidationBatchLogic.commitProtectionCloseAttempt (OrderLiquidationBatchLogic.sol:186-211) builds the request via _protectionCloseRequest (OrderLiquidationBatchLogic.sol:657-680):

Solidity
        PositionProtectionTypes.CloseFinancialLimits memory limits =
            host.positionProtectionBook().closeFinancialLimits(protectionId);
        ...
        request.bounds.submitBy = uint64(block.timestamp);
        request.bounds.executionWindowSeconds = uint32(host.maxExecutionWindowSeconds());
        ...
        request.bounds.maxExecutionBountyAssets = 0;
        request.bounds.maxExecutionNotionalAssets = limits.maxExecutionNotionalAssets;
        request.bounds.maxGrossAccountDebitAssets = limits.maxGrossAccountDebitAssets;
        request.bounds.maxActionChargeAssets = limits.maxActionChargeAssets;
        request.bounds.maxExplicitFeesAssets = limits.maxExplicitFeesAssets;

And _recordCloseAttempt (PositionProtectionBook.sol:564-578) immediately transitions protection.status back to Triggered with a newly generated linkedOrderId.

Thus, any address can:

  • Repeatedly enqueue a demonstrably unexecutable order with the stale, failing closeLimits (even after previous failures with ConstraintViolation, ExecutionModeDisallowed, or PlannerRejected);
  • Incur zero bounty expense (maxExecutionBountyAssets = 0) while switching the status Latched -> Triggered and locking out amendLatchedPositionProtectionCloseLimits for another maxExecutionWindowSeconds duration (60 seconds by default in OrderExecutionOrchestrator.sol:11, up to 1 hours in OrderRouterAdmin.sol:31).

2.3. Guaranteed Exploitability on Arbitrum (Without Public Mempool)

On Arbitrum One, the sequencer processes transactions on a First-Come, First-Served (FCFS) basis without a public mempool, meaning traditional mempool frontrunning is neither needed nor utilized. Instead, an attacker leverages three deterministic interception vectors:

  • Scenario 1. Atomic expireOrder + retryPositionProtectionClose in a single transaction:
    The attacker's contract monitors executionDeadline of the active linkedOrderId. Because the child close order carries zero keeper incentive (maxExecutionBountyAssets = 0) and is guaranteed to fail limits, external keepers have zero economic motive to incur Pyth oracle gas costs. The order expires cleanly upon timeout (default 60 seconds), and the attacker atomically executes the following within a single transaction:
    • OrderRouter.expireOrder(linkedOrderId) -> in OrderRecoverySidecar.sol:49-64, the deadline check passes without invoking the oracle, the order is cleared (pendingOrderCounts(account) == 0), and handleFailedProtectionAttempt transitions the protection to Latched;
    • PositionProtectionBook.retryPositionProtectionClose(protectionId) -> immediately flips the protection back to Triggered with a new linkedOrderId and a fresh maxExecutionWindowSeconds window.
      Between these two calls, there is zero block or millisecond gap — an EOA owner cannot physically interleave amendLatchedPositionProtectionCloseLimits.
  • Scenario 2. Atomic window closing by keeper-bot via executeOrder + retryPositionProtectionClose:
    If the attacker's bot acts as the keeper during the initial execution attempt, OrderRouter.executeOrder upon a closeLimits breach does not revert the transaction; it gracefully returns LifecycleStatus.Failed with TerminalReason.ConstraintViolation (OrderLifecycleBook.sol:335-347) and immediately calls handleFailedProtectionAttempt, setting the status to Latched. The bot's multicall contract immediately invokes retryPositionProtectionClose as the very next call, eliminating the Latched window right at step one.
  • Scenario 3. Reaction to third-party keepers:
    Even if an independent keeper executes executeOrder in isolation, a bot monitors the PositionProtectionCloseAttemptFailed event and submits retryPositionProtectionClose within sub-seconds via FCFS, whereas an ordinary user interacting through a web wallet interface cannot react and sign a transaction in time. All subsequent 1,440 cycles are then locked atomically via Scenario 1.

Why the owner cannot compete in an FCFS race at executionDeadline:

  • Standard EOA traders cannot use an external multicall contract:
    Ordinary users operate via standard EOAs and frontends. Neither OrderRouter nor PositionProtectionBook exposes an atomic expireAndAmend(...) helper or delegate/operator authorization mechanism. Furthermore, amendLatchedPositionProtectionCloseLimits (PositionProtectionBook.sol:319, 983-991) strictly enforces msg.sender == protection.account via _ownedActiveProtection(protectionId, msg.sender) (reverting with OrderRouter__Unauthorized() otherwise). Consequently, a third-party helper contract invoked by Alice's EOA cannot amend her closeLimits: to compete with the attacker at executionDeadline, a retail trader would have to configure EIP-7702 delegation or trade from a custom Smart Account mid-crisis, authoring custom batch logic for expireOrder -> amendLatchedPositionProtectionCloseLimits -> retryPositionProtectionClose.
  • Even with Smart Accounts / EIP-7702, the attacker maintains asymmetric advantage:
    The attacker initiates each cycle and controls the exact timing. They can broadcast transactions to the sequencer with fine-grained timing precision (Arbitrum blocks arrive every ~250 ms) across multiple RPC endpoints. If the attacker's transaction arrives first at block T >= executionDeadline + 1, the owner's transaction reverts, and the window snaps shut for the full maxExecutionWindowSeconds.

2.4. Developer Blind Spot (MED-9 Fix Context and Tests)

The closeLimits and amendLatchedPositionProtectionCloseLimits features were introduced as a remediation for MED-9 in Cecuro's audit (audits/plether-ai-audit-report-2026-10-26.pdf, page 27), where the protocol team documented:

"Only the owner may amend the retained ceilings while protection is Latched; keepers cannot relax them... Tight limits may prevent execution until conditions improve or the owner amends them."

However, in the official unit test packages/perps/test/perps/spec/trader/PositionProtection.t.sol:954-1005 (test_ProtectionCloseLimits_OnlyOwnerCanAmendLatchedLimitsForNextRetry), the developers only tested an uncontested sequence: protection transitions to Latched, ALICE calls amendLatchedPositionProtectionCloseLimits without interference, and only then does CAROL call retryPositionProtectionClose. The adversarial scenario, where CAROL (or an automated bot) repeatedly preempts Latched via retryPositionProtectionClose and perpetually starves ALICE from calling amendLatchedPositionProtectionCloseLimits, was completely unaddressed.


3. Practical Impact

3.1. Position and Collateral Margin Freezing (Temporary freezing of funds)

When closeLimits become unfulfillable (e.g., due to market gaps passing the stop-loss, shifts in VPI, or cumulative carry exceeding the allowance), the trader's only legitimate escape route is amending their limits via amendLatchedPositionProtectionCloseLimits. By suppressing this call, an attacker completely deprives the trader of the ability to close the position (either through protection or manually via OrderRouter.commitOrder) and reclaim their collateral margin.

Crucially, this fund freeze does not rely on speculative market conditions:

  • If ConstraintViolation is triggered by accrued carry (effects.carryCollectedAssets > maxActionChargeAssets or maxGrossAccountDebitAssets in OrderLifecycleBook.sol:335-347), unlike market price, carry in CfdEnginePlanLib._pendingCarryAssets (CfdEnginePlanLib.sol:183-197) accumulates monotonically and never decreases on its own — such a limit will never become passable without calling amendLatchedPositionProtectionCloseLimits (or until liquidation).
  • Even in a stop-loss price gap scenario, the explicit purpose of a stop-loss is to cap losses during adverse market momentum; while the market trades outside the limit and moves toward liquidation, the trader is prevented from widening slippage tolerance to rescue remaining capital.
  • Liquidation is not an alternative exit route for the locked trader: as long as the position remains solvent (netEquity >= maintenanceMargin), neither the trader nor any keeper can trigger liquidation — executeLiquidation is strictly rejected by solvency checks in the core CfdEngine. The trader remains entirely frozen out. If adverse market movement eventually drives the unclosable position into insolvency, the outcome is not margin return, but total capital loss alongside liquidation penalty deductions.

3.2. Continuous Lock for 24+ Hours and Attack Economics on Arbitrum

A single expireOrder + retryPositionProtectionClose cycle requires neither an open position, nor a capital deposit, nor Pyth oracle fee expenditure from the attacker (the oracle is not invoked during expireOrder and retryPositionProtectionClose).

Based on precise gas measurements from the Foundry PoC below (gasleft() inside ProtectionFreezeBot.expireAndRetry):

  • Function execution consumes 1,117,751 gas on cycle 1 and 1,117,766 gas in steady-state on cycle 65.
  • The full L2 transaction (including 21,000 base gas + 68 bytes calldata = 1,088 gas) equals exactly 1,139,848 L2 execution gas per transaction, or 1,641,381,120 gas across 1,440 cycles (68.93 USD total L2 execution at 0.02 gwei).
  • L1 Poster Fee: Publishing 68 bytes of calldata in an L1 blob on Arbitrum One post-EIP-4844 costs fractions of a cent per transaction (~0.10–0.20 USD across all 1,440 txs), having negligible impact on overall attack cost.

According to Arbiscan Gas Tracker, Arbitrum One network utilization is typically minimal, with an average base gas price of 0.02 gwei. The attacker's L2 execution costs under the default maxExecutionWindowSeconds = 60 s window and an ETH = 2,100 USD exchange rate are:

  • 1 cycle (61 s): 1,139,848 gas (0.0000228 ETH = 0.047 USD);
  • 1+ hour (3,965 s, 65 cycles): ~74.09M gas (0.001482 ETH = 3.11 USD);
  • 24+ hours (87,840 s = 24.4 hours, 1,440 cycles): 1,641,381,120 gas (0.032828 ETH = 68.93 USD).

Frozen User Capital vs. Attack Cost on Arbitrum:

In the PoC test fixture, the trader opens a 200,000 USD notional position with 50,000 USD collateral margin at a baseline mark price of 1.00. When the market shifts to the stop-loss price of 1.15, unrealized PnL loss (30,000 USD), opening fees, and accrued carry (~290 USD) leave 19,710.00 USD in net equity (netEquity). Over the 24-hour freeze, an additional 3.14 USD in monotonic carry accrues, reducing net equity to 19,706.86 USD:

  • Frozen User Funds: 19,706.86 USD of remaining net equity that the trader cannot close, modify, or withdraw for over 24 hours.
  • Attacker Cost for 24.4 hours (1,440 cycles): 68.93 USD in L2 execution gas (at 0.02 gwei base fee and ETH = 2,100 USD).
  • Freeze-to-Cost Ratio: 1 to 285.8 (every 1 USD spent by the attacker freezes 285.80 USD of victim equity).
  • Unavoidable Carry Leakage: Over the freeze period, 3.13 USD of carry fees accrue (3.14 USD net equity reduction), proving that the position is unclosable and that capital actively degrades even in a flat market.
  • Market Risk: As the market trends unfavorably, the trader, unable to execute their stop-loss or adjust constraints, faces total liquidation of all locked funds (19,706.86 USD).
  • During a 10x gas spike during market volatility (if L2 base fee reaches 0.20 gwei): the attacker's cost is ~0.47 USD per cycle and ~689 USD for 24 hours to lock the same 19,706.86 USD in user capital.

3.3. Monotonic carry Accrual and Inability to Salvage Remaining Equity

While the position is forcibly locked, carry accrues continuously (3.13 USD over 24.4 hours in the PoC), acting as an unavoidable parasitic drain that proves the inability to exit the trade. Concurrently, the underlying position remains exposed to full market risk: if prices deteriorate, the trader cannot widen slippage via amendLatchedPositionProtectionCloseLimits to close their trade, risking total forfeiture of remaining netEquity (~19,700 USD in the PoC).

3.4. Immunefi Classification (Plether Perps Scope)

  • Severity Level: High — matching the official Plether Impacts in Scope: High — Temporary freezing of funds for at least 24 hours, verified by a runnable Foundry PoC running 1,440 consecutive cycles (87,840 seconds = 24.4 hours) and a detailed cost-of-attack calculation on Arbitrum (68.93 USD L2 execution at 0.02 gwei, ETH = 2,100 USD).
  • Known Issues Analysis: In packages/perps/SECURITY.md (lines 547–552 and 1356–1359) and audits/scan-plether-fi-plether-core-d4541b49.md (lines 542–585), only the irreversibility of triggers, uncompensated retries, and keeper liveness dependency during Latched states are acknowledged. The reverse vector — actively suppressing the Latched state, defeating operator alerts for extended Latched positions, and permanently deadlocking amendLatchedPositionProtectionCloseLimits via permissionless retryPositionProtectionClose — is neither documented nor mitigated in the scope commit a82d4fef or any plether-core branch.

Proof of Concept

4. Proof of Concept (PoC)

The Foundry PoC below demonstrates:

  • Continuous freezing of a 200,000 USD notional / 50,000 USD initial margin position (~19,710 USD residual netEquity at trigger) for over 24 hours (1,440 consecutive cycles) after a tight maxActionChargeAssets = 102 USD limit (92 USD closing fee + 10 USD carry budget) is breached by monotonic carry accrual, measuring gas consumption across the first 65 cycles and tracking netEquity degradation;
  • Control test test_Control_AtTrigger_SameLimitsExecuteWithoutAmend, proving that at the moment of trigger, the exact same closeLimits were fully executable without amendment;
  • Control test test_Control_WithoutAttacker_OwnerCanAmendAndClose, proving that absent attacker interference, the owner cleanly widens limits in Latched and closes the position.

Note on PoC Fixture and the Binding Limit: In the test, wide caps (500,000 USD) are set for the other three constraints (maxExecutionNotionalAssets, maxGrossAccountDebitAssets, maxExplicitFeesAssets), isolating maxActionChargeAssets = 102 USD (92 USD close fee + 10 USD carry budget) as the binding constraint. The pre-trigger warp PRE_TRIGGER_WARP_SECONDS = 279_950 s (~3.24 days) is calibrated so that at trigger time, accrued carry equals 9.99 USD (actionCharge = 101.99 USD <= 102.00 USD), leaving a slack of ~0.01 USD, which expires within 50 seconds. This demonstrates the exact condition the MED-9 fix was designed to solve: a tight cap that is valid at trigger but degrades within the execution window and drops the protection into Latched.

4.1. Step-by-Step Attack Scenario

  1. Protection Creation with Realistic Limits: Trader Alice opens a position and arms TP/SL protection via PositionProtectionBook.createPositionProtection, establishing closeLimits (maxActionChargeAssets = 102 USD, covering a 92 USD close fee and a 10 USD carry budget) that are fully executable at opening.
  2. Stop-Loss Trigger and Transition to Triggered: Once the trigger price is reached, a keeper calls PositionProtectionBook.triggerPositionProtection, transitioning the protection into Triggered and enqueuing a child close order. At trigger time, accrued carry is 9.99 USD, satisfying constraints (101.99 USD <= 102.00 USD).
  3. Execution Failure via Monotonic Carry and Transition to Latched: Within the 60-second window (+50s), monotonic carry pushes total charges above the 102.00 USD ceiling. When the keeper attempts execution, it fails with TerminalReason.ConstraintViolation. PositionProtectionBook.handleFailedProtectionAttempt cleans up the order and marks the protection as Latched.
  4. Trader Lockout by Protocol Architecture: While protection is active (Triggered or Latched), the trader cannot close manually via OrderRouter.commitOrder (reverts with OrderRouter__ProtectionActive), cannot cancel via cancelPositionProtection (reverts with OrderRouter__ProtectionNotArmed), and cannot close directly in CfdEngine. The only architectural exit is waiting for Latched and calling PositionProtectionBook.amendLatchedPositionProtectionCloseLimits.
  5. Atomic Window Preemption by Attacker: The attacker's bot monitors the executionDeadline of the child order. The moment block.timestamp > executionDeadline, the attacker executes the following in a single transaction via ProtectionFreezeBot:
    • Calls OrderRouter.expireOrder(linkedOrderId), transitioning protection Triggered -> Latched;
    • Immediately calls PositionProtectionBook.retryPositionProtectionClose(protectionId).
      Because retryPositionProtectionClose is permissionless, it checks neither msg.sender == owner nor limit amendments, immediately re-enqueuing an order with the same failing limits and returning status Latched -> Triggered.
  6. Continuous 24+ Hour Freeze: Executing both calls atomically ensures that the Latched state does not exist for a single block or millisecond, physically preventing Alice's EOA from invoking amendLatchedPositionProtectionCloseLimits. Repeating this sequence every 60 seconds across 1,440 cycles costs the attacker only 68.93 USD per day on Arbitrum One, while Alice's margin remains trapped, her position cannot be closed, and her residual equity (~19,700 USD) remains exposed to market risk and monotonic carry attrition.

4.2. Runnable PoC Instructions

4.2.1. Clone Repository and Checkout Commit

Bash
git clone https://github.com/immunefi-team/audit-comp-plether.git
cd audit-comp-plether
git checkout a82d4fefb02768e5b3bddcc97dee371eee24fea8
git submodule update --init --recursive

4.2.2. Create PoC Test File

Bash
cat << 'EOF' > packages/perps/test/perps/spec/trader/PositionProtectionRetryFreezePoC.t.sol
// SPDX-License-Identifier: AGPL-3.0
pragma solidity 0.8.35;

import {BasePerpTest} from "../../BasePerpTest.sol";
import {CfdTypes} from "@plether/perps/CfdTypes.sol";
import {OrderV3Types} from "@plether/perps/OrderV3Types.sol";
import {IOrderRouterErrors} from "@plether/perps/interfaces/IOrderRouterErrors.sol";
import {IPerpsKeeper} from "@plether/perps/interfaces/IPerpsKeeper.sol";
import {IPositionProtectionActions} from "@plether/perps/interfaces/IPositionProtectionActions.sol";
import {IPositionProtectionViews} from "@plether/perps/interfaces/IPositionProtectionViews.sol";
import {AccountLensViewTypes} from "@plether/perps/interfaces/AccountLensViewTypes.sol";
import {PositionProtectionTypes} from "@plether/perps/interfaces/PositionProtectionTypes.sol";
import {MockPyth} from "@plether/test-utils/MockPyth.sol";
import {console2} from "forge-std/console2.sol";

contract ProtectionFreezeBot {

    IPerpsKeeper public immutable KEEPER;
    IPositionProtectionActions public immutable PROTECTION;

    constructor(
        address router,
        address protectionBook
    ) {
        KEEPER = IPerpsKeeper(router);
        PROTECTION = IPositionProtectionActions(protectionBook);
    }

    function expireAndRetry(
        uint64 expiredOrderId,
        uint64 protectionId
    ) external returns (uint64 nextOrderId) {
        KEEPER.expireOrder(expiredOrderId);
        nextOrderId = PROTECTION.retryPositionProtectionClose(protectionId);
    }

}

contract PositionProtectionRetryFreezePoCTest is BasePerpTest {

    IPositionProtectionActions internal protectionActions;
    IPositionProtectionViews internal protectionViews;
    ProtectionFreezeB

The original report as published on Immunefi, by dikanevn. 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 is permissionless and does not require that the close limits were amended since the last failure, so it can re-enqueue the same unexecutable order indefinitely.

Impact

The trader's position and collateral margin could stay frozen for more than 24 hours while carry fees accrue and market risk continues, because the owner cannot amend limits, cancel, replace or manually close the position.

What the attacker needed

No account or deposit needed; position in latched state; attacker pays gas each cycle

The fix

The retry should be restricted or should require that the close limits were amended since the last failure, so the owner's latched window cannot be closed by a third party.

How it was found

  1. Wait until the protection's linked close order fails or its execution deadline passes, moving the protection to the latched state.
  2. In the same transaction, call the router to expire the linked order, which latches the protection.
  3. Immediately call the permissionless retry function so the protection returns to triggered with the same stale limits.
  4. Repeat the cycle every execution window to keep the owner from ever amending the limits.

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.

When a stop-loss or take-profit fires, the system tries to close the trade within limits the user set. If those limits are too tight, the close fails and the trade is parked in a 'latched' state where only the owner can loosen the limits. The bug is that anyone can restart the failed close attempt, which puts the trade straight back into the busy state and shuts the owner out of the only fix, so the trade stays stuck.

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 dikanevn

View all

4 more disclosed reports, 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.