gnark-crypto

repository·master·Indexed 20 days ago

https://github.com/consensys/gnark-crypto

A high-performance Go library providing cryptographic primitives optimized for zero-knowledge proof (ZKP) applications. It includes finite field arithmetic, Fast Fourier Transform (FFT), and support for various elliptic curves and pairings such as BN254, BLS12-381, BLS12-377, BW6-761, and SECP256K1. The library also provides implementations for the KZG commitment scheme, MiMC hash function, and Twisted Edwards curves for efficient zkSNARK circuits.

Tokens
710
Snippets
2
Records
6
Agent score
20%

What's inside gnark-crypto

  1. Overview of `gnark-crypto` primitives

    master

    gnark-crypto provides high-performance cryptographic primitives in Go, optimized for 64-bit architectures (x86 amd64) and tested on Unix (Linux/macOS).

    Key features include:

    • Elliptic Curve Cryptography & Pairing: Supports bn254, bls12-381, bls24-317, bls12-377, bw6-761, bls24-315, and bw6-633. Each curve includes a twistededwards sub-package for efficient ECC inside zkSNARK circuits.
    • Additional Curves: secp256r1 (P-256), secp256k1, grumpkin, and stark-curve.
    • Arithmetic & Transforms: field/generator for finite field arithmetic, and fft (Fast Fourier Transform).
    • Protocols & Schemes: fiatshamir (transcript builder), mimc (hash function), kzg (commitment scheme), permutation (permutation proofs), and eddsa (signatures on companion twisted Edwards curves).
  2. View supported elliptic curves in gnark-crypto

    master

    gnark-crypto provides implementations for a wide variety of elliptic curves used in zero-knowledge proofs and blockchain protocols. Supported curves include:

    • BLS12-381 (used by Zcash, Ethereum)
    • BN254 (used by Ethereum)
    • GRUMPKIN (2-cycle with BN254)
    • BLS12-377 (used by ZEXE, Linea)
    • BW6-761 (2-chain with BLS12-377, Linea)
    • BLS24-315 (KZG-oriented curve)
    • BW6-633 (2-chain with BLS24-315)
    • BLS24-317 (KZG-oriented curve)
    • STARK (STARK curve for ECDSA)
    • SECP256K1 (used by Bitcoin, Ethereum)
    • SECP256R1 (NIST)
  3. Use Twisted Edwards curves for efficient zkSNARK circuits

    master

    For efficient elliptic curve cryptography inside zkSNARK circuits, gnark-crypto provides Twisted Edwards curves as companions to specific pairing-friendly curves. These are accessible via a twistededwards sub-package.

    Key pairings include:

    • Jubjub: The companion curve for BLS12-381.
    • Baby-Jubjub: The companion curve for BN254.
  4. Regenerate code using `go generate`

    master

    Much of the code in gnark-crypto is generated from templates located in internal/generator. The generated code is strongly typed and avoids interfaces to maximize performance and minimize garbage collection overhead during high-volume field element manipulation.

    To regenerate the files, run the following command from the repository root:

    go generate ./...
  5. Install `gnark-crypto`

    master

    To use gnark-crypto in your Go project, install it using go get.

    Important: If you are using Go modules, the module path is case-sensitive. Ensure you use github.com/consensys/gnark-crypto (lowercase consensys).

    go get github.com/consensys/gnark-crypto