Implement verify_merkle_proof for miden::agglayer#2361
Implement verify_merkle_proof for miden::agglayer#2361mmagician merged 11 commits intoagglayer-fixed-2from
verify_merkle_proof for miden::agglayer#2361Conversation
mmagician
left a comment
There was a problem hiding this comment.
The core of the logic looks very good
I haven't reviewed the test/test generation code yet
| # Merkle path is guaranteed to contain 32 nodes | ||
| repeat.32 |
There was a problem hiding this comment.
Not for this PR, but I wonder if we should ensure that the caller in #2288 guarantees this
crates/miden-agglayer/solidity-compat/test/MMRTestVectors.t.sol
Outdated
Show resolved
Hide resolved
crates/miden-agglayer/solidity-compat/test/MMRTestVectors.t.sol
Outdated
Show resolved
Hide resolved
crates/miden-agglayer/solidity-compat/test/MMRTestVectors.t.sol
Outdated
Show resolved
Hide resolved
42d3a8e to
73f164e
Compare
|
Excuse me for doing the force push, by mistake I rebased my local branch instead of merging it. |
crates/miden-agglayer/solidity-compat/test/SMTMerkleProofVectors.t.sol
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
This PR wires up a full end-to-end SMT Merkle proof verification path for AggLayer, implementing verify_merkle_proof/calculate_root in MASM and validating them against Solidity’s DepositContractBase.verifyMerkleProof using shared test vectors. It also refactors shared Keccak/Merkle helpers and integrates the new verification into the bridge-in flow.
Changes:
- Implement
crypto_utils::verify_merkle_proofandcrypto_utils::calculate_rootin MASM to compute SMT roots from Keccak-based Merkle paths and compare them against an expected root. - Add Solidity and Rust test infrastructure (Foundry test, JSON vectors, Rust compatibility tests) to ensure Miden’s implementation matches the Solidity
DepositContractBasebehavior. - Refactor shared Keccak/Merkle helper utilities (memory double-word load/store, test-only digest formatting) and integrate SMT root verification into
bridge_in.masmwith a dedicated error code.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
crates/miden-testing/tests/agglayer/test_utils.rs |
Adds reusable keccak_digest_to_word_strings helper and updates mainnet_exit_root test constant used in AggLayer tests. |
crates/miden-testing/tests/agglayer/mmr_frontier.rs |
Refactors to reuse the shared keccak_digest_to_word_strings helper from test_utils instead of a local copy. |
crates/miden-testing/tests/agglayer/crypto_utils.rs |
Introduces JSON-based Merkle proof vectors, parsing logic, and a test_solidity_verify_merkle_proof_compatibility test that compiles and executes MASM scripts calling crypto_utils::verify_merkle_proof against Solidity-generated fixtures. |
crates/miden-agglayer/src/errors/agglayer.rs |
Adds ERR_SMT_ROOT_VERIFICATION_FAILED MASM error mapping for SMT root verification failures to Rust error definitions. |
crates/miden-agglayer/solidity-compat/test/SMTMerkleProofVectors.t.sol |
Adds a Foundry test contract that builds a canonical SMT over 32 leaves, generates leaves/roots/paths arrays, sanity-checks them via Solidity verifyMerkleProof, and serializes them to JSON. |
crates/miden-agglayer/solidity-compat/test-vectors/merkle_proof_vectors.json |
Commits the generated Merkle proof test vectors (leaves, roots, per-leaf Merkle paths) which are consumed by Rust tests for Miden–Solidity compatibility. |
crates/miden-agglayer/asm/bridge/utils.masm |
Introduces shared mem_store_double_word/mem_load_double_word helpers for double-word big-endian memory operations used by SMT/MMR code. |
crates/miden-agglayer/asm/bridge/mmr_frontier32_keccak.masm |
Refactors to use the new shared utils::mem_store_double_word/mem_load_double_word helpers instead of local copies. |
crates/miden-agglayer/asm/bridge/crypto_utils.masm |
Extends crypto utilities with type aliases, local layout constants, a fully-implemented verify_merkle_proof that computes the SMT root via calculate_root and compares to an expected root with word::eq, and a calculate_root loop that walks a 32-level Keccak Merkle path using mem_stream and index bits. |
crates/miden-agglayer/asm/bridge/bridge_in.masm |
Integrates SMT root verification into the bridge-in flow: adjusts MAINNET_EXIT_ROOT_PTR to point at the exit roots block, threads LEAF_VALUE through process_global_index_mainnet, calls crypto_utils::verify_merkle_proof, and asserts with ERR_SMT_ROOT_VERIFICATION_FAILED. |
Makefile |
Extends generate-solidity-test-vectors target to also run the new Foundry test that produces merkle_proof_vectors.json. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
bobbinth
left a comment
There was a problem hiding this comment.
Not a very in-depth review from me - but looks good! Thank you!
This PR implements a
verify_merkle_proofhelper procedure, which calculates the SMT root based on the provided Merkle Path and leaf, and compares it to the provided root to ensure they are equal.TODO:
Closes: #2278