groth16

package
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: 20 Imported by: 111

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 IsSolved added in v0.4.0

func IsSolved(r1cs frontend.CompiledConstraintSystem, witness frontend.Circuit) error

IsSolved attempts to solve the constraint system with provided witness returns nil if it succeeds, error otherwise.

func NewCS added in v0.4.0

func NewCS(curveID ecc.ID) frontend.CompiledConstraintSystem

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

func ReadAndVerify added in v0.4.0

func ReadAndVerify(proof Proof, vk VerifyingKey, publicWitness io.Reader) error

ReadAndVerify behaves like Verify, except witness is read from a io.Reader witness must be encoded following the binary serialization protocol described in gnark/backend/witness package

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 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 frontend.Circuit) error

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

Types

type Assert

type Assert struct {
	*require.Assertions
}

Assert is a helper to test circuits

func NewAssert

func NewAssert(t *testing.T) *Assert

NewAssert returns an Assert helper

func (*Assert) ProverFailed

func (assert *Assert) ProverFailed(r1cs frontend.CompiledConstraintSystem, witness frontend.Circuit)

ProverFailed check that a witness does NOT solve a circuit

func (*Assert) ProverSucceeded

func (assert *Assert) ProverSucceeded(r1cs frontend.CompiledConstraintSystem, witness frontend.Circuit)

ProverSucceeded check that a witness solves a circuit

1. Runs groth16.Setup()

2. Solves the R1CS

3. Runs groth16.Prove()

4. Runs groth16.Verify()

5. Ensure deserialization(serialization) of generated objects is correct

ensure result vectors a*b=c, and check other properties like random sampling

func (*Assert) SolvingFailed

func (assert *Assert) SolvingFailed(r1cs frontend.CompiledConstraintSystem, witness frontend.Circuit)

SolvingFailed Verifies that the R1CS is not solved with the given witness, without executing groth16 workflow

func (*Assert) SolvingSucceeded

func (assert *Assert) SolvingSucceeded(r1cs frontend.CompiledConstraintSystem, witness frontend.Circuit)

SolvingSucceeded Verifies that the R1CS is solved with the given witness, without executing groth16 workflow

type Proof

type Proof interface {
	gnarkio.WriterRawTo
	io.WriterTo
	io.ReaderFrom
}

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 frontend.CompiledConstraintSystem, pk ProvingKey, witness frontend.Circuit, force ...bool) (Proof, error)

Prove runs the groth16.Prove algorithm.

If force flag is set, executes all the prover computations, even if the witness is invalid (in which case it will produce an invalid proof)

func ReadAndProve added in v0.4.0

func ReadAndProve(r1cs frontend.CompiledConstraintSystem, pk ProvingKey, witness io.Reader, force ...bool) (Proof, error)

ReadAndProve behaves like Prove, , except witness is read from a io.Reader witness must be encoded following the binary serialization protocol described in gnark/backend/witness package

type ProvingKey

type ProvingKey interface {
	gnarkio.WriterRawTo
	io.WriterTo
	io.ReaderFrom
	IsDifferent(interface{}) bool
}

ProvingKey represents a Groth16 ProvingKey

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

func DummySetup

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 {
	gnarkio.WriterRawTo
	io.WriterTo
	io.ReaderFrom
	SizePublicWitness() int // number of elements expected in the public witness
	IsDifferent(interface{}) bool
	ExportSolidity(w io.Writer) error
}

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

Jump to

Keyboard shortcuts

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