Skip to content

feat(frontend): Client-Side SPV Header Verification and Cuckoo Filter WASM Integration (#301) - #338

Closed
huangji6693-max wants to merge 1 commit into
LynxXProtocol:mainfrom
huangji6693-max:feat/client-spv-cuckoo-filter-wasm-301
Closed

huangji6693-max wants to merge 1 commit into
LynxXProtocol:mainfrom
huangji6693-max:feat/client-spv-cuckoo-filter-wasm-301

Conversation

@huangji6693-max

@huangji6693-max huangji6693-max commented Oct 26, 2026 •

Copy link
Copy Markdown

Summary

Implements client-side Simplified Payment Verification (SPV) header chain validation and a zero-allocation Cuckoo Filter WASM pre-filter for the browser local indexer (#301).

Closes #301
/claim #301

Architecture & Key Changes

  1. Zero-Allocation Cuckoo Filter & Merkle Branch Verifier in Rust (contracts/validation/src/cuckoo.rs & contracts/validation/src/lib.rs):

    • Implemented ZeroAllocCuckooFilter using a fixed [[u16; 4]; 1024] 4-way associative bucket table (~8 KiB) with FNV-1a 64-bit primary bucket indexing, non-zero 16-bit fingerprints ([1, 65535]), XOR alternate bucket involution (i2 = (i1 ^ (hash(fp) & 0x3FF)) & 0x3FF), and bounded deterministic Cuckoo eviction kicks (MAX_CUCKOO_KICKS = 64).
    • Implemented verify_sha256_merkle_branch for deterministic SHA-256 Merkle inclusion branch verification without heap allocations.
  2. WASM Bridge (frontend/src/wasm/pactum-validation/pactum_validation.js & pactum_validation.d.ts):

    • Exported zero-allocation Uint16Array Cuckoo filter primitives (cuckoo_filter_reset, cuckoo_filter_len, cuckoo_filter_contains, cuckoo_filter_insert, cuckoo_filter_delete) matching the Rust ZeroAllocCuckooFilter semantics.
  3. WebWorker SPV Header Chain & BucketList Inclusion Verifier (frontend/src/workers/validation.worker.ts):

    • Added verifySpvHeaderChain validating strictly sequential Stellar ledger headers, previous-header hash links, canonical header SHA-256 hashes, and 4-level Stellar BucketList SHA-256 Merkle roots (curr_0..3 / snap_0..3).
    • Added evaluateCuckooInclusionProof combining O(1) Cuckoo Filter pre-checks with full SHA-256 Merkle inclusion branch verification against the verified BucketList root.
    • Added worker message handlers VERIFY_SPV_HEADER_CHAIN and VERIFY_CUCKOO_INCLUSION.
  4. Local Indexer RPC Guard (frontend/src/lib/localIndexer/rpcClient.ts):

    • Added SpvStateManager to verify incoming RPC ledger states and commitments before rendering balances or commitments in the UI.
    • Detects and blocks spoofed balances, tampered commitment amounts/statuses, and phantom RPC entries that fail Cuckoo filter or Merkle inclusion verification, surfacing explicit WARNING: ... security alerts.

Verification

  • Rust Unit Tests (contracts/validation): cargo test -p pactum-validation — 13 / 13 passed
  • Rust Clippy: cargo clippy -p pactum-validation --lib -- -D warnings — 0 warnings
  • Frontend Vitest Suite (spvVerification.test.ts + localIndexer): npx vitest run src/lib/localIndexer/spvVerification.test.ts src/lib/localIndexer/poller.test.ts src/lib/localIndexer/events.test.ts src/lib/localIndexer/db.test.ts — 29 / 29 passed
  • Frontend Linter & Typecheck: npm run lint (oxlint) & npx tsc -b --noEmit — 0 warnings, 0 errors
  • Numeric ID Policy Check: node scripts/ci/check-numeric-ids.mjs — PASSED

… WASM Integration (LynxXProtocol#301)

- Implement zero-allocation Cuckoo filter (ZeroAllocCuckooFilter) and SHA-256 Merkle inclusion branch verifier (verify_sha256_merkle_branch) in contracts/validation/src/cuckoo.rs
- Export zero-allocation Uint16Array Cuckoo filter WASM primitives (cuckoo_filter_reset, cuckoo_filter_len, cuckoo_filter_contains, cuckoo_filter_insert, cuckoo_filter_delete) in pactum_validation
- Add VERIFY_SPV_HEADER_CHAIN and VERIFY_CUCKOO_INCLUSION message handlers to validation.worker.ts with 4-level Stellar BucketList SHA-256 Merkle root verification
- Integrate SpvStateManager into frontend/src/lib/localIndexer/rpcClient.ts to enforce cryptographic SPV state verification and Cuckoo filter pre-checks before rendering balances or commitments, blocking spoofed RPC payloads with WARNING: security alerts
- Add comprehensive Rust (13/13) and Vitest (14/14) test suites covering honest chains, spoofed balances, tampered commitments, and phantom RPC entries

Closes LynxXProtocol#301
@coderabbitai

coderabbitai Bot commented Oct 26, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: af5e8108-4fa0-49a4-bce4-9d691a42f824
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@amankoli09 amankoli09 closed this Nov 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

design(frontend): Define authenticated Stellar state verification

2 participants