Trait miden_processor::AdviceProvider
source · pub trait AdviceProvider {
// Required methods
fn read_tape(&mut self) -> Result<Felt, ExecutionError>;
fn read_tape_w(&mut self) -> Result<Word, ExecutionError>;
fn read_tape_dw(&mut self) -> Result<[Word; 2], ExecutionError>;
fn write_tape(&mut self, source: AdviceSource) -> Result<(), ExecutionError>;
fn insert_into_map(
&mut self,
key: Word,
values: Vec<Felt>
) -> Result<(), ExecutionError>;
fn get_tree_node(
&self,
root: Word,
depth: Felt,
index: Felt
) -> Result<Word, ExecutionError>;
fn get_merkle_path(
&self,
root: Word,
depth: Felt,
index: Felt
) -> Result<MerklePath, ExecutionError>;
fn update_merkle_leaf(
&mut self,
root: Word,
index: Felt,
leaf_value: Word,
update_in_copy: bool
) -> Result<MerklePath, ExecutionError>;
fn advance_clock(&mut self);
// Provided method
fn by_ref(&mut self) -> &mut Self { ... }
}Expand description
Common behavior of advice providers for program execution.
An advice provider supplies non-deterministic inputs to the processor.
- Provide a tape functionality that yields elements as a stack (last in, first out). These can be yielded as elements, words or double words.
- Provide a map functionality that will store temporary tapes that can be appended to the main tape. This operation should not allow key overwrite; that is: if a given key exists, the implementation should error if the user attempts to insert this key again, instead of the common behavior of the maps to simply override the previous contents. This is a design decision to increase the runtime robustness of the execution.
- Provide merkle sets, that are mappings from a Merkle root its tree. The tree should yield nodes & leaves, and will provide a Merkle path if a leaf is updated.
Required Methods§
sourcefn read_tape(&mut self) -> Result<Felt, ExecutionError>
fn read_tape(&mut self) -> Result<Felt, ExecutionError>
Pops an element from the advice tape and returns it.
Errors
Returns an error if the advice tape is empty.
sourcefn read_tape_w(&mut self) -> Result<Word, ExecutionError>
fn read_tape_w(&mut self) -> Result<Word, ExecutionError>
Pops a word (4 elements) from the advice tape and returns it.
Note: a word is always stored as little-endian. A [...,a,b,c,d] tape will yield
[d,c,b,a].
Errors
Returns an error if the advice tape does not contain a full word.
sourcefn read_tape_dw(&mut self) -> Result<[Word; 2], ExecutionError>
fn read_tape_dw(&mut self) -> Result<[Word; 2], ExecutionError>
Pops a double word (8 elements) from the advice tape and returns them.
Note: a double word is always stored as little-endian. A [...,a,b,c,d,e,f,g,h] tape will
yield [h,g,f,e],[,d,c,b,a].
Errors
Returns an error if the advice tape does not contain two words.
sourcefn write_tape(&mut self, source: AdviceSource) -> Result<(), ExecutionError>
fn write_tape(&mut self, source: AdviceSource) -> Result<(), ExecutionError>
Writes values specified by the source to the head of the advice tape.
sourcefn insert_into_map(
&mut self,
key: Word,
values: Vec<Felt>
) -> Result<(), ExecutionError>
fn insert_into_map( &mut self, key: Word, values: Vec<Felt> ) -> Result<(), ExecutionError>
Maps a key to a value list to be yielded by write_tape_from_map.
Errors
Returns an error if the key is already present in the advice map.
sourcefn get_tree_node(
&self,
root: Word,
depth: Felt,
index: Felt
) -> Result<Word, ExecutionError>
fn get_tree_node( &self, root: Word, depth: Felt, index: Felt ) -> Result<Word, ExecutionError>
Returns a node/leaf for the given depth and index in a Merkle tree with the given root.
Errors
Returns an error if:
- A Merkle tree for the specified root cannot be found in this advice provider.
- The specified depth is either zero or greater than the depth of the Merkle tree identified by the specified root.
- Value of the node at the specified depth and index is not known to this advice provider.
sourcefn get_merkle_path(
&self,
root: Word,
depth: Felt,
index: Felt
) -> Result<MerklePath, ExecutionError>
fn get_merkle_path( &self, root: Word, depth: Felt, index: Felt ) -> Result<MerklePath, ExecutionError>
Returns a path to a node at the specified index in a Merkle tree with the specified root.
Errors
Returns an error if:
- A Merkle tree for the specified root cannot be found in this advice provider.
- The specified depth is either zero or greater than the depth of the Merkle tree identified by the specified root.
- Path to the node at the specified depth and index is not known to this advice provider.
sourcefn update_merkle_leaf(
&mut self,
root: Word,
index: Felt,
leaf_value: Word,
update_in_copy: bool
) -> Result<MerklePath, ExecutionError>
fn update_merkle_leaf( &mut self, root: Word, index: Felt, leaf_value: Word, update_in_copy: bool ) -> Result<MerklePath, ExecutionError>
Updates a leaf at the specified index on an existing Merkle tree with the specified root; returns the Merkle path from the updated leaf to the new root.
If update_in_copy is set to true, retains both the tree prior to the update (i.e. with
the original root), and the new updated tree. Otherwise, the old merkle set is removed from
this provider.
Errors
Returns an error if:
- A Merkle tree for the specified root cannot be found in this advice provider.
- The specified depth is either zero or greater than the depth of the Merkle tree identified by the specified root.
- Path to the leaf at the specified index in the specified Merkle tree is not known to this advice provider.
sourcefn advance_clock(&mut self)
fn advance_clock(&mut self)
Increments the clock cycle.
This is used to keep the state of the VM in sync with the state of the advice provider, and should be incrementally updated when called.