In the past decade, Blockchain has been the most revolutionary with significant impacts on financial markets, insurance, the automobile industry, pharmaceuticals, IOTs, Healthcare, and governments. These are just a few of the industries that are exploring the potential of disruptive technology. Most technologies come with ups and downs, Blockchain is not an exception.
Bitcoin being the predecessor, was faced with the inability to scale followed by Ethereum. These are Layer 1 Blockchains.
In this post, we will discuss the following topics.
- Introduction to Layer 2
- Understanding Blockchain Architecture
- The Need for Layer 2 Solutions
- Types of Layer 2 Solutions
- The Role of Off-chain Scaling in Layer 2 Solutions
- Drawbacks and Limitations of Layer 2 Scaling
- Conclusion and Future Prospects
- Further Reading and Resources
A Blockchain is a digital ledger distributed among a network of interconnected computers across geographical locations. This structure makes it almost impossible for the system to be hacked or tampered with.
The functionality of every Blockchains technology is to store transactional records of the public grouped into blocks in several databases, known as the “chain,” in a network connected through peer-to-peer computers called 'nodes`. Typically, where these transactions are kept is referred to as a ‘digital ledger.’
A typical Blockchain has three major aspects which are Security, Scalability, and Decentralization. These three are essential to achieving full functionality in every Blockchain network.
Scalability: The ability of the Blockchain to accommodate an increasing inflow of transactions to the network.
Decentralization: The transfer of control and decision-making from a centralized point or entity (individual, organization) to a distributed network of participants.
Security: The system of preventing unauthorized access to data on the blockchain. Blockchains maintain security through decentralization and cryptography. There is a critical need for all blockchain networks to secure transaction data from being easily accessed, and this is done using cryptography to encrypt data while they are transferred between nodes. This type of encryption is irreversible.
Some of the earlier Blockchains would sacrifice decentralization to gain throughput, and vice versa. In the next section, we will look at how developers tend to solve this problem.
Over the years, implementation of the three concepts in a Blockchain network work has been a pain in the neck. This is a condition known as the
Blockchain trilemma. Blockchain trilemma is synonymous with the idea of an
opportunity cost where one of the concepts is preferred over the other. Layer 1 Blockchain such as Ethereum has consistently experienced scalability issues due to high participation in the network consequently resulting in increasing gas fees since everyone in the network is competing for storage. Ethereum earlier adopted the proof or work consensus mechanism which was said to be more secure but not ideal for scalability. Celo inherits largely from Ethereum although with significant changes and improvements. Among different solutions developers have found to improve the scalability feature on the Layer 1 blockchains, Layer 2 was proven to be more effective.
In the Blockchain domain, its ecosystem is a collection of components that are blended together to produce a unique trustless environment. Predominantly, a Blockchain has 5 layers each with unique functionalities. Although, some experts argued a Blockchain typically has 7 layers with
"Contract" layers being differences. Harmonizing these layers makes the system a complete solution ranging from management of backend data while enabling user-facing applications at the frontend level.
This is the Blockchain’s topmost layer. The content of a Blockchain is hosted on a server. The server is then mounted in the data center. There is a client-server architecture, a term often used in web browsing and other applications that queries the application server for contents.
Blockchain technology uses a Peer-to-Peer (P2P) network of connected computers (i.e.Nodes) for calculating, validating, and recording transactions in the digitally shared ledger in an orderly manner.
This layer contains the structures for managing and representing data in the Blockchain such as the Linked list. A link list has two components:
Link to the previous list: A collection of chained blocks or lists with each of the blocks containing the information about the previous block.
The integrity and security of a Blockchain are maintained using a cryptography system called “Merkle tree” - a tree of hashes represented in binary form that contains the hash of the Merkle root plus other information including the hash of the previous block, the nonce, date, block version number, and the current difficulty target.
This is the peer-to-peer (P2P) layer responsible for propagating messages among the nodes i.e. internode communication. A Peer-to-peer (P2P) network is a type of computer network where nodes are dispersed across regions sharing workloads with the goal of accomplishing a common purpose. Each connected node is involved in approving transactions and mining blocks.
This is a vital layer on the Blockchain that ensures the right and acceptable standards are being upheld. It is in charge of validating the blocks containing transactions, arranging them in the proper sequence, and ensuring everyone in the network agrees to a decision.
It contains every infrastructure that the end users need to interact with the Blockchain such as the APIs, interfaces, smart contracts, frameworks, and decentralized applications.
Over the years, among many tested solutions such as increased block sizes, introducing multiple/alternative consensus mechanisms, etc, Layer 2 solutions have proven to be more elegant in resolving the inability of Layer 1 to scale over time. Effective scaling of Blockchains has been enabled while simultaneously maintaining decentralization in the network.
To set up Layer 2, no structural alterations or modifications are required to the Layer 1 or main chain.
High throughput or scalability is achieved without giving up security at the base layer.
Significant reduction in costs.
With Layer 1 designs, it would handle a considerable number of transactions based on the available hardware and infrastructures. Soon as the volume of transactions increases which directly imparted fees in the network, it would not be able to accommodate transactions that surpass its hardware capability.
Therefore, there is a need to expand its reach through modifications such as increasing block size. This could compromise either security or its decentralization feature and obstruct adoption and long-term growth. With Layer 2 solutions, the base layer will be allowed some breathing room since most of the computations and processes are relieved of Layer 1.
Difference between Layer 1 and Layer 2 blockchains, and the reliance of Layer 2 on Layer 1 for security and finality
A theoretical glance at the architectural view of blockchain shows that the blockchain system itself is in layers. Examples of Layer 1 blockchains are Celo and the Ethereum blockchains. Layer2 networks rely on these Layer 1 technologies for finality and automatically inherit the security feature.
Let’s take a view of the differences between Layer 1 and Layer 2.
|Layer 2s are a scaling solution built on top of layer 1 blockchains such as Celo or Ethereum
|More secure and decentralized but not scalable
|Primarily designed to address the issue of scalability of Layer 1
|Increasing cost of transaction
|It equivalently solves the issue of high gas fees especially when the network is experiencing congestion.
|Maintains security and finality
|Transactions are grouped in batches, and sent to Layer 1 for finality
To improve the performance of the base main chain, Layer 2 technology was proven to be an ideal solution at this time. There are different types of Layer 2 solutions targeted at enforcing scalability. They include:
- Side chains
- Payment channels
- State channels
Sidechains are similar to Layer 1 in structure except that they can choose to be independent of the main chain or not. They operate nodes with a set of validators and maintain their own consensus mechanism to enhance the security, scalability, and decentralization of their network. But they differ in that their nodes will be fewer in number compared to the Layer 1 chain. This literally enables them to reach a consensus faster than Layer 1. In practice, developers might prefer running Sidechains to other Layer 2 solutions such as Payment channels if they desire more flexibility and control over their infrastructure for reasons such as operating a native token. Alternatively, they may also rely on Layer 1 by submitting state data to benefit from the security feature of the main chain.
This is an off-chain transaction arrangement between two or more users for sending and receiving values. Two people could agree to form a channel purposely for settling payments between each other. The final state of their account i.e. final balances could then be broadcasted to the Layer 1 network. It can also be viewed as a peer-to-peer protocol that connects two parties to make an undetermined number of transactions amongst themselves while they only need to post the final results to the blockchain. A cryptography approach is then used, to sum up the aggregate data results from the earlier set of transactions. Executing and validating state changes are enabled by interested parties so as to minimize computation on the execution layer. This system reduces congestion while simultaneously increasing speeds.
A perfect example of a Payment channel is an escrow account. Consider “XYZ”, an escrow service with the following steps.
- Deploy a smart contract at
"K"with native asset
- Bob and Alice lock
"K"causes the channel to open for both parties
- They can now transfer tokens
"N"between themselves so long the total of
"N"spent by either party does not exceed the equivalent amount in
- Each time a transfer occurs, their accounts’ current state is shared.
- In this channel,
"A"will be valid and accepted as a form of money since both participants are aware they have funds locked in
"K"which can be redeemed in part or full.
- To close the channel, it could be that either of the participants can submit the current accounts state to the main chain as a single valid transaction i.e. after the escrow agreement is completed.
This type of Layer 2 Payment channel is much faster and cheaper since it does not require the outright consensus of the whole network for verification and participants only need to pay for the gas fee for locking funds and submitting final state changes to the main network to close the channel. It can be used for a one-time transaction or simply left open for a determined or indefinite period of time to enable off-chain bonds between the participants while periodically updating the latest state to the Layer 1 chain when any of the participants wish to redeem their funds.
This is a blockchain Layer 2 solution that allows participants to conduct unlimited and more complex private transactions off-chain than the mere transfer of funds. They’re a more generalized form of payment channel. Participants in this channel are only able to observe transactions since they’re not public. Like the Payment channel, only the initial and final state of the transactions is transmitted to the main chain, fees are only incurred to open and close the channel.
To avoid recording multiple small transactions such as transfers on the first-layer blockchain, State channels are introduced. This encourages security, speed, and cost minimization.
Gaming is an example of a complex operation that could be conducted in a state channel such as tic-tac-toe. The rules of the game are usually embedded in
game logic while the current stated is contained in the
state logic. The state logic also handles the locked funds which are released based on the final outcome of the game.
The main chain (Layer 1) and Layer 2 have special methods through which values are transferred between them. Where an element of value (i.e. Money) is involved, care must be taken to avoid leakages. Rollups are basically a popular option among layer 2 scaling solutions. It works by moving transaction processing off the main chain. One of its goals is to facilitate security and aggregating transactions for storage on the Layer 1 blockchain.
Majorly, there are two methods for transferring value between these technologies, and they use different approaches to agree on the true state of operations on the main layer.
State of operation on Layer 1 at any time is the aggregate account balances with total values in each connected Layer 2
- Optimistic, and
Primarily, Rollups involve using smart contracts to bundle up a series of transaction data off Layer 1. These bundled transactions go through validation tests from the network participants known as validators. The validators perform additional tasks on the bundled data to achieve a highly compressed end result which is then sent to the Layer 1 network. They can facilitate off-chain data availability by not broadcasting results to the main chain thus generally creating significant scaling improvements. Using EIP4844, Optimistic Rollups facilitate cost-efficiency thereby making it seem a preferred alternative to ZK-Rollups.
This is a form of cryptography computation that allows one party in a transaction (the prover) to prove that they have knowledge of a specific piece of information to another party called the verifier without revealing what exactly the information is. It’s a cryptographic method of preventing fraud in a system.
ZK-Rollups work similarly to Optimistic Rollups as transaction processes are taken off-chain, and the end result is cryptographically verified before being sent to the execution layer. A quick comparison between the two methods shows that Optimistic Rollups assume that the data are correct while the ZK method ensures the integrity of data before they’re propagated for inclusion on the main chain.
Everything about Layer 2 is operated without the knowledge of Layer 1. This is a pure indication that transaction execution is completed elsewhere and not on Layer 1. Any arrangement or channel where transactions can be completed between more than one participant with the use of smart contracts without the complete transaction process happening on Layer 1 is referred to as off-chain scaling.
The goal of layer 2 off-chain scaling is to achieve throughput i.e. increase speed in the network and accommodate more transactions i.e. speed and scalability. Before Sharding was implemented, Ethereum Layer 1 (mainnet) was only able to process 15 transactions per second. When demand becomes high, the network resources is not able to accommodate the inflow hence congestion. Layer 2 was later introduced to scale the network. Celo blockchain takes after Ethereum since it is a fork of Ethereum’s Layer 1. Since the scalability issue becomes inherent, to cushion the effect, Celo has also implemented Layer 2 solutions. It is worth noting that Celo’s approaches to both layers of solutions are very commendable.
Overview of different designs that can be adopted to achieve these goals while still maintaining security and finality on Layer 1.
Since the focus is on the two trilemmas, different approaches, and designs that do not require the need for decentralization can be adopted in as much as the end result is transmitted to Layer 1 where security will be enforced i.e. decentralization and finality. Let’s consider some XYZ, an escrow service that operates in a much similar way as Remittano. Bob has initiated a transaction request to transfer the
x amount of Celo-based asset to Alice provided she (Alice) deposited the
y amount of another asset in escrow to the XYZ account. XYZ acting as the intermediary successfully completes the transaction between the parties in off-chain mode. XYZ could decide to communicate to the Celo mainnet using batched transaction method if a specified number of transactions are completed in a certain period of time. It could also be a time-based communication.
The bone of contention to Layer 2 solutions is often
"Delayed withdrawals" with optimistic Rollups topping the list with the longest withdrawal time. Usually, it takes several hours to days to complete verification on the transaction submitted on the Optimistic network.
A Sidechain could suffer a severe permanent loss of users’ funds with a 51% attack if it chooses not to perform periodic data submission to the main chain.
We started by examining what a Blockchain entails, then I introduced you to the Blockchain trilemma, its architecture, and Layer 2 technologies. We also discussed the importance of off-chain scaling, differences between Layer 1 and Layer 2, the different types of Layer 2 scaling solutions, its limitations, and applications in the real world citing an example under Payment channel.
Layer 2 offers faster and cheaper alternatives for developers and dapp users to interact with the blockchain while allowing Layer1s like Ethereum and Celo to gain popularity and increase adoption without compromising decentralization at the protocol layer. The risk of permanent loss or hacks can be mitigated as long as Layer 2 is willing to adopt the security and decentralized features of the main chain by consistently backing up the most recent data to Layer 1. Celo as a Layer 1 Blockchain has implemented a few Layer 2 solutions which I hope to discuss in my next post, and how you can implement them in your project.
By now, you should have good knowledge of Layer 2 concepts. If you’re a web3 developer, understanding the concept of Layer 2 technology will help you make the best decision to pick the best solution for your project. Applying what you have gained in your project. To learn how to deploy your dream project on the Celo blockchain, visit the Learn more how to deploy your dream projects.
Digging deep into cutting-edge technology gives you an upper hand over others to navigate opportunities and build top-notch skills that set you up for better careers.
Isaac Jesse, aka Bobelr is a full-stack web3 developer with proficiency in smart contracts development. He was an ambassador and DevAm for several projects like Algorand etc.
Thank you for reading.