security(route-tax): make cyclic-route launch guards and refund semantics consistent #1390

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

Summary and severity

Medium launch-phase availability; conditional control weakening. Route quotes and execution need a consistent launch-guard policy so legitimate funding and owned refunds succeed while independent trades and actual acquired value remain protected.

Internal review references: SBHIGH-05/08; KIMIK3 RT-1/RT-4; chains C/V. 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

Authenticated router sells skip trader cooldown when the token appears in acquired_tokens. That is intentional for normal buy-then-sell intermediate funding and is covered by an existing successful-route test. Buy/reacquisition does not share that skip, and record_trade_blocks stamps every economic boundary. A cyclic route can consequently quote successfully but revert on reacquisition of a guarded token. If only a transient intermediate is guarded, its buy/sell can occur within the route; this alone is not proof of round-trip profit or outsider theft.

Final/refund RouteTransfer still checks max_wallet against positive recipient credit. Returning a payer's owned residue can therefore revert after their existing balance exceeds a subsequently lowered cap. Protocol-exempt trader execution checks also differ from the public route preview.

Why a new implementation is needed

Route quotes and execution need a consistent launch-guard policy so legitimate funding and owned refunds succeed while independent trades and actual acquired value remain protected.

Constraints and guardrails

  • Keep ordinary A→B→C funded intermediate routes working, and block a second independent route in the cooldown window.
  • No unconditional same-block bypass, user-supplied acquired_tokens trust or blanket launch-guard exemption.
  • Preserve trading_enabled, recipient max_wallet, paid SKU/exemption controls and atomic rollback. Cooldowns are per-wallet controls, not Sybil resistance.

Relevant files

  • Define cooldown per independent economic route while retaining the valid intermediate buy/sell exception; either reject repeated capable assets consistently in query/execute/solver or authenticate their first-touch policy explicitly.
  • Distinguish owned residue restoration from new acquired value when enforcing max_wallet. Do not grant unrestricted transfer exemptions.
  • Align executable preflight and simulation with protocol-exempt trader restrictions and return explicit guard failures where guard state is observable.

Acceptance criteria

  • Cyclic capable-token policy is documented and identical across forward/reverse quote, solve and execute.
  • Normal intermediate routing succeeds while independent same-block trades remain blocked.
  • Residue returning owned input cannot alone cause a false cap violation; actual bought output and third-party delivery remain capped.
  • Protocol-exempt trader preview/preflight no longer promises an executable route that the token deterministically rejects.

Test plan: supported and failure paths

  • Test A→B→A, A→B→C→B, ordinary acyclic routes, each placement of the guarded token and cooldown 0/1/>1.
  • Test manager/protocol exemptions, feature disabled, prior-height trades, insufficient gross, lowered max_wallet, zero/nonzero residue and different recipient.
  • Run existing issue1381 cooldown tests, token launch-guard tests, solver and frontend preflight tests; reconcile balances/supply/sinks on rollback.

Test plan: attack, hack and abuse vectors

  • Spoof trader/acquired history, append duplicate asset hops, split into multiple same-block transactions and attempt to carry one route's exemption into another.
  • Try labelling purchased output as residue, using a different recipient to evade cap, and repeated refunds to inflate a capped wallet.
  • Use synthetic profitable/nonprofitable round trips; report actual successful/reverting paths instead of asserting an unmeasured anti-snipe bypass.

Verification criteria

  • Source confirms the sell skip and independent buy check; baseline issue1381 cooldown regression passes. The audits' conflicting cyclic claims require the expanded matrix above.
  • Acceptance needs actual success/failure receipts for each policy branch and unchanged gross funding, dust isolation and atomicity.
    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.

1388: route-trust, 1398: economic-guards. Each report owns its stated acceptance scope.

## Summary and severity Medium launch-phase availability; conditional control weakening. Route quotes and execution need a consistent launch-guard policy so legitimate funding and owned refunds succeed while independent trades and actual acquired value remain protected. Internal review references: SBHIGH-05/08; KIMIK3 RT-1/RT-4; chains C/V. 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 Authenticated router sells skip trader cooldown when the token appears in acquired_tokens. That is intentional for normal buy-then-sell intermediate funding and is covered by an existing successful-route test. Buy/reacquisition does not share that skip, and record_trade_blocks stamps every economic boundary. A cyclic route can consequently quote successfully but revert on reacquisition of a guarded token. If only a transient intermediate is guarded, its buy/sell can occur within the route; this alone is not proof of round-trip profit or outsider theft. Final/refund RouteTransfer still checks max_wallet against positive recipient credit. Returning a payer's owned residue can therefore revert after their existing balance exceeds a subsequently lowered cap. Protocol-exempt trader execution checks also differ from the public route preview. ## Why a new implementation is needed Route quotes and execution need a consistent launch-guard policy so legitimate funding and owned refunds succeed while independent trades and actual acquired value remain protected. ## Constraints and guardrails - Keep ordinary A→B→C funded intermediate routes working, and block a second independent route in the cooldown window. - No unconditional same-block bypass, user-supplied acquired_tokens trust or blanket launch-guard exemption. - Preserve trading_enabled, recipient max_wallet, paid SKU/exemption controls and atomic rollback. Cooldowns are per-wallet controls, not Sybil resistance. ## Relevant files - [smartcontracts/contracts/community-tax-token/src/tax.rs](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/748579ab718026efad54afcef4b2a5186fe82662/smartcontracts/contracts/community-tax-token/src/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/packages/dex-common/src/route_tax.rs](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/748579ab718026efad54afcef4b2a5186fe82662/smartcontracts/packages/dex-common/src/route_tax.rs) - [smartcontracts/tests/src/route_tax_1381_tests.rs](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/748579ab718026efad54afcef4b2a5186fe82662/smartcontracts/tests/src/route_tax_1381_tests.rs) - [indexer/src/api/route_solver.rs](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/748579ab718026efad54afcef4b2a5186fe82662/indexer/src/api/route_solver.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) - [frontend-dapp/src/services/terraclassic/swapRoutePreflight.ts](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/748579ab718026efad54afcef4b2a5186fe82662/frontend-dapp/src/services/terraclassic/swapRoutePreflight.ts) ## Recommended direction - Define cooldown per independent economic route while retaining the valid intermediate buy/sell exception; either reject repeated capable assets consistently in query/execute/solver or authenticate their first-touch policy explicitly. - Distinguish owned residue restoration from new acquired value when enforcing max_wallet. Do not grant unrestricted transfer exemptions. - Align executable preflight and simulation with protocol-exempt trader restrictions and return explicit guard failures where guard state is observable. ## Acceptance criteria - [ ] Cyclic capable-token policy is documented and identical across forward/reverse quote, solve and execute. - [ ] Normal intermediate routing succeeds while independent same-block trades remain blocked. - [ ] Residue returning owned input cannot alone cause a false cap violation; actual bought output and third-party delivery remain capped. - [ ] Protocol-exempt trader preview/preflight no longer promises an executable route that the token deterministically rejects. ## Test plan: supported and failure paths - Test A→B→A, A→B→C→B, ordinary acyclic routes, each placement of the guarded token and cooldown 0/1/>1. - Test manager/protocol exemptions, feature disabled, prior-height trades, insufficient gross, lowered max_wallet, zero/nonzero residue and different recipient. - Run existing issue1381 cooldown tests, token launch-guard tests, solver and frontend preflight tests; reconcile balances/supply/sinks on rollback. ## Test plan: attack, hack and abuse vectors - Spoof trader/acquired history, append duplicate asset hops, split into multiple same-block transactions and attempt to carry one route's exemption into another. - Try labelling purchased output as residue, using a different recipient to evade cap, and repeated refunds to inflate a capped wallet. - Use synthetic profitable/nonprofitable round trips; report actual successful/reverting paths instead of asserting an unmeasured anti-snipe bypass. ## Verification criteria - Source confirms the sell skip and independent buy check; baseline issue1381 cooldown regression passes. The audits' conflicting cyclic claims require the expanded matrix above. - Acceptance needs actual success/failure receipts for each policy branch and unchanged gross funding, dust isolation and atomicity. 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 remediation reports [1388: route-trust](https://git.cl8y.com/code/cl8y-dex-terraclassic/issues/1388), [1398: economic-guards](https://git.cl8y.com/code/cl8y-dex-terraclassic/issues/1398). 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: Reconcile repeated-token/cyclic-route launch guards, acquired-token cooldown accounting, and quote/refund semantics. No cyclic-route protocol changes are included in this merge. 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: Reconcile repeated-token/cyclic-route launch guards, acquired-token cooldown accounting, and quote/refund semantics. No cyclic-route protocol changes are included in this merge. This issue stays open for that substantive work, not merely a verification hold.
Author
Owner

PR #1410 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.

Both trust and launch-guard behavior are retained in version 1.3.0. Missing refund metadata keeps max-wallet enforcement; legacy zero nonces fail closed. Six funded routes, two invoices and 16 guard/cooldown/refund controls passed on the isolated chain.

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 #1410 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). Both trust and launch-guard behavior are retained in version 1.3.0. Missing refund metadata keeps max-wallet enforcement; legacy zero nonces fail closed. Six funded routes, two invoices and 16 guard/cooldown/refund controls passed on the isolated chain. 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#1390
No description provided.