Layer 2 Solutions: Taking Scalability to New Heights
In this article we will explore the concept behind Layer 2 Solutions and the problems they are solving in blockchain.
According to the CAP theorem (also known as Brewer's theorem) first proposed in 1998 by Eric Brewer before Seth Gilbert and Nancy Lynch propounded it in 2002, a distributed system cannot attain consistency, availability, and partition tolerance simultaneously. This same opinion holds sway among blockchain experts for blockchain protocols. The belief often referred to as blockchain trilemma suggests that blockchain cannot achieve three of its core principles: security, scalability, and decentralization simultaneously.
By implication, the blockchain trilemma said, a protocol can achieve decentralization and security while sacrificing scalability and vice versa. The blockchain trilemma provided an answer to why centralized networks can boast thousands of transactions per second and the blockchain networks like bitcoin and Ethereum can only afford a few tens of transactions per second. In that light, the trading system sacrifices decentralization while achieving high throughput, secure and scalable network. To scale up blockchain protocols, developers began looking to salvage the situation.
So far, to solve the trilemma belief, several approaches are taken. The proposed solutions to achieving scalability are Layer 2 and Layer 1 solutions respectively.
Layer-1 and Layer-2 Solutions
Although this article focuses on Layer 2 solutions, it will be necessary to lay a background that includes Layer 1 solutions. It will highlight several Layer 1 and Layer 2 solutions as well as references to top Layer 2 implementations you should know about.
Often referred to as on-chain solutions, Layer-1 solutions are the scalability solutions that require redesigning the underlying protocols of the base protocol. Look at the Layer-1 solution as say, redesigning Ethereum or Bitcoin protocols to increase throughput and reduce fees. For instance, Visa, MasterCard, and other payment processors process an average transaction per second of 5000 while Bitcoin and Ethereum process 4 and 15, respectively. Going by the current design of these blockchain networks, as users of the networks grow, the TPS will keep reducing and transactions keep getting unnecessarily slow, hence, the need for a redesign. The Layer-1 solution entails redesigning the underlying protocols of the networks to allow for throughput, energy efficiency, and cheaper transaction fees.
There are thus several methodologies employed to redesign the base protocols. Although some of them are still at their experimental stage, they include:
Consensus-Based Protocol Redesign
This consists of redesigning the consensus protocol of the base protocol to scale transactions and efficiency. The leading blockchain networks like Bitcoin and Ethereum have leveraged PoW consensus that allows miners to solve cryptographic puzzles to validate and verify blocks thereby making it energy-demanding and tedious. Nonetheless, PoW systems are secured but often characterized by high transaction fees and low throughput when there is network congestion. To mitigate this risk and achieve a scalable network, PoS consensus becomes a good choice. Instead of miners solving cryptographic puzzles using enormous energy, users stake coins on the blockchain.
PoS consensus is set to cut down the high cost of transaction and throughput of the PoW networks. It is yet in its experimental stage, but some protocols are already developing on it. Among the top projects are Solana, Avalanche, and Ethereum. Ethereum termed its proposed PoS version Ethereum 2.0. From a frontier phase, Ethereum will be going full serenity next year by launching a Proof-of-Stake (PoS) consensus algorithm. Unlike the high cost of transaction and low TPS of Ethereum 1.0, Ethereum 2.0 is expected to dramatically and fundamentally increase the capacity of the Ethereum network while increasing decentralization and preserving network security.
Also in an experimental stage, sharding is adapted from distributed databases as one of the Layer-1 scaling solutions. Employing a Sharding Layer-1 scaling solution means breaking the state of the base protocol into distinct datasets called "shards". Here, tasks are managed by shards, simultaneously processed in parallel and they collectively maintain the entire network.
Each node in a network represents a shard instead of maintaining a copy of the entire main chain to allow scalability. Each shard across the network provides proofs to the mainchain and interacts with one another to share addresses, balances, and general states using cross-shard communication protocols. Although in an experimental stage, awaiting its launch in 2022, Ethereum 2.0 is exploring the implementations of shards.
Instead of implementing the changes of the parent protocols of the blockchain, Layer-2 solutions took scalability to a whole new height. Layer-2 solutions are those scalability solutions that entail adding a layer to the base protocol to increase throughput. They take transactions off the main chain, hence, are called off-chain solutions.
The off-chain solution doesn't allow base protocol structural changes since the second layer is added as an extra layer. For that reason, Layer-2 scaling solutions have the potential to achieve high throughput without sacrificing network security.
Layer-2 solutions consist of smart contracts built on top of the main blockchain. Those secondary layers are for scaling payments and off-chain computation. Layer-2 solutions can be achieved in various ways. For example;
Rollups are one of the Layer-2 scaling solutions built on the Ethereum blockchain. Unlike the Layer-1 solutions, they are secondary layers that allow users to perform transactions off the main Ethereum chain (Layer-1). It is designed to post transactional data on Layer-1 thereafter, hence, inheriting the security of the base protocol. Rollups possess the following properties:
- Executes transaction outside Layer-1.
- Proofs transactions on Layer-1, thereby improving the security of Layer-2.
- Using the transactional data on Layer-1, rollup smart contract in Layer 2 enforces correct transaction execution on it.
- Operators stake a bond on the Rollups smart contract which they get incentivized to verify and execute transactions correctly.
Rollups can either be zero-knowledge or optimistic Rollups. They both differ in their security model:
Optimistic rollups is a Layer 2 solution designed to enable autonomous smart contracts using the Optimistic Virtual Machine. By default it doesn't perform any computation, hence, can offer up to 10-100x improvements in scalability depending on the transaction. It sits parallel to the main Ethereum chain on Layer-2. Transactions on Optimistic rollups are written on the main Ethereum chain in form of call data thereby further reducing the gas cost.
As stated ab initio, Optimistic rollups do compute transactions outside of the main layer in the form of batches and submit only the root hash of the block to the main chain. Hence, the need for a mechanism (fraud proofs) to ensure transactions are legitimate That way, when someone notices a fraudulent transaction, the rollups initiate fraud proofs before running a transactional computation using available state data. By implication, Optimistic rollups take significantly longer to confirm transactions than zero knowledge rollups.
There are currently multiple implementations of Optimistic rollups that you can integrate into your dApps. They include; Optimism, Off-chain Labs Arbitrum Rollup, Fuel Network, Cartesi, OMGX
This is a type of rollup on the ethereum blockchain. It bundles hundreds of transactions off-chain and generates a cryptographic proof known as Succinct Non-Interactive Argument of Knowledge (SNARK), often called validity proof.
The ZK-rollup smart contract maintains and updates the state of all transfers on Layer 2 with validity proof. Instead of the entire transactional data, the ZK Rollups needs only the validity proof, which goes on to simplify transactions on the network. Validating a block is quicker and cheaper in ZK Rollups because less data is included.
There are multiple implementations of ZK-rollups that you can integrate into your dApps. They include; Loopring, Starkware, Matter Labs zkSync, zkTube, Aztec 2.0, and so on.
A State Channel is a Layer-2 scaling solution that facilitates two-way communication between the participants which will allow them to perform transactions off the main blockchain. Typically, for a recurring payment State Channel does not require a recurring validation by nodes of the Layer-1 network to improve overall transaction capacity and speed. The underlying blockchain is sealed off via a set of smart contracts or multi-signature seals off. Leveraging the smart contract pre-defined by participants, they can directly interact with each other without the need of the miners. Upon the completion of the transaction or batch of transactions on a state channel, the final “state” of the “channel” and all its inherent transitions are recorded to the underlying blockchain. Some projects including Liquid Network, Celer, Bitcoin Lightning, and Ethereum's Raiden Network are currently deploying state channels scaling solutions.
A Sidechain is a secondary blockchain linked to the main blockchain via a two-way peg. Like most layer 2 scaling solutions, it uses an independent consensus and contracts to optimize throughput. On the sidechain, the main chain takes up security roles, confirming batched transaction records and resolving disputes.
They are somewhat similar to channels, however, it differs in how they process transactions and the security impacts. Transactions are recorded publicly on the ledger, unlike the private records of the channels. Sidechains enable tokens and other digital assets to move back and forth freely from the main chain. When the sidechain completes a transaction, a confirmation is relayed across the chains, followed by a waiting period for added security. Due to their allowance to move assets around freely on the new network, a user who wants to send the coins/assets back to the main chain can do that by simply reversing the process.
Plasma is a secondary chain on the Ethereum blockchain, proposed by Joseph Poon and Vitalik Buterin in their paper Plasma: Scalable Autonomous Smart Contracts. It comprises Merkel trees and smart contracts which create unlimited smaller versions of the main chain (Ethereum), called child chains. Integrating these child chains enables fast and cheap transactions off the main Ethereum blockchain into child chains.
Users can deposit and withdraw plasma chain funds, enabled by fraud proofs. For such a transaction to go on, there has to be communication between the child chains and the root chain, secured by the fraud proofs. Users deposit by sending the asset on the smart contract, managed by the plasma chain. Then the plasma chain proceeds to assign a unique ID to the deposited assets while the operator generates a batch of plasma transactions received off-chain at intervals. On the other hand, the contract initiates a challenging period during which anyone can use the Merkle branches to invalidate withdrawals if they can.
Like the CAP theorem in distributed systems, the blockchain trilemma suggests that blockchain cannot achieve scalability, security, and decentralization simultaneously. However, the Layer-2 scaling solutions have come to challenge the thought system. It allows the mainchain to take care of security while maintaining scalable networks in its additional layers.
Also Read Arbitrum: Scaling without Compromise