Warning
Paper reference artifact. NOT SOUND — do not use in production. This fork predates two gnark security fixes that apply to the code it benchmarks (see Why this is not sound). It is kept, frozen, only to reproduce the numbers reported in the paper.
For anything else use mistcash/polyring:
the same technique as a standalone Go module on patched gnark.
Reference implementation for:
Shramee Srivastav. Pairing Proofs and Polynomial Ring Toolkit. IACR Transactions on Cryptographic Hardware and Embedded Systems (TCHES), 2027.
this repo (ppprt) |
polyring |
|
|---|---|---|
| Purpose | reproduce the paper's Table 7 | use the technique |
| Built on | gnark fork, upstream merged up to c05c6a8 (3 Aug 2026) |
gnark v0.16.4 (patched) via a pinned fork |
| Sound | no | yes, unaudited |
| Shape | toolkit inside gnark's std/math/emulated |
standalone module: std/polyring, ring pairing, recursive Groth16 verifier, Solidity verifier |
| Maintained | frozen | yes |
polyring's ARTIFACT.md
puts the paper's numbers, this repo's re-run and polyring's numbers on patched
gnark side by side, and explains how they relate.
Two gnark advisories published after this fork's last upstream merge apply to the emulated arithmetic and pairing code this repo builds on:
- GHSA-3mvx-pp85-pm65
(critical, fixed in v0.16.2): the carry polynomial in emulated-field deferred
checks came from a hint and was never range-checked, so a malicious prover
could satisfy a false multiplication. Every
std/algebra/emulatedpairing, this repo's included, sits on those checks. - GHSA-fwf3-jmp7-gmrj (medium): the on-twist check on G2 inputs to the Miller loop was computed and then discarded.
The fixes add constraints to both columns of Table 7, gnark's own pairing included. This repo is left as it was measured so the published numbers stay reproducible; polyring carries the fixes.
| Paper | Code |
|---|---|
| Polynomial ring toolkit (Section 6) | std/math/emulated/field_polyring.go |
NewPolyRingCheck, MulPolyRings, ToCommit, PolyRingAccumulator (Section 6.3.1) |
same file |
performDeferredRingChecks, polyRingMulHint, quotientsRLCHint (Sections 6.2, 6.3) |
same file |
InnerProductNoReduce, deferred reduction (Section 6.5) |
same file |
| BN254 pairing with polynomial ring checks (Sections 4–5) | std/algebra/emulated/sw_bn254/pairing.go, std/algebra/emulated/fields_bn254/e12.go |
| BLS12-381 pairing | std/algebra/emulated/sw_bls12381/pairing.go |
| 3-pairing benchmark (Table 7) | std/algebra/emulated/sw_bn254/g16_simulation_test.go, std/algebra/emulated/sw_bls12381/g16_simulation_test.go |
Requirements: Go ≥ 1.25.7 (tested with 1.26.4). No other setup. Each package takes about 10 s to benchmark after the first build.
git checkout 2f9ffd0
go test -v -run '^$' -bench 'Groth16Simulation' -benchmem \
./std/algebra/emulated/sw_bn254/ ./std/algebra/emulated/sw_bls12381/Each package prints two lines like
g16_simulation_test.go:141: nb commitments: 269616, scs size: … (bytes), nb constraints 1035338, …
g16_simulation_test.go:167: nb commitments: 269616, r1cs size: … (bytes), nb constraints 315955, …
plus four benchmark lines (compile_scs, solve_scs, compile_r1cs,
solve_r1cs). Lines like api.Commit …/field_polyring.go:433 commitmentIndex=0
are a leftover debug print and can be ignored.
The baseline is the same tree with gnark's own pairing files (upstream 8e4363f) and e12.go from 8ea4366:
git checkout 2f9ffd0
git fetch --depth 1 https://github.com/Consensys/gnark 8e4363f1a60dc2febaa872fbda8847d78ce8cf48
git checkout FETCH_HEAD -- std/algebra/emulated/sw_bn254/pairing.go std/algebra/emulated/sw_bn254/hints.go std/algebra/emulated/sw_bls12381/pairing.go
git checkout 8ea4366 -- std/algebra/emulated/fields_bn254/e12.go std/algebra/emulated/fields_bls12381/e12.go
go test -v -run '^$' -bench 'Groth16Simulation' -benchmem \
./std/algebra/emulated/sw_bn254/ ./std/algebra/emulated/sw_bls12381/The raw output of the baseline run reported in the paper is kept verbatim in
both test files, in the Benchmark results BEFORE comment at the bottom; it
matches Table 7's baseline column to the digit.
| Table 7 row | Benchmark output |
|---|---|
| Nb Constraints | nb constraints on the :141 (SCS) and :167 (R1CS) lines |
| Nb Fq Committed | nb commitments: the number of values passed to api.Commit. The counter is only incremented by the SCS builder, so the R1CS line repeats the SCS value: it is the same circuit. |
| Compile Time, Solve Time | ns/op of compile_* and solve_* |
| Compile Memory, Solve Memory | B/op of the same lines: bytes allocated per operation (-benchmem), not peak memory. The paper's GB and MB are 2³⁰ and 2²⁰ bytes. |
Constraint and commitment counts are deterministic. Times and allocations depend on the machine; the paper's were taken on an Apple M3 Pro (arm64).
Measured on an Apple M3 Pro, Go 1.26.4.
| Paper | Re-run (2f9ffd0) |
|
|---|---|---|
| BN254 SCS constraints | 1,592,440 → 1,035,550 (35.0%) | 1,592,216 → 1,035,338 (35.0%) |
| Fq committed | 571,125 → 269,616 (52.8%) | 571,125 → 269,616 (52.8%) |
| R1CS constraints | 491,447 → 316,167 (35.7%) | 491,223 → 315,955 (35.7%) |
| BLS12-381 SCS constraints | 1,784,247 → 1,191,105 (33.2%) | 1,784,091 → 1,190,949 (33.2%) |
| Fq committed | 660,160 → 300,104 (54.5%) | 660,160 → 300,104 (54.5%) |
| R1CS constraints | 545,510 → 368,434 (32.5%) | 545,354 → 368,278 (32.5%) |
Fq committed counts are identical to the paper; constraints are within 0.06%.
- The first commit is a snapshot of Consensys/gnark
at
6e6960808, with upstream history squashed into it. - All following commits are the original development history, unchanged.
The two
Merge upstream gnark … (squashed)commits bring in upstream changes (8e4363f1aandc05c6a810), again squashed into one commit each.
The Go module path is still github.com/consensys/gnark, so the packages build
as in upstream.
Apache 2.0, as upstream gnark (see LICENSE).
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.
- Circuit development in idiomatic Go
- Fast proving and verification backends
- Reusable standard gadgets in
std/ - Active security and regression testing culture
gnarkUser DocumentationgnarkPlaygroundgnarkIssuesgnarkBenchmarks 🏁gnark-announce- release and security announcements
- Go
1.25+(module target:go 1.25.7)
go get github.com/consensys/gnark@latestgo run ./examples/cubicTo design your first circuit, follow the tutorial in gnark User Documentation.
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.
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.
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)
}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.
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 ./...- Kudelski Security - October 2022 - gnark-crypto (contracted by Algorand Foundation)
- Sigma Prime - May 2024 - gnark-crypto KZG (contracted by Ethereum Foundation)
- Consensys Diligence - June 2023 - gnark PLONK Solidity verifier
- LeastAuthority - August 2023 - gnark Groth16 Solidity verifier template (contracted by Worldcoin)
- OpenZeppelin - November 2023 - gnark PLONK Solidity verifier template
- ZKSecurity.xyz - May 2024 - gnark standard library
- OpenZeppelin - June 2024 - gnark PLONK prover and verifier
- LeastAuthority - September 2024 - gnark general and GKR
- LeastAuthority - November 2024 - Linea zkEVM
See CHANGELOG.md.
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}
}See CONTRIBUTING.md and CODE_OF_CONDUCT.md.
gnark follows SemVer. Available versions are in tags.
Licensed under Apache 2.0 (see LICENSE).