Permissionless protection retries prevent owners from amending failed close limits, freezing position funds for over 24 hours
A permissionless retry function lets any third party move a failed stop-loss protection from the Latched state back to Triggered, which removes the only state in which the owner can raise their close debit cap. By repeating this before each owner amendment, a third party can keep a plain-EOA owner locked out of closing or cancelling the position for over 24 hours while losses grow.
- Disclosed after under an hour
#98559 [SC-High] Permissionless protection retries prevent owners from amending failed close limits, freezing position funds for over 24 hours
Submitted on Nov 8th 2026 at 17:46:26 UTC by @Mukymuk for Audit Competition | Plether
- Report ID: #98559
- Report Type: Smart Contract
- Report severity: High
- Target: https://github.com/immunefi-team/audit-comp-plether/tree/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/src
- Impacts:
- Temporary freezing of funds for at least 24 hours
Description
Brief/Intro
When a stop-loss fires on Plether, the close can fail if the price has gapped past the stop and the close now costs more than the owner's own debit cap. The protocol's recovery for that case is a state, Latched, in which the owner can raise the cap and retry.
Anyone can take that state away. retryPositionProtectionClose is permissionless and moves the protection from Latched back to Triggered, where the owner can no longer amend the cap, cancel the protection or close the position. A third party who repeats this every time the 60-second close order expires keeps a plain-EOA owner locked out.
With the release parameters, a local test keeps the lock for 24 h 39 s. At the end, with a fresh oracle, the position is still open and only the 500 USDG of free margin outside it can be withdrawn. From the same state without the third party, the owner closes the position and withdraws 3,491.20 USDG in total, about 2,991.20 USDG more than the lock allows.
While the lock lasts, the position stays open and its loss keeps growing. If the price keeps moving against it, the owner ends with 2,000.80 USDG less than without the third party (price rising to 1.40), or 2,985.70 USDG less if the position reaches its liquidation price. The third party's gas for the cycles in those tests is under $1.
The lock depends on ordering: the third party's retry has to land before the owner's amendment each time. A local test chooses that order; it cannot show who wins inclusion on a live network. Owners whose account can batch calls in one transaction (EIP-7702) escape at any point; the affected owners are plain EOAs.
Vulnerability Details
All references are under packages/perps/ at commit a82d4fefb02768e5b3bddcc97dee371eee24fea8.
The owner's remedy. After a failed protected close, the owner is meant to amend the close limits and retry. The interface gives the owner this remedy after a relatch (src/interfaces/IPositionProtectionActions.sol L32–37). amendLatchedPositionProtectionCloseLimits allows it only for the owner, only in Latched, and only with no pending order (src/PositionProtectionBook.sol L315–327). Failed-attempt relatching and owner amendment are documented recovery behaviour (WORKING_WITH_AI_AGENTS.md L282–286, SECURITY.md L730–731).
Who else can use the state. retryPositionProtectionClose accepts any caller while the protection is Latched (src/PositionProtectionBook.sol L382–406). It returns the protection to Triggered with a new close order that carries the old limits. Latched has a single writer, handleFailedProtectionAttempt (L666), reached both from expiry (src/OrderRouter.sol L226) and from a failed execution (src/OrderRouter.sol L328). It records nothing about where it came from, so the permissionless retry accepts both.
The owner's other exits are closed while protection is active. An ordinary close reverts with ProtectionActive (src/router/OrderLiquidationBatchLogic.sol L313–314). cancelPositionProtection and the atomic cancelPositionProtectionAndCommitClose revert with ProtectionNotArmed outside Armed (the latter at src/PositionProtectionBook.sol L346–348; both asserted in the PoC). Amendment needs Latched.
The cycle.
- The stop fires. Protection becomes
Triggeredand a close order is queued with the default 60-second execution window. - The price has gapped past the stop, so the close debits more than the owner's
maxGrossAccountDebitAssets. An honest keeper executes the order and it fails withConstraintViolation/GrossAccountDebit. Protection becomesLatched. - If a third party's
retryPositionProtectionCloselands before the owner's amendment, protection is back inTriggeredwith a new order and the old cap. The owner's amendment reverts (ProtectionNotLatched), and cancel and close revert as before. - The new order cannot fill, because the cap has not changed. When its window ends, the third party expires it and retries in the same transaction (
executeOrderandexpireOrderare permissionless,src/OrderRouter.solL240 and L191), soLatchedis never visible between blocks. - Step 4 repeats. Honest keeper executions in between also fail on the cap and relatch, and the third party retries again.
The repository already tests repeated retries and owner amendment separately. What this report adds is their composition: a permissionless retry consumes the only state in which the owner's documented recovery works, and nothing reserves that opportunity for the owner. Respecting the owner's financial cap is correct; making its amendment unreachable is the failure.
Why this is not the intended design. The repository documents every piece separately, and this report relies on that documentation:
- The program treats keepers as untrusted: "anyone can execute orders, liquidations, price updates and protections, so harm caused by any caller acting as a keeper is in scope." The third party here only calls permissionless keeper functions.
- The acknowledged Cecuro finding MED-9 ("Keepers can retry protection closes without the trader's financial limits") was answered by keeping the owner's ceilings on every retry, with this caveat: "Tight limits may prevent execution until conditions improve or the owner amends them." That accepted limitation depends on the owner being able to amend. The cycle removes exactly that: the owner's ceilings stay, and the amendment never becomes reachable. The program accepts reports on acknowledged findings that show the fix is incomplete.
- The operational safeguard is "operators must alert on prolonged Latched state without a live child" (
SECURITY.mdL1356–1359). The cycle always keeps a live child, soLatchednever persists and that alert never fires. - Keeper guidance says a conservative worker should "not continuously queue the same failing attempt" (
DEPLOYMENT.mdL419–421). An untrusted keeper does not have to follow it. - The repository's own test
test_ProtectionCloseLimits_OnlyOwnerCanAmendLatchedLimitsForNextRetry(PositionProtection.t.solL954–1004) asserts that once a third party retries, the owner's amendment reverts withProtectionNotLatched(L995); in that test the owner had already amended, so the retry closes.test_RepeatedProtectionAttemptExpiryRetry_ConservesSingleBounty(L1558) runs repeated third-party expire-and-retry cycles and checks only that bounties and settlement are conserved. Neither considers a third party repeating the retry before the owner can amend.
Relationship to known issues. The AI-scan item "Protection trigger bounty is paid before a zero-bounty close is executed" (audits/scan-plether-fi-plether-core-d4541b49.md L542–584) describes the same exposure (the position "can remain open through its stop-loss/take-profit threshold and incur further loss or liquidation"), but from a different cause: keepers having no incentive to execute a zero-bounty close. In that case nothing blocks recovery: the order expires, protection becomes Latched, and the owner amends and exits (X5b in the PoC). Here honest keepers do execute and the close fails on the cap (X5a); what blocks the owner is the permissionless retry consuming Latched. Cecuro MED-15 accepts "temporary execution unavailability when no positive valid quote exists"; here a valid quote exists and is executed. Cecuro MED-30 is about stops not firing while the market is closed; here the stop fires. Cecuro MED-7 needs an older signed price; nothing like that is used here.
Impact Details
Selected impact: High, Temporary freezing of funds for at least 24 hours.
Measured with the release parameters (LONG of 10,000 at 1.00, 5,000 USDG margin, stop at 1.10, cap 1.5 times the stop-close debit, price gapping to 1.20):
| After 24 h 39 s of the cycle, fresh oracle at 1.20 | Value |
|---|---|
| Position | still open (size 10,000) |
| Free margin outside the position | 500 USDG, withdrawable |
| Position-backed balance | 4,995.50 USDG; withdrawing even 1 unit reverts MarginClearinghouse__InsufficientFreeEquity |
| Control, same state, no third party: owner expires, amends, retries, keeper closes at 1.20, owner withdraws | 3,491.20 USDG in total (including the 500 USDG free margin) |
The value kept from the owner for over 24 hours is about 2,991.20 USDG: the 3,491.20 USDG the owner withdraws in the control, less the 500 USDG that stays withdrawable during the lock. During the lock the position also stays exposed to price; the stop-loss that should have closed it cannot complete. Carry over the 24 hours is negligible (0.003436 USDG at the checkpoint).
Damage while locked. The stop-loss exists to cap the loss. While the owner is locked out, the position keeps losing if the price keeps moving. Owner USDG actually received at the end (balanceOf after withdrawing everything allowed), same position and cap:
| Branch | Owner receives | vs control |
|---|---|---|
| Stop works: close at 1.10 | 3,991.60 USDG | +1,000.40 |
| Control: the gap close fails at 1.20; no third party; the owner amends and closes at 1.20 | 2,991.20 USDG | 0 |
| D1: the cycle runs while the price rises to 1.30 and 1.40; then the owner closes at 1.40 | 990.40 USDG | −2,000.80 |
D2: the cycle runs until the first liquidatable price (1.498); the position is liquidated while Triggered |
5.50 USDG | −2,985.70 |
The control already contains the gap loss; the difference from the control is what the lock adds. It scales with how far the price moves while the owner is locked out: on this 10,000 position, each 0.01 of further rise costs the owner about 100 USDG (D1: 2,000.80 for 0.20). In D1 and D2 the moves happen over 15 cycles (about 15 minutes). Liquidation works normally while the protection is Triggered (PositionLiquidated is emitted and the protection ends Liquidated), and in D2 it leaves no bad debt. The lock does not create a solvency problem; it removes the owner's exit while the loss grows.
Who is affected: owners using a plain EOA. An owner with EIP-7702 batching escapes in one transaction at any point, even after the cycle has started (tests E4a–E4c in the PoC). A plain EOA cannot: its own execution relatches the protection, and a third-party retry that lands before its amendment closes the window again (E4d).
Preconditions:
- The owner set a finite close cap and a price gap pushed the close debit above it. In the test the cap is 1.5 times the debit at the stop (1,505.85 USDG); at the stop the close succeeds (1,003.90 USDG, G1), and after the gap it fails (2,004.30 USDG, G2). No claim is made about gap frequency.
- The position has enough margin to stay open during the lock (it does, in the test).
- A third party keeps retrying, and each retry lands before the owner's amendment.
Cost to the third party. It earns nothing and pays gas for one expire-and-retry transaction per window. Measured execution gas is 1,113,356 per cycle, identical over 10 cycles. An estimated execution gas after a cold-access adjustment, adding EIP-2929 cold surcharges for the 13 accounts and 112 storage slots one cycle touches, is about 1,367,356; this is an estimate, not a measurement or a strict upper bound. Adding the 21,000 base gas, at 0.020 gwei (Arbiscan, 7 Nov 2026) and ETH at $2,243.46 (DappAtlas, citing CoinGecko, 7 Nov 2026), one cycle costs about $0.05–0.06:
| Period | Cycles | Third-party cost |
|---|---|---|
| D1 / D2 lock in the tests | 15 | $0.76–0.93 |
| One hour | 59 | $3.00–3.68 |
| One day | 1,417 | $72–88 |
L1 data posting and extra inclusion fees are not included.
The program's griefing rule: "spending USD 1 to cause USD 10 or less in damage is Griefing, while spending USD 1 to cause USD 100 or more in damage is not." Cost and damage depend on how long the lock lasts and how far the price moves meanwhile. In D1 and D2, 15 cycles (under $1 of gas) keep the owner locked out while the position loses 2,000.80–2,985.70 USDG more than without the third party, a ratio well above 100. In the 24-hour run the price stays at 1.20: the third party spends about $72–88 and the effect is the freeze itself, with no further loss. The damage therefore requires the price to keep moving against the position during the lock; the third party does not cause that move, it blocks the owner's documented exit while it happens.
The program states: "Impact is calculated first, separately from feasibility. Feasibility limitations do not change the impact or severity of a finding, only the amount paid for it." If triage applies the program's griefing rule, or accepts a duration shorter than 24 hours, the same evidence meets Medium (Temporary freezing of funds for at least 1 hour).
Recommended fix
Let the owner stage new limits while the protection is Triggered, so the next attempt uses them, while the live attempt keeps its committed bounds. A prototype:
// in amendLatchedPositionProtectionCloseLimits, after loading the owned protection:
if (protection.status == PositionProtectionTypes.PositionProtectionStatus.Triggered) {
// Stage limits for the next attempt; the live attempt keeps its committed bounds.
_setCloseLimits(protection, limits);
_emitCloseLimitsUpdated(protection);
return;
}
Two regression tests start after the third party's retry, with a plain EOA owner (P1, P2 in the PoC). Both fail on the original code with ProtectionNotLatched and pass with the change: the next attempt carries the owner's new cap and the position closes. In the repository's PositionProtection.t.sol suite, the change passes 103 of 104 tests. The one failure, test_ProtectionCloseLimits_OnlyOwnerCanAmendLatchedLimitsForNextRetry, asserts the exact rule the change relaxes; the part of it that checks the live order keeps its committed limits still holds (P2). The function's NatSpec, which currently promises amendment only in Latched, should be updated with the change. An owner-only window after a relatch would be an alternative.
Proof of Concept
Step-by-step
All results come from local Foundry tests at commit a82d4fefb02768e5b3bddcc97dee371eee24fea8. No public network was used.
Configuration: the release parameters from DEPLOYMENT.md and the deploy script (margins 10/20 bps, execution fee 4 bps, Senior cap 80%, 1 USDG seeds, protection trigger bounty, router and oracle values, 60-second execution window). HT1V6Base._assertLaunchConfig asserts each one.
-
Alice opens a LONG of 10,000 at 1.00 with 5,000 USDG margin and a stop-loss at 1.10 (in this protocol a LONG loses when the price rises). Her protection's
maxGrossAccountDebitAssetsis 1.5 times the close debit at the stop: 1,505.85 USDG. Control G1: executed at the stop, the close debits 1,003.90 USDG and succeeds. -
The stop fires and the price gaps to 1.20. The close would now debit 2,004.30 USDG. An honest keeper executes it inside the 60-second window and it fails with
ConstraintViolation/GrossAccountDebit. Protection becomesLatchedand the position stays open (G2). -
Before Alice amends, a third party (
RetryCycler, a plain helper contract) callsretryPositionProtectionClose. Protection isTriggeredagain, with a new close order and the same cap. -
Alice tries every exit. Each reverts with an exact selector:
amendLatchedPositionProtectionCloseLimits -> OrderRouter__ProtectionNotLatched() 0x5b54e624
cancelPositionProtection -> OrderRouter__ProtectionNotArmed() 0x2dee7d8f
commitOrder (ordinary close) -> OrderRouter__ProtectionActive() 0x3a0535a3
-
The new order cannot fill, because the cap is unchanged. When its window ends, the third party expires it and retries in one transaction.
Latchednever appears between blocks, and Alice's three calls revert again. -
Step 5 repeats 1,417 times. Halfway through, a second honest keeper execution fails the same way and relatches, and the third party retries again before Alice. The lock lasts 86,439 seconds (24 h 39 s) with the window still at 60 seconds (asserted).
-
At the end, with a fresh oracle at 1.20:
| Value | |
|---|---|
| Position size | 10,000 (still open) |
| Free margin (500 USDG extra deposit) | withdrawable: 500 USDG |
| Position-backed balance | 4,995.50 USDG; withdraw(1) reverts MarginClearinghouse__InsufficientFreeEquity() 0x024ec6ee |
| Control from the same state, no third party: expire, amend, retry, keeper closes at 1.20, withdraw | 3,491.20 USDG withdrawn in total (the snapshot is taken before the free-margin withdrawal, so this includes the 500 USDG); size 0 |
Who can escape (EIP-7702)
executeOrder and expireOrder are permissionless, so an owner who can batch calls in one transaction escapes even after the cycle has started:
| Test | Owner action in one transaction | Result |
|---|---|---|
| E4a | executeOrder(live order) fails on the cap → Latched; amend; retry | new order executes at 1.20; closed |
| E4b | after the deadline: expireOrder; amend; retry | closed |
| E4c | the third party wins the expiry block; the owner repeats E4a on the new live order | closed |
| d | a batch that names an order the third party already replaced | reverts OrderRouter__OrderNotPending() (stale target) |
| E4d | plain EOA: its own executeOrder relatches; a third-party retry lands before its amend | amend reverts ProtectionNotLatched; position open |
Controls
| Test | Result |
|---|---|
| X1, ordinary close during the lock (both commit overloads) | ProtectionActive; no order created |
X2, atomic cancel-and-close while Triggered |
ProtectionNotArmed |
X2C, control while Armed |
atomic cancel-and-close executes; size 0 |
| X3, free margin during the lock | 250 of the 500 USDG free margin withdrawn; withdrawing the rest of the balance reverts InsufficientFreeEquity |
| X4, owner expires the order herself | Latched, but cancel-and-close, ordinary close and cancel still fail |
| X5a, retry without amending | keeper at 1.20 fails on the cap (2,004.30 > 1,505.85 USDG); relatches |
| X5b, expire, amend, retry as three owner transactions, no third party | cap raised to 25,000 USDG; keeper executes at 1.20; size 0 |
| a, three cycles | amend, cancel and close fail each time with the selectors above |
| b, 5,000 USDG deposit during the lock | owner paths still fail with the same selectors |
| c, 7702 batch before any cycle | expire, amend, retry; closed at 1.20 |
Damage while the lock lasts (HT1V7Damage)
Same position, cap and gap. "Received" is the owner's wallet USDG after withdrawing everything getWithdrawableAssets allows, measured from the moment the stop fires.
| Branch | What happens | Owner receives | vs control |
|---|---|---|---|
| STOP | the order executes at 1.10 | 3,991.60 | +1,000.40 |
| CONTROL | fails at 1.20 on the cap → Latched; no third party; owner amends and retries; keeper closes at 1.20 |
2,991.20 | 0 |
| D1 | gap failure → third-party retry → cycle: 5 cycles at 1.20, fresh mark 1.30 and 5 cycles, fresh mark 1.40 and 5 cycles; then the cycle stops and the owner expires, amends, retries; keeper closes at 1.40 | 990.40 | −2,000.80 |
| D2 | same cycle up to 1.40; then the first liquidatable price on a 0.001 grid (1.498); router.executeLiquidation with fresh price data while the protection is Triggered and the third party's order is live |
5.50 | −2,985.70 |
D2 details: previewLiquidation reports liquidatable with equity 5.499965 USDG and a 5 USDG keeper bounty; executeLiquidation does not revert; PositionLiquidated is emitted for the owner at 1.498; position size 0; protection status Liquidated; the third party's order ends Failed; the owner withdraws the remaining 5.499965 USDG.
Third-party cost (HT1V7Gas)
The measured call is RetryCycler.atomicExpireAndRetry (router.expireOrder + retryPositionProtectionClose) under the release configuration. Execution gas only; the 21,000 base gas and calldata are not included.
| Value | |
|---|---|
G1: 10 consecutive cycles, vm.lastCallGas().gasTotalUsed |
1,113,356 every cycle |
G1: same cycles, gasleft() delta (includes the test's call overhead) |
1,116,951 average |
| G2: accounts / storage slots touched by one cycle | 13 / 112 |
| G2: estimated execution gas after a cold-access adjustment, warm gas + EIP-2929 surcharges ((13 − 1) × 2,500 + 112 × 2,000) | about 1,367,356 (estimate, not a strict upper bound) |
vm.cool() and --isolate did not change the measured gas on this forge version, so the cold figure is derived from the access counts rather than measured.
Fix prototype
With the change from the Description applied, P1 and P2 (both start after the third party's retry, plain EOA owner) pass: the owner's new cap is used by the next attempt and the position closes. On the original code both fail with ProtectionNotLatched. Tests that assert the original rule (a, b, E4d, H24) fail on the patched copy, as expected.
Running the tests
Save the five files below, plus the two posted as a comment on this report (HT1V7Gas.t.sol, HT1V6OwnerAmendWhileTriggered.t.sol), in packages/perps/test/perps/spec/trader/ (they import ./PositionProtection.t.sol from that folder, so they must not go in a subfolder). From the repository root:
forge test --offline --root packages/perps --match-path 'test/perps/spec/trader/HT1V6*.t.sol' --match-test test_HT1V6 --gas-limit 18446744073709551615 -vv
forge test --offline --root packages/perps --match-path 'test/perps/spec/trader/HT1V7*.t.sol' --match-test test_HT1V7 -vv
With all seven files, on the original code: the HT1V6 files give 20 passing tests, and P1, P2 fail (they test the fix); the HT1V7 files give 5 passing tests. The gas test and the fix tests (P1, P2) did not fit in this field's 65,536-character limit and are posted as a comment right after submission.
RetryCycler.t.sol
// SPDX-License-Identifier: AGPL-3.0
pragma solidity 0.8.35;
// Companion helper only; no additional scenario tests. Run the importing test files with forge test --offline --root packages/perps --match-path 'test/perps/spec/trader/<File>.t.sol' -vv.
import {OrderRouter} from "@plether/perps/OrderRouter.sol";
import {OrderV3Types} from "@plether/perps/OrderV3Types.sol";
import {IPositionProtectionActions} from "@plether/perps/interfaces/IPositionProtectionActions.sol";
/// @notice Test helper. Property under test: once a protection close child fails or expires, the
/// documented `Latched` remedy (owner amends close limits) stays available to the owner. This helper
/// sequences permissionless calls (execute/expire, then retryPositionProtectionClose) to check whether
/// `Latched` remains observable between transactions.
contract RetryCycler {
OrderRouter public immutable router;
IPositionProtectionActions public immutable protectionActions;
constructor(
OrderRouter router_,
IPositionProtectionActions protectionActions_
) {
router = router_;
protectionActions = protectionActions_;
}
function atomicFailAndRetry(
uint64 childOrderId,
uint64 protectionId,
bytes[] calldata pythUpdateData
) external payable returns (OrderV3Types.ExecutionResult memory execResult, uint64 newChildOrderId) {
execResult = router.executeOrder{value: msg.value}(childOrderId, pythUpdateData);
newChildOrderId = protectionActions.retryPositionProtectionClose(protectionId);
}
function atomicExpireAndRetry(
uint64 childOrderId,
uint64 protectionId
) external returns (OrderV3Types.ExecutionResult memory execResult, uint64 newChildOrderId) {
execResult = router.expireOrder(childOrderId);
newChildOrderId = protectionActions.retryPositionProtectionClose(protectionId);
}
/// @notice Single permissionless retry, sent as its own transaction (not atomic with any execution).
function retryClose(
uint64 protectionId
) external returns (uint64) {
return protectionActions.retryPositionProtectionClose(protectionId);
}
receive() external payable {}
}
HT1V6Base.t.sol
// SPDX-License-Identifier: AGPL-3.0
pragma solidity 0.8.35;
// Shared launch-configuration base for the HT1 v6 tests (helper only; no tests of its own).
// Place in packages/perps/test/perps/spec/trader/ next to PositionProtection.t.sol and RetryCycler.t.sol.
//
// Launch parameters (packages/perps/DEPLOYMENT.md "Initial release parameters" and
// script/DeployPerpsArbitrumSepolia.s.sol): risk params set through the Engine constructor (_riskParams),
// Senior limits $40M / 80% and the Router/Oracle release values set through the governed 72h paths, 1 USDG seeds.
// Sign convention (PositionProtection.t.sol:65-66): a LONG loses when the price RISES (stop-loss above entry).
import {RetryCycler} from "./RetryCycler.t.sol";
import {PositionProtectionTest} from "./PositionProtection.t.sol";
import {CfdTypes} from "@plether/perps/CfdTypes.sol";
import {OrderV3Types} from "@plether/perps/OrderV3Types.sol";
import {ICfdEngineRiskParamsView} from "@plether/perps/interfaces/ICfdEngineRiskParamsView.sol";
import {IOrderLifecycleBook} from "@plether/perps/interfaces/IOrderLifecycleBook.sol";
import {IOrderRouterAdminHost} from "@plether/perps/interfaces/IOrderRouterAdminHost.sol";
import {PositionProtectionTypes} from "@plether/perps/interfaces/PositionProtectionTypes.sol";
import {Vm} from "forge-std/Vm.sol";
/// @dev Minimal EIP-7702 delegation: the EOA calls itself and executes N calls atomically (reverts as a whole).
contract BatchExec7702V6 {
struct Call {
address target;
uint256 value;
bytes data;
}
function exec(Call[] calldata calls) external payable {
require(msg.sender == address(this), "only self");
for (uint256 i; i < calls.length; ++i) {
(bool ok, bytes memory ret) = calls[i].target.call{value: calls[i].value}(calls[i].data);
if (!ok) {
assembly {
revert(add(ret, 32), mload(ret))
}
}
}
}
receive() external payable {}
}
abstract contract HT1V6Base is PositionProtectionTest {
uint256 internal constant OWNER_PK = 0xA11CE7702;
uint256 internal constant SIZE = 10_000e18; // 10,000 synthetic units; multiple of SIZE_QUANTUM (1e20)
uint256 internal constant MARGIN = 5_000e6; // survives the gap price below with launch margins 10/20 bps
uint256 internal constant ENTRY = 1e8;
uint256 internal constant STOP = 1.1e8; // LONG stop-loss (LONG loses as price rises)
uint256 internal constant GAP = 1.2e8; // price jumps past the stop before the child executes
uint256 internal constant WIDE = 25_000e6;
struct Exec {
uint8 status;
uint8 reason;
uint8 constraint;
uint256 actual;
uint256 limit;
bool receipt;
}
// ---- Launch configuration ----------------------------------------------------------------------------
function _initialJuniorSeedDeposit() internal pure override returns (uint256) { return 1e6; }
function _initialSeniorSeedDeposit() internal pure override returns (uint256) { return 1e6; }
function _riskParams() internal pure override returns (CfdTypes.RiskParams memory) {
return CfdTypes.RiskParams({
vpiFactor: 0.01e18,
maxSkewRatio: 0.4e18,
maintMarginBps: 10,
initMarginBps: 20,
fadMarginBps: 300,
baseCarryBps: 500,
minBountyAssets: 1e6,
bountyBps: 10,
keeperShareBps: 5000,
protocolShareBps: 0
});
}
/// PositionProtectionTest.setUp is not virtual: every HT1 v6 test applies the launch configuration first.
modifier launched() {
_launch();
_;
}
function _launch() internal {
_setSeniorCapacity(40_000_000e6, 8000);
IOrderRouterAdminHost.RouterConfig memory rc = _routerConfig();
rc.minOpenNotionalAssets = 1000e6;
rc.adverseConfidenceMultiplierBps = 2500;
rc.basketMaxConfidenceRatioBps = 10;
rc.maxPendingOrders = 5;
rc.positionProtectionTriggerBountyAssets = 200_000;
_setRouterConfig(rc);
// The governed paths warp 2 x 72h (into a weekend, oracle frozen): move to the next Monday 10:00 UTC.
vm.warp(SETUP_TIMESTAMP + 7 days);
vm.roll(vm.getBlockNumber() + 1);
_refreshMark(ENTRY);
_assertLaunchConfig();
}
function _assertLaunchConfig() internal view {
CfdTypes.RiskParams memory rp = ICfdEngineRiskParamsView(address(engine)).riskParams();
assertEq(rp.vpiFactor, 0.01e18, "vpiFactor");
assertEq(rp.maxSkewRatio, 0.4e18, "maxSkewRatio");
assertEq(rp.maintMarginBps, 10, "maintMarginBps");
assertEq(rp.initMarginBps, 20, "initMarginBps");
assertEq(rp.fadMarginBps, 300, "fadMarginBps");
assertEq(rp.baseCarryBps, 500, "baseCarryBps");
assertEq(rp.minBountyAssets, 1e6, "minBountyAssets");
assertEq(rp.bountyBps, 10, "bountyBps");
assertEq(rp.keeperShareBps, 5000, "keeperShareBps");
assertEq(rp.protocolShareBps, 0, "protocolShareB
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 permissionless retry function accepts the Latched state without reserving a window for the owner to amend the close limits, so a third party can consume the only state in which the owner's documented recovery works.
Impact
A plain-EOA owner could be kept from closing or amending the position for over 24 hours, with about 2,991.20 USDG of value locked and further losses of up to 2,985.70 USDG if the price keeps moving against the position; owners who can batch calls in one transaction (EIP-7702) escape.
What the attacker needed
Owner set a finite close debit cap; price gap pushed close debit above the cap; position has enough margin to stay open; third party retries before each owner amendment
The fix
The owner should be allowed to stage new close limits while the protection is Triggered, so the next attempt uses them while the live attempt keeps its committed bounds.
How it was found
- The owner opens a position with a stop-loss and a finite close debit cap; the stop fires and the price gaps so the close would exceed the cap.
- An honest keeper executes the close order and it fails on the debit constraint, moving the protection to Latched.
- Before the owner amends, a third party calls the permissionless retry, returning the protection to Triggered with the old cap.
- The owner's amendment, cancel and ordinary close all revert because the protection is no longer Latched.
- When the new order's window expires, the third party expires it and retries in one transaction so Latched is never visible between blocks.
- The cycle repeats, keeping the owner locked out while the position stays open.
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 stop-loss is meant to close a losing trade automatically. Here the close failed because the price jumped and the trade would cost more than the owner had allowed, so the system put the protection into a special state where the owner could raise that limit and try again. The report shows that anyone can call a public function to knock the protection out of that state, and by doing so repeatedly they stop the owner from ever raising the limit, leaving the trade open and losing money.
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.