prover

package
v1.5.2 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2023 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

prover package abstracts the logic and types of go-rapidsnark (https://github.com/iden3/go-rapidsnark) to support basic operations for the rest of vocdoni-node project. It returns custom errors with some more information, trying to clarify the original workflow and standardizing the inputs/outputs types.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPublicSignalFormat = fmt.Errorf("invalid proof public signals format")
	ErrParsingWeight      = fmt.Errorf("error parsing proof weight string to big.Int")
	ErrParsingNullifier   = fmt.Errorf("error parsing proof nullifier string to big.Int")
	ErrParsingWitness     = fmt.Errorf("error parsing provided circuit inputs, it must be a not empty marshalled bytes of a json")
	ErrInitWitnessCalc    = fmt.Errorf("error parsing circuit wasm during calculator instance")
	ErrWitnessCalc        = fmt.Errorf("error during witness calculation")
	ErrProofGen           = fmt.Errorf("error during zksnark proof generation")
	ErrParseProofData     = fmt.Errorf("error parsing the proof provided, it must be a valid json, check https://github.com/iden3/go-rapidsnark/blob/73d5784d2aa791dd6646142b0017dbef97240f57/types/proof.go")
	ErrParsePubSignals    = fmt.Errorf("error during zksnark public signals proof generation, it must be a json with array of strings")
	ErrEncodingProof      = fmt.Errorf("error encoding prove result into a proof struct")
	ErrDecodingProof      = fmt.Errorf("error decoding prove as []byte")
	ErrVerifyProof        = fmt.Errorf("error during zksnark verification")
)

TODO: Refactor the error handling to include the trace of the original error into the error returned.

Functions

This section is empty.

Types

type Proof

type Proof struct {
	Data       ProofData `json:"data"`
	PubSignals []string  `json:"pubSignals"`
}

Proof struct wraps the ProofData struct and its associated public signals. Contains all the required information to perform a proof verification.

func ParseProof

func ParseProof(proofData, pubSignals []byte) (*Proof, error)

ParseProof encodes the provided proof data and public signals into a Proof struct, performing an unmarshal operation over them. Returns an error if something is wrong.

func Prove

func Prove(zKey, wasm, inputs []byte) (*Proof, error)

Prove generates a verifiable proof of the execution of the circuit for the input signals using the proving key provided. All the arguments are slices of bytes with the data read from the generated files by Circom (wasm circuit) and SnarkJS (proving zkey). It returns the verifiable proof of the execution with the public signals associated or an error if something fails.

func (*Proof) Bytes

func (p *Proof) Bytes() ([]byte, []byte, error)

Bytes returns the current Proof struct parameters Data and PubSignals as []byte. It returns an error if something fails.

func (*Proof) Nullifier

func (p *Proof) Nullifier() (*big.Int, error)

Nullifier decodes the vote nullifier value from the current proof public signals and return it as a big.Int

func (*Proof) Verify

func (p *Proof) Verify(vKey []byte) error

Verify performs a verification of the provided proof and its public signals. It receives the verification key and returns an error if something fails or nil if the verification was ok.

func (*Proof) Weight

func (p *Proof) Weight() (*big.Int, error)

Weight decodes the vote weight value from the current proof public signals and return it as a big.Int.

type ProofData

type ProofData struct {
	A []string   `json:"pi_a"`
	B [][]string `json:"pi_b"`
	C []string   `json:"pi_c"`
}

ProofData struct contains the calculated parameters of a Proof. It allows to encode and decode go-rapidsnark inputs and outputs easily.

Jump to

Keyboard shortcuts

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