/gnark-crypto

gnark-crypto provides elliptic curve cryptography (+pairing) on BN254, BLS12-381, BLS12-377, BW6-761. Also various algorithms (algebra, crypto) of particular interest for zero knowledge proof systems.

Primary LanguageAssemblyApache License 2.0Apache-2.0

gnark-crypto

License Go Report Card PkgGoDev

gnark-crypto provides:

gnark-crypto is actively developed and maintained by the team (zkteam@consensys.net | HackMD) behind:

Warning

gnark-crypto has not been audited and is provided as-is, use at your own risk. In particular, gnark-crypto makes no security guarantees such as constant time implementation or side-channel attack resistance.

gnark-crypto packages are optimized for 64bits architectures (x86 amd64) and tested on Unix (Linux / macOS).

Getting started

Go version

gnark-crypto is tested with the last 2 major releases of Go (1.15 and 1.16).

Install gnark-crypto

go get github.com/consensys/gnark-crypto

Note if that if you use go modules, in go.mod the module path is case sensitive (use consensys and not ConsenSys).

Documentation

PkgGoDev

The APIs are consistent accross the curves. For example, here is bn254 godoc.

Development

Most (but not all) of the code is generated from the templates in internal/generator.

The generated code contains little to no interfaces and is strongly typed with a base field (generated by the gnark-crypto/field). The two main factors driving this design choice are:

  1. Performance: gnark-crypto algorithms manipulates millions (if not billions) of field elements. Interface indirection at this level, plus garbage collection indexing takes a heavy toll on perf.
  2. No generics in Go: need to derive (mostly) identical code for various moduli and curves, with consistent APIs

To regenerate the files, see internal/generator/main.go. Run:

go generate ./internal/...

Benchmarks

Benchmarking pairing-friendly elliptic curves libraries

The libraries are implemented in different languages and some use more assembly code than others. Besides the different algorithmic and software optimizations used across, it should be noted also that some libraries target constant-time implementation for some operations making it de facto slower. However, it can be clear that consensys/gnark-crypto is one of the fastest pairing-friendly elliptic curve libraries to be used in zkp projects with different curves.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

License

This project is licensed under the Apache 2 License - see the LICENSE file for details