Skip to content

Implement verify_merkle_proof for miden::agglayer#2361

Merged
mmagician merged 11 commits intoagglayer-fixed-2from
andrew-verify-merkle-proof
Feb 4, 2026
Merged

Implement verify_merkle_proof for miden::agglayer#2361
mmagician merged 11 commits intoagglayer-fixed-2from
andrew-verify-merkle-proof

Conversation

@Fumuran
Copy link
Contributor

@Fumuran Fumuran commented Jan 28, 2026

This PR implements a verify_merkle_proof helper 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:

  • Implement Solidity compatibility test

Closes: #2278

@partylikeits1983 partylikeits1983 added no changelog This PR does not require an entry in the `CHANGELOG.md` file agglayer PRs or issues related to AggLayer bridging integration labels Jan 28, 2026
@Fumuran Fumuran marked this pull request as ready for review January 29, 2026 15:52
Copy link
Collaborator

@mmagician mmagician left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The core of the logic looks very good

I haven't reviewed the test/test generation code yet

Comment on lines 97 to 98
# Merkle path is guaranteed to contain 32 nodes
repeat.32
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not for this PR, but I wonder if we should ensure that the caller in #2288 guarantees this

@Fumuran Fumuran force-pushed the andrew-verify-merkle-proof branch from 42d3a8e to 73f164e Compare February 3, 2026 00:39
@Fumuran
Copy link
Contributor Author

Fumuran commented Feb 3, 2026

Excuse me for doing the force push, by mistake I rebased my local branch instead of merging it.

@Fumuran Fumuran requested a review from mmagician February 3, 2026 00:56
@Fumuran Fumuran requested a review from mmagician February 3, 2026 14:36
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_proof and crypto_utils::calculate_root in 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 DepositContractBase behavior.
  • Refactor shared Keccak/Merkle helper utilities (memory double-word load/store, test-only digest formatting) and integrate SMT root verification into bridge_in.masm with 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.

@mmagician mmagician requested a review from bobbinth February 3, 2026 19:23
Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a very in-depth review from me - but looks good! Thank you!

@mmagician mmagician merged commit 6f6b40e into agglayer-fixed-2 Feb 4, 2026
15 checks passed
@mmagician mmagician deleted the andrew-verify-merkle-proof branch February 4, 2026 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agglayer PRs or issues related to AggLayer bridging integration no changelog This PR does not require an entry in the `CHANGELOG.md` file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants