Layer 2 Rollups
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 which can make 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.
- 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, this allows rollups to be 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:
- Zero knowledge rollups: runs computation off-chain and submits a validity proof to the chain
- 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, also known as ZK-rollups, bundle or "roll up" hundreds of transfers off-chain and generates 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.
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.
The sidechain where ZK-rollups happen 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.
|Faster finality time since the state is instantly verified once the proofs are sent to the main chain.||Some don't have EVM support.|
|Not vulnerable to the economic attacks that Optimistic rollups can be vulnerable to.||Validity proofs are intense to compute – not worth it for applications with little on-chain activity.|
|Secure and decentralized, since the data that is needed to recover the state is stored on the layer 1 chain.|
Multiple implementations of ZK-rollups exist that you can integrate into your dapps:
Optimistic rollups use a sidechain that sits in parallel to the main Ethereum chain. 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 the Eth2 upgrade: shard chains. This is because there will be more data available in the event that a transaction is disputed.
Optimistic rollups don't actually compute the transaction, so there needs to be a mechanism in place 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 it could be 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: particpants get penalized for conducting fraud and reimbursed for proving fraud.
|Anything you can do on Ethereum layer 1, you can do with Optimistic rollups as it's EVM and Solidity compatible.||Long wait times for on-chain transaction due to potential fraud challenges.|
|All transaction data is stored on the layer 1 chain, meaning it's secure and decentralized.|
Multiple implementations of Optimistic rollups exist that you can integrate into your dapps:
Hybrid solutions exist that combine the best parts of multiple layer 2 technologies, and may offer configurable trade-offs.
- Everything you need to know about Optimistic Rollup
- EthHub on optimistic rollups
- OVM Deep Dive
- How does Optimism's Rollup really work?
Know of a community resource that helped you? Edit this page and add it!
Help us with this page
If you're an expert on the topic and want to contribute, edit this page and sprinkle it with your wisdom.
You'll be credited and you'll be helping the Ethereum community!
Use this flexible documentation template
Questions? Ask us in the #content channel on our Discord serverEdit page