当前位置:网站首页>Circom 2.0: A Scalable Circuit Compiler
Circom 2.0: A Scalable Circuit Compiler
2022-07-24 21:45:00 【mutourend】
1. 引言
本文主要摘自 IDEN3团队Albert Rubio在Compiler and Composability in ZKP 上的演讲内容。

2. 何为Circom?
何为Circom?==>circom
- 为编程语言和编译器
- 由Jordi Baylina创建的,针对ZK协议中电路设计的DSL语言
- 为iden3项目的一部分
- circom 2.0编译器主要由UCM大学的团队开发
- circom 2.0编译器完全开源且由Rust语言写成,提供了更快的电路编译和更好的安全性
- circom社区正在快速承载
- 社区对于circom的成功至关重要
一个circom program主要有两重目的:
- 1)提供相应电路的符号描述:在二进制文件中有一组R1CS约束。
- 2)提供一种高效的方式来根据输入计算witness:
- 将有WebAssembly(wasm)代码与JS或主流浏览器结合
- 为大型电路提供了C++代码(如ZK-Rollups for Layer 2)
circom支持开发者从底层设计arithmetic电路(类似于设计电子电路)。
在circom中,所有的约束必须由开发者明确添加。
约束可被简化,在编译时可移除signals,但是永远不会引入新的signals。
在circom,实际的电路称为components,而component是基于template实例化的,template为对电路的参数化描述,如:
如上,电路Multiplier接收2个输入,然后输出signal为二者的乘积。
circom的一个关键特征是提供了不同的指令来:
- 在symbolic层定义新的约束:
会生成约束out === in1 * in2; // symbolic level "only"in1 * in2 - out = 0。 - 在computational层计算a signal:
会生成类似out<-- in1 * in2; // computational level onlyout := in1 * in2的代码。 - 或者借助
<==操作符:
会生成 约束out <== in1 * in2; // symbolic and computational levelin1 * in2 - out = 0和 代码out := in1 * in2。
通常需要使用<==操作符,但某些时候不需要。如,定义检查input是否为0的电路,应为:
使用<--和===操作符,并不能保证电路在symbolic层和computational层的等价性,需要由开发者来负责实现相应的等价性。
可基于circomlib库等对templates进行组合来构建电路:
如上,使用变量sum来结算loop循环内的加法,引入参数n来限定input signals的数量。
构建约束时,变量是symbolic表达;而计算witness时,变量对应的是field数值。
circomlib库中包含了一些有用的电路实现,可用作primitive templates,具体有:
- Binary transformers and operations
- Comparators
- 哈希函数:mimc、pedersen、sha256
- Elliptic curves:babyjubjub(twisted Edwards),Montgomery
- Sparse Merkle Trees
充分展现了Circom语言的强大,以及如何以quadratic constraints来编码复杂计算。
3. 约束简化
描述密码学协议的arithmetic circuits生成的约束系统中可能包含数百万个约束,通常可从中移除许多约束。对约束系统的简化是下一阶段提升效率的重要工作。大多数约束系统可处理的约束数上限约为 2 17 2^{17} 217。
在不修改电路行为并保留R1CS表达的情况下,Circom支持对约束的简化。
如MultiAND()电路生成的约束系统为:
可简化其linear constraints,生成仅有2个R1CS约束的等价系统:
circom中高效实现了对linear constraint的简化:
- 编译器应用clustering并行化简化工作;
- 使用Gauss-Jordan移除 来实现linear简化;
- 迭代整个过程直到没有剩余的linear constraints;
- 可实现约80%的reduction;
- 编译过程中最expensive的部分为:
- 超大电路需要约750GB的local memory(需要swapping)。
- 可将约6.5亿个约束reduce为1.3亿个。
- 在64核512GB RAM机器上,编译用时约3小时(若使用老版本的circom,用时需要数天)。
- 包含简化后R1CS的二进制文件大小约为50GB。
- 具有1千万个约束的电路在笔记本电脑上编译(并完全简化)用时约8分钟。
以上简化技术:
- 并不会引入新的signals,
- 应可高效实现,
- 是一种新型的代码优化
- circom中的简化技术要远强于Zokrates中的
- 可独立用于由其它语言生成的R1CS约束系统 的简化
4. 小结
- circom为面向底层arithmetic电路设计的DSL
- circom既支持开发者描述如何生成电路约束,也支持开发者根据任意指定输入高效计算witness
- 在circom中,由开发者来完全控制电路定义
- circomlib库中包含了许多circuit templates,可减轻开发者工作量
- circom有一个庞大活跃的社区
- circom可与iden3 proving system结合使用,如snarkjs/wasmsnark/rapidsnark
- zkREPL,为zkSNARKs的线上开发环境,是基于circom构建的
边栏推荐
- Dtable launched in the public beta, which is not only a table, but also a business application builder
- Multiplication and addition of univariate polynomials
- [development tutorial 6] crazy shell arm function mobile phone - interruption experiment tutorial
- Class notes (4) (3) -573. Lecture hall arrangement (Hall)
- Drawing library matplotlibmatplotlib quick start
- A very useful log4net logging library
- Metauniverse: technological evolution, industrial ecology and big country game
- [combination of classes (define a class in a class)]
- The relationship between cloud computing and digital transformation has finally been clarified
- What should I do when selecting the RDS instance access method?
猜你喜欢
![[development tutorial 6] crazy shell arm function mobile phone - interruption experiment tutorial](/img/21/ef2274360e0c5cf19990ab3e46f116.png)
[development tutorial 6] crazy shell arm function mobile phone - interruption experiment tutorial

Ch single database data migration to read / write separation mode

MySQL forced indexing

Day5: three pointers describe a tree

String matching (Huawei)

Redefine analysis - release of eventbridge real-time event analysis platform

Binary search
![[image processing] pyefd.elliptic_ fourier_ How descriptors are used](/img/72/d2c825ddd95f541b37b98b2d7f6539.png)
[image processing] pyefd.elliptic_ fourier_ How descriptors are used
![[CCNA experiment sharing] routing between VLANs of layer 3 switches](/img/71/2f28c6b6b62f273fad1b3d71e648a1.jpg)
[CCNA experiment sharing] routing between VLANs of layer 3 switches

2022 Tsinghua summer school notes L2_ 1 basic composition of neural network
随机推荐
CAD sets hyperlinks to entities (WEB version)
[Development Tutorial 4] open source Bluetooth heart rate waterproof sports Bracelet - external flash reading and writing
P2404 splitting of natural numbers
What is the database account in DTS?
Es+redis+mysql, the high availability architecture design is awesome! (supreme Collection Edition)
Scientific computing toolkit SciPy data interpolation
Class notes (4) (3) -573. Lecture hall arrangement (Hall)
Image processing notes (1) image enhancement
Classical review: understanding the "knowledge consistency" of neural networks (ICLR 2020)
[crawler knowledge] better than lxml and BS4? Use of parser
Using gcc to avoid stack smash attack
[jzof] 05 replace spaces
Five common misuse of async/await
Selenium test page content download function
Multiplication and addition of univariate polynomials
90% of people don't know the most underestimated function of postman!
如何修改 Kubernetes 节点 IP 地址?
Ch single database data migration to read / write separation mode
【类的组合(在一个类中定义一个类)】
How to output position synchronization of motion control