compress

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertChecksumEquals

func AssertChecksumEquals(api frontend.API, e []frontend.Variable, checksum frontend.Variable) error

AssertChecksumEquals takes a MiMC hash of e and asserts it is equal to checksum

func ChecksumPaddedBytes

func ChecksumPaddedBytes(b []byte, validLength int, hsh hash.Hash, fieldNbBits int) []byte

ChecksumPaddedBytes packs b into field elements, then hashes the field elements along with validLength (encoded into a field element of its own)

func Pack

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

Pack packs the words as tightly as possible, and works Big Endian: i.e. the first word is the most significant in the packed elem it is on the caller to make sure the words are within range

func PackN

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

PackN packs the words wordsPerElem at a time into field elements, and works Big Endian: i.e. the first word is the most significant in the packed elem it is on the caller to make sure the words are within range

func ReadNum

func ReadNum(api frontend.API, c []frontend.Variable, radix *big.Int) frontend.Variable

ReadNum reads the slice c as a big endian number in base radix

func ShiftLeft

func ShiftLeft(api frontend.API, slice []frontend.Variable, shiftAmount frontend.Variable) []frontend.Variable

ShiftLeft erases shiftAmount many elements from the left of Slice and replaces them in the right with zeros it is the caller's responsibility to make sure that 0 \le shift < len(c)

func UnpackIntoBytes

func UnpackIntoBytes(api frontend.API, bytesPerElem int, packed []frontend.Variable) (unpacked []frontend.Variable, nbBytes frontend.Variable, err error)

UnpackIntoBytes construes every element in packed as consisting of bytesPerElem bytes, returning those bytes it DOES NOT prove that the elements in unpacked are actually bytes nbBytes is the number of "valid" bytes according to the padding scheme in https://github.com/Consensys/zkevm-monorepo/blob/main/prover/lib/compressor/blob/blob_maker.go#L299 TODO @tabaie @gbotrel move the padding/packing code to gnark or compress the very last non-zero byte in the unpacked stream is meant to encode the number of unused bytes in the last field element used. though UnpackIntoBytes includes that last byte in unpacked, it is not counted in nbBytes

func UnpackIntoBytesHint

func UnpackIntoBytesHint(_ *big.Int, ins, outs []*big.Int) error

Types

type NumReader

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

NumReader takes a sequence of words [ b₀ b₁ ... ], along with a base r and length n and returns the numbers (b₀ b₁ ... bₙ₋₁)ᵣ, (b₁ b₂ ... bₙ)ᵣ, ... upon successive calls to Next()

func NewNumReader

func NewNumReader(api frontend.API, toRead []frontend.Variable, numNbBits, wordNbBits int) *NumReader

NewNumReader returns a new NumReader toRead is the slice of words to read from numNbBits defines the radix as r = 2ⁿᵘᵐᴺᵇᴮⁱᵗˢ (or rather numNbBits = log₂(r) ) wordNbBits defines the number of bits in each word such that n = numNbBits/wordNbBits it is the caller's responsibility to check 0 ≤ bᵢ < r ∀ i

func (*NumReader) AssertNextEquals

func (nr *NumReader) AssertNextEquals(v frontend.Variable)

AssertNextEquals is functionally equivalent to

z := nr.Next()
api.AssertIsEqual(v, z)

while saving exactly one constraint

func (*NumReader) Next

func (nr *NumReader) Next() frontend.Variable

Next returns the next number in the sequence and advances the reader head by one word. assumes bits past the end of the Slice are 0

func (*NumReader) SetNumNbBits

func (nr *NumReader) SetNumNbBits(numNbBits int)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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