What are Zero-Knowledge(ZK) Rollups & How they work?
Tags: blockchain, web3, computerscience, programming
Published: 2022-10-30 14:16:13

## Why is Ethereum Mainnet a Problem?

It is no secret that the cryptocurrency industry has experienced rapid expansion in recent years. Since the ICO era, DeFi protocols, NFT collections, ZK-rollup projects, and everything in between have all debuted.

Ethereum is still pricey for many people to use, even after the most recent crypto meltdown.

The widespread use of cryptocurrencies has led to significant price increases and a faster rate of innovation. However, increased transaction volumes on networks like Ethereum have revealed a number of problems. Scalability is a common issue among these problems, and it directly affects how well the blockchain performs. In the most well-known, secure, and decentralized smart contract network, transactions are now more expensive and take longer to complete.

As a result, Layer-2 blockchains and rollups were chosen to overcome Ethereum's scalability issues. One of the two popular Layer-2 scalability techniques is zero-knowledge rollups, the other being optimistic rollups. Built on Ethereum, zero-knowledge rollups like as zkSync and Loopring revolutionized the crypto industry by decreasing the network's entrance barrier and allowing decentralized apps to scale quicker and with greater anonymity.

---

## What are Ethereum L2s

Ethereum Layer 2s are blockchains that take use of the execution layer's security while being faster and less expensive than transactions on the main Ethereum chain. The main goals of Layer 2s are to address the issues of high transaction costs and slow transaction speeds on Ethereum that arise when the network is congested (when many users are attempting to use the Ethereum network at the same time).

<img src="https://d33wubrfki0l68.cloudfront.net/23d9d8c14aa8f8187d767acce1dac196dccfcdff/16d65/static/aea37731b69ef20e24d7de8f873b940d/95e90/hero.png" width="400px"/>


Most Layer 2 solutions execute transactions "off-chain," that is, not on the Ethereum blockchain, and bundle those transactions into a simpler, and hence cheaper, transaction that is published on the Ethereum network.

However, the processes used by Layer 2 scaling solutions to safely process, batch, and publish off-chain transactions into Ethereum are dependent on the scaling technology and rollups they employ.

---

## What are rollups?

Rollups are bundles of transactions that are rolled up (thus the name). The final, rolled-up transaction is reported as a single transaction to the Ethereum network.

Rollups reduce expenses by dividing the cost of an Ethereum transaction plus the minor cost of rolling up batches of transactions among users. They also accelerate things: the rollup is really fast, and the Ethereum blockchain only needs to process one transaction rather than several. This is useful because Ethereum's unaided transaction rate is roughly 15 transactions per second.

---

## Different Ethereum Layer 2s

State channels, optimistic rollups, and zero-knowledge rollups are three different kinds of Ethereum Layer 2s that assist in resolving the scalability issue with Ethereum.

### State Channels

State channels are an Ethereum scalability solution that enables users to do an infinite number of off-chain transactions while only sending the first and last transaction to the Ethereum network.

Here’s how it works:

1. The initial transaction "locks" the state and opens the state channel.
2. Transactions are carried out by users off-chain.
3. After off-chain transactions are finished, the state that is still in effect is recorded in a subsequent transaction that "closes" the state channel.

Examples of Ethereum L2s that leverage state channels include: 

- **Connext** - a network for cross-chain applications and communication that is quick and trustless.
- **The Kchannels** - provides a trust-minimized payment channel for Ethereum 
- **Perun** - gives users access to an off-chain infrastructure that facilitates real-time payments 
- **Radien** - provides a quick, affordable method of transferring ERC20 tokens

---

### Optimistic Rollups

Optimistic rollups include processing a large number of transactions, carrying out computation off-chain, and "rolling" them up into a smaller transaction that is published to Ethereum's execution layer.

Transactions are presumed to be authentic until proven otherwise, hence the moniker optimistic rollups.

Before optimistic rollup transactions are confirmed on Ethereum's main chain, a window of opportunity exists for disputing potentially fraudulent transactions by presenting a fraud evidence.

All pending transactions are confirmed onto Ethereum once the fraud proof dispute time has passed.

Compared to other techniques like Zero-Knowledge rollups, optimistic rollup Layer 2s have a tendency to prolong transaction confirmation times because they are designed to apply fraud proofs.


Several Ethereum L2s use optimistic rollups, for instance:

- The largest positive rollup by TVL ($3.2B) and market share (54.7%), **Arbitrum**
* - **Metis** -  TVL's ($457M) third-largest optimistic rollup and its 7.84% market share.
*  **Positivity** - TVL's second-largest optimistic rollup, with a $465 million market share.
* **Boba Network** - Fourth-largest upbeat rollup by TVL ($187M) and market share (3.22%)*

---

### Zero-Knowledge Rollups

Similar to optimistic rollups, ZK-rollups combine numerous off-chain Layer 2 transactions and send them to Ethereum as a single transaction.

ZK-rollups use validity proofs to instantly identify whether or not transactions are valid instead of assuming they are real until proven otherwise.

Due to the technology's complexity and ability to execute arbitrary code, producing optimistic rollups is easier than developing ZK-rollups that are EVM-compatible.

When deciding whether to build on a ZK-rollup Layer 2 blockchain or any EVM-compatible blockchain, it is crucial to bear this in mind.

The following are some instances of Ethereum L2s that use ZK-rollups:

-   **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

Let's take a closer look at zk-rollups.

---

## What are ZK-rollups?

A ZK-rollup is a Layer-2 blockchain system that off-chain handles transactions, computes, and stores data while holding assets in an on-chain smart contract. Traditional Layer-1 blockchain technologies, such as Ethereum, naturally validate blocks and transactions on-chain. ZK-rollups take the identical off-chain actions and convey a summary of the validated activity to the blockchain. The rollup thereby refreshes the status of the Layer-1 blockchain while storing only a portion of the total data.

<img src="https://dexterlab.com/content/images/2022/03/ZK-Rollups.png" />


Zero-knowledge rollups, like rolled paper, combine multiple transactions into a single transaction to be executed off-chain. The ZK-rollup then presents a validity proof rather than broadcasting the specific information of all transactions in the batch to the blockchain. This proof is a receipt that proves that the transactions are genuine and may thus be accounted for in both the rollup and the main chain.

---

## What are Validity Proofs

_A validity proof, also known as a zero knowledge (ZK) proof, is a way of transaction verification that occurs between a prover, who creates a proof for certain information, and a verifier, who verifies the proof with no information shared between the two._

A witness is information provided between a prover and a verifier that is often the solution to a complex mathematical equation. In essence, the prover must demonstrate that they accurately know the witness, and the verifier must be able to determine whether the prover has knowledge of the witness.

Validity proofs are supposed to be difficult to decipher and rely on a cryptographic method called polynomial commitments. Information from each stage of a verification computation is encoded into polynomials in polynomial commitments, and a factored polynomial expression can stand in for a large number of equations between numbers.

You are indirectly confirming the numerical calculations by verifying the polynomial equations, but the technique for hashing these polynomials is difficult. For polynomial commitments, the three major polynomial hashing algorithms are:

- Bulletproofs 
- KZG (Kate) Polynomial Commitments
- FRIs 

FRI is an abbreviation for "Fast Reed-Solomon Interactive Oracle Proofs of Proximity".

---

## How does a ZK-rollup work?

### Structure of ZK-Rollups

<img src="https://res.cloudinary.com/polygontech/image/upload/f_auto,q_auto,dpr_2,h_380/triangle_d81f4fe0e4" />


To understand how zero-knowledge rollups operate, at least for the most prominent ZK-rollup projects, we must look at how they are organized, with Ethereum serving as the basic settlement layer.

The usual ZK-rollup is built on Ethereum and is supported by two on-chain smart contracts: the "main" contract and a verifier contract. These contracts serve as anchors and are in charge of a variety of functions. The main contract saves rollup blocks, checks the state of the blockchain, and tracks fund deposits and withdrawals. The verifier contract, on the other hand, validates zero-knowledge proofs sent to Ethereum, the base layer.

The second layer of a typical ZK-rollup is occupied by an off-chain virtual machine. As previously stated, ZK-rollups complete transactions in an off-chain environment that is independent of Ethereum. The off-chain environment is referred to as an off-chain virtual machine, and it is the major factor that promotes scalability and throughput. ZK-rollups use this off-chain virtual machine to process batches of transactions and post a validity proof on-chain to confirm their activity.

ZK-rollups function as hybrids, operating off-chain yet relying on Ethereum for several functions. For starters, they get their security from Ethereum, because the network verifies the validity of every update to the ZK-state rollup's and validates that the data that explains these updates is available. They also post compressed transaction data to Ethereum, while the network serves as a settlement layer for the ZK-rollup and aids in censorship resistance.

Here is an Merkel Tree Illustration of zk-Sync's Validation

<img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iwn5gum53t7x3ca34lr2.png" />

A typical ZK-rollup also has a Layer-2 operator contract, and a supernode, in charge of transaction execution, batching, and Layer-1 submissions. Some of them use a single operator, while others rotate their role among a set of proof-of-stake validators.

---

### Internal mechanisms of ZK-rollups  

<img src="https://pbs.twimg.com/media/FWbTkHpXgAUPVrI?format=jpg&name=large" />

ZK-rollups follow a three-pronged setup that involves transactions, state commitments, and zero-knowledge validity proofs:  

- Users of ZK-rollup approve transactions and send them to the Layer-2 operator. This operator is in charge of Layer-2 block production as well as all activities ranging from transaction validation to publishing compressed data on-chain.
- The accounts and balances of the ZK-rollup are represented by two Merkle trees. The rollup's accounts and balances change status after each batch of transactions. Merkle roots are used to represent this new state, which is subsequently published to the Layer-1 blockchain.
- When an operator submits a new state root to Ethereum, the blockchain's state can only change if the operator can demonstrate that the root represents valid revisions to the rollup's state. The operator validates the batched transactions using a zero-knowledge validity proof. ZK-SNARKs or ZK-STARKs are used in the majority of ZK-rollups and ZK-rollup projects. Furthermore, one validity proof can be used to verify other validity proofs, reducing storage space.

---

## Benefits & drawbacks of ZK-rollup projects

ZK-rollups have improved Layer-1 blockchain networks like Ethereum's scalability and transaction costs, but there are still some areas where they fall short. The following are some advantages and drawbacks of zero-knowledge rollups:

### Benefits

- To assure their security, ZK-rollups use trustless cryptographic configurations. Optimistic rollups rely on trustworthy validators and sequencers, therefore trustless crypto methods are a safer bet.
- The use of validity proofs to validate off-chain transactions and stop users from altering Ethereum's state inadvertently.
ZK-rollups ensure security, decentralization, and censorship resistance by updating the state of their host Layer-1 blockchains by storing compressed transaction data on-chain.
- Because ZK-rollups only require the blockchain to check validity proofs supplied by the sequencers, transaction finality timeframes are shorter.
- There are hardly any withdrawal delays, and consumers can utilize their funds more effectively.
- ZK-rollups lower the cost of publishing data on-chain as a result of efficient data compression techniques, which lowers user fees.
- In order to safeguard their assets, some sidechains and scaling solutions typically demand that users validate the blockchain. Since ZK-rollups don't rely on liveness assumptions, they don't demand such efforts.

---

### Drawbacks  

- Zero-knowledge-proof systems are a crucial component of the frameworks used by ZK-rollups. Certain ZK-proof systems typically demand [trusted setups](https://twitter.com/vitalikbuterin/status/1503409375725109250). Mishandling a trusted setup could seriously reduce the rollup's security.
- Some ZK-rollups use a supernode, a single operator, as their sequencer. This centralized structure occasionally results in censorship and can directly affect the order of transactions.
Zero-knowledge validity proofs are the result of computer labour, which must be carried out on specialist hardware. The chain is at risk of centralization because of the high entrance barrier that results from limiting the position of sequencers to a select few.
- The rollup is vulnerable to attacks from malevolent operators and censorship because expensive hardware requirements limit the number of participants who can profitably engage in the chain.
- Rollup customers may pay higher fees as a result of the high costs associated with computation and validity proof verification.
- Prior to recently, smart contracts were not enabled due to the expensive expense of developing zero-knowledge rollups that are compatible with the Ethereum Virtual Machine. Additionally, the complexity of zero-knowledge technology makes it more difficult to develop zkEVM solutions.


---

Congratulations ㊗️🥂 on making it this far! Be sure to read some other fascinating articles about blockchain and web3 technology.

{% embed https://dev.to/envoy_/awesome-web3-519 %}
{% embed https://dev.to/envoy_/blockchain-app-developer-roadmap-31p5 %}
{% embed https://dev.to/envoy_/what-are-soulbound-tokens-14lj %}

---

Additionally, make sure to follow to ensure that you do not miss any web3-related trends.

{% embed https://dev.to/envoy_ %}

---
---