Skip to main content

miden_tx/executor/
program_executor.rs

1use miden_processor::advice::AdviceInputs;
2use miden_processor::{
3    ExecutionError,
4    ExecutionOptions,
5    ExecutionOutput,
6    FastProcessor,
7    FutureMaybeSend,
8    Host,
9    Program,
10    StackInputs,
11};
12
13/// A transaction-scoped program executor used by
14/// [`TransactionExecutor`](super::TransactionExecutor).
15///
16/// TODO: Move this trait into `miden-vm` once the executor boundary is
17/// consolidated there.
18pub trait ProgramExecutor {
19    /// Create a new executor configured with the provided transaction inputs and options.
20    fn new(
21        stack_inputs: StackInputs,
22        advice_inputs: AdviceInputs,
23        options: ExecutionOptions,
24    ) -> Self
25    where
26        Self: Sized;
27
28    /// Execute the provided program against the given host.
29    fn execute<H: Host + Send>(
30        self,
31        program: &Program,
32        host: &mut H,
33    ) -> impl FutureMaybeSend<Result<ExecutionOutput, ExecutionError>>;
34}
35
36impl ProgramExecutor for FastProcessor {
37    fn new(
38        stack_inputs: StackInputs,
39        advice_inputs: AdviceInputs,
40        options: ExecutionOptions,
41    ) -> Self {
42        FastProcessor::new_with_options(stack_inputs, advice_inputs, options)
43    }
44
45    fn execute<H: Host + Send>(
46        self,
47        program: &Program,
48        host: &mut H,
49    ) -> impl FutureMaybeSend<Result<ExecutionOutput, ExecutionError>> {
50        FastProcessor::execute(self, program, host)
51    }
52}