All about Chains: Layer 1, Layer 2 and Side Chains

Why the need to have L2s and sidechains? Also, you may wonder why the L2s that we have mentioned so far are all scaling solutions for Ethereum and Bitcoin network, and not for the other L1s.

All about Chains: Layer 1, Layer 2 and Side Chains
Photo by Robin Pierre / Unsplash

Definitions

  • Layer-1 blockchains (“L1”) refer to a base network, such as Bitcoin, Ethereum, Binance Smart Chain (“BSC”), or Avalanche, and its underlying infrastructure. L1 blockchains can validate and finalize transactions without the need for another network. Meanwhile Layer-2s (“L2”) are built on top of L1, and in order to validate and finalize transaction, they need the help of the L1 on top of which they are built on. Examples of L2 blockchains are Arbitrum, Optimism, and Immutable-X. All three of them are built on top of the Ethereum mainnet
  • Other than L1 and L2, we also have sidechains. Sidechains have their own blockchain that is connected to L1 mainnet via a two-way peg system. Example of a side chain is Polygon (connected to Ethereum) and Liquid (connected to Bitcoin). The main difference between a sidechain with L2 solution is that most L2 solutions are built as an extension of the mainchains themselves and therefore rely on their security structure, whilst sidechains have their own blockchain, their own security structure and governance. Sidechains have their own consensus algorithms, validator, nodes or miners and are generally considered to be a more flexible “scaling solution”, at the expense of being less secure & more centralized compared to the L2s
  • Why the need to have L2s and sidechains? Also, you may wonder why the L2s that we have mentioned so far are all scaling solutions for Ethereum and Bitcoin network, and not for the other L1s. L1 blockchains like Ethereum and Bitcoin are very popular resulting in the network having to handle a lot of data which contributed to its congestion, while the other L1s have not reached the scale in which they are so congested they need a scaling solution. As per the image below, Ethereum has the most scaling solutions available, and you may have heard or read about some of these solutions in the past as they have became quite popular. Note that for the purpose of this article, we will not be discussing hybrid and validium solutions
  • How congested is Ethereum? For Ethereum, its block size / throughput are often constrained at max 45 transactions per second (“tps“), vs Visa’s offchain processing at 100,000 tps. The reason why these L1 blockchains like Ethereum have such low tps is due to the time and energy that need to be consumed in order to process onchain transaction in a secure manner. High demand and low tps results in inefficiencies such as outrageously expensive gas fees (we discuss gas fees in this article), especially in Ethereum chain. During peak times, it is not uncommon to see gas soaring too 200 Gwei, which means a simple ERC-20 wallet transfer require transfer fee of more than $10. Imagine transferring $50 worth of Ethereums only to receive net $40 worth of Ethereums in your wallet because 20% of the value is eaten up by blockchain fee. This actually occurs quite often in the crypto universe
  • L2s are invented to address the costly L1 transaction fees, and also as scalability solution to L1. L2s are not written into a code that affects the main blockchain. Instead, they are built using outside tools or factors that allow the transactions to scale through L2s, and into the main blockchain. For example is Arbitrum — Arbitrum does not have its own validators or miners, security features and etc. Arbitrum is a L2 solution for Ethereum, so it is simply existing on top of the Ethereum mainnet, with transactions occuring at its level requiring to be validated by Ethereum mainnet

How does L2 work?

How does Arbitrum and other L2 solution solve the cost and scalability issue of L1s? Firstly, the purpose are all the same — take the workload away from the mainchain, and only use it as a trust and arbitration layer

There are several methods:

  • Rollups: Simply defined — rollups move computations offchain i.e. from L1 to L2, compress the data into a single transaction, and validate this in L1 / the main blockchain. This frees up the blockchain capacity by taking lots of data processing away from the main blockchain. Rollup technology is further divided into two:
    1) Zero-Knowledge (“ZK”): ZK rollups seek to confirm that all transactions are valid. ZK generate validity proof for each transaction it processes with each batch of transactions having its own ‘validity proof’ for submission to the mainchain. The main benefits of ZK rollups is that since all transactions are validated (unlike Optimism), they can facilitate instant withdrawal from L2 to L1. Also, ZK rollups eliminates the tail risk of a fraudulent transaction as all transactions inside a batch are validated with succinct ZK proofs (“SNARK”), proving there exists a series of transactions correctly signed by owners. Additionally, onchain transaction on ZK rollup network is cheaper than Optimism as they are have better data compression tricks. This means, transaction data that are not relevant for verification & updating the state data can be left offchain, while the same cannot be achieved with Optimism (this doubles as better privacy for users). The main drawback of ZK rollups is that it is more technically and mathematically complex than Optimism which leads to higher fixed gas cost per batch, and applying ZK rollups will need learning curve from developers for adoption. Example of layer using ZK roll-up technology is Immutable X
    2) Optimism: Optimism, as per its namesake, is an optimist. They process transaction without checking its validity or performing any types of calculation. However, they include a challenge period (1 week) during which anyone can dispute the legitimacy of the data contained in a batch. If a fraudulent transaction is detected, the rollup executes a so called fraud proof and runs the content of the entire batch using the data available on L1. The main advantage of Optimism roll-up is that it is simpler and lighter in terms of fixed gas cost per batch as they are not required to compute all transactions (only batches in which there are questionable transactions). Another advantage is that Optimism is able to process smart contracts as it has higher EVM generalizability than ZK rollups. Optimism is also simpler to implement from tech perspective and requires less learning curve from developers. The main drawback of Optimism is the challenge period of 1 week which made it impossible for instant withdrawal. If you want to withdraw your funds from Optimism back to Ethereum mainnet, you will need 1 week before it can happen. Additionally, Optimism’s onchain per transaction gas cost is higher than ZK rollups as they need to include all data, just in case fraud proof is generated for some transactions inside the batch and the whole batch needs to be verified
  • State channels: State channel is a protocol between a fixed set of participants (often two) that want to transact securely between themselves offchain. The participants are allowed to transact x number of times offchain while only submitting two on-chain transactions to the Ethereum network. An example of an application would be two people engaging in an onchain game — lets say a game of chess. A specialized multisig smart contract will have to be created as the “channel” of this transaction, with the prize that is to be paid to the winner to be locked up inside the contract. Each move that is made by the players are all recorded as ‘nonce’, which essentially act as a timestamp for each transactions. When the game concludes, the channel would need to be closed by submitting the ‘final state’ in which the set of transactions submitted to the smart contract for one-time gas fee. The smart contract would then validate the transaction and pays the prize to the winner, assuming no dispute from all parties on the ‘final state’. The advantage of state channels are very high transaction outputs, cheapest gas and instant withdrawal. The drawbacks include the fact that the creation of the channel is time and resource consuming, the number of participants must be known (no open participation) and locking up your funds inside the smart contract
  • Plasma: Something like a mix between Optimism and a sidechain — altogether often referred to as Plasma childchains. Similar to Optimistic rollups, Plasma uses fraud proofs to arbitrate disputes and similar to a sidechain, Plasma childchain can have its own consensus mechanisms, its own block sizes, and its own confirmation times, the design is very malleable relative to each application. The main advantages of Plasma are its high throughput and low cost per transaction. Among its notable drawbacks are that it supports only certain types of transactions, such as simple token transfers and swaps. Another drawback is that withdrawals are delayed by several days to allow for challenges. D’apps that incur very high transaction fees with similar types of transactions are better suited to Plasma

What of Sidechains?

  • Sidechains like Polygon and RSK network are blockchain that exists on its own right, as mentioned above, with their own governance, security features, validators / miners and tokenomics, and are still considered by many crypto experts to be operating at L1 level
  • Sidechain uses a two-way peg connection with the base L1 chain like Ethereum or Bitcoin. It has similar purpose to L2 — to take workload off the mainchain in order to improve the mainchain’s performance. The two way peg allows for assets to be seamlessly moved around the main and sidechain, with a party called the Federation managing this peg. Each sidechain has their own policies when it comes to the Federation, for example, decisions such as how many signatures are needed to release the asset, whether or not time-lock is implemented or not, and many others — each policy design will have their own tradeoffs i.e. Federation that requires higher amount of multisigs to execute transaction probably prioritizes security over availability, and so forth
  • Do the tokens from the mainnet actually move to the sidechain? The answer is — not really. The tokens from the mainnet are stored in an output address and they are locked and unspendable. Another token is issued on the sidechain maintaining 1:1 value with the tokens in custody. For example, sending your Bitcoins to RSK network will convert your $BTC to $rBTC. $rBTC is pegged 1:1 to $BTC and can be converted back anytime. This means whenever you are in the RSK network and interacting with the applications built on top of the RSK network, the Bitcoin that you will be using is the $rBTC, not the $BTC. If you’re thinking this is similar to a multichain bridge — yes, the mechanics of moving around assets is similar in a way to a bridge
  • The benefits of sidechain is that it allows you more flexibility than the L2s at the expense of being more capital intensive. Sidechains also allow developers to experiment on a utility for a network without having to do it on mainnet. Sidechain like RSK allows developers to add utility to the immutable Bitcoin, such as borrowing, lending, staking etc that is otherwise impossible to do on the mainnet. Holders of Bitcoin now has more options on what to do with their Bitcoin bags other than just holding
  • The drawbacks, as previously mentioned, is that sidechain can be a very expensive venture. Also, the two-way peg of a sidechain may be vulnerable to attacks, and the sidechain can become compromised. However the good news is when a sidechain of a mainnet becomes compromised, the damage is limited to the sidechain itself. However, the peg may be compromised and the assets in the sidechain may not be able to maintain its 1:1 peg with the mainchain
  • Sidechains often have their own native currency as well which may or may not denominate the gas fees. For example, Polygon’s native currency is $MATIC, and users are paying gas denominated in $MATIC