Understand Layer 2 in one article

Chainlink
本文约4666字,阅读全文需要约19分钟
Layer 2 refers to the off-chain network, system or technology based on the underlying blockchain, with the purpose of expanding the underlying blockchain network.

blockchainblockchain(Note: Usually also referred to as "Layer 1 network") off-chain network, system or technology, the purpose is to expand the underlying blockchain network. Layer 2 networks can improve the throughput and other performance of any underlying blockchain.

A core value of a Layer 2 network, system or technology is the ability to leverage the security of the underlying blockchain. Its transaction data must be verified and confirmed by the underlying blockchain network in some form. According to this standard, the side chain does not belong to Layer 2, because the side chain usually deploys its own consensus mechanism and verification nodes, so it has a security mechanism independent of the underlying blockchain.

first level title

The need for Layer 2

Blockchain technology was born in 2008. Since then, thousands of researchers and developers have been working on solving the bottleneck of blockchain scalability to meet the ever-increasing application demands. These bottlenecks lead to high transaction costs and slow execution speeds, and have become a stumbling block to the mainstreaming of blockchain technology.

Ethereum co-founder Vitalik Buterin first proposed"Blockchain Impossible Triangle"The concept that the blockchain cannot take into account the three dimensions of scalability, security and decentralization at the same time. Developers have to make a trade-off between the three. Today's blockchain network can only satisfy two of these dimensions at the same time.

Layer 2 is an emerging technology, which claims that the reason why the blockchain has limitations in scalability is because the blockchain needs to complete too many tasks. The current blockchain has three core functions, namely: execution of transactions, data availability, and consensus.

  • Execute the transaction——Process and complete transactions. The metric is the number of calculations (which includes the number of transactions) that the blockchain can complete per second.

  • Data Availability -Nodes and validators in the network need to store transactions, state, and other data. Metrics are standard storage units such as MB and GB.

  • Reach a consensus——Nodes and validators need to reach a consensus on the state of the network and ordering of transactions. The metrics are the level of decentralization and finality velocity, or the time it takes for all nodes to agree on a state change.

blockchain scalabilityblockchain scalabilityfirst level title

How the L2 solution works

Note: Most Layer 2 solutions are still in their early stages, with many elements yet to be validated.

smart contractsmart contract, responsible for resolving any disagreements and transmitting the consensus reached by the Layer 2 network to the underlying blockchain for verification.

Transactions and calculations can be performed quickly on the Layer 2 network. Different networks will improve transaction throughput in completely different ways. But these Layer 2 networks have one thing in common, that is, they will submit some kind of verifiable cryptographic proof to the underlying blockchain at the time of settlement to prove the authenticity of the state change. Some Layer 2 proofs are created in advance and submitted to the underlying blockchain, while others create proofs retroactively later.

In addition, different Layer 2 networks implement different smart contracts on the underlying blockchain, but the core functions of smart contracts are the same, namely:

  1. Save and release funds, transfer to Layer 2;

  2. Receive the proof submitted by Layer 2, verify it, resolve differences, and finally confirm the transaction.

first level title

payment channel

Two or more users can deposit funds into the channel in advance, and then transfer tokens off-chain.

Alice and Bob respectively lock a sum of funds in the smart contract, create a payment channel, and agree on how much funds both parties can use through encrypted signature technology. For example, both parties lock in $50 each, so the total amount of funds in the payment channel is $100. Then they will probably agree that each party can use $50.

Once the payment channel is established, both Alice and Bob can transact off-chain through signed messages without submitting the transaction to the underlying blockchain. Alice can pay Bob, and Bob can pay Alice, with no cost or delay. In this two-way payment channel, transactions from Alice and Bob are not sent to the underlying blockchain. Only when both parties decide to close the channel, the final transaction result will be sent to the chain for settlement.

image description

first level title

Rollups

Optimistic rollups and zk-rollups can execute smart contract state changes off-chain and verify them on-chain to increase blockchain throughput and reduce costs. Rollups can be expanded in the following three ways:

1. Rollups inExecute transactions off-chain, the underlying blockchain only needs to calculate lightweight transaction proofs, verify network activities and store raw transaction data.

2. Rollups willTransaction data packaging, and submitted to the blockchain, the gas fee on the chain can be allocated to each transaction.

secondary title

off-chain execution

A key feature of rollups is that transactions are executed off-chain. This means that the Layer 2 network can handle transactions with other users or smart contracts instead of the underlying blockchain. Due to the smaller number of verification nodes and more powerful hardware, this will greatly increase the transaction throughput of the Layer 2 network compared to the underlying blockchain.

secondary title

package deal

Another way to reduce costs is to bundle transactions. You can think of this as gift giving. On the blockchain, each transaction is an individual gift, put in a different box. This can lead to very high shipping costs because you need to pay a shipping fee for each gift you send. Rollups, on the other hand, put many gifts in one big box and pay for the shipping once, splitting the shipping cost for each gift.

If you want to explain it in more technical language, it is that rollups package raw transaction data into calldata. The verification method of Rollup transactions is different from that of transactions on the chain. The transaction data is packaged only to store the data on the underlying blockchain. The verification nodes or rollup participants can rebuild the state of the Layer 2 network at any time if necessary. However, the core logic remains unchanged, that is, multiple rollup transactions are stored in one packaged transaction on the main chain.

This can effectively reduce transaction costs and clear the way for blockchain expansion. Compressing data can further reduce transaction execution costs.

secondary title

Reduce the number of validating nodes

As mentioned above, Layer 2 can take advantage of the security and decentralization level of the underlying blockchain, which we will elaborate on below. But the core concept here is that Layer 2 must submit some kind of proof to the underlying blockchain that the state change it initiated was valid.

first level title

Proofs are critical to Layer 2 security

"Proofs" are crucial for Layer 2, because Layer 2 needs to take advantage of the security guarantees of the underlying blockchain by submitting proofs. In the real world, proof can take many forms, such as fingerprints on weapons or surveillance video can be proof.

Encrypted proofs are similar, but the content is more objective than evidence in court. Using cryptography to prove something guarantees objectivity, verifiability, and tamper resistance. If it proves to be valid, then it can guarantee 100% authenticity. For example, in the payment channel mentioned above, attaching an encrypted signature to the transaction can provide deterministic authoritative facts for the smart contract and resolve any differences.

zero-knowledge proofzero-knowledge proofsecondary title

Payment channel signature message

Assume that when the payment channel is closed, Bob or Alice launch a malicious attack and try to take away funds that do not belong to them. Any of them can send a previous version of the payment channel "ledger" to the smart contract.

The key to payment channels is that every transaction must be accompanied by a cryptographic signature. This can provide proof to smart contracts on the underlying blockchain to resolve disagreements. For example, if Alice submits an out-of-date copy of the ledger, taking money that doesn't belong to her, then Bob can challenge the settlement transaction and submit an up-to-date copy of the ledger. The smart contract can then determine the correct amount. And Alice will be fined for dishonest behavior.

Since the underlying blockchain smart contract will be adjudicated, the payment channel is also a Layer 2 solution. A simple way to judge is to see if there is "proof". After the payment channel is created, both Bob and Alice must sign each transaction they initiate and store a copy of each other's signature.

This is the proof of the transaction in the payment channel. But proof is not enough; facts need to be enforced, much like the process by which a judge makes a verdict after being given evidence and jury deliberations. Likewise, the smart contract will execute the verdict and send the correct amount to each party's wallet on the underlying blockchain for settlement.

secondary title

False Proof of Optimistic Rollups

False proofs are actually quite simple. A Layer 2 network using this proof method will default to all transactions being valid. However, the network will set a challenge period, and any participant can initiate a challenge and submit a proof to the smart contract that the transaction data or state change is wrong. When the error proof is released, the rollup transaction will be partially or completely recalculated on the chain, and the final state change will be compared with the original result. If the recalculated result is different, the original result will be considered invalid and withdrawn.

image description

secondary title

Validity proof of zk-rollup

Validity proof is another completely different philosophical perspective. By default, all calculation results are doubtful and must be proved before they can be accepted.

image description

first level title

Blockchain Expansion Solution

Payment channels, rollups and Layer 2 are all block chain expansion solutions, all of which have long-term potential and can provideWeb3Provide assistance for application development and improve user experience.

Most Web3 technology stacks, such as Layer 1 and Layer 2, are just getting started and need to continue to evolve. These technologies have not yet reached the breaking point, and still need to go through a series of actual combat tests to prove themselves. However, countless developers and researchers are making unremitting efforts to expand the blockchain ecosystem and develop DAG and Layer 2 solutions to promote the mainstream application of Web3.