security(route-tax): preserve router trust across upgrades and revoke obsolete settlement authority #1388

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

Summary and severity

High availability; conditional settlement defense in depth. The current write-once trust model can halt existing taxed routes during router replacement and provides no standard recovery/revocation path; upgrade attestation must distinguish actual funded code.

Internal review references: SBHIGH-01/02; KIMIK3 RT-5, OPS-06, IX-2; chains A/T. 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

community-tax-token stamps CONFIG.router and PROTOCOL_EXEMPT during instantiate/adoption. Same-crate migrate rejects adoption and only updates cw2; settings and execute expose no router rotation. Router preview requires the token's configured router to match the active router. Replacing the router address therefore makes existing taxed routes unavailable until new token recovery code is deployed. Current rollout prose does not explicitly require in-place migration. The existing read-only probe already checks funding version/router equality and fails with --expect-funded; reuse that check as a mandatory inventory-wide rollout preflight rather than claiming the comparator is absent. Legacy instances need their stored config.router inventoried before they expose v1 capability.

Router/token cw2 remains 1.2.0 across different implementations, so version-only evidence cannot prove route funding. Trading-discovery cache identities omit the live token code ID. execute_route_transfer authenticates the configured router and tests membership with .any(), without consuming a settlement entry. The canonical router emits each entry once: replay is a conditional trusted-router regression risk, not a demonstrated outsider drain. Its debit is the router's balance, not arbitrary trader wallets.

Why a new implementation is needed

The current write-once trust model can halt existing taxed routes during router replacement and provides no standard recovery/revocation path; upgrade attestation must distinguish actual funded code.

Constraints and guardrails

  • Preserve RT1381-1–RT1381-10, gross-only funding, exact pair credit and catalog's code/admin/creation/origin provenance. #1229 remains the launcher-spoof implementation issue.
  • No permissionless or token-manager router repointing; prevent a malicious candidate from inheriting authority. Remove only obsolete role exemptions, preserving overlapping valid protocol roles.
  • Do not claim replay enables theft from other wallets or that source-only changes upgrade deployed contracts. Bound any added replay state and preserve storage compatibility.

Relevant files

  • Require unchanged router address for the immediate rollout, inventory all token bindings, and reject mismatches before a state-changing migration.
  • Add an explicitly authenticated governance recovery/rotation operation for future router replacement, with candidate capability/factory validation and atomic removal of obsolete router authority/exemptions.
  • Verify stored artifacts by actual code ID/data hash and live capability; key discovery verdicts by instance code identity and invalidate on rollout.
  • If exact single-use settlement is guaranteed, use a genuine monotonic route ID plus per-settlement slot and token identity. Never use gross amount, block height alone or recipient/amount alone as a nonce.

Acceptance criteria

  • New-address rollout is rejected by preflight; existing-address migration preserves successful funded routing.
  • Authorized router rotation can recover an already-adopted instance; stale router calls fail after rotation; unauthorized or malformed rotations fail atomically.
  • Same-version/different-hash code cannot pass artifact verification; discovery changes immediately when code identity changes.
  • Settlement tests distinguish canonical one-time emission, duplicate-slot replay, legitimate identical transfers in different routes and pre-existing router dust.

Test plan: supported and failure paths

  • Test instantiate, foreign adoption, same-crate migrate, in-place rollout, candidate mismatch, rollback and future router recovery with synthetic contracts.
  • Test taxed first/middle/final hops, zero intermediate balances, refunds, manager exemptions, multiple inventories and code/cache cutover.
  • Run make verify-issue-1381 and actual LocalTerra legacy-to-new migration when reviewed legacy artifacts are available.

Test plan: attack, hack and abuse vectors

  • Spoof router/factory/capability, replay stale route contexts, rotate to an attacker contract, call from old router and attempt overlapping-exemption removal.
  • Duplicate final/refund message under one authenticated context; same-height separate routes with identical amounts; forced later-hop failure must roll back consumption and all balances.
  • Re-run launcher-spoof/cw2-spoof attestation failures; never treat origin alone as catalog proof.

Verification criteria

  • Source review confirms the write-once binding and membership-only settlement check; baseline contracts/frontend and synthetic LocalTerra funding/rollback tests passed.
  • Require hash/inventory/rotation and replay regression receipts before implementation acceptance; production recovery requires separate actual migration receipts.
    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.

Complements open #1384 rollout with missing source recovery and preflight behavior. #1229 is already open; do not duplicate it. Settlement replay is included as conditional authorization hardening, not an independently reproduced fund-loss exploit.

1390: launch-guards, 1394: discovery-cache. Each report owns its stated acceptance scope.

## Summary and severity High availability; conditional settlement defense in depth. The current write-once trust model can halt existing taxed routes during router replacement and provides no standard recovery/revocation path; upgrade attestation must distinguish actual funded code. Internal review references: SBHIGH-01/02; KIMIK3 RT-5, OPS-06, IX-2; chains A/T. 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 `community-tax-token` stamps `CONFIG.router` and `PROTOCOL_EXEMPT` during instantiate/adoption. Same-crate migrate rejects adoption and only updates cw2; settings and execute expose no router rotation. Router preview requires the token's configured router to match the active router. Replacing the router address therefore makes existing taxed routes unavailable until new token recovery code is deployed. Current rollout prose does not explicitly require in-place migration. The existing read-only probe already checks funding version/router equality and fails with --expect-funded; reuse that check as a mandatory inventory-wide rollout preflight rather than claiming the comparator is absent. Legacy instances need their stored config.router inventoried before they expose v1 capability. Router/token cw2 remains 1.2.0 across different implementations, so version-only evidence cannot prove route funding. Trading-discovery cache identities omit the live token code ID. `execute_route_transfer` authenticates the configured router and tests membership with `.any()`, without consuming a settlement entry. The canonical router emits each entry once: replay is a conditional trusted-router regression risk, not a demonstrated outsider drain. Its debit is the router's balance, not arbitrary trader wallets. ## Why a new implementation is needed The current write-once trust model can halt existing taxed routes during router replacement and provides no standard recovery/revocation path; upgrade attestation must distinguish actual funded code. ## Constraints and guardrails - Preserve RT1381-1–RT1381-10, gross-only funding, exact pair credit and catalog's code/admin/creation/origin provenance. #1229 remains the launcher-spoof implementation issue. - No permissionless or token-manager router repointing; prevent a malicious candidate from inheriting authority. Remove only obsolete role exemptions, preserving overlapping valid protocol roles. - Do not claim replay enables theft from other wallets or that source-only changes upgrade deployed contracts. Bound any added replay state and preserve storage compatibility. ## Relevant files - [smartcontracts/contracts/community-tax-token/src/contract.rs](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/748579ab718026efad54afcef4b2a5186fe82662/smartcontracts/contracts/community-tax-token/src/contract.rs) - [smartcontracts/contracts/community-tax-token/src/adopt.rs](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/748579ab718026efad54afcef4b2a5186fe82662/smartcontracts/contracts/community-tax-token/src/adopt.rs) - [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/community-tax-token/src/msg.rs](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/748579ab718026efad54afcef4b2a5186fe82662/smartcontracts/contracts/community-tax-token/src/msg.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/contracts/router/src/contract.rs](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/748579ab718026efad54afcef4b2a5186fe82662/smartcontracts/contracts/router/src/contract.rs) - [indexer/src/api/trading_tax_discovery.rs](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/748579ab718026efad54afcef4b2a5186fe82662/indexer/src/api/trading_tax_discovery.rs) - [scripts/qa/probe-route-tax-1381.py](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/748579ab718026efad54afcef4b2a5186fe82662/scripts/qa/probe-route-tax-1381.py) - [docs/runbooks/route-local-tax-1381.md](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/748579ab718026efad54afcef4b2a5186fe82662/docs/runbooks/route-local-tax-1381.md) ## Recommended direction - Require unchanged router address for the immediate rollout, inventory all token bindings, and reject mismatches before a state-changing migration. - Add an explicitly authenticated governance recovery/rotation operation for future router replacement, with candidate capability/factory validation and atomic removal of obsolete router authority/exemptions. - Verify stored artifacts by actual code ID/data hash and live capability; key discovery verdicts by instance code identity and invalidate on rollout. - If exact single-use settlement is guaranteed, use a genuine monotonic route ID plus per-settlement slot and token identity. Never use gross amount, block height alone or recipient/amount alone as a nonce. ## Acceptance criteria - [ ] New-address rollout is rejected by preflight; existing-address migration preserves successful funded routing. - [ ] Authorized router rotation can recover an already-adopted instance; stale router calls fail after rotation; unauthorized or malformed rotations fail atomically. - [ ] Same-version/different-hash code cannot pass artifact verification; discovery changes immediately when code identity changes. - [ ] Settlement tests distinguish canonical one-time emission, duplicate-slot replay, legitimate identical transfers in different routes and pre-existing router dust. ## Test plan: supported and failure paths - Test instantiate, foreign adoption, same-crate migrate, in-place rollout, candidate mismatch, rollback and future router recovery with synthetic contracts. - Test taxed first/middle/final hops, zero intermediate balances, refunds, manager exemptions, multiple inventories and code/cache cutover. - Run make verify-issue-1381 and actual LocalTerra legacy-to-new migration when reviewed legacy artifacts are available. ## Test plan: attack, hack and abuse vectors - Spoof router/factory/capability, replay stale route contexts, rotate to an attacker contract, call from old router and attempt overlapping-exemption removal. - Duplicate final/refund message under one authenticated context; same-height separate routes with identical amounts; forced later-hop failure must roll back consumption and all balances. - Re-run launcher-spoof/cw2-spoof attestation failures; never treat origin alone as catalog proof. ## Verification criteria - Source review confirms the write-once binding and membership-only settlement check; baseline contracts/frontend and synthetic LocalTerra funding/rollback tests passed. - Require hash/inventory/rotation and replay regression receipts before implementation acceptance; production recovery requires separate actual migration receipts. 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 Complements open #1384 rollout with missing source recovery and preflight behavior. #1229 is already open; do not duplicate it. Settlement replay is included as conditional authorization hardening, not an independently reproduced fund-loss exploit. ## Related remediation reports [1390: launch-guards](https://git.cl8y.com/code/cl8y-dex-terraclassic/issues/1390), [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: Preserve or deliberately rotate trusted router identity across upgrades and revoke obsolete settlement permissions. The rollout now migrates existing addresses in place; the underlying trust-lifecycle remediation is not implemented by 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: Preserve or deliberately rotate trusted router identity across upgrades and revoke obsolete settlement permissions. The rollout now migrates existing addresses in place; the underlying trust-lifecycle remediation is not implemented by this merge. This issue stays open for that substantive work, not merely a verification hold.
Author
Owner

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

Settlement/refund fixture interfaces were reconciled, legacy zero nonces remain rejected, and the shared test signer aliases now use the funded account. The integrated contract and funded-route checks pass.

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 #1408 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). Settlement/refund fixture interfaces were reconciled, legacy zero nonces remain rejected, and the shared test signer aliases now use the funded account. The integrated contract and funded-route checks pass. 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#1388
No description provided.