MCPcopy Index your code
hub / github.com/Consensys/gnark-crypto

github.com/Consensys/gnark-crypto @v0.20.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.20.1 ↗ · + Follow
17,827 symbols 101,592 edges 1,483 files 9,769 documented · 55% 15 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

gnark-crypto

Twitter URL License Go Report Card PkgGoDev DOI

gnark-crypto provides efficient cryptographic primitives, in Go:

  • Elliptic curve cryptography & Pairing on:
  • [bn254] (audit report)
  • [bls12-381] (audit report)
  • [bls24-317]
  • [bls12-377] / [bw6-761]
  • [bls24-315] / [bw6-633]
  • Each of these curves has a [twistededwards] sub-package with its companion curve which allow efficient elliptic curve cryptography inside zkSNARK circuits.
  • Additional elliptic curves:
  • [secp256r1] (P-256)
  • [secp256k1]
  • [grumpkin]
  • [stark-curve]
  • [field/generator] - Finite field arithmetic code generator (blazingly fast big.Int)
  • [fft] - Fast Fourier Transform
  • [fri] - FRI (multiplicative) commitment scheme
  • [fiatshamir] - Fiat-Shamir transcript builder
  • [mimc] - MiMC hash function using Miyaguchi-Preneel construction
  • [kzg] - KZG commitment scheme
  • [permutation] - Permutation proofs
  • [plookup] - Plookup proofs
  • [eddsa] - EdDSA signatures (on the companion [twistededwards] curves)

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

Warning

gnark-crypto is not fully 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.

To report a security bug, please refer to gnark Security Policy.

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

Audits

See list of audits for gnark and gnark-crypto

Getting started

Go version

gnark-crypto is tested with the last 2 major releases of Go (currently 1.25 and 1.26).

Install gnark-crypto

go get github.com/consensys/gnark-crypto

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

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 field (generated by the gnark-crypto/field package). The two main factors driving this design choice are:

  1. Performance: gnark-crypto algorithms manipulate millions (if not billions) of field elements. Interface indirection at this level, plus garbage collection indexing takes a heavy toll on perf.
  2. Need to derive (mostly) identical code for various moduli and curves, with consistent APIs. Generics introduce significant performance overhead and are not yet suited for high performance computing.

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

go generate ./...

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.

Citing

If you use gnark-crypto in your research a citation would be appreciated. Please use the following BibTeX to cite the most recent release.

@software{gnark-crypto-v0.20,
  author       = {Gautam Botrel and
                  Thomas Piellard and
                  Youssef El Housni and
                  Arya Tabaie and
                  Gus Gutoski and
                  Ivo Kubjas and
                  Yao J. Galteland},
  title        = {Consensys/gnark-crypto: v0.20.0},
  month        = mar,
  year         = 2026,
  publisher    = {Zenodo},
  version      = {v0.20.0},
  doi          = {10.5281/zenodo.5815453},
  url          = {https://doi.org/10.5281/zenodo.5815453}
}

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.

Extension points exported contracts — how you extend this code

ByteOrder (Interface)
A ByteOrder specifies how to convert byte slices into a Element [50 implementers]
ecc/bls24-317/fp/element.go
ByteOrder (Interface)
A ByteOrder specifies how to convert byte slices into a Element [50 implementers]
ecc/bw6-761/fp/element.go
ByteOrder (Interface)
A ByteOrder specifies how to convert byte slices into a Element [50 implementers]
ecc/secp256r1/fp/element.go
ByteOrder (Interface)
A ByteOrder specifies how to convert byte slices into a Element [50 implementers]
ecc/bn254/fp/element.go
ByteOrder (Interface)
A ByteOrder specifies how to convert byte slices into a Element [50 implementers]
ecc/bw6-633/fp/element.go
ByteOrder (Interface)
A ByteOrder specifies how to convert byte slices into a Element [50 implementers]
ecc/stark-curve/fp/element.go
ByteOrder (Interface)
A ByteOrder specifies how to convert byte slices into a Element [50 implementers]
ecc/secp256k1/fp/element.go
ByteOrder (Interface)
A ByteOrder specifies how to convert byte slices into a Element [50 implementers]
ecc/bls12-377/fp/element.go

Core symbols most depended-on inside this repo

Equal
called by 4543
signature/signature.go
Mul
called by 2805
ecc/bls12-377/fr/vector_amd64.go
Butterfly
called by 2798
ecc/bls12-377/fr/element_purego.go
mustElement
called by 2636
ecc/bn254/fr/poseidon2/poseidon2_constants.go
Bytes
called by 781
signature/signature.go
madd2
called by 517
ecc/bw6-761/fp/arith.go
Mul
called by 498
ecc/bn254/fp/vector_amd64.go
New
called by 497
ecc/bn254/fr/fri/fri.go

Shape

Function 9,136
Method 6,662
TypeAlias 944
Struct 857
Interface 166
FuncType 62

Languages

Go100%

Modules by API surface

ecc/bn254/multiexp_affine.go100 symbols
ecc/bls24-317/multiexp_affine.go99 symbols
ecc/bls24-315/multiexp_affine.go99 symbols
ecc/bls12-381/multiexp_affine.go99 symbols
ecc/bls12-377/multiexp_affine.go99 symbols
ecc/stark-curve/fp/element_test.go92 symbols
ecc/grumpkin/fr/element_test.go92 symbols
ecc/grumpkin/fp/element_test.go92 symbols
ecc/bw6-761/fr/element_test.go92 symbols
ecc/bw6-761/fp/element_test.go92 symbols
ecc/bw6-633/fr/element_test.go92 symbols
ecc/bw6-633/fp/element_test.go92 symbols

For agents

$ claude mcp add gnark-crypto \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact