current position:Home>Web3 series of advanced tutorials---1. Layer 2

Web3 series of advanced tutorials---1. Layer 2

2022-08-05 14:48:54Li Liubai

Layer 1 vs Layer 2

Layer 1

第1层区块链(Also known as parent chain or root chain)Usually a name used to describe a major blockchain network protocol,如以太坊或比特币.第1Layer blockchain is only the first2The main network on which the layer scaling solution is attached,to improve the main chain or the first1Layer Scalability and Transaction Throughput.第1The layer's name comes from its connection to the2Layer scaling solution relationship,as status channel、rollups和plasma侧链,All of these we will cover in detail.

把第1Layers are seen as the standard blockchain technology we have been working on so far,而第2Layers are extensions built on top of that blockchain,以增加功能.

Layer 2

Layer 2 refers to secondary frameworks or protocols built on top of existing blockchain systems.Major cryptocurrency networks like Ethereum face difficulties with transaction speed and scaling.Bitcoin and Ethereum still can't handle thousands of transactions per second.And these second layer solutions usually offer better transaction fees.

Layer 2 protocols are specifically designed to integrate with the underlying blockchain,以提高交易吞吐量.They rely on the consensus mechanism and security of the main chain.第2Layer operations can often be independent of the1层进行.This is why these are sometimes called "链外 "解决方案.Although the main chain/第1Layers can provide the inherent security of the blockchain,但第2Layers can provide speed.

由于第2Layer transactions happen on different chains,So a connection is opened periodically,Move these transactions to the main blockchain.This connection is sometimes called a bridge,或通道.因此,第2A major consideration for layer solutions is how transactions are verified and confirmed before being transferred to the main chain.

Layer 2扩展解决方案

There are now many second-tier or scaling solutions under development.We will do extensive research on them.

有两个主要的维度,The scaling solutions for the second layer are different from each other.The first is transaction execution,The second is data availability.

Trade execution strategies deal with how trades work、在哪里运行、What is the trust environment、What is safe and decentralized environment etc..

Data Availability Policy Handling Section 2 Does the layer solution make its transaction data 1 Layer available on the main chain.

We will look into the following categories:

  1. 状态通道

  2. 侧链

  3. Rollups

    • Optimistic Rollups (ORs)

    • Zero-Knowledge Rollups (ZKRs)

    • ZKR vs OR

  4. Plasma

  5. Validiums

  6. Volitions

状态通道

State channels are the first broad scaling method for blockchains.When two or more users want to perform a large number of transactions in a trusted environment without paying for gas every time,will use the state channel.

一个简单的例子,It's a tic-tac-toe game with bets on the blockchain.

假设Alice和Bob想投入10个ETHcome play tic tac toe.另外,假设Alice和Bob互相信任.We can design a smart contract,Let every move be recorded on the blockchain,在游戏结束时,Alice或Bobwill receive their profits.but it will be an expensive game,Because every move costs moneyAlice或Bob的汽油费.This can be solved with state channels.

We did not design a smart contract to support every move of tic-tac-toe,Instead, a smart contract was designed,Allows opening and closing a status channel.一旦打开,The state channel will have the default start state of the game,Alice和BobActions can be performed on it without paying for gas,Because the open state channel will be off-chain.Every move will not be written to the main chain.当通道关闭时,The end state of the game is written into the main chain,Process the winnings of the game at the same time.所以,Not writing every move on the blockchain,Instead, only write the start and end of the game to the blockchain,To save a lot of transaction costs.Tic tac toe may not have a large amount of action,But imagine a game of chess or Go,You'll know how much you can save.

in relation to currency/In the application of cryptocurrency transfer,Sometimes these are called payment channels.

对于支付,Another example of a good use of state channels is getting music royalties.例如,Suppose an artist wishes to receive their songs monthly on a music service(如Spotify)Pay for being listened to.The artist hopes to obtainETH支付,But they don't really want to do the work.A company can provide such a service for the artist.If the artist received every song he listened toETHtransfer to their wallet,Transfer fees will far exceed the profits of listening to songs.Using state channels,Companies can open a channel at the beginning of the month,Collect royalties for the month on behalf of the artist,Then close the channel at the end of the month,all royaltiesETHsend them all at once,Only pay the transfer fee once a month.This saves on transfer fees,又保证了安全.

State channels still use the blockchain approach,such as making every state change cryptographically secure.

In addition to increasing speed and reducing costs,There are other benefits of state channels.Since the start and end of the game are written into the main chain,but the intermediate state does not,So you can have more privacy.The state channel is just Alice 和 Bob 之间,But since each step is not published on the blockchain,So every step is private.

This approach is not without its challenges.A useful core assumption of state channels is that state channel participants trust each other to execute these transactions off-chain.Since the channel is to be opened,Alice 和 Bob must invest 10 ETH.The money is locked in a smart contract,until the state channel is closed.但是,如果Alice Offline on the move,Bobwill never get his money back.因此,如果 Bob 不信任 Alice,State channels are not the best approach,Because any party can lock the smart contract.

ethereum.org status channel on

侧链

Sidechain is an independent EVM 兼容的区块链,It runs in parallel with the main blockchain,and has access to the 1 层的通道.Sidechains have their own validators and consensus methods for adding blocks.sidechain fast、Accumulate deals cheaply,and aggregate it to the main chain through bridges or channels.

Since the sidechain is based on EVM,You can think of them as mini Ethereum blockchains.side chains have EVM 的所有优点,like writing reliable smart contracts,并使用 web3 API 与链交互.

The disadvantage of sidechains is that they can be more centralized.例如,If their consensus protocol uses less secure or less decentralized methods,In order to have a higher transaction throughput,and these nodes conspire to commit fraud.

需要注意的是,Unlike other solutions below,Sidechains are not technically the first2层,Because they do not use the security of the main chain,but often called.

ethereum.org side chain on

Rollups

Rollups is the solution for executing transactions on the second layer,but publish transaction data to the first layer in bundles or summaries.可以把rollups 看作是一种 "压缩和合并 "的操作.By moving computation off-chain,They free up more on-chain space.On-chain data availability is critical,Because it allows Ethereum to double checkrollups交易的完整性.与状态通道不同,rollups Transaction data published on the main chain can be verified as correct or incorrect,而且rollups The execution does not need to take place in a trusted environment.

Rollups的工作方式是在第1层部署一组智能合约,负责存款、Withdrawal and verification proof.Proofs are of a different typerollups的主要区别.一般来说,有两种rollups:Optimistic Rollups 和 Zero-Knowledge Rollups.

Optimistic Rollups

在Optimistic Rollups中,Transaction data batches are sent to the main chain,and is considered valid by default(Hence the name optimistic) ,But it may be questioned by other users.

理论上,Anyone can submit a claim by(Also known as fraud proof)to challenge them,To prove that a batch submitted to the chain contains invalid state transitions.If the fraud proof is valid,These invalid state transitions will be rolled back.If no one questions the deal,It will be committed to the main chain.To give users enough time to challenge the transaction,There is a long wait time from when a transaction is published until it is committed to the main chain,通常是几天,but maybe a week.在这段时间内,You cannot withdraw your funds to the main chain.

需要注意的是,when the challenge happens,The main chain can always verify the authenticity of transactions in potential blocks.But these validations need to work,therefore cost.

How to stop bad actors from sending bad transactions to aggregating networks or spamming networks with fraud proof verification?if questioned,第 1 Where the funds used by the layer to verify transactions come from?为了回答这个问题,We introduce the field of 3 位参与者:

  1. asserter- The proposer tries to publish the transaction proof on the main chain,thus asserting its validity
  2. challenger- Attempting to justify issuing a proofasserteris a fraudulent challenger
  3. verifier- Smart contracts on the main chain,Used to verify proofs and check their validity

asserterA deposit is required to propose a block of transactions,usually someETH的形式.challengerA security deposit is also required(通常是ETH)来进行挑战.verifierTransactions on the main chain will be verified.

如果asserterfound to be fraudulent,they will lose some margin.verifierGet part of the Assertor bond for handling validation,并获得challengerAnother part of the assertion of margin as a reward found fraud.

如果asserterfound not deceived,则challengerlose some margin.verifierHandling validation as before earns some challenger's deposit,This time they willasserterGet some challenger's bond as a reward for detecting fraud.

ZK Rollups

ZK 代表“零知识”,它是一种方法,一方(证明者)可以向另一方(验证者)Prove that the given statement is true,while the prover avoids conveying any additional information,Except for the fact that the statement is true.更多关于零知识证明.

in this roundup,No individual to verify.相反,Everyone who proposes to add a new set of aggregated transactions to the main chain builds a zero-knowledge proof for it.This can be automatically verified by the smart contract that controls the addition of transactions to the main chain.因此,与 Optimistic Rollups 相比,ZK Rollups 没有challenger作用,Every proof published on the main chain is verified at the time of publication.

特别是,The proposer constructed some kind of zero-knowledge proof,称为zk-SNARK,This is a non-interactive zero-knowledge proof,This means that the proof requires no interaction between the prover and the verifier.

要更深入地了解 zk-SNARKS,请参阅 David Wong 的系列文章,zk-SNARKS 的解释

ZK vs Optimistic

乍一看,ZK rollups seems to be better in every wayOptimistic Rollups更好.毕竟,Transactions can be automatically verified,no challenger required,Assertors prove their transactions before committing.此外,他们支付 gas to handle proofs in smart contracts,So it will only fail if an invalid proof is submitted.

那么,为什么要进行Optimistic Rollups呢?

ZK rollups 的问题在于,从数学上讲,It is difficult to construct these proofs.Each use case requires research time to find a matching cryptographic proof,This can take a long time to find.

此外,Zero-knowledge proofs are often complicated,Therefore, the verification cost is high.Smart contracts contain more operations,运行成本就越高.此外,The space for smart contracts is also limited,So the proof must be run in less than a certain number of operations.

Plasma

Plasmais an extensible2tier application framework.PlasmaUsed many of the above ideas in its application.PlasmaThe artifact is executed off-chain,状态承诺,以及进入/Exit the main chain.Plasmachain is an independent,Be anchored in the etheric lane on the main chain block chain.PlasmaChain uses various fraud proofs to arbitrate disputes,就像optimistic rollups一样.like sidechains,PlasmaThe chain has its own consensus algorithm,and create transaction block.In a fixed time interval,A compressed representation of each block is committed to an Ethereum smart contract.MerkleTrees make it possible to create infinite stacks of these chains,These chains can work hard from the parent chain(包括Mainnet)offload bandwidth.PlasmaThe chain does as much work as possible off-chain.PlasmaThe implementation enables hundreds of sidechain transactions to be processed offline,Only a hash of the sidechain block is added to the Ethereum blockchain.

Plasma The chain only interacts with the main chain,to submit its status,or facilitate entry and exit.由于大多数Plasma implementation is a completely different blockchain,It must facilitate entry and exit from the main chain,This is a smart contracts to promote.实际上,Plasma A big disadvantage of the web is that,It is difficult to extract assets from it to the main chain.Withdrawals will be delayed for a few days,以允许挑战,就像optimistic rollups.对于可替换的资产,This can be mitigated by liquidity providers,But there is an associated capital cost.这是因为Plasma The assets on the network and the main chain of assets are not identical.例如,你在Plasma does not holdETH,you usually holdwETH(wrapped ETH),它与ETH的价值是1:1.

Plasma The implementation also relies on validators to observe the network and ensure security.when funds are withdrawn,There is also a waiting period,以允许挑战.same as sidechain,Plasma The benefits are higher throughput and lower cost per transaction.This is great for transactions between two users.然而,Plasma The disadvantage is that it does not support as complex calculations as the main chain allows,Although many solutions are working to solve this problem.

要使用Plasma,You can integrate several already implementedPlasma的项目之一,例如Polygon,它的正式名称是Matic.

To delve into plasma,请查看Plasma白皮书.

关于plasmaSome other useful documents: Learn PlasmaPlasma Docs on ethereum.org.

数据可用性

到目前为止,We have been discussing the different approaches to trade execution taken by various scaling solutions,and the trust and security environment in which these transactions run.

然而,Another dimension of the second layer with different tradeoffs is the availability of data.在主链上,We are used to publishing all data publicly on the blockchain.然而,This comes with significant privacy concerns.

例如,If a professional trading firm is in DEX conduct large-scale financial transactions on,They may not want their trading strategies to be made public,Otherwise it won't do them any good.

第2Layer solutions fall into one of these data availability cases.

注意: 在这个上下文中,On-chain and off-chain refer specifically to the main layer1链.On-chain means that data is available on the first layer of the main chain,and off-chain means it's not available on the first layer of the main chain,Although it may be in the second layer chain.

两种rollup Technology is to store data by issuing verifiable proofs on the main chain,但ZKRUsing a proof of validity that was verified at the time of publication,而ORrely on challengers to catch fraudulent proofs.

另一方面,PlasmaThe chain stores most of its data outside the main chain,The main chain usually only needs to be touched in the event of a dispute.充其量,They will publish the snapshot to the main chain,without proof.因此,if you trustPlasma链,then only snapshots will help.与OR类似,Snapshots are considered valid by default,unless someone disputes.

现在我们来看看 Validiums 和Volitions.

Validium 链

In addition to data stored in the main chain,Validium 的工作原理与 ZK Aggregation is very similar.Since transaction data is not published on the main chain,This introduces a new trust assumption,Because the user has to trust the operator,to make data available when needed.This is usually accomplished through a committee of known entities,These entities bet their business reputations on being reliable data providers.如果 L2Node operator stops serving withdrawal requests,The committee will make a copy of its data public.

需要注意的是,Validium is a data availability situation,It itself doesn't care how the transaction is executed.通常,您可以使用基于 ZKR transactions executed Valdium 方法.

Volition 链

Volitionchains are those fromRollups和ValidiumBorn in the Data Availability Approach.从本质上讲,They allow a hybrid data availability scenario,Users can decide what they want on the main chain,And they don't want to be in the main chain.

例如,A large trading firm may not want every one of its transactions to be public on the main chain,But over the weekend required to publish proofs on the main chain to inherit its security benefits.因此,They can store the data of each transaction off-chain,But store the whole week's profit and loss and balance changes on-chain.

同样,与Validiums类似,This is just a case of data availability,Does not involve how the transaction is executed.通常情况下,你可以使用ZKR的Volition方法.

第2layer example

Immutable X

Immutable X 是以太坊上的NFTs的第二层扩展解决方案.It allows developers to build marketplaces、游戏、应用程序等.以太坊每秒只能处理约15笔交易,and suffer from high gas bills,而像Immutable X这样的第2Layer solution can process per second9000笔交易,and no gas charges.It leverages the well-established security of Ethereum、Connectivity and ecosystem to help developers.

Polygon (formerly Matic)

Polygon是一个基于plasma,兼容EVM的第二层扩展解决方案,Proof of Stake、侧链等.It is one of the most popular Ethereum Layer 2 solutions out there.A brief introduction to it,你应该阅读《 New to Polygon?》和《Polygon Architecture.》.

in a future module,we will use morePolygon的实际例子.

Arbitrum

Arbitrum是一个optimistic rollup解决方案,For general smart contracts on Ethereum.它与EVM兼容,Developers can easily convert their existingSolidity代码移植到Arbitrum.

Optimism

Optimism 也是EthereumOne of the general smart contracts onoptimistic rollup解决方案.它也与EVM兼容,Developers can convert their existingSolidity代码移植到Optimism.

Arbitrum和Optimismdiffers in some low-level trivial technical details,但从表面上看,They all operate in the same category.

zkSync

zkSyncis for EthereumZK-Rollup解决方案.由于通用的ZK-Rollups非常困难,目前zkSync支持ETH和ERC20代币转移,NFTs,Atomic swaps and order book basedDEX的.

以及更多...

This is not an exhaustive list,There are also many second-tier solutions out there competing for attention and market share,There are different technical details on the low-level implementation.if you look online,You may be able to find hundreds of.

推荐关注

Ethereum Layer 2 Scaling Explained

Rollups Explained

Overview of different Scaling Solutions

ETH 网络升级与Layer 2

as we get closerETH网络升级(以前被称为Eth2),一个常见的问题是 "第2Does the layering still make sense??"

简单来说,是的.

Long answer requires us to look atETHWhat did the upgrade bring,and why it2Layers are beneficial.

目前,ETH作为一个单一的、分布式的 "世界计算机 "运行.All transactions are executed serially,and have a single shared state,In all the etheric lane maintenance between nodes.This has its advantages,但缺点是,When many users want to trade in parallel,Gas bills will skyrocket,This can make the transaction very expensive.最近,对Ethereum dAppsdemand has resulted in relatively high gas bills.You can argue all day about the benefits of security and decentralization,而不是成本,But for an ordinary newbie,It's still expensive to use.

第二层解决方案,如rollups,Through the outside of the main chain trade execution to help reduce the cost.相反,They do calculations at the second layer,The cryptographic proof is then published on the main chain,任何人都可以验证.Since anyone can check whether the issued certificate is valid,They can rest assured knowing whether the transaction was executed correctly or incorrectly.由于这一特性,rollupsInherited the security advantages of the main chain,without the need to pay gas fees for computation and execution on the main chain.

随着ETH的升级,ETHFocus on implementing data sharding.从本质上讲,This means that a single state of the network will be decomposed into smaller datasets,称为分片,Its purpose is to reduce storage costs by making storage more accessible to the network.这样做的结果是,When aggregated, the proof goes back to the main chain,it will be cheaper.

目前,rollup The cost of gas on-chain is limited by the cost of gas stored on the main chain.即使第2Layer computation is very cheap,But posting the proof to the main chain still requires paying gas on Ethereum to store the proof.If Ethereum's storage cost falls,那么使用rollup The cost of the chain will also drop,Because the proof can be released at a cheaper price.This will motivate more people to use the second layer chain,Direct demand for Ethereum data storage will drop,This will further reduce the storage cost of Ethereum,甚至更多,等等.

因此,ETH Upgrades will actually help secure second-tier solutions gain adoption,and become cheaper to use.

原文: https://www.learnweb3.io/tracks/junior/layer-2s

copyright notice
author[Li Liubai],Please bring the original link to reprint, thank you.
https://en.netfreeman.com/2022/217/202208051426466918.html

Random recommended