Miden processor

This crate contains an implementation of Miden VM processor. The purpose of the processor is to execute a program and to generate a program execution trace. This trace is then used by Miden VM to generate a proof of correct execution of the program.

Usage

The processor exposes two functions which can be used to execute programs: execute() and execute_iter(). Both of these functions take the same arguments:

The execute() function returns a Result<ExecutionTrace, ExecutionError> which will contain the execution trace of the program if the execution was successful, or an error, if the execution failed. Internally, the VM then passes this execution trace to the prover to generate a proof of a correct execution of the program.

The execute_iter() function returns a VmStateIterator which can be used to iterate over the cycles of the executed program for debug purposes. In fact, when we execute a program using this function, a lot of the debug information is retained and we can get a precise picture of the VM's state at any cycle. Moreover, if the execution results in an error, the VmStateIterator can still be used to inspect VM states right up to the cycle at which the error occurred.

For example: ```Rust use midenassembly::Assembler; use midenprocessor::{execute, execute_iter, ProgramInputs};

// instantiate the assembler let assembler = Assembler::default();

// compile Miden assembly source code into a program let program = assembler.compile("begin push.3 push.5 add end").unwrap();

// execute the program with no inputs let trace = execute(&program, &ProgramInputs::none()).unwrap();

// now, execute the same program in debug mode and iterate over VM states for vmstate in executeiter(&program, &ProgramInputs::none()) { match vmstate { Ok(vmstate) => println!("{:?}", vmstate), Err() => println!("something went terribly wrong!"), } } ```

Processor components

The processor is organized into several components: * The decoder, which is responsible for decoding instructions and managing control flow. * The stack, which is responsible for executing instructions against the stack. * The range-checker, which is responsible for checking whether values can fit into 16 bits. * The chiplets module, which contains specialized chiplets responsible for handling complex computations (e.g., hashing) as well as random access memory.

These components are connected via two busses: * The range-checker bus, which links stack and chiplets modules with the range-checker. * The chiplet bus, which links stack and the decoder with the chiplets module.

A much more in-depth description of Miden VM design is available here.

Crate features

Miden processor can be compiled with the following features:

To compile with no_std, disable default features via --no-default-features flag.

License

This project is MIT licensed.