witness

package
v0.0.0-...-51639b7 Latest Latest
Warning

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

Go to latest
Published: May 4, 2023 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package witness provides serialization helpers to encode a witness into a []byte.

Binary protocol

Witness     ->  [uint32(nbPublic) | uint32(nbSecret) | fr.Vector(variables)]
fr.Vector is a *field element* vector encoded a big-endian byte array like so: [uint32(len(vector)) | elements]

Ordering

First, `publicVariables`, then `secretVariables`. Each subset is ordered from the order of definition in the circuit structure. For example, with this circuit on `ecc.BN254`

type Circuit struct {
    X frontend.Variable
    Y frontend.Variable `gnark:",public"`
    Z frontend.Variable
}

A valid witness would be:

  • `[uint32(1)|uint32(2)|uint32(3)|bytes(Y)|bytes(X)|bytes(Z)]`
  • Hex representation with values `Y = 35`, `X = 3`, `Z = 2` `000000010000000200000003000000000000000000000000000000000000000000000000000000000000002300000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000002`

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidWitness = errors.New("invalid witness")

Functions

This section is empty.

Types

type Witness

type Witness interface {
	io.WriterTo
	io.ReaderFrom
	encoding.BinaryMarshaler
	encoding.BinaryUnmarshaler

	// Public returns the Public an object containing the public part of the Witness only.
	Public() (Witness, error)

	// Vector returns the underlying fr.Vector slice
	Vector() any

	// Fill range over the provided chan to fill the underlying vector.
	// Will allocate the underlying vector with nbPublic + nbSecret elements.
	// This is typically call by internal APIs to fill the vector by walking a structure.
	Fill(nbPublic, nbSecret int, values <-chan any) error
}

Witness represents a zkSNARK witness.

The underlying data structure is a vector of field elements, but a Witness also may have some additional meta information about the number of public elements and secret elements.

In most cases a Witness should be [de]serialized using a binary protocol. JSON conversions for pretty printing are slow and don't handle all complex circuit structures well.

func New

func New() (Witness, error)

New initialize a new empty Witness.

Jump to

Keyboard shortcuts

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