Trait miden_processor::Host

source ·
pub trait Host {
    // Required methods
    fn get_advice<S: ProcessState>(
        &mut self,
        process: &S,
        extractor: AdviceExtractor
    ) -> Result<HostResponse, ExecutionError>;
    fn set_advice<S: ProcessState>(
        &mut self,
        process: &S,
        injector: AdviceInjector
    ) -> Result<HostResponse, ExecutionError>;

    // 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§

source

fn get_advice<S: ProcessState>( &mut self, process: &S, extractor: AdviceExtractor ) -> Result<HostResponse, ExecutionError>

Returns the requested advice, specified by AdviceExtractor, from the host to the VM.

source

fn set_advice<S: ProcessState>( &mut self, process: &S, injector: AdviceInjector ) -> Result<HostResponse, ExecutionError>

Sets the requested advice, specified by AdviceInjector, on the host.

Provided Methods§

source

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.

source

fn on_event<S: ProcessState>( &mut self, process: &S, event_id: u32 ) -> Result<HostResponse, ExecutionError>

Handles the event emitted from the VM.

source

fn on_debug<S: ProcessState>( &mut self, process: &S, options: &DebugOptions ) -> Result<HostResponse, ExecutionError>

Handles the debug request from the VM.

source

fn on_trace<S: ProcessState>( &mut self, process: &S, trace_id: u32 ) -> Result<HostResponse, ExecutionError>

Handles the trace emmited from the VM.

source

fn on_assert_failed<S: ProcessState>( &mut self, process: &S, err_code: u32 ) -> ExecutionError

Handles the failure of the assertion instruction.

source

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.

source

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.

source

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.

source

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.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<'a, H> Host for &'a mut H
where H: Host,

source§

fn get_advice<S: ProcessState>( &mut self, process: &S, extractor: AdviceExtractor ) -> Result<HostResponse, ExecutionError>

source§

fn set_advice<S: ProcessState>( &mut self, process: &S, injector: AdviceInjector ) -> Result<HostResponse, ExecutionError>

source§

fn on_debug<S: ProcessState>( &mut self, process: &S, options: &DebugOptions ) -> Result<HostResponse, ExecutionError>

source§

fn on_event<S: ProcessState>( &mut self, process: &S, event_id: u32 ) -> Result<HostResponse, ExecutionError>

source§

fn on_trace<S: ProcessState>( &mut self, process: &S, trace_id: u32 ) -> Result<HostResponse, ExecutionError>

source§

fn on_assert_failed<S: ProcessState>( &mut self, process: &S, err_code: u32 ) -> ExecutionError

Implementors§