Skip to content
Business logic Audit finding Advanced

Open-order carry checkpoint bypasses the trader's charge limits

Committing an open order collects carry owed by the trader's existing position, but the router records the commitment as having collected zero carry. At execution the policy checks only the later trade charge against the trader's stated maximum, so an increase can execute even though the combined charge exceeds the authorised limit.

CarlosMB Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

#98293 [SC-Low] Open-order carry checkpoint bypasses the trader's charge limits

Submitted on Nov 6th 2026 at 19:11:40 UTC by @CarlosMB for Audit Competition | Plether

Description

Executive Summary

Committing an open order checkpoints and collects carry owed by the trader's existing position. The Router then records the order as though no carry was collected. When the order executes, the opening-order policy checks only the later trade charge against Alice's stated financial limit. An increase can therefore execute even though the total charge across commitment and execution exceeds that limit. The accounting specification requires direct carry collection to count once in financial bounds.

In the controlled PoC, Bob is a Junior LP and permissionless keeper. Alice commits an increase; Bob executes it and fully redeems his LP shares through public calls. A one-atom lower limit rejects the increase, while the bypass branch pays Bob 0.548347 USDG more wallet cash, with the same keeper bounty and no remaining shares. A separate same-mark test closes Alice's position through a later Alice-authored order: she finishes flat with 8.000102 USDG less than in the rejection control. Bob's cashout needs no second order from Alice; the measurement of her final, closed-position loss does.

Four-step failure

  1. Alice's existing 50,000-unit position owes 0.219630 USDG carry. She submits a 10,000-unit increase with maxActionChargeAssets = 9.488955 USDG. This cap covers carry, VPI and fees together.
  2. Committing the increase collects that 0.219630 USDG from the old position, but stores zero as commitment carry. The new 10,000 units have not yet existed and owe no historical carry.
  3. During the brief commit-to-execution interval, the old position accrues another 0.000002 USDG. At execution, the policy sees 9.488955 USDG of VPI, fee and that small carry amount. It accepts equality with Alice's cap.
  4. The actual combined action charge is 0.219630 + 9.488955 = 9.708585 USDG, exceeding Alice's maximum by 0.219630 USDG. The same omission makes the gross debit 9.908585 USDG against a 9.688955 USDG gross cap.
Financial limit Alice's maximum Amount checked at execution Actual total from commitment through execution Excess
Action charge 9.488955 9.488955 9.708585 0.219630 USDG
Gross account debit, including bounty 9.688955 9.688955 9.908585 0.219630 USDG

The old carry payment is legitimate and is not charged twice. The failure is executing the additional trade after its total charge has exceeded Alice's conditional authorization.

Background

The competition information pins the code in scope to the frozen commit above. v2.0.0 is a verified public release containing the inspected V3 order flow. Alice is the trader and account owner. The public commitOrder entry point, lines 127-135 attributes an ordinary order to msg.sender, so Alice must commit it herself. Bob is a Junior LP and keeper; Carol is another Junior LP. The scope notes expressly allow anyone to act as a keeper.

Documented property violated

OrderV3Types.sol, line 131 calls the bounds “Mandatory financial authority supplied with every V3 order.” The integration guide, line 103 defines maxActionChargeAssets as the “Maximum assessed action charge after carry, signed virtual price impact (VPI), fees, and frozen spread are combined”; its adjacent line includes aggregate settlement debit and reserved bounty in maxGrossAccountDebitAssets. ACCOUNTING_SPEC.md, line 723 says “Receipts and financial bounds include the direct collection once.” SECURITY.md, lines 756-765 makes the maxima inclusive. The 0.219630 USDG carry collected at commitment is direct collection under that rule, yet the Book records zero and the opening execution check omits it. The checked total is therefore 9.488955 instead of 9.708585 USDG, contradicting both the combined-charge definition and the count-once requirement.

The tested setup starts by funding Alice with 100,000 USDG and opening a 50,000-unit LONG with 10,000 USDG margin. Carol deposits 900,000 USDG and Bob 100,000 into Junior; the fixture has no Senior LP. After one day at mark 1.00, Alice owes 0.219630 USDG of carry on her existing position. She submits one same-side increase of 10,000 units with 1,000 USDG additional margin. Bob already owns his LP shares before this order. The fixture uses the relevant release risk and fee parameters; its LP mix is a reproducible scenario, not a measured production distribution.

Carry itself is not the bug. It is an obligation of Alice's existing position and collected carry is LP trading revenue. The bug is that the protocol collects it while creating this financially bounded order, then lets the order execute as though that collection had never consumed Alice's limit.

Vulnerability Details

Commit and collect the old carry

OrderReservationAccounting._reserveExecutionBounty, lines 108-127 takes the opening-order branch, assigns only effects.bountyFromFreeAssets and calls clearinghouse.lockReservedSettlement. The returned effects still have carryCollectedAssets equal to zero. MarginClearinghouse.lockReservedSettlement, lines 818-824 first invokes _checkpointCarryBeforeMarginChange. Its collection path, lines 1336-1355 can transfer the old-position carry at this point. The PoC measures 0.219630 USDG collected at commitment.

Record an incomplete commitment

OrderCommitHandler._createPendingOrder, lines 21-35 passes those effects to _onOrderCommitted in OrderRouterBase, lines 110-115, which records them in the Book. OrderLifecycleBook.recordCommitment, lines 327-359 checks both bounds against the supplied effects.carryCollectedAssets and stores the same zero. Its internal balance consistency check cannot detect the earlier Clearinghouse debit because the supplied effects do not include that debit. A later margin reservation is another possible carry checkpoint; the PoC's observed collection occurs at the nonzero bounty reservation.

Check the wrong total at execution

CfdOrderPolicyEvaluator, lines 64-67 calls _includeCommitment only for closes. For an increase, CfdOrderPolicyEvaluatorBase, lines 340-348 computes the charge from carry still pending at execution plus the new trade cost. The 0.219630 already collected is no longer pending and was not retained in the Book. _includeCommitment, lines 474-486 contains the operation that would add a commitment's carry once, but the opening branch does not invoke it. _enforceBounds, lines 489-518 therefore compares an incomplete charge with Alice's stated maxima.

The tested increase's 9.488955 USDG execution charge is 5.488953 positive opening VPI credited to the pool, 4.000000 fee credited to the treasury, and 0.000002 carry accrued on the pre-existing position between commitment and execution. Adding the 0.219630 USDG old-position carry collected at commitment produces 9.708585 USDG. The separate gross-debit control adds the 0.200000 USDG reserved execution bounty: the stated maximum is 9.688955, whereas the accumulated debit is 9.908585 USDG. The omitted old carry explains the exact 0.219630 excess in each limit. No one charges carry twice; the check fails to count an already-realized charge once.

Exploitability Analysis

One-atom authorization control

The one-atom control establishes execution outside Alice's authenticated financial limit. Restoring the same snapshot and changing only maxActionChargeAssets from 9.488954 to 9.488955 USDG changes the order from Failed to Executed. An independent maxGrossAccountDebitAssets control changes 9.688954 to 9.688955 with the same result. Both branches collect Alice's 0.219630 old carry and award the same 0.200000 bounty. The control shows that the difference is admission of the increase, not a carry waiver or an extra keeper payment.

Public-entrypoint cashout and measured scaling

A separate Foundry fixture funds Junior LPs, settles their deposits, opens Alice's initial LONG, updates the mark, commits and executes her increase, settles Bob's redemption epoch and pays his full withdrawal through public protocol calls. Only token minting, time advances and the out-of-scope Pyth mock are fixture operations. Each scale restores the same snapshot and compares the action cap with that cap minus one USDG atom. At every tested scale the lower cap fails, the higher cap executes, Bob redeems 100% of his shares, and his keeper custody is equal across branches. Alice still owns the larger position after Bob's autonomous cashout, so her custody delta here is not a measured terminal loss.

Public E2E fixture Bob initial Junior stake Old carry collected at commitment Action cap that executes Bob's extra wallet USDG after full exit Alice custody difference; position still open
1×; 1,000,000 USDG Junior depth 100,000 0.219632 9.488955 +0.548347 −9.488955
10×; 10,000,000 USDG Junior depth 1,000,000 2.196326 94.988328 +5.498283 −94.988328
100×; 100,000,000 USDG Junior depth 10,000,000 21.963267 949.982259 +54.997676 −949.982259

For the 100× fixture, the execution check admits 949.982259 USDG while the combined charge is 21.963267 + 949.982259 = 971.945526 USDG. Bob's actual wallet payout is 10,000,127.169723 USDG in the failed-order control and 10,000,182.167399 USDG after execution; his keeper-bounty custody is 0.400000 USDG in both. The 949.982259 custody difference reconciles as Bob wallet +54.997676, residual pool cash +494.984583 and treasury +400.000000. Carol's LP share valuation increases by 494.979083 but is not a withdrawn amount and must not be added again. The public E2E 1× fixture's old carry is 0.219632, two USDG atoms above the earlier 0.219630 example, because the public initial open and timing differ. These are code-scale results using minted MockUSDG and simulated 100 million USDG depth, not evidence that a deployed pool holds that liquidity or that Bob earned a 54.997676 USDG net profit after external costs.

Closed-position counterfactual

A second test completes Alice's accounting with one sequence per branch: Alice commits the increase; Bob executes or the limit rejects it; Alice then independently commits a public full close of her resulting position; Bob executes it at mark 1.00; Bob redeems all his LP shares through the public Router. The second Alice order must close 50,000 units in the rejected branch and 60,000 in the executed branch, so that downstream request necessarily follows the position created by the first decision. Both branches end flat.

Final state after Alice closes and Bob exits, mark 1.00 Rejected control Bypass executed Bypass difference
Alice custody; position zero 99,959.580203 99,951.580101 −8.000102 USDG
Bob wallet after redeeming 100% of shares 100,001.245391 100,001.793738 +0.548347 USDG
Bob keeper-bounty custody 0.200000 0.200000 0
Bob residual LP shares and claim 0 0 0
Carol LP share valuation, not withdrawn 900,011.199404 900,016.134529 +4.935125 USDG
Pool cash after paying Bob 902,011.449297 902,016.389906 +4.940609 USDG
Treasury custody 27.525109 30.036255 +2.511146 USDG

The final 8.000102 USDG difference in Alice's custody reconciles as Bob wallet +0.548347 + residual pool cash +4.940609 + treasury +2.511146. Carol's LP share valuation is a claim on pool assets, not extra cash to add to that sum. With the same 100,000 USDG initial stake, Bob's wallet plus bounty custody is 100,001.445391 in the control and 100,001.993738 after the bypass, before external costs.

Impact and severity

Alice's cap should prevent the entire increase, not merely the last 0.219630 USDG of its charge. The protocol nevertheless executes that financially unauthorized trade; Bob, an unrelated party who selects it for execution, converts part of the resulting pool revenue to USDG in his own wallet. The same-mark close scenario demonstrates that Alice can finish with a real, price-independent 8.000102 USDG loss while Bob retains his incremental withdrawal. This realized third-party payout from a financially unauthorized execution supports the proposed Critical direct-theft impact.

Limits of the demonstrated impact

Alice submits the increase and must submit the later close; Bob cannot unilaterally create either. Positive opening VPI and fees are ordinary protocol revenue for a trade that executes. ACCOUNTING_SPEC.md, lines 1055-1065 makes a negative close rebate conditional on available cash, and no preview creates a guaranteed refund. Bob's no-close payout alone proves a realized transfer from pool revenue, while Alice still owns the enlarged position; Alice's terminal loss is demonstrated only when she later closes voluntarily. Gas, oracle expense, capital cost and exposure to price movement during the LP epoch were not measured. Immunefi may therefore classify the proven financial-bound violation as Medium user damage rather than Critical direct theft. The proposed Critical severity is supported by the realized cashout and closed-position loss, but it is not settled by these tests alone.

Version and public-issue check

The frozen competition code and public v2.0.0 release contain this flow; the first affected and first fixed releases have not been established. PR #124 prevents an early carry checkpoint when refunding a protection bounty before a manual close, a different path from reserving bounty for an ordinary increase. The published Cecuro MED-22 concerns carry rounding. No identical public disclosure was identified, though PR #124's conceptual overlap may be debated. The competition rules invalidate public disclosures of the same root cause and keep private duplicates eligible.

Proof of Concept

Proof of Concept

These are the complete runnable Foundry test sources. Save each Solidity block verbatim at its stated path in a clean checkout of the competition commit. They use BasePerpTest and mocked out-of-scope inputs; no packages/perps/src contract is modified and no public-chain transaction is required. The public-entrypoint test distinguishes protocol calls from fixture minting, snapshots and clock advances.

Test 1 — Public open, increase and full LP withdrawal

Save as: packages/perps/test/perps/audit/AuditCarryPublicE2E.t.sol. This test contains the 1×, 10× and 100× same-snapshot cap controls and Bob's fully claimed LP exit.

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 {ICfdEngineTypes} from "@plether/perps/interfaces/ICfdEngineTypes.sol";

/// @notice Public-path E2E audit probe. Token mint and time warp are fixture setup only.
contract AuditCarryPublicE2E is BasePerpTest {
    address private constant ALICE = address(0x111);
    address private constant BOB = address(0x222);
    address private constant CAROL = address(0x333);

    function _initialJuniorDeposit() internal pure override returns (uint256) { return 0; }
    function _initialSeniorDeposit() internal pure override returns (uint256) { return 0; }

    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: 5_000,
            protocolShareBps: 0
        });
    }

    struct Outcome {
        uint8 status;
        uint8 reason;
        uint256 sizeAfterExecution;
        uint256 aliceCustodyAfterExecution;
        uint256 aliceCustodyAfterClaim;
        uint256 bobWalletAfterClaim;
        uint256 bobKeeperCustodyAfterClaim;
        uint256 bobSharesAfterClaim;
        uint256 carolLpClaimAfterClaim;
        uint256 poolCashAfterClaim;
        uint256 treasuryAfterClaim;
    }

    function test_OneXPublicInitialOpenIncreaseAndFullLpCashout() public {
        _runScale(1);
    }

    function test_TenXPublicInitialOpenIncreaseAndFullLpCashout() public {
        _runScale(10);
    }

    function test_HundredXPublicInitialOpenIncreaseAndFullLpCashout() public {
        _runScale(100);
    }

    function _runScale(uint256 scale) private {
        _fundJuniorPublic(CAROL, 900_000e6 * scale);
        _fundJuniorPublic(BOB, 100_000e6 * scale);
        _fundTrader(ALICE, 100_000e6 * scale);

        OrderV3Types.OrderRequest memory initial = _openRequest(
            keccak256("public-initial-open"), 50_000e18 * scale, 10_000e6 * scale, type(uint256).max
        );
        vm.prank(ALICE);
        uint64 initialId = router.commitOrder(initial);
        bytes[] memory initialPriceData = _mockPythUpdateData(1e8);
        vm.prank(BOB);
        OrderV3Types.ExecutionResult memory initialExecution = router.executeOrder(initialId, initialPriceData);
        assertEq(uint8(initialExecution.status), uint8(OrderV3Types.LifecycleStatus.Executed));
        (uint256 initialSize,,,,,,) = engine.positions(ALICE);
        assertEq(initialSize, 50_000e18 * scale);

        vm.warp(vm.getBlockTimestamp() + 1 days);
        router.updateMarkPrice(_mockPythUpdateData(1e8));
        uint256 oldCarry = _expectedIndexedCarryAssets(ALICE);
        ICfdEngineTypes.OpenPreview memory quote = engineLens.previewOpen(
            ALICE, CfdTypes.Side.LONG, 10_000e18 * scale, 1_000e6 * scale, 1e8
        );
        emit log_named_uint("scale", scale);
        emit log_named_uint("old carry", oldCarry);
        emit log_named_uint("preview invalid reason", uint8(quote.invalidReason));
        assertTrue(quote.valid, "scaled increase must be planner valid");
        assertGt(oldCarry, 0);
        assertGt(quote.tradeCostAssets, 0);
        uint256 reportedCharge = _calibrateNextExecutionCharge(scale);
        emit log_named_uint("pre-commit trade cost", uint256(quote.tradeCostAssets));
        emit log_named_uint("reported action charge", reportedCharge);
        emit log_named_uint("preview VPI charge", uint256(quote.vpiAssets));
        emit log_named_uint("preview execution fee", quote.executionFeeAssets);
        uint256 bobShares = juniorVault.balanceOf(BOB);
        uint256 snapshot = vm.snapshotState();

        Outcome memory rejected = _runBranch(scale, reportedCharge - 1, bobShares);
        assertEq(rejected.status, uint8(OrderV3Types.LifecycleStatus.Failed));
        assertEq(rejected.reason, uint8(OrderV3Types.TerminalReason.ConstraintViolation));
        assertEq(rejected.sizeAfterExecution, 50_000e18 * scale);
        assertEq(rejected.bobSharesAfterClaim, 0);

        assertTrue(vm.revertToState(snapshot));
        Outcome memory bypass = _runBranch(scale, reportedCharge, bobShares);
        assertEq(bypass.status, uint8(OrderV3Types.LifecycleStatus.Executed));
        assertEq(bypass.reason, uint8(OrderV3Types.TerminalReason.Executed));
        assertEq(bypass.sizeAfterExecution, 60_000e18 * scale);
        assertEq(bypass.bobSharesAfterClaim, 0);
        assertGt(bypass.bobWalletAfterClaim, rejected.bobWalletAfterClaim);
        assertEq(bypass.bobKeeperCustodyAfterClaim, rejected.bobKeeperCustodyAfterClaim);
        assertEq(rejected.aliceCustodyAfterClaim - bypass.aliceCustodyAfterClaim, reportedCharge);

        emit log_named_uint("Bob LP stake", 100_000e6 * scale);
        emit log_named_uint("Carol LP stake", 900_000e6 * scale);
        emit log_named_uint("Bob control wallet after full cashout", rejected.bobWalletAfterClaim);
        emit log_named_uint("Bob bypass wallet after full cashout", bypass.bobWalletAfterClaim);
        emit log_named_uint("Bob incremental realized wallet", bypass.bobWalletAfterClaim - rejected.bobWalletAfterClaim);
        emit log_named_uint("Bob control keeper custody", rejected.bobKeeperCustodyAfterClaim);
        emit log_named_uint("Bob bypass keeper custody", bypass.bobKeeperCustodyAfterClaim);
        emit log_named_uint("Alice control custody", rejected.aliceCustodyAfterClaim);
        emit log_named_uint("Alice bypass custody", bypass.aliceCustodyAfterClaim);
        emit log_named_uint("Carol control LP claim preview", rejected.carolLpClaimAfterClaim);
        emit log_named_uint("Carol bypass LP claim preview", bypass.carolLpClaimAfterClaim);
        emit log_named_uint("pool control cash", rejected.poolCashAfterClaim);
        emit log_named_uint("pool bypass cash", bypass.poolCashAfterClaim);
        emit log_named_uint("treasury control custody", rejected.treasuryAfterClaim);
        emit log_named_uint("treasury bypass custody", bypass.treasuryAfterClaim);
    }

    /// @dev Test-only reverted calibration: a temporary permissive commit and next-second
    ///      view are reverted before the same-snapshot one-atom control branches begin.
    function _calibrateNextExecutionCharge(uint256 scale) private returns (uint256 charge) {
        uint256 calibrationSnapshot = vm.snapshotState();
        OrderV3Types.OrderRequest memory probe = _openRequest(
            keccak256("temporary-charge-calibration"), 10_000e18 * scale, 1_000e6 * scale, type(uint256).max
        );
        vm.prank(ALICE);
        router.commitOrder(probe);
        _mockPythUpdateData(1e8);
        ICfdEngineTypes.OpenPreview memory executionQuote = engineLens.previewOpen(
            ALICE, CfdTypes.Side.LONG, 10_000e18 * scale, 1_000e6 * scale, 1e8
        );
        assertTrue(executionQuote.valid);
        assertGt(executionQuote.tradeCostAssets, 0);
        charge = uint256(executionQuote.tradeCostAssets) + executionQuote.pendingCarryAssets;
        emit log_named_uint("post-commit one-second carry", executionQuote.pendingCarryAssets);
        assertTrue(vm.revertToState(calibrationSnapshot));
    }

    function _fundJuniorPublic(address lp, uint256 amount) private {
        settlementToken.mint(lp, amount);
        vm.startPrank(lp);
        settlementToken.approve(address(juniorVault), amount);
        uint256 requestId = juniorVault.requestDeposit(amount, lp, lp);
        vm.stopPrank();
        vm.warp(juniorVault.depositEpochStart(requestId));
        bytes[] memory settlePriceData = _mockPythUpdateData(1e8);
        vm.prank(BOB);
        router.settleLpEpoch(settlePriceData);
        uint256 claimableAssets = juniorVault.claimableDepositRequest(requestId, lp);
        assertEq(claimableAssets, amount);
        vm.prank(lp);
        juniorVault.claimDeposit(requestId, claimableAssets, lp, lp);
    }

    function _runBranch(uint256 scale, uint256 maxActionChargeAssets, uint256 bobShares)
        private returns (Outcome memory out)
    {
        OrderV3Types.OrderRequest memory increase = _openRequest(
            keccak256("public-increase"), 10_000e18 * scale, 1_000e6 * scale, maxActionChargeAssets
        );
        vm.prank(ALICE);
        uint64 id = router.commitOrder(increase);
        assertEq(router.lifecycleBook().pendingIntent(id).commitment.carryCollectedAssets, 0);
        bytes[] memory executePriceData = _mockPythUpdateData(1e8);
        vm.prank(BOB);
        OrderV3Types.ExecutionResult memory execution = router.executeOrder(id, executePriceData);
        out.status = uint8(execution.status);
        out.reason = uint8(router.lifecycleBook().terminalOutcome(id).reason);
        (out.sizeAfterExecution,,,,,,) = engine.positions(ALICE);
        out.aliceCustodyAfterExecution = clearinghouse.balanceAssets(ALICE);

        vm.prank(BOB);
        uint256 redeemId = juniorVault.requestRedeem(bobShares, BOB, BOB);
        vm.warp(pool.lpEpochStart(redeemId));
        bytes[] memory settlePriceData = _mockPythUpdateData(1e8);
        vm.prank(BOB);
        router.settleLpEpoch(settlePriceData);
        uint256 claimableShares = juniorVault.claimableRedeemRequest(redeemId, BOB);
        assertEq(claimableShares, bobShares);
        vm.prank(BOB);
        juniorVault.claimRedeem(redeemId, claimableShares, BOB, BOB);

        out.aliceCustodyAfterClaim = clearinghouse.balanceAssets(ALICE);
        out.bobWalletAfterClaim = settlementToken.balanceOf(BOB);
        out.bobKeeperCustodyAfterClaim = clearinghouse.balanceAssets(BOB);
        out.bobSharesAfterClaim = juniorVault.balanceOf(BOB);
        out.carolLpClaimAfterClaim = juniorVault.convertToAssets(juniorVault.balanceOf(CAROL));
        out.poolCashAfterClaim = pool.totalAssets();
        out.treasuryAfterClaim = clearinghouse.balanceAssets(engine.protocolTreasury());
    }

    function _openRequest(bytes32 clientId, uint256 size, uint256 margin, uint256 maxActionCharge)
        private view returns (OrderV3Types.OrderRequest memory request)
    {
        request.clientOrderId = clientId;
        request.side = CfdTypes.Side.LONG;
        request.sizeDelta = size;
        request.marginDelta = margin;
        request.targetPrice = 1e8;
        request.bounds = OrderV3Types.ExecutionBounds({
            submitBy: uint64(vm.getBlockTimestamp() + router.maxExecutionWindowSeconds()),
            executionWindowSeconds: uint32(router.maxExecutionWindowSeconds()),
            allowedExecutionModes: 7,
            expectedConfigHash: router.lifecycleBook().currentExecutionConfigHash(),
            maxExecutionBountyAssets: type(uint256).max,
            maxExecutionNotionalAssets: type(uint256).max,
            maxGrossAccountDebitAssets: type(uint256).max,
            maxActionChargeAssets: maxActionCharge,
            maxExplicitFeesAssets: type(uint256).max,
            maxPostPositionSize: type(uint256).max,
            minPostSettlementBalanceAssets: 0,
            minPostPositionEquityAssets: 0,
            maxPostLeverageBps: type(uint32).max
        });
    }
}

Test 2 — One-atom action and gross-debit limits

Save as: packages/perps/test/perps/audit/AuditCarryOneAtomThreshold.t.sol. This test isolates both inclu

The original report as published on Immunefi, by CarlosMB. 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 opening-order branch records carryCollectedAssets as zero after the clearinghouse has already collected old-position carry, and the execution-time policy only adds commitment carry for closes, so the collected amount is never counted against the trader's bounds.

Impact

A financially unauthorised increase could execute, and in the PoC a keeper LP who executes it and redeems his shares ends with more wallet cash, while the trader's terminal loss is only shown when she later closes voluntarily; the report itself notes the severity may be classed as Medium rather than Critical.

What the attacker needed

Trader submits the increase order; keeper executes the order; existing position owes carry; trader later closes to realise loss

The fix

The commitment should record the carry actually collected and the execution-time bounds check should include it once, so the combined charge is compared against the trader's stated maxima.

How it was found

  1. Alice submits a same-side increase with a maximum action charge that covers carry, VPI and fees together.
  2. Committing the order collects the old-position carry but stores zero as commitment carry.
  3. During the commit-to-execution interval the old position accrues a tiny further carry amount.
  4. At execution the policy checks only the later trade charge plus that small carry against Alice's cap and accepts equality.
  5. The actual combined charge exceeds Alice's maximum by the omitted old carry, yet the order executes.

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 can attach a spending cap to an order, meaning the protocol should refuse the order if it would cost more than that cap. Here the protocol took a fee (carry) from the trader's existing position when the order was submitted, then forgot to count that fee when checking the cap at execution. So the order went through even though the real total cost was above what the trader allowed.

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 CarlosMB

View all

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