gnark

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2021 License: Apache-2.0 Imports: 0 Imported by: 8

README

gnark zk-SNARK library

License Go Report Card PkgGoDev Documentation Status

gnark is a fast zk-SNARK library that offers a high-level API to design circuits. The library is open source and developed under the Apache 2.0 license

Issues

gnark issues are tracked in the GitHub issues tab.

If you have any questions, queries or comments, GitHub discussions is the place to find us.

You can also get in touch directly: zkteam@consensys.net

gnark Users

To get started with gnark and write your first circuit, follow these instructions.

Release Notes

Release Notes

Proving schemes and curves

Refer to Proving schemes and curves for more details.

gnark support the following zk-SNARKs:

which can be instantiated with the following curves

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

Refer to the gnark User Documentation

Here is what x**3 + x + 5 = y looks like

// CubicCircuit defines a simple circuit
// x**3 + x + 5 == y
type CubicCircuit struct {
	// struct tags on a variable is optional
	// default uses variable name and secret visibility.
	X frontend.Variable `gnark:"x"`
	Y frontend.Variable `gnark:",public"`
}

// Define declares the circuit constraints
// x**3 + x + 5 == y
func (circuit *CubicCircuit) Define(curveID gurvy.ID, cs *frontend.ConstraintSystem) error {
	x3 := cs.Mul(circuit.X, circuit.X, circuit.X)
	cs.AssertIsEqual(circuit.Y, cs.Add(x3, circuit.X, 5))
	return nil
}

// compiles our circuit into a R1CS
var circuit CubicCircuit
r1cs, err := frontend.Compile(ecc.BN254, backend.GROTH16, &circuit)

// groth16 zkSNARK
pk, vk := groth16.Setup(r1cs)
proof, err := groth16.Prove(r1cs, pk, witness)
err := groth16.Verify(proof, vk, publicWitness)

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

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

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

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.
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.
examples
Package frontend contains the object and logic to define and compile gnark circuits
Package frontend contains the object and logic to define and compile gnark circuits
Package gnarkd provides experimental gRPC endpoints to create and verify proofs with gnark.
Package gnarkd provides experimental gRPC endpoints to create and verify proofs with gnark.
client
Package client provides a minimalist example of a gRPC client connecting to gnarkd/server.
Package client provides a minimalist example of a gRPC client connecting to gnarkd/server.
pb
server
Package server implements a gRPC server following protobuf description of the proof service in gnarkd/pb.
Package server implements a gRPC server following protobuf description of the proof service in gnarkd/pb.
internal
backend/circuits
Package circuits contains test circuits
Package circuits contains test circuits
Package io offers serialization interfaces for gnark objects.
Package io offers serialization interfaces for gnark objects.
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/sw
Package sw (short weierstrass)
Package sw (short weierstrass)
groth16
Package groth16 provides a ZKP-circuit function to verify BLS12_377 Groth16 inside a BW6_761 circuit.
Package groth16 provides a ZKP-circuit function to verify BLS12_377 Groth16 inside a BW6_761 circuit.
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.
signature/eddsa
Package eddsa provides a ZKP-circuit function to verify a EdDSA signature.
Package eddsa provides a ZKP-circuit function to verify a EdDSA signature.

Jump to

Keyboard shortcuts

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