gnark

package module
v0.15.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 13, 2026 License: Apache-2.0 Imports: 2 Imported by: 17

README

gnark zk-SNARK library

Twitter URL License Go Report Card PkgGoDev Documentation Status DOI

High-performance zk-SNARKs in Go.

gnark provides a high-level API to define circuits, then compile, prove, and verify with production-grade proving systems. It is open-source under Apache 2.0 and uses gnark-crypto for field arithmetic and cryptographic primitives.

gnark powers Linea zk-rollup. Include your project in known users by opening a PR.

Why gnark

  • Circuit development in idiomatic Go
  • Fast proving and verification backends
  • Reusable standard gadgets in std/
  • Active security and regression testing culture

Quick Start

Requirements
  • Go 1.25+ (module target: go 1.25.7)
Install
go get github.com/consensys/gnark@latest
Run an example
go run ./examples/cubic

To design your first circuit, follow the tutorial in gnark User Documentation.

Supported Proving Systems and Curves

gnark currently supports:

  • Groth16
  • PLONK

on the following curves:

  • BN254
  • BLS12-381
  • BLS12-377
  • BW6-761

Notes:

  • Solidity verifier export support is curve-dependent (BN254 is the primary target).
  • Serialized formats are not guaranteed to be stable across versions.

GPU Acceleration (Experimental)

gnark includes experimental GPU acceleration through Ingonyama's ICICLE backend for Groth16 on:

  • BN254
  • BLS12-377
  • BLS12-381
  • BW6-761

See accelerated backend documentation and the ICICLE repository.

Example Circuit

The circuit below encodes x**3 + x + 5 == y.

package main

import (
	"github.com/consensys/gnark-crypto/ecc"
	"github.com/consensys/gnark/backend/groth16"
	"github.com/consensys/gnark/frontend"
	"github.com/consensys/gnark/frontend/cs/r1cs"
)

// CubicCircuit defines a simple circuit.
// x**3 + x + 5 == y
type CubicCircuit struct {
	X frontend.Variable `gnark:"x"`
	Y frontend.Variable `gnark:",public"`
}

// Define declares the circuit constraints.
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
}

func main() {
	var circuit CubicCircuit
	ccs, _ := frontend.Compile(ecc.BN254.ScalarField(), r1cs.NewBuilder, &circuit)

	pk, vk, _ := groth16.Setup(ccs)

	assignment := CubicCircuit{X: 3, Y: 35}
	witness, _ := frontend.NewWitness(&assignment, ecc.BN254.ScalarField())
	publicWitness, _ := witness.Public()

	proof, _ := groth16.Prove(ccs, pk, witness)
	_ = groth16.Verify(proof, vk, publicWitness)
}

Security

gnark and gnark-crypto have been extensively audited, but are provided as-is with no guarantees or warranties. In particular, gnark does not guarantee constant-time implementations or side-channel resistance.

Report vulnerabilities via Security Policy. Do not open public issues for security reports.

Published advisories are listed here.

Testing

CI runs formatting, generated-file, lint, and test checks on pull requests and pushes.

Common local commands:

go test -short ./...
go test -tags=release_checks,solccheck .
go test -tags=prover_checks ./test/... ./examples/...
go test -run=NONE -fuzz=FuzzIntcomp -fuzztime=30s ./internal/backend/ioutils
go generate ./...

Audits

Release Notes

See CHANGELOG.md.

Citing

If you use gnark in research, please cite the latest release:

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

Contributing

See CONTRIBUTING.md and CODE_OF_CONDUCT.md.

Versioning

gnark follows SemVer. Available versions are in tags.

License

Licensed under Apache 2.0 (see LICENSE).

Documentation

Overview

Package gnark provides fast Zero Knowledge Proofs (ZKP) systems and a high level APIs to design ZKP circuits.

gnark supports the following ZKP schemes:

  • Groth16
  • PLONK

gnark supports the following curves:

  • BN254
  • BLS12_377
  • BLS12_381
  • BW6_761

User documentation https://docs.gnark.consensys.net

Index

Constants

This section is empty.

Variables

View Source
var Version = semver.MustParse("0.15.0")

Functions

func Curves

func Curves() []ecc.ID

Curves return the curves supported by gnark

Types

This section is empty.

Directories

Path Synopsis
Package backend implements Zero Knowledge Proof systems: it consumes circuit compiled with gnark/frontend.
Package backend implements Zero Knowledge Proof systems: it consumes circuit compiled with gnark/frontend.
accelerated/icicle
Package icicle implements backends using ICICLE library.
Package icicle implements backends using ICICLE library.
accelerated/icicle/groth16
Package groth16 implements Groth16 proof system with ICICLE acceleration.
Package groth16 implements Groth16 proof system with ICICLE acceleration.
accelerated/icicle/groth16/bls12-377
Package bls12377 implements ICICLE acceleration for BLS12-377 Groth16 backend.
Package bls12377 implements ICICLE acceleration for BLS12-377 Groth16 backend.
accelerated/icicle/groth16/bls12-381
Package bls12381 implements ICICLE acceleration for BLS12-381 Groth16 backend.
Package bls12381 implements ICICLE acceleration for BLS12-381 Groth16 backend.
accelerated/icicle/groth16/bn254
Package bn254 implements ICICLE acceleration for BN254 Groth16 backend.
Package bn254 implements ICICLE acceleration for BN254 Groth16 backend.
accelerated/icicle/groth16/bw6-761
Package bw6761 implements ICICLE acceleration for BW6-761 Groth16 backend.
Package bw6761 implements ICICLE acceleration for BW6-761 Groth16 backend.
groth16
Package groth16 implements Groth16 Zero Knowledge Proof system (aka zkSNARK).
Package groth16 implements Groth16 Zero Knowledge Proof system (aka zkSNARK).
plonk
Package plonk implements PLONK Zero Knowledge Proof system.
Package plonk implements PLONK Zero Knowledge Proof system.
witness
Package witness provides serialization helpers to encode a witness into a []byte.
Package witness provides serialization helpers to encode a witness into a []byte.
Package constraint provides constructs needed to build and use a constraint system.
Package constraint provides constructs needed to build and use a constraint system.
solver/gkrgates
Package gkrgates contains the registry of GKR gates.
Package gkrgates contains the registry of GKR gates.
Package examples provides various example circuits.
Package examples provides various example circuits.
accelerated_gpu
Package accelerated_gpu provides examples on how to use gnark with GPU acceleration.
Package accelerated_gpu provides examples on how to use gnark with GPU acceleration.
inputpacking
Package inputpacking illustrates input packing for reducing public input.
Package inputpacking illustrates input packing for reducing public input.
plonk command
print_constraints
Package print_constraints demonstrates how to print constraints from a compiled constraint system.
Package print_constraints demonstrates how to print constraints from a compiled constraint system.
pubkeyhashing
Package pubkeyhashing implements a simple example of ECDSA public key hashing using SHA2.
Package pubkeyhashing implements a simple example of ECDSA public key hashing using SHA2.
serialization command
sudoku
Package sudoku implements a Sudoku circuit using gnark.
Package sudoku implements a Sudoku circuit using gnark.
witness
Package witness provides an example of witness export as vector.
Package witness provides an example of witness export as vector.
cs
schema/internal/reflectwalk
reflectwalk is a package that allows you to "walk" complex structures similar to how you may "walk" a filesystem: visiting every element one by one and calling callback functions allowing you to handle and manipulate those elements.
reflectwalk is a package that allows you to "walk" complex structures similar to how you may "walk" a filesystem: visiting every element one by one and calling callback functions allowing you to handle and manipulate those elements.
internal
backend/circuits
Package circuits contains test circuits
Package circuits contains test circuits
compilelogger
Package compilelogger provides logging helpers for circuit compilation time.
Package compilelogger provides logging helpers for circuit compilation time.
frontendtype
Package frontendtype allows to assert frontend type.
Package frontendtype allows to assert frontend type.
gkr
kvstore
Package kvstore implements simple key-value store
Package kvstore implements simple key-value store
regression_tests
Package regressiontests includes tests to avoid re-introducing regressions.
Package regressiontests includes tests to avoid re-introducing regressions.
small_rational/polynomial
Package polynomial provides polynomial methods and commitment schemes.
Package polynomial provides polynomial methods and commitment schemes.
smallfields/tinyfield
Package tinyfield contains field arithmetic operations for modulus = 0x2f.
Package tinyfield contains field arithmetic operations for modulus = 0x2f.
stats/generate command
widecommitter
package widecommitter provides mocked implementation of the widecommitter interface
package widecommitter provides mocked implementation of the widecommitter interface
Package io offers serialization interfaces for gnark objects.
Package io offers serialization interfaces for gnark objects.
Package logger provides a configurable logger across gnark components
Package logger provides a configurable logger across gnark components
Package profile provides a simple way to generate pprof compatible gnark circuit profile.
Package profile provides a simple way to generate pprof compatible gnark circuit profile.
internal/graph
Package graph collects a set of samples into a directed graph.
Package graph collects a set of samples into a directed graph.
internal/measurement
Package measurement export utility functions to manipulate/format performance profile sample values.
Package measurement export utility functions to manipulate/format performance profile sample values.
internal/report
Package report summarizes a performance profile into a human-readable report.
Package report summarizes a performance profile into a human-readable report.
std
Package std provides components or functions to help design gnark circuits.
Package std provides components or functions to help design gnark circuits.
accumulator/merkle
Package merkle provides a ZKP-circuit function to verify merkle proofs.
Package merkle provides a ZKP-circuit function to verify merkle proofs.
algebra
Package algebra implements:
Package algebra implements:
algebra/algopts
Package algopts provides shareable options for modifying algebraic operations.
Package algopts provides shareable options for modifying algebraic operations.
algebra/emulated/fields_bls12381
Package fields_bls12381 implements the fields arithmetic of the direct 𝔽p¹² extension used to compute the pairing over the BLS12-381 curve.
Package fields_bls12381 implements the fields arithmetic of the direct 𝔽p¹² extension used to compute the pairing over the BLS12-381 curve.
algebra/emulated/fields_bn254
Package fields_bn254 implements the fields arithmetic of the direct 𝔽p¹² extension used to compute the pairing over the BN254 curve.
Package fields_bn254 implements the fields arithmetic of the direct 𝔽p¹² extension used to compute the pairing over the BN254 curve.
algebra/emulated/fields_bw6761
Package fields_bw6761 implements the fields arithmetic of the Fp6 tower used to compute the pairing over the BW6-761 curve.
Package fields_bw6761 implements the fields arithmetic of the Fp6 tower used to compute the pairing over the BW6-761 curve.
algebra/emulated/sw_bls12381
Package sw_bls12381 implements G1 and G2 arithmetics and pairing computation over BLS12-381 curve.
Package sw_bls12381 implements G1 and G2 arithmetics and pairing computation over BLS12-381 curve.
algebra/emulated/sw_bn254
Package sw_bn254 implements G1 and G2 arithmetics and pairing computation over BN254 curve.
Package sw_bn254 implements G1 and G2 arithmetics and pairing computation over BN254 curve.
algebra/emulated/sw_bw6761
Package sw_bw6761 implements G1 and G2 arithmetics and pairing computation over BW6-761 curve.
Package sw_bw6761 implements G1 and G2 arithmetics and pairing computation over BW6-761 curve.
algebra/emulated/sw_emulated
Package sw_emulated implements elliptic curve group operations in (short) Weierstrass form.
Package sw_emulated implements elliptic curve group operations in (short) Weierstrass form.
algebra/native/fields_bls12377
Package fields_bls12377 implements the fields arithmetic of the Fp12 tower used to compute the pairing over the BLS12-377 curve.
Package fields_bls12377 implements the fields arithmetic of the Fp12 tower used to compute the pairing over the BLS12-377 curve.
algebra/native/sw_bls12377
Package sw_bls12377 implements the arithmetics of G1, G2 and the pairing computation on BLS12-377 as a SNARK circuit over BW6-761.
Package sw_bls12377 implements the arithmetics of G1, G2 and the pairing computation on BLS12-377 as a SNARK circuit over BW6-761.
algebra/native/sw_grumpkin
Package sw_grumpkin implements the the Grumpkin curve in-circuit.
Package sw_grumpkin implements the the Grumpkin curve in-circuit.
algebra/native/twistededwards
Package twistededwards implements the arithmetic of twisted Edwards curves in native fields.
Package twistededwards implements the arithmetic of twisted Edwards curves in native fields.
commitments/kzg
Package kzg implements KZG polynomial commitment verification.
Package kzg implements KZG polynomial commitment verification.
commitments/pedersen
Package pedersen implements the Pedersen vector commitment scheme verifier.
Package pedersen implements the Pedersen vector commitment scheme verifier.
conversion
Package conversion provides methods for converting between different primitive types.
Package conversion provides methods for converting between different primitive types.
evmprecompiles
Package evmprecompiles implements the Ethereum VM precompile contracts.
Package evmprecompiles implements the Ethereum VM precompile contracts.
hash
Package hash provides an interface that hash functions (as gadget) should implement.
Package hash provides an interface that hash functions (as gadget) should implement.
hash/expand
Package expand implements message expansion according to RFC9380.
Package expand implements message expansion according to RFC9380.
hash/mimc
Package mimc provides a ZKP-circuit function to compute a MiMC hash.
Package mimc provides a ZKP-circuit function to compute a MiMC hash.
hash/ripemd160
Package ripemd160 implements in-circuit ripemd160 hash function.
Package ripemd160 implements in-circuit ripemd160 hash function.
hash/sha2
Package sha2 implements SHA2 hash computation.
Package sha2 implements SHA2 hash computation.
hash/sha3
Package sha3 provides ZKP circuits for SHA3 hash algorithms applying sponge construction over Keccak f-[1600] permutation function.
Package sha3 provides ZKP circuits for SHA3 hash algorithms applying sponge construction over Keccak f-[1600] permutation function.
internal/fieldextension
Package fieldextension provides operations over an extension field of the native field.
Package fieldextension provides operations over an extension field of the native field.
internal/logderivarg
Package logderivarg implements log-derivative argument.
Package logderivarg implements log-derivative argument.
internal/logderivprecomp
Package logderivprecomp allows computing functions using precomputation.
Package logderivprecomp allows computing functions using precomputation.
internal/mimc
Package mimc implements the MiMC hash function as a gnark circuit
Package mimc implements the MiMC hash function as a gnark circuit
lookup/logderivlookup
Package logderivlookup implements append-only lookups using log-derivative argument.
Package logderivlookup implements append-only lookups using log-derivative argument.
math/bitslice
Package bitslice allows partitioning variables.
Package bitslice allows partitioning variables.
math/cmp
Package cmp provides methods and functions for comparing two numbers.
Package cmp provides methods and functions for comparing two numbers.
math/emulated
Package emulated implements operations over any modulus.
Package emulated implements operations over any modulus.
math/emulated/emparams
Package emparams contains emulation parameters for well known fields.
Package emparams contains emulation parameters for well known fields.
math/polynomial
Package polynomial provides field-agnostic polynomials.
Package polynomial provides field-agnostic polynomials.
math/uints
Package uints implements optimised byte and long integer operations.
Package uints implements optimised byte and long integer operations.
multicommit
Package multicommit implements commitment expansion.
Package multicommit implements commitment expansion.
permutation/keccakf
Package keccakf implements the KeccakF-1600 permutation function.
Package keccakf implements the KeccakF-1600 permutation function.
permutation/ripemd160
Package ripemd160 implements the permutation used in the ripemd160 hash function.
Package ripemd160 implements the permutation used in the ripemd160 hash function.
rangecheck
Package rangecheck implements range checking gadget
Package rangecheck implements range checking gadget
recursion
Package recursion provides in-circuit verifiers for different proofs systems.
Package recursion provides in-circuit verifiers for different proofs systems.
recursion/groth16
Package groth16 provides in-circuit Groth16 verifier.
Package groth16 provides in-circuit Groth16 verifier.
recursion/plonk
Package plonk implements in-circuit PLONK verifier.
Package plonk implements in-circuit PLONK verifier.
recursion/sumcheck
Package sumcheck implements non-native sumcheck verifier.
Package sumcheck implements non-native sumcheck verifier.
selector
Package selector provides a lookup table and map, based on linear scan.
Package selector provides a lookup table and map, based on linear scan.
signature/bls
Package bls implements a subset of the BLS (Boneh-Lynn-Shacham) signature scheme.
Package bls implements a subset of the BLS (Boneh-Lynn-Shacham) signature scheme.
signature/ecdsa
Package ecdsa implements ECDSA signature verification over any elliptic curve.
Package ecdsa implements ECDSA signature verification over any elliptic curve.
signature/eddsa
Package eddsa implements EdDSA signature verification over twisted Edwards elliptic curves available in gnark and gnark-crypto.
Package eddsa implements EdDSA signature verification over twisted Edwards elliptic curves available in gnark and gnark-crypto.
Package test provides components or functions to help test and fuzz gnark circuits.
Package test provides components or functions to help test and fuzz gnark circuits.
unsafekzg
Package unsafekzg is a convenience package (to be use for test purposes only) to generate and cache SRS for the kzg scheme (and indirectly for PlonK setup).
Package unsafekzg is a convenience package (to be use for test purposes only) to generate and cache SRS for the kzg scheme (and indirectly for PlonK setup).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL