security(router): bound reverse-query work and isolate exact-output capacity #1389

Closed
opened 2026-10-04 12:37:47 +00:00 by PlasticDigits · 2 comments
Owner

Summary and severity

Medium–High public availability. Public reverse queries can amplify pair simulation work far beyond the intended small budget and share scarce exact-output capacity, degrading legitimate quote availability.

Internal review references: SBHIGH-03/09/13; KIMIK3 EO-1; chain B. Investigated against source revision 748579ab718026efad54afcef4b2a5186fe82662 on 2026-10-04. These are engineering findings, not third-party audit certification. Only technical findings and synthetic test cases are included; no conversation, user identity, credentials or real-user activity is published.

Current codebase and evidence

reverse_greedy_offer repeatedly calls full pair HybridSimulation during a 128-step expansion, a confirmation, then Uint128-width bisection. This is finite but lacks a small shared call budget, memoization or pool seed; a request can perform hundreds of nested simulations across MAX_HOPS=4. Pair declared-hybrid reverse has a 32-call ceiling but still exhausts it for feasible large targets. Browser reverse queries reach LCD directly, bypassing indexer HTTP controls. Exact-output HTTP work uses four global permits and a finite timeout, with no per-client capacity share. Observe also subtracts user-supplied seconds_ago from block time without checked subtraction.

Quote-path outages can impair availability; sandwich extraction additionally needs victim transactions and weakened user protections. No forced fallback or MEV profit was reproduced.

Why a new implementation is needed

Public reverse queries can amplify pair simulation work far beyond the intended small budget and share scarce exact-output capacity, degrading legitimate quote availability.

Constraints and guardrails

  • Preserve four-hop cap, Uint256 math, target intent, fresh forward sufficiency and all user minimum/spread protections.
  • HTTP limits do not fix direct contract/LCD amplification. Do not automatically submit a weaker trade or retry deterministic budget failures.
  • Tests/load probes must use mocks or LocalTerra; do not stress public LCD.

Relevant files

  • Meter every nested simulation against a documented per-hop and whole-request budget; reuse prior responses, seed feasible brackets from checked pool math and return a typed budget error.
  • Improve declared-hybrid search within its existing finite ceiling; never solve exhaustion by expanding the cap without measured gas evidence.
  • Give exact-output requests bounded per-client admission in addition to global limits, timeout/cancellation cleanup and metrics. Use checked arithmetic for Observe range validation.

Acceptance criteria

  • Worst-case nested call counts remain within documented budgets for every search branch and hop combination.
  • Supported large feasible declared-hybrid targets produce sufficient offers within budget; exhaustion and impossible targets terminate with stable errors.
  • One client cannot monopolize all exact-output permits; cancellation releases them. Invalid Observe horizons return errors without panic.
  • Quote failures preserve receive intent and clear executable operations, with no automatic resend or reduced signing protection.

Test plan: supported and failure paths

  • Instrument query counters for pool-only, greedy and declared-hybrid, both orientations, 6/18 decimals, zero/small/near-reserve/Uint128-boundary targets.
  • Exercise empty/stale/full books, maker and scan caps, failed nested queries, oversize hops, disconnected UI, timeout, cancellation and capacity recovery.
  • Run contract reverse suites, make verify-issue-1376, API exact-output tests and quote-state frontend regressions.

Test plan: attack, hack and abuse vectors

  • Synthetic requests requiring long expansion plus bisection and four capped-book hops must hit a work error before exhausting resources.
  • Concurrent clients, repeated cancellations, invalid targets and proxy address spoofing must not evade the chosen admission policy.
  • Adversarial pool/book movement must never fabricate sufficiency or remove minimum_receive/max_spread protections.

Verification criteria

  • Source confirms expansion/bisection and global permit limits; focused API suite passed 55 tests on an isolated database, including 12 exact-output tests.
  • Require call-count and bounded LocalTerra gas evidence plus fair-admission tests. No public DoS or economic extraction test was performed.
    Record revision, UTC time, exact commands, outcomes and evidence scope. Complete runnable checks first. Unavailable signing, deployment, device or infrastructure checks must be explicitly recorded as unverified; they do not block filing or implementation. An executed failure remains FAIL. Never claim deployment acceptance from unit tests or read-only probes. Public receipts must use synthetic identities and omit secrets.

New router amplification/capacity repair; #257 and closed #1376 address earlier pair/receive sizing, while #1386 separately tracks production pair rollout.

1399: book-liveness, 1394: discovery-cache. Each report owns its stated acceptance scope.

## Summary and severity Medium–High public availability. Public reverse queries can amplify pair simulation work far beyond the intended small budget and share scarce exact-output capacity, degrading legitimate quote availability. Internal review references: SBHIGH-03/09/13; KIMIK3 EO-1; chain B. Investigated against source revision `748579ab718026efad54afcef4b2a5186fe82662` on 2026-10-04. These are engineering findings, not third-party audit certification. Only technical findings and synthetic test cases are included; no conversation, user identity, credentials or real-user activity is published. ## Current codebase and evidence `reverse_greedy_offer` repeatedly calls full pair `HybridSimulation` during a 128-step expansion, a confirmation, then Uint128-width bisection. This is finite but lacks a small shared call budget, memoization or pool seed; a request can perform hundreds of nested simulations across MAX_HOPS=4. Pair declared-hybrid reverse has a 32-call ceiling but still exhausts it for feasible large targets. Browser reverse queries reach LCD directly, bypassing indexer HTTP controls. Exact-output HTTP work uses four global permits and a finite timeout, with no per-client capacity share. Observe also subtracts user-supplied seconds_ago from block time without checked subtraction. Quote-path outages can impair availability; sandwich extraction additionally needs victim transactions and weakened user protections. No forced fallback or MEV profit was reproduced. ## Why a new implementation is needed Public reverse queries can amplify pair simulation work far beyond the intended small budget and share scarce exact-output capacity, degrading legitimate quote availability. ## Constraints and guardrails - Preserve four-hop cap, Uint256 math, target intent, fresh forward sufficiency and all user minimum/spread protections. - HTTP limits do not fix direct contract/LCD amplification. Do not automatically submit a weaker trade or retry deterministic budget failures. - Tests/load probes must use mocks or LocalTerra; do not stress public LCD. ## Relevant files - [smartcontracts/contracts/router/src/route_tax.rs](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/748579ab718026efad54afcef4b2a5186fe82662/smartcontracts/contracts/router/src/route_tax.rs) - [smartcontracts/contracts/router/src/contract.rs](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/748579ab718026efad54afcef4b2a5186fe82662/smartcontracts/contracts/router/src/contract.rs) - [smartcontracts/contracts/pair/src/hybrid_reverse.rs](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/748579ab718026efad54afcef4b2a5186fe82662/smartcontracts/contracts/pair/src/hybrid_reverse.rs) - [smartcontracts/contracts/pair/src/contract.rs](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/748579ab718026efad54afcef4b2a5186fe82662/smartcontracts/contracts/pair/src/contract.rs) - [indexer/src/api/route_exact_output.rs](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/748579ab718026efad54afcef4b2a5186fe82662/indexer/src/api/route_exact_output.rs) - [indexer/src/api/mod.rs](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/748579ab718026efad54afcef4b2a5186fe82662/indexer/src/api/mod.rs) - [frontend-dapp/src/services/terraclassic/router.ts](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/748579ab718026efad54afcef4b2a5186fe82662/frontend-dapp/src/services/terraclassic/router.ts) - [skills/AGENTS_SWAP_EXACT_OUTPUT.md](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/748579ab718026efad54afcef4b2a5186fe82662/skills/AGENTS_SWAP_EXACT_OUTPUT.md) ## Recommended direction - Meter every nested simulation against a documented per-hop and whole-request budget; reuse prior responses, seed feasible brackets from checked pool math and return a typed budget error. - Improve declared-hybrid search within its existing finite ceiling; never solve exhaustion by expanding the cap without measured gas evidence. - Give exact-output requests bounded per-client admission in addition to global limits, timeout/cancellation cleanup and metrics. Use checked arithmetic for Observe range validation. ## Acceptance criteria - [ ] Worst-case nested call counts remain within documented budgets for every search branch and hop combination. - [ ] Supported large feasible declared-hybrid targets produce sufficient offers within budget; exhaustion and impossible targets terminate with stable errors. - [ ] One client cannot monopolize all exact-output permits; cancellation releases them. Invalid Observe horizons return errors without panic. - [ ] Quote failures preserve receive intent and clear executable operations, with no automatic resend or reduced signing protection. ## Test plan: supported and failure paths - Instrument query counters for pool-only, greedy and declared-hybrid, both orientations, 6/18 decimals, zero/small/near-reserve/Uint128-boundary targets. - Exercise empty/stale/full books, maker and scan caps, failed nested queries, oversize hops, disconnected UI, timeout, cancellation and capacity recovery. - Run contract reverse suites, make verify-issue-1376, API exact-output tests and quote-state frontend regressions. ## Test plan: attack, hack and abuse vectors - Synthetic requests requiring long expansion plus bisection and four capped-book hops must hit a work error before exhausting resources. - Concurrent clients, repeated cancellations, invalid targets and proxy address spoofing must not evade the chosen admission policy. - Adversarial pool/book movement must never fabricate sufficiency or remove minimum_receive/max_spread protections. ## Verification criteria - Source confirms expansion/bisection and global permit limits; focused API suite passed 55 tests on an isolated database, including 12 exact-output tests. - Require call-count and bounded LocalTerra gas evidence plus fair-admission tests. No public DoS or economic extraction test was performed. Record revision, UTC time, exact commands, outcomes and evidence scope. Complete runnable checks first. Unavailable signing, deployment, device or infrastructure checks must be explicitly recorded as unverified; they do not block filing or implementation. An executed failure remains FAIL. Never claim deployment acceptance from unit tests or read-only probes. Public receipts must use synthetic identities and omit secrets. ## Related work and duplicate check New router amplification/capacity repair; #257 and closed #1376 address earlier pair/receive sizing, while #1386 separately tracks production pair rollout. ## Related remediation reports [1399: book-liveness](https://git.cl8y.com/code/cl8y-dex-terraclassic/issues/1399), [1394: discovery-cache](https://git.cl8y.com/code/cl8y-dex-terraclassic/issues/1394). Each report owns its stated acceptance scope.
Author
Owner

Merge sweep 2026-10-05: the two existing October 4 audit reports are being preserved on main with the sanity receipt. They document findings; committing them does not implement remediation.

Remaining implementation: Bound router reverse-query simulations and isolate public exact-output request capacity. The rollout and dependency PRs do not change these query limits. This issue stays open for that substantive work, not merely a verification hold.

Merge sweep 2026-10-05: the two existing October 4 audit reports are being preserved on main with the sanity receipt. They document findings; committing them does not implement remediation. Remaining implementation: Bound router reverse-query simulations and isolate public exact-output request capacity. The rollout and dependency PRs do not change these query limits. This issue stays open for that substantive work, not merely a verification hold.
Author
Owner

PR #1407 and the final integration PR #1423 are merged into main. Source acceptance: 944 contract tests + strict all-target Clippy, 858 indexer tests across 29 suites, and 3,093 frontend tests + lint/build. Fresh pinned optimizer verification passed. Full receipt.

The reverse-path fixture now reverses hop order as well as asset directions. The real default-3M funded reverse-query failure (3,043,317 gas) is retained as concrete repair #1422; the passing isolated chain fixture used a finite 15M limit.

CI was skipped by explicit operator instruction. Native wrap-stack and production execution remain explicitly unverified. Deployment/history/release work is transferred to #1421 and existing #1384/#1385/#1386; the default query-gas repair is #1422. The source issue is complete and carries no verification-only hold; closure does not claim production deployment.

PR #1407 and the final integration PR #1423 are merged into main. Source acceptance: 944 contract tests + strict all-target Clippy, 858 indexer tests across 29 suites, and 3,093 frontend tests + lint/build. Fresh pinned optimizer verification passed. [Full receipt](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/branch/main/docs/qa/merge-2026-10-06/README.md). The reverse-path fixture now reverses hop order as well as asset directions. The real default-3M funded reverse-query failure (3,043,317 gas) is retained as concrete repair #1422; the passing isolated chain fixture used a finite 15M limit. CI was skipped by explicit operator instruction. Native wrap-stack and production execution remain explicitly unverified. Deployment/history/release work is transferred to #1421 and existing #1384/#1385/#1386; the default query-gas repair is #1422. The source issue is complete and carries no verification-only hold; closure does not claim production deployment.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
code/cl8y-dex-terraclassic#1389
No description provided.