pub trait Snippet {
Show 18 methods
// Required methods
fn entrypoint(&self) -> String;
fn inputs(&self) -> Vec<String>;
fn input_types(&self) -> Vec<DataType>;
fn output_types(&self) -> Vec<DataType>;
fn outputs(&self) -> Vec<String>;
fn stack_diff(&self) -> isize;
fn function_code(&self, library: &mut SnippetState) -> String;
fn crash_conditions(&self) -> Vec<String>;
fn gen_input_states(&self) -> Vec<ExecutionState>;
fn common_case_input_state(&self) -> ExecutionState;
fn worst_case_input_state(&self) -> ExecutionState;
fn rust_shadowing(
&self,
stack: &mut Vec<BFieldElement>,
std_in: Vec<BFieldElement>,
secret_in: Vec<BFieldElement>,
memory: &mut HashMap<BFieldElement, BFieldElement>
);
// Provided methods
fn function_code_as_instructions(
&self,
library: &mut SnippetState
) -> Vec<LabelledInstruction> { ... }
fn link_for_isolated_run(&self, words_statically_allocated: usize) -> String { ... }
fn link_and_run_tasm_for_test(
&self,
stack: &mut Vec<BFieldElement>,
std_in: Vec<BFieldElement>,
secret_in: Vec<BFieldElement>,
memory: &mut HashMap<BFieldElement, BFieldElement>,
words_statically_allocated: usize
) -> VmOutputState { ... }
fn link_and_run_tasm_for_bench(
&self,
stack: &mut Vec<BFieldElement>,
std_in: Vec<BFieldElement>,
secret_in: Vec<BFieldElement>,
memory: &mut HashMap<BFieldElement, BFieldElement>,
words_statically_allocated: usize
) -> Result<ExecutionResult> { ... }
fn link_and_run_tasm_from_state_for_test(
&self,
execution_state: &mut ExecutionState
) -> VmOutputState { ... }
fn link_and_run_tasm_from_state_for_bench(
&self,
execution_state: &mut ExecutionState
) -> Result<ExecutionResult> { ... }
}
Required Methods§
sourcefn entrypoint(&self) -> String
fn entrypoint(&self) -> String
The name of a Snippet
This is used as a unique identifier, e.g. when generating labels.
fn input_types(&self) -> Vec<DataType>
fn output_types(&self) -> Vec<DataType>
sourcefn stack_diff(&self) -> isize
fn stack_diff(&self) -> isize
The stack difference
sourcefn function_code(&self, library: &mut SnippetState) -> String
fn function_code(&self, library: &mut SnippetState) -> String
The function
sourcefn crash_conditions(&self) -> Vec<String>
fn crash_conditions(&self) -> Vec<String>
Ways in which this snippet can crash at runtime
sourcefn gen_input_states(&self) -> Vec<ExecutionState>
fn gen_input_states(&self) -> Vec<ExecutionState>
Examples of valid initial states for running this snippet
fn common_case_input_state(&self) -> ExecutionState
fn worst_case_input_state(&self) -> ExecutionState
fn rust_shadowing( &self, stack: &mut Vec<BFieldElement>, std_in: Vec<BFieldElement>, secret_in: Vec<BFieldElement>, memory: &mut HashMap<BFieldElement, BFieldElement> )
Provided Methods§
fn function_code_as_instructions( &self, library: &mut SnippetState ) -> Vec<LabelledInstruction>
fn link_for_isolated_run(&self, words_statically_allocated: usize) -> String
fn link_and_run_tasm_for_test( &self, stack: &mut Vec<BFieldElement>, std_in: Vec<BFieldElement>, secret_in: Vec<BFieldElement>, memory: &mut HashMap<BFieldElement, BFieldElement>, words_statically_allocated: usize ) -> VmOutputState
fn link_and_run_tasm_for_bench( &self, stack: &mut Vec<BFieldElement>, std_in: Vec<BFieldElement>, secret_in: Vec<BFieldElement>, memory: &mut HashMap<BFieldElement, BFieldElement>, words_statically_allocated: usize ) -> Result<ExecutionResult>
fn link_and_run_tasm_from_state_for_test( &self, execution_state: &mut ExecutionState ) -> VmOutputState
fn link_and_run_tasm_from_state_for_bench( &self, execution_state: &mut ExecutionState ) -> Result<ExecutionResult>
Implementors§
impl Snippet for U32IsOdd
impl Snippet for IsU32
impl Snippet for LeadingZerosU32
impl Snippet for OrU32
impl Snippet for SafeAdd
impl Snippet for SafeMul
impl Snippet for SafeSub
impl Snippet for ShiftLeftU32
impl Snippet for ShiftRightU32
impl Snippet for AddU64
impl Snippet for AndU64
impl Snippet for DecrU64
impl Snippet for Div2U64
impl Snippet for DivModU64
impl Snippet for DoublePow2U64
impl Snippet for EqU64
impl Snippet for IncrU64
impl Snippet for IndexOfLastNonZeroBitU64
impl Snippet for LeadingZerosU64
impl Snippet for Log2FloorU64
impl Snippet for LtStandardU64
This lt_standard_u64
does consume its argument.
The fastest way we know is to calculate without consuming, and then pop the operands. This is because there are three branches, so sharing cleanup unconditionally means less branching (fewer cycles) and less local cleanup (smaller program).
impl Snippet for LtU64
This lt_u64
does not consume its arguments, which is the norm for tasm functions.
See LtStandardU64
for a variant that does.
impl Snippet for OrU64
impl Snippet for PopCountU64
impl Snippet for Pow2U64
impl Snippet for SafeMulU64
impl Snippet for ShiftLeftU64
impl Snippet for ShiftRightU64
impl Snippet for SubU64
impl Snippet for WrappingMulU64
impl Snippet for XorU64
impl Snippet for AddU128
impl Snippet for ShiftLeftU128
impl Snippet for ShiftRightU128
impl Snippet for SubU128
impl Snippet for EqDigest
impl Snippet for HashVarlen
impl Snippet for LoadAuthPathFromSecretInSafeList
impl Snippet for LoadAuthPathFromSecretInUnsafeList
impl Snippet for LoadAuthPathFromStdInSafeList
impl Snippet for LoadAuthPathFromStdInUnsafeList
impl Snippet for ReverseDigest
impl Snippet for SampleIndices
impl Snippet for SwapDigest
impl Snippet for LoadFromInput
Load a list of words from the input source into memory. The first element of the input source is the length of the list that is loaded into memory. Returns a pointer to the first element in memory.
impl Snippet for LoadStructFromInput
Load several list of words from the input source into memory.
The first element of each list is the length of the list
that is loaded into memory. Returns a pointer to the first element
in memory. This function is named load_struct_from_input
because
structs are encoded as a sequence of length-prepended lists of words.
Note that the field_count
input argument may never be set through
user input, rather it should be known statically.
This snippet assumes that the dynamic allocator will allocate all
fields contiguously in memory.
impl Snippet for ReadSecret
impl Snippet for ReadStdIn
impl Snippet for GetLength
impl Snippet for GetPointerList
impl Snippet for All
impl Snippet for Filter
impl Snippet for Map
impl Snippet for Zip
impl Snippet for MultisetEquality
impl Snippet for Range
impl Snippet for SafeGet
impl Snippet for SafeLength
impl Snippet for SafeNew
impl Snippet for SafePop
impl Snippet for SafePush
impl Snippet for SafeSet
impl Snippet for SafeSetLength
impl Snippet for UnsafeGet
impl Snippet for UnsafeLength
impl Snippet for UnsafeNew
impl Snippet for UnsafePop
impl Snippet for UnsafePush
A parameterized version of Push
where N
is the size of an element in the list
impl Snippet for UnsafeSet
impl Snippet for UnsafeSetLength
impl Snippet for DynMalloc
impl Snippet for MemCpy
impl Snippet for PushRamToStack
impl Snippet for BagPeaks
impl Snippet for CalculateNewPeaksFromAppend
impl Snippet for MmrCalculateNewPeaksFromLeafMutationMtIndices
impl Snippet for DataIndexToNodeIndex
impl Snippet for GetHeightFromDataIndex
impl Snippet for MmrLeafIndexToMtIndexAndPeakIndex
impl Snippet for MmrLeftChild
impl Snippet for MmrLeftMostAncestor
impl Snippet for MmrLoadFromSecretInThenVerify
impl Snippet for MmrNonLeafNodesLeftUsingAnd
impl Snippet for MmrRightChild
impl Snippet for MmrRightChildAndHeight
impl Snippet for MmrRightLineageCountAndHeight
impl Snippet for MmrRightLineageLength
impl Snippet for MmrVerifyFromMemory
impl Snippet for MmrVerifyLeafMembershipFromSecretIn
impl Snippet for Commit
impl Snippet for GetSwbfIndices
impl Snippet for BfeAdd
impl Snippet for Lsb
impl Snippet for Neg
impl Snippet for Sub
impl Snippet for DummyTestSnippetA
impl Snippet for DummyTestSnippetB
impl Snippet for DummyTestSnippetC
impl Snippet for GetField
impl Snippet for GetFieldWithSize
impl<H: AlgebraicHasher + Debug> Snippet for MtApVerifyFromSecretInput<H>
TVM assembly to verify Merkle authentication paths
input: number of authentication paths, merkle root, authentication paths, each one preceded by the corresponding node index in the merkle tree, where the authentication path starts
output: Result<(), VMFail>
uses RAM at address 0 to store the number of authentication paths