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 ¶
- type API
- func (a *API) Add(i1 vars.Variable, i2 vars.Variable, in ...vars.Variable) vars.Variable
- func (a *API) AddU64(in ...vars.U64) vars.U64
- func (a *API) And(i1, i2 vars.Bool) vars.Bool
- func (a *API) AssertIsBoolean(i1 vars.Variable)
- func (a *API) AssertIsDifferent(i1, i2 vars.Variable)
- func (a *API) AssertIsEqual(i1, i2 vars.Variable)
- func (a *API) AssertIsEqualBool(i1, i2 vars.Bool)
- func (a *API) AssertIsEqualByte(i1, i2 vars.Byte)
- func (a *API) AssertIsLessOrEqual(i1, i2 vars.Variable)
- func (a *API) Cmp(i1, i2 vars.Variable) vars.Variable
- func (a *API) Div(i1 vars.Variable, i2 vars.Variable) vars.Variable
- func (a *API) FrontendAPI() frontend.API
- func (a *API) Inverse(i1 vars.Variable) vars.Variable
- func (a *API) IsZero(i1 vars.Variable) vars.Bool
- func (a *API) Lookup2(b1, b2 vars.Variable, i1, i2, i3, i4 vars.Variable) vars.Variable
- func (a *API) Mul(i1 vars.Variable, i2 vars.Variable, in ...vars.Variable) vars.Variable
- func (a *API) MulU64(in ...vars.U64) vars.U64
- func (a *API) Neg(i1 vars.Variable) vars.Variable
- func (a *API) Not(i1 vars.Bool) vars.Bool
- func (a *API) Or(i1, i2 vars.Bool) vars.Bool
- func (a *API) PrintU64(u64 vars.U64)
- func (a *API) PrintVarBytes(vars []vars.Byte)
- func (a *API) Select(selector vars.Bool, i1 vars.Variable, i2 vars.Variable) vars.Variable
- func (a *API) SelectByte(selector vars.Bool, i1 vars.Byte, i2 vars.Byte) vars.Byte
- func (a *API) SelectBytes32(selector vars.Bool, i1 [32]vars.Byte, i2 [32]vars.Byte) [32]vars.Byte
- func (a *API) Sub(i1 vars.Variable, i2 vars.Variable, in ...vars.Variable) vars.Variable
- func (a *API) ToBinaryBE(i1 vars.Variable, nbBits int) []vars.Bool
- func (a *API) ToBinaryLE(i1 vars.Variable, nbBits int) []vars.Bool
- func (a *API) ToBitsFromByte(i1 vars.Byte) [8]vars.Bool
- func (a *API) ToByteFromBits(i1 [8]vars.Bool) vars.Byte
- func (a *API) ToBytes32FromU64LE(i1 vars.U64) [32]vars.Byte
- func (a *API) Xor(i1, i2 vars.Bool) vars.Bool
- type InputReader
- type OutputWriter
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 (*API) AddU64 ¶
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) AssertIsBoolean ¶
AssertIsBoolean fails if v != 0 ∥ v != 1.
func (*API) AssertIsDifferent ¶
AssertIsDifferent fails if i1 == i2.
func (*API) AssertIsEqual ¶
AssertIsEqual fails if i1 != i2
func (*API) AssertIsEqualBool ¶
Asserts that two booleans are equal.
func (*API) AssertIsEqualByte ¶
func (*API) AssertIsLessOrEqual ¶
AssertIsLessOrEqual fails if i1 > i2.
func (*API) FrontendAPI ¶
Returns the underlying gnark frontend.FrontendAPI object. Most developers should not need to use this.
func (*API) Lookup2 ¶
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) PrintVarBytes ¶
func (*API) SelectByte ¶
func (*API) SelectBytes32 ¶
func (*API) ToBinaryBE ¶
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 ¶
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 ¶
Converts a byte to bits with little-endian ordering.
func (*API) ToBytes32FromU64LE ¶
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].
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 (*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.