gnark
is a fast zk-SNARK library that offers a high-level API to design circuits. The library is open source and developed under the Apache 2.0 license
gnark
issues are tracked in the GitHub issues tab.
If you have any questions, queries or comments, GitHub discussions is the place to find us.
You can also get in touch directly: [email protected]
To get started with gnark
and write your first circuit, follow these instructions.
Checkout the online playground to compile circuits and visualize constraint systems.
Refer to Proving schemes and curves for more details.
gnark
support the following zk-SNARKs:
which can be instantiated with the following curves
- BN254
- BLS12-381
- BLS12-377
- BW6-761
- BLS24-315
- BW6-633
Refer to the gnark
User Documentation
Here is what x**3 + x + 5 = y
looks like
// CubicCircuit defines a simple circuit
// x**3 + x + 5 == y
type CubicCircuit struct {
// struct tags on a variable is optional
// default uses variable name and secret visibility.
X frontend.Variable `gnark:"x"`
Y frontend.Variable `gnark:",public"`
}
// Define declares the circuit constraints
// x**3 + x + 5 == y
func (circuit *CubicCircuit) Define(api frontend.API) error {
x3 := api.Mul(circuit.X, circuit.X, circuit.X)
api.AssertIsEqual(circuit.Y, api.Add(x3, circuit.X, 5))
return nil
}
// compiles our circuit into a R1CS
var circuit CubicCircuit
ccs, err := frontend.Compile(ecc.BN254, backend.GROTH16, &circuit)
// groth16 zkSNARK: Setup
pk, vk, err := groth16.Setup(ccs)
// witness definition
assignment := CubicCircuit{X: 3, Y: 35}
witness, err := frontend.NewWitness(&assignment, ecc.BN254)
publicWitness, _ := witness.Public()
// groth16: Prove & Verify
proof, err := groth16.Prove(ccs, pk, witness)
err := groth16.Verify(proof, vk, publicWitness)
If you use gnark
in your research a citation would be appreciated.
Please use the following BibTeX to cite the most recent release.
@software{gnark-v0.6.4,
author = {Gautam Botrel and
Thomas Piellard and
Youssef El Housni and
Ivo Kubjas and
Arya Tabaie},
title = {ConsenSys/gnark: v0.6.4},
month = feb,
year = 2022,
publisher = {Zenodo},
version = {v0.6.4},
doi = {10.5281/zenodo.6093969},
url = {https://doi.org/10.5281/zenodo.6093969}
}
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
We use SemVer for versioning. For the versions available, see the tags on this repository.
This project is licensed under the Apache 2 License - see the LICENSE file for details