groth16

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2024 License: Apache-2.0 Imports: 29 Imported by: 163

Documentation

Overview

Package groth16 implements Groth16 Zero Knowledge Proof system (aka zkSNARK).

See also

https://eprint.iacr.org/2016/260.pdf

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCS added in v0.4.0

func NewCS(curveID ecc.ID) constraint.ConstraintSystem

NewCS instantiate a concrete curved-typed R1CS and return a R1CS interface This method exists for (de)serialization purposes

func Setup

Setup runs groth16.Setup with provided R1CS and outputs a key pair associated with the circuit.

Note that careful consideration must be given to this step in a production environment. groth16.Setup uses some randomness to precompute the Proving and Verifying keys. If the process or machine leaks this randomness, an attacker could break the ZKP protocol.

Two main solutions to this deployment issues are: running the Setup through a MPC (multi party computation) or using a ZKP backend like PLONK where the per-circuit Setup is deterministic.

func Verify

func Verify(proof Proof, vk VerifyingKey, publicWitness witness.Witness, opts ...backend.VerifierOption) error

Verify runs the groth16.Verify algorithm on provided proof with given witness

Types

type Proof

type Proof interface {
	CurveID() ecc.ID

	io.WriterTo
	io.ReaderFrom

	// Raw methods for faster serialization-deserialization. Does not perform checks on the data.
	// Only use if you are sure of the data you are reading comes from trusted source.
	gnarkio.WriterRawTo
}

Proof represents a Groth16 proof generated by groth16.Prove

it's underlying implementation is curve specific (see gnark/internal/backend)

func NewProof added in v0.3.6

func NewProof(curveID ecc.ID) Proof

NewProof instantiates a curve-typed Proof and returns an interface This function exists for serialization purposes

func Prove

func Prove(r1cs constraint.ConstraintSystem, pk ProvingKey, fullWitness witness.Witness, opts ...backend.ProverOption) (Proof, error)

Prove runs the groth16.Prove algorithm.

if the force flag is set:

	will execute all the prover computations, even if the witness is invalid
 will produce an invalid proof
	internally, the solution vector to the R1CS will be filled with random values which may impact benchmarking

type ProvingKey

type ProvingKey interface {
	CurveID() ecc.ID

	io.WriterTo
	io.ReaderFrom

	// Raw methods for faster serialization-deserialization. Does not perform checks on the data.
	// Only use if you are sure of the data you are reading comes from trusted source.
	gnarkio.WriterRawTo
	gnarkio.UnsafeReaderFrom

	// BinaryDumper is the interface that wraps the WriteDump and ReadDump
	// methods. It performs a very fast and very unsafe memory dump writing and
	// reading.
	gnarkio.BinaryDumper

	// NbG1 returns the number of G1 elements in the ProvingKey
	NbG1() int

	// NbG2 returns the number of G2 elements in the ProvingKey
	NbG2() int

	// IsDifferent compares against another proving key and returns true if they are different.
	IsDifferent(any) bool
}

ProvingKey represents a Groth16 ProvingKey

it's underlying implementation is strongly typed with the curve (see gnark/internal/backend)

func DummySetup

func DummySetup(r1cs constraint.ConstraintSystem) (ProvingKey, error)

DummySetup create a random ProvingKey with provided R1CS it doesn't return a VerifyingKey and is use for benchmarking or test purposes only.

func NewProvingKey added in v0.3.6

func NewProvingKey(curveID ecc.ID) ProvingKey

NewProvingKey instantiates a curve-typed ProvingKey and returns an interface object This function exists for serialization purposes

type VerifyingKey

type VerifyingKey interface {
	CurveID() ecc.ID

	io.WriterTo
	io.ReaderFrom

	// Raw methods for faster serialization-deserialization. Does not perform checks on the data.
	// Only use if you are sure of the data you are reading comes from trusted source.
	gnarkio.WriterRawTo
	gnarkio.UnsafeReaderFrom

	// VerifyingKey are the methods required for generating the Solidity
	// verifier contract from the VerifyingKey. This will return an error if not
	// supported on the CurveID().
	solidity.VerifyingKey

	// NbPublicWitness returns number of elements expected in the public witness
	NbPublicWitness() int

	// NbG1 returns the number of G1 elements in the VerifyingKey
	NbG1() int

	// NbG2 returns the number of G2 elements in the VerifyingKey
	NbG2() int

	IsDifferent(interface{}) bool
}

VerifyingKey represents a Groth16 VerifyingKey

it's underlying implementation is strongly typed with the curve (see gnark/internal/backend)

ExportSolidity is implemented for BN254 and will return an error with other curves

func NewVerifyingKey added in v0.3.6

func NewVerifyingKey(curveID ecc.ID) VerifyingKey

NewVerifyingKey instantiates a curve-typed VerifyingKey and returns an interface This function exists for serialization purposes

Directories

Path Synopsis
icicle
Package icicle_bn254 implements ICICLE acceleration for BN254 Groth16 backend.
Package icicle_bn254 implements ICICLE acceleration for BN254 Groth16 backend.

Jump to

Keyboard shortcuts

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