witness

package
v0.6.5 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2022 License: Apache-2.0 Imports: 15 Imported by: 147

Documentation

Overview

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

Binary protocol

Full witness     ->  [uint32(nbElements) | publicVariables | secretVariables]
Public witness   ->  [uint32(nbElements) | publicVariables ]

where

  • `nbElements == len(publicVariables) [+ len(secretVariables)]`.
  • each variable (a *field element*) is encoded as a big-endian byte array, where `len(bytes(variable)) == len(bytes(modulus))`

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(3)|bytes(Y)|bytes(X)|bytes(Z)]`
  • Hex representation with values `Y = 35`, `X = 3`, `Z = 2` `00000003000000000000000000000000000000000000000000000000000000000000002300000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000002`

Index

Constants

This section is empty.

Variables

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

Functions

This section is empty.

Types

type Vector added in v0.6.1

type Vector interface {
	io.WriterTo
	io.ReaderFrom
	FromAssignment(assignment interface{}, leafType reflect.Type, publicOnly bool) (*schema.Schema, error)
	ToAssignment(assigment interface{}, leafType reflect.Type, publicOnly bool)
	Len() int
	Type() reflect.Type
}

type Witness added in v0.6.1

type Witness struct {
	Vector  Vector         //  TODO @gbotrel the result is an interface for now may change to generic Witness[fr.Element] in an upcoming PR
	Schema  *schema.Schema // optional, Binary encoding needs no schema
	CurveID ecc.ID         // should be redundant with generic impl
}

Witness represents a zkSNARK witness.

A witness can be in 3 states: 1. Assignment (ie assigning values to a frontend.Circuit object) 2. Witness (this object: an ordered vector of field elements + metadata) 3. Serialized (Binary or JSON) using MarshalBinary or MarshalJSON

func New added in v0.6.1

func New(curveID ecc.ID, schema *schema.Schema) (*Witness, error)

func (*Witness) MarshalBinary added in v0.6.1

func (w *Witness) MarshalBinary() (data []byte, err error)

MarshalBinary implements encoding.BinaryMarshaler Only the vector of field elements is marshalled: the curveID and the Schema are omitted.

func (*Witness) MarshalJSON added in v0.6.1

func (w *Witness) MarshalJSON() (r []byte, err error)

MarshalJSON implements json.Marshaler

Only the vector of field elements is marshalled: the curveID and the Schema are omitted.

func (*Witness) Public added in v0.6.1

func (w *Witness) Public() (*Witness, error)

Public extracts the public part of the witness and returns a new witness object

func (*Witness) UnmarshalBinary added in v0.6.1

func (w *Witness) UnmarshalBinary(data []byte) error

UnmarshalBinary implements encoding.BinaryUnmarshaler

func (*Witness) UnmarshalJSON added in v0.6.1

func (w *Witness) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler

Jump to

Keyboard shortcuts

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