Compass Bureau

zkrollup merkle trees

Getting Started with ZK-Rollup Merkle Trees: What to Know First

June 14, 2026 By Kai Stone

Zero-knowledge rollups (ZK-rollups) have emerged as a leading Layer 2 scaling solution for blockchain networks, achieving high throughput while preserving security by anchoring validity proofs on Layer 1. At the heart of every ZK-rollup lies a Merkle tree structure that compresses the state of thousands of off-chain transactions into a single, verifiable root. Understanding this data structure is essential before evaluating rollup architectures, designing applications, or assessing tradeoffs between cost, latency, and data availability. This article provides a foundation for what Merkle trees do inside ZK-rollups, how they interact with zero-knowledge proofs, and what developers should consider when getting started.

What is a Merkle Tree and Why ZK-Rollups Use It

A Merkle tree is a binary hash tree where each leaf node stores a piece of data (typically a transaction or an account balance), and each internal node stores the cryptographic hash of its two child nodes. The root of the tree—the Merkle root—uniquely commits to the entire dataset. In a ZK-rollup, the operator collects hundreds or thousands of off-chain transactions, constructs a Merkle tree of the updated state (e.g., account balances or smart contract storage), and then generates a zero-knowledge proof attesting that the state transition is valid. This proof, along with the new Merkle root, is submitted to the Layer 1 chain. Anyone can verify the proof without re-executing the transactions, because the proof guarantees that the new root is the correct outcome of applying the batch of transactions to the previous root.

The key advantage of this approach is succinctness: the on-chain footprint per batch is a fixed-size proof (typically ~200-500 bytes) plus the new Merkle root (32 bytes), regardless of how many transactions are batched. This compression enables throughput on the order of 2,000–4,000 transactions per second (TPS) compared to ~15 TPS on Ethereum Layer 1. However, the efficiency depends heavily on the choice of Merkle tree parameters. Most ZK-rollups use a binary Merkle tree with a fixed depth (e.g., depth 32 for a state tree containing up to 232 accounts), but some variants use ternary trees or Patricia tries. The tradeoff is between proof generation time (which scales with tree depth) and on-chain data size. For instance, a deeper tree increases the number of hashes needed in the proof, raising prover costs but potentially reducing the cost of inclusion proofs for users.

Role of Merkle Trees in Validity Proofs and Data Availability

In a ZK-rollup, the Merkle tree serves two distinct but related functions: commitment to the state and provision of membership proofs. The zero-knowledge circuit proves that for a given initial root, a batch of valid transactions produces a new root. This circuit internally recomputes the affected Merkle branches, verifying that the hashes match the claimed updates. The prover does not need to reveal the entire tree—only the branches that changed. This is where the "zero-knowledge" property combines with the Merkle tree: the verifier learns only that the update is correct, not the balances or transaction details of unrelated parties.

Data availability is a separate concern. While the validity proof guarantees correctness, the Layer 1 must still be able to reconstruct the rollup's state in case of an operator failure. Most ZK-rollups publish the transaction data (or a compressed version) on a dedicated data availability layer (e.g., Ethereum calldata or a separate data availability chain). The Merkle tree structure ensures that any data availability solution can quickly verify that the published data matches the root. Without the tree, the verifier would need to process all transactions sequentially, defeating the purpose of batching. With the tree, a user can prove their balance with a simple Merkle proof against the current root submitted on-chain, enabling trustless withdrawals. This mechanism is why Merkle trees are non-negotiable in production-grade ZK-rollups.

Key Parameters and Tradeoffs in Merkle Tree Design

Choosing the right Merkle tree configuration for a ZK-rollup requires balancing proof generation time, verification cost, and storage overhead. Below is a breakdown of the critical parameters:

  • Tree depth: The number of levels determines the maximum number of leaves. A depth of 32 supports 4 billion accounts, but each proof requires 32 hashes for any leaf. Deeper trees increase the size of inclusion proofs, which matters for withdrawal operations. Some rollups use a depth of 64 to future-proof, but this adds ~10% more work for the prover.
  • Hash function: The choice of hash significantly impacts prover overhead. Poseidon, a zero-knowledge-friendly hash function, is common because it requires fewer constraints in the circuit compared to SHA-256. For example, Poseidon hash for a 256-bit value costs only ~200 constraints, while SHA-256 costs ~27,000 constraints per hash. Using Poseidon can reduce overall proof generation time by a factor of 50–100.
  • Node degree: Binary trees (degree 2) are standard, but some implementations use 4-ary or 8-ary trees. Higher arity reduces tree depth but increases each node's fan-out, raising the cost of verifying a single branch. Binary trees remain the most efficient for circuits because they minimize the number of input wires per hash operation.
  • Persistence and pruning: In real-time operation, the rollup maintains the full tree in a database. Pruning old leaves (e.g., after a certain number of state roots) reduces storage but complicates reconstructing historical proofs. Most rollups keep the last 2^16 roots for light client verification.

When evaluating a specific ZK-rollup, these parameters directly affect gas costs on Layer 1 and the latency of transaction finality. For example, a rollup using a depth-32 binary tree with Poseidon hashing typically spends around 200,000 gas per batch submission, while a deeper tree with SHA-256 can exceed 1 million gas. Developers building on top of a rollup should understand these tradeoffs to optimize their application's data submission patterns—for instance, batching state updates to minimize the number of Merkle proofs required.

If you are exploring practical implementations, you can begin testing these concepts right away by reviewing rollup client source code that constructs and verifies Merkle proofs. Understanding the parameter choices in a live system will solidify the theory behind them.

How ZK-Rollups Use Merkle Trees for Privacy

While the primary goal of ZK-rollups is scalability, the combination of zero-knowledge proofs and Merkle trees enables inherent privacy properties for certain operations. Because the validity proof only reveals that a state transition is correct, not the specifics of individual transactions, users can batch deposits, transfers, and withdrawals without exposing their balances to the network. This is particularly relevant in financial applications or decentralized identity systems where transaction confidentiality is desired.

The Merkle tree structure facilitates private membership proofs: a user can prove they are part of the rollup's state (e.g., owning a specific account) without revealing which account they own. This is done by providing a Merkle inclusion proof that links a user's public key to a leaf in the tree, combined with a zero-knowledge proof that the key is controlled by the prover. The verifier only learns that the leaf exists at a certain position, not which one. This technique is used in private smart contract platforms built on top of ZK-rollups, such as those implementing the Tornado Cash-style mixer. For a deeper dive, consult the documentation on Zkrollup Privacy Features to see how recursive proofs and Merkle tree traversal enable full transaction privacy without compromising scalability.

Note that privacy is not automatic in all ZK-rollups. Some rollups prioritize transparency for compliance or interoperability, publishing transaction amounts and account balances in plaintext. The privacy layer is optional and typically requires additional circuit constraints to ensure that the Merkle proof does not leak information through the tree path. Operators must also design the Merkle tree with a uniform depth and zero-knowledge-friendly hash to avoid side-channel attacks that correlate user activity with proof generation time.

Practical Steps for Developers: Example Workflow

To solidly grasp Merkle trees in ZK-rollups, follow this concrete workflow:

  1. Set up a local test environment: Clone an open-source ZK-rollup framework like zkSync Era or Polygon zkEVM. These repos include Merkle tree implementations in Solidity and Rust.
  2. Build a simple Merkle tree: Write a script that creates a depth-8 binary tree with 256 leaves. Populate leaves with random 32-byte values. Compute the root and verify that it matches your manual computation.
  3. Generate a Merkle proof: For a given leaf, extract the sibling nodes and path indices required to compute the root. The standard approach uses a recursive function that traverses from leaf to root, keeping track of sibling hashes.
  4. Implement a zero-knowledge circuit: Use a DSL like Circom or Noir to write a circuit that takes the old root, a list of transactions, and the new root as public inputs, and the Merkle branches as private witnesses. Compile and generate a proof for a small batch (e.g., 10 transactions).
  5. Verify on a simulated chain: Deploy a minimal Solidity contract that takes the proof and the new root, and verifies it using the bn254 elliptic curve pairing precompiles. Monitor gas consumption—this will show the real cost of tree depth and hash function choices.

By following these steps, you will directly observe how each parameter affects performance. For instance, switching from SHA-256 to Poseidon in step 3 reduces proof generation time from minutes to seconds. These hands-on iterations are the fastest way to internalize the material.

Conclusion: What to Prioritize When Starting Out

Getting started with ZK-rollup Merkle trees requires a clear understanding of the cryptographic building blocks and the design space. Your first priority should be to grasp the link between the Merkle root and the validity proof—this is the foundation of trustless off-chain execution. Next, recognize that the choice of hash function and tree depth is not merely theoretical; it directly dictates the economic viability of your rollup or dApp. Finally, evaluate whether privacy features are needed for your use case, as they introduce additional circuit complexity but can be efficiently implemented using Merkle membership proofs.

As you move forward, focus on practical experiments: run a full node, analyze the proof generation time for various batch sizes, and benchmark on-chain verification costs. The ecosystem is evolving rapidly, but the core mechanics of Merkle trees in ZK-rollups remain stable. Master these, and you will be well-prepared to build or audit next-generation scalable systems.

Related: zkrollup merkle trees — Expert Guide

Spotlight

Getting Started with ZK-Rollup Merkle Trees: What to Know First

Learn the core mechanics of ZK-rollup Merkle trees, how they batch transactions with zero-knowledge proofs, and why this design matters for scalability and privacy.

K
Kai Stone

Explainers, without the noise