This is the library of templates of circom
, a circuit compiler for zero-knowledge circuits.
Circom
is a circuit programming language and a compiler that allows programmers to design and create their own arithmetic circuits for zero-knowledge proofs. The aim of the circom
language is two-folded. On the one hand, it allows to describe arithmetic circuits by means of quadratic constraints. On the other hand, it allows to describe how to efficiently compute the output and intermediate signals from a given set of inputs.
Essentially, a circom circuit consists of a set of wires that carry values from the field F_p
and connect them to addition and multiplication gates modulo p
. It is important to keep in mind that:
- The
circom
language is parametric to a certain prime numberp
(which can be changed without affecting the rest of the language usingGLOBAL_FIELD_P
). - All the elements of circom circuits operate
modulo
this primep
. - Any number greater than
p
will overflow.
By default,
p = 21888242871839275222246405745257275088548364400416034343698204186575808495617
With circom
, it is possible to create large circuits by combining smaller circuits called templates
. This repository is an open source library of circom
templates that contains hundreds of circuits such as comparators, hash functions, digital signatures, binary and decimal convertors and many more. You can also create your custom templates, but before start coding, we recommend you to take a look at the circom documentation website: https://docs.circom.io.
The circuits
folder contains several circom circuit templates to perform different kinds of operations. From more basic ones, like comparing two numbers or doing binary arithmetic, to more complex functions, such as elliptic curve operations, validating digital signatures or hashing.
The documentation about some of the more complicated circuits is in the doc
folder. It contains some Markdown files and some circuit schemes in ASCII. The latter must be opened with Monodraw, an ASCII art editor for Mac.
The src
folder has utils written in JavaScript for deploying contracts. These files are required to perform some of the some tests.
circuits
basics
crypto
baby_jubjub
baby_edwards_add
baby_edwards_bits2point
baby_edwards_bits2point_strict
baby_edwards_check
baby_edwards_dbl
baby_edwards_pbk
baby_edwards_point2bits
baby_edwards_point2bits_strict
baby_edwards_scalar_mul
baby_edwards_scalar_mul_any
baby_edwards_scalar_mul_fix
baby_edwards2montgomery
baby_montgomery_add
baby_montgomery_dbl
baby_montgomery2edwards
hash_functions
signatures
smt
doc
src
Anyone is welcome to contribute with code, tests, documentation, bugs spotting or any small fix! If you would like to contribute, check out first if there is already any open issue related to your contribution and if not, please open a new issue or submit a pull request.
Thank you for your help!
This repository is still under development and not ready for production.
This repository is part of the iden3 project. All files are copyrighted under 2018 0KIMS association and published with GPL-3 license. Please check the LICENSE
file for more details.