security(orderbook): finish unfillable head-row eviction left unresolved by closed #1225 #1399

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

Summary and severity

Medium permissionless matching denial; conditional economic amplifier. Economically unfillable active rows need rejection or bounded eviction so permissionless head-prefix placement cannot permanently starve useful matching.

Internal review references: KIMIK3 SC-02/L26; carried-over chain O. 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

Current placement/reprice allows exact human MIN_LIMIT_PRICE and only checks size/price bounds, not economic fillability. All four execute/simulation book walkers skip cost.is_zero() rows with continue, leaving active head nodes linked. Default clean thresholds remain zero. An unexpired economically unfillable prefix can spend the bounded MAX_SCAN_STEPS without reaching fillable orders. Remaining escrow is recoverable by owner cancellation; no free-fill or pool theft is demonstrated.

#1225 is closed, but its latest verification comments state source work remains and the merged change was documentation only. This report supplies an active implementation continuation. Existing tests protect against zero-payout fills, not head-row liveness.

Why a new implementation is needed

Economically unfillable active rows need rejection or bounded eviction so permissionless head-prefix placement cannot permanently starve useful matching.

Constraints and guardrails

  • Keep zero-cost fill rejection: never pay a maker zero for a positive sold amount.
  • Preserve escrow conservation, FIFO, owner-only changes, pause/blacklist/freeze, scan/maker/park caps and atomicity.
  • Hints alone or nonzero governance clean settings are insufficient fixes. Do not silently enable greedy-by-default or bypass signing protections.

Relevant files

  • Use checked decimal-aware economic-fillability validation for single placement, batch/ladder and repricing; audit both order sides.
  • Make legacy unfillable live rows evictable/parkable under default config within bounded matching/clean work, preserving escrow claims.
  • Mirror execute behavior in on-chain simulation/indexer and prove useful progress across long prefixes without removing the scan ceiling.

Acceptance criteria

  • All placement/reprice/ladder paths reject unfillable rows under supported decimal combinations.
  • Legacy unexpired rows are recoverable/removed from active traversal under zero clean thresholds; valid rows remain correctly ordered.
  • More than MAX_SCAN_STEPS synthetic invalid heads cannot permanently hide the fillable row without bounded cleanup progress.
  • Execute, contract sim and indexer agree; existing no-zero-payout and expired-prefix tests stay green.

Test plan: supported and failure paths

  • Test ask and bid boundary prices, 6/6, 6/18 and 18/6 assets, below/exact/above minimum payable amount and checked overflow.
  • Seed legacy live/expired/dust prefixes, clean pagination, claim/cancel/reprice and full ladders; reconcile pending escrow and claim queues.
  • Run dex-common placement, pair orderbook, full contract and DB book-simulation tests.

Test plan: attack, hack and abuse vectors

  • Only in unit/LocalTerra fixtures, place a long economically unfillable head prefix with no expiry followed by a legitimate order; assert bounded forward progress.
  • Try repricing a valid row into the clog, batch splitting, minimum-step hints, scan-cap exhaustion and park-cap starvation.
  • Ensure removal cannot manufacture a free fill, steal escrow, skip a valid best-priced row or double-refund an order.

Verification criteria

  • Exact boundary acceptance and zero-cost continue paths were source-verified; #1225 comments confirm outstanding source implementation.
  • Require long-prefix progress and execute/sim/indexer parity receipts before source acceptance; no mainnet clog test was run.
    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.

Continuation of closed #1225, not duplicate of closed #470 zero-payout correctness or #289 expired rows. #718 is also closed but source remains opt-in; this ticket does not change product default policy.

1389: reverse-budget, 1400: ci-supply-chain. Each report owns its stated acceptance scope.

## Summary and severity Medium permissionless matching denial; conditional economic amplifier. Economically unfillable active rows need rejection or bounded eviction so permissionless head-prefix placement cannot permanently starve useful matching. Internal review references: KIMIK3 SC-02/L26; carried-over chain O. 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 Current placement/reprice allows exact human MIN_LIMIT_PRICE and only checks size/price bounds, not economic fillability. All four execute/simulation book walkers skip cost.is_zero() rows with continue, leaving active head nodes linked. Default clean thresholds remain zero. An unexpired economically unfillable prefix can spend the bounded MAX_SCAN_STEPS without reaching fillable orders. Remaining escrow is recoverable by owner cancellation; no free-fill or pool theft is demonstrated. #1225 is closed, but its latest verification comments state source work remains and the merged change was documentation only. This report supplies an active implementation continuation. Existing tests protect against zero-payout fills, not head-row liveness. ## Why a new implementation is needed Economically unfillable active rows need rejection or bounded eviction so permissionless head-prefix placement cannot permanently starve useful matching. ## Constraints and guardrails - Keep zero-cost fill rejection: never pay a maker zero for a positive sold amount. - Preserve escrow conservation, FIFO, owner-only changes, pause/blacklist/freeze, scan/maker/park caps and atomicity. - Hints alone or nonzero governance clean settings are insufficient fixes. Do not silently enable greedy-by-default or bypass signing protections. ## Relevant files - [smartcontracts/packages/dex-common/src/limit_placement.rs](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/748579ab718026efad54afcef4b2a5186fe82662/smartcontracts/packages/dex-common/src/limit_placement.rs) - [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/orderbook.rs](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/748579ab718026efad54afcef4b2a5186fe82662/smartcontracts/contracts/pair/src/orderbook.rs) - [smartcontracts/contracts/pair/src/limit_book_clean.rs](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/748579ab718026efad54afcef4b2a5186fe82662/smartcontracts/contracts/pair/src/limit_book_clean.rs) - [indexer/src/api/db_orderbook_sim.rs](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/748579ab718026efad54afcef4b2a5186fe82662/indexer/src/api/db_orderbook_sim.rs) - [smartcontracts/tests/src/limit_order_tests.rs](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/748579ab718026efad54afcef4b2a5186fe82662/smartcontracts/tests/src/limit_order_tests.rs) - [docs/limit-orders.md](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/748579ab718026efad54afcef4b2a5186fe82662/docs/limit-orders.md) ## Recommended direction - Use checked decimal-aware economic-fillability validation for single placement, batch/ladder and repricing; audit both order sides. - Make legacy unfillable live rows evictable/parkable under default config within bounded matching/clean work, preserving escrow claims. - Mirror execute behavior in on-chain simulation/indexer and prove useful progress across long prefixes without removing the scan ceiling. ## Acceptance criteria - [ ] All placement/reprice/ladder paths reject unfillable rows under supported decimal combinations. - [ ] Legacy unexpired rows are recoverable/removed from active traversal under zero clean thresholds; valid rows remain correctly ordered. - [ ] More than MAX_SCAN_STEPS synthetic invalid heads cannot permanently hide the fillable row without bounded cleanup progress. - [ ] Execute, contract sim and indexer agree; existing no-zero-payout and expired-prefix tests stay green. ## Test plan: supported and failure paths - Test ask and bid boundary prices, 6/6, 6/18 and 18/6 assets, below/exact/above minimum payable amount and checked overflow. - Seed legacy live/expired/dust prefixes, clean pagination, claim/cancel/reprice and full ladders; reconcile pending escrow and claim queues. - Run dex-common placement, pair orderbook, full contract and DB book-simulation tests. ## Test plan: attack, hack and abuse vectors - Only in unit/LocalTerra fixtures, place a long economically unfillable head prefix with no expiry followed by a legitimate order; assert bounded forward progress. - Try repricing a valid row into the clog, batch splitting, minimum-step hints, scan-cap exhaustion and park-cap starvation. - Ensure removal cannot manufacture a free fill, steal escrow, skip a valid best-priced row or double-refund an order. ## Verification criteria - Exact boundary acceptance and zero-cost continue paths were source-verified; #1225 comments confirm outstanding source implementation. - Require long-prefix progress and execute/sim/indexer parity receipts before source acceptance; no mainnet clog test was run. 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 Continuation of closed #1225, not duplicate of closed #470 zero-payout correctness or #289 expired rows. #718 is also closed but source remains opt-in; this ticket does not change product default policy. ## Related remediation reports [1389: reverse-budget](https://git.cl8y.com/code/cl8y-dex-terraclassic/issues/1389), [1400: ci-supply-chain](https://git.cl8y.com/code/cl8y-dex-terraclassic/issues/1400). 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: Implement the unfillable order-book head-row eviction still missing after #1225. No order-book matching 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: Implement the unfillable order-book head-row eviction still missing after #1225. No order-book matching changes are included in this merge. This issue stays open for that substantive work, not merely a verification hold.
Author
Owner

PR #1409 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 independent pair regression modules were preserved, including Observe horizons and zero/unfillable claims. Full contracts, strict all-target Clippy, book simulation and DB hybrid-route/park/claim regressions 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 #1409 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 independent pair regression modules were preserved, including Observe horizons and zero/unfillable claims. Full contracts, strict all-target Clippy, book simulation and DB hybrid-route/park/claim regressions 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#1399
No description provided.