Any account's retry blocks the owner's amend of a failed stop-loss (incomplete MED-9 fix): the position stays open past its stop
The owner's documented ability to amend a latched stop-loss protection's close limits can be blocked by any other account calling the permissionless retry, which flips the status back to Triggered. The trader's position then stays open past its stop, exposing it to adverse market moves until the owner finds an undocumented workaround.
- Disclosed after under an hour
#99399 [SC-High] Any account's retry blocks the owner's amend of a failed stop-loss (incomplete MED-9 fix): the position stays open past its stop
Submitted on Nov 13th 2026 at 13:52:09 UTC by @Lester for Audit Competition | Plether
- Report ID: #99399
- Report Type: Smart Contract
- Report severity: High
- Target: https://github.com/immunefi-team/audit-comp-plether/tree/a82d4fefb02768e5b3bddcc97dee371eee24fea8/packages/perps/src
- Impacts:
- Griefing (e.g. no profit motive for an attacker, but damage to the users or the protocol)
Description
Brief/Intro
The documents promise that after a failed protection close the trader who owns the protection ("the owner") can change its close limits before the next attempt:
- "If a queued close fails and the protected side and size still match, protection becomes
Latched; the owner may amend its limits before retrying." (packages/perps/WORKING_WITH_AI_AGENTS.md:283-284) - "The owner may amend the close ceilings of a
Latchedprotection withPositionProtectionBook.amendLatchedPositionProtectionCloseLimits(uint64,CloseFinancialLimits)when the account has no pending Router order." (packages/perps/CANONICAL_ENTRYPOINTS.md:145-147) - Cecuro MED-9, team comment, marked "Addressed": "Only the owner may amend the retained ceilings while protection is Latched; keepers cannot relax them. [...] Tight limits may prevent execution until conditions improve or the owner amends them."
The code makes that amend depend on a state that any other account can end. retryPositionProtectionClose is callable by anyone and needs only Latched (PositionProtectionBook.sol:382-388); it sets the status back to Triggered (:573). amendLatchedPositionProtectionCloseLimits reverts unless the status is Latched and the account has no pending Router order (:320-325). So when another account retries right after the failed close, the owner's amend returns OrderRouter__ProtectionNotLatched. While the protection is active, every other owner method that would close the position or change the limits is refused as well. The position stays open past its stop.
- Who is harmed: the trader whose protection close failed on its own ceiling (a stop-loss in the PoC). It cannot apply the documented remedy and carries the market move that follows.
- Who acts: any account, through permissionless entry points only. It gains nothing and pays gas.
- Numbers (PoC, release risk parameters, position 10,000 lots = 1,000,000 USDG notional, margin 100,000 USDG): during one hour 240 of 240 amend calls of the trader are refused. Trader's final equity against the documented path (amend accepted at once): -0.4629 USDG if the price stays; -5,017.65 at 1.0100 -> 1.0150; -30,104.71 at -> 1.0400; -80,284.45 at -> 1.0900; -88,565.89 at -> 1.1050, where the position is liquidated. If the price returns to 1.0000 the delay favours the trader: +10,033.69.
Vulnerability Details
Root cause (packages/perps/src/PositionProtectionBook.sol at the pinned commit a82d4fefb02768e5b3bddcc97dee371eee24fea8)
// :315-328 - the owner's amend (added by the MED-9 fix)
function amendLatchedPositionProtectionCloseLimits(uint64 protectionId, PositionProtectionTypes.CloseFinancialLimits calldata limits) external nonReentrant {
StoredProtection storage protection = _ownedActiveProtection(protectionId, msg.sender);
if (protection.status != PositionProtectionTypes.PositionProtectionStatus.Latched) {
revert OrderRouter__ProtectionNotLatched();
}
if (IPositionProtectionRouterHost(ROUTER).pendingOrderCounts(msg.sender) != 0) {
revert OrderRouter__PendingOrdersExist();
}
_setCloseLimits(protection, limits);
_emitCloseLimitsUpdated(protection);
}
// :382-406 - the retry: no caller check (`_activeProtection`, not `_ownedActiveProtection`), no delay, no count
function retryPositionProtectionClose(uint64 protectionId) external nonReentrant returns (uint64 linkedOrderId) {
StoredProtection storage protection = _activeProtection(protectionId);
if (protection.status != PositionProtectionTypes.PositionProtectionStatus.Latched) {
revert OrderRouter__ProtectionNotLatched();
}
...
_recordCloseAttempt(protection, linkedOrderId); // :573 protection.status = Triggered
}
(multi-line signatures are joined on one line)
- A failed close attempt puts the protection into
Latched(:666). Both functions above need exactly that state, and the retry ends it. - Each attempt carries the stored limits ("It copies the four retained close limits into each attempt",
WORKING_WITH_AI_AGENTS.md:278), so the new attempt fails on the same ceiling. - While the protection is active the owner has no other lever:
cancelPositionProtectionandreplacePositionProtectionaccept onlyPendingOpenorArmed(:414-419,:272-277).cancelPositionProtectionAndCommitCloseaccepts onlyArmed(:346-348).- Ordinary orders are refused with
OrderRouter__ProtectionActive(router/OrderLiquidationBatchLogic.sol:313-315). - The documents say the same: "
TriggeredandLatchedprotection remain binding and cannot be cancelled or replaced." (WORKING_WITH_AI_AGENTS.md:288); "ordinary orders are blocked while it is active, except through the documented protection actions" (WORKING_WITH_AI_AGENTS.md:240-241).
- PoC test 5 calls every one of these methods in the
Triggeredstate: all are refused, and the position and the limits stay as they were.
Why this is an incomplete fix of MED-9
MED-9 ("Keepers can retry protection closes without the trader's financial limits") was fixed in commit eadc5c58 (2026-10-23; Cecuro's fix link: plether-core 8a2853f80bce067656c1fd0fcf2dadc5892e2aee). Its commit message states the two parts of the fix: "MED-9: retain trader-selected close financial ceilings across protection triggers and retries, with owner amendment after relatch."
- The first part works: every attempt carries the trader's ceilings.
- The second part is the remedy for the case the first part creates, a close that fails on those ceilings. The team comment names it: "Tight limits may prevent execution until conditions improve or the owner amends them."
- The fix added the amend with the
Latchedgate (:320-321is inside the fix diff). It left the retry as it was since 2026-08-29 (git blame -L 382,406: no line fromeadc5c58). When the retry was written there was no amend, so nothing depended on how long theLatchedstate lasts. After the fix the owner's amend depends on it, and any account can still end that state at once. - Result: the party MED-9 was about, a keeper, cannot relax the limits, but it can keep the owner from changing them.
The program admits this kind of report: "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." (program page, Known Issues and Previous Audits)
What we do not dispute, and why it does not cover this
- "Retry is permissionless" (
SECURITY.md:550) is documented. The interface comment of the amend says "Lets the owner change close limits after a failed attempt relatches, before a fresh retry. [...] A live child cannot be changed." (IPositionProtectionActions.sol:32-33). Each half is documented. No sentence in the repository, the audits or the program page says that another account's retry may come before the owner's amend, or what the owner should do then. Four texts describe the amend as available after a failed close (the two documents and the MED-9 comment quoted in the Brief, and the fix commit message); none says that a retry by another account takes it away. - The team's own test of the amend,
test_ProtectionCloseLimits_OnlyOwnerCanAmendLatchedLimitsForNextRetry, runs one order only: the owner amends, another account retries, and a second amend is refused because the attempt is live. The opposite order, retry first, is not tested. DEPLOYMENT.md:419-421tells the reference worker: "Investigate planner, constraint, or other persistent failures before retrying; do not continuously queue the same failing attempt." This is an instruction to the project's own keeper, not a rule of the contract. The program page says "Keepers are not trusted: anyone can execute orders, liquidations, price updates and protections, so harm caused by any caller acting as a keeper is in scope" and "Researchers should consider any contract-permitted behavior, including deviations from the reference implementation."- The known limitation "Liveness depends on keepers processing the terminal attempt and separately appending a retry, and operators must alert on prolonged
Latchedstate without a live child" (SECURITY.md:1356-1359) is about the opposite case, a retry that does not come. Here the retry comes before the owner can use the state. - The AI-scan Low "Protection trigger bounty is paid before a zero-bounty close is executed" describes a position that stays open past its threshold because nobody executes the queued close. Here the close attempts are executed and fail on the trader's ceiling, and the remedy added afterwards by the MED-9 fix is what is refused. The program page dates the scan October 15, 2026; the amend was added on October 23.
- We do not dispute that tight limits may prevent execution (accepted in the MED-9 comment). This report is about the second half of that sentence, "or the owner amends them".
Sequence (PoC, _setupToFirstFailedClose and _loopHour)
- TRADER holds a LONG of 10,000 lots opened at 1.0000 with 100,000 USDG margin. It arms a stop-loss at 1.0100 with
maxActionChargeAssets= 1,015.050281 USDG: the charge quoted for that close in the book of that moment (914.050281) plus 25 % of the execution fee as headroom. - Another trader opens a SHORT of 10,000 lots, an ordinary order. The pool's skew changes, and the price-impact part of TRADER's future close rises: the same close now costs 1,934.082056 USDG.
- The mark reaches 1.0100. A keeper triggers the protection (one-off trigger bounty of 0.20 USDG, paid by TRADER) and executes the queued close. It fails with
ConstraintViolationon TRADER's ceiling. The protection isLatched. This is the state in which the documents say the owner may amend. - Another account calls
retryPositionProtectionClose. Status:Triggered. TRADER's amend returnsOrderRouter__ProtectionNotLatched. - Every 30 seconds the other account sends one transaction that executes the failing attempt and retries. After each of its transactions the status is
Triggeredagain. In one hour: 120 such transactions, 240 amend calls of TRADER (right before and right after each), 240 refused. - A single retry is enough while nobody executes the attempt: with one transaction of the other account and no execution, TRADER's amend is refused at each of 3,600 seconds (PoC test 4). The status stays
Triggeredalthough the attempt expired long ago.
Impact Details
Measured effect. Both paths start from the same state (step 3). Reference path: the amend is accepted at once, as documented; retry; the close executes at 1.0100. Loop path: steps 4-5 for one hour, then TRADER gets out with its own execute + amend (see "Preconditions and limits") and the close executes at the price of that moment. Reference final equity of TRADER: 1,988,165.492588 USDG.
| Price during the hour | TRADER final equity, loop path | Loop minus reference (USDG) |
|---|---|---|
| stays at 1.0100 | 1,988,165.029688 | -0.462900 (one more hour of carry) |
| 1.0100 -> 1.0150 | 1,983,147.842951 | -5,017.649637 |
| 1.0100 -> 1.0400 | 1,958,060.784323 | -30,104.708265 |
| 1.0100 -> 1.0900 | 1,907,881.042350 | -80,284.450238 |
| 1.0100 -> 1.1050 (beyond the margin; the move comes with the other account's first transaction, the amend is refused, and TRADER is liquidated a few seconds later) | 1,899,599.600000 | -88,565.892588 |
| 1.0100 -> 1.0000 (returns to the entry) | 1,998,199.178173 | +10,033.685585 (the delay favours TRADER) |
- The difference is the market move after the stop on the position that should have been closed, plus the larger charges at the later price. The other account does not move the price. If the price stays, the cost is 0.46 USDG. If it comes back, the trader is better off.
- What the other account spends: gas only. Its token, clearinghouse, claim and ETH balances do not change over 20 transactions (PoC test 8); no fee, bond or deposit is taken for a retry, and the function has no count or delay (
:382-406). Gas with the fixture's mock oracle: 1,483,383 per "execute + retry" transaction and 772,950 for a retry alone (forge--isolate, per transaction). A real Pyth update adds verification gas and the Pyth fee.
Preconditions and limits
- The first failure must happen. The protection close must first fail on the owner's own ceiling. In ordinary operation this happens when other traders' orders move the skew between arming and the trigger (step 2). With unlimited ceilings (
type(uint256).max) there is no failure and noLatchedstate. - The damage needs an adverse move after the stop. See the table: -0.46 USDG when the price stays, a gain for the trader when it returns.
- The other account gains nothing and pays gas for every transaction. We claim no profit motive.
- The owner has two ways out. The PoC shows both.
- A plain account can execute the pending attempt itself (permissionless
executeOrder; the attempt fails, statusLatched) and send the amend as its next transaction. If nothing lands between the two, the amend is accepted and the next attempt closes the position (test 6a). If one retry of another account lands between them, the amend is refused again (test 6b). - An account that is a contract can do both calls in one transaction. That works without any ordering (test 7).
- A plain account can execute the pending attempt itself (permissionless
- Why a trader following the documents does not find these. The documented action after a failed close is the amend. No document says that the owner must first execute the pending attempt itself (for a live attempt this needs oracle update data,
DEPLOYMENT.md:439-440) and then win the ordering against a retry. No protocol entry point combines the two calls. The repository's reference client builds the amend as a single call (packages/perps-aa-client/src/protection.ts:103-107), and its README describes it as the whole action: "buildAmendLatchedProtectionCloseLimitsActionlets the owner change the close limits of aLatchedprotection before a permissionless retry." (packages/perps-aa-client/README.md:204-205). This client is outside the scope and is cited only to show the documented user flow. Its trading accounts are smart accounts, which can batch calls, so the one-transaction exit is within technical reach of such users, but they would have to compose it themselves. The core contracts accept any address as a trader. - Not modelled: other keepers. The project's reference keeper is expected to execute the pending attempt ("The ordinary keeper then uses the attempt's execution window",
DEPLOYMENT.md:410). Each such execution opens aLatchedmoment, and the amend is accepted only if it lands before the next retry of any account. - No trusted role is involved. After the fixture setup the PoC makes no owner-only call. The other account uses
executeOrder,retryPositionProtectionCloseandtriggerPositionProtection.
Impact (Medium): "Griefing (e.g. no profit motive for an attacker, but damage to the users or the protocol)"
| element of the row text | assertion (PoC) | measured value |
|---|---|---|
| "no profit motive" | test 8: the other account's balances in every asset are equal before and after each of 20 transactions | change 0 / 0 / 0 / 0; it pays gas |
| "damage to the users" | tests 2 and 3: loop-path equity minus reference-path equity is at or below minus the price move on 10,000 lots | -5,017.65 to -88,565.89 USDG on the adverse rows |
| the damage comes from the refused remedy | test 1: 240 of 240 amend calls refused, position still 10,000 lots; test 5: every other closing or limit-changing method refused | 240 / 240 |
- Bound, as a fact: the damage equals the adverse market move during the time the amend is refused, on the size of the protected position. It is 0.46 USDG if the price does not move and negative (a gain) if the price returns. It ends when the owner uses one of the two exits above.
- Floor row (alternative): "Contract fails to deliver promised returns, but doesn't lose value" (Low). If triage reads the price-dependent damage as not shown, what remains is that the documented owner amendment after a failed close is not delivered while another account retries: 240 of 240 calls refused in the PoC, 3,600 of 3,600 seconds after a single retry.
- We do not claim "Temporary freezing of funds": the trader's margin actions work throughout (test 5), and the exits above exist.
- The griefing downgrade rule on the program page concerns High and Critical findings; this report is filed at the Griefing row itself.
Recommended fix
Give the owner a path that another account's retry cannot take away. Any one of these is enough:
- Let the owner amend while
Triggered: the Book cancels the pending zero-bounty attempt and stores the new limits in the same call. (Relaxing the status check alone is not enough: the second check at:323-325refuses the amend while the attempt is a pending Router order.) - Make the retry owner-only for a short time after each relatch, and permissionless after it.
- Let the owner cancel a
LatchedorTriggeredprotection together with a bounded full close, ascancelPositionProtectionAndCommitClosedoes forArmed.
Which one fits the design is the team's decision.
References
packages/perps/src/PositionProtectionBook.sol#L315-L328(amend),#L382-L406(retry),#L564-L578(_recordCloseAttempt),#L637-L675(handleFailedProtectionAttempt),#L983-L1000(_ownedActiveProtection,_activeProtection),#L264-L277,#L341-L348,#L408-L419packages/perps/src/router/OrderLiquidationBatchLogic.sol#L313-L315packages/perps/src/interfaces/IPositionProtectionActions.sol#L32-L37,#L70-L78packages/perps/WORKING_WITH_AI_AGENTS.mdl.240-241, l.265-266, l.283-288;packages/perps/CANONICAL_ENTRYPOINTS.mdl.142-148, l.257-259;packages/perps/SECURITY.mdl.547-552, l.1356-1359;packages/perps/DEPLOYMENT.mdl.412-421- Cecuro AI audit report (
audits/plether-ai-audit-report-2026-10-26.pdf), item MED-9; AI scan findings (audits/scan-plether-fi-plether-core-d4541b49.md), "Protection trigger bounty is paid before a zero-bounty close is executed" - Fix commit
eadc5c587e2f2f1ec26c51132472ab876d6edc15("fix(perps): harden trader protection, liquidation pricing, and manual exits (#124)", 2026-10-23); retry introduced by5661cc55("feat(perps): latch protection close retries", 2026-08-29) - Project test
packages/perps/test/perps/spec/trader/PositionProtection.t.sol#L954-L1005
Proof of Concept
Proof of Concept
One runnable Foundry test file in the repository's own perps test suite, at the frozen commit a82d4fefb02768e5b3bddcc97dee371eee24fea8. It is a local test; no fork, RPC or env var is used.
- Fixture: the repository's
BasePerpTest. The only mocks are MockPyth and the USDG mock, both outside the scope (the program page allows mocks for "components outside the scope, such as Pyth price updates and USDG"). The fixture's basket has two feeds. - Parameters: release risk values (maintenance margin 10 bps, initial margin 20 bps, frozen-market margin 300 bps, execution fee 4 bps, Senior cap 40M USDG and 80 % of the pool).
- No in-scope contract is modified. No
vm.store, novm.etch. No protocol address is impersonated. - Roles: the test contract deploys the system. After
setUpit makes no owner-only call. The other account (KEEPER) calls onlyexecuteOrder,retryPositionProtectionClose,triggerPositionProtection,updateMarkPriceandexecuteLiquidation, which anyone can call.
Setup and command
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
# Save the test code at the end of this section as packages/perps/test/PocS6_ProtectionAmendRetry.t.sol
FOUNDRY_SPARSE_MODE=true forge test --root packages/perps --match-path 'test/PocS6_*' -vv # Foundry 1.5.1
# optional, per-transaction gas of test 8:
FOUNDRY_SPARSE_MODE=true forge test --root packages/perps --match-path 'test/PocS6_*' --match-test test_8_OtherAccount_PaysGasOnly --isolate -vv
Expected result: 8 passed; 0 failed. FOUNDRY_SPARSE_MODE=true compiles only this test and its dependencies (194 files, about one minute); without it forge first builds the whole via-IR suite. The compiler prints warnings for lib/forge-std, OpenZeppelin ERC4626.sol, src/CfdEngine.sol and src/CfdOrderPolicyEvaluatorBase.sol; none is in the PoC file.
Accounts
- TRADER (0xB001): owns the position and its stop-loss protection. The documents call this account "the owner". In test 7 TRADER is a small contract account instead.
- KEEPER (0x0E0E1): "another account". Any caller; the program page defines keepers as untrusted.
- TRADER_C, TRADER_D: two other traders with ordinary orders.
- Amounts in the log are USDG atoms (6 decimals); prices have 8 decimals.
Steps
Shared start (_setupToFirstFailedClose).
- Junior and Senior hold 5,000,000 USDG each. TRADER_C opens SHORT 10,000 lots and TRADER opens LONG 10,000 lots (1,000,000 USDG notional, margin 100,000) at 1.0000.
- TRADER arms a stop-loss at 1.0100. Its
maxActionChargeAssetsis 1,015.050281: the charge the public evaluator quotes for this close at the stop in the current book (914.050281) plus 25 % of the execution fee (404.00). - TRADER_D opens SHORT 10,000 lots at 1.0000, an ordinary order.
- The mark reaches 1.0100. KEEPER triggers the protection; TRADER pays the trigger bounty of 0.20 USDG once. KEEPER executes the queued close: it fails with
ConstraintViolationon TRADER's ceiling (the close now costs 1,934.082056). Protection status:Latched. Position: 10,000 lots.
Test 1, the documented amend is refused for one hour. KEEPER calls retryPositionProtectionClose right after the failed close. Then, every 30 seconds, it sends one transaction through a small helper contract: execute the failing attempt, retry. TRADER calls the amend right before and right after each of these transactions. Result: 120 transactions, 240 amend calls, 240 refused with OrderRouter__ProtectionNotLatched; the position is still 10,000 lots and the stored ceiling is unchanged.
Tests 2 and 3, TRADER's final equity on two paths from the same state.
- Reference path (the documented sequence): the amend is accepted at once, KEEPER retries, the close executes at 1.0100. Final equity 1,988,165.492588.
- Loop path: the hour of test 1 at the given oracle price; then TRADER executes the pending attempt itself, amends right behind it, KEEPER retries, and the close executes at that price.
- Loop minus reference: price stays -0.462900; 1.0150 -5,017.649637; 1.0400 -30,104.708265; 1.0900 -80,284.450238; back to 1.0000 +10,033.685585 (the delay favours TRADER).
- Price 1.1050: the move comes with KEEPER's first transaction; TRADER's amend is refused; TRADER is liquidatable and is liquidated. Final equity 1,899,599.600000, that is -88,565.892588 against the reference path.
Test 4, one retry is enough while nobody executes the attempt. KEEPER sends a single retry. The amend is tried at each of 3,600 seconds: 3,600 refused; the status stays Triggered. Then TRADER executes the expired attempt itself and amends right behind it: accepted.
Test 5, TRADER's methods in the Triggered state. Refused, with the position and the limits unchanged: amend (ProtectionNotLatched, 0x5b54e624), cancel, cancel-and-close, replace, trigger (ProtectionNotArmed, 0x2dee7d8f), a new protection (ProtectionAlreadyActive, 0x389e2bd1), ordinary full close, partial close and increase (ProtectionActive, 0x3a0535a3), retry by TRADER (ProtectionNotLatched). Accepted, but without closing the position or changing the limits: addMargin, depositMargin, withdrawMargin. The one call that changes the status: TRADER executes the pending attempt itself (it fails; status Latched).
Test 6, the way out for a plain account. TRADER executes the pending attempt, then amends. (a) With nothing between the two transactions the amend is accepted and the next attempt closes the position. (b) With one retry of KEEPER between them the amend is refused and the position stays open.
Test 7, the way out for a contract account. After 20 transactions of KEEPER (20 plain amend calls refused), the contract account executes the attempt and amends in one transaction: accepted. The next attempt closes the position.
Test 8, what the other account spends. Over 20 "execute + retry" transactions the balances of KEEPER and of its helper contract do not change in token, clearinghouse balance, trader claim or ETH; TRADER is debited nothing per failed attempt. Gas per transaction in --isolate mode: 1,483,383 (retry alone 772,950). In the normal run the same lines show call-frame gas (1,195,467 and 668,046). The oracle is the fixture's mock; a real Pyth update costs more.
Every privileged or impersonated call, and the role it stands for
- The test contract (
address(this)) is the deployer and owner of the perps contracts. Its owner-only calls are all in the fixture setup: the deployment and tranche seeding inBasePerpTest.setUp, andpool.proposePoolConfig+pool.finalizePoolConfig, which set the release Senior cap. None is made aftersetUp. vm.prank(KEEPER)= any caller:router.updateMarkPrice,pool.settleLpEpoch(0, 0)(setup, no open positions),router.executeOrder,book.triggerPositionProtection,book.retryPositionProtectionClose, the helper contract'sexecuteAndRetry, androuter.executeLiquidationin test 3.vm.prank(TRADER / TRADER_C / TRADER_D)= ordinary traders acting on their own accounts: deposits,router.commitOrder, the protection calls, androuter.executeOrder(permissionless). In test 7 the contract account's ordinary calls are sent withvm.prankfor brevity; its one-transaction exit is the contract's own code.vm.prank / vm.startPrank(JLP / SLP)= two LPs depositing in the setup.- Test scaffolding:
settlementToken.mint(USDG mock), MockPyth prices,vm.warp/vm.roll,vm.snapshotState/vm.revertToStateto start several branches from one state. The fixture's_mockPythUpdateDataadvances the clock by one second.
Output of the run
Clean copy of the pinned tree, only the PoC file added, cold build (2026-11-13, forge 1.5.1-stable, Solc 0.8.35, 194 files compiled in 49.89 s):
Ran 8 tests for test/PocS6_ProtectionAmendRetry.t.sol:PocS6_ProtectionAmendRetryTest
[PASS] test_1_AmendAfterFailedClose_IsRefusedForTheWholeHour() (gas: 130541516)
Logs:
setup: close charge quoted at arming / of which execution fee / trader's ceiling 914050281 404000000 1015050281
setup: first protection close FAILED on the ceiling; protection status (8 = Latched) 8
DOCUMENTED [DOC-1]: after a failed close 'protection becomes Latched; the owner may amend its
limits before retrying' -> expected: the trader's amend is accepted
OBSERVED: another account retried first, then sent one transaction every 30 s (execute + retry)
other account's transactions / seconds 120 3600
trader's amend calls / of them refused with OrderRouter__ProtectionNotLatched 240 240
trader's position (lots) / protection status (3 = Triggered) / ceiling still stored 10000 3 1015050281
[PASS] test_2_EquityTable_PriceStays_And_ModerateMoves() (gas: 379757133)
Logs:
setup: close charge quoted at arming / of which execution fee / trader's ceiling 914050281 404000000 1015050281
setup: first protection close FAILED on the ceiling; protection status (8 = Latched) 8
[reference path: amend accepted at once] close price (8 dec) / trader final equity (USDG atoms, 6 dec) 101000000 1988165492588
[reference path: amend accepted at once] close: action charge / execution fee / carry 1934082056 404000000 8871
[reference path: amend accepted at once] close: realized PnL (signed)
-10000000000
ROW price stays at 1.0100 for the hour
[loop path] close price (8 dec) / trader final equity (USDG atoms, 6 dec) 101000000 1988165029688
[loop path] close: action charge / execution fee / carry 1934544956 404000000 471842
[loop path] close: realized PnL (signed)
-10000000000
other account's transactions / trader's refused amend calls / seconds 120 240 3600
TRADER FINAL EQUITY, LOOP PATH MINUS REFERENCE PATH (USDG atoms, signed):
-462900
ROW price 1.0100 -> 1.0150
[loop path] close price (8 dec) / trader final equity (USDG atoms, 6 dec) 101500000 1983147842951
[loop path] close: action charge / execution fee / carry 1951731693 406000000 471842
[loop path] close: realized PnL (signed)
-15000000000
other account's transactions / trader's refused amend calls / seconds 120 240 3600
TRADER FINAL EQUITY, LOOP PATH MINUS REFERENCE PATH (USDG atoms, signed):
-5017649637
ROW price 1.0100 -> 1.0400
[loop path] close price (8 dec) / trader final equity (USDG atoms, 6 dec) 104000000 1958060784323
[loop path] close: action charge / execution fee / carry 2038790321 416000000 4718
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the amend requires the Latched status while the permissionless retry immediately clears it, so the remedy added by the MED-9 fix depends on a state any account can end.
Impact
The trader could not apply the documented remedy and carried the market move after the stop, losing up to about 88,565 USDG in the PoC when the price moved adversely, though the delay favoured the trader if the price returned; the attacker gains nothing and pays only gas.
What the attacker needed
A stop-loss close fails on its own ceiling; an adverse price move after the stop; attacker pays gas only
The fix
The owner should be given a path another account's retry cannot take away, such as amending while Triggered, a short owner-only retry window, or cancelling a Latched protection with a bounded close.
How it was found
- The trader opens a long position and arms a stop-loss with a tight maximum charge.
- Another trader's ordinary order changes the pool skew, raising the cost of the trader's future close.
- The mark reaches the stop; a keeper triggers the protection and the queued close fails on the trader's ceiling, leaving it Latched.
- Another account calls the permissionless retry, setting the status back to Triggered.
- The trader's amend call is refused with OrderRouter__ProtectionNotLatched, repeatedly over the hour.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A trader set a stop-loss, a rule that should close their position if the price moves against them. The close failed because the trader's own cost limit was too tight, and the protocol offers a way to raise that limit before trying again. But anyone can press a 'retry' button that locks that option, so the trader's position stays open while the price keeps moving.
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.