# 区块链零知识证明实现大盘比

By [Zero](https://paragraph.com/@layer3.ailiaili) · 2022-06-15

---

随着zksync、zcash、zkswap等零知识证明项目的出现，越来越多的开发者、研究者把目光投入到零知识证明领域，极大的促进了这个领域的繁荣发展。据不完全统计，光零知识证明的算法已经达到两位数。本文着重介绍一些圈内比较出名的，有开源仓库的算法实现，帮助有开发需求的伙伴进行技术决策。

**首先来看零知识证明的实现协议，即不同的实现道路**。不同道路最后产生的效果均不太一样，主要体现在安全性、计算速度、计算消耗、上链消耗上。

如上图所示，横坐标代表proof size，在区块链中几乎等同于上链消耗；纵坐标代表安全性，纵坐标标注的信息为安全性的实现方式。此图有一定的误导，因为PreviousSNARKs有很多不同的算法实现，不同算法实现最后生成的proof size会是不一样的，这里是Grouth16举例。

从结果来看，STARKs是最安全的（抗量子性）、proof size最大的，PreviousSNARKs是最不安全、proof size最小的。这就涉及到一个权衡，区块链到底需要哪个级别的安全性，如果PreviousSNARKs足够安全，那么这肯定是最适合的方案。

这个问题loopring给我们交出了完美的答卷，他们基于libsnark仓库实现了L2（loopring自己）-L1的OrderBook方案，用户余额、撮合信息等均存储在L2的默克尔树上，只需把交易数据作为calldata传到L1。如此杜绝抢跑的同时，还可以给用户节省相当多的L1费用，相比0x等实现方案，优秀太多太多了。这家公司绝对是一个潜力股，纵使目前用户数堪忧，但不影响业界对他们的技术认可。

**然后再来看看PreviousSNARKs这条路下的所有算法**

Fractal：Fractal 是一种允许递归的zk-SNARK。通过对电路的预处理实现了透明设置。证明最大250KB，这笔其他构建生成的证明都要大的多。Fractal论文链接:

[将要访问​www.oschina.net/action/GoToLink?url=https%3A%2F%2Feprint.iacr.org%2F2019%2F1076](https://link.zhihu.com/?target=https%3A//www.oschina.net/action/GoToLink%3Furl%3Dhttps%253A%252F%252Feprint.iacr.org%252F2019%252F1076)

Halo：Halo支持递归证据组织，无需可信设置。与其他新的zk-SNARK构建不同，Halo的验证时间是线性的。Halo论文链接:

[将要访问​www.oschina.net/action/GoToLink?url=https%3A%2F%2Feprint.iacr.org%2F2019%2F1021](https://link.zhihu.com/?target=https%3A//www.oschina.net/action/GoToLink%3Furl%3Dhttps%253A%252F%252Feprint.iacr.org%252F2019%252F1021)

SuperSonic：SuperSonic 是Sonic的改进版，是第一个在验证时间和证明数据量方面实用化的透明zk-SNARK。SuperSonic论文链接:

[将要访问​www.oschina.net/action/GoToLink?url=https%3A%2F%2Feprint.iacr.org%2F2019%2F1229](https://link.zhihu.com/?target=https%3A//www.oschina.net/action/GoToLink%3Furl%3Dhttps%253A%252F%252Feprint.iacr.org%252F2019%252F1229)

Plonk：Plonk也是Sonic的改进，证明时间缩短5倍。Plonk论文链接:

[将要访问​www.oschina.net/action/GoToLink?url=https%3A%2F%2Feprint.iacr.org%2F2019%2F953](https://link.zhihu.com/?target=https%3A//www.oschina.net/action/GoToLink%3Furl%3Dhttps%253A%252F%252Feprint.iacr.org%252F2019%252F953)

Marlin：Marlin 是Sonic的改进版，证明时间缩短10倍，验证时间缩短4倍。Marlin论文链接:

[将要访问​www.oschina.net/action/GoToLink?url=https%3A%2F%2Feprint.iacr.org%2F2019%2F1047](https://link.zhihu.com/?target=https%3A//www.oschina.net/action/GoToLink%3Furl%3Dhttps%253A%252F%252Feprint.iacr.org%252F2019%252F1047)

Sonic：Sonic是一个早期的通用zk-SNARK协议。论文发表于2019年1月。Sonic支持通用、可升级的参考字符串。Sonic的证明大小固定，但是验证成本高。理论上可以将多个证明分批验证以获得更好的性能。下面列举的许多新的zk-SNARK都是基于Sonic。Sonic论文链接：

[将要访问​www.oschina.net/action/GoToLink?url=https%3A%2F%2Feprint.iacr.org%2F2019%2F099](https://link.zhihu.com/?target=https%3A//www.oschina.net/action/GoToLink%3Furl%3Dhttps%253A%252F%252Feprint.iacr.org%252F2019%252F099)

Groth16：Groth16是目前最快、数据量最小的zk-SNARK，被用于Zcash等。Groth16的CRS（the Common Reference String）不是通用的，其设置需要绑定到一个特定的电路。由于其速度和证明的小数据量，因此常常被新的zk-SNARK拿来比较性能。Groth16论文链接：

[将要访问​www.oschina.net/action/GoToLink?url=https%3A%2F%2Feprint.iacr.org%2F2016%2F260](https://link.zhihu.com/?target=https%3A//www.oschina.net/action/GoToLink%3Furl%3Dhttps%253A%252F%252Feprint.iacr.org%252F2016%252F260)

**最后分享一下目前零知识证明的实现开源库**

名称开发语言应用维护中github地址libsnark/ethsnarkC++zcash、loopring否[https://github.com/scipr-lab/libsnark](https://link.zhihu.com/?target=https%3A//github.com/scipr-lab/libsnark)gnarkgolang是[https://github.com/ConsenSys/gnark](https://link.zhihu.com/?target=https%3A//github.com/ConsenSys/gnark)go-snarkgolang否[https://github.com/arnaucube/go-snark](https://link.zhihu.com/?target=https%3A//github.com/arnaucube/go-snark)xJsnarkJava是[https://github.com/akosba/xjsnark](https://link.zhihu.com/?target=https%3A//github.com/akosba/xjsnark)snarkjsJavascript是[https://github.com/iden3/snarkjs](https://link.zhihu.com/?target=https%3A//github.com/iden3/snarkjs)circomJavascript是[https://github.com/iden3/circom](https://link.zhihu.com/?target=https%3A//github.com/iden3/circom)wasmsnarkJavascript是[https://github.com/iden3/wasmsnark](https://link.zhihu.com/?target=https%3A//github.com/iden3/wasmsnark)PysnarkPython否[https://github.com/Charterhouse/pysnark](https://link.zhihu.com/?target=https%3A//github.com/Charterhouse/pysnark)ZoKratesRust是[https://github.com/Zokrates/ZoKrates](https://link.zhihu.com/?target=https%3A//github.com/Zokrates/ZoKrates)bellmanRustzcash是[https://github.com/zkcrypto/bellman](https://link.zhihu.com/?target=https%3A//github.com/zkcrypto/bellman)zksnark-rsRust否[https://github.com/republicprotocol/zksnark-rs](https://link.zhihu.com/?target=https%3A//github.com/republicprotocol/zksnark-rs)

是否维护基于github一年内是否有commit。

**1、libsnark/ethsnark**

libsnark是SCIPR Lab开发的zkSNARK方案实现，开发语言为 C++，应用于zcash等多个项目。

libsnark主要包括三部分：通用证据系统、基础电路库和应用示例。

libsnark下载地址：[https://github.com/scipr-lab/libsnark](https://link.zhihu.com/?target=https%3A//github.com/scipr-lab/libsnark)

**2、ZoKrates**

ZoKrates是一个用于以太坊零知识证明应用开发的zkSNARK工具箱， 利用ZokRates提供的插件，你可以直接在Remix 中开发零知识证明应用。

ZoKrates的开发语言主要为Rust。

ZoKrates下载地址：[https://github.com/Zokrates/ZoKrates](https://link.zhihu.com/?target=https%3A//github.com/Zokrates/ZoKrates)

**3、snarkjs** snarkjs是zkSARNK方案的javascript实现库，支持原始的8points协议和 Groth协议。利用snarkjs你可以进行可信设置、生成证据并验证证据。

snarkjs使用iden3自己的circom编译器对DSL定义的电路进行编译。

snarkjs下载地址：[https://github.com/iden3/snarkjs](https://link.zhihu.com/?target=https%3A//github.com/iden3/snarkjs)

**4、circom** circom是iden3设计的zk-snark电路描述DSL，circom npm包含了 使用该DSL描述的电路的编译器。

circom下载地址：[https://github.com/iden3/circom](https://link.zhihu.com/?target=https%3A//github.com/iden3/circom)

**5、wasmsnark** wasmsnark是一个采用原生Web Assembly开发的快速的zkSnark证据生成 和验证工具，其速度可媲美libsnark，可以用于在浏览器中生成zkSnark证据并进行验证。

wasmsnark也是iden3出品，目前仅支持groth16。

wasmsnark下载地址：[https://github.com/iden3/wasmsnark](https://link.zhihu.com/?target=https%3A//github.com/iden3/wasmsnark)

**6、gnark** gnark是consenSys开发的一个zkSARNK实现，采用Go语言，使用类似GO 的DSL描述电路。目前支持groth16。

[https://github.com/ConsenSys/gnark](https://link.zhihu.com/?target=https%3A//github.com/ConsenSys/gnark)

**7、go-snark** go-snark是一个采用go语言实现的zkSNARK开发库，目前支持 Groth16协议和Pinocchio协议。

go-snark下载地址：[https://github.com/arnaucube/go-snark](https://link.zhihu.com/?target=https%3A//github.com/arnaucube/go-snark)

**8、xJsnark** xJsnark是开发zk-SNARK电路的高层框架，其目标是填补高级语言开发 与性能之间的鸿沟。xJsnark提供一组可以让开发者在较高层级编写 zk-SNARK电路的特性，同时也提供了削减所生成的电路成本的技术， 从而使采用框架开发的电路性能接近手工开发的电路性能。

xJsnark采用Java开发，包含前端用于电路设计的Jetbrains扩展和 后端的电路生成单元。

xjsnark下载地址：[https://github.com/akosba/xjsnark](https://link.zhihu.com/?target=https%3A//github.com/akosba/xjsnark)

**9、bellman** bellman是一个用于开发zk-SNARK电路的Rust库，它提供电路接口、 基础结构以及一些基本电路实现，例如布尔和数值抽象。

bellman下载地址：[https://github.com/zkcrypto/bellman](https://link.zhihu.com/?target=https%3A//github.com/zkcrypto/bellman)

**10、zksnark-rs** zksnark-rs是一个用于创建和利用零知识证据的Rust库，提供了 基础的电路描述语言，目前支持Groth16。

zksnark-rs下载地址：[https://github.com/republicprotocol/zksnark-rs](https://link.zhihu.com/?target=https%3A//github.com/republicprotocol/zksnark-rs)

**11、Pysnark** pysnark是Python开发的zk-snark方案实现，支持Pinocchio协议， 支持生成用于以太坊的智能合约用于验证零知识证据。

pysnark下载地址：[https://github.com/Charterhouse](https://link.zhihu.com/?target=https%3A//github.com/Charterhouse/pysnark)

---

*Originally published on [Zero](https://paragraph.com/@layer3.ailiaili/gNgft3uruhDhkGCg7Y1R)*
