Original English article: https://www.nervos.org/zh/knowledge-base/zk_rollup_vs_optimistic_rollup

Rollup is a powerful blockchain scaling solution that has become very popular in the past two years. There are two types of Rollup, ZK Rollup and Optimistic Rollup, which serve the same purpose but have different functions.

Transactions in Optimistic Rollup are automatically assumed to be valid until proven otherwise, while ZK Rollup uses zero-knowledge proofs (explained below) to prove the validity of transactions. Both types of Rollup have their own advantages and disadvantages, which will be explained in detail below.

Why do we need Rollup?

The blockchain industry journey over the past few years has shown that it is nearly impossible to scale a monolithic blockchain with transaction execution, consensus, and data availability without sacrificing security and decentralization.

For this reason, many Layer 1 blockchains have recently begun using different Rollup solutions to alleviate throughput requirements by moving transaction execution to Layer 2. This way, the majority of transactions can be processed on a separate layer, which then batches together individual transactions that are settled on the underlying Layer 1.

Simply put, Rollup is an independent, high-throughput transaction execution network built on top and borrows the security of the Layer 1 blockchain. Rollup allows blockchain to scale to tens of thousands of transactions per second without compromising security and decentralization. Rollup provides users with a superior experience by significantly reducing transaction costs and increasing settlement times. In contrast, transactions on Ethereum can cost users anywhere from a few dollars to hundreds of dollars, depending on the current network congestion. On the other hand, current Ethereum-based Rollup transaction fees range from $0.01 to $0.1.

*Before continuing, please also review the explanation of Layer 1 vs. Layer 2 to fully understand the terminology used here.

The difference between ZK Rollup and Optimistic Rollup

The main difference between the two Rollup types is how they verify proofs.

Optimistic Rollups are called “optimistic” because they assume that all layer 2 transactions are valid unless proven otherwise. ZK Rollups, on the other hand, use complex cryptography called zero-knowledge proofs to prove the validity of transactions without knowing too much about the details of the transactions.

Another difference between the two technologies is the amount of data they publish to their underlying base chains. Because ZK Rollup has a mechanism to verify transactions before publishing them to the base chain, they do not need to transmit as much data to Layer 1 as their Optimistic counterparts. That is, ZK Rollup only publishes validity proofs to settle transactions with finality on the base chain, while Optimistic Rollup publishes the entire transaction data.

Data relayed to Layer 1 via ZK Rollup (left) and Optimistic Rollup (right)

For users, the key difference between the two Rollup types is the withdrawal time. That is, because Optimisitc Rollup relies on validators to check each transaction and may dispute it if they believe it is invalid, the withdrawal time of assets may last anywhere from a few days to two weeks. While the dispute period may vary between various Optimistic Rollup implementations, it is still necessary, which means that users must always wait a few days before withdrawing funds on the base chain.

This dispute period is necessary to give validators enough time to dispute suspicious transactions through so-called fraud proofs. A fraud proof is a statement that a state transition (i.e., a transaction) is invalid, and therefore the entire batch should be reverted. Validators can prove invalid transactions because they have full data on all transactions on Layer 2, including a copy of the current Rollup state. They also compute post-state roots in the Rollup.

If there are no fraud proof claims from any validator, the batch of transactions will automatically settle on Layer 1 at the end of the dispute period. Once this is over, the original assets on Layer 1 will be unlocked and the identical copies on Layer 2 will be destroyed.

As for ZK Rollup, asset withdrawals to the underlying chain can be instant because the transactions have been verified. As mentioned earlier, ZK Rollup proves that transactions are valid through zero-knowledge proofs, which are cryptographic mechanisms that allow one party (the prover) to prove something to another party (the verifier) ​​without sharing any sensitive information about the subject in question. Zero-knowledge proofs can come in two forms, STARKS (Succinct, Transparent Arguments of Knowledge) and SNARKS (Succinct, Non-Interactive Arguments of Knowledge), each with their own advantages and disadvantages.

Optimistic and ZK Rollup: Structure and Mechanism

ZK Rollup and Optimistic Rollup have two roots, a state-pre-root and a state-post-root.

The state before root shows the Rollup state before the transaction is executed. On the other hand, the state after root shows the Rollup state after the transaction is executed.

Both Rollups also use multiple smart contracts. ZK Rollup uses two smart contracts, a master contract and a validator contract. The master contract stores Rollup blocks and tracks asset deposits and withdrawals. Meanwhile, the validator contract verifies zero-knowledge proofs published to Layer 1.

Optimistic Rollup, on the other hand, utilizes a bridge smart contract deployed on the Rollup and the underlying Layer 1. For every asset locked in the Layer 1 bridge smart contract, the same asset is minted on the Rollup.

Both ZK Rollup and Optimistic Rollup have an operator called a sequencer, whose job is to facilitate transactions, produce Rollup blocks, add transactions to contracts, and submit data back to the underlying Layer 1. The effective task of the sequencer is to connect the Layer 1 and Layer 2 networks. When users migrate assets from the base chain to the Rollup chain and vice versa, the sequencer relays transactions.

When the sequencer submits the transaction data, it will also automatically propose a new state root to the Rollup smart contract. Rollup must ensure that the current state root is equivalent to the state root. After verification, the state root proposed by the sequencer becomes the new state root.

pros and cons

The benefit of Optimistic Rollups is that they have lower complexity and transaction costs, at the expense of longer dispute periods or withdrawal times. ZK Rollups, on the other hand, are much more complex at the base level but offer considerable advantages in speed, security, and privacy.

What type of Rollup does Nervos use?

Nervos used a custom Optimistic Rollup solution in its first Layer 2, Godwoken. Godwoken’s dispute period is about seven days, which is shorter than most Rollup solutions on Ethereum, but still long enough to ensure adequate security.

Godwoken is a high-throughput, GameFi-focused Layer 2 network built on top of Nervos’ highly secure proof-of-work Layer 1 CKB. It is fully compatible with the EVM, meaning developers can port their decentralized applications from Ethereum with relative ease, with only minor modifications required.

Summarize

ZK Rollup vs. Optimistic Rollup remains a hotly debated topic, with each approach having its own pros and cons. Currently, Optimistic Rollup is favored over ZK Rollup due to its greater cost-effectiveness. However, with both types of Rollup gaining momentum quickly, a clear winner between them has yet to emerge. It remains plausible that ZK Rollup may eventually gain greater popularity and utility, making them a popular choice in the future.