Skip to main content
Version: Next (unstable)

Usage

Before you can use Miden VM, you'll need to make sure you have Rust installed. Miden VM v0.19 requires Rust version 1.96 or later.

Miden VM consists of several crates, each of which exposes a small set of functionality. The most notable of these crates are:

  • miden-processor, which can be used to execute Miden VM programs.
  • miden-prover, which can be used to execute Miden VM programs and generate proofs of their execution.
  • miden-verifier, which can be used to verify proofs of program execution generated by Miden VM prover.

The above functionality is also exposed via the single miden-vm crate, which also provides a CLI interface for interacting with Miden VM.

CLI interface​

Compiling Miden VM​

To compile Miden VM into a binary, we have a Makefile with the following tasks:

make exec

This will place an optimized, multi-threaded miden-vm executable into the ./target/optimized directory. It is equivalent to executing:

cargo build --profile optimized --features concurrent,executable

If you would like to enable single-threaded mode, you can compile Miden VM using the following command:

make exec-single

Controlling parallelism​

Internally, Miden VM uses rayon for parallel computations. To control the number of threads used to generate a STARK proof, you can use RAYON_NUM_THREADS environment variable.

SIMD acceleration​

Miden VM execution and proof generation can be accelerated via vectorized instructions. Currently, SIMD acceleration can be enabled on platforms supporting SVE and AVX2 instructions.

To compile Miden VM with AVX2 acceleration enabled, you can run the following command:

make exec-avx2

To compile Miden VM with SVE acceleration enabled, you can run the following command:

make exec-sve

This will place the resulting miden-vm executable into the ./target/optimized directory.

SVE/AVX2 acceleration is currently applicable only to recursive proofs which can be generated using the -r flag.

Running Miden VM​

Once the executable has been compiled, you can run Miden VM like so:

./target/optimized/miden-vm [subcommand] [parameters]

Currently, Miden VM can be executed with the following subcommands:

  • run - this will execute a Miden assembly program and output the result, but will not generate a proof of execution.
  • prove - this will execute a Miden assembly program, and will also generate a STARK proof of execution.
  • verify - this will verify a previously generated proof of execution for a given program.
  • compile - this will compile a Miden assembly program (i.e., build a program MAST) and outputs stats about the compilation process.
  • example - this will execute a Miden assembly example program, generate a STARK proof of execution and verify it. Currently, it is possible to run blake3 and fibonacci examples.

All of the above subcommands require various parameters to be provided. To get more detailed help on what is needed for a given subcommand, you can run the following:

./target/optimized/miden-vm [subcommand] --help

For example:

./target/optimized/miden-vm prove --help

To execute a program using the Miden VM there needs to be a .masm file containing the Miden Assembly code and a .inputs file containing the inputs.

Enabling logging​

You can use MIDEN_LOG environment variable to control how much logging output the VM produces. For example:

MIDEN_LOG=trace ./target/optimized/miden-vm [subcommand] [parameters]

If the level is not specified, warn level is set as default.

Routine VM execution and proving spans use TRACE. Set MIDEN_LOG=info,miden::vm=trace to enable them, or MIDEN_LOG=info,miden::vm::prove=trace for STARK proving only.

Debugging procedures​

You can inspect VM state by importing the miden::core::debug module and calling its print procedures from a MASM program.

./target/optimized/miden-vm run [path_to.masm]

After execution, run prints the stack outputs and the unpadded and padded sizes of the VM trace components.

Precompile policies​

run, prove, and verify accept four optional limits:

OptionCeilingType/unit
--max-precompile-elementsStructural elements in each accounting scopeu64 field elements
--max-precompile-hash-bytesTotal hash input size in each scopeu64 bytes
--max-precompile-msm-termsTerms in one MSMu32 terms
--max-precompile-total-msm-termsTotal MSM terms in each scopeu64 terms

Each supplied value overrides the corresponding field in both execution and verification policies. Their accounting remains independent: execution counts all guest-induced deferred work, including repeated registration attempts; verification counts the final root-reachable witness. Verification limits apply during export, prover admission, and native deferred verification. Standalone verify applies only the verification policy. Complete precompile STARKs contain no portable witness to admit.

Unspecified fields retain each scope's library defaults, supplied by miden_vm::default_execution_precompile_limits() and miden_vm::default_verification_precompile_limits(). The CLI defines no separate policy defaults. The per-MSM and total-MSM term ceilings are independent: changing one preserves the other. Class counts, per-hash item sizes, and uint/curve-specific limits keep their library defaults; advanced callers can configure these through the Rust interfaces.

Hash byte sizes accept bare integers or case-sensitive K/M/G (powers of 1000) and Ki/Mi/Gi (powers of 1024) suffixes. Elements and term counts use unsigned decimal integers within the listed types' ranges. Zero is a real ceiling, never an unlimited sentinel. Each option may be supplied once. For example:

miden-vm prove program.masm \
--max-precompile-hash-bytes 16Mi \
--max-precompile-msm-terms 8192 \
--max-precompile-total-msm-terms 131072

Raising these logical ceilings does not change hard transport, allocation, or root-count safety ceilings, or combine different work classes into an aggregate budget.

Prover memory budgets​

For prove, --max-prover-memory SIZE sets the modelled peak-memory budget for each enabled proving stage. Default proving includes the VM and any precompile STARK; --deferred runs only the VM proving stage and exports the precompile witness. The explicit option sets the same budget for both stages. When omitted, each stage uses its own library default (Prover::DEFAULT_MAX_PROVER_MEMORY_BYTES and Prover::DEFAULT_MAX_PRECOMPILE_PROVER_MEMORY_BYTES). The option uses the byte suffixes described above. Independent stage budgets remain configurable through the Rust interfaces.

These are separate modelled proving-stage budgets rather than a combined allocation cap or a bound on total process memory. Precompile witness preparation/Session import and concurrent proofs are outside the proving budgets. Logical work limits remain independent.

run reads stack outputs from the execution claim and reports trace sizes from the recording. Core rows include HALT. Chiplet rows include aligned hash controller rows, expanded AEAD and ACE work, and the mandatory padding row. Eidos compression rows and their padded height are upper bounds because the prover combines repeated compression requests. The byte-pair lookup table has a fixed height. If the exact heights already require more than --max-prover-memory at the minimum Eidos height, run fails. If only the upper bound exceeds the limit, run warns and returns the outputs. The prover enforces its budget using the actual padded heights.

Complete and deferred proofs​

prove follows the library's Prover::prove_full workflow by default: it generates the VM STARK and any required precompile STARK, without exporting a raw precompile witness. prove --complete explicitly selects the same behavior.

Use prove --deferred to opt into the library's Prover::prove workflow: generate only the VM STARK and include the raw precompile witness in the .proof file for later proving. That witness includes raw precompile inputs and can reveal inputs taken from private advice. Only use this option when that disclosure is intended; keep the default complete proof for publication without the raw witness. The two proving options cannot be combined.

Without precompile work, the VM STARK alone is already complete in either mode. Deferral applies to the precompile STARK; normal execution still checks precompile predicates natively. Proving reports the resulting proof status and, for a deferred proof, the witness-export disclosure, its missing precompile STARK and outstanding root.

verify accepts valid complete and deferred proofs by default. For a deferred proof, the verifier authenticates the VM STARK, checks the witness limits, binds its reconstructed root to the VM-authenticated root, and evaluates it natively. Only after these checks succeed does it exit with status 0 and print Proof status: deferred, the VM STARK conjectured and proven security levels, the natively validated witness, missing precompile STARK, and outstanding root. Native validation does not establish a cryptographically complete precompile proof.

Use verify --require-complete to require a fully STARK-backed proof. A serialized deferred artifact then exits with status 1 before STARK verification or native witness evaluation. This is a policy rejection based on unauthenticated proof metadata; it does not establish whether the proof is valid.

Complete results exit with status 0 with or without --require-complete. They print Proof status: complete and the minimum conjectured and proven security levels of the verified STARKs (the VM levels alone if there is no precompile work). Invalid STARKs, malformed or false witnesses, root mismatches, and admission failures always fail verification.

Inputs​

As described here the Miden VM can consume public and secret inputs.

  • Public inputs:
    • operand_stack - can be supplied to the VM to initialize the stack with the desired values before a program starts executing. If the number of provided input values is less than 16, the input stack will be padded with zeros to the length of 16. The maximum number of the stack inputs is limited by 16 values, providing more than 16 values will cause an error.
  • Secret (or nondeterministic) inputs:
    • advice_stack - can be supplied to the VM. There is no limit on how much data the advice provider can hold. This is provided as a string array where each string entry represents a field element.
    • advice_map - is supplied as a map of 64-character hex keys, each mapped to an array of numbers. The hex keys are interpreted as 4 field elements and the arrays of numbers are interpreted as arrays of field elements.
    • merkle_store - the Merkle store is container that allows the user to define merkle_tree, sparse_merkle_tree and partial_merkle_tree data structures.
      • merkle_tree - is supplied as an array of 64-character hex values where each value represents a leaf (4 elements) in the tree.
      • sparse_merkle_tree - is supplied as an array of tuples of the form (number, 64-character hex string). The number represents the leaf index and the hex string represents the leaf value (4 elements).
      • partial_merkle_tree - is supplied as an array of tuples of the form ((number, number), 64-character hex string). The internal tuple represents the leaf depth and index at this depth, and the hex string represents the leaf value (4 elements).

Check out the comparison example to see how secret inputs work.

After a program finishes executing, the elements that remain on the stack become the outputs of the program. Notice that the number of values on the operand stack at the end of the program execution can not be greater than 16, otherwise the program will return an error. The truncate_stack utility procedure from the core library could be used to conveniently truncate the stack at the end of the program.

Fibonacci example​

In the miden-vm/masm-examples/fib directory, we provide a very simple Fibonacci calculator example. This example computes the 1001st term of the Fibonacci sequence. You can execute this example on Miden VM like so:

./target/optimized/miden-vm run miden-vm/masm-examples/fib/fib.masm

Capturing Output​

This will run the example code to completion and will output the top element remaining on the stack.

If you want the output of the program in a file, you can use the --output or -o flag and specify the path to the output file. For example:

./target/optimized/miden-vm run miden-vm/masm-examples/fib/fib.masm -o fib.out

This will dump the output of the program into the fib.out file. The output file will contain the state of the stack at the end of the program execution.

Running with miden::core::debug procedures​

Inside miden-vm/masm-examples/fib/fib.masm, import the miden::core::debug module before begin, then call one of its procedures, such as exec.debug::print_stack, anywhere between begin and end:

use miden::core::debug

begin
# ...
exec.debug::print_stack
# ...
end

Then run:

./target/optimized/miden-vm run miden-vm/masm-examples/fib/fib.masm

You should see output similar to "Stack state before step ..."