internal

package
v0.0.0-...-253a51a Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2025 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertEqualIf

func AssertEqualIf(api frontend.API, cond, a, b frontend.Variable)

AssertEqualIf asserts cond ≠ 0 ⇒ (a == b)

func AssertIsLessIf

func AssertIsLessIf(api frontend.API, cond, a, b frontend.Variable)

AssertIsLessIf asserts cond ≠ 0 ⇒ (a < b)

func AssertSliceEquals

func AssertSliceEquals(api frontend.API, a, b []frontend.Variable)

func Bls12381ScalarToBls12377Scalars

func Bls12381ScalarToBls12377Scalars(v interface{}) (r [2][]byte, err error)

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

func ChecksumSlice(slice [][]byte) []byte

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 CloneSlice[T any](s []T, cap ...int) []T

func CombineBytesIntoElements

func CombineBytesIntoElements(api frontend.API, b [32]frontend.Variable) [2]frontend.Variable

func CopyHexEncodedBytes

func CopyHexEncodedBytes(dst []frontend.Variable, hex string) error

CopyHexEncodedBytes panics if the string won't fit. If the string is too small, is will be 0-padded on the left.

func Differences

func Differences(api frontend.API, s []frontend.Variable) []frontend.Variable

func DivEuclidean

func DivEuclidean(api frontend.API, a, b frontend.Variable) (quotient, remainder frontend.Variable)

DivEuclidean conventional integer division with a remainder TODO @Tabaie replace all/most special-case divisions with this, barring performance issues

func InnerProd

func InnerProd(api frontend.API, x, y []frontend.Variable) frontend.Variable

func MapSlice

func MapSlice[X, Y any](f func(X) Y, x ...X) []Y

func MimcHash

func MimcHash(api frontend.API, e ...frontend.Variable) frontend.Variable

func NoCheck

func NoCheck(b *bool)

func Pack

func Pack(api frontend.API, words []frontend.Variable, bitsPerElem, bitsPerWord int) []frontend.Variable

func PackFull

func PackFull(api frontend.API, words []frontend.Variable, bitsPerWord int) []frontend.Variable

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

func PartialSums(api frontend.API, s []frontend.Variable) []frontend.Variable

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 SelectMany(api frontend.API, c frontend.Variable, ifSo, ifNot []frontend.Variable) []frontend.Variable

func SliceToTable

func SliceToTable(api frontend.API, slice []frontend.Variable) *logderivlookup.Table

func Sum

func Sum[T constraints.Integer](x ...T) T

func SumSnark

func SumSnark(api frontend.API, x ...frontend.Variable) frontend.Variable

func ToCrumbs

func ToCrumbs(api frontend.API, v frontend.Variable, nbCrumbs int) []frontend.Variable

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 Truncate

func Truncate(api frontend.API, slice []frontend.Variable, n frontend.Variable) []frontend.Variable

Truncate ensures that the slice is 0 starting from the n-th element

func Uint64To32Bytes

func Uint64To32Bytes(i uint64) [32]byte

Types

type NewRangeOption

type NewRangeOption func(*bool)

type Range

type Range struct {
	InRange, IsLast, IsFirstBeyond []frontend.Variable
	// contains filtered or unexported fields
}

func NewRange

func NewRange(api frontend.API, n frontend.Variable, max int, opts ...NewRangeOption) *Range

func (*Range) AddIfLastI

func (r *Range) AddIfLastI(i int, accumulator, atI frontend.Variable) frontend.Variable

AddIfLastI returns accumulator + IsLast[i] * atI

func (*Range) AssertArrays32Equal

func (r *Range) AssertArrays32Equal(a, b [][32]frontend.Variable)

func (*Range) AssertEqualI

func (r *Range) AssertEqualI(i int, a, b frontend.Variable)

AssertEqualI i ∈ [0, n) ⇒ a == b with n as given to the constructor

func (*Range) AssertEqualLastI

func (r *Range) AssertEqualLastI(i int, a, b frontend.Variable)

AssertEqualLastI i == n-1 ⇒ a == b with n as given to the constructor

func (*Range) LastArray32

func (r *Range) LastArray32(slice [][32]frontend.Variable) [32]frontend.Variable

func (*Range) LastArray32F

func (r *Range) LastArray32F(provider func(int) [32]frontend.Variable) [32]frontend.Variable

func (*Range) LastF

func (r *Range) LastF(provider func(i int) frontend.Variable) frontend.Variable

func (*Range) PartialSums

func (r *Range) PartialSums(slice []frontend.Variable) []frontend.Variable

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 (r *Range) PartialSumsF(provider func(int) frontend.Variable) []frontend.Variable

func (*Range) StaticLength

func (r *Range) StaticLength() int

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

func Concat(api frontend.API, maxLinearizedLength int, slices ...VarSlice) Slice[frontend.Variable]

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

func SubSlice

func SubSlice(api frontend.API, slice Slice[frontend.Variable], start, length frontend.Variable, maxLength int) Slice[frontend.Variable]

SubSlice DOES NOT range check start and length, but it does end := start + length

type Var32Slice

type Var32Slice Slice[[32]frontend.Variable]

func (Var32Slice) Checksum

func (s Var32Slice) Checksum(api frontend.API) frontend.Variable

type VarSlice

type VarSlice Slice[frontend.Variable]

func (VarSlice) Checksum

Checksum is the SNARK equivalent of ChecksumSlice TODO consider doing (r *Range) f (slice []frontend.Variable)

func (VarSlice) Range

func (s VarSlice) Range(api frontend.API) *Range

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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