What is a Layer 2 Blockchain?
The scalability trilemma is a persistent problem that has plagued blockchain developers ever since the Bitcoin blockchain was launched in 2009.
Amongst the many solutions that have been tested over the years, bigger block sizes, alternative consensus mechanisms, more sophisticated mining hardware, etc, layer two networks have stood out as the most elegant solution for enabling blockchains to scale without compromising on decentralization.
Key Takeaways - Layer 2
- A Layer 2 is a scaling solution that sits on top of a layer 1 blockchain like Bitcoin or Ethereum. Layer 2’s (or L2s) increase the speed and reduce the cost of transacting on a blockchain.
- Layer 2’s exist to address the scalability challenges of L1 networks, particularly the issue of high gas fees during times of network congestion.
- Layer 2 scaling solutions can take different forms, including payment channels, state channels, side chains and rollups.
- Some potential drawbacks of L2 networks is that the withdrawal times from an L2 to the Ethereum mainnet can sometimes take several hours to 7 days to complete.
- Also, Layer 2s compromise on decentralization and security in order to achieve speed, which can make it more risky to store funds on them.
What is Layer 2 Scaling?
A Layer 2 is a scaling solution that sits on top of a layer 1 blockchain like Bitcoin or Ethereum. Layer 2’s (or L2s) increase the speed and reduce the cost of transacting on a blockchain by setting up separate networks or channels where transactions can be executed between a limited set of nodes or participants, thereby reducing the time it takes to achieve consensus.
Transactions from layer 2 networks are batched together every so often and transmitted back to their base layer 1 network, where they are validated by the layer 1 node as a single transaction.
This modular design enables the layer 1 network to prioritize decentralization and security, while the layer 2 can focus on speed and scalability.
Layer 2’s are also seen as off-chain scaling solutions because the transaction execution process happens off of the layer 1 blockchain.
This means that the layer 2 network does not have to be a separate blockchain, it can simply be a payments channel for transferring funds between 2 or more participants using smart contacts, or even a centralized network where participants agree to trust each other instead of relying on code to enforce trust.
The key objective of layer 2’s is speed and scalability, which means it can explore a variety of designs that are not limited to the need for decentralization, as long as the data is communicated to the Ethereum mainnet at some point in order to reinforce its security.
Why is Layer 2 Needed?
Layer 1 Scalability Challenges
While layer 1s like Ethereum offer a highly decentralized infrastructure for developing secure and censorship resistant applications, the network has been marred by high gas fees during times of network congestion, which is a direct result of its inability to scale while relying solely on an L1.
High gas fees are a costly deterrent for users trying to perform transactions on dapps. They also undermine the value proposition of blockchains as a tool for making cheaper and faster payments.
Users who leave centralized payment services like Paypal because of their 3% fees are no better off if they have to spend $200+ to make a single transaction on Ethereum.
Layer 2 solutions like Polygon, Arbitrum, Loopring and Optimism currently exist on Ethereum to mitigate some of these scalability challenges.
They allow users to transfer their ETH to these networks in order to transact on many of the same Dapps available on the Ethereum mainnet, but for much lower gas fees.
What are the Differences Between Layer 2 and Layer 0?
A layer 0 is a type of protocol that enables developers to launch multiple layer 1 blockchains that are connected to the L0 mainchain, but operate independently.
Each layer 1 blockchain on a layer 0 can potentially operate its own set of L2 networks in order to scale its underlying infrastructure.
Layer 0 protocols are designed to give developers greater flexibility in how they design dapps by allowing them to also control the underlying infrastructure of their dapps, via their own blockchain.
Layer 0 networks are also optimized for cross-chain interoperability, as it becomes easier for the various L1s connected to a single mainchain to speak with one another.
By contrast, layer 2 networks exist primarily to scale a single layer 1 network. Increased protocol flexibility and cross-chain interoperability are not the core focus of an L2.
Types of Layer 2 Scaling Solutions
A layer 2 scaling solution can be designed as a payment or state channel for processing transactions between 2 participants using smart contracts, or as an entirely separate network (or sidechain) with its own set of validator nodes.
A payment channel is a two way channel that runs between 2 participants and exists entirely off-chain. Two users can form a payment channel by each locking a certain amount of tokens in a smart contract on-chain.
We can think of this like an escrow account.
Locking the funds in a smart contract initiates the channel to open, allowing both parties to send tokens to each other as long as the total amount spent by either participant remains under the amount that is locked in their smart contract.
Each time tokens are transferred from one person to another, the current state of each person's account is also shared. We can think about this like the transferring of IOU’s between 2 banks that each hold a certain amount of capital in their accounts that has been verified by both banks.
Within the payment channel, the IOUs will be accepted as money because both parties know that they have enough assets locked away for their IOUs to be redeemed in full when necessary.
To close out the channel, a user can submit the latest state update (i.e the final balance of both users accounts) to the L1, which validates this entry as a single transaction on the blockchain.
Payments made with an L2 channel are much faster because they don’t require broad network consensus to verify.
They are also much cheaper because users only need to pay a fee to the L1 when locking their funds in a smart contract to open the channel, and when submitting the final balances to the L1 in order to close the channel.
Payment channels can also be set up using a multisig-wallet.
With the multisig approach, each user holds a portion of the private keys to a wallet that stores their locked funds and mediates transactions within the payment channel. This ensures that both parties must provide a digital signature to authorize funds to be spent from that wallet.
Payment channels can be set up for one-off transactions or kept open for extended periods of time to allow participants to transact with each other off-chain, and periodically post the current state of the channel to the L1 when a user wants to withdraw some of their funds.
Lightning Network is the most popular example of an L2 payment channel for the Bitcoin blockchain.
State channels are a more generalized form of payment channels. They enable participants to conduct more complex operations than sending simple payments back and forth.
An example of an operation that could be conducted in a state channel is a game of tic-tac-toe between 2 users, where the ‘game logic’ contains the rules of the game and the ‘state logic’ records the current state of the game while also determining where the funds locked in the smart contract should go based on the final outcome.
Like a payments channel, fees are only incurred to open and close the channel, and any transactions that occur between users within the channel are essentially instantaneous and free.
This state channel mechanism makes it possible for play-to-earn games and other dapps that are not strictly financial to be launched on an L2.
Unlike payment or state channels, Sidechains are independent blockchains with their own set of validator nodes. Sidechains will normally have fewer nodes than the L1 mainchain, which allows them to achieve consensus faster.
A developer might adopt a sidechain over a payment or state channel if they need even more flexibility and control over their underlying infrastructure.
This could be for the purpose of launching a token or dapp while still taking advantage of the low cost and faster speeds enabled by not deploying smart contracts directly on the L1.
Sidechains operate using their own consensus mechanism, which means developers can optimize their network for scalability, security or decentralization, and can even choose to make their networks private and permissioned or public and permissionless.
While side chains are not required to submit state data to the mainchain, many still choose to do so in order to leverage the larger, more decentralized chain's security.
The two main methods of transferring value between L2s and the Ethereum mainnet are Optimistic Rollups and zk-Rollups.
Both offer different approaches for the Ethereum mainnet (consensus layer) to confirm the true state of operations on the execution layers (i.e., account balances and total values in each L2) without the need to validate every single transaction.
Optimistic rollups submit transaction data to the Ethereum network and leverage a dispute resolution system for detecting fraudulent transactions to ensure that all submitted transactions are valid.
The party responsible for submitting batches of transactions to the Ethereum network must post a bond of ETH that can be taken away, or slashed, if their submission is discovered to be fraudulent.
Zero-Knowledge (ZK) Rollups
A Zero-Knowledge Proof, or ZKP, is a form of cryptography that enables one party in a transaction (the prover) to prove that they have knowledge of a specific piece of information to another party (the verifier) without revealing what that information is.
This technology has many advantages not only in protecting users’ sensitive data, but also in simplifying how nodes communicate to enable blockchain networks to confirm transactions with greater efficiency and become more scalable.
Zero-Knowledge Rollups or zk-Rollups enable thousands of layer 2 transactions to be bundled into one transaction, and then be transmitted and validated by the Ethereum network without the Ethereum nodes knowing the details of each transaction.
Zk-Rollups leverage ZK-SNARKs to offer greater scalability to the Ethereum network by only requiring the Ethereum nodes to verify the proof of computation of batches of transactions rather than verifying each transaction on the Ethereum mainnet or L1.
Ethereum L2 ZK-Rollups
ZK-Rollups enable faster settlement of L2 transactions on the Ethereum L1 using only proof of computation. The Ethereum network must verify proof of computation for batches of L2 transactions.
This requires submission of some limited information about each transaction to the the Ethereum network, which reduces scalability
L2s are considered off-chain scaling solutions for Dapps. They are not independent blockchains and therefore are less secure and rely on the Ethereum network for final transaction settlement
Drawbacks to Layer 2 Scaling
Withdrawals from layer 2 networks to the Ethereum mainnet can sometimes take several hours to 7 days to complete. Optimistic rollups experience the longest withdrawal times because it takes a while for verifiers to determine if there is any fraud in the transactions submitted to the network.
Layer 2s also compromise quite heavily on decentralization and security, however this is mostly mitigated by the fact that there are security guarantees provided by the Ethereum L1.
Meaning, in the event of an exploit, users will always be able to recover their funds based on the most recent state of the L2 network that was validated on the Ethereum mainnet.
Nevertheless, sidechains like Polygon carry greater security risks because they operate as independent blockchains which have a native token for rewarding their own set of validators.
Because sidechains are independent, the security guarantees provided by the Ethereum L1 are not automatically applied to the protocol in the same way that it is for a payment or state channel.
This means that if a sidechain does not choose to periodically submit state data to the Ethereum mainnet, it could incur permanent loss of user funds if it were ever 51% attacked, as there would be no alternative network carrying validated proof of its most recent state prior to the attack.
Despite the risks of increased centralization, layer 2s offer a more cost effective and faster alternative for developers and end users to interact with the blockchain, thereby enabling layer 1s like Bitcoin and Ethereum to increase user adoption without compromising on decentralization at the base protocol layer.
As long as layer 2 networks continue to leverage the security of the underlying L1, the risks of hacks can mostly be mitigated by the knowledge that the most recent data of the L2 network's state is backed up on a more decentralized and secure blockchain.
Frequently Asked Questions - Layer 2
What are the Differences Between Layer 2 and Layer 1?
Layer 2 is a scaling solution that sits on top of a layer 1 like Bitcoin or Ethereum. L2s increase the speed and reduce the cost of transacting on an L1 by setting up separate networks or channels where transactions can be executed between a limited set of nodes or participants, thereby reducing the time it takes to achieve consensus.
L2 networks rely on the underlying L1 for security, meaning that all transactions that occur on the L2 network must eventually settle on the larger, more decentralized L1.
What are Rollups?
A rollup is a technique used to transfer value between L2 networks and the Ethereum mainnet. With rollups, transactions from layer 2 networks are periodically batched together and transmitted back to the base layer 1 network, where they are validated by the layer 1 node as a single transaction.
Optimistic and zk-Rollups are 2 variations of the rollup technique that each take a different approach to securely and accurately submitting state data from the L2 to the L1 without the need for the L1 to validate every single L2 transaction.
What are the Most Popular Layer 2 Networks?
Polygon, Arbitrum, Loopring and Optimism are among the most popular L2 networks.
These networks feature many of the most popular dapps on the Ethereum blockchain, including Uniswap, Opensea, the Sandbox and more.