Skip to content
Gallery
Blockchain One Pager
Share
Explore
Layer 2

icon picker
Intro to Layer 2

We have a brief intro about layers in
image.png
Layer 2
Keep Security, Decentralization
And Increase Scalability
An L2 (layer-two) is a type of scaling solution that has a separate execution layer (where code runs, i.e. EVM) that inherits the security guarantees and decentralization of the network it’s running on top of i.e., the L1, Ethereum in our case. The bridge of a true L2 is fully permissionless and decentralized so there's always a guarantee the funds are accessible once deposited by users.
image.png
On a layer one blockchain, all computation is executed on the main chain, and all data is stored there as well. Layer 2 solutions, then, can be classified by how they address the scalability of these two bottlenecks: computation and data storage. This is what's reflected in the 2-by-2 above. Let's proceed by filling in the squares of this matrix, concluding with the new Validium construction.

Plasma

At its core, the idea of Plasma is relatively straightforward. To achieve greater scalability, Plasma moves both computation and data storage off of the main blockchain and into a second layer chain. The operators of this second layer network post "state commitments" to the main chain periodically in the form of Merkle tree roots. If the operator posts an invalid state transition, a user can submit a fraud proof to a smart contract on the main chain. If fraud is shown, this contract slashes the operator's required deposit. (like SPV insurance)
While this idea is simple and elegant, the devil is (as usual) in the details. One such critical detail is data availability. Operators can be punished via fraud proofs if they post an invalid commitment to the main chain. For a user to submit a fraud proof, though, they need the data that went into that state commitment in the first place. What if the plasma operators simply refuse to publish this data? This would enable them to advance the network to invalid states without being held accountable.
Many workarounds to this problem were proposed, such as long withdrawal delays, which would enable a "mass exit" from the Plasma chain in the case of bad behavior. After years of research, though, a workable implementation of this mechanism has yet to materialize. This led to the exploration of other quadrants of our 2-by-2 matrix.
从本质来说,Plasma 的思想相对直观。为了获得更好的扩展性,Plasma 将计算和数据存储都迁移到 layer 2 进行;由 layer 2 的执行者周期性地向主链递交 Merkle 根形式的 “状态承诺” 。如果执行者递交无效的状态,用户可以向主链上的智能合约提供错误性证明(fraud proof);一旦确认执行者出现欺诈行为,则智能合约会罚没他的保证金 (参考SPV的保险机制)
虽然这个想法简单优雅,但细节实现起来却是困难重重 —— 其中一个问题就出在数据可用性( data availability )。虽然说我们可以通过错误性证明,使得提供无效承诺的执行者在主链上遭到惩罚;但用户如果想要提供错误性证明,首先得取得构造出错误承诺的错误数据。这时候问题就来了 —— 如果 plasma 的执行者拒绝在主链上公开数据,那用户能怎么办?(这会导致主网上记载的 layer-2 状态被推进到错误的状态,且无法对执行者追责)
针对这个问题, Plasma 衍生出一些相应的方案,如延长资产从 layer 2 退出的时间——当出现作恶行为,就能允许大量资产从 Plasma 链退出。但经过这些年的摸索,可行的方案还没有真正实现;这也促使二阶矩阵其他象限的方案的出现。

zkRollup

zkRollup 通过一种间接的方式解决了数据可用性问题 —— 将所有 layer 2 上的交易数据,作为参数发送到主链上的某个智能合约内;这意味任何人都能通过观察区块链上的 “calldata (数据调用)” 来获得 layer 2 的所有数据,但这同时让 zkRollup 能带来的可扩展性优势仅限于计算这一个维度上了。
Plasma 设计了错误性证明激励机制,来保证计算的正确;而 zkRollup 则是靠着在主链完成零知识证明,保证无效的状态绝不会发生。因为所有计算都被 “汇总” 到证明里,所以无需信任或是检查执行者。
另外,zkRollups 对数据存储方面也带来了一定程度上的扩展性提升。举例来说,zkRollups 可以发送压缩过的数据给智能合约,而且全节点不需要将 calldata 存储在活跃状态里面,减轻了全节点的使用负担;在 zkRollups 链上无需包含签名数据,因为零知识证明就足以证明交易的有效与否
zkRollup 强大的功能却也成为它主要的短板:这些强大的功能依托于零知识证明 —— 一种非常前沿的密码学方法。zkRollup 除了很难安全部署,大众对当前可用的零知识证明接受度也不高,所以现有的 zkRollup 技术只专注于应用在某几个特定项目,如 的去中心化 layer 2 交易所。

Optimistic Rollup

为了在 layer 2 也能使用智能合约,研究者们开始探索一种 “与 zkRollups 架构相似,但不依靠零知识证明” 的扩展方案。有个现成的方案是重新采用交互式错误性证明,也就是接下来我们要谈到的 Optimistic Rollups 。
前面我们已经聊过 Plasma 和 zkRollup,那么 Optimistic Rollup 也很好理解。Optimistic Rollups 保留 calldata ,可以在主链获得所有 layer 2 的数据;同时 Optimistic Rollup 采用错误性证明(跟 Plasma 方案一样),对提交无效状态的执行者进行惩罚。
相比于 Plasma 和 zkRollup, Optimistic Rollup 做了一些权衡,所以带来的扩展性提升幅度最小。但这也是为什么 Optimistic Rollup 如此令人感兴趣,因为 Optimistic Rollup 不依赖于什么过于前沿的技术或悬而未决的问题,实际推广中 Optimistic Rollup 更好落地。 有多个团队(比如 “Ethereum Optimism” 团队)都已接近将 Optimistic Rollup 架构部署到主网上。

Validium

Validium 选择将 layer 2 的交易数据放在链下,因而比 rollup 架构有着更高的扩展性。验证计算方面,Validium 不像 Plasma 依托诈欺证明,而是采用零知识证明。如先前在讨论 zkRollup 时提到的,这样做会导致 Validium 在目前的应用部署,只能局限于特定目的(普适性低),比如 StarkEx 就是面向去中心化交易所的方案。
但这些权衡使得 Validium 在某些方面优于 Plasma 。在主网进行零知识证明验证能避免执行者提供无效状态,也能降低执行者不公开数据造成的后果。举例来说,想要勾结执行者,让状态错误地转变为 “把他人的钱转到自己账户” 是不可能办到的;因此 Validium 不需要在协议中设计 “大量资金退出” 激励博弈,也不需要延长资金从 layer 2 退出的时间。
正如其他研究者指出的,零知识证明并不是解决数据可用性问题的万灵丹:比如(恶意)执行者修改自己所控制的账户的状态是没有问题的,然后积压关于这些交易的数据,这会导致某些用户想退出资金时,无法提供 Merkle proof
image.png
这种攻击在本质上就是冻结 layer 2 上的账户,也为执行者的受贿行为大开方便之门 —— 执行者可以拒绝提供某用户需要的状态,以此进行勒索或受贿。
为了避免此类攻击发生,StarkWare 团队使用了一种手段,我称之为 “engineering hack (工程黑客)”技术。这个术语我用得很亲切,因为我整个职业生涯中就时常与 “engineering hack ”打交道。StarkEx 系统中包含了一个 “数据可用性委员会” —— 委员负责对数据签名,并保证数据始终可用。只要其中有一位委员在线且他是诚实的,用户就一定能获得退出资金需要的数据。【去中心化了】
Validium 不是最完美的方案,但它可能是目前各种场景最能接受的一种方案,但要记住每件事情都有其权衡及折中的考量。相较于主链上完全去信任的 DEX ,StarkEx 交易所的确面临更高的第三方风险;但作为相应的优点,StarkEx 交易所在性能上高出 DEX 几个量级——高频交易者非常看重这个优点。而相较于传统的中心化交易所,Validium 仍然安全得多,也最大程度地去信任化。

image.png
OR vs. ZR 2
Property
Optimistic rollups
ZK rollups
1
Fixed gas cost per batch
~40,000 (a lightweight transaction that mainly just changes the value of the state root)
~500,000 (verification of a ZK-SNARK is quite computationally intensive)
2
Withdrawal period
~1 week (withdrawals need to be delayed to give time for someone to publish a fraud proof and cancel the withdrawal if it is fraudulent)
Very fast (just wait for the next batch)
3
Complexity of technology
Low
High (ZK-SNARKs are very new and mathematically complex technology)
4
Generalizability
Easier (general-purpose EVM rollups are already close to mainnet)
Harder (ZK-SNARK proving general-purpose EVM execution is much harder than proving simple computations, though there are efforts (eg. Cairo) working to improve on this)
5
Per-transaction on-chain gas costs
Higher
Lower (if data in a transaction is only used to verify, and not to cause state changes, then this data can be left out, whereas in an optimistic rollup it would need to be published in case it needs to be checked in a fraud proof)
6
Off-chain computation costs
Lower (though there is more need for many full nodes to redo the computation)
Higher (ZK-SNARK proving especially for general-purpose computation can be expensive, potentially many thousands of times more expensive than running the computation directly)
There are no rows in this table


Bibliography


Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.