security(oracle): reject invalid or stale prices and contain manipulable hub spot marks #1391

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

Summary and severity

Medium data integrity; High only when unsafe downstream financial use is proven. Invalid/stale CEX data and manipulable pool marks can corrupt public USD data and, where consumed financially, steer economic decisions without violating settlement math.

Internal review references: KIMIK3 ORB-01/05/06; SBHIGH chain G; chains P/S. 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

CEX parsers accept parse::() without a finite-positive check; successful sources are averaged arithmetically. Overflow/nonfinite conversion through f64_to_bd silently defaults to zero. get_latest_average_price returns the newest historical average without an age bound. Hub pricing uses current reserves and ranks candidates by TVL valued at the candidate's own implied token price, with a $100 floor.

Correction to the audit attack example: factory uniqueness prevents a second UST1/cUSTC pool, and current UST1 resolution accepts only canonical cUSTC as its priced leg. The real UST1 risk is manipulation of the existing reserve ratio. USTR may select between eligible cUSTC and UST1 pools, allowing candidate switching and propagation of a manipulated UST1 mark. Settlement does not read these USD marks. The inspected buyback scripts primarily use CEX USTC/LUNC/FDUSD values; a specific hub-mark-driven treasury path must be demonstrated before claiming that part of the chain.

Why a new implementation is needed

Invalid/stale CEX data and manipulable pool marks can corrupt public USD data and, where consumed financially, steer economic decisions without violating settlement math.

Constraints and guardrails

  • Preserve cUSTC/LUNC external-source independence, exact contract identity, decimals and honest quality/coverage reporting. Do not add symbol-based stablecoin or hub trust.
  • No claim of on-chain collateral theft without an actual consumer path. Monitor closure is not protective implementation: closed #1216 is a discussion ticket.
  • Do not invent fresh prices, force a $1 UST1 peg or use manipulable self-valued TVL as independent backing.

Relevant files

  • Reject nonfinite, zero, negative and out-of-range values before persisting source rows or aggregation; never coerce conversion failure to a valid zero.
  • Use explicit source-quorum/outlier policy, freshness limits and confidence/status metadata propagated to downstream consumers.
  • Bound hub deviation and source switching using independently priced-leg depth, authenticated canonical identities and an appropriate observation/reference policy. Median-of-N is not a cure for a single canonical UST1 pool.
  • Stop automated financial actions on stale/degraded/unavailable prices; publish spot marks as non-oracle-grade and implement measurable divergence alerts.

Acceptance criteria

  • Invalid sources cannot persist or contaminate a valid aggregate; stale/no-quorum values become explicit unavailable/degraded results.
  • UST1 reserve manipulation and USTR candidate switching are detected/contained under documented bounds; confidence propagates through USD APIs/adapters and financial callers.
  • Each consuming automated action validates source, age and quality before preparing a transaction.
  • Canonical identity and coverage tests pass and API docs disclose remaining spot-manipulation risk.

Test plan: supported and failure paths

  • Mock all CEX combinations including partial/all outage, expired last-good value, recovered quorum, mixed decimals and deterministic historical timestamps.
  • Seed actual canonical UST1/cUSTC and eligible USTR pools; test reserve shifts, depth loss, source ties/switches and propagated UST1 error.
  • Run oracle/hub unit suites and Postgres USD/adapter tests; mock scripts to prove stale/degraded inputs yield no transaction preparation.

Test plan: attack, hack and abuse vectors

  • Inject NaN/Infinity/1e999, negative/zero values, finite overflow and one extreme source; valid peers must remain usable under policy.
  • Use LocalTerra reserve manipulation and LP withdrawal, never a fictional duplicate canonical pair. Test insufficient independent depth and coordinated manipulation of candidates.
  • Attempt stale timestamp replay, renamed ticker/contract spoof, upstream outage and cache poisoning; no consumer may silently accept a fabricated healthy quote.

Verification criteria

  • Parser, aggregate, unbounded historical lookup and reserve-derived selection were source-verified; no production price manipulation was performed.
  • Require deterministic mocked-source and canonical-pool attack receipts, freshness/quality propagation and transaction-suppression evidence.
    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 #556 introduced hub marks; closed #1216 records discussion rather than a implemented safety monitor. This is a source hardening successor, not a reopening of the earlier price-scale fixes.

1392: chain-trust, 1395: parser-integrity. Each report owns its stated acceptance scope.

## Summary and severity Medium data integrity; High only when unsafe downstream financial use is proven. Invalid/stale CEX data and manipulable pool marks can corrupt public USD data and, where consumed financially, steer economic decisions without violating settlement math. Internal review references: KIMIK3 ORB-01/05/06; SBHIGH chain G; chains P/S. 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 CEX parsers accept parse::<f64>() without a finite-positive check; successful sources are averaged arithmetically. Overflow/nonfinite conversion through f64_to_bd silently defaults to zero. get_latest_average_price returns the newest historical average without an age bound. Hub pricing uses current reserves and ranks candidates by TVL valued at the candidate's own implied token price, with a $100 floor. Correction to the audit attack example: factory uniqueness prevents a second UST1/cUSTC pool, and current UST1 resolution accepts only canonical cUSTC as its priced leg. The real UST1 risk is manipulation of the existing reserve ratio. USTR may select between eligible cUSTC and UST1 pools, allowing candidate switching and propagation of a manipulated UST1 mark. Settlement does not read these USD marks. The inspected buyback scripts primarily use CEX USTC/LUNC/FDUSD values; a specific hub-mark-driven treasury path must be demonstrated before claiming that part of the chain. ## Why a new implementation is needed Invalid/stale CEX data and manipulable pool marks can corrupt public USD data and, where consumed financially, steer economic decisions without violating settlement math. ## Constraints and guardrails - Preserve cUSTC/LUNC external-source independence, exact contract identity, decimals and honest quality/coverage reporting. Do not add symbol-based stablecoin or hub trust. - No claim of on-chain collateral theft without an actual consumer path. Monitor closure is not protective implementation: closed #1216 is a discussion ticket. - Do not invent fresh prices, force a $1 UST1 peg or use manipulable self-valued TVL as independent backing. ## Relevant files - [indexer/src/indexer/oracle.rs](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/748579ab718026efad54afcef4b2a5186fe82662/indexer/src/indexer/oracle.rs) - [indexer/src/db/queries/oracle.rs](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/748579ab718026efad54afcef4b2a5186fe82662/indexer/src/db/queries/oracle.rs) - [indexer/src/indexer/hub_usd.rs](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/748579ab718026efad54afcef4b2a5186fe82662/indexer/src/indexer/hub_usd.rs) - [indexer/src/api/oracle.rs](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/748579ab718026efad54afcef4b2a5186fe82662/indexer/src/api/oracle.rs) - [indexer/src/api/hub_prices.rs](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/748579ab718026efad54afcef4b2a5186fe82662/indexer/src/api/hub_prices.rs) - [indexer/src/indexer/protocol_tvl.rs](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/748579ab718026efad54afcef4b2a5186fe82662/indexer/src/indexer/protocol_tvl.rs) - [scripts/mint-swap-custc-ust1.sh](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/748579ab718026efad54afcef4b2a5186fe82662/scripts/mint-swap-custc-ust1.sh) - [scripts/mint-swap-burn-ust1-clunc.sh](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/748579ab718026efad54afcef4b2a5186fe82662/scripts/mint-swap-burn-ust1-clunc.sh) - [scripts/rebalance-mint-ust1-lp.sh](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/748579ab718026efad54afcef4b2a5186fe82662/scripts/rebalance-mint-ust1-lp.sh) ## Recommended direction - Reject nonfinite, zero, negative and out-of-range values before persisting source rows or aggregation; never coerce conversion failure to a valid zero. - Use explicit source-quorum/outlier policy, freshness limits and confidence/status metadata propagated to downstream consumers. - Bound hub deviation and source switching using independently priced-leg depth, authenticated canonical identities and an appropriate observation/reference policy. Median-of-N is not a cure for a single canonical UST1 pool. - Stop automated financial actions on stale/degraded/unavailable prices; publish spot marks as non-oracle-grade and implement measurable divergence alerts. ## Acceptance criteria - [ ] Invalid sources cannot persist or contaminate a valid aggregate; stale/no-quorum values become explicit unavailable/degraded results. - [ ] UST1 reserve manipulation and USTR candidate switching are detected/contained under documented bounds; confidence propagates through USD APIs/adapters and financial callers. - [ ] Each consuming automated action validates source, age and quality before preparing a transaction. - [ ] Canonical identity and coverage tests pass and API docs disclose remaining spot-manipulation risk. ## Test plan: supported and failure paths - Mock all CEX combinations including partial/all outage, expired last-good value, recovered quorum, mixed decimals and deterministic historical timestamps. - Seed actual canonical UST1/cUSTC and eligible USTR pools; test reserve shifts, depth loss, source ties/switches and propagated UST1 error. - Run oracle/hub unit suites and Postgres USD/adapter tests; mock scripts to prove stale/degraded inputs yield no transaction preparation. ## Test plan: attack, hack and abuse vectors - Inject NaN/Infinity/1e999, negative/zero values, finite overflow and one extreme source; valid peers must remain usable under policy. - Use LocalTerra reserve manipulation and LP withdrawal, never a fictional duplicate canonical pair. Test insufficient independent depth and coordinated manipulation of candidates. - Attempt stale timestamp replay, renamed ticker/contract spoof, upstream outage and cache poisoning; no consumer may silently accept a fabricated healthy quote. ## Verification criteria - Parser, aggregate, unbounded historical lookup and reserve-derived selection were source-verified; no production price manipulation was performed. - Require deterministic mocked-source and canonical-pool attack receipts, freshness/quality propagation and transaction-suppression evidence. 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 #556 introduced hub marks; closed #1216 records discussion rather than a implemented safety monitor. This is a source hardening successor, not a reopening of the earlier price-scale fixes. ## Related remediation reports [1392: chain-trust](https://git.cl8y.com/code/cl8y-dex-terraclassic/issues/1392), [1395: parser-integrity](https://git.cl8y.com/code/cl8y-dex-terraclassic/issues/1395). 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: Reject invalid/stale oracle marks and contain manipulable hub spot prices. No oracle remediation is 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: Reject invalid/stale oracle marks and contain manipulable hub spot prices. No oracle remediation is included in this merge. This issue stays open for that substantive work, not merely a verification hold.
Author
Owner

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

Treasury fixtures now exercise chain attestation and oracle validation independently; malformed/stale marks still block preparation. API/oracle/liquidity/database and financial-script 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 #1412 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). Treasury fixtures now exercise chain attestation and oracle validation independently; malformed/stale marks still block preparation. API/oracle/liquidity/database and financial-script 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#1391
No description provided.