Layer 2 Blockchain scaling solutions: Channels, Sidechains, Rollups and Plasma (Part 16)

Techskill Brew
Blockchain 101 by Techskill Brew
16 min readMar 3, 2022

Welcome to the 16th part of the 100 part series on Blockchain.

Previous parts: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 and 15.

Layer 1 solutions aren’t the only option available to scale Blockchains. Layer 2 scaling solutions establish an additional protocol that is built on top of Blockchains like those of Ethereum and Bitcoin.

Layer 2 Blockchain

While Layer-1 is the term used to describe the underlying main Blockchain architecture, Layer-2, is an overlaying network that lies on top of underlying main Blockchain layer 1. They are called layer 2 because they are not written into a code that affects layer 1. Consider Bitcoin and Lightning Network. Bitcoin is the layer 1 network, while the lightning network is layer 2.

Layer 1 and layer 2 Blockchain

Other Blockchain layer 2 examples are Ethereum’s Plasma, Polygon, and so on. The layer 2 scaling solutions don’t require changes in the layer 1. It can be just built on top of the layer 1 using the existing elements, such as smart contracts.

Layer 2 scaling solutions help with increasing the capabilities of layer 1 by handling transactions off-chain. The two main capabilities that can be improved are transaction speed and transaction throughput. For instance, Ethereum can currently process around 15 transactions per second on its base/mainchain layer 1. Ethereum 2.0 has already scaled Ethereum 1.0 Blockchain to some extent. It uses Proof of Stake and sharding that increased the transaction throughput on layer 1. But layer 2 scaling solutions can enable Ethereum 2.0 to handle hundreds of thousands of transactions per second.

On top of that layer 2 solutions can greatly reduce the transaction fees (gas fees in Ethereum Blockchain).

Layer 2 scaling solutions can be divided into 4 categories:

· channels

· roll-ups

· plasma

· and sidechains.

While sidechains have their own security properties, other layer-2 solutions (channels, rollups, and plasma) generally rely on the security of the mainchain (layer 1).

Channels

The first type of scaling solution is channels, which allow creating a peer-to-peer channel between two parties. The parties can exchange an unlimited amount of transactions off-chain (on layer 2) while only submitting two transactions to the mainchain layer 1, which are:

(i) One is the first transaction that opens the connection between mainchain layer 1 and channel layer 2.

(ii) Another transaction stored on layer 1 is the transaction that closes the connection between layer 1 and layer 2.

By taking most of the transactions away from layer 1 (off-chain transactions), layer 2 channels improve transaction speed and reduce network congestion, transaction fees, and transaction delays.

The most popular types of channels are state channels and payment channels. Payment channels deal with payments, and state channels deal with general state updates.

(a) State channels: State channels deal with the state update on a Blockchain network. Let’s understand state channels through an example. Suppose two players want to play game tic-tac-toe on Ethereum Blockchain. For this,

(i) First, the players create a multi-signature smart contract on the Ethereum mainchain that contains the rules of tic-tac-toe, information about the players, and prize money 1ETH for the winner.

(ii) Then, players enter the state channel and begin playing the game. Each move of the player creates an off-chain transaction that is stored on the smart contract.

(iii) When there’s a winner, the players close the channel by signing the final state and submitting it to the multi-signature contract. The final state of the contract is then stored on the Ethereum mainchain, and the prize money 1ETH is transferred to the winner.

State channels to play tic-tac-toe game on Ethereum Blockchain

(b) Payment channels: Payment channels are similar to state channels, but they deal with payments only. For instance, the payment channel used by Bitcoin Blockchain is the Lighting network, and the payment channel used by the Ethereum Blockchain is Raiden. The channels enable the creation of peer-to-peer payment channels between two parties. The two parties can transfer funds between themselves indefinitely without the involvement of layer 1. Eventually, when the two parties decide to finish transacting, they can close the channel. The final state of the transaction is then recorded on Blockchain layer 1.

(i) To open a payment channel like a Lighting network, the two participants must first deposit some coins in the muti-signature wallet (greater than the total amount involved in the subsequent transactions). It is the first transaction to open the channel and is recorded on Bitcoin layer 1.

(ii) After the money is deposited, both participants can make unlimited transactions without interaction with layer 1. This can happen unlimited times as long as there is sufficient balance in the wallet.

(iii) If one of the participant cheats, all funds in the channel will be sent to another participant as a penalty.

(iv) When the participants are done with transactions, they sign on the final state of the transaction with their private keys, and the channel is closed. The final state of the transaction is then recorded, and the balance is transferred to the participants on the mainchain.

Only two transactions (opening and closing of payment channel) are recorded on the main Blockchain. This significantly reduces the transaction load on the Bitcoin network.

Payment channels to handle payment transfers

Examples: Examples of other channels are the Celer network, Connext, Kchannels, etc.

Benefits: (i) By taking transactions away from layer 1 (off-chain transactions), layer 2 decongests the layer 1 network and subsequently increases the transaction speed. For instance, the main Bitcoin Blockchain (layer 1) can handle around 10 transactions per second, but the Lightning Network (layer 2) can handle thousands to millions of transactions per second.

(ii) Because of the decrease in transaction fees, micropayments are feasible. For instance, the payment channels may even allow users to pay for even smaller goods and services such as coffee without affecting the main Blockchain network.

Limitations: Although channels have the potential to process thousands of transactions per second efficiently, they come with a few downsides:

(i) For transactions, the participants have to stay online at all times and use their private keys to sign in. This makes them vulnerable to hacks and thefts if attackers crack the private keys.

(ii) Participants have to lock up a certain amount of their funds in a multi-signature wallet in order to open the payment channel. Keeping coins in a hot wallet on a mobile, server, or PC makes them more vulnerable to online attacks, leading to stolen coins. On the other hand, a cold wallet is not connected to the internet, making it more secure but less convenient.

Sidechains

Sidechains are separate Blockchains that are connected to the main Blockchain through a two-way peg to help process some of the data from the main Blockchain.

Sidechains are connected to the mainchain through a two-way peg

Each of these chains has its own set of rules, functionalities, and purposes. Unlike other layer 2 solutions- channels, plasma, and roll-ups, which leverage the security of layer 1, sidechains are responsible for their own security. Another important point about sidechains is that they need their own nodes to validate transactions and create a block. They also have their own consensus mechanisms (such as POW, POS, Proof of Authority, DPoS, etc.) and block parameters. The block validating nodes earn the rewards for their work in a sidechain in the same manner that all other Blockchains work. Although sidechains remain independent from one another, together they form an entire ecosystem.

How do sidechains work?

The main job of sidechains is

· processing and validating data for the mainchain

· or adding functionality, such as running smart contracts for Blockchains that are unable to do that, like Bitcoin.

Sidechains communicate with the mainchain via a two-way peg (2WP); thus, the sidechains are also called pegged sidechains.

(i) Two-way peg (2WP): The 2WP acts as an intermediary to facilitate the transfer of assets or coins from the mainchain (layer 1) to the sidechain (layer 2) and vice versa. Under the hood, coins are not transferred; instead, they are temporarily locked on the mainchain by creating a transaction. A second transaction is generated to unlock the same amount of equivalent coins in a sidechain. The coins on the mainchain can be unlocked only when the equivalent amount of coins on the sidechain are locked again. This is done to avoid the presence of free coins on both chains and prevent a double-spending problem. 2WP system enables the interested parties to get into a transaction on the sidechain without revealing the information to the entire network.

Locking and unlocking of mainchain and sidechain coins

(ii) Presence of the third-party: The third-party/authority is in charge of the locking and releasing functions between the sidechains and mainchains. A transaction to lock coins is initiated. After the consensus is reached among the nodes, the signed block is submitted to the mainchain. This automatically locks the coins on the mainchain.

The trusted authority who controls the 2-way peg then issues an equivalent sum of coins in the sidechain to the transaction parties. The parties can then have a bunch of transactions within the confines of the sidechain. Once the transactions are done, the authority then verifies the transactions and releases the corresponding coins in the mainchain by unlocking the coins.

The whole sidechain construct is based on the 2-way peg and the trusted authority for maintaining the integrity of transactions between the two chains. The presence of authority can bring centralization in the network by giving it too much power.

(iii) SPV proofs: SPV (Simple Payment Verification) proof is a way to cryptographically prove that the coins are locked on the mainchain for their use on the sidechain. Rather than checking all the previous transactions, which would be slow, an SPV also proves whether the transaction initiated on the mainchain is valid and is a part of the valid block. Through SPVs, the nodes on the sidechain are not required to download the whole main Blockchain every time the verification process is needed. The Bitcoin and Ethereum Blockchains support SPVs in the form of Merkle proofs. The Merkle Proofs include the Merkle Root and the Merkle Path.

Each pair of hashed transactions is hashed together by the hash function and so on until there is one hash for the entire block, which is called Merkle Root or Root hash. On the other hand, the Merkle path is the set of hash values required for generating root hash. For instance, the Merkle path for transaction D will be the hash values Hash C, Hash AB, Hash EFGH, and Merkle root.

Merkle path for transaction D

The nodes of the sidechain repeat the hash operation to compute the root hash value. If the root hash value obtained by the process matches with the root hash value present in SPV, it means the transaction has been initiated that locked coins on the mainchain.

Examples: Examples of sidechains of Bitcoin Blockchain are the Liquid Network and Rootstock (RSK). With the Liquid network, blocks are added every minute, compared to Bitcoin’s 10 minute block time. By adding the RSK sidechain to Bitcoin Blockchain, Bitcoin can use smart contracts, thus, broadening its functionality. Therefore, RSK can add an Ethereum-like layer to the Bitcoin protocol and thus enable the Bitcoin protocol to develop DApps using smart contracts.

xDai Chain, POA network, and Polygon (formerly known as Matic network) are a few examples of sidechains of Ethereum Blockchain. Interoperability of sidechains with Ethereum mainchain is made possible by using the same Ethereum Virtual Machine (EVM). So contracts deployed to the Ethereum base layer can be directly deployed to the sidechain.

Benefits: (i) Sidechains increase the transaction throughput by taking away the majority of transactions into their sidechain and processing transactions at a much higher rate. They also significantly decrease the transaction fees. For example, Polygon, an Ethereum sidechain, claims to have reached scalability of 65000 transactions per second, with transaction fees of around $1.

(ii) Public Blockchains are transparent and open to audit. Every transaction is recorded and can be verified by any participant. But for enterprise businesses, public Blockchains are not useful due to the risk of revealing a lot of business-specific information. But with sidechains, the privacy of the transactions can be maintained. The data about the business-related transactions reside in the sidechain, and the mainchain acts as a record store for verification of hashed data. While the mainchain is public and permissionless, the sidechain is designed private & permissioned to cater to business needs. The business-specific data can be stored securely in the sidechain and hence much more secure and immune to hacking.

Challenges: Most sidechains are a little more centralized than the mainchain because of which they provide a security trade-off for speed. Therefore, the information that is outsourced to the sidechain can be selected, with the most sensitive details remaining on the mainchain to maintain security.

Plasma

Plasma is another layer 2 scaling solution. Plasma leverages smart contracts and Merkle trees to create an unlimited number of child chains copies of the parent Blockchain mainly (Ethereum Blockchain). Offloading transactions from the mainchain (layer 1) into child chains (layer 2) allows fast and cheap transactions. Like sidechains, each child chain is treated as a separate blockchain with its own consensus mechanism, nodes, block size, and block time.

Like channels, plasma leverages the security of the mainchain. The mainchain and child chains are tied together through ‘smart contracts’ that contain the rules guiding each child chain. The contracts act as the bridge that lets the participants move digital assets/coins between the mainchain and the child chains. Initially, all transactions have to be created on the mainchain.

If any suspicion or fraud is detected in the plasma child chains, plasma users can exit the plasma chain and move to the mainchain.

How does Plasma work?

(i) The child chain operator lays down the rules in which the child chain will operate.

(ii) Processed transactions stay at the plasma chains. But the block headers (containing Merkle roots) of each block of the plasma chains are submitted and recorded in the blocks of the mainchain. This reduces the mainchain network congestion and thus, allowing tens of thousands of transactions to be processed simultaneously in plasma chains.

(iii) The data on child chains is validated using “fraud proofs.” Fraud proofs are a mechanism by which anyone can determine if the data is invalid using Merkle proofs. For example, when fraud occurs in a plasma chain, whether it is a double-spending case or one cash out more than they have in all accounts, anyone can provide a fraud proof to prove the transaction is invalid. If the transaction is proven fraud, it will be rolled back.

Benefits: (i) Plasma chains are more favorable than channels because one can send assets/coins to anyone, whereas with channels, the transaction can occur between two parties only.

(ii) The advantage of Plasma chains over sidechains is that the plasma chain is secured by the mainchain. If the sidechain gets attacked, nothing happens to the mainchain, but the mainchain can’t do anything to protect users on the sidechain. While, since the plasma chains leverage the security of mainchain, in the case of any attacks, plasma chain users can exit and move to the mainchain. Thus, the security of plasma is more than the sidechains.

Limitations: (i) One of the drawbacks of plasma is a long waiting period for users who want to withdraw their coins from layer 2 and transfer them to layer 1.

(ii) The users have to wait for at least 7–14 days for the withdrawal. This time duration is required to verify that the withdrawal transaction isn’t fraudulent.

Examples: The project that leverages the power of Plasma on Ethereum is OMG.

Rollups

Like channels, sidechains, and plasma, rollups are also scaling solutions that use both layer 1 and layer 2 Blockchains. In rollups, the transactions initiated on the mainchain are executed on layer 2. Then the data of the executed transactions are bundled or rolled up into a single block and then posted to the mainchain layer 1. Thus the scaling solution got the name “rollups.” As a result, Layer 1 is eased up as all the computation work is done off-chain on layer 2. Because of this, more transactions can be processed in parallel, making the Blockchain network scalable. Additionally, like channels and plasma, rollups also rely on the security of the mainchain.

Rollups bundles executed transactions into a single block and post it to the mainchain layer 1

A version of the Ethereum Virtual Machine or EVM is run inside the rollup layer. It means that any transaction possible on the Ethereum mainchain is possible to execute on the rollup. Additionally, it allows the existing Ethereum applications to migrate to rollups without writing any new code.

Advantages over plasma: The advantage of rollups over plasma is that the data of each batch of executed transactions is bundled and is posted on the mainchain. But with Plasma, only the Merkle roots are recorded on the mainchain. The amount of data posted on the mainchain is the minimum amount required to validate the rollups transaction. By putting data on the mainchain, anyone can detect fraud. Therefore, rollups give much higher security than Plasma chains.

How do rollups work?

(i) There’s a “rollup contract” on the mainchain that stores the state root of the rollup layer. The state root is the Merkle root of the current state of the rollup. Merkle tree is derived from all the transactions on the rollup.

Rollup contract on the mainchain contains state root of the layer2

(ii) When transactions happen on the rollup layer, state root (Merkle root) changes. That means the state root needs to be updated on the rollup contract on the mainchain. For this, the executed transactions are compressed, batched, and posted on the rollup contract together with updated state root. Along with the updated state root, the batch of executed transactions includes account balances of the users, addresses, contract code, etc. The entire Merkle tree is stored on the layer 2 rollup, not on the mainchain.

(ii) The batch of executed transactions is stored on the mainchain in a highly compressed form along with the previous state root (Merkle root before processing transactions) and the new state root (Merkle root after processing transactions).

State root is updated on rollup contract when transactions are executed on the layer2

(iv) The rollup contract checks that the previous state root in the batch matches its current state root; if it matches, it switches the state root to the newly updated state root.

Types of rollups: There are two types of roll-ups based on the proofs to validate that the state roots in the batches are correct.

· Zk roll-ups

· Optimistic roll-ups

Optimistic rollups: A new batch of transactions is compressed, bundled, and posted to the mainchain along with the state root. The rollup contract keeps track of the entire history of state roots of each batch. At the time of posting, it is not actually validated that the transactions have been executed correctly. In other words, we are “optimistically” posting the new state root and transaction data to the rollup contract on the mainchain. If someone discovers that one batch with incorrect state root has been published to the rollup contract, they can generate a “fraud-proof.” The fraud-proof incudes:

· Proof of pre-state root, or the Merkle root that should be before processing transactions

· Proof of new state root, or the Merkle root that should be after processing transactions

· Proof of the executed transactions

The fraud-proof is posted to the rollup contract on the mainchain. The rollup contract verifies the proof and compares the result to its state root. If there’s a mismatch, the contract rolls back the batch and all the batches after it until it reverts to the last known valid batch.

Examples of Optimistic rollups include: Optimism and Arbitrum

A major limitation of Optimistic rollups is the longer withdrawal time. If anyone suspects a transaction to be fraudulent, they can challenge it and submit fraud-proof within the time duration of 7 days. Thus, users have to wait around one week to withdraw their assets from layer 2 rollups.

Zero-knowledge rollup (ZK Rollup): Since the optimistic rollups work on the “innocent until proven guilty” belief, ZK rollups rely on the “don’t trust, verify” belief. The batch of bundled transactions is updated on the mainchain only when validity proof called SNARK (succinct non-interactive argument of knowledge) is submitted. SNARK is cryptographic proof that proves the new state root is the correct result of executing the batch of transactions in the ZK-rollup layer. The validity proof is posted to the rollup contract, so anyone can use it to verify transactions in a particular batch on the rollup layer.

SNARKs are also called Zero-Knowledge Proofs or ZK Proofs because they allow anyone to verify that the transactions are valid without revealing any information about the transaction. In other words, anyone can verify that the data existed, even if they don’t have access to the data itself.

Examples of ZK rollups include: Loopring, Hermez and Starkware

Limitations: (i) Since the data of executed transactions is bundled and posted on the mainchain, the scalability gets limited. The scalability with rollups can be up to 100x, but they can’t scale the Blockchain infinitely.

(ii) Though the mainchain network congestion is eased as all the computation work is done off-chain on the rollup layer 2, the transactions are executed by running a version of the EVM in the rollups. Thus, on the rollups as well, the same execution is being performed as the Ethereum mainchain, and the users are charged gas fees. But gas fees on the rollup layer are much cheaper than on Ethereum.

If you liked this article and want to know more about Blockchain, NFTs, Metaverse, and their applications, click the below link.

Happy learning!

--

--