Layer2

Layer2

Layer2技术主要目的是扩展去快乐的性能,同时保留分布式协议的去中心化优势

  • 闪电网络

    闪电网络的主要思路十分简单–将大量交易放到比特币区块链之外进行,只把关键环节放到链上进行确认。闪电网络主要通过引入智能合约的思想来完善链下的交易渠道。核心概念有两个:RSMC(Recoverable Sequence Maturity Contract) 和 HTLC (Hashed Timelock Contract)前者解决了链下>交易的确认问题,后者解决了支付通道的问题。

    • RSMC

      RSMC类似资金池机制。首先假定交易双方存在一个"微支付通道"(资金池).交易双方先预存一部分资金到"微支付通道"里,初始情况下双方的>分配方案等于预存的金额。每次发生交易,需要对交易后产生资金分配方案等于预存的金额。每次发生交易,需要对交易后产生资金分配结果共同进行确认,同时签字把旧版本分配方案作废掉,任何一方需要提现时,可以将他手里双方签署过的交易结果写到区块链网络中,从而被确认。从这个过程中可以看到,只有在提现时候才需要通过区块链。

      任何一个版本的方案都需要经过双方的签名认证才合法,任何一方在任何时候都可以提出提现,提现时需要提供一个双方都签名的资金分配方

    • HTLC

      微支付通道是通过 Hashed Timelock Contract 来确定的,这个功能就是限时转账,理解起来也很简单,通过智能合约,双方约定转账方先冻结一笔钱,并提供一个哈希值,如果在一定时间内有人能提出一个字符串,使得它哈希后的值跟已知值匹配(实际上意味着转账方授权了接收方来提现),则这笔钱转给接收方。

      推广一步,甲想转账给丙,丙先发给甲一个哈希值。甲可以先跟乙签订一个合同,如果你在一定时间内能告诉我一个暗语,我就给你多少钱。乙于是跑去跟丙签订一个合同,如果你告诉我那个暗语,我就给你多少钱。丙于是告诉乙暗语,拿到乙的钱,乙又从甲拿到钱。最终达到结果是甲转账给丙。这样甲和丙之间似乎构成了一条完整的虚拟的“支付通道”。

      HTLC 机制可以扩展到多个人的场景

    RSMC保障了两个人之间的直接交易可以在链下完成,HTLC保障了任意两人之间的转账都可以通过一条“支付”通道来完成。闪电网络整合这两种机制,就可以实现任意两个人之间的交易都在链下完成了。

  • 侧链

    侧链协议允许资产在比特币区块链和其他区块链之间互转,这一项目也来自比特币社区。侧链可以是一个独立的区块链,有自己的按需定制的账本、共识机制、交易类型、脚本和合约的支持等。

    SPV(Simplified Payment Verification)可以实现这一点.SPV能够以较小的代价判断某个支付交易是否已经被验证过,以及得到了多少算力保护(定位包含该交易的区块在区块链中的位置)。SPV客户端只需要下载所有区块的区块头,并进行简单的定位和计算工作就可以给出验证结论

    侧链协议中,用SPV来证明一个交易确实已经在区块中发生过,称为SPV证明,一个SPV证明包括两部分内容:一组区块头列表,表示工作量证明;一个特定输出(output)确实存在于某个区块中的密码学证明

  • Plasma

    侧链是独立运行的,如果侧链上出现问题,会导致侧链执行交易有误,返回给layer1的信息也是虚假的,安全性不够. plasma不是完全被托管的,它使用了欺诈证明的退出机制,当检测到plasma链上出现错误时,用户可以安全的从plasma链上退出,因此plasma拥有更高的安全性.

    plasma的安全性比较强,但是它给layer1返回的仅有交易结果,没有交易信息。而rollup则是同时返回交易结果和交易的信息,并将这些数据进行压缩后返回给layer2.

  • rollup

    Optimistic and Zero-Knowledge(ZK), dozens and dozens of transactions are recorded on the layer 2 chain, then “rolled up” into a single transaction that is then fed back to the more expensive, slower blockchain. By doing this, the cost of that one transaction is split across lots of users.

    Optimistic Rollup 靠的是欺詐證明,zk-Rollup 靠的是有效性證明)。

    • Optimistic rollups

      The first variety is called an Optimistic rollup. This is because it optimistically assumes that all the transactions contained within a rollup are valid. Optimistic rollups give everyone on the network a certain amount of time, usually a week, to contest fraudulent transactions. The benefit of the Optimistic rollup is that it’s quick; by assuming things are correct, the network doesn’t have to waste time confirming things. The drawback is that it usually takes about a week to officially withdraw your funds from popular networks like Optimism or Arbirtrum.

    • ZK-rollup

      The second kind of rollup is a Zero-Knowledge rollup, also known as a ZK-rollup. These protocols use a complex piece of cryptography called a Zero-Knowledge proof to determine that a transaction is valid using only minimal information about that transaction. It’s privacy-preserving, sleek and, most important, fast and cheap. Compared with an Optimistic rollup, which requires funds to stay on the network until the dispute resolution period has closed, ZK-rollups allow users to withdraw their funds with less of a delay.

    • https://www.coindesk.com/learn/what-are-rollups-zk-rollups-and-optimistic-rollups-explained/

    • optimistic-rollup: https://ethereum.org/en/developers/docs/scaling/optimistic-rollups/

    • zk-rollup: https://ethereum.org/en/developers/docs/scaling/zk-rollups

    • rollup: https://www.8btc.com/article/6734992

  • 分片

    • 进行中
  • 一文理清layer2和跨链方式: https://learnblockchain.cn/article/2603