Trait miden_processor::Host
source · pub trait Host {
// Required methods
fn get_advice<P: ProcessState>(
&mut self,
process: &P,
extractor: AdviceExtractor,
) -> Result<HostResponse, ExecutionError>;
fn set_advice<P: ProcessState>(
&mut self,
process: &P,
injector: AdviceInjector,
) -> Result<HostResponse, ExecutionError>;
fn get_mast_forest(
&self,
node_digest: &RpoDigest,
) -> Option<Arc<MastForest>>;
// Provided methods
fn by_ref(&mut self) -> &mut Self { ... }
fn on_event<S: ProcessState>(
&mut self,
_process: &S,
_event_id: u32,
) -> Result<HostResponse, ExecutionError> { ... }
fn on_debug<S: ProcessState>(
&mut self,
_process: &S,
_options: &DebugOptions,
) -> Result<HostResponse, ExecutionError> { ... }
fn on_trace<S: ProcessState>(
&mut self,
_process: &S,
_trace_id: u32,
) -> Result<HostResponse, ExecutionError> { ... }
fn on_assert_failed<S: ProcessState>(
&mut self,
process: &S,
err_code: u32,
) -> ExecutionError { ... }
fn pop_adv_stack<S: ProcessState>(
&mut self,
process: &S,
) -> Result<Felt, ExecutionError> { ... }
fn pop_adv_stack_word<S: ProcessState>(
&mut self,
process: &S,
) -> Result<Word, ExecutionError> { ... }
fn pop_adv_stack_dword<S: ProcessState>(
&mut self,
process: &S,
) -> Result<[Word; 2], ExecutionError> { ... }
fn get_adv_merkle_path<S: ProcessState>(
&mut self,
process: &S,
) -> Result<MerklePath, ExecutionError> { ... }
}Expand description
Defines an interface by which the VM can make requests to the host.
There are three variants of requests, these can get advice, set advice and invoke the
debug handler. The requests are specified by the AdviceExtractor, AdviceInjector and
DebugOptions enums which target the get_advice, set_advice and on_debug methods
respectively. The host is responsible for handling the requests and returning the results to
the VM in the form of HostResponse. The host is provided with a reference to the current
state of the VM (ProcessState), which it can use to extract the data required to fulfill the
request.
Required Methods§
sourcefn get_advice<P: ProcessState>(
&mut self,
process: &P,
extractor: AdviceExtractor,
) -> Result<HostResponse, ExecutionError>
fn get_advice<P: ProcessState>( &mut self, process: &P, extractor: AdviceExtractor, ) -> Result<HostResponse, ExecutionError>
Returns the requested advice, specified by AdviceExtractor, from the host to the VM.
sourcefn set_advice<P: ProcessState>(
&mut self,
process: &P,
injector: AdviceInjector,
) -> Result<HostResponse, ExecutionError>
fn set_advice<P: ProcessState>( &mut self, process: &P, injector: AdviceInjector, ) -> Result<HostResponse, ExecutionError>
Sets the requested advice, specified by AdviceInjector, on the host.
sourcefn get_mast_forest(&self, node_digest: &RpoDigest) -> Option<Arc<MastForest>>
fn get_mast_forest(&self, node_digest: &RpoDigest) -> Option<Arc<MastForest>>
Returns MAST forest corresponding to the specified digest, or None if the MAST forest for this digest could not be found in this Host.
Provided Methods§
sourcefn by_ref(&mut self) -> &mut Self
fn by_ref(&mut self) -> &mut Self
Creates a “by reference” host for this instance.
The returned adapter also implements Host and will simply mutably borrow this instance.
sourcefn on_event<S: ProcessState>(
&mut self,
_process: &S,
_event_id: u32,
) -> Result<HostResponse, ExecutionError>
fn on_event<S: ProcessState>( &mut self, _process: &S, _event_id: u32, ) -> Result<HostResponse, ExecutionError>
Handles the event emitted from the VM.
sourcefn on_debug<S: ProcessState>(
&mut self,
_process: &S,
_options: &DebugOptions,
) -> Result<HostResponse, ExecutionError>
fn on_debug<S: ProcessState>( &mut self, _process: &S, _options: &DebugOptions, ) -> Result<HostResponse, ExecutionError>
Handles the debug request from the VM.
sourcefn on_trace<S: ProcessState>(
&mut self,
_process: &S,
_trace_id: u32,
) -> Result<HostResponse, ExecutionError>
fn on_trace<S: ProcessState>( &mut self, _process: &S, _trace_id: u32, ) -> Result<HostResponse, ExecutionError>
Handles the trace emitted from the VM.
sourcefn on_assert_failed<S: ProcessState>(
&mut self,
process: &S,
err_code: u32,
) -> ExecutionError
fn on_assert_failed<S: ProcessState>( &mut self, process: &S, err_code: u32, ) -> ExecutionError
Handles the failure of the assertion instruction.
sourcefn pop_adv_stack<S: ProcessState>(
&mut self,
process: &S,
) -> Result<Felt, ExecutionError>
fn pop_adv_stack<S: ProcessState>( &mut self, process: &S, ) -> Result<Felt, ExecutionError>
Pops an element from the advice stack and returns it.
§Errors
Returns an error if the advice stack is empty.
sourcefn pop_adv_stack_word<S: ProcessState>(
&mut self,
process: &S,
) -> Result<Word, ExecutionError>
fn pop_adv_stack_word<S: ProcessState>( &mut self, process: &S, ) -> Result<Word, ExecutionError>
Pops a word (4 elements) from the advice stack and returns it.
Note: a word is popped off the stack element-by-element. For example, a [d, c, b, a, ...]
stack (i.e., d is at the top of the stack) will yield [d, c, b, a].
§Errors
Returns an error if the advice stack does not contain a full word.
sourcefn pop_adv_stack_dword<S: ProcessState>(
&mut self,
process: &S,
) -> Result<[Word; 2], ExecutionError>
fn pop_adv_stack_dword<S: ProcessState>( &mut self, process: &S, ) -> Result<[Word; 2], ExecutionError>
Pops a double word (8 elements) from the advice stack and returns them.
Note: words are popped off the stack element-by-element. For example, a
[h, g, f, e, d, c, b, a, ...] stack (i.e., h is at the top of the stack) will yield
two words: [h, g, f,e ], [d, c, b, a].
§Errors
Returns an error if the advice stack does not contain two words.
sourcefn get_adv_merkle_path<S: ProcessState>(
&mut self,
process: &S,
) -> Result<MerklePath, ExecutionError>
fn get_adv_merkle_path<S: ProcessState>( &mut self, process: &S, ) -> Result<MerklePath, ExecutionError>
Returns a path to a node at the specified depth and 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.