groth16

package
v0.3.8 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2020 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DummySetup

func DummySetup(r1cs *bls381backend.R1CS, pk *ProvingKey) error

DummySetup fills a random ProvingKey used for test or benchmarking purposes

func ParsePublicInput

func ParsePublicInput(expectedNames []string, input map[string]interface{}) ([]fr.Element, error)

ParsePublicInput return the ordered public input values in regular form (used as scalars for multi exponentiation). The function is public because it's needed for the recursive snark.

func Setup

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

Setup constructs the SRS

func Verify

func Verify(proof *Proof, vk *VerifyingKey, inputs map[string]interface{}) error

Verify verifies a proof

Types

type Proof

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

Proof represents a Groth16 proof that was encoded with a ProvingKey and can be verified with a valid statement and a VerifyingKey Notation follows Figure 4. in DIZK paper https://eprint.iacr.org/2018/691.pdf

func Prove

func Prove(r1cs *bls381backend.R1CS, pk *ProvingKey, solution map[string]interface{}, force bool) (*Proof, error)

Prove generates the proof of knoweldge of a r1cs with solution. if force flag is set, Prove ignores R1CS solving error (ie invalid solution) and executes the FFTs and MultiExponentiations to compute an (invalid) Proof object

func (*Proof) GetCurveID

func (proof *Proof) GetCurveID() gurvy.ID

GetCurveID returns the curveID

func (*Proof) ReadFrom added in v0.3.6

func (proof *Proof) ReadFrom(r io.Reader) (n int64, err error)

ReadFrom attempts to decode a Proof from reader Proof must be encoded through WriteTo (compressed) or WriteRawTo (uncompressed) note that we don't check that the points are on the curve or in the correct subgroup at this point

func (*Proof) WriteRawTo added in v0.3.6

func (proof *Proof) WriteRawTo(w io.Writer) (n int64, err error)

WriteRawTo writes binary encoding of the Proof elements to writer points are stored in uncompressed form Ar | Krs | Bs use WriteTo(...) to encode the proof with point compression

func (*Proof) WriteTo added in v0.3.6

func (proof *Proof) WriteTo(w io.Writer) (n int64, err error)

WriteTo writes binary encoding of the Proof elements to writer points are stored in compressed form Ar | Krs | Bs use WriteRawTo(...) to encode the proof without point compression

type ProvingKey

type ProvingKey struct {
	// domain
	Domain fft.Domain

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

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

ProvingKey is used by a Groth16 prover to encode a proof of a statement Notation follows Figure 4. in DIZK paper https://eprint.iacr.org/2018/691.pdf

func (*ProvingKey) GetCurveID

func (pk *ProvingKey) GetCurveID() gurvy.ID

GetCurveID returns the curveID

func (*ProvingKey) IsDifferent

func (pk *ProvingKey) IsDifferent(_other interface{}) bool

IsDifferent returns true if provided pk is different than self this is used by groth16.Assert to ensure random sampling

func (*ProvingKey) ReadFrom added in v0.3.6

func (pk *ProvingKey) ReadFrom(r io.Reader) (int64, error)

ReadFrom attempts to decode a ProvingKey from reader ProvingKey must be encoded through WriteTo (compressed) or WriteRawTo (uncompressed) note that we don't check that the points are on the curve or in the correct subgroup at this point TODO while Proof points correctness is checkd in the Verifier, here may be a good place to check key

func (*ProvingKey) WriteRawTo added in v0.3.6

func (pk *ProvingKey) WriteRawTo(w io.Writer) (n int64, err error)

WriteRawTo writes binary encoding of the key elements to writer points are not compressed use WriteTo(...) to encode the key with point compression

func (*ProvingKey) WriteTo added in v0.3.6

func (pk *ProvingKey) WriteTo(w io.Writer) (n int64, err error)

WriteTo writes binary encoding of the key elements to writer points are compressed use WriteRawTo(...) to encode the key without point compression

type VerifyingKey

type VerifyingKey struct {
	// ordered public input names
	PublicInputs []string

	// e(α, β)
	E curve.GT

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

	// [Kvk]1
	G1 struct {
		K []curve.G1Affine // The indexes correspond to the public wires
	}
}

VerifyingKey is used by a Groth16 verifier to verify the validity of a proof and a statement Notation follows Figure 4. in DIZK paper https://eprint.iacr.org/2018/691.pdf

func (*VerifyingKey) GetCurveID

func (vk *VerifyingKey) GetCurveID() gurvy.ID

GetCurveID returns the curveID

func (*VerifyingKey) IsDifferent

func (vk *VerifyingKey) IsDifferent(_other interface{}) bool

IsDifferent returns true if provided vk is different than self this is used by groth16.Assert to ensure random sampling

func (*VerifyingKey) ReadFrom added in v0.3.6

func (vk *VerifyingKey) ReadFrom(r io.Reader) (n int64, err error)

ReadFrom attempts to decode a VerifyingKey from reader VerifyingKey must be encoded through WriteTo (compressed) or WriteRawTo (uncompressed) note that we don't check that the points are on the curve or in the correct subgroup at this point TODO while Proof points correctness is checkd in the Verifier, here may be a good place to check key

func (*VerifyingKey) WriteRawTo added in v0.3.6

func (vk *VerifyingKey) WriteRawTo(w io.Writer) (n int64, err error)

WriteRawTo writes binary encoding of the key elements to writer points are not compressed use WriteTo(...) to encode the key with point compression

func (*VerifyingKey) WriteTo added in v0.3.6

func (vk *VerifyingKey) WriteTo(w io.Writer) (n int64, err error)

WriteTo writes binary encoding of the key elements to writer points are compressed use WriteRawTo(...) to encode the key without point compression

Jump to

Keyboard shortcuts

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