feat: implement Soroban MMR accumulator & Merkle proof verification engine - #1004
Merged
Mosas2000 merged 1 commit intoJul 30, 2026
Merged
Conversation
…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
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. |
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. |
Contributor
|
Thank you for the good job. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1002
Summary
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 extensionbackend/src/services/mmrAccumulator.service.ts):MmrAccumulatorServicein TypeScript mirroring the contract algorithm exactly —append,appendBatch,generateProof,verifyProof,verifyProofAgainstCurrent,serialize/fromSerializedbackend/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 appendPOST /mmr/append-batch— batch simulation (up to 1 000 leaves)POST /mmr/generate-proof— proof generation for a given leaf indexGET /mmr/state— live root, leaf count, active peaksComplexity
Every proof path length ≤ ⌊log₂ N⌋ + peaks_count ≤ 2 log₂ N, giving O(log N) space and verification time as required.