How Do ZK Rollups Work? Details and Implementation

Joseph Appolos
Joseph Appolos
Technical Writer
ZK rollups are a type layer 2 scaling solution designed to increase the throughput of blockchain networks without compromising security.

Zero-knowledge (ZK) rollups are increasingly becoming the go-to solution for scaling Ethereum without sacrificing security or decentralization—the scalability trilemma of blockchains. As developers continue to push the boundaries of blockchain, understanding ZK rollups at a granular level is essential for building the next generation of dApps.

This article delves into the intricacies of ZK rollups, offering a unique and technical perspective tailored for developers and crypto enthusiasts.

What are ZK Rollups?

ZK rollups, or Zero-Knowledge rollups, are a type layer 2 scaling solution designed to increase the throughput of blockchain networks without compromising security. ZK rollups bundle or "roll up" multiple transactions into one transaction, which is then processed off-chain. The results of these transactions are then submitted to the layer 1 blockchain (e.g., Ethereum) as a single proof.

One critical component of ZK rollups is using "zero-knowledge proofs.” These cryptographic proofs allow one party to prove to another that a statement is true without revealing additional information. In the context of ZK rollups, zero-knowledge proofs are used to verify the correctness of the off-chain transactions without processing each transaction individually on-chain.

How ZK Rollups Differ from Other Scaling Solutions

ZK rollups are often compared to other layer 2 scaling solutions like sidechains and sharding. However, the distinction lies in how they achieve scalability and security. Sidechains require a separate blockchain to process transactions operating independently with their consensus mechanisms, often sacrificing some security for scalability.

Sharding, however, involves splitting the blockchain into smaller, more manageable pieces. Each piece can process transactions independently but introduces complexities in maintaining consensus.

ZK rollups ZK rollups operate directly on the main (layer 1) blockchain, maintaining its underlying security by inheriting its consensus mechanism. By contrast, they offer a more straightforward and secure solution.

This approach ensures that transactions are secure and reduces the computational load on the layer 1 blockchain, thereby improving scalability without compromising decentralization or security.

Comparison

Here’s a detailed comparison between ZK rollups and other popular scaling solutions like Optimistic Rollups, Sidechains, and State Channels:

feature/AspectZK RollupsOptimistic RollupsSidechainsState Channels
Verification MethodZero-knowledge proofs (zk-SNARKs, zk-STARKs)Fraud proofsIndependent consensus mechanismOff-chain transactions with final state on-chain
Transaction FinalityImmediate upon proof verificationDelayed (up to 7 days for fraud-proof)Immediate (depends on sidechain’s consensus)Immediate (upon closing the channel)
SecurityHigh (secured by main chain and cryptographic proofs)Moderate (depends on fraud detection)Varies (depends on sidechain’s security)High (secured by main chain)
ScalabilityHigh (batch processing and proof aggregation)High (batch processing)High (independent processing)High (off-chain processing)
EVM CompatibilityVaries (zkEVMs are Compatible)Fully EVM-CompatibleDepends on SidechainCompatible
Data AvailabilityEnsured by main chain or external solutionsEnsured by main chainDepends on sidechain’s designEnsured by participants
ComplexityHigh (complex cryptographic proofs)Moderate (simpler fraud proofs)Varies (depends on sidechain’s implementation)Moderate (requires channel management)
PrivacyHigh (zero-knowledge proofs)Low (transactions are public)Varies (depends on sidechain’s design)Low (transactions are visible to participants)

Technical Deep Dive

Zero-knowledge proofs are a cornerstone of ZK rollups, so let's break them down. A zero-knowledge proof allows a prover to convince a verifier that a particular statement is true without revealing any other information. This concept is critical in ZK rollups, where the goal is to validate multiple transactions off-chain while only posting proof on-chain.

Types of Zero-Knowledge Proofs: zk-SNARKs and zk-STARKs

zk-SNARKs (Zero-Knowledge Succinct Non-Interactive Arguments of Knowledge): These are the more commonly used proofs in ZK rollups. They are succinct, meaning they are small in size and non-interactive, meaning they do not require interaction between the prover and the verifier after the initial setup.

The downside of zk-SNARKs is that they require a trusted setup—a one-time generation of cryptographic parameters that, if compromised, could undermine the security of the proofs.

How ZK-SNARK works. Source: Wallstreetmojo.

zk-STARKs (Zero-Knowledge Scalable Transparent Arguments of Knowledge): These are a newer form of ZKPs that do not require a trusted setup, making them more secure in certain respects. They are also more scalable but typically produce more extensive proofs than zk-SNARKs, which can be a trade-off in some scenarios.

How Zero-Knowledge Proofs Work in ZK Rollups

In the context of ZK rollups, zero-knowledge proofs are used to verify the correctness of a batch of transactions processed off-chain. Here’s a simplified overview of how this works:

  1. Batching Transactions: Multiple transactions are aggregated into a single batch off-chain.

  2. Generating the Proof: A zero-knowledge proof is generated for the entire batch, proving that all transactions within the batch are valid.

  3. Submitting the Proof: The proof, along with a summary of the batch (such as the updated state root), is submitted to the main blockchain.

  4. Verification: The main blockchain verifies the proof. If the proof is valid, the state of the blockchain is updated accordingly.

ZK Rollup Architecture

ZK rollups are built on critical components that work together to ensure secure, efficient, and scalable transaction processing off-chain. The architecture of a ZK rollup can be split into two main components - on-chain and off-chain components.

On-Chain Components

These include any data/component necessary for validating proofs and ensuring the rollup operates according to the protocol's rules. These components include:

  1. Verifier: On the main chain, the verifier ensures that only valid state transitions are accepted by checking the proofs generated by the prover, maintaining the ZK rollup's integrity.

  2. Smart Contracts: Located on Ethereum's main chain, these contracts manage the rollup’s state, validate proofs, and enforce correct state transitions, securing the rollup.

  3. State Commitment (Merkle Tree): The Merkle root, updated with each transaction batch, summarizes the rollup's state, ensuring efficient state verification.

  4. Calldata: Transaction data is stored on-chain in compressed form, reducing costs while maintaining state constructibility.

Off-Chain Components

These include the generation of proofs, transaction aggregation, and any state transitions that occur off-chain. The heavy lifting happens off-chain, with only the proof being submitted on-chain, which is crucial to achieving scalability. The components involved are:

  1. Sequencer/Operator: Aggregates and orders transactions off-chain, bundles them into batches and submits them to the main chain. It also generates validity proofs to ensure transaction correctness.

  2. Prover: Creates zero-knowledge proofs (ZKPs) like ZK-SNARKs or ZK-STARKs, ensuring that batched transactions are processed correctly without revealing sensitive data and maintaining security and privacy.

  3. Data Availability Layer: Ensures the accessibility of data needed to reconstruct the rollup’s state, stored on-chain or through decentralized solutions for system reliability.

zkEVMs in Relation to ZK Rollups

zkEVMs (Zero-Knowledge Ethereum Virtual Machines) extend the functionality of ZK rollups by allowing them to support Ethereum smart contracts fully. While ZK rollups improve scalability by processing transactions off-chain and validating them with zero-knowledge proofs, zkEVMs ensure these rollups are compatible with the Ethereum Virtual Machine, enabling seamless deployment of existing dApps without significant changes.

This integration maintains Ethereum's security and functionality while benefiting from the scalability and cost-efficiency of ZK rollups, making zkEVMs a crucial bridge between Ethereum’s Layer 1 and scalable Layer 2 solutions.

Types of zkEVMs and Their Applications

zkEVMs are categorized into several types, each offering different levels of compatibility and performance.

Type 1 zkEVMs

These aim for complete equivalence with Ethereum, meaning they don’t change the core Ethereum logic, making them fully compatible with existing Ethereum dApps, but the trade-off is slower performance due to longer prover times.

Currently, Type 1 zkEVMs are more theoretical, with no fully deployed examples on the mainnet yet.

Type 2 zkEVMs

Type 2 zkEVMs slightly modify Ethereum’s logic to improve performance, especially by reducing prover times. They remain highly compatible with Ethereum dApps, requiring only minimal adjustments. Polygon zkEVM is a notable Type 2 zkEVM, designed to be both efficient and compatible.

Type 3 zkEVMs

These make more significant changes to improve efficiency, such as faster prover times, but may require some adjustments to dApps. They serve as a middle ground, offering better performance at the cost of some compatibility. Scroll zkEVM is an example in this category.

An overview of Scroll Architecture. Source: Scroll Medium.

Type 4 zkEVMs

Type 4 zkEVMs are the most optimized for performance. They compile smart contracts into a more suitable form for ZK-SNARKs, resulting in very fast prover times but requiring significant changes to dApps.  An example of this architecture is zkSync Era, a leading Type 4 zkEVM, offering high scalability and low costs.

Developer’s Guide to Implementing ZK Rollups

Implementing ZK rollups can be complex, requiring a well-rounded understanding of the tools, frameworks, and best practices across various ZK rollup solutions. Below is a comprehensive guide that covers multiple ZK rollup ecosystems.

1. Required Tools and Frameworks

To implement ZK rollups, developers rely on many tools and frameworks tailored to different platforms. These include the zkSync SDK, StarkNet CLI, Polygon’s zkEVM tools, Aztec SDK, and Loopring SDK, depending on the ZK Rollup solution you want to implement.

Circom is used to construct zero-knowledge circuits, and zkInterface is used for interoperability among zk-SNARK and zk-STARK implementations. These tools collectively enable the development of scalable, secure, and privacy-focused ZK rollup solutions.

2. Set Up the Environment

  • Install Necessary Tools: Begin by setting up a development environment using tools like Hardhat or Truffle for smart contract development, and choose the relevant SDK or CLI for the ZK rollup you plan to use.

  • Zero-Knowledge Proof Libraries: Tools like snarkjs, circom, or other proof generation libraries should be installed to handle the creation of ZKPs (Zero-Knowledge Proofs).

  • Local Blockchain Instance: Use tools like Ganache to create a local blockchain environment for testing and debugging.

  • Choose a ZK Rollup Network: Whether it's zkSync, StarkNet, Polygon zkEVM, Aztec, or Loopring, choose the network that aligns with your project’s goals.

3. Building and Integrating Zero-Knowledge Proofs

  • Design the Circuit: Define the computation logic for your application by writing circuits that represent the data flows and transactions.

  • Generate Proofs: Use libraries like zk-SNARKs, zk-STARKs, or other relevant tools based on the specific ZK rollup solution to generate the necessary proofs.

4. Writing and Deploying Smart Contracts

  • Develop Rollup Contracts: Write smart contracts tailored to the ZK rollup, ensuring they handle batch processing, proof verification, and state updates. The specifics will vary depending on whether you use zkSync, StarkNet, or another platform.

  • Deploy Contracts: Deploy your contracts first on a testnet, like Rinkeby or Goerli, using deployment tools suitable for your environment.

5. Debugging and Testing

  • Debugging Tools: Utilize debugging features in Hardhat, Truffle, or specific tools provided by your ZK rollup framework (e.g., zkSync's or StarkNet's debugging utilities) to trace and resolve issues.

  • Testing: Implement comprehensive unit and integration tests, focusing on the interaction between zero-knowledge proofs and smart contracts.

6. Optimizing for Gas Efficiency

  • Calldata Optimization: In any ZK rollup implementation, reducing the size of the calldata can significantly lower gas costs, which is a crucial step for maintaining cost efficiency.

  • Optimize Storage and Computation: Avoid costly operations like excessive storage writes and optimize loops and computations, which can be particularly expensive on Ethereum.

7. Addressing Common Vulnerabilities

  • Trusted Setup Risks: For zk-SNARK-based systems, ensure the trusted setup is secure. Multi-party computation (MPC) ceremonies can be used to mitigate risks associated with compromised setups.

  • Data Availability: Ensure your system is designed to handle data availability issues, particularly in rollups like Aztec, which emphasizes privacy, or Loopring, which focuses on high-frequency trading.

Case Studies of Projects Using ZK Rollups

Several blockchain projects have already implemented ZK rollups with notable success. Let's explore a few examples:

Loopring

Loopring is a decentralized exchange (DEX) that utilizes ZK rollups to achieve high-speed, low-cost trading on Ethereum. By batching transactions off-chain and verifying them with zero-knowledge proofs on-chain, Loopring offers transaction speeds of up to 2,025 trades per second, reducing gas costs by up to 100x compared to traditional on-chain transactions.

Loopring’s Smart Contract Architecture. Source: Loopring Twitter

zkSync

Developed by Matter Labs, zkSync is a layer 2 scaling solution that leverages ZK rollups to enable fast and secure transactions on Ethereum. It processes transactions off-chain, using zk-SNARKs for verification, which are then submitted to the Ethereum mainnet. zkSync supports various applications, including payments and smart contracts, offering near-instant finality and significantly lower fees.

Souce: zkSync homepage.

StarkNet

StarkNet, built by StarkWare, is a leading ZK rollup solution using zk-STARK technology. It is designed for high scalability and privacy, allowing developers to run general-purpose smart contracts with the security of zero-knowledge proofs. StarkNet supports various decentralized applications (dApps) and is known for its high transaction throughput.

Polygon zkEVM

Part of the Polygon ecosystem, Polygon zkEVM provides a scalable, Ethereum-compatible environment that uses ZK rollups to process transactions off-chain while proving their validity on-chain. This process ensures compatibility with existing Ethereum smart contracts, making it accessible for developers familiar with Ethereum's ecosystem.

Other zkEVM Projects

  • Scroll: Scroll is a zkEVM-based ZK rollup focused on high throughput and low latency. It offers full EVM compatibility, allowing developers to easily port existing Ethereum smart contracts to Scroll with minimal modifications, making it a promising solution for decentralized finance (DeFi) applications.

  • Aztec: Aztec is a privacy-focused ZK rollup that combines public and private smart contracts. It uses a hybrid model with layers of ZK infrastructure to encrypt transactions, providing developers with tools to build privacy-preserving applications on Ethereum.

  • Linea: Developed by ConsenSys, Linea is a zkEVM implementation designed to enhance Ethereum's scalability. It integrates with popular tools like MetaMask and Truffle, offering a seamless developer experience while maintaining full EVM compatibility.

  • Taiko: Taiko is an early-stage Ethereum-equivalent ZK rollup that prioritizes EVM compatibility. It supports all Ethereum opcodes, allowing developers to transition their projects seamlessly without requiring modifications to existing code.

Covalent's Role in Supporting the ZK Rollup Ecosystem

Covalent, now known as GoldRush, has played a pivotal role in advancing the ZK Rollup ecosystem through strategic partnerships and comprehensive data services. By collaborating with Scroll, a zkEVM solution designed to scale Ethereum, Covalent became the first Web3 data aggregator to provide complete data transparency for zkEVM blockchains.

This integration allows developers to access detailed, real-time data crucial for optimizing the efficiency and security of ZK Rollups.

Covalent's support extends to other zkRollup platforms like Polygon zkEVM and zkLink Nova, ensuring developers have the tools to build scalable and interoperable dApps. Through its unified API, Covalent facilitates the growth and adoption of ZK Rollup technologies, making it a key player in enhancing the scalability and usability of blockchain networks.

Upcoming Advancements in ZK Rollups

The future of ZK Rollups is promising, with several important advancements on the horizon:

  1. zkPorter: zkSync is developing zkPorter, a hybrid model combining ZK Rollups with off-chain data availability. This approach offers users the choice between storing data on-chain for maximum security or off-chain to reduce costs, enhancing scalability and flexibility.

  2. Recursive Proofs: Research into recursive zero-knowledge proofs (ZKPs) advances, where one proof can validate another. This innovation allows for more complex transactions to be verified succinctly on-chain, further boosting the scalability and efficiency of ZK Rollups.

Conclusion

ZK rollups represent a significant leap forward in blockchain scalability, offering a solution that preserves the security and decentralization of layer 1 blockchains while dramatically increasing throughput. For developers, understanding and experimenting with ZK rollups is not just a technical challenge—it's an opportunity to be part of the next wave of blockchain innovation. So dive in, start experimenting, and help build the scalable blockchain solutions of tomorrow.

Read more

Ready to Dive In?

Get started with Covalent API in minutes. Sign up for a free API key and start building.

Support

Explore multiple support options! From FAQs for self-help to real-time interactions on Discord

Contact Sales

Interested in our professional or enterprise plans? Contact our sales team to learn more.