sdk

package
v0.3.14 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: MIT Imports: 57 Imported by: 4

Documentation

Index

Constants

View Source
const (
	Uint248Type = "Uint248"
	Uint521Type = "Uint521"
	Int248Type  = "Int248"
	Bytes32Type = "Bytes32"
	Uint32Type  = "Uint32"
	Uint64Type  = "Uint64"
)
View Source
const NumMaxLogFields = 4

NumMaxLogFields is the max amount of log fields each Receipt can have. This couples tightly to the decoding capacity of the receipt decoder circuit on Brevis' side

Variables

View Source
var (
	ReceiptD     = new(big.Int).SetUint64(uint64(1))
	StorageD     = new(big.Int).SetUint64(uint64(2))
	TransactionD = new(big.Int).SetUint64(uint64(3))

	ReceiptVkHashHex     = "0x03e2e4a805080e6a792c9927ab14a83f427ec91d601ab463446231954b4a6d38"
	StorageVkHashHex     = "0x19efa435ccc1bf59b4e97281e7dcc612e2eda104987cfa9f6457435a90156297"
	TransactionVkHashHex = "0x051756e504e16aa2635181222db1d8a9310930599ce44c000414b02101431c89"
	MiddleNodeVkHashHex  = "0x15dc69eafcfd4546b82fecf468fd5878e2f7cb2270abee4e15abb638c77bbe52"
	AggAllVkHash         = "0x078ab850e8148fc412016972abf837fddbc8c7f87d049e337fcdfdc1a47caca2"

	ReceiptCircuitDigestHash = &pgoldilocks.HashOut256{17996561756193319820, 8980630437335591722, 9122961916495130738, 10142517542627101229}
	StorageCircuitDigestHash = &pgoldilocks.HashOut256{3568882391461234058, 14936808234931181849, 15089276379577470236, 10371820311878429064}
	TxCircuitDigestHash      = &pgoldilocks.HashOut256{15153155867950515743, 11132023200088999656, 10234366714538403336, 10983752963612260249}

	P2AggRecursionLeafCircuitDigestHash      = &pgoldilocks.HashOut256{6297162860691876658, 7207440660511781486, 956392925008767441, 15443083968980057808}
	P2Bn128WrapCircuitDigestHashForOnly2Leaf = utils.Hex2BigInt("0x1a608b7771b23c7972539bad7f395d7ad5c4a5e5be9dc891960179c1cacd8c78") // for from P2AggRecursionLeafCircuitDigestHash

	P2AggRecursionMiddleFormMiddleLeafCircuitDigestHash  = &pgoldilocks.HashOut256{14561383570925761150, 12116100132768392867, 2216989100987824959, 11720816772597981334}
	P2AggRecursionNoLeafCircuitDigestHash                = &pgoldilocks.HashOut256{14007309231803840793, 2325011900429631668, 6598512353030159473, 12456847712279341912}
	P2Bn128WrapCircuitDigestHashForOnlyFromLeafRecursion = utils.Hex2BigInt("0x08e1f454d096c46ebf2e1f40ff4858ce8188f86cc9623242ea605b774aee12aa") // for from P2AggRecursionMiddleFormMiddleLeafCircuitDigestHash
	P2Bn128WrapCircuitDigestHash                         = utils.Hex2BigInt("0x1E24794162210326BC751EB2FB4AFB6CB76B2CD94E6CEAFB9191A18B6E24A9D1") // for from P2AggRecursionNoLeafCircuitDigestHash

	ReceiptVkHash     = utils.Hex2BigInt(ReceiptVkHashHex)
	StorageVkHash     = utils.Hex2BigInt(StorageVkHashHex)
	TransactionVkHash = utils.Hex2BigInt(TransactionVkHashHex)
	MiddleNodeVkHash  = utils.Hex2BigInt(MiddleNodeVkHashHex)

	ReceiptNode = Hash2HashDigestNode{
		CircuitDigest: ReceiptD,
		VkHash:        ReceiptVkHash,
	}

	StorageNode = Hash2HashDigestNode{
		CircuitDigest: StorageD,
		VkHash:        StorageVkHash,
	}

	TransactionNode = Hash2HashDigestNode{
		CircuitDigest: TransactionD,
		VkHash:        TransactionVkHash,
	}

	ReceiptPlonky2Node = Plonky2DigestNode{
		CurCircuitDigest: ReceiptCircuitDigestHash,
		IsLeafNode:       true,
	}

	StoragePlonky2Node = Plonky2DigestNode{
		CurCircuitDigest: StorageCircuitDigestHash,
		IsLeafNode:       true,
	}

	TransactionPlonky2Node = Plonky2DigestNode{
		CurCircuitDigest: TxCircuitDigestHash,
		IsLeafNode:       true,
	}
)
View Source
var MaxBytes32 = ConstUint521(common.Hex2Bytes("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))
View Source
var MaxUint248 = new(big.Int).Sub(new(big.Int).Lsh(big.NewInt(1), 248), big.NewInt(1))

MaxUint248 is the largest safe number for uint248 type

View Source
var MaxUint32 = new(big.Int).Sub(new(big.Int).Lsh(big.NewInt(1), 32), big.NewInt(1))

Functions

func AssertEach

func AssertEach[T CircuitVariable](ds *DataStream[T], assertFunc AssertFunc[T])

AssertEach asserts on each valid element in the data stream

func AssertSorted

func AssertSorted[T CircuitVariable](ds *DataStream[T], sortFunc SortFunc[T])

AssertSorted Performs the sortFunc on each valid pair of data points and asserts the result to be 1.

func CalBrevisCircuitDigest

func CalBrevisCircuitDigest(receiptCount, storageCount, transactionCount int, appVk plonk.VerifyingKey) (*big.Int, error)

func CalMerkleRoot

func CalMerkleRoot(gapi frontend.API, datas []frontend.Variable) (frontend.Variable, error)

return merkle root hash, must be a full binary tree

func CalOneHash2HashNodeDigest

func CalOneHash2HashNodeDigest(left, right Hash2HashDigestNode) (*big.Int, error)

func CalOnePlonky2NodeDigest

func CalOnePlonky2NodeDigest(left, right Plonky2DigestNode) (*pgoldilocks.HashOut256, error)

func CalPoseidonBn254MerkleTree

func CalPoseidonBn254MerkleTree(leafs []*big.Int) (*big.Int, error)

func CheckNumberPowerOfTwo

func CheckNumberPowerOfTwo(n int) bool

func Cmp

func Cmp(api frontend.API, i1, i2 frontend.Variable, nbBits int) frontend.Variable

Cmp compares i1 and i2 based on a specified number of bits (nbBits). Returns -1 if i1 < i2, 0 if i1 == i2, and 1 if i1 > i2. This version is optimized to avoid full bit decomposition and only uses range checking and hinting.

func CmpHint added in v0.3.10

func CmpHint(_ *big.Int, inputs []*big.Int, results []*big.Int) error

CmpHint is a hint function that compares two values and returns -1, 0, or 1

func Compile

func Compile(app AppCircuit, compileOutDir, srsDir string) (constraint.ConstraintSystem, plonk.ProvingKey, plonk.VerifyingKey, []byte, error)

func CompileOnly

func CompileOnly(app AppCircuit) (constraint.ConstraintSystem, error)

CompileOnly is like Compile, but it does not automatically save the compilation output

func ComputeVkHash

func ComputeVkHash(vk plonk.VerifyingKey) (common.Hash, error)

func DataPointsNextPowerOf2 added in v0.3.3

func DataPointsNextPowerOf2(value int) int

The minimum dataPoints should be 64

func DoHash

func DoHash(hasher *utils.PoseidonBn254Hasher, packed []*big.Int) (*big.Int, error)

func DoHashWithPoseidonBn254

func DoHashWithPoseidonBn254(packed []*big.Int) (*big.Int, error)

func GetAndCheckLeafCount

func GetAndCheckLeafCount(receiptCount, storageCount, transactionCount int) (receiptLeafCount int, storageLeafCount int, transactionLeafCount int, totalLeafCount int, err error)

func GetHash2HashCircuitDigest

func GetHash2HashCircuitDigest(receiptCount, storageCount, transactionCount int) (*big.Int, error)

func GetHeaderAndTxHashes added in v0.3.14

func GetHeaderAndTxHashes(ec *ethclient.Client, ctx context.Context, blkNum *big.Int) (*types.Header, []common.Hash, error)

func GetHints

func GetHints() []solver.Hint

func GetPlonky2CircuitDigestFromRootNodeSelf added in v0.3.8

func GetPlonky2CircuitDigestFromRootNodeSelf(receiptCount, storageCount, transactionCount int) (*pgoldilocks.HashOut256, bool, bool, error)

func GetReceiptProof added in v0.3.14

func GetReceiptProof(bk *types.Block, receipts types.Receipts, index int) (nodes [][]byte, keyIndex, leafRlpPrefix []byte, err error)

func GetUnderlying

func GetUnderlying[T CircuitVariable](ds *DataStream[T], index int) T

GetUnderlying gets an element from the DataStream. Performed on the underlying data directly. It also requires the underlying data slot is valid

func GroupValuesHint

func GroupValuesHint(_ *big.Int, inputs []*big.Int, outputs []*big.Int) error

func MaxGeneric

func MaxGeneric[T CircuitVariable](ds *DataStream[T], initialMax T, gt SortFunc[T]) T

MaxGeneric finds out the maximum value from the data stream with the user defined sort function. Uses Reduce under the hood. Note if the data stream is empty (all data points are toggled off), this function returns `initialMax`.

func MinGeneric

func MinGeneric[T CircuitVariable](ds *DataStream[T], initialMin T, lt SortFunc[T]) T

MinGeneric finds out the minimum value from the data stream with the user defined sort function. Uses Reduce under the hood. Note if the data stream is empty (all data points are toggled off), this function returns `initialMin`.

func NewFullWitness

func NewFullWitness(assign AppCircuit, in CircuitInput) (w, wpub witness.Witness, err error)

func PackBitsToInt

func PackBitsToInt(bits []uint, bitSize int) []*big.Int

func QuoRemBigHint

func QuoRemBigHint(_ *big.Int, in []*big.Int, out []*big.Int) error

func QuoRemHint

func QuoRemHint(_ *big.Int, in, out []*big.Int) error

func ReadCircuitFrom

func ReadCircuitFrom(path string) (constraint.ConstraintSystem, error)

func ReadPkFrom

func ReadPkFrom(path string) (plonk.ProvingKey, error)

func ReadProofFrom

func ReadProofFrom(path string) (plonk.Proof, error)

func ReadVkFrom

func ReadVkFrom(path string, maxReceipt, maxStorage, numMaxDataPoints int) (plonk.VerifyingKey, []byte, error)

func Reduce

func Reduce[T, R CircuitVariable](ds *DataStream[T], initial R, reducer ReduceFunc[T, R]) R

Reduce reduces the data stream to another CircuitVariable with the given reducer and initial condition

func Select

func Select[T CircuitVariable](api *CircuitAPI, s Uint248, a, b T) T

func Setup

func Setup(ccs constraint.ConstraintSystem, cacheDir string, maxReceipt, maxStorage, dataPoints int) (pk plonk.ProvingKey, vk plonk.VerifyingKey, vkHash []byte, err error)

func SortHint

func SortHint(_ *big.Int, in, out []*big.Int) error

SortHint sorts the input in descending order

func SqrtHint

func SqrtHint(_ *big.Int, in, out []*big.Int) error

func Verify

func Verify(vk plonk.VerifyingKey, publicWitness witness.Witness, proof plonk.Proof) error

func WriteTo

func WriteTo(w io.WriterTo, path string) error

Types

type AppCircuit

type AppCircuit interface {
	Define(api *CircuitAPI, in DataInput) error
	Allocate() (maxReceipts, maxStorage, maxTransactions int)
}

type AssertFunc

type AssertFunc[T CircuitVariable] func(current T) Uint248

AssertFunc returns 1 if the assertion passes, and 0 otherwise

type BrevisApp

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

func NewBrevisApp

func NewBrevisApp(
	srcChainId uint64,
	rpcUrl string,
	outDir string,
	gatewayUrlOverride ...string,
) (*BrevisApp, error)

func (*BrevisApp) AddMockReceipt added in v0.3.7

func (q *BrevisApp) AddMockReceipt(data ReceiptData, index ...int)

AddMockReceipt adds the MockReceipt to be queried. If an index is specified, the data will be assigned to the specified index of DataInput.Receipts. It should be used ONLY for circuit implementation and testing.

func (*BrevisApp) AddMockStorage added in v0.3.7

func (q *BrevisApp) AddMockStorage(data StorageData, index ...int)

AddMockStorage adds the MockStorage to be queried. If an index is specified, the data will be assigned to the specified index of DataInput.StorageSlots. It should be used ONLY for circuit implementation and testing.

func (*BrevisApp) AddMockTransaction added in v0.3.7

func (q *BrevisApp) AddMockTransaction(data TransactionData, index ...int)

AddMockTransaction adds the MockTransaction to be queried. If an index is specified, the data will be assigned to the specified index of DataInput.Transactions. It should be used ONLY for circuit implementation and testing.

func (*BrevisApp) AddReceipt

func (q *BrevisApp) AddReceipt(data ReceiptData, index ...int)

AddReceipt adds the ReceiptData to be queried. If an index is specified, the data will be assigned to the specified index of DataInput.Receipts.

func (*BrevisApp) AddStorage

func (q *BrevisApp) AddStorage(data StorageData, index ...int)

AddStorage adds the StorageData to be queried. If an index is specified, the data will be assigned to the specified index of DataInput.StorageSlots.

func (*BrevisApp) AddTransaction

func (q *BrevisApp) AddTransaction(data TransactionData, index ...int)

AddTransaction adds the TransactionData to be queried. If an index is specified, the data will be assigned to the specified index of DataInput.Transactions.

func (*BrevisApp) BuildCircuitInput

func (q *BrevisApp) BuildCircuitInput(app AppCircuit) (CircuitInput, error)

BuildCircuitInput executes all added queries and package the query results into circuit assignment (the DataInput struct) The provided ctx is used when performing network calls to the provided blockchain RPC.

func (*BrevisApp) BuildReceipt added in v0.3.7

func (q *BrevisApp) BuildReceipt(t ReceiptData) (Receipt, error)

func (*BrevisApp) BuildStorageSlot added in v0.3.1

func (q *BrevisApp) BuildStorageSlot(s StorageData) (StorageSlot, error)

func (*BrevisApp) BuildTx added in v0.3.1

func (q *BrevisApp) BuildTx(t TransactionData) (Transaction, error)

func (*BrevisApp) GenerateProtoQuery added in v0.3.7

func (q *BrevisApp) GenerateProtoQuery(
	vk plonk.VerifyingKey,
	witness witness.Witness,
	proof []byte,
	callbackAddr common.Address,
) (*gwproto.Query, error)

func (*BrevisApp) PrepareRequest

func (q *BrevisApp) PrepareRequest(
	vk plonk.VerifyingKey,
	witness witness.Witness,
	srcChainId, dstChainId uint64,
	refundee, appContract common.Address,
	callbackGasLimit uint64,
	option *gwproto.QueryOption,
	apiKey string,
) (calldata []byte, requestId common.Hash, nonce uint64, feeValue *big.Int, err error)

func (*BrevisApp) ResetInput added in v0.3.10

func (q *BrevisApp) ResetInput()

Reset app input, used for prover server

func (*BrevisApp) SendBatchQuery added in v0.3.7

func (q *BrevisApp) SendBatchQuery(
	queries []*gwproto.Query,
	batchAPIKey string,
	queryOption *gwproto.QueryOption,
) (queryKeys []*gwproto.QueryKey, fee string, err error)

func (*BrevisApp) SubmitProof

func (q *BrevisApp) SubmitProof(proof plonk.Proof, options ...SubmitProofOption) error

func (*BrevisApp) SubmitProofWithQueryId

func (q *BrevisApp) SubmitProofWithQueryId(queryId string, nonce uint64, dstChainId uint64, proof []byte) error

func (*BrevisApp) WaitFinalProofSubmitted

func (q *BrevisApp) WaitFinalProofSubmitted(ctx context.Context) (tx common.Hash, err error)

type Bytes32

type Bytes32 struct {
	Val [2]frontend.Variable
}

Bytes32 is an in-circuit representation of the solidity bytes32 type.

func ConstFromBigEndianBytes added in v0.3.10

func ConstFromBigEndianBytes(data []byte) Bytes32

ConstFromBigEndianBytes initializes a constant Bytes32 circuit variable. Panics if the length of the supplied data bytes is larger than 32.

func (Bytes32) FromValues

func (v Bytes32) FromValues(vs ...frontend.Variable) CircuitVariable

func (Bytes32) NumVars

func (v Bytes32) NumVars() uint32

func (Bytes32) String

func (v Bytes32) String() string

func (Bytes32) Values

func (v Bytes32) Values() []frontend.Variable

type Bytes32API

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

func (*Bytes32API) AssertIsDifferent

func (api *Bytes32API) AssertIsDifferent(a, b Bytes32)

AssertIsDifferent asserts a != b

func (*Bytes32API) AssertIsEqual

func (api *Bytes32API) AssertIsEqual(a, b Bytes32)

AssertIsEqual asserts a == b

func (*Bytes32API) FromBinary

func (api *Bytes32API) FromBinary(vs ...Uint248) Bytes32

FromBinary interprets the input vs as a list of little-endian binary digits and recomposes it to a Bytes32. Input size can be less than 256 bits, the input is padded on the MSB end with 0s.

func (*Bytes32API) FromFV

func (api *Bytes32API) FromFV(v frontend.Variable) Bytes32

func (*Bytes32API) IsEqual

func (api *Bytes32API) IsEqual(a, b Bytes32) Uint248

IsEqual returns 1 if a == b, and 0 otherwise

func (*Bytes32API) IsZero

func (api *Bytes32API) IsZero(a Bytes32) Uint248

IsZero returns 1 if a == 0, and 0 otherwise

func (*Bytes32API) Select

func (api *Bytes32API) Select(s Uint248, a, b Bytes32) Bytes32

Select returns a if s == 1, and b if s == 0

func (*Bytes32API) ToBinary

func (api *Bytes32API) ToBinary(v Bytes32) List[Uint248]

ToBinary decomposes the input v to a list (size 256) of little-endian binary digits

type CircuitAPI

type CircuitAPI struct {
	Uint248 *Uint248API
	Uint521 *Uint521API
	Int248  *Int248API
	Bytes32 *Bytes32API
	Uint32  *Uint32API
	Uint64  *Uint64API
	// contains filtered or unexported fields
}

CircuitAPI contains a set of APIs that can only be used in circuit to perform logical and arithmetic operations over circuit variables. It is an extension of g's frontend.API.

func NewCircuitAPI

func NewCircuitAPI(gapi frontend.API) *CircuitAPI

func (*CircuitAPI) AssertInputsAreUnique

func (api *CircuitAPI) AssertInputsAreUnique()

AssertInputsAreUnique Asserts that all input data (Transaction, Receipt, StorageSlot) are different from each other

func (*CircuitAPI) Keccak256 added in v0.3.2

func (api *CircuitAPI) Keccak256(inputs []Bytes32, inputBitSize []int32) Bytes32

Keccak256 computes keccak256(concatenated inputs) where each element of `inputs“ can have a length up to 32 bytes (256 bits). The actual size of each element needs to be specified in `inputBitSize`. Eg. To compute the keccak256 hash of the concatenation of two 20 byte (160 bit) addresses, use Keccak256([]Bytes32{api.ToBytes32(address0), api.ToBytes32(address1)}, []int32{160, 160}).

func (*CircuitAPI) NewHint

func (api *CircuitAPI) NewHint(f solver.Hint, nbOutputs int, inputs ...frontend.Variable) ([]frontend.Variable, error)

func (*CircuitAPI) NewMiMC

func (api *CircuitAPI) NewMiMC() (mimc.MiMC, error)

func (*CircuitAPI) NewPoseidon

func (api *CircuitAPI) NewPoseidon() (poseidon.PoseidonCircuit, error)

func (*CircuitAPI) OutputAddress

func (api *CircuitAPI) OutputAddress(v Uint248)

OutputAddress adds an output of solidity address type.

func (*CircuitAPI) OutputBool

func (api *CircuitAPI) OutputBool(v Uint248)

OutputBool adds an output of solidity bool type

func (*CircuitAPI) OutputBytes32

func (api *CircuitAPI) OutputBytes32(v Bytes32)

OutputBytes32 adds an output of solidity bytes32/uint256 type

func (*CircuitAPI) OutputUint

func (api *CircuitAPI) OutputUint(bitSize int, v Uint248)

OutputUint adds an output of solidity uint_bitSize type where N is in range [8, 248] with a step size 8. e.g. uint8, uint16, ..., uint248. Panics if a bitSize of non-multiple of 8 is used. Panics if the bitSize exceeds 248. For outputting uint256, use OutputBytes32 instead

func (*CircuitAPI) OutputUint32

func (api *CircuitAPI) OutputUint32(bitSize int, v Uint32)

OutputUint32 adds an output of solidity uint_bitSize type where N is in range [8, 32] with a step size 8. e.g. uint8, uint16, ..., uint32. Panics if a bitSize of non-multiple of 8 is used. Panics if the bitSize exceeds 32.

func (*CircuitAPI) OutputUint64

func (api *CircuitAPI) OutputUint64(bitSize int, v Uint64)

OutputUint adds an output of solidity uint_bitSize type where N is in range [8, 64] with a step size 8. e.g. uint8, uint16, ..., uint64. Panics if a bitSize of non-multiple of 8 is used. Panics if the bitSize exceeds 64.

func (*CircuitAPI) SlotOfArrayElement

func (api *CircuitAPI) SlotOfArrayElement(arrSlot Bytes32, elementSize int, index, offset Uint248) Bytes32

SlotOfArrayElement computes the storage slot for an element in a solidity array state variable. `arrSlot` is the plain slot of the array variable, it is the slot where the first element of the array starts, so that for dynamic arrays, taking the keccak hash of the slot address at which the array itself is located should be handled. `elementSize` is the number of storage slots each element uses, it is not size in bytes. `index` determines the array index. `offset` determines the offset (in terms of bytes32) within each array element.

func (*CircuitAPI) SlotOfStructFieldInMapping

func (api *CircuitAPI) SlotOfStructFieldInMapping(
	slot, offset int, valueSlot Bytes32, nestedMappingSlots ...Bytes32) Bytes32

SlotOfStructFieldInMapping computes the slot for a struct field stored in a solidity mapping. Implements keccak256(h(k) | p) for computing mapping or nested mapping's slot where the value is a struct. The mapping slots are of the order which you would access the solidity mapping. For example, to access nested mapping at slot 1 value with m[a][b] and subsequently the 4th index of the struct value counted in slots, use SlotOfStructFieldInMapping(1, 4, a, b). If your a and b are not of Bytes32 type, cast them to Bytes32 first using api.ToBytes32.

https://docs.soliditylang.org/en/v0.8.24/internals/layout_in_storage.html#mappings-and-dynamic-arrays

func (*CircuitAPI) ToBytes32

func (api *CircuitAPI) ToBytes32(i interface{}) Bytes32

ToBytes32 casts the input to a Bytes32 type. Supports Bytes32, Int248, Uint521, and Uint248.

func (*CircuitAPI) ToInt248

func (api *CircuitAPI) ToInt248(i interface{}) Int248

ToInt248 casts the input to a Int248 type. Supports Int248, Uint248, and Bytes32 Note that Uint248 values with the top bit set will be interpreted as negative values

func (*CircuitAPI) ToUint248

func (api *CircuitAPI) ToUint248(i interface{}) Uint248

ToUint248 casts the input to a Uint248 type. Supports Uint32, Uint64, Uint248, Int248, Bytes32, and Uint521 Note that using ToUint248 with negative Int248 results in a wraparound modulo 2^248

func (*CircuitAPI) ToUint521

func (api *CircuitAPI) ToUint521(i interface{}) Uint521

ToUint521 casts the input to a Uint521 type. Supports Uint521, Bytes32, and Uint248

type CircuitInput

type CircuitInput struct {
	DataInput

	// InputCommitments is a list of hash commitment to each value of Raw. These
	// commitments must match sub-prover circuit's commitment to its rlp decoded
	// values
	InputCommitmentsRoot frontend.Variable `gnark:",public"`
	InputCommitments     []frontend.Variable
	TogglesCommitment    frontend.Variable
	// OutputCommitment is a keccak256 commitment to the computation results of the
	// developer's circuit. The output of this commitment is revealed by the
	// developer in their application contract.
	OutputCommitment                OutputCommitment  `gnark:",public"`
	DummyReceiptInputCommitment     frontend.Variable `gnark:",public"`
	DummyStorageInputCommitment     frontend.Variable `gnark:",public"`
	DummyTransactionInputCommitment frontend.Variable `gnark:",public"`
	// contains filtered or unexported fields
}

func (CircuitInput) Clone

func (in CircuitInput) Clone() CircuitInput

func (CircuitInput) GetAbiPackedOutput

func (in CircuitInput) GetAbiPackedOutput() []byte

type CircuitVariable

type CircuitVariable interface {
	Values() []frontend.Variable
	FromValues(vs ...frontend.Variable) CircuitVariable
	NumVars() uint32
	String() string
}

type DataInput

type DataInput struct {
	Receipts     DataPoints[Receipt]
	StorageSlots DataPoints[StorageSlot]
	Transactions DataPoints[Transaction]
}

func (DataInput) Toggles

func (d DataInput) Toggles() []frontend.Variable

type DataPersistence added in v0.3.7

type DataPersistence struct {
	Receipts map[string]*ReceiptData     `json:"receipts,omitempty"`
	Storages map[string]*StorageData     `json:"storage_slots,omitempty"`
	Txs      map[string]*TransactionData `json:"txs,omitempty"`
}

To reduce rpc requests for developers, save data into local storage for future reference

type DataPoints

type DataPoints[T any] struct {
	// Raw is the structured input data (receipts, txs, and slots).
	Raw []T
	// Toggles is a bitmap that toggles the effectiveness of each position of Raw.
	// len(Toggles) must equal len(Raw)
	Toggles []frontend.Variable
}

func NewDataPoints

func NewDataPoints[T any](maxCount int, newEmpty func() T) DataPoints[T]

func (DataPoints[T]) Clone

func (dp DataPoints[T]) Clone() DataPoints[T]

type DataStream

type DataStream[T CircuitVariable] struct {
	// contains filtered or unexported fields
}

func Filter

func Filter[T CircuitVariable](ds *DataStream[T], predicate FilterFunc[T]) *DataStream[T]

Filter filters the data stream with the given predicate

func GroupBy

func GroupBy[T, R CircuitVariable](
	ds *DataStream[T],
	reducer ReduceFunc[T, R],
	reducerInit R,
	field GetValueFunc[T],
	maxUniqueGroupValuesOptional ...int,
) (*DataStream[R], error)

GroupBy a given field (identified through the field func), call reducer on each group, and returns a data stream in which each element is an aggregation result of the group. The optional param maxUniqueGroupValuesOptional can be supplied to optimize performance. It assumes the worst case (all values in the data stream are unique) if no maxUniqueGroupValuesOptional is configured.

func Map

func Map[T, R CircuitVariable](ds *DataStream[T], mapFunc MapFunc[T, R]) *DataStream[R]

Map maps each valid element in the data stream by calling the user defined mapFunc

func NewDataStream

func NewDataStream[T CircuitVariable](api *CircuitAPI, in DataPoints[T]) *DataStream[T]

func RangeUnderlying

func RangeUnderlying[T CircuitVariable](ds *DataStream[T], start, end int) *DataStream[T]

RangeUnderlying selects a range of the data stream. Performed on the underlying data directly.

func WindowUnderlying

func WindowUnderlying[T CircuitVariable](ds *DataStream[T], size int, step ...int) *DataStream[List[T]]

WindowUnderlying splits a DataStream into many equal sized List. Performed on the underlying data directly. Panics if `size` does not divide the length of the underlying list. Use Range to cut the list length into a multiple of `size` first

func ZipMap2

func ZipMap2[T0, T1, R CircuitVariable](
	a *DataStream[T0], b List[T1],
	zipFunc ZipMap2Func[T0, T1, R],
) *DataStream[R]

ZipMap2 zips a data stream with a list and apply the map function over the zipped data. The underlying toggles of the result data stream depends on the toggles from the source data stream. Panics if the underlying data lengths mismatch Example: ZipMap2([1,2,3], [4,5,6], mySumFunc) -> [5,7,9]

func ZipMap3

func ZipMap3[T0, T1, T2, R CircuitVariable](
	a *DataStream[T0], b List[T1], c List[T2],
	zipFunc ZipMap3Func[T0, T1, T2, R],
) *DataStream[R]

ZipMap3 zips a data stream with two other lists and apply the map function over the zipped data. The underlying toggles of the result data stream depends on the toggles from the source data stream. Example: ZipMap3([1,2,3], [4,5,6], [7,8,9], mySumFunc) -> [12,15,18]

func (*DataStream[T]) Show

func (ds *DataStream[T]) Show()

Show pretty prints the data stream. Useful for debugging.

type FilterFunc

type FilterFunc[T CircuitVariable] func(current T) Uint248

FilterFunc must return 1/0 to include/exclude `current` in the filter result

type GatewayClient

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

func NewGatewayClient

func NewGatewayClient(url ...string) (*GatewayClient, error)

func (*GatewayClient) GetQueryStatus

func (c *GatewayClient) GetQueryStatus(req *gwproto.GetQueryStatusRequest) (resp *gwproto.GetQueryStatusResponse, err error)

func (*GatewayClient) PrepareQuery

func (c *GatewayClient) PrepareQuery(req *gwproto.PrepareQueryRequest) (resp *gwproto.PrepareQueryResponse, err error)

func (*GatewayClient) SendBatchQueries

func (c *GatewayClient) SendBatchQueries(req *gwproto.SendBatchQueriesRequest) (resp *gwproto.SendBatchQueriesResponse, err error)

func (*GatewayClient) SubmitProof

type GetValueFunc

type GetValueFunc[T any] func(current T) Uint248

type Hash2HashDigestNode

type Hash2HashDigestNode struct {
	CircuitDigest *big.Int
	VkHash        *big.Int
}

type HostCircuit

type HostCircuit struct {
	Input CircuitInput
	Guest AppCircuit
	// contains filtered or unexported fields
}

func DefaultHostCircuit

func DefaultHostCircuit(app AppCircuit) *HostCircuit

func NewHostCircuit

func NewHostCircuit(in CircuitInput, guest AppCircuit) *HostCircuit

func (*HostCircuit) Define

func (c *HostCircuit) Define(gapi frontend.API) error

type Int248

type Int248 struct {
	// Val encodes the entire int248 including the sign bit as a uint
	Val frontend.Variable
	// SignBit caches the sign bit signal. 0 if positive, 1 if negative. It could be
	// uninitialized.
	SignBit frontend.Variable
	// contains filtered or unexported fields
}

func ConstInt248

func ConstInt248(v *big.Int) Int248

ConstInt248 initializes a constant Int248. This function does not generate circuit wires and should only be used outside of circuit. The input big int can be negative

func (Int248) FromValues

func (v Int248) FromValues(vs ...frontend.Variable) CircuitVariable

func (Int248) NumVars

func (v Int248) NumVars() uint32

func (Int248) String

func (v Int248) String() string

func (Int248) Values

func (v Int248) Values() []frontend.Variable

type Int248API

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

func (*Int248API) ABS

func (api *Int248API) ABS(a Int248) Uint248

ABS returns the absolute value of a

func (*Int248API) AssertIsDifferent

func (api *Int248API) AssertIsDifferent(a, b Int248)

AssertIsDifferent asserts a != b

func (*Int248API) AssertIsEqual

func (api *Int248API) AssertIsEqual(a, b Int248)

AssertIsEqual asserts a == b

func (*Int248API) FromBinary

func (api *Int248API) FromBinary(vs ...Uint248) Int248

FromBinary interprets the input vs as a list of little-endian binary digits and recomposes it to an Int248. The MSB (most significant bit) of the input is interpreted as the sign bit

func (*Int248API) IsEqual

func (api *Int248API) IsEqual(a, b Int248) Uint248

IsEqual returns 1 if a == b, and 0 otherwise

func (*Int248API) IsGreaterThan

func (api *Int248API) IsGreaterThan(a, b Int248) Uint248

IsGreaterThan returns 1 if a > b, and 0 otherwise

func (*Int248API) IsLessThan

func (api *Int248API) IsLessThan(a, b Int248) Uint248

IsLessThan returns 1 if a < b, and 0 otherwise

func (*Int248API) IsZero

func (api *Int248API) IsZero(a Int248) Uint248

IsZero returns 1 if a == 0, and 0 otherwise

func (*Int248API) Select

func (api *Int248API) Select(s Uint248, a, b Int248) Int248

Select returns a if s == 1, and b if s == 0

func (*Int248API) ToBinary

func (api *Int248API) ToBinary(v Int248) List[Uint248]

ToBinary decomposes the input v to a list (size n) of little-endian binary digits

type List

type List[T CircuitVariable] []T

func (List[T]) FromValues

func (l List[T]) FromValues(vs ...frontend.Variable) CircuitVariable

func (List[T]) NumVars

func (l List[T]) NumVars() uint32

func (List[T]) String

func (l List[T]) String() string

func (List[T]) Values

func (l List[T]) Values() []frontend.Variable

type LogField

type LogField struct {
	// The contract from which the event is emitted
	Contract Uint248
	// the log position in the receipt
	LogPos Uint32
	// The event ID of the event to which the field belong (aka topics[0])
	EventID Uint248
	// Whether the field is a topic (aka "indexed" as in solidity events)
	IsTopic Uint248
	// The index of the field. For example, if a field is the second topic of a log, then Index is 1; if a field is the
	// third field in the RLP decoded data, then Index is 2.
	Index Uint248
	// The value of the field in event, aka the actual thing we care about, only 32-byte fixed length values are supported.
	Value Bytes32
}

LogField represents a single field of an event.

func (LogField) FromValues

func (f LogField) FromValues(vs ...frontend.Variable) CircuitVariable

func (LogField) NumVars

func (f LogField) NumVars() uint32

func (LogField) String

func (f LogField) String() string

func (LogField) Values

func (f LogField) Values() []frontend.Variable

type LogFieldData

type LogFieldData struct {
	// The contract from which the event is emitted
	// Optional value
	Contract common.Address `json:"contract,omitempty"`
	// The event ID of the event to which the field belong (aka topics[0])
	// Optional value
	EventID common.Hash `json:"event_id,omitempty"`
	// the log's position in the receipt
	// Required value
	LogPos uint `json:"log_index,omitempty"`
	// Whether the field is a topic (aka "indexed" as in solidity events)
	// Required value
	IsTopic bool `json:"is_topic,omitempty"`
	// The index of the field in either a log's topics or data. For example, if a
	// field is the second topic of a log, then FieldIndex is 1; if a field is the
	// third field in the RLP decoded data, then FieldIndex is 2.
	// Required value
	FieldIndex uint `json:"field_index,omitempty"`
	// The value of the field in event, aka the actual thing we care about, only
	// 32-byte fixed length values are supported.
	// Optional value
	Value common.Hash `json:"value,omitempty"`
}

type LogFieldPos added in v0.3.7

type LogFieldPos struct {
	// the log's position in the receipt
	LogPos uint `json:"log_index,omitempty"`
	// Whether the field is a topic (aka "indexed" as in solidity events)
	IsTopic bool `json:"is_topic,omitempty"`
	// The index of the field in either a log's topics or data. For example, if a
	// field is the second topic of a log, then FieldIndex is 1; if a field is the
	// third field in the RLP decoded data, then FieldIndex is 2.
	FieldIndex uint `json:"field_index,omitempty"`
}

LogFieldPos represents a single field of an event.

type MapFunc

type MapFunc[T, R CircuitVariable] func(current T) R

type OutputCommitment

type OutputCommitment [2]frontend.Variable

OutputCommitment represents the value of a keccak256 hash H in the form of {H[:16], H[16:]}

func (OutputCommitment) Hash

func (c OutputCommitment) Hash() common.Hash

Hash returns the go hash representation of the commitment

type Plonky2DigestNode

type Plonky2DigestNode struct {
	PubCircuitDigest           *pgoldilocks.HashOut256 // in pub
	CurCircuitDigest           *pgoldilocks.HashOut256 // in json
	IsLeafNode                 bool
	IsRecursionOfLeaf          bool
	IsRecursionRecursionOfLeaf bool
}

func GetPlonky2CircuitDigest

func GetPlonky2CircuitDigest(receiptCount, storageCount, transactionCount int) (*Plonky2DigestNode, error)

type ProofWriter added in v0.3.1

type ProofWriter struct {
	Keys   [][]byte
	Values [][]byte
}

func (*ProofWriter) Delete added in v0.3.1

func (p *ProofWriter) Delete(key []byte) error

func (*ProofWriter) Put added in v0.3.1

func (p *ProofWriter) Put(key []byte, value []byte) error

type Receipt

type Receipt struct {
	BlockNum     Uint32
	BlockBaseFee Uint248
	MptKeyPath   Uint32
	Fields       [NumMaxLogFields]LogField
}

Receipt is a collection of LogField.

func ConvertReceiptDataToReceipt added in v0.3.13

func ConvertReceiptDataToReceipt(r *ReceiptData) Receipt

func DefaultReceipt

func DefaultReceipt() Receipt

func (Receipt) FromValues

func (r Receipt) FromValues(vs ...frontend.Variable) CircuitVariable

func (Receipt) GoPack

func (r Receipt) GoPack() []*big.Int

func (Receipt) NumVars

func (r Receipt) NumVars() uint32

func (Receipt) Pack

func (r Receipt) Pack(api frontend.API) []frontend.Variable

func (Receipt) String

func (r Receipt) String() string

func (Receipt) Values

func (r Receipt) Values() []frontend.Variable

type ReceiptData

type ReceiptData struct {
	TxHash       common.Hash    `json:"tx_hash,omitempty"`        // Required value
	BlockNum     *big.Int       `json:"block_num,omitempty"`      // Optional value
	BlockBaseFee *big.Int       `json:"block_base_fee,omitempty"` // Optional value
	MptKeyPath   *big.Int       `json:"mpt_key_path,omitempty"`   // Optional value
	Fields       []LogFieldData `json:"fields,omitempty"`         // required value
}

type ReceiptPos added in v0.3.7

type ReceiptPos struct {
	TxHash common.Hash   `json:"tx_hash,omitempty"`
	Fields []LogFieldPos `json:"fields,omitempty"`
}

type ReduceFunc

type ReduceFunc[T, R CircuitVariable] func(accumulator R, current T) (newAccumulator R)

type SortFunc

type SortFunc[T CircuitVariable] func(a, b T) Uint248

SortFunc returns 1 if a, b are sorted, 0 if not.

type StorageData

type StorageData struct {
	BlockNum     *big.Int       `json:"block_num,omitempty"`      // Required value
	BlockBaseFee *big.Int       `json:"block_base_fee,omitempty"` // Optional value
	Address      common.Address `json:"address,omitempty"`        // Required value
	Slot         common.Hash    `json:"slot,omitempty"`           // Required value
	Value        common.Hash    `json:"value,omitempty"`          // Optional value
}

type StoragePos added in v0.3.7

type StoragePos struct {
	BlockNum *big.Int       `json:"block_num,omitempty"`
	Address  common.Address `json:"address,omitempty"`
	Slot     common.Hash    `json:"slot,omitempty"`
}

type StorageSlot

type StorageSlot struct {
	BlockNum     Uint32
	BlockBaseFee Uint248

	// The contract to which the storage slot belong
	Contract Uint248
	// The storage slot
	Slot Bytes32
	// The storage slot value
	Value Bytes32
}

func ConvertStorageDataToStorage added in v0.3.13

func ConvertStorageDataToStorage(data *StorageData) StorageSlot

func (StorageSlot) FromValues

func (s StorageSlot) FromValues(vs ...frontend.Variable) CircuitVariable

func (StorageSlot) GoPack

func (s StorageSlot) GoPack() []*big.Int

func (StorageSlot) NumVars

func (s StorageSlot) NumVars() uint32

func (StorageSlot) Pack

func (s StorageSlot) Pack(api frontend.API) []frontend.Variable

func (StorageSlot) String

func (s StorageSlot) String() string

func (StorageSlot) Values

func (s StorageSlot) Values() []frontend.Variable

type SubmitProofOption

type SubmitProofOption func(option submitProofOptions)

func WithContext

func WithContext(ctx context.Context) SubmitProofOption

WithContext uses the input context as the context for waiting for final proof submission

func WithFinalProofSubmittedCallback

func WithFinalProofSubmittedCallback(onSubmitted func(txHash common.Hash), onError func(err error)) SubmitProofOption

WithFinalProofSubmittedCallback sets an async callback for final proof submission result

type Transaction

type Transaction struct {
	// ChainId  Uint248
	BlockNum     Uint32
	BlockBaseFee Uint248
	MptKeyPath   Uint32
	// Nonce    Uint248
	// GasTipCapOrGasPrice is GasPrice for legacy tx (type 0) and GasTipCapOap for
	// dynamic-fee tx (type 2)
	// GasTipCapOrGasPrice Uint248
	// GasFeeCap is always 0 for legacy tx
	// GasFeeCap Uint248
	// GasLimit  Uint248
	// From      Uint248
	// To        Uint248
	// Value     Bytes32
	LeafHash Bytes32
}

TODO: Bring back detailed information when subproof expose corresponding data LeafHash: unsigned tx rlp keccak result

func ConvertTxDataToTransaction added in v0.3.13

func ConvertTxDataToTransaction(data *TransactionData) Transaction

func (Transaction) FromValues

func (t Transaction) FromValues(vs ...frontend.Variable) CircuitVariable

func (Transaction) GoPack

func (t Transaction) GoPack() []*big.Int

func (Transaction) NumVars

func (t Transaction) NumVars() uint32

func (Transaction) Pack

func (t Transaction) Pack(api frontend.API) []frontend.Variable

func (Transaction) String

func (t Transaction) String() string

func (Transaction) Values

func (t Transaction) Values() []frontend.Variable

type TransactionData

type TransactionData struct {
	Hash         common.Hash `json:"hash,omitempty"`           // Required value
	BlockNum     *big.Int    `json:"block_num,omitempty"`      // Optional value
	BlockBaseFee *big.Int    `json:"block_base_fee,omitempty"` // Optional value
	MptKeyPath   *big.Int    `json:"mpt_key_path,omitempty"`   // Optional value
	LeafHash     common.Hash `json:"leaf_hash,omitempty"`      // Optional value
}

type TransactionPos added in v0.3.7

type TransactionPos struct {
	Hash common.Hash `json:"hash,omitempty"`
}

type Tuple2

type Tuple2[F0, F1 CircuitVariable] struct {
	F0 F0
	F1 F1
}

func (Tuple2[F0, F1]) FromValues

func (t Tuple2[F0, F1]) FromValues(vs ...frontend.Variable) CircuitVariable

func (Tuple2[F0, F1]) NumVars

func (t Tuple2[F0, F1]) NumVars() uint32

func (Tuple2[F0, F1]) String

func (t Tuple2[F0, F1]) String() string

func (Tuple2[F0, F1]) Values

func (t Tuple2[F0, F1]) Values() []frontend.Variable

type Tuple3

type Tuple3[F0, F1, F2 CircuitVariable] struct {
	F0 F0
	F1 F1
	F2 F2
}

func (Tuple3[F0, F1, F2]) FromValues

func (t Tuple3[F0, F1, F2]) FromValues(vs ...frontend.Variable) CircuitVariable

func (Tuple3[F0, F1, F2]) NumVars

func (t Tuple3[F0, F1, F2]) NumVars() uint32

func (Tuple3[F0, F1, F2]) String

func (t Tuple3[F0, F1, F2]) String() string

func (Tuple3[F0, F1, F2]) Values

func (t Tuple3[F0, F1, F2]) Values() []frontend.Variable

type Tuple4

type Tuple4[F0, F1, F2, F3 CircuitVariable] struct {
	F0 F0
	F1 F1
	F2 F2
	F3 F3
}

func (Tuple4[F0, F1, F2, F3]) FromValues

func (t Tuple4[F0, F1, F2, F3]) FromValues(vs ...frontend.Variable) CircuitVariable

func (Tuple4[F0, F1, F2, F3]) NumVars

func (t Tuple4[F0, F1, F2, F3]) NumVars() uint32

func (Tuple4[F0, F1, F2, F3]) String

func (t Tuple4[F0, F1, F2, F3]) String() string

func (Tuple4[F0, F1, F2, F3]) Values

func (t Tuple4[F0, F1, F2, F3]) Values() []frontend.Variable

type Tuple5

type Tuple5[F0, F1, F2, F3, F4 CircuitVariable] struct {
	F0 F0
	F1 F1
	F2 F2
	F3 F3
	F4 F4
}

func (Tuple5[F0, F1, F2, F3, F4]) FromValues

func (t Tuple5[F0, F1, F2, F3, F4]) FromValues(vs ...frontend.Variable) CircuitVariable

func (Tuple5[F0, F1, F2, F3, F4]) NumVars

func (t Tuple5[F0, F1, F2, F3, F4]) NumVars() uint32

func (Tuple5[F0, F1, F2, F3, F4]) String

func (t Tuple5[F0, F1, F2, F3, F4]) String() string

func (Tuple5[F0, F1, F2, F3, F4]) Values

func (t Tuple5[F0, F1, F2, F3, F4]) Values() []frontend.Variable

type Tuple6

type Tuple6[F0, F1, F2, F3, F4, F5 CircuitVariable] struct {
	F0 F0
	F1 F1
	F2 F2
	F3 F3
	F4 F4
	F5 F5
}

func (Tuple6[F0, F1, F2, F3, F4, F5]) FromValues

func (t Tuple6[F0, F1, F2, F3, F4, F5]) FromValues(vs ...frontend.Variable) CircuitVariable

func (Tuple6[F0, F1, F2, F3, F4, F5]) NumVars

func (t Tuple6[F0, F1, F2, F3, F4, F5]) NumVars() uint32

func (Tuple6[F0, F1, F2, F3, F4, F5]) String

func (t Tuple6[F0, F1, F2, F3, F4, F5]) String() string

func (Tuple6[F0, F1, F2, F3, F4, F5]) Values

func (t Tuple6[F0, F1, F2, F3, F4, F5]) Values() []frontend.Variable

type Tuple7

type Tuple7[F0, F1, F2, F3, F4, F5, F6 CircuitVariable] struct {
	F0 F0
	F1 F1
	F2 F2
	F3 F3
	F4 F4
	F5 F5
	F6 F6
}

func (Tuple7[F0, F1, F2, F3, F4, F5, F6]) FromValues

func (t Tuple7[F0, F1, F2, F3, F4, F5, F6]) FromValues(vs ...frontend.Variable) CircuitVariable

func (Tuple7[F0, F1, F2, F3, F4, F5, F6]) NumVars

func (t Tuple7[F0, F1, F2, F3, F4, F5, F6]) NumVars() uint32

func (Tuple7[F0, F1, F2, F3, F4, F5, F6]) String

func (t Tuple7[F0, F1, F2, F3, F4, F5, F6]) String() string

func (Tuple7[F0, F1, F2, F3, F4, F5, F6]) Values

func (t Tuple7[F0, F1, F2, F3, F4, F5, F6]) Values() []frontend.Variable

type Tuple8

type Tuple8[F0, F1, F2, F3, F4, F5, F6, F7 CircuitVariable] struct {
	F0 F0
	F1 F1
	F2 F2
	F3 F3
	F4 F4
	F5 F5
	F6 F6
	F7 F7
}

func (Tuple8[F0, F1, F2, F3, F4, F5, F6, F7]) FromValues

func (t Tuple8[F0, F1, F2, F3, F4, F5, F6, F7]) FromValues(vs ...frontend.Variable) CircuitVariable

func (Tuple8[F0, F1, F2, F3, F4, F5, F6, F7]) NumVars

func (t Tuple8[F0, F1, F2, F3, F4, F5, F6, F7]) NumVars() uint32

func (Tuple8[F0, F1, F2, F3, F4, F5, F6, F7]) String

func (t Tuple8[F0, F1, F2, F3, F4, F5, F6, F7]) String() string

func (Tuple8[F0, F1, F2, F3, F4, F5, F6, F7]) Values

func (t Tuple8[F0, F1, F2, F3, F4, F5, F6, F7]) Values() []frontend.Variable

type Uint248

type Uint248 struct {
	Val frontend.Variable
}

func ConstUint248

func ConstUint248(i interface{}) Uint248

ConstUint248 initializes a constant Uint248. This function does not generate circuit wires and should only be used outside of circuit. Supports all int and uint variants, bool, []byte (big-endian), *big.Int, and string inputs. If input is string, this function uses *big.Int SetString function to interpret the string

func Count

func Count[T CircuitVariable](ds *DataStream[T]) Uint248

Count returns the number of valid elements (i.e. toggled on) in the data stream.

func IsSorted

func IsSorted[T CircuitVariable](ds *DataStream[T], sortFunc SortFunc[T]) Uint248

IsSorted returns 1 if the data stream is sorted to the criteria of sortFunc, 0 if not.

func Max

func Max(ds *DataStream[Uint248]) Uint248

Max finds out the maximum value from the data stream. Uses MaxGeneric. Note if the data stream is empty (all data points are toggled off), this function returns 0.

func Mean

func Mean(ds *DataStream[Uint248]) Uint248

Mean calculates the arithmetic mean over the selected fields of the data stream. Uses Sum.

func Min

func Min(ds *DataStream[Uint248]) Uint248

Min finds out the minimum value from the data stream. Uses MinGeneric. Note if the data stream is empty (all data points are toggled off), this function returns MaxUint248.

func ParseEventID

func ParseEventID(b []byte) Uint248

ParseEventID initializes a circuit Uint248 from bytes. Only the first 6 bytes of the event id is used to save space. This function does not generate circuit wires and should only be used outside of circuit.

func Sum

func Sum(ds *DataStream[Uint248]) Uint248

Sum sums values of the selected field in the data stream. Uses Reduce

func (Uint248) FromValues

func (v Uint248) FromValues(vs ...frontend.Variable) CircuitVariable

func (Uint248) NumVars

func (v Uint248) NumVars() uint32

func (Uint248) String

func (v Uint248) String() string

func (Uint248) Values

func (v Uint248) Values() []frontend.Variable

type Uint248API

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

func (*Uint248API) Add

func (api *Uint248API) Add(a, b Uint248, other ...Uint248) Uint248

Add returns a + b. Overflow can happen if a + b > 2^248

func (*Uint248API) And

func (api *Uint248API) And(a, b Uint248, other ...Uint248) Uint248

And returns 1 if a && b [&& other[0] [&& other[1]...]] is true, and 0 otherwise a, b and other... must be 0 or 1

func (*Uint248API) AssertIsDifferent

func (api *Uint248API) AssertIsDifferent(a, b Uint248)

AssertIsDifferent asserts a != b

func (*Uint248API) AssertIsEqual

func (api *Uint248API) AssertIsEqual(a, b Uint248)

AssertIsEqual asserts a == b

func (*Uint248API) AssertIsLessOrEqual

func (api *Uint248API) AssertIsLessOrEqual(a, b Uint248)

AssertIsLessOrEqual asserts a <= b

func (*Uint248API) Div

func (api *Uint248API) Div(a, b Uint248) (quotient, remainder Uint248)

Div computes the standard unsigned integer division (like Go) and returns the quotient and remainder. Uses QuoRemHint

func (*Uint248API) FromBinary

func (api *Uint248API) FromBinary(vs ...Uint248) Uint248

FromBinary interprets the input vs as a list of little-endian binary digits and recomposes it to a Uint248

func (*Uint248API) IsEqual

func (api *Uint248API) IsEqual(a, b Uint248) Uint248

IsEqual returns 1 if a == b, and 0 otherwise

func (*Uint248API) IsGreaterThan

func (api *Uint248API) IsGreaterThan(a, b Uint248) Uint248

IsGreaterThan returns 1 if a > b, and 0 otherwise

func (*Uint248API) IsLessThan

func (api *Uint248API) IsLessThan(a, b Uint248) Uint248

IsLessThan returns 1 if a < b, and 0 otherwise

func (*Uint248API) IsZero

func (api *Uint248API) IsZero(a Uint248) Uint248

IsZero returns 1 if a == 0, and 0 otherwise

func (*Uint248API) Mul

func (api *Uint248API) Mul(a, b Uint248) Uint248

Mul returns a * b. Overflow can happen if a * b > 2^248

func (*Uint248API) Not

func (api *Uint248API) Not(a Uint248) Uint248

Not returns 1 if a is 0, and 0 if a is 1. The user must make sure a is either 0 or 1

func (*Uint248API) Or

func (api *Uint248API) Or(a, b Uint248, other ...Uint248) Uint248

Or returns 1 if a || b [|| other[0] [|| other[1]...]] is true, and 0 otherwise a, b and other... must be 0 or 1

func (*Uint248API) Select

func (api *Uint248API) Select(s Uint248, a, b Uint248) Uint248

Select returns a if s == 1, and b if s == 0

func (*Uint248API) Sqrt

func (api *Uint248API) Sqrt(a Uint248) Uint248

Sqrt returns √a. Uses SqrtHint

func (*Uint248API) Sub

func (api *Uint248API) Sub(a, b Uint248) Uint248

Sub returns a - b. Underflow can happen if b > a

func (*Uint248API) ToBinary

func (api *Uint248API) ToBinary(v Uint248, n int) List[Uint248]

ToBinary decomposes the input v to a list (size n) of little-endian binary digits

type Uint32

type Uint32 struct {
	Val frontend.Variable
}

func ConstUint32

func ConstUint32(i interface{}) Uint32

ConstUint32 initializes a constant Uint32. This function does not generate circuit wires and should only be used outside of circuit. Supports all int and uint variants, bool, []byte (big-endian), *big.Int, and string inputs. If input is string, this function uses *big.Int SetString function to interpret the string

func (Uint32) FromValues

func (v Uint32) FromValues(vs ...frontend.Variable) CircuitVariable

func (Uint32) NumVars

func (v Uint32) NumVars() uint32

func (Uint32) String

func (v Uint32) String() string

func (Uint32) Values

func (v Uint32) Values() []frontend.Variable

type Uint32API

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

func (*Uint32API) Add

func (api *Uint32API) Add(a, b Uint32, other ...Uint32) Uint32

Add returns a + b. Overflow can happen if a + b > 2^32

func (*Uint32API) And

func (api *Uint32API) And(a, b Uint32, other ...Uint32) Uint32

And returns 1 if a && b [&& other[0] [&& other[1]...]] is true, and 0 otherwise a, b and other... must be 0 or 1

func (*Uint32API) AssertIsDifferent

func (api *Uint32API) AssertIsDifferent(a, b Uint32)

AssertIsDifferent asserts a != b

func (*Uint32API) AssertIsEqual

func (api *Uint32API) AssertIsEqual(a, b Uint32)

AssertIsEqual asserts a == b

func (*Uint32API) Div

func (api *Uint32API) Div(a, b Uint32) (quotient, remainder Uint32)

Div computes the standard unsigned integer division (like Go) and returns the quotient and remainder. Uses QuoRemHint

func (*Uint32API) FromBinary

func (api *Uint32API) FromBinary(vs ...Uint32) Uint32

FromBinary interprets the input vs as a list of little-endian binary digits and recomposes it to a Uint32

func (*Uint32API) IsEqual

func (api *Uint32API) IsEqual(a, b Uint32) Uint32

IsEqual returns 1 if a == b, and 0 otherwise

func (*Uint32API) IsGreaterThan

func (api *Uint32API) IsGreaterThan(a, b Uint32) Uint32

IsGreaterThan returns 1 if a > b, and 0 otherwise

func (*Uint32API) IsLessThan

func (api *Uint32API) IsLessThan(a, b Uint32) Uint32

IsLessThan returns 1 if a < b, and 0 otherwise

func (*Uint32API) IsZero

func (api *Uint32API) IsZero(a Uint32) Uint32

IsZero returns 1 if a == 0, and 0 otherwise

func (*Uint32API) Mul

func (api *Uint32API) Mul(a, b Uint32) Uint32

Mul returns a * b. Overflow can happen if a * b > 2^32

func (*Uint32API) Not

func (api *Uint32API) Not(a Uint32) Uint32

Not returns 1 if a is 0, and 0 if a is 1. The user must make sure a is either 0 or 1

func (*Uint32API) Or

func (api *Uint32API) Or(a, b Uint32, other ...Uint32) Uint32

Or returns 1 if a || b [|| other[0] [|| other[1]...]] is true, and 0 otherwise a, b and other... must be 0 or 1

func (*Uint32API) Select

func (api *Uint32API) Select(s Uint32, a, b Uint32) Uint32

Select returns a if s == 1, and b if s == 0

func (*Uint32API) Sqrt

func (api *Uint32API) Sqrt(a Uint32) Uint32

Sqrt returns √a. Uses SqrtHint

func (*Uint32API) Sub

func (api *Uint32API) Sub(a, b Uint32) Uint32

Sub returns a - b. Underflow can happen if b > a

func (*Uint32API) ToBinary

func (api *Uint32API) ToBinary(v Uint32, n int) List[Uint32]

ToBinary decomposes the input v to a list (size n) of little-endian binary digits

type Uint521

type Uint521 struct {
	*emulated.Element[Uint521Field]
}

func ConstUint521

func ConstUint521(i interface{}) Uint521

ConstUint521 initializes a constant Uint521. This function does not generate circuit wires and should only be used outside of circuit. Supports all int and uint variants, bool, []byte (big-endian), *big.Int, and string inputs. If input is string, this function uses *big.Int SetString function to interpret the string

func (Uint521) FromValues

func (v Uint521) FromValues(vs ...frontend.Variable) CircuitVariable

func (Uint521) NumVars

func (v Uint521) NumVars() uint32

func (Uint521) String

func (v Uint521) String() string

func (Uint521) Values

func (v Uint521) Values() []frontend.Variable

type Uint521API

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

func (*Uint521API) Add

func (api *Uint521API) Add(a, b Uint521) Uint521

Add returns a + b. The result is reduced by modulo 2^521 - 1.

func (*Uint521API) AssertIsEqual

func (api *Uint521API) AssertIsEqual(a, b Uint521)

AssertIsEqual asserts a == b

func (*Uint521API) AssertIsLessOrEqual

func (api *Uint521API) AssertIsLessOrEqual(a, b Uint521)

AssertIsLessOrEqual asserts a <= b

func (*Uint521API) Div

func (api *Uint521API) Div(a, b Uint521) (quotient, remainder Uint521)

Div computes the standard unsigned integer division (like Go) and returns the quotient and remainder. Uses QuoRemHint

func (*Uint521API) FromBinary

func (api *Uint521API) FromBinary(vs ...Uint248) Uint521

FromBinary interprets the input vs as a list of little-endian binary digits and recomposes it to a Uint521

func (*Uint521API) IsEqual

func (api *Uint521API) IsEqual(a, b Uint521) Uint248

IsEqual returns 1 if a == b, and 0 otherwise

func (*Uint521API) Mul

func (api *Uint521API) Mul(a, b Uint521) Uint521

Mul returns a * b. The result is reduced by modulo 2^521 - 1.

func (*Uint521API) Select

func (api *Uint521API) Select(s Uint248, a, b Uint521) Uint521

Select returns a if s == 1, and b if s == 0

func (*Uint521API) Sub

func (api *Uint521API) Sub(a, b Uint521) Uint521

Sub returns a - b. Underflow can happen if b > a

func (*Uint521API) ToBinary

func (api *Uint521API) ToBinary(v Uint521, n int) List[Uint248]

ToBinary decomposes the input v to a list (size n) of little-endian binary digits

type Uint521Field

type Uint521Field struct{}

func (Uint521Field) BitsPerLimb

func (f Uint521Field) BitsPerLimb() uint

func (Uint521Field) IsPrime

func (f Uint521Field) IsPrime() bool

func (Uint521Field) Modulus

func (f Uint521Field) Modulus() *big.Int

func (Uint521Field) NbLimbs

func (f Uint521Field) NbLimbs() uint

type Uint64

type Uint64 struct {
	Val frontend.Variable
}

func ConstUint64

func ConstUint64(i interface{}) Uint64

ConstUint64 initializes a constant Uint64. This function does not generate circuit wires and should only be used outside of circuit. Supports all int and uint variants, bool, []byte (big-endian), *big.Int, and string inputs. If input is string, this function uses *big.Int SetString function to interpret the string

func (Uint64) FromValues

func (v Uint64) FromValues(vs ...frontend.Variable) CircuitVariable

func (Uint64) NumVars

func (v Uint64) NumVars() uint32

func (Uint64) String

func (v Uint64) String() string

func (Uint64) Values

func (v Uint64) Values() []frontend.Variable

type Uint64API

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

func (*Uint64API) Add

func (api *Uint64API) Add(a, b Uint64, other ...Uint64) Uint64

Add returns a + b. Overflow can happen if a + b > 2^64

func (*Uint64API) And

func (api *Uint64API) And(a, b Uint64, other ...Uint64) Uint64

And returns 1 if a && b [&& other[0] [&& other[1]...]] is true, and 0 otherwise a, b and other... must be 0 or 1

func (*Uint64API) AssertIsDifferent

func (api *Uint64API) AssertIsDifferent(a, b Uint64)

AssertIsDifferent asserts a != b

func (*Uint64API) AssertIsEqual

func (api *Uint64API) AssertIsEqual(a, b Uint64)

AssertIsEqual asserts a == b

func (*Uint64API) Div

func (api *Uint64API) Div(a, b Uint64) (quotient, remainder Uint64)

Div computes the standard unsigned integer division (like Go) and returns the quotient and remainder. Uses QuoRemHint

func (*Uint64API) FromBinary

func (api *Uint64API) FromBinary(vs ...Uint64) Uint64

FromBinary interprets the input vs as a list of little-endian binary digits and recomposes it to a Uint64

func (*Uint64API) IsEqual

func (api *Uint64API) IsEqual(a, b Uint64) Uint64

IsEqual returns 1 if a == b, and 0 otherwise

func (*Uint64API) IsGreaterThan

func (api *Uint64API) IsGreaterThan(a, b Uint64) Uint64

IsGreaterThan returns 1 if a > b, and 0 otherwise

func (*Uint64API) IsLessThan

func (api *Uint64API) IsLessThan(a, b Uint64) Uint64

IsLessThan returns 1 if a < b, and 0 otherwise

func (*Uint64API) IsZero

func (api *Uint64API) IsZero(a Uint64) Uint64

IsZero returns 1 if a == 0, and 0 otherwise

func (*Uint64API) Mul

func (api *Uint64API) Mul(a, b Uint64) Uint64

Mul returns a * b. Overflow can happen if a * b > 2^64

func (*Uint64API) Not

func (api *Uint64API) Not(a Uint64) Uint64

Not returns 1 if a is 0, and 0 if a is 1. The user must make sure a is either 0 or 1

func (*Uint64API) Or

func (api *Uint64API) Or(a, b Uint64, other ...Uint64) Uint64

Or returns 1 if a || b [|| other[0] [|| other[1]...]] is true, and 0 otherwise a, b and other... must be 0 or 1

func (*Uint64API) Select

func (api *Uint64API) Select(s Uint64, a, b Uint64) Uint64

Select returns a if s == 1, and b if s == 0

func (*Uint64API) Sqrt

func (api *Uint64API) Sqrt(a Uint64) Uint64

Sqrt returns √a. Uses SqrtHint

func (*Uint64API) Sub

func (api *Uint64API) Sub(a, b Uint64) Uint64

Sub returns a - b. Underflow can happen if b > a

func (*Uint64API) ToBinary

func (api *Uint64API) ToBinary(v Uint64, n int) List[Uint64]

ToBinary decomposes the input v to a list (size n) of little-endian binary digits

type ZipMap2Func

type ZipMap2Func[T0, T1, R CircuitVariable] func(a T0, b T1) R

type ZipMap3Func

type ZipMap3Func[T0, T1, T2, R CircuitVariable] func(a T0, b T1, c T2) R

Directories

Path Synopsis
proto
gwproto
Package brevis is a reverse proxy.
Package brevis is a reverse proxy.
sdkproto
Package sdk is a reverse proxy.
Package sdk is a reverse proxy.

Jump to

Keyboard shortcuts

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