DEV Community

Akim (mousticke.eth) @Colossos
Akim (mousticke.eth) @Colossos

Posted on • Updated on

Understand the ZK Rollups

Abstract

Imagine you have a Christmas gift to send to your family for the next Christmas and you have 4 gifts to send. One option is to send 4 different parcels to your family location. But it will be expensive and/or maybe some delays between each parcels. What if you send all the gifts at once in a single parcel containing each parcel? It will be less expensive and you save time and effort.
If you understand this small abstract, you'll understand what ZK rollups are and how they scale Ethereum network. Let's dive into them.

What is a Rollup.

If you refer to the Ethereum website, the definition is a bit hard to understand. I'll try to make it easier for you to explain as I dedicate this article to everybody with or without deep knowledge about the blockchain.
On the Ethereum blockchain, there are two things that can be posted on the blockchain. Transactions or Data.
A transaction is just the action to send ETH between two addresses.
A data can be stored on the Ethereum blockchain which makes it different from Bitcoin. A data can be anything. A simple text or a compiled code which are smart-contracts.
A rollup is a solution that performs a bunch or a bundle of transactions execution outside the mainnet and post the final transactions data to the mainnet.

Blocks in Ethereum

But first, you need to know that the block size isn't dynamic and unlimited in space. A block has a target of 15 million gas but depending on the networks demand, the block can increase to 30 million of gas. The total amount of gas expended by all transactions in the block must be less than the block gas limit. This is important because it ensures that blocks can’t be arbitrarily large. If blocks could be arbitrarily large, then less performant full nodes would gradually stop being able to keep up with the network due to space and speed requirements. A block is proposed every 12 seconds.
Based on this statement, let's say that there are 100,000 transactions and every block can process 100 transactions. The priority of the validated blocks go for people who add a tip in the gas fee for the validator. Others transactions have to wait. Depending on the demand of the networks, a transaction can be delayed and slow. A fee can be more and more expensive so each transactions have to be more and more important to be included in priority.
As mentioned earlier, the Ethereum blockchain can handle data. We can perform some transactions in this data.
So what if one data can perform 10 transactions and we can process only 100 transactions or data in one block to the blockchain? We have scaled the Ethereum blockchain to 1000 transactions per block. This is what rollups are about.

A single transaction

A simple Ethereum transaction (to send ETH) takes around 110 bytes. An ETH transfer on a rollup, however, takes only 12 bytes

Parameter Ethereum Rollup
Nonce 3 0
Gasprice 8 0.5
Gas 3 0.5
To 21 4
Value 9 3
Signature 2 + 33 +33 (68) 0.5
From 0 4
Total 112 12

How does a rollup work?

There is a smart contract on-chain which maintains the Merkle root of the state of the rollup. Anyone can publish a batch of transactions in a highly compressed form together with the previous state root and the new state root. The contract checks that the previous state root in the batch matches its current state root. If it does, it switches the state root to the new state root.
How to do know that the post-state roots in the batches are correct? The answer to this question is the main key of the solution proposed by the two families of rollup.

ZKsnarks Rollup

If you break down the acronym Zero Knowledge Succinct Non-Interactive Argument of Knowledge you have:
Zero Knowledge: No need to see the transactions data
Succinct: Short
Non-Interactive: No need to deal with the people who verify the work
Argument of Knowledge: Proof they provided that these transactions are good.
ZKSnark or Zero Knowledge Succinct Non-Interactive Argument of Knowledge runs a computation off chain and submit a validity proof on chain.
A validity proof is the result of a computation and mathematically verified to be not fraudulent. So this rollup needs more computation and time to be submitted to the network. (If you want to know more about Zero Knowledge, you can find the paper on the internet. It a concept invented in 1985 by Silvio Micali).
Then, once this validity proof is created, it will be submitted to the blockchain and approved to the Layer 1. This computation off chain means that the Ethereum blockchain has offloaded some work to the ZKSnark checker which is what a Layer 2 solution does. Unlikely to the Optimistic rollup, once the validity proof is submitted, the funds are directly available to the user. However, it's more difficult to create an EVM compatible ZK rollup. You can check ZK-Sync for this part.

Optimistic Rollup

This rollup is used by Arbitrum and Optimism because it's easier to implement. These L2 use a single centralised node called a Sequencer that submits the transactions.
It assumes that the transactions are good and valid by default. Instead of submitting a validity proof, the optimistic rollups submit a fraud proof but only if the transactions are challenged by the networks.
So this rollup assumes that everybody tell the truth. They dont do some computation like ZKSnarks do. However, what they do post, is fact check-able by the network. Because transactions involves money, there will be always some people checking the transactions. So if the network attests that a transaction is fraudulent, the transaction is reverted and the block validator is slashed. That's why in Optimitic rollup, you have a challenge period where the nodes can use a verifier (contract) to check the transactions. The challenge period can last for one week and during this time, the user cannot withdraw the funds. The other drawback of this rollup is the sequencer. It's centralised and prone to censorship.

Recap

In short, here a table comparing the two solutions:

Rollup property/Rollup solution Optimistic ZK Rollup
Fixed gas cost per batch 40,000 (a lightweight transaction that mainly just changes the value of the state root) ~500,000 (verification of a ZK-SNARK is quite computationally intensive)
Withdrawal period 1 week (withdrawals need to be delayed to give time for someone to publish a fraud proof and cancel the withdrawal if it is fraudulent) Very fast (just wait for the next batch)
Complexity of technology Low High (ZKSnarks are mathematically complex technology)

Top comments (0)