Skip to content

feat: implement Soroban MMR accumulator & Merkle proof verification engine - #1004

Merged
Mosas2000 merged 1 commit into
StellaBridge:mainfrom
unlimitedengineer:feat/mmr-accumulator-1002
Jul 30, 2026
Merged

feat: implement Soroban MMR accumulator & Merkle proof verification engine#1004
Mosas2000 merged 1 commit into
StellaBridge:mainfrom
unlimitedengineer:feat/mmr-accumulator-1002

Conversation

@unlimitedengineer

Copy link
Copy Markdown
Contributor

Closes #1002

Summary

  • Soroban contract (contracts/soroban/src/mmr_accumulator.rs): MmrAccumulatorContract — append-only leaf insertion, peak aggregation, bagged-root derivation, and O(log N) verify_mmr_proof + verify_against_current; domain-separated hashing (0x00 prefix for leaves, 0x01 for inner nodes); persistent storage with 90-day TTL extension
  • Backend service (backend/src/services/mmrAccumulator.service.ts): MmrAccumulatorService in TypeScript mirroring the contract algorithm exactly — append, appendBatch, generateProof, verifyProof, verifyProofAgainstCurrent, serialize/fromSerialized
  • API routes (backend/src/api/routes/mmrVerification.routes.ts, registered under /api/v1/reconciliation):
    • POST /verify-mmr-proof — stateless proof verification (all material in request body)
    • POST /mmr/append — simulation append
    • POST /mmr/append-batch — batch simulation (up to 1 000 leaves)
    • POST /mmr/generate-proof — proof generation for a given leaf index
    • GET /mmr/state — live root, leaf count, active peaks
  • 13 Soroban unit tests covering init, double-init guard, append, determinism, empty-root error, single/two-leaf proof round-trips, tampered leaf detection, 1 001-leaf tree consistency
  • 28 TypeScript unit tests covering all service methods, proof round-trips for 1/2/4/7-leaf trees, tampered data detection, 5 000-leaf spot verification, 10 000-leaf root stability, serialization, historical proof against captured root

Complexity

Every proof path length ≤ ⌊log₂ N⌋ + peaks_count ≤ 2 log₂ N, giving O(log N) space and verification time as required.

…tellaBridge#1002)

Adds a full Merkle Mountain Range (MMR) accumulator system spanning the
Soroban contract, backend service, API routes, and test suites.

Soroban contract (contracts/soroban/src/mmr_accumulator.rs):
- MmrAccumulatorContract with initialize, append, get_root, get_leaf_count,
  get_peaks, verify_mmr_proof, verify_against_current methods
- Domain-separated hashing: leaf = SHA-256(0x00 || data), node = SHA-256(0x01 || L || R)
- Append algorithm: merges leaf upward through peaks until a vacant height
  slot is found; O(log N) work per insertion
- bag_peaks(): sequential right-to-left merge of active peaks → single root
- verify_mmr_proof(): re-derives local subtree root from leaf + siblings,
  substitutes into peaks snapshot, bags, and compares against expected_root
- O(log N) space: only peaks (at most ⌊log₂ N⌋ + 1) are stored persistently
- 90-day TTL extension on every state write

Backend service (backend/src/services/mmrAccumulator.service.ts):
- MmrAccumulatorService class mirroring contract algorithm in TypeScript
- append(rawCommitment), appendBatch, generateProof(leafIndex)
- verifyProof(proof, expectedRoot), verifyProofAgainstCurrent(proof)
- serialize() / fromSerialized() for persistence integration
- hashLeaf / hashNode match Soroban domain separators exactly

API routes (backend/src/api/routes/mmrVerification.routes.ts):
- POST /api/v1/reconciliation/verify-mmr-proof — stateless proof verification
- POST /api/v1/reconciliation/mmr/append — simulation append
- POST /api/v1/reconciliation/mmr/append-batch — batch simulation
- POST /api/v1/reconciliation/mmr/generate-proof — proof generation
- GET  /api/v1/reconciliation/mmr/state — current root + leaf count + peaks
- Zod validation on all inputs; registered in reconciliation route group

Tests:
- contracts/soroban/tests/mmr_accumulator.test.rs (13 Soroban unit tests):
  init, double-init guard, append single/multiple, root changes, determinism,
  empty-root error, single-leaf proof, wrong-root failure, tampered leaf,
  two-leaf peak count, 1001-leaf determinism, verify_against_current
- backend/tests/unit/mmrAccumulator.test.ts (28 TypeScript tests):
  append semantics, invalid size rejection, root determinism, batch append,
  proof round-trips for 1/2/4/7-leaf trees, tampered leaf/sibling/root
  detection, out-of-range index error, historical proof against captured root,
  10 000-leaf root stability, 5 000-leaf spot verification, serialization

Closes StellaBridge#1002
@Mosas2000

Copy link
Copy Markdown
Contributor

The implementation of the Soroban MMR accumulator and its accompanying proof verification engine is exceptionally well-architected, providing a highly efficient, log-space solution for historical reserve commitments.

@Mosas2000

Copy link
Copy Markdown
Contributor

The seamless synchronization between the smart contract, backend services, and comprehensive test suites makes this a robust feature that is fully ready to be approved and merged.

@Mosas2000

Copy link
Copy Markdown
Contributor

Thank you for the good job.

@Mosas2000
Mosas2000 merged commit 5e79130 into StellaBridge:main Jul 30, 2026
16 checks passed
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.

feat: Implement Soroban State Archive Compression & Merkle Accumulator Proof Verification Engine

2 participants