security(pair/AutoLP): enforce net execution floors and bounded hook work #1398

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

Summary and severity

Medium price-protection completeness; privileged hook availability. Protection must cover user net output and issued LP shares, and trusted hook work must have finite admission limits.

Internal review references: KIMIK3 SC-03/04/05; conditional hook/MEV chains. 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

Pair asserts max_spread on pre-hook return, then collects fee-hook deductions and checks optional min_return on net_return. A direct caller supplying max_spread without a net minimum can receive less than that protection appears to promise; callers with a sufficient net min_return are already protected. UpdateHooks accepts an arbitrary-length list from factory governance, increasing per-swap GetConfig/AfterSwap work. AutoLP's swap has protections, but its reply supplies all remaining balances with ProvideLiquidity slippage_tolerance=None; pair only enforces LP ratio tolerance when Some is supplied.

Hooks are governance-gated and transactions atomic. Whole-transaction front-running can change the pool before execution; no actor can insert a transaction between the AutoLP swap and reply. Economic extraction is a test hypothesis, not an observed mainnet loss.

Why a new implementation is needed

Protection must cover user net output and issued LP shares, and trusted hook work must have finite admission limits.

Constraints and guardrails

  • Preserve existing hook charging/conservation, net min_return, swap mutex, fee tiers and hybrid book protections; do not silently waive governance hooks.
  • Do not change max_spread semantics by accident or count pool/book fees twice; migrate/document client-visible semantics.
  • Keep AutoLP receiver/factory-listed pair rules, skim floor and configured swap cap; do not substitute mutable spot-derived UI prices as an economic security anchor.

Relevant files

  • Define/evaluate execution price protection against user net output, including known hook deductions, or require an explicit net minimum on hook-bearing paths with consistent signing semantics.
  • Cap hook count and duplicates at every admission/update boundary; preserve intentional hook failure atomicity and provide a bounded legacy configuration repair path.
  • Bind AutoLP LP issuance to an explicit ratio/min-LP guard grounded in its approved pre-skim policy and carry the bounds through reply.

Acceptance criteria

  • Direct/hybrid/router callers cannot satisfy stated protection on pre-hook output while violating required net protection.
  • Quote and execute account for hooks consistently; unsupported hook pricing fails explicitly without weakening user bounds.
  • Oversized/duplicate hook lists fail before mutation, and bounded legacy configs can recover without losing required policy hooks.
  • AutoLP supply rejects insufficient LP/ratio outcomes and fully rolls back balances/allowances/sinks on failure.

Test plan: supported and failure paths

  • Pool/book/mixed directions with no/one/multiple hooks, 0/max deduction, min_return absent/present, maker discounts and taxed routes.
  • AutoLP first/existing liquidity, all balance shapes, manipulated pre-skim reserves, stale bounds and failed reply; reconcile LP supply/receiver shares.
  • Run hook/pair/AutoLP multitests, full contracts and LocalTerra measured maximum supported hook/skim work.

Test plan: attack, hack and abuse vectors

  • Synthetic hook underquotes/fails GetConfig, takes large permitted deduction, reverts AfterSwap or attempts reentry; preserve atomic rollback.
  • Governance submits oversized/duplicate succeeding-heavy hook lists; cap prevents unbounded fanout, while a single malicious trusted hook remains a documented policy risk.
  • Front-run the entire synthetic skim transaction, test donations/skewed ratios and confirm economic floor behavior; never assume same-tx interleaving.

Verification criteria

  • Pre-hook max_spread ordering, optional net min_return, arbitrary hook count and None LP tolerance are source-confirmed.
  • Require net-output and LP-ledger attack regressions and gas/call ceilings; no public hook registration or reserve manipulation 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.

Closed #377 hardened hook trust/charging but does not enforce these end-to-end bounds; preserve its intended reverting-hook policy.

1389: reverse-budget, 1390: launch-guards. Each report owns its stated acceptance scope.

## Summary and severity Medium price-protection completeness; privileged hook availability. Protection must cover user net output and issued LP shares, and trusted hook work must have finite admission limits. Internal review references: KIMIK3 SC-03/04/05; conditional hook/MEV chains. 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 Pair asserts max_spread on pre-hook return, then collects fee-hook deductions and checks optional min_return on net_return. A direct caller supplying max_spread without a net minimum can receive less than that protection appears to promise; callers with a sufficient net min_return are already protected. UpdateHooks accepts an arbitrary-length list from factory governance, increasing per-swap GetConfig/AfterSwap work. AutoLP's swap has protections, but its reply supplies all remaining balances with ProvideLiquidity slippage_tolerance=None; pair only enforces LP ratio tolerance when Some is supplied. Hooks are governance-gated and transactions atomic. Whole-transaction front-running can change the pool before execution; no actor can insert a transaction between the AutoLP swap and reply. Economic extraction is a test hypothesis, not an observed mainnet loss. ## Why a new implementation is needed Protection must cover user net output and issued LP shares, and trusted hook work must have finite admission limits. ## Constraints and guardrails - Preserve existing hook charging/conservation, net min_return, swap mutex, fee tiers and hybrid book protections; do not silently waive governance hooks. - Do not change max_spread semantics by accident or count pool/book fees twice; migrate/document client-visible semantics. - Keep AutoLP receiver/factory-listed pair rules, skim floor and configured swap cap; do not substitute mutable spot-derived UI prices as an economic security anchor. ## Relevant files - [smartcontracts/contracts/pair/src/contract.rs](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/748579ab718026efad54afcef4b2a5186fe82662/smartcontracts/contracts/pair/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/community-tax-autolp/src/contract.rs](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/748579ab718026efad54afcef4b2a5186fe82662/smartcontracts/contracts/community-tax-autolp/src/contract.rs) - [smartcontracts/contracts/community-tax-autolp/src/state.rs](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/748579ab718026efad54afcef4b2a5186fe82662/smartcontracts/contracts/community-tax-autolp/src/state.rs) - [smartcontracts/contracts/factory/src/contract.rs](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/748579ab718026efad54afcef4b2a5186fe82662/smartcontracts/contracts/factory/src/contract.rs) - [smartcontracts/tests/src/lib.rs](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/748579ab718026efad54afcef4b2a5186fe82662/smartcontracts/tests/src/lib.rs) ## Recommended direction - Define/evaluate execution price protection against user net output, including known hook deductions, or require an explicit net minimum on hook-bearing paths with consistent signing semantics. - Cap hook count and duplicates at every admission/update boundary; preserve intentional hook failure atomicity and provide a bounded legacy configuration repair path. - Bind AutoLP LP issuance to an explicit ratio/min-LP guard grounded in its approved pre-skim policy and carry the bounds through reply. ## Acceptance criteria - [ ] Direct/hybrid/router callers cannot satisfy stated protection on pre-hook output while violating required net protection. - [ ] Quote and execute account for hooks consistently; unsupported hook pricing fails explicitly without weakening user bounds. - [ ] Oversized/duplicate hook lists fail before mutation, and bounded legacy configs can recover without losing required policy hooks. - [ ] AutoLP supply rejects insufficient LP/ratio outcomes and fully rolls back balances/allowances/sinks on failure. ## Test plan: supported and failure paths - Pool/book/mixed directions with no/one/multiple hooks, 0/max deduction, min_return absent/present, maker discounts and taxed routes. - AutoLP first/existing liquidity, all balance shapes, manipulated pre-skim reserves, stale bounds and failed reply; reconcile LP supply/receiver shares. - Run hook/pair/AutoLP multitests, full contracts and LocalTerra measured maximum supported hook/skim work. ## Test plan: attack, hack and abuse vectors - Synthetic hook underquotes/fails GetConfig, takes large permitted deduction, reverts AfterSwap or attempts reentry; preserve atomic rollback. - Governance submits oversized/duplicate succeeding-heavy hook lists; cap prevents unbounded fanout, while a single malicious trusted hook remains a documented policy risk. - Front-run the entire synthetic skim transaction, test donations/skewed ratios and confirm economic floor behavior; never assume same-tx interleaving. ## Verification criteria - Pre-hook max_spread ordering, optional net min_return, arbitrary hook count and None LP tolerance are source-confirmed. - Require net-output and LP-ledger attack regressions and gas/call ceilings; no public hook registration or reserve manipulation 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 Closed #377 hardened hook trust/charging but does not enforce these end-to-end bounds; preserve its intended reverting-hook policy. ## Related remediation reports [1389: reverse-budget](https://git.cl8y.com/code/cl8y-dex-terraclassic/issues/1389), [1390: launch-guards](https://git.cl8y.com/code/cl8y-dex-terraclassic/issues/1390). 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: Enforce pair/AutoLP net execution floors and cap hook work. No pair or AutoLP behavior 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: Enforce pair/AutoLP net execution floors and cap hook work. No pair or AutoLP behavior changes are included in this merge. This issue stays open for that substantive work, not merely a verification hold.
Author
Owner

Merged PR #1425 with signed post-hook minima, bounded hook admission and anchored AutoLP issuance protection retained. The #1427 version conflict was resolved in favor of integrated router 1.4.0, pair 1.21.0 and factory 1.12.0; rollout defaults/checklists agree. Final optimized artifacts were rebuilt and checksums verified.

make verify-issue-1398: 7 PASS, 0 FAIL, 0 SKIP, including 982 contract workspace tests and 168 focused frontend tests per pass. Funding and guard regressions pass, and all 18 actual funded 3M queries pass twice on the new versions. Production maximum-hook/AutoLP gas and migration remain #1421. Actual-manager recovery for token-owned legacy AutoLP policies is now separately tracked in #1429; unchanged token settings remain a no-op. This completed source issue can close without pretending that legacy rollout has happened.

All four source PRs #1424–#1427 are merged; final receipt published through #1430. Local main is reconciled with both remotes, with no stashes. Hosted CI was skipped by explicit operator instruction; no fake PASS status was posted. Original merge protection is restored. Integrated evidence. Source closure does not claim production deployment.

Merged PR #1425 with signed post-hook minima, bounded hook admission and anchored AutoLP issuance protection retained. The #1427 version conflict was resolved in favor of integrated router 1.4.0, pair 1.21.0 and factory 1.12.0; rollout defaults/checklists agree. Final optimized artifacts were rebuilt and checksums verified. make verify-issue-1398: 7 PASS, 0 FAIL, 0 SKIP, including 982 contract workspace tests and 168 focused frontend tests per pass. Funding and guard regressions pass, and all 18 actual funded 3M queries pass twice on the new versions. Production maximum-hook/AutoLP gas and migration remain #1421. Actual-manager recovery for token-owned legacy AutoLP policies is now separately tracked in #1429; unchanged token settings remain a no-op. This completed source issue can close without pretending that legacy rollout has happened. All four source PRs #1424–#1427 are merged; final receipt published through #1430. Local main is reconciled with both remotes, with no stashes. Hosted CI was skipped by explicit operator instruction; no fake PASS status was posted. Original merge protection is restored. [Integrated evidence](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/branch/main/docs/qa/merge-2026-10-06-final/README.md). Source 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#1398
No description provided.