schema

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: 6 Imported by: 24

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Copy

func Copy(from interface{}, fromType reflect.Type, to interface{}, toType reflect.Type)

TODO @gbotrel this should probably not be here.

Types

type Field

type Field struct {
	Name       string
	NameTag    string
	Visibility Visibility
	Type       FieldType
	SubFields  []Field // will be set only if it's a struct, or an array of struct
	ArraySize  int
}

Field represent a schema Field and is analogous to reflect.StructField (but simplified)

type FieldType

type FieldType uint8

FieldType represents the type a field is allowed to have in a gnark Schema

const (
	Leaf FieldType = iota
	Array
	Struct
)

type LeafHandler

type LeafHandler func(visibility Visibility, name string, tValue reflect.Value) error

LeafHandler is the handler function that will be called when Visit reaches leafs of the struct

type Schema

type Schema struct {
	Fields   []Field
	NbPublic int
	NbSecret int
}

Schema represents the structure of a gnark circuit (/ witness)

func Parse

func Parse(circuit interface{}, tLeaf reflect.Type, handler LeafHandler) (*Schema, error)

Parse filters recursively input data struct and keeps only the fields containing slices, arrays of elements of type frontend.Variable and return the corresponding Slices are converted to arrays.

If handler is specified, handler will be called on each encountered leaf (of type tLeaf)

func (Schema) Instantiate

func (s Schema) Instantiate(leafType reflect.Type, omitEmptyTag ...bool) interface{}

Instantiate builds a concrete type using reflect matching the provided schema

It replaces leafs by provided type, such that one can do:

struct { A []frontend.Variable} -> Schema -> struct {A [12]fr.Element}

Default behavior is to add "json:,omitempty" to the generated struct

func (Schema) WriteSequence

func (s Schema) WriteSequence(w io.Writer) error

WriteSequence writes the expected sequence order of the witness on provided writer witness elements are identified by their tag name, or if unset, struct & field name

The expected sequence matches the binary encoding protocol [public | secret]

type Tag

type Tag string

Tag is a (optional) struct tag one can add to Variable to specify compiler.Compile() behavior

the tag format is as follow:

type MyCircuit struct {
	Y frontend.Variable `gnark:"name,option"`
}

if empty, default resolves to variable name (here "Y") and secret visibility similarly to json or xml struct tags, these are valid:

`gnark:",public"` or `gnark:"-"`

using "-" marks the variable as ignored by the Compile method. This can be useful when you need to declare variables as aliases that are already allocated. For example

type MyCircuit struct {
	Y frontend.Variable `gnark:",public"`
	Z frontend.Variable `gnark:"-"`
}

it is then the developer responsability to do circuit.Z = circuit.Y in the Define() method

type Visibility

type Visibility uint8

Visibility encodes a Variable (or wire) visibility Possible values are Unset, Internal, Secret or Public

const (
	Unset Visibility = iota
	Internal
	Secret
	Public
	Virtual
)

func (Visibility) String

func (v Visibility) String() string

Jump to

Keyboard shortcuts

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