security: bound reverse queries and isolate exact-output capacity #1407

Merged
PlasticDigits merged 3 commits from fix/issue-1389-reverse-budget into main 2026-10-06 02:09:40 +00:00
Owner

Public router reverse quotes could perform hundreds of nested pair simulations per request, while one peer could occupy all exact-output slots. This change meters reverse work before each call and adds bounded client admission without weakening receive or signing protections.

Addresses #1389. Pair cw2 is 1.20.0; router cw2 is 1.3.0. Execute messages and storage layout are unchanged.

  • Router reserves at most 33 pair simulations per hop and 96 per request, including fresh forward sufficiency. Greedy probes use checked pool seeds and cached responses. Declared queries reserve the full shared 32-call pair ceiling; legacy or unknown pool reverse identities receive conservative accounting.
  • Pair declared search retains 32 calls, improves checked inverse/interpolation/plateau probes, and requires sufficient output plus an insufficient predecessor. Observe horizons use checked subtraction.
  • Both exact-output GET endpoints share four global slots, one per socket-peer IP. Forwarded headers cannot override identity; cancellation/error/timeout releases capacity, idle client keys are removed, and aggregate tracing counters avoid client labels. NAT/proxy users share one slot.
  • Receive-state regressions cover work-budget, capacity and timeout failures after executable quotes; Receive remains intact, Pay clears, signing is disabled, and automatic deterministic retries stop.

Completed issue criteria:

  • AC1: bounded nested counts across search branches, legacy identities and all 81 four-hop mode combinations.
  • AC2: supported large declared/pure-book targets are sufficient within 32 calls; impossible/exhausted work terminates with stable errors. Conservative support limits are documented.
  • AC3: fair admission, cancellation/timeout recovery, spoofing resistance and panic-free invalid Observe horizons.
  • AC4: preserved receive intent and cleared executable state without resend or reduced protections.

Validation: 888 contract workspace tests passed, with focused retests; router 12 tests twice; pair 96 plus focused retests; final-source exact-output unit 19, API integration 12 and admission 6 each passed twice; frontend 134 tests twice, plus 199 receive regressions and 268 tax regressions twice. Strict Clippy, formatting, frontend lint/types/production build, docs checks and secret scan pass. The Rust 2024 formatting mismatch discovered by the tax verifier was corrected and retested. Post-hook frontend formatting also passed all four affected failure cases.

Shared-host kernel disk I/O blocked normal Cargo bookkeeping. Equivalent final-source executables were preserved or freshly compiled to tmpfs, with source/binary hashes and compiler-argument provenance recorded. make verify-issue-1389 completed PASS=8 FAIL=0 SKIP=1; the #1376 and corrected #1381 verifiers pass with their explicit unavailable scopes.

Unverified: LocalTerra gas/funded execution (height 838695 frozen since 06:49:55 UTC with a pending transaction), browser replay (Vite navigation setup timed out before app assertions), remaining unchanged broad indexer tax suites, and production deployment/migration. Failed setup attempts remain recorded; none is claimed as a passing test. No public LCD stress or real-wallet activity was performed. Production pair rollout remains separately tracked in #1386.

Reviewer/agent instructions:

  1. Read invariants and bounds and agent protocol.
  2. Run make verify-issue-1389 and the review checklist; inspect actual evidence and remaining scope.
  3. Reproduce gas/browser checks once infrastructure is available. Agents may mark overall review PASS with explicit skips for checks they cannot complete, recording exact reasons; skipped rows remain unverified and failing assertions stay FAIL until fixed and retested. Runtime safeguards and credential boundaries remain enforced.
Public router reverse quotes could perform hundreds of nested pair simulations per request, while one peer could occupy all exact-output slots. This change meters reverse work before each call and adds bounded client admission without weakening receive or signing protections. Addresses #1389. Pair cw2 is 1.20.0; router cw2 is 1.3.0. Execute messages and storage layout are unchanged. - Router reserves at most 33 pair simulations per hop and 96 per request, including fresh forward sufficiency. Greedy probes use checked pool seeds and cached responses. Declared queries reserve the full shared 32-call pair ceiling; legacy or unknown pool reverse identities receive conservative accounting. - Pair declared search retains 32 calls, improves checked inverse/interpolation/plateau probes, and requires sufficient output plus an insufficient predecessor. Observe horizons use checked subtraction. - Both exact-output GET endpoints share four global slots, one per socket-peer IP. Forwarded headers cannot override identity; cancellation/error/timeout releases capacity, idle client keys are removed, and aggregate tracing counters avoid client labels. NAT/proxy users share one slot. - Receive-state regressions cover work-budget, capacity and timeout failures after executable quotes; Receive remains intact, Pay clears, signing is disabled, and automatic deterministic retries stop. Completed issue criteria: - [x] AC1: bounded nested counts across search branches, legacy identities and all 81 four-hop mode combinations. - [x] AC2: supported large declared/pure-book targets are sufficient within 32 calls; impossible/exhausted work terminates with stable errors. Conservative support limits are documented. - [x] AC3: fair admission, cancellation/timeout recovery, spoofing resistance and panic-free invalid Observe horizons. - [x] AC4: preserved receive intent and cleared executable state without resend or reduced protections. Validation: 888 contract workspace tests passed, with focused retests; router 12 tests twice; pair 96 plus focused retests; final-source exact-output unit 19, API integration 12 and admission 6 each passed twice; frontend 134 tests twice, plus 199 receive regressions and 268 tax regressions twice. Strict Clippy, formatting, frontend lint/types/production build, docs checks and secret scan pass. The Rust 2024 formatting mismatch discovered by the tax verifier was corrected and retested. Post-hook frontend formatting also passed all four affected failure cases. Shared-host kernel disk I/O blocked normal Cargo bookkeeping. Equivalent final-source executables were preserved or freshly compiled to tmpfs, with source/binary hashes and compiler-argument provenance recorded. `make verify-issue-1389` completed PASS=8 FAIL=0 SKIP=1; the #1376 and corrected #1381 verifiers pass with their explicit unavailable scopes. Unverified: LocalTerra gas/funded execution (height 838695 frozen since 06:49:55 UTC with a pending transaction), browser replay (Vite navigation setup timed out before app assertions), remaining unchanged broad indexer tax suites, and production deployment/migration. Failed setup attempts remain recorded; none is claimed as a passing test. No public LCD stress or real-wallet activity was performed. Production pair rollout remains separately tracked in #1386. Reviewer/agent instructions: 1. Read [invariants and bounds](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/e36505273933dfeb99697c9602c8218780d9ba4a/docs/route-solver.md#reverse-query-availability-1389) and [agent protocol](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/e36505273933dfeb99697c9602c8218780d9ba4a/skills/AGENTS_REVERSE_QUERY_BUDGET.md). 2. Run `make verify-issue-1389` and the [review checklist](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/e36505273933dfeb99697c9602c8218780d9ba4a/docs/qa/issue-1389/README.md); inspect [actual evidence and remaining scope](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/e36505273933dfeb99697c9602c8218780d9ba4a/docs/qa/issue-1389/verification.md). 3. Reproduce gas/browser checks once infrastructure is available. Agents may mark overall review PASS with explicit skips for checks they cannot complete, recording exact reasons; skipped rows remain unverified and failing assertions stay FAIL until fixed and retested. Runtime safeguards and credential boundaries remain enforced.
fix: bound reverse queries and isolate exact-output capacity
All checks were successful
ci/woodpecker/pr/woodpecker Pipeline was successful
a451d916b7
Meter nested pair simulations across hops, seed and cache bounded reverse searches, and retain fresh forward sufficiency. Add per-peer request admission with cancellation cleanup, checked Observe horizons, regressions, and agent verification guidance.
docs: link reverse-query repair and agent checklist to review
All checks were successful
ci/woodpecker/pr/woodpecker Pipeline was successful
e365052739
Refresh bounded reverse queries against main [skip ci]
Some checks failed
ci/woodpecker/pr/woodpecker Pipeline failed
45554eb6a5
Sign in to join this conversation.
No reviewers
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!1407
No description provided.