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 ¶
var (
ErrInvalidWitness = errors.New("invalid witness")
)
Functions ¶
This section is empty.
Types ¶
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 (*Witness) MarshalBinary ¶ added in v0.6.1
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
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
Public extracts the public part of the witness and returns a new witness object
func (*Witness) UnmarshalBinary ¶ added in v0.6.1
UnmarshalBinary implements encoding.BinaryUnmarshaler
func (*Witness) UnmarshalJSON ¶ added in v0.6.1
UnmarshalJSON implements json.Unmarshaler