14 releases (9 breaking)

new 0.11.0 Nov 5, 2024
0.9.1 Apr 4, 2024
0.8.0 Feb 27, 2024
0.7.0 Oct 11, 2023
0.3.0 Nov 24, 2022

#595 in Magic Beans

Download history 1548/week @ 2024-07-19 2609/week @ 2024-07-26 2076/week @ 2024-08-02 1826/week @ 2024-08-09 1922/week @ 2024-08-16 1819/week @ 2024-08-23 805/week @ 2024-08-30 1379/week @ 2024-09-06 1557/week @ 2024-09-13 1445/week @ 2024-09-20 911/week @ 2024-09-27 1345/week @ 2024-10-04 883/week @ 2024-10-11 893/week @ 2024-10-18 365/week @ 2024-10-25 885/week @ 2024-11-01

3,230 downloads per month
Used in 11 crates (3 directly)

MIT license

1.5MB
21K SLoC

Miden prover

This crate contains the Miden VM prover, which proves correct execution of Miden VM. Internally, the prover uses Miden processor to execute the programs, and then relies on the Winterfell prover to generate STARK proofs.

Usage

This crate exposes a prove() function which can be used to execute Miden VM programs and generate proofs of their execution. The function takes the following parameters:

  • program: &Program - a reference to a Miden program to be executed.
  • stack_inputs: StackInputs - a set of public inputs with which to execute the program.
  • host: Host - an instance of a Host which can be used to supply non-deterministic inputs to the VM and receive messages from the VM.
  • options: &ProvingOptions - config parameters for proof generation. The default options target 96-bit security level.

If the program is executed successfully, the function returns a tuple with 2 elements:

  • outputs: StackOutputs - the outputs generated by the program.
  • proof: ExecutionProof - proof of program execution. ExecutionProof can be easily serialized and deserialized using to_bytes() and from_bytes() functions respectively.

Proof generation example

Here is a simple example of executing a program which pushes two numbers onto the stack and computes their sum:

use miden_assembly::Assembler;
use miden_prover::{prove, ProvingOptions, StackInputs, DefaultHost};

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

// this is our program, we compile it from assembly code
let program = assembler.compile("begin push.3 push.5 add end").unwrap();

// let's execute it and generate a STARK proof
let (outputs, proof) = prove(
    &program,
    StackInputs::default(),       // we won't provide any stack inputs
    DefaultHost::default(),       // we'll be using a default host
    &ProvingOptions::default(),   // we'll be using default options
)
.unwrap();

// the output should be 8
assert_eq!(8, outputs.stack().first().unwrap().as_int());

Crate features

Miden prover can be compiled with the following features:

  • std - enabled by default and relies on the Rust standard library.
  • concurrent - implies std and also enables multi-threaded proof generation.
  • metal - enables Metal-based acceleration of proof generation (for recursive proofs) on supported platforms (e.g., Apple silicon).
  • no_std does not rely on the Rust standard library and enables compilation to WebAssembly.
    • Only the wasm32-unknown-unknown and wasm32-wasip1 targets are officially supported.

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

Concurrent proof generation

When compiled with concurrent feature enabled, the prover will generate STARK proofs using multiple threads. For benefits of concurrent proof generation check out these benchmarks.

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

License

This project is MIT licensed.

Dependencies

~8–34MB
~514K SLoC