groth16

package
v0.1.0-alpha Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2020 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package groth16 exposes zkSNARK (Groth16) 3 algorithms: Setup, Prove and Verify

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrGotOneWire       = errors.New("ONE_WIRE is a reserved name, should not be set manually")
	ErrMissingAssigment = errors.New("missing assigment")
	ErrGotPrivateInput  = errors.New("expecting only public inputs, got a input marked private")
)

Functions

func BenchmarkProver

func BenchmarkProver(b *testing.B, circuit cs.CS, solution cs.Assignments)

BenchmarkProver is a helper to benchmark groth16.Prove on a given circuit it will run the Setup, reset the benchmark timer and benchmark the prover

func BenchmarkSetup

func BenchmarkSetup(b *testing.B, circuit cs.CS)

BenchmarkSetup is a helper to benchmark groth16.Setup on a given circuit

func BenchmarkVerifier

func BenchmarkVerifier(b *testing.B, circuit cs.CS, solution cs.Assignments)

BenchmarkVerifier is a helper to benchmark groth16.Verify on a given circuit it will run the Setup, the Prover and reset the benchmark timer and benchmark the verifier the provided solution will be filtered to keep only public inputs

func ParsePublicInput

func ParsePublicInput(expectedNames []string, publicInput map[string]cs.Assignment) ([]curve.Element, error)

ParsePublicInput return the input values, not in Montgomery form

func Setup

func Setup(r1cs *cs.R1CS, pk *ProvingKey, vk *VerifyingKey)

Setup constructs the SRS

func Verify

func Verify(proof *Proof, vk *VerifyingKey, publicInputs map[string]cs.Assignment) (bool, error)

Verify verifies a proof

Types

type Assert

type Assert struct {
	*require.Assertions
	// contains filtered or unexported fields
}

Assert is a helper to test circuits it embeds a cs.Assert object (see gnark/cs/assert)

func NewAssert

func NewAssert(t *testing.T) *Assert

NewAssert returns an Assert helper

func (*Assert) NotSolved

func (assert *Assert) NotSolved(circuit cs.CS, solution cs.Assignments)

NotSolved check that a solution does NOT solve a circuit error may be missing inputs or unsatisfied constraints it runs cs.Assert.NotSolved and ensure running groth16.Prove and groth16.Verify doesn't return true

func (*Assert) Solved

func (assert *Assert) Solved(circuit cs.CS, solution cs.Assignments, expectedValues map[string]interface{})

Solved check that a solution solves a circuit for each expectedValues, this helper compares the output from r1cs.Inspect() after Solving. this helper also ensure the result vectors a*b=c it runs cs.Assert.Solved and ensure running groth16.Prove and groth16.Verify returns true

type Proof

type Proof struct {
	Ar, Krs ecc.G1Affine
	Bs      ecc.G2Affine
}

Proof represents a Groth16 proof that was encoded with a ProvingKey and can be verified with a valid statement and a VerifyingKey

func Prove

func Prove(r1cs *cs.R1CS, pk *ProvingKey, solution map[string]cs.Assignment) (*Proof, error)

Prove creates proof from a circuit

type ProvingKey

type ProvingKey struct {
	// [α]1, [β]1, [δ]1
	// [A(t)]1, [B(t)]1, [Kpk(t)]1, [Z(t)]1
	G1 struct {
		Alpha, Beta, Delta ecc.G1Affine
		A, B, Z            []ecc.G1Affine
		K                  []ecc.G1Affine // the indexes correspond to the private wires
	}

	// [β]2, [δ]2, [B(t)]2
	G2 struct {
		Beta, Delta ecc.G2Affine
		B           []ecc.G2Affine
	}
}

ProvingKey is used by a Groth16 prover to encode a proof of a statement

type VerifyingKey

type VerifyingKey struct {
	// e(α, β)
	E ecc.PairingResult

	// -[γ]2, -[δ]2
	// note: storing GammaNeg and DeltaNeg instead of Gamma and Delta
	// see proof.Verify() for more details
	G2Aff struct {
		GammaNeg, DeltaNeg ecc.G2Affine
	}

	// [Kvk]1
	G1Jac struct {
		K []ecc.G1Jac // The indexes correspond to the public wires
	}

	PublicInputsTracker []string // maps the name of the public input
}

VerifyingKey is used by a Groth16 verifier to verify the validity of a proof and a statement

Jump to

Keyboard shortcuts

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