When it comes to choosing Ethereum scaling solutions, Web3 developers have many options to choose from. There are Layer 1 improvements like Ethereum 2.0, Layer 2 chains like Optimism and Arbitrum, and side chains like Polygon or xDai.
Even within the category of Layer 2 Ethereum scaling solutions, web3 developers have choices to make between using state channels, optimistic rollups, or zero-knowledge (ZK) rollups.
ZK-rollups are an increasingly popular scaling solution for Ethereum and have the potential to drastically reduce costs and time it takes for transactions to be confirmed. To help you choose the right scaling solution for your dApp, we’ll explain the differences between ZK-rollups and other Layer 2 solutions, and deep dive into the ZK technology.
What are Ethereum Layer 2s?
Ethereum Layer 2s are blockchains that are designed to be faster and cheaper than transacting on the main Ethereum chain, while leveraging the security of Ethereum’s execution layer. Layer 2s are primarily focussed on solving high transaction fees and low transaction speeds that occur on Ethereum during periods of network congestion (when many users are attempting to use the Ethereum network at the same time).
At a high level, most Layer 2 solutions process transactions “off-chain”, as in, not on Ethereum, and batch those transactions into a simpler, and therefore cheaper transaction that gets published on the Ethereum blockchain.
However, the mechanisms Layer 2 scaling solutions use to securely process, batch, and publish off-chain transactions onto Ethereum depends on the scaling technology they are using.
Let’s look at the three different types of Layer 2 scaling technologies.
What types of Ethereum Layer 2s exist and how are they different?
There are three types of Ethereum Layer 2s that help solve Ethereum's scalability problem: state channels, optimistic rollups, and zero-knowledge rollups.
Let’s explore the differences between these three different types of Layer 2 technologies.
1. State Channels
State channels are an Ethereum scaling solution that allow users to make unlimited transactions off-chain while only having to submit two transactions onto the Ethereum network: the first transaction and the last transaction.
Here’s how it works:
- The first transaction opens a state channel and “locks” that state.
- Users perform transactions off-chain.
- The remaining state after off-chain transactions are complete is recorded in a second transaction that “closes” the state channel.
Examples of Ethereum L2s that leverage state channels include:
- Connext - a network for fast, trustless, cross-chain applications and communication
- Kchannels - offers a trust-minimized payment channel for Ethereum
- Perun - offers user an off-chain framework that supports real-time payments
- Radien - offers a fast, cheap way to transfer ERC20 tokens
2. Optimistic Rollups
Optimistic rollups involve processing a large volume of transactions, handling computation off-chain, and “rolling” them up in a simpler transaction that gets published to Ethereum’s execution layer.
Optimistic rollups are considered “optimistic” because transactions are assumed to be valid until they are proven false.
Before optimistic rollup transactions are confirmed on Ethereum’s main chain, there is a period of time when potentially invalid transactions can be disputed by submitting a fraud proof.
Once that fraud proof’s dispute period is over, all remaining transactions are confirmed onto Ethereum.
Because optimistic rollup Layer 2s are designed to use fraud proofs, this confirmation window tends to increase transaction confirmation times than other solutions like Zero-Knowledge rollups.
Examples of Ethereum L2s that leverage optimistic rollups include:
- Arbitrum - the largest optimistic rollup by TVL ($3.2B) and market share (54.7%)*
- Metis - third largest optimistic rollup by TVL ($457M) and market share (7.84%)*
- Optimism - 2nd largest optimistic rollup by TVL ($465M) and market share (7.97%)*
- Boba Network - 4th largest optimistic rollup by TVL ($187M) and market share (3.22%)*
*Layer 2 TVL and market share data provided by L2Beat.
3. Zero-Knowledge Rollups
Zero-knowledge rollups (ZK-rollups) are similar to optimistic rollups in that they combine a large number of Layer 2 transactions that were executed off-chain and submit them as one transaction onto Ethereum.
However, instead of assuming transactions are valid until proven otherwise, ZK-rollups use validity proofs to instantly prove if transactions are valid or not.
Compared to optimistic rollups, developing EVM-compatible ZK-rollups is challenging due to the complexity of the technology and its ability to execute arbitrary code.This is something to consider when deciding to build on a ZK-rollup Layer 2 blockchain compared to another EVM-compatible blockchain.
Examples of Ethereum L2s that leverage ZK-rollups include:
- Starknet - used by dYdX and ImmutableX the leading decentralized exchange for perpetual contracts on Ethereum
- zkSync - used by dApps like Yearn Finance, FRAX, and Zerion
How do ZK-rollups work?
To understand how ZK-rollups work, we first need to understand the founding concept: zero-knowledge proofs (ZKPs)
ZKPs represent a way to prove that you know something without revealing what it is that you know.
For example, in the recently viral Wordle game, I can prove that I have the solution without revealing what the solution is by sending a screenshot of my final board. With zero knowledge of the actual answer, everyone can confidently agree that I have the correct result. This is the essence of a ZKP.
ZK-rollups use ZKPs by combining a large number of Layer 2 transactions (off-chain) into one transaction that then gets mined on the Ethereum mainnet.
Instead of mining 100s of transactions individually, they can be rolled up into a single transaction.
This single transaction takes form as a validity proof, otherwise known as a succinct, non-interactive argument of knowledge (SNARK) or succinct, transparent argument of knowledge (STARK).
SNARKs and STARKs are the same concept as a cryptographic transaction hash. Even though there are many components to a typical Ethereum transaction, they can all be represented in a unique transaction hash without revealing the transaction data, as seen in the example below.
Ultimately, mining this one transaction instead of hundreds of Ethereum transactions is what makes ZK-rollups significantly cheaper than using Ethereum’s Layer 1 chain.
Unlike optimistic rollups that force transactions to wait a period of time for fraud proofs, when a ZK-SNARK is sent to Ethereum the receiving smart contract can instantly verify if the proof is valid or not on-chain.
Because ZK-SNARKs are verified instantly, funds are able to be withdrawn on ZK-rollups as soon as the ZK-SNARK transaction is mined on Ethereum (~12 seconds), rather than waiting days or weeks for the dispute period to end.
Validity proofs prevent fraud without manual intervention or verification like fraud proofs, which makes transaction confirmation with ZK-rollups much faster and scalable than optimistic rollups.
Building dApps with ZK-rollup Technology
There are a handful of ZK-rollup solutions that are available for you to explore building with, including StarkNet, ZKSync, and Mina Protocol.