Back

What is layer2? From state channel to Roll Up

Ethereum blockchain is increasingly used, but the protocol's capacity is quite limited, resulting in congestion and soaring transaction fees. Many large-scale applications are unable to function properly on the Ethereum network, which is detrimental to the ecosystem's development. This situation has given rise to Layer 2 solutions.

Layer 2 is an overarching solution aimed at enhancing the performance of the Ethereum network (Layer 1). Layer 1 ensures security and decentralization, achieving global consensus through smart contract-designed rules for arbitration, and transmitting trust to Layer 2 through economic incentives. The core concept of Layer 2 solutions is to enable multiple participants to securely transact without posting transactions on the main chain (Layer 1). However, to some extent, they still rely on the main chain as an arbiter to ensure their security.

Status Channels

State channels are an introductory-level solution within Layer 2. They involve two transaction parties creating a channel off-chain, where they conduct transactions by signing with private keys. State channels serve as a means of scaling up transactions off-chain.

State channels, also known as payment channels, are the most widely adopted Layer 2 solution today. For instance, the Lightning Network is built upon payment channel technology.

How to use State Channels

For example, to establish an Ethereum payment channel worth $100, the funds are first locked. Once the locking is completed, both traders can send status updates in the form of [round, amount, signature] to each other to complete the transfer without interacting with the main chain. , as long as the balances of both parties are still positive. Once one party wants to stop using the payment channel, it can perform the 'exit' operation: submit the final status update to the main chain, and the settled balance will be returned to the two parties that initiated the payment channel. The main chain can verify the validity of status updates by verifying signatures and final balances, thereby preventing both parties to the transaction from using invalid status to exit the payment channel and ensuring the security of the exit mechanism.

Disadvantages of state channels

1. There is a problem with the 'exit' mode, that is, the main chain cannot verify whether the payment channel has submitted all transactions, that is, whether no new status updates will appear after the status update has been submitted.

The current solution to this problem is to provide a 'challenge period' for both parties to the transaction. This challenge period leads to a disadvantage: both parties may have to wait a relatively long period of time, usually 24 hours, to exit, and the main chain needs to be monitored frequently (at least once per exit period) to ensure that their counterparties are not using Exit from a certain state in the past.

2.The second disadvantage of state channels is low fund utilization. Since capital liquidity cannot be expanded, when many funds are locked in a state channel and can only be forwarded through the state channel, the efficiency is very low.

Sidechain

The core concept of a sidechain is to establish an entirely independent blockchain with its own validators and operators. It can transfer assets back and forth with the main chain, selectively sending snapshots of block headers to the main chain to prevent forks. These snapshots effectively prevent forks, even if validators on the sidechain conspire to initiate a fork attack.

What is layer2

From the figure, it can be observed that sidechains generate blocks and send their snapshots to the main chain. These snapshots refer to the block hashes stored on the main chain. The forking selection rule on the sidechain is that a legitimate chain must be built on the most recent block that has been snapshotted. In the illustrated scenario, Block A's snapshot has already been sent to the main chain. Even if validators on the sidechain collude and attempt a double-spending attack by generating a longer chain A' <- B' <- C' after the generation of Block A, participants on the sidechain would disregard this longer chain.

Disadvantages of Sidechain

Weak security. Although sidechains can leverage the security of the main chain to prevent forks, validators can still collude to launch another attack called invalid state transition. The idea behind this attack is that it is inherently impossible for the main chain to verify all blocks on the side chain. Therefore, if more than 50% or 66% (depending on the architecture of the sidechain) of validators collude, they can create a completely invalid block, steal other participants' assets, and send a snapshot of this block Go to the main chain, initiate and complete an 'exit' transaction, and you can successfully steal these assets.

Plasma

Plasma is a technology that enables 'unsupervised' sidechains. In other words, even if all validators on the sidechain (often called the 'plasma chain') conspire to do evil, the assets on the plasma chain are safe and can Return to the main chain. The simplest plasma design, often called Plasma Cash, only supports simple non-fungible tokens, and the assets transferred per transaction can only be a specific constant. Plasma Cash works as shown below:

What is layer2

Plasma's structure is built through the use of smart contracts and Merkle trees, allowing the creation of an unlimited number of child chains - essentially smaller copies of the parent Ethereum blockchain. On top of each sub-chain, more chains can be created, which is why it is called a tree structure. The biggest advantage of Plasma is that the tokens stored on the plasma chain are highly secure.

Disadvantages of Plasma

The complete history of the token must be provided at the time of transfer, and the exit mechanism is very complex. And it cannot be applied to smart contracts, which puts a heavy burden on users to run nodes.

Roll Up

Rollups is currently the most mainstream expansion solution. Its essence is to package a large amount of transaction data originally distributed in blocks into a set of transactions and publish it to the chain. Roll Up is actually a sidechain, so it generates blocks and sends snapshots of those blocks to the main chain. However, the operators on Roll Up do not need to be trusted. In other words, Roll Up assumes that the operator can stop block production, generate invalid blocks, conceal data and other malicious behaviors at any time.

As mentioned above, the problem of stateful validity of side chains. In order to avoid this problem, Roll Up requires operators to provide a SNARK (simplified non-interactive knowledge proof) when taking a snapshot of a block to prove the chain. A valid state transition has been performed using a related set of transactions. The following figure is an example:

What is layer2

There are three blocks on the Roll Up chain: A, B and C. Their snapshots correspond to blocks X, Y and Z on the main chain respectively. At each point in time, the main chain only needs to store the latest state of the Merkle root on the Roll Up chain. When block A takes a snapshot, the transactions sent to the main chain include:

  • Merkel root h(S2) of the new state S2.
  • The complete state data of S2, or all transactions in the block.
  • A zk-SNARK that proves that all transactions between state hash h(S1) and state hash h(S2) are valid and match the data provided in (2).

There are two types of Rollups: ZK Rollups and Optimistic Rollups.

ZK rollups

ZK rollups refers to packaging hundreds of off-chain transactions into a single transaction through smart contracts. After the data is submitted, the smart contract can confirm all transactions, which is also called validity proof. Since blocks contain less data, verification is faster and verification costs are lower. But ZK rollups cannot support smart contracts.

zk Rollup is a new Layer 2 expansion solution, mainly used for decentralized exchanges. The core idea of this technology is:

  • Use the main chain as a storage medium, not a consensus engine;
  • Compress transactions and reach consensus on the state off-chain.
  • Ensuring the security of off-chain state consensus using zero-knowledge proofs.

Optimistic Rollup

Optimistic Rollup is a layer 2 technology that extends Ethereum's general-purpose smart contracts using OVM (Optimistic Virtual Machine). The OVM is feature-rich and can provide a compatible execution environment with Ethereum's virtual machine, primarily used in layer 2 systems. It looks, feels, and behaves much like Ethereum's main chain. The design of Optimistic Rollup draws heavily from Plasma and ZK Rollup. However, it makes certain trade-offs in scalability to allow fully generalized smart contract execution within Layer 2, protected by Layer 1.

Optimistic Rollup inherits the 'fraud proof' concept from Plasma and defaults to 'optimistically' trusting that nodes will publish the most recent and accurate data to the main chain. Therefore, in terms of security, it is slightly lower than the mainnet. While the risk of losing funds is low, there might be a time cost involved (long exit periods).

The core ideas of this technology are:

  • The default transaction speed is 100 TPS.
  • This number can go up to 500 TPS when using BLS signature aggregation.
  • If EVM compatibility is broken, throughput could theoretically grow to the limits of ZK Rollup.
  • Actual throughput cap (token transfer): 500 TPS.
Recent search