Documentation
¶
Index ¶
- func AssertEqualIf(api frontend.API, cond, a, b frontend.Variable)
- func AssertIsLessIf(api frontend.API, cond, a, b frontend.Variable)
- func AssertSliceEquals(api frontend.API, a, b []frontend.Variable)
- func Bls12381ScalarToBls12377Scalars(v interface{}) (r [2][]byte, err error)
- func ChecksumSlice(slice [][]byte) []byte
- func ChecksumSubSlices(api frontend.API, hsh snarkHash.FieldHasher, slice []frontend.Variable, ...) []frontend.Variable
- func CloneSlice[T any](s []T, cap ...int) []T
- func CombineBytesIntoElements(api frontend.API, b [32]frontend.Variable) [2]frontend.Variable
- func CopyHexEncodedBytes(dst []frontend.Variable, hex string) error
- func Differences(api frontend.API, s []frontend.Variable) []frontend.Variable
- func DivEuclidean(api frontend.API, a, b frontend.Variable) (quotient, remainder frontend.Variable)
- func InnerProd(api frontend.API, x, y []frontend.Variable) frontend.Variable
- func MapSlice[X, Y any](f func(X) Y, x ...X) []Y
- func MimcHash(api frontend.API, e ...frontend.Variable) frontend.Variable
- func NoCheck(b *bool)
- func Pack(api frontend.API, words []frontend.Variable, bitsPerElem, bitsPerWord int) []frontend.Variable
- func PackFull(api frontend.API, words []frontend.Variable, bitsPerWord int) []frontend.Variable
- func PackedBytesToCrumbs(api frontend.API, bytes []frontend.Variable, bitsPerElem int) []frontend.Variable
- func PartialSums(api frontend.API, s []frontend.Variable) []frontend.Variable
- func PartialSumsInt[T constraints.Integer](s []T) []T
- func PartitionSlice(api frontend.API, s []frontend.Variable, selectors []frontend.Variable, ...)
- func PartitionSliceEmulated[T emulated.FieldParams](api frontend.API, s []emulated.Element[T], selectors []frontend.Variable, ...) [][]emulated.Element[T]
- func RegisterHints()
- func RotateLeft(api frontend.API, v []frontend.Variable, n frontend.Variable) (res []frontend.Variable)
- func SelectMany(api frontend.API, c frontend.Variable, ifSo, ifNot []frontend.Variable) []frontend.Variable
- func SliceToTable(api frontend.API, slice []frontend.Variable) *logderivlookup.Table
- func Sum[T constraints.Integer](x ...T) T
- func SumSnark(api frontend.API, x ...frontend.Variable) frontend.Variable
- func ToCrumbs(api frontend.API, v frontend.Variable, nbCrumbs int) []frontend.Variable
- func Truncate(api frontend.API, slice []frontend.Variable, n frontend.Variable) []frontend.Variable
- func Uint64To32Bytes(i uint64) [32]byte
- type NewRangeOption
- type Range
- func (r *Range) AddIfLastI(i int, accumulator, atI frontend.Variable) frontend.Variable
- func (r *Range) AssertArrays32Equal(a, b [][32]frontend.Variable)
- func (r *Range) AssertEqualI(i int, a, b frontend.Variable)
- func (r *Range) AssertEqualLastI(i int, a, b frontend.Variable)
- func (r *Range) LastArray32(slice [][32]frontend.Variable) [32]frontend.Variable
- func (r *Range) LastArray32F(provider func(int) [32]frontend.Variable) [32]frontend.Variable
- func (r *Range) LastF(provider func(i int) frontend.Variable) frontend.Variable
- func (r *Range) PartialSums(slice []frontend.Variable) []frontend.Variable
- func (r *Range) PartialSumsF(provider func(int) frontend.Variable) []frontend.Variable
- func (r *Range) StaticLength() int
- type Slice
- type Var32Slice
- type VarSlice
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertEqualIf ¶
AssertEqualIf asserts cond ≠ 0 ⇒ (a == b)
func AssertIsLessIf ¶
AssertIsLessIf asserts cond ≠ 0 ⇒ (a < b)
func Bls12381ScalarToBls12377Scalars ¶
Bls12381ScalarToBls12377Scalars interprets its input as a BLS12-381 scalar, with a modular reduction if necessary, returning two BLS12-377 scalars r[1] is the lower 252 bits. r[0] is the higher 3 bits. useful in circuit "assign" functions
func ChecksumSlice ¶
ChecksumSlice returns H(len(slice), partial) where partial is slice[0] if length is 1, and hsh(slice[0], slice[1], ..., slice[len(slice)-1]) otherwise Proof of collision resistance: By the collision resistance of H, we may assume that f(a_1, ..., a_n) = f(b_1, ..., b_m) implies m=1 and f(a_1,...,a_n) = f(b) = b. If n = 1, then f(a) = a and thus a = b. Otherwise, n ≠ 1 implies H(n, f(a_1,...,a_n)) ≠ H(1, b).
func ChecksumSubSlices ¶
func ChecksumSubSlices(api frontend.API, hsh snarkHash.FieldHasher, slice []frontend.Variable, subEndPoints VarSlice) []frontend.Variable
ChecksumSubSlices returns the hash of consecutive sub-slices, compatible with ChecksumSliceSnark the endpoints are not range checked and are assumed to be strictly increasing, and that endpoint[0] ≠ 0 and endpoint[endpoints.Length-1] \leq len(slice) due to its hint, it only works with MiMC in BLS12-377
func CloneSlice ¶
func CopyHexEncodedBytes ¶
CopyHexEncodedBytes panics if the string won't fit. If the string is too small, is will be 0-padded on the left.
func DivEuclidean ¶
DivEuclidean conventional integer division with a remainder TODO @Tabaie replace all/most special-case divisions with this, barring performance issues
func PackFull ¶
PackFull packs as many words as possible into a single field element The words are construed in big-endian, and 0 padding is added as needed on the left for every element and on the right for the last element
func PackedBytesToCrumbs ¶
func PackedBytesToCrumbs(api frontend.API, bytes []frontend.Variable, bitsPerElem int) []frontend.Variable
PackedBytesToCrumbs converts a slice of bytes, padded with zeros on the left to make bitsPerElem bits field elements, into a slice of two-bit crumbs panics if bitsPerElem is not a multiple of 2
func PartialSums ¶
PartialSums returns s[0], s[0]+s[1], ..., s[0]+s[1]+...+s[len(s)-1]
func PartialSumsInt ¶
func PartialSumsInt[T constraints.Integer](s []T) []T
func PartitionSlice ¶
func PartitionSlice(api frontend.API, s []frontend.Variable, selectors []frontend.Variable, subs ...[]frontend.Variable)
PartitionSlice populates sub-slices subs[0], ... where subs[i] contains the elements s[j] with selectors[j] = i There are no guarantee on the values in the subs past their actual lengths. The hint sets them to zero but PartitionSlice does not check that fact. It may produce an incorrect result if selectors are out of range
func PartitionSliceEmulated ¶
func PartitionSliceEmulated[T emulated.FieldParams](api frontend.API, s []emulated.Element[T], selectors []frontend.Variable, subSliceMaxLens ...int) [][]emulated.Element[T]
PartitionSliceEmulated populates sub-slices subs[0], ... where subs[i] contains the elements s[j] with selectors[j] = i There are no guarantee on the values in the subs past their actual lengths. The hint sets them to zero but PartitionSlice does not check that fact. It may produce an incorrect result if selectors are out of range
func RegisterHints ¶
func RegisterHints()
func RotateLeft ¶
func RotateLeft(api frontend.API, v []frontend.Variable, n frontend.Variable) (res []frontend.Variable)
RotateLeft rotates the slice v by n positions to the left, so that res[i] becomes v[(i+n)%len(v)]
func SelectMany ¶
func SliceToTable ¶
func Sum ¶
func Sum[T constraints.Integer](x ...T) T
func ToCrumbs ¶
TODO add to gnark: bits.ToBase ToCrumbs decomposes scalar v into nbCrumbs 2-bit digits. It uses Little Endian order for compatibility with gnark, even though we use Big Endian order in the circuit
func Uint64To32Bytes ¶
Types ¶
type NewRangeOption ¶
type NewRangeOption func(*bool)
type Range ¶
type Range struct {
InRange, IsLast, IsFirstBeyond []frontend.Variable
// contains filtered or unexported fields
}
func (*Range) AddIfLastI ¶
AddIfLastI returns accumulator + IsLast[i] * atI
func (*Range) AssertArrays32Equal ¶
func (*Range) AssertEqualI ¶
AssertEqualI i ∈ [0, n) ⇒ a == b with n as given to the constructor
func (*Range) AssertEqualLastI ¶
AssertEqualLastI i == n-1 ⇒ a == b with n as given to the constructor
func (*Range) LastArray32 ¶
func (*Range) LastArray32F ¶
func (*Range) PartialSums ¶
PartialSums returns a slice of the same length as slice, where res[i] = slice[0] + ... + slice[i]. Out of range values are excluded.
func (*Range) PartialSumsF ¶
func (*Range) StaticLength ¶
type Slice ¶
type Slice[T any] struct { // @reviewer: better for slice to be non-generic with frontend.Variable type and just duplicate the funcs for the few [32]frontend.Variable applications? Values []T // Values[:Length] contains the data Length frontend.Variable }
func Concat ¶
Concat does not range check the slice lengths individually, but it does their sum all slices have to be nonempty. This is not checked either Runtime in the order of maxLinLength + len(slices) * max_i(len(slices[i]) it does not perform well when one of the slices is statically much longer than the others