Layer 2 is a collective term for solutions designed to help scale your application by handling transactions off the Ethereum Mainnet (layer 1) while taking advantage of the robust decentralized security model of Mainnet. Transaction speed suffers when the network is busy, making the user experience poor for certain types of dapps. And as the network gets busier, gas prices increase as transaction senders aim to outbid each other. This can make using Ethereum very expensive.
You should have a good understanding of all the foundational topics and a high-level understanding of Ethereum scaling. Implementing scaling solutions such as rollups is an advanced topic as the technology is less battle-tested and continues to be researched and developed.
See more: Ethereum zk rollup
Why is layer 2 needed?
- Some use-cases, like blockchain games, make no sense with current transaction times.
- It can be unnecessarily expensive to use blockchain applications.
- Any updates to scalability should not be at the expense of decentralization or security – layer 2 builds on top of Ethereum.
Rollups are solutions that perform transaction execution outside the main Ethereum chain (layer 1) but post transaction data on layer 1. As transaction data is on layer 1, rollups are secured by layer 1. Inheriting the security properties of layer 1 while performing execution outside of layer 1 is a defining characteristic of rollups.
Three simplified properties of rollups are:
- transaction execution outside layer 1
- data or proof-of-transactions is on layer 1
- a rollup smart contract in layer 1 that can enforce correct transaction execution on layer 2 by using the transaction data on layer 1
Rollups require “operators” to stake a bond in the rollup contract. This incentivises operators to verify and execute transactions correctly.
- reducing fees for users
- open participation
- fast transaction throughput
There are two types of rollups with different security models:
- Optimistic rollups: assumes transactions are valid by default and only runs computation, via a fraud proof, in the event of a challenge
- Zero-knowledge rollups: runs computation off-chain and submits a validity proof to the chain
Optimistic rollups sit in parallel to the main Ethereum chain on layer 2. They can offer improvements in scalability because they don’t do any computation by default. Instead, after a transaction, they propose the new state to Mainnet or “notarise” the transaction.
With Optimistic rollups, transactions are written to the main Ethereum chain as calldata, optimising them further by reducing the gas cost.
As computation is the slow, expensive part of using Ethereum, Optimistic rollups can offer up to 10-100x improvements in scalability dependent on the transaction. This number will increase even more with the introduction of shard chains as more data will be available if a transaction is disputed.
Optimistic rollups don’t compute the transaction, so there needs to be a mechanism to ensure transactions are legitimate and not fraudulent. This is where fraud proofs come in. If someone notices a fraudulent transaction, the rollup will execute a fraud-proof and run the transaction’s computation, using the available state data. This means you may have longer wait times for transaction confirmation than a ZK-rollup because the transaction could get challenged.
The gas you need to run the computation of the fraud proof is even reimbursed. Ben Jones from Optimism describes the bonding system in place:
“anyone who might be able to take an action that you would have to prove fraudulent to secure your funds requires that you post a bond. You basically take some ETH and lock it up and you say “Hey, I promise to tell the truth”… If I don’t tell the truth and fraud is proven, this money will be slashed. Not only does some of this money get slashed but some of it will pay for the gas that people spent doing the fraud proof”
So you can see the incentives: participants get penalized for conducting fraud and reimbursed for proving fraud.
Pros and cons
A visual explanation of optimistic rollups
Watch Finematics explain optimistic rollups:
Use Optimistic rollups
Multiple implementations of Optimistic rollups exist that you can integrate into your dapps:
- Fuel Network
Zero-knowledge rollups (ZK-rollups) bundle (or “roll-up”) hundreds of transfers off-chain and generate a cryptographic proof, known as a SNARK (succinct non-interactive argument of knowledge). This is known as a validity proof and is posted on layer 1.
The ZK-rollup smart contract maintains the state of all transfers on layer 2, and this state can only be updated with a validity proof. This means that ZK-rollups only need the validity proof instead of all transaction data. With a ZK-rollup, validating a block is quicker and cheaper because less data is included.
Maybe you are interested: How to Earn Interest on Ethereum – The Economic Times
With a ZK-rollup, there are no delays when moving funds from layer 2 to layer 1 because a validity proof accepted by the ZK-rollup contract has already verified the funds.
Being on layer 2, ZK-rollups can be optimised to reduce transaction size further. For instance, an account is represented by an index rather than an address, which reduces a transaction from 32 bytes to just 4 bytes. Transactions are also written to Ethereum as calldata, reducing gas.
Pros and cons
A visual explanation of ZK-rollups
Watch Finematics explain ZK-rollups:
Multiple implementations of ZK-rollups exist that you can integrate into your dapps:
- Matter Labs zkSync
- Aztec 2.0
- Polygon Hermez
Hybrid solutions exist that combine the best parts of multiple layer 2 technologies, and may offer configurable trade-offs.
Use hybrid solutions
- Offchain Labs Arbitrum SCSC
- An Incomplete Guide to Rollups
- Optimistic Rollups vs ZK Rollups
- Zero-Knowledge Blockchain Scalability
- Why rollups + data shards are the only sustainable solution for high scalability
- Ethereum-powered ZK-Rollups: World Beaters
- What Are Zero-Knowledge Rollups?
- EthHub on zk-rollups
- Everything you need to know about Optimistic Rollup
- EthHub on optimistic rollups
- The Essential Guide to Arbitrum
- How does Optimism’s Rollup really work?
- OVM Deep Dive
- Adding Hybrid PoS-Rollup Sidechain to Celer’s Coherent Layer-2 Platform on Ethereum
- Volitions: best of all worlds
- Rollups – The Ultimate Ethereum Scaling Strategy?
Know of a community resource that helped you? Edit this page and add it!
Maybe you are interested: How To Buy Ethereum (ETH) In Canada 2022 | Wealthsimple