What are ZK rollups and why are they important?
Let's have a look at how cryptographical zero-knowledge proofs can help secure and scale the L2 networks on Ethereum. Are ZK rollups superior solution to Optimistic rollups?
Rollup basics
At this time, the Ethereum mainnet processing speed is limited to 20 - 40 transactions per second. While promoting safety and decentralization, scaling is not a particularly strong side of Ethereum.
One solution proposed to solve this issue by bundling (rolling up) users' transactions together and uploading them to the mainnet for verification. This method relieves the computational pressure off of the mainnet and significantly reduces gas fees for users. Just like that the L2 (layer two) scaling solutions emerged. The ones you probably already know are Arbitrum and Optimism.
With the recent increase in the popularity of Ethereum, many users were discouraged from using the mainnet due to its high gas fees and transferred over to a second layer. Entire ecosystems were built on top of the L2 and their bridge smart contracts are one of the largest ETH holders overall.
Optimistic vs zk rollups
The fundamental problem with rollup scaling solutions is maintaining security. They still rely on the Ethereum consensus mechanism, but as the changes are processed in bundles, the verification suddenly becomes much more difficult.
Optimistic
The first generation of rollups is called optimistic because they don't present any cryptographic proof upon depositing transactions on the mainnet. Transactions are assumed to be legitimate and later reviewed by the so-called Watchers.
When transferring funds from the L2, there is a time window of usually 7 days before updating the mainnet. During this time certain transactions can be challenged with fraud suspicion. The suspected transactions are later run again to verify if the fraud actually happened - this is called the fraud proof method of verification. In case of no suspicion, the bundle of transactions is deposited on the mainnet.
- While using optimistic L2s, users need to trust the network to a certain level
- The verification process is a bit slow
- It is easy for developers to work with optimistic L2s
The fraud proof method relies on revealing the fraudulent transactions before they are processed on the mainnet. This of course creates an exploitable pain point, where a malicious entity may create fake transactions and conceal them, or otherwise manipulate the outcome of verification.
Zero-knowledge
Zk rollups (zero-knowledge) present a solution for a safe verification of the bundled transactions. They work by compressing users' data without loss and providing cryptographic validity proof before updating the state of the Ethereum mainnet. Compared to optimistic rollups, the verification is much faster and safer, but more difficult to implement.
- The L2 creates a mathematical proof that ensures the transactions are valid
- Operating on these chains is faster and safer compared to optimistic L2s
- More difficult for developers to build on
A typical transaction process looks like this: Users sign transactions on the L2 and submit them to the L2 operators. The job of these operators is to bundle up transactions and transfer them to the mainnet (L1) for verification. Operators present validity proof in form of a single hash, which is decoded by the verifier contract. Once everything checks out, the change of state is recorded on the mainnet.
Zk architecture
On-chain components
Zk rollups have a similar architecture to that of optimistic rollups. They are composed of multiple smart contracts on the Ethereum mainnet, which maintain the overall balance of the L2. We have the main smart contract, which stores blocks from the L2 and tracks deposits. Then we have a kind of secondary contract, which processes the zero-knowledge proofs provided by L2 operators. These two types of contracts work together to create what is known as Layer 1 (L1) of the rollup
- Main smart contract - placed on the Ethereum mainnet. Stores the state of L2
- Verifier smart contract - also on the Ethereum mainnet. Verifies if the validity proofs are correct
Off-chain components
The off-chain environment is where the actual ecosystem of the rollup is built. We call this environment Layer 2 (L2) of the rollup. Transactions executed here are processed but verified only after the state of the main contract is updated on the Ethereum mainnet. The contract state is updated every time L2 Operators send out a bundle of transactions to the L1. Zero-knowledge validity proofs guarantee that the state of the off-chain environment always remains correct according to the L1.
- The entire Layer 2 is placed off-chain
- Users sign transactions the same as they would on the Ethereum mainnet (L1)
- Transactions on the L2 are processed by the so-called Operators/Sequencers
Users can safely operate on the L2s, without needing to write down every single transaction on the mainnet. This way gas fees are reduced, with TPS (transactions per second) increasing rapidly. For comparison, Ethereum L1 has around 30 TPS, while some rollups can achieve up to several thousand TPS.
Zero-knowledge proofs
A cryptography tool called zero-knowledge proof is used for verifying the transactions executed in the L2 (off-chain). The exchange of information occurs between the prover and the verifier. The prover (usually an L2 operator) provides proof of holding secret information (transaction information), without sharing none of it (hence the name zero-knowledge).
Let's say I know a secret. Thanks to Zero-knowledge proofs I can prove to anyone that I know the secret, without me having to reveal the secret.
There are two types of proofs: ZK-SNARKS and ZK-STARKS. Both of these have distinct qualities and are used by various crypto projects. However, the consensus is that ZK-STARKS enable more scalability and are therefore preferred by the Ethereum foundation.
Pros and cons
As with every new technology, Zk rollups have ups and also downs. They are prominent scaling technology for Ethereum, maintaining high security, privacy and improving user experience by higher speed and reduced cost. With careful consideration, Zk rollups can be considered superior scaling technology to optimistic rollups. That is not to say the optimistic rollups would disappear entirely from the market.
The technology is still in its early stages and at this time it is very difficult to implement. Due to the zero-knowledge cryptography used, the developers are limited by technical challenges. Many developers might even feel discouraged to build their projects on top of zero-knowledge technology, just because of the difficult cryptography implementations. Often the use of expensive hardware or software is required.
FAQs
Why should I use a rollup in the first place?
Ethereum mainnet at this time has scaling limitations, which means higher gas prices for users and slower transactions. Using a can make this user experience much smoother.
What are the benefits of using a Zk rollup?
Faster and cheaper transactions. More privacy, trustless transactions, and exponential scalability.
What are some Zk rollups?
The most prominent projects are StarkWare and zkSync, none of which has a token available for sale at this time. So be mindful of scammers.
What is the difference between a Zk rollup and an Optimistic rollup?
Optimistic rollups do not provide any cryptographic proof when depositing transactions from the L2 to the L1. Zk rollups provide Zero-knowledge proofs.
Is it safe to use an Optimistic rollup?
Depends on the provider. Most L2 Optimistic chains are very safe but are still not trustless.
Is Polygon a Zk rollup?
Polygon by itself is a different scaling solution - a sidechain, not a rollup. However, Polygon is developing its own Zk rollup called Hermez.