security(indexer): reject malformed event amounts without corrupting accounting #1395

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

Summary and severity

Medium accounting integrity. Malformed financial input must not be accepted as valid zero amounts and propagated into ledgers, aggregates or evidence.

Internal review references: KIMIK3 INT-02; carried-over parser integrity 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

Swap offer/return and other fee/amount fields in parser.rs use parse().unwrap_or_default(), turning malformed text into a valid zero. Downstream event ledgers, volume, P&L and fee evidence can then accept corrupted rows. New book-snapshot numeric parsing is already strict, so ingestion policy is inconsistent. An attack requires emitted/accepted malformed events or an upstream integrity failure; factory/event provenance checks are a separate boundary.

Why a new implementation is needed

Malformed financial input must not be accepted as valid zero amounts and propagated into ledgers, aggregates or evidence.

Constraints and guardrails

  • No float conversion, lossy saturation or substitute zero for mandatory financial fields.
  • Do not drop legitimate zero-valued optional fields or erase unrelated valid events/blocks.
  • Do not trust caller-supplied contract_address attributes over authenticated event provenance.

Relevant files

  • Introduce strict bounded raw-amount parsing with typed missing/invalid/overflow errors; distinguish allowed real zero from failed conversion.
  • Reject or quarantine the complete affected economic event with bounded observability and documented retry policy; retain deterministic block progress without a poisoned-row retry loop.
  • Preserve event-emitter provenance and aggregate idempotency across reorg/replay; reuse shared strict parsing helpers.

Acceptance criteria

  • Malformed mandatory amounts cannot enter swaps/fee/position ledgers as zero; actual valid zero is handled by schema policy.
  • Quarantined events are observable without secrets/real-user public receipts; malformed repeated events cannot wedge block processing.
  • Valid largest-supported raw amounts, decimals and multi-hop fee identities remain exact; replays do not double-count.

Test plan: supported and failure paths

  • Unit-test each economic event type with valid/zero/missing/negative/whitespace/decimal/scientific/overflow values and optional-field defaults.
  • Postgres-test ledger/rollup/evidence consistency, partial bad blocks, retries, reorg rollback and deduplication.
  • Run parser and block-processor suites plus API evidence/fee/volume integration tests on an isolated database.

Test plan: attack, hack and abuse vectors

  • Synthetic approved/foreign contracts emitting amount-like junk, spoofed contract attributes and oversized numeric strings.
  • Repeated poison-event replay and mixed valid/malformed multihop records must not fabricate activity, clear balances or block all indexing.
  • Compare API and database amounts against authenticated valid event fixtures; invalid input yields errors/quarantine, never apparent zero-volume success.

Verification criteria

  • Specific parser zero-coercion paths were source-verified; current lib baseline passes but does not prove malformed-event integrity.
  • Require typed rejection regressions, row/aggregate reconciliation and bounded processing 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 #285 hardened lifecycle emitter provenance; this report addresses numeric coercion and preserves that boundary.

1391: oracle-integrity, 1396: database-isolation. Each report owns its stated acceptance scope.

## Summary and severity Medium accounting integrity. Malformed financial input must not be accepted as valid zero amounts and propagated into ledgers, aggregates or evidence. Internal review references: KIMIK3 INT-02; carried-over parser integrity 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 Swap offer/return and other fee/amount fields in parser.rs use parse().unwrap_or_default(), turning malformed text into a valid zero. Downstream event ledgers, volume, P&L and fee evidence can then accept corrupted rows. New book-snapshot numeric parsing is already strict, so ingestion policy is inconsistent. An attack requires emitted/accepted malformed events or an upstream integrity failure; factory/event provenance checks are a separate boundary. ## Why a new implementation is needed Malformed financial input must not be accepted as valid zero amounts and propagated into ledgers, aggregates or evidence. ## Constraints and guardrails - No float conversion, lossy saturation or substitute zero for mandatory financial fields. - Do not drop legitimate zero-valued optional fields or erase unrelated valid events/blocks. - Do not trust caller-supplied contract_address attributes over authenticated event provenance. ## Relevant files - [indexer/src/indexer/parser.rs](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/748579ab718026efad54afcef4b2a5186fe82662/indexer/src/indexer/parser.rs) - [indexer/src/indexer/mod.rs](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/748579ab718026efad54afcef4b2a5186fe82662/indexer/src/indexer/mod.rs) - [indexer/src/indexer/book_snapshot.rs](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/748579ab718026efad54afcef4b2a5186fe82662/indexer/src/indexer/book_snapshot.rs) - [indexer/src/db/queries/evidence_daily.rs](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/748579ab718026efad54afcef4b2a5186fe82662/indexer/src/db/queries/evidence_daily.rs) ## Recommended direction - Introduce strict bounded raw-amount parsing with typed missing/invalid/overflow errors; distinguish allowed real zero from failed conversion. - Reject or quarantine the complete affected economic event with bounded observability and documented retry policy; retain deterministic block progress without a poisoned-row retry loop. - Preserve event-emitter provenance and aggregate idempotency across reorg/replay; reuse shared strict parsing helpers. ## Acceptance criteria - [ ] Malformed mandatory amounts cannot enter swaps/fee/position ledgers as zero; actual valid zero is handled by schema policy. - [ ] Quarantined events are observable without secrets/real-user public receipts; malformed repeated events cannot wedge block processing. - [ ] Valid largest-supported raw amounts, decimals and multi-hop fee identities remain exact; replays do not double-count. ## Test plan: supported and failure paths - Unit-test each economic event type with valid/zero/missing/negative/whitespace/decimal/scientific/overflow values and optional-field defaults. - Postgres-test ledger/rollup/evidence consistency, partial bad blocks, retries, reorg rollback and deduplication. - Run parser and block-processor suites plus API evidence/fee/volume integration tests on an isolated database. ## Test plan: attack, hack and abuse vectors - Synthetic approved/foreign contracts emitting amount-like junk, spoofed contract attributes and oversized numeric strings. - Repeated poison-event replay and mixed valid/malformed multihop records must not fabricate activity, clear balances or block all indexing. - Compare API and database amounts against authenticated valid event fixtures; invalid input yields errors/quarantine, never apparent zero-volume success. ## Verification criteria - Specific parser zero-coercion paths were source-verified; current lib baseline passes but does not prove malformed-event integrity. - Require typed rejection regressions, row/aggregate reconciliation and bounded processing 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 #285 hardened lifecycle emitter provenance; this report addresses numeric coercion and preserves that boundary. ## Related remediation reports [1391: oracle-integrity](https://git.cl8y.com/code/cl8y-dex-terraclassic/issues/1391), [1396: database-isolation](https://git.cl8y.com/code/cl8y-dex-terraclassic/issues/1396). 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 malformed event amounts without replacing them with accounting-corrupting values. No event-ingestion 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 malformed event amounts without replacing them with accounting-corrupting values. No event-ingestion remediation is included in this merge. This issue stays open for that substantive work, not merely a verification hold.
Author
Owner

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

New amount-integrity fixtures now include expected chain identity and block headers, and reorg replay restores identity after resetting mocks. make verify-issue-1395 passed the full library twice, integrity database tests twice, and related accounting/recovery suites.

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 #1406 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). New amount-integrity fixtures now include expected chain identity and block headers, and reorg replay restores identity after resetting mocks. make verify-issue-1395 passed the full library twice, integrity database tests twice, and related accounting/recovery suites. 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#1395
No description provided.