Skip to content
Business logic Audit finding Advanced

LP epoch settlement omits pending orders whose fill prices are already fixed, so the order of permissionless calls moves their PnL between the epoch's depositors and redeemers

LP epoch settlement prices deposits and redemptions without accounting for pending orders whose fill price is already fixed, so whichever permissionless call lands first (execute or settle) decides which LP cohort bears the order's PnL. An attacker or ordinary keeper ordering the calls can shift value between the epoch's depositors and redeemers, though the amounts are small and the protocol loses nothing in aggregate.

argo_the_hacker Follow

Originally disclosed on Immunefi

Critical View original
  • Disclosed after under an hour

#99894 [SC-Critical] LP epoch settlement omits pending orders whose fill prices are already fixed, so the order of permissionless calls moves their PnL between the epoch's depositors and redeemers

Submitted on Nov 15th 2026 at 17:09:05 UTC by @argo_the_hacker for Audit Competition | Plether

Description

Severity: Low. Impact selected from the program's list: "Contract fails to deliver promised returns, but doesn't lose value". If the judge reads it as informational, it is the Insight.

Target: immunefi-team/audit-comp-plether @ a82d4fefb02768e5b3bddcc97dee371eee24fea8, packages/perps/src: the Router's LP settlement path OrderLiquidationBatchLogic.settleLpEpoch (router/OrderLiquidationBatchLogic.sol:549-581) and HousePool.settleLpEpoch (HousePool.sol:797-821), together with the delayed-order mark update OrderRouterExecutionSidecar._updateEngineMark (OrderRouterExecutionSidecar.sol:1053-1060).

Relation to prior findings: the closest known issue is the AI scan's "Order execution accepts oracle updates older than the engine's cached mark". It describes the behaviour this report builds on, but a different harm (a trader choosing a favourable older price against the pool) with a different fix location. This report's root is in LP settlement. See "Relation to prior findings".

Summary

LP deposits and redemptions settle once per hourly epoch, through the permissionless OrderRouter.settleLpEpoch, at a freshly pushed mark. SECURITY.md:849-860 ("Exact symmetric LP NAV") promises that LP entry and exit price off the same terminal snapshot, and that "new LPs receive the same marked-liability discount borne by existing LPs and do not inherit old trader obligations at a higher deposit NAV".

A delayed order's fill price is fixed as soon as its unique historical tick, the first tick after commitTime (within 15 s, PletherOracle.sol:87), is published. The order can still wait to execute until its deadline (60 s by default, router/OrderExecutionOrchestrator.sol:11). Settlement NAV is the pool's physical assets, less trader claims, plus or minus the terminal price delta of the Engine's open positions (libraries/HousePoolAccountingLib.sol:60-77, TerminalNavBookV2.sol:208-237). A pending order's PnL from its fixed fill to the settlement mark is not part of it, and the settlement path does not read the order queue (router/OrderLiquidationBatchLogic.sol:549-581).

So when an epoch boundary passes while such an order is pending, two permissionless calls race:

  • execute → settle: the position exists at settlement, and its marked PnL is in the price at which the epoch's redeemers exit and its depositors enter.
  • settle → execute: settlement prices both directions without it. The order then opens at its old fill. The Engine keeps the newer settlement mark (OrderRouterExecutionSidecar.sol:1053-1060), so the position's marked PnL against that mark is in place immediately. It falls on whoever holds shares after settlement, including the depositor who has just entered at a NAV that did not carry it. The redeemer has already left at a NAV that did not carry it.

Both orderings end with the same position (size, margin, entry) and the same Engine mark. Only the split between the epoch's entering and exiting LPs differs.

At the release parameters, the ordering effect reproduces. The run uses the pinned release script's own deployment (script/DeployPerpsArbitrumSepolia.s.sol) and the live v1.3.1 bootstrap: VPI factor 0.01, skew cap 40%, a 500M junior seed and a 10M senior seed. A 20M LONG is pending at the boundary. About 50M of junior is redeemed and 50M deposited, each about 7% of ~700M junior. With no price move at all, settle → execute and execute → settle differ by 185.29 USDC between the redeemer and the depositor. The pending open's execution charge (its VPI, 2,594.08 USDC into junior NAV) lands on whichever cohort the call order picks. A price move adds a second part, about 136 USDC per basis point in this configuration. In the measured direction it offsets the VPI part: 50.79 USDC at 1 bp and 497.68 at 5 bp. The account that orders the calls receives nothing, and an LP who holds through is unchanged. At the fixture sizes used below, the 500M release seed dilutes the effect to 0.048 USDC at a 1% move.

In the fixture configuration of the PoC below (VPI 0, ~201,000 junior USDC; see "Fixture notes"), a 50,000-token LONG fills at 1.00 at b − 9 (b is the epoch boundary) and settlement runs at 0.99 at b + 1. 50,000 of about 201,000 junior USDC is redeemed and 50,000 deposited. Under settle → execute, the redeemer receives 124.378110 USDC more and the new depositor's shares are worth 124.378126 USDC less than under execute → settle. An LP who holds through the epoch is unchanged in both orders. The mirror case (the market moves against the trader) moves the same amount the other way. The transfer is linear in the move: 1.24 USDC at 1 bp.

The same root covers more than one fresh open. The PoC shows two further cases (fixture configuration):

  • Pending closes. A trader whose position is open at settlement commits a full close at b − 10, with its fill fixed at b − 9. Settlement marks the still-open position at the new price, and the close then realizes at the old fill. The redeemer's payout differs by ±124.38 USDC between the two orderings at a 1% move (124.378153 and 124.378066), about the same as the open case. The depositor's change is not the exact negative of the redeemer's here (see the PoC section). So the precondition can be an existing trader's exit in the seconds before a boundary, if that close is otherwise executable, not only a fresh open. The PoC shows one fully funded full close; partial closes and other configurations are not tested.
  • More than two outcomes: a prefix of the queue. Three unrelated traders' opens are pending at the boundary (LONG 50,000, SHORT 80,000 and LONG 40,000, all filled at 1.00; settlement at 0.99). Executions are FIFO and permissionless. So a settler can execute the first k, settle, and leave the rest for afterwards, if its calls land in that order before another permissionless keeper executes the head or settles. This is a feasible scheduling choice, not exclusive control, and it is not a free permutation of the queue: only FIFO prefixes are available, and expiry, slippage, collateral or solvency checks can rule some out. The test has no competing keepers; it shows that all four prefixes are feasible for this queue. The redeemer's payout for k = 0, 1, 2, 3 is 49,999.99, 49,875.61, 50,074.62 and 49,975.12 USDC. That is a 199.00 USDC range, against 24.88 USDC between "all after" and "all before" (8×). All four final states hold the same three position sizes. The most a settler can move is the spread between the highest and lowest redeemer payout over the feasible prefixes of the pending fixed fills at the boundary, which include orders of accounts it does not control.

The amount is small. At release liquidity, a material amount needs a large pending order plus entering and exiting cohorts that are each a large share of junior. Even then it is about 0.1-1.0 bp of the losing cohort's position in the measured runs (50.79-497.68 USDC on a 50M cohort; 185.29 USDC, about 0.4 bp, with no move). The other cohort gains the same amount. When the move runs the other way, the price part adds to the VPI part instead of offsetting it. At 5 bp that is roughly 870 USDC (about 1.7 bp), derived from the measured parts, not run. A competing keeper that executes at the fill tick removes the price part for orders whose fill precedes the boundary, but not the VPI part. The protocol in aggregate loses nothing. The Impact section states the limits, and the first objection a reviewer will raise is answered under "The first objection".

Relation to prior findings

AI scan, "Order execution accepts oracle updates older than the engine's cached mark" (info; a known issue under the program's rules). It describes the enabling behaviour: an order can execute at a historical price older than the Engine's cached mark, and the mark is not rewound. It frames the harm as a self-executing trader who keeps a favourable older update, waits for a newer adverse mark and opens at the old price against the pool. At the pinned commit the order's execution tick is the unique first tick after commit (PletherOracle.sol:596-640), so the trader no longer chooses the price. A late execution at the historical fill is the design, and this report does not dispute it. This report's root is that LP epoch settlement does not account for that already-fixed fill. Its harm runs between LPs, the epoch's depositors against its redeemers, not between trader and pool. The fix belongs in settlement, not in order execution.

Cecuro MED-18 (fixed): its fix note says an older historical fill cannot rewind a newer mark. That is the behaviour this report relies on, not its root.

Cecuro MED-7 (acknowledged): a keeper's choice of basket component. Its comment says a sole keeper already has execution-timing discretion. That concerns which tick an order executes at, not which LP cohort bears an order whose price is already fixed. Cecuro HIGH-1 (acknowledged): a trader commits after seeing a tick. This report does not need the trader to know anything at commit.

AI scan, permissionless settlement timing in the frozen window: the same class (who times a permissionless settlement), but a different root (the settlement fee).

SECURITY.md:1044-1052 (LP request cutoff) says the cutoff "is not an immutable settlement snapshot" and that "trading, closes, liquidations, claims, carry, and pool accounting can change NAV" before settlement. That covers state that changes before settlement and that settlement then prices. Here the order's price is already fixed before settlement, and settlement does not price it at all. Whether it lands in the entering or the exiting cohort is decided after the boundary, by which permissionless call lands first. Nothing in the Known Limitations says settlement excludes pending orders.

The SC Audit Studio pre-audit, the collaborative audit and the Cantina report have no epoch-settlement ordering item.

Vulnerability details

The Router's settlement path pushes the current tick, installs it as the Engine mark and settles the pool against it. It never looks at the order queue (router/OrderLiquidationBatchLogic.sol:561-563):

Solidity
        IPletherOracle.PriceSnapshot memory snapshot =
            oracle.updatePrice{value: pythFee}(msg.sender, pythUpdateData, IPletherOracle.PriceMode.PoolReconcile);
        host.engine().updateMarkPrice(snapshot.markPrice, snapshot.publishTime);

HousePool.settleLpEpoch (HousePool.sol:797-821) then takes one accounting snapshot. Its price exposure comes from the terminal NAV book, which values the Engine's open-interest curves at the Engine mark (TerminalNavBookV2.sol:208-237). Terminal equity is physical assets, less trader claims, plus or minus that delta (libraries/HousePoolAccountingLib.sol:60-77). Redemptions and deposits of the matured epoch are priced from it (HousePool.sol:835-938). A pending open has no position yet, so its PnL from its fixed fill to this mark is not in the snapshot. A pending close does have an installed position, and the snapshot values it at this mark; what the snapshot omits is the pending close's adjustment to that position (below).

The pending order still executes afterwards at its fixed historical fill. The Engine mark is updated only if the execution tick is newer (OrderRouterExecutionSidecar.sol:1053-1060):

Solidity
        if (result.publishTime > engine_.lastMarkTime()) {
            engine_.updateMarkPrice(result.neutralMarkPrice, result.publishTime);
        }

The fill tick is older than the settlement mark, so the newer settlement mark stays. The new position's PnL against that mark, (mark − fill) × size in the LPs' direction, enters NAV right after the epoch's LPs have been priced without it.

Both entry points are permissionless: OrderRouter.executeOrder (OrderRouter.sol:240) and OrderRouter.settleLpEpoch (OrderRouter.sol:479, "Permissionless and available while the router admin is paused"; SECURITY.md:506-513: "Keepers are permissionless executors").

For a balanced epoch away from caps, the amount moved is about (redeemed share of the tranche's equity) × |mark − fill| × size. In the PoC that is (50,000 / 201,000) × 500 ≈ 124.38 USDC. With unequal deposits and redemptions, tranche waterfalls, caps or partial funding the split is different, and the PoC does not cover those cases.

A close is the same omission from the other side. The position is open at settlement, so it is valued at the settlement mark M. But its close fill P_f is already fixed, and executing the close afterwards realizes (P_f − M) × size against post-settlement holders. With several pending orders i = 1..N (FIFO by commit time; executeOrder is permissionless on the head), a settler can execute a prefix k before settling, for any k that the FIFO, expiry and solvency checks leave executable. The redeeming cohort's payout then moves by about (redeemed share) × Σ_{i≤k} s_i (M − P_i). The settler chooses k only if its calls land in that order before another keeper executes the head or settles. Mixed directions make an interior prefix more extreme than either end, as in the PoC.

Impact

Who acts, and who pays. Either call can be submitted by any account. Whoever lands first chooses the ordering, but does not bear the result. The loss lands on a third party: the depositor (when the market moved in the trader's favour) or the redeemer (when it moved against the trader). That party took no action after making its LP request before the cutoff. An LP already in the settling epoch can pick the ordering that favours it. The PoC shows the redeemer calling settleLpEpoch herself before the order keeper and receiving the 124.378110 USDC. No adversary is needed at all: the result also follows whenever the settlement keeper simply runs before the order keeper. At the release parameters, a settler with no shares and no position receives no settlement token and ends with the same ETH in both orders. OrderLiquidationBatchLogic.sol:556-579 forwards only the quoted Pyth fee and refunds the rest. So the account that orders the calls gains nothing, and a third party bears the result.

What the contract fails to deliver. A depositor is promised entry at a NAV that already carries the discount for old trader obligations (SECURITY.md:854-855). In the settle-first order the depositor enters without that discount and then bears part of an obligation whose price was fixed before the boundary. A redeemer is likewise promised exit at the same snapshot, and in the mirror case leaves without a gain that was already fixed. The value moves between LPs of one tranche. In the single-open case an LP who holds through is unchanged, and the protocol loses nothing in aggregate. This matches the program's Low impact "Contract fails to deliver promised returns, but doesn't lose value".

Limits, stated plainly:

  • The order must be pending when the epoch settles, with its fill tick already published. In practice it was committed within its execution window before the boundary (60 s by default, router/OrderExecutionOrchestrator.sol:11; the governance limit is 1 h, OrderRouterAdmin.sol:31) and has not yet been executed. Ordinary keepers execute within seconds of the fill tick, so this is mostly orders committed in the last seconds before a boundary, or orders behind a held FIFO head. It can happen at most once per epoch (hourly). The order can be an open or a close, so an existing trader's ordinary exit qualifies. All such orders at one boundary count together, and a settler whose calls land first can choose how many of them execute first (the FIFO-prefix test); another permissionless keeper can act before it.
  • A competing keeper narrows the window, measured at the release parameters:
    • A keeper that executes at the fill tick's own second (b − 9) leaves no order pending at settlement.
    • What survives is an order committed in the last second before b. Its fill tick is b itself, so the settler and the keeper race inside that second. The VPI part still moves 185.29 USDC there with no price move.
    • One second of keeper latency at a 1 bp move leaves 50.79 USDC.
    • An unprivileged contract can settle and execute in one transaction. A competing keeper's later execution of the same order then reverts, so the settler needs to land first only once.
  • At the release parameters the amount has two parts:
    • The VPI part needs no price move: 185.29 USDC with a 20M pending open and ~7% cohorts.
    • The price part is linear in the move between the fill tick and the settlement mark: about 136 USDC per bp in the same configuration.
    • Measured: 185.29 USDC flat, 50.79 at 1 bp and 497.68 at 5 bp. In this direction the two parts offset; in the other they add.
    • At the PoC's fixture sizes, the 500M seed dilutes the effect to 0.047944 USDC at 1%.
  • Measured in the fixture configuration (VPI 0, ~201,000 junior; see "Fixture notes"): 1.243781 USDC at 1 bp, 6.218906 at 5 bp, 24.875625 at 20 bp, 124.378126 at 100 bp. The PoC's 1% is a stress illustration.
  • The beneficiary must already be in the settling epoch. The five-minute request cutoff (TrancheVault.sol:39) prevents seeing a pending order and then joining, and a redeemer needs cooldown-aged shares. The actor chooses the ordering, not the cohort.
  • A fixed fill is not an unconditional obligation. FIFO eligibility, expiry, slippage, collateral and solvency checks still decide whether the order executes. The PoC shows a case where it executes in both orderings.
  • The depositor's loss is marked share value, not realized cash. The redeemer's gain is cash.
  • Making the precondition yourself (committing an order seconds before a boundary) costs fees that exceed a basis-point-sized transfer. This is not presented as a profitable strategy.

The first objection

"This is async noise. The window is under a minute, the amounts are a few basis points, and a pending order is not a position. In each ordering the epoch is still priced off one authenticated snapshot, SECURITY.md:1044-1052 says the cutoff is not an immutable snapshot, and keeper timing discretion is accepted (Cecuro MED-7). Insight at most."

Our answer, point by point:

  • Narrow window. It is narrow, but it recurs at every hourly boundary that has a pending order. Its edges are protocol parameters (the 60 s execution window, the 15 s fill search), not market conditions.
  • Small amounts. Agreed, and the severity claimed is the lowest paid tier for that reason. At release liquidity it is about 0.1-1.0 bp of the losing cohort's position in the measured runs, with an equal gain to the other cohort. It is not zero, and part of it (the VPI part, 185.29 USDC on 50M cohorts) needs no price move at all. The price part scales linearly with pending notional and the move. It is also more than a coin flip between two outcomes: a settler whose calls land first can choose among the feasible FIFO prefixes of the pending queue (199.00 USDC range against 24.88 USDC for the two ends in the PoC).
  • Whose loss. It is not the actor's own loss. The account that orders the calls bears nothing; the cost lands on a depositor or redeemer who did nothing after requesting.
  • "A live keeper executes first." It shrinks the window but does not close it (release parameters). Orders whose fill precedes the boundary are executed before settlement and leave nothing to reorder. An order committed in the last second before b is still raced inside one second. There the VPI part moves 185.29 USDC with no price move, and one second of latency at 1 bp leaves 50.79 USDC.
  • "A pending order is not a position." Its price is fixed before the boundary. Once it executes, its PnL against the settlement mark is an old trader obligation in the exact sense of SECURITY.md:854-855. Which cohort bears it is decided by a call race after the boundary, not by the market. The cutoff text covers changes that settlement prices; here settlement skips one it cannot see.

We accept that the docs do not promise call-order independence for unexecuted orders in so many words. If the judge holds that pending orders are outside the "Exact symmetric LP NAV" promise, this report is the Insight: LP settlement can be ordered ahead of orders whose fills are already fixed, which moves their PnL between entering and exiting LPs.

Recommendation

Make LP epoch settlement wait for orders whose fill is already fixed, so that every order whose price is known at the settlement mark is in the settlement NAV. In the Router's settleLpEpoch path (router/OrderLiquidationBatchLogic.sol:549-581), before calling HousePool.settleLpEpoch, one option is to revert while the global FIFO head (nextExecuteId) is a pending order whose commitTime is earlier than the settlement snapshot's publishTime. The orders are FIFO by commit time, so checking the head is enough. Its fill tick then lies at or before the settlement mark. This covers closes as well as opens, and every pending order, not just one: settlement can then only run once no order with a fixed pre-settlement fill is left, so the settler has no prefix to choose. A second option is to execute, or expire, such orders first in the same call. Each order expires within its execution window (60 s by default), so either option delays settlement by at most one window, and the existing expiry and terminal rules prevent a held head from blocking settlement for longer. A regression test like test_Property_DepositorDoesNotInheritFixedFillObligation above covers it. This is a sketch; it has not been implemented or run against the maintainers' suite.

Link to Proof of Concept

https://gist.github.com/Richter2552/02c222de349d148bb3a02fe83011aec8

Proof of Concept

Proof of Concept

The program requires PoCs to run in the repository's Foundry test suite at the commit in scope without modifying the contracts in scope. The test file below extends the maintainers' AtomicLpEpochSettlementTestFixture (packages/perps/test/perps/shared/AtomicLpEpochSettlementFixture.sol). After the fixture's setUp it uses public entry points only, from accounts with no role:

  • TrancheVault request/claim.
  • HousePool.settleLpEpoch while no position is open (permissionless then, SECURITY.md:319).
  • The production V3 OrderRouter.commitOrder(OrderRequest), from the trader's own account.
  • router.updateMarkPrice, router.settleLpEpoch and router.executeOrder.

Pyth is the maintainers' MockPyth, with explicit per-feed payloads that satisfy the oracle's unique-historical-tick check. USDC is the fixture's mock token. Both are outside the scope. No protocol contract is pranked and no storage is written.

Fixture notes, disclosed:

  • The maintainers' BasePerpTest deploys the Router as LegacyOrderRouterHarness (test/utils/LegacyOrderRouterHarness.sol). It is a subclass of OrderRouter that adds only a scalar commitOrder adapter (it builds a V3 request and delegatecalls the production commit) and an IS_TEST constant. It overrides no settlement or execution function, and this test does not use the adapter: it calls the V3 commit directly. So the code that settles and executes is the production Router's.
  • BasePerpTest also seeds 1,000 USDC junior and 1,000 USDC senior through initializeSeedPosition (held by the test contract), so junior equity is about 201,000 USDC.
  • The ticks carry zero confidence, with all basket feeds moving together. This is a controlled fixture choice, not a production-parameter calibration.
  • The fixture's risk and pool parameters are valid contract configuration (the Engine constructor accepts them, CfdEngine.sol:304-327), but they are not the repository's initial release defaults:
Parameter Fixture (this PoC) Initial release defaults
VPI factor 0 0.01e18
Maximum skew ratio 1e18 0.4e18
Maintenance / initial margin (bps) 100 / 150 10 / 20
Junior / senior seed 1,000 USDC each 1 settlement-token unit each (1e6)
Senior exposure limit / senior share limit type(uint256).max - 1 (effectively unbounded) / 9,999 bps 40,000,000 units (40_000_000e6) / 8,000 bps

Sources. Fixture: packages/perps/test/perps/shared/AtomicLpEpochSettlementFixture.sol:124-145 and packages/perps/test/perps/BasePerpTest.sol:115-116,168-208,255-260. Release: packages/perps/DEPLOYMENT.md:123-156 (checked-in script and constructor defaults, which that document says are not a claim about any live deployment) and script/DeployPerpsArbitrumSepolia.s.sol:434-446.

The amounts this PoC prints are fixture-configuration measurements. The same root was re-run at the release parameters: the release script's own deployment, VPI 0.01, skew cap 40% and a 500M junior seed (see "Release-parameter run" below). The ordering effect reproduces there. At this PoC's sizes the 500M seed dilutes it to 0.048 USDC. With a 20M pending LONG and 50M entering and exiting cohorts, it moves:

  • 185.29 USDC with no price move, because the pending order's VPI (2,594.08 USDC) also lands on whichever cohort the call order picks;
  • 50.79 USDC at 1 bp;
  • 497.68 USDC at 5 bp.

The account that orders the calls receives nothing. A competing keeper that executes at the fill tick removes the price part for orders whose fill precedes the boundary. It does not remove the VPI part: a same-second race still moves 185.29 USDC.

Each test of the single-open case runs the same state twice from one snapshot: A = executeOrder then settleLpEpoch, B = settleLpEpoch then executeOrder, with the same ticks. Each of those runs asserts that B settles with the order pending and A with none, that the order executes in both, and that both end with the same position size, margin, entry (the fill, 1.00) and Engine mark and mark time. It also asserts the redeemer is fully funded. The two wider cases below make fewer assertions; each bullet lists exactly what its runs assert. The property tests state the behaviour the code should have and fail on the pinned code. The control and characterize tests pass.

The last section of the file covers the two wider cases, with the same LP setup:

  • Pending close. TRADER opens a 50,000 LONG at 1.00 before the epoch, and it executes. TRADER then commits a full close at b − 10, with the fill at 1.00 at b − 9. Arm A executes the close and then settles; arm B settles and then executes the close. Both arms use the production V3 commit with isClose = true. Each arm asserts that the close executes, that TRADER is flat afterwards, and that the redeemer is fully funded; it also asserts the pending-close count at settlement (0 in A, 1 in B). The arms do not compare trader cash or claims, carry indexes or the final mark. The depositor's change is not the exact negative of the redeemer's in this case. At −1%, ALICE (redeemer) is paid 124.378153 USDC less in B, and CAROL's (depositor's) final value is 124.611013 higher. At +1%, ALICE is paid 124.378066 more, and CAROL is 124.146056 lower. The test does not account for the other balances (BOB, ALICE's retained shares, the seed holders, reserves, carry), so it shows the redeemer's payout depending on call order, not an exact depositor-to-redeemer transfer.
  • FIFO prefix. T1, T2 and T3 commit opens at b − 13, b − 12 and b − 11 (LONG 50,000, SHORT 80,000, LONG 40,000; fills at 1.00). For each k from 0 to 3, the first k execute, then the epoch settles, then the rest execute. Each run asserts that every execution returns Executed, that the final sizes are 50,000, 80,000 and 40,000, and that the redeemer is fully funded. Entry, margin, the final mark and time, the pending counts at settlement, trader balances and claims are not compared across prefixes.

Run instructions (from a checkout of immunefi-team/audit-comp-plether at a82d4fefb02768e5b3bddcc97dee371eee24fea8 with submodules; solc 0.8.35 via the repository's packages/perps/foundry.toml):

Bash
cp Card8240S1SettleBeforePendingFill.t.sol packages/perps/test/perps/spec/lp/
cd packages/perps

forge test --match-contract '^Card8240S1SettleBeforePendingFillTest$' --match-test '^test_Property_' -vv

forge test --match-contract '^Card8240S1SettleBeforePendingFillTest$' --match-test '^test_(Control|Characterize)_' -vv

PoC output (pinned code, unmodified contracts)

Run against the pinned commit (forge 1.8.1, solc 0.8.35, via-IR). Result: the six control and characterize tests pass, and the five property tests fail. Excerpt of forge test -vv for the five tests of the single-open case (USDC amounts in 6-decimal units; prices in 8 decimals; order status 2 = Executed):

CONSOLE
[PASS] test_Characterize_RedeemerSettlesFirstHerself() (gas: 18324756)
Logs:
  settler = ALICE, -1%: ALICE gain / CAROL loss (USDC 6dp) 124378110 124378126
  BOB value A / B 99751234670 99751234681

[PASS] test_Characterize_Scaling() (gas: 73038662)
Logs:
  move (bps) / CAROL loss (USDC 6dp) 1 1243781
  move (bps) / CAROL loss (USDC 6dp) 5 6218906
  move (bps) / CAROL loss (USDC 6dp) 20 24875625
  move (bps) / CAROL loss (USDC 6dp) 100 124378126

[PASS] test_Control_FlatMark_Ord

The original report as published on Immunefi, by argo_the_hacker. 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 settlement path never reads the order queue, so an order whose fill tick is already published is excluded from the settlement NAV and its PnL lands on post-settlement share holders instead.

Impact

Value could move between the epoch's depositors and redeemers, but only by a few basis points of the losing cohort's position, only when an order is pending at the boundary, and the protocol loses nothing in aggregate.

What the attacker needed

An order pending at the epoch boundary; its fill tick already published; LP deposit and redemption in the same epoch; actor's calls land before other keepers

The fix

Settlement should revert or first execute/expire any pending order whose fill is already fixed before pricing the epoch, so no prefix of the queue can be chosen.

How it was found

  1. Commit a trader order shortly before an epoch boundary so its fill tick is published but it is not yet executed.
  2. Have an LP request redemption and another deposit within the cutoff for the same epoch.
  3. Call settleLpEpoch before executeOrder, or executeOrder before settleLpEpoch, to change the ordering.
  4. Observe the redeemer's payout and the depositor's share value differ between the two orderings while the final position is identical.

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.

Liquidity providers put money into a pool and get shares; once an hour the pool works out what those shares are worth so people can join or leave at a fair price. A trader's order can have its price locked in before that hourly calculation but only actually run afterwards, and the calculation ignores it. So whoever triggers the two actions in a particular order decides whether the new joiners or the leavers absorb that order's profit or loss.

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 argo_the_hacker

View all

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