builder

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2024 License: Apache-2.0, MIT Imports: 3 Imported by: 0

Documentation

Overview

The basic APIs (for vars.Variable, vars.Bit, vars.Byte, vars.U64, etc) needed to write circuits and tools for reading and writing inputs and outputs from on-chain and off-chain data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API struct {
	// contains filtered or unexported fields
}

This is the API that we recommend developers use for writing circuits. It is a wrapper around the gnark frontend API. Additional methods can be accessed by importing other packages such as sha256 or ssz.

func NewAPI

func NewAPI(api frontend.API) *API

Creates a new succinct.API object.

func (*API) Add

func (a *API) Add(i1 vars.Variable, i2 vars.Variable, in ...vars.Variable) vars.Variable

Add returns res = i1+i2+...in.

func (*API) AddU64

func (a *API) AddU64(in ...vars.U64) vars.U64

Computes a_1 + ... + a_n where a_i \in [0, 2^64). This function automatically carries the result such that the result is in [0, 2^64). The cost of the carry can be amortized over multiple calls to this function by accumulating more terms into a single add.

func (*API) And

func (a *API) And(i1, i2 vars.Bool) vars.Bool

Computes the and of two bits or i1 & i2.

func (*API) AssertIsBoolean

func (a *API) AssertIsBoolean(i1 vars.Variable)

AssertIsBoolean fails if v != 0 ∥ v != 1.

func (*API) AssertIsDifferent

func (a *API) AssertIsDifferent(i1, i2 vars.Variable)

AssertIsDifferent fails if i1 == i2.

func (*API) AssertIsEqual

func (a *API) AssertIsEqual(i1, i2 vars.Variable)

AssertIsEqual fails if i1 != i2

func (*API) AssertIsEqualBool

func (a *API) AssertIsEqualBool(i1, i2 vars.Bool)

Asserts that two booleans are equal.

func (*API) AssertIsEqualByte

func (a *API) AssertIsEqualByte(i1, i2 vars.Byte)

func (*API) AssertIsLessOrEqual

func (a *API) AssertIsLessOrEqual(i1, i2 vars.Variable)

AssertIsLessOrEqual fails if i1 > i2.

func (*API) Cmp

func (a *API) Cmp(i1, i2 vars.Variable) vars.Variable

Cmp returns 1 if i1>i2, 0 if i1=i2, -1 if i1<i2

func (*API) Div

func (a *API) Div(i1 vars.Variable, i2 vars.Variable) vars.Variable

Div returns i1 / i2.

func (*API) FrontendAPI

func (a *API) FrontendAPI() frontend.API

Returns the underlying gnark frontend.FrontendAPI object. Most developers should not need to use this.

func (*API) Inverse

func (a *API) Inverse(i1 vars.Variable) vars.Variable

Inverse returns 1/i.

func (*API) IsZero

func (a *API) IsZero(i1 vars.Variable) vars.Bool

IsZero returns 1 if a is zero, 0 otherwise.

func (*API) Lookup2

func (a *API) Lookup2(b1, b2 vars.Variable, i1, i2, i3, i4 vars.Variable) vars.Variable

Lookup2 performs a 2-bit lookup between i1, i2, i3, i4 based on bits b0 and b1. Returns i0 if b0=b1=0, i1 if b0=1 and b1=0, i2 if b0=0 and b1=1 and i3 if b0=b1=1.

func (*API) Mul

func (a *API) Mul(i1 vars.Variable, i2 vars.Variable, in ...vars.Variable) vars.Variable

Mul returns res = i1 * i2 * ... in.

func (*API) MulU64

func (a *API) MulU64(in ...vars.U64) vars.U64

func (*API) Neg

func (a *API) Neg(i1 vars.Variable) vars.Variable

Neg returns -i.

func (*API) Not

func (a *API) Not(i1 vars.Bool) vars.Bool

Computes the not of a bit or !i1.

func (*API) Or

func (a *API) Or(i1, i2 vars.Bool) vars.Bool

Computes the or of two bits or i1 | i2.

func (*API) PrintU64

func (a *API) PrintU64(u64 vars.U64)

func (*API) PrintVarBytes

func (a *API) PrintVarBytes(vars []vars.Byte)

func (*API) Select

func (a *API) Select(selector vars.Bool, i1 vars.Variable, i2 vars.Variable) vars.Variable

Select if b is true, yields i1 else yields i2.

func (*API) SelectByte

func (a *API) SelectByte(selector vars.Bool, i1 vars.Byte, i2 vars.Byte) vars.Byte

func (*API) SelectBytes32

func (a *API) SelectBytes32(selector vars.Bool, i1 [32]vars.Byte, i2 [32]vars.Byte) [32]vars.Byte

func (*API) Sub

func (a *API) Sub(i1 vars.Variable, i2 vars.Variable, in ...vars.Variable) vars.Variable

Sub returns res = i1 - i2 - ...in.

func (*API) ToBinaryBE

func (a *API) ToBinaryBE(i1 vars.Variable, nbBits int) []vars.Bool

Decomposes a variable in the circuit into a number of bits with big-endian ordering. This function can also be used for "range-checking", in other words checking that some value is less than 2**n.

func (*API) ToBinaryLE

func (a *API) ToBinaryLE(i1 vars.Variable, nbBits int) []vars.Bool

Decomposes a variable in the circuit into a number of bits with little-endian ordering. This function can also be used for "range-checking", in other words checking that some value is less than 2**n.

func (*API) ToBitsFromByte

func (a *API) ToBitsFromByte(i1 vars.Byte) [8]vars.Bool

Converts a byte to bits with little-endian ordering.

func (*API) ToByteFromBits

func (a *API) ToByteFromBits(i1 [8]vars.Bool) vars.Byte

func (*API) ToBytes32FromU64LE

func (a *API) ToBytes32FromU64LE(i1 vars.U64) [32]vars.Byte

Converts a U64 to a Bytes32 in little-endian format. In particular, the u64 is decomposed into bytes b1, ..., b8 such that 256^0 * b1 + ... + 256^7 * b8 is the native value. The bytes32 returned is in the form [b1, ..., b8, 0, ..., 0].

func (*API) Xor

func (a *API) Xor(i1, i2 vars.Bool) vars.Bool

Computes the xor of two bits or i1 ^ i2.

type InputReader

type InputReader struct {
	// contains filtered or unexported fields
}

InputReader is used for reading inputs into a circuit that were provided at the time of the request, either on-chain or off-chain.

func NewInputReader

func NewInputReader(api API, bytes []vars.Byte) *InputReader

Creates a new InputReader.

func (*InputReader) ReadBytes32

func (r *InputReader) ReadBytes32() [32]vars.Byte

Reads a byte32 from the input stream.

func (*InputReader) ReadUint64

func (r *InputReader) ReadUint64() vars.U64

ReadUint64 reads a uint64 in big-endian from the input stream.

type OutputWriter

type OutputWriter struct {
	// contains filtered or unexported fields
}

OutputWriter is used for writing outputs from a circuit that need to be read on-chain. In particular, the struct is used for writing to a a list of output bytes which is then hashed to produce a commitment to the outputs of the circuit.

func NewOutputWriter

func NewOutputWriter(api API) *OutputWriter

Creates a new OutputWriter.

func (*OutputWriter) Close

func (w *OutputWriter) Close(expectedBytes []vars.Byte)

func (*OutputWriter) WriteBytes32

func (w *OutputWriter) WriteBytes32(bytes [32]vars.Byte)

func (*OutputWriter) WriteU64

func (w *OutputWriter) WriteU64(i1 vars.U64)

Writes a single u64 to the output stream.

Jump to

Keyboard shortcuts

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