Skip to content
This repository has been archived by the owner on Jan 13, 2023. It is now read-only.

Latest commit

 

History

History
57 lines (42 loc) · 2.93 KB

README.md

File metadata and controls

57 lines (42 loc) · 2.93 KB

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.
  • inputs: &ProgramInputs - a reference to a set of public and secret inputs with which to execute the program.
  • num_stack_outputs: usize - number of items on the stack to be returned as program output.
  • options: &ProofOptions - 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: Vec<u64> - the outputs generated by the program. The number of elements in the vector will be equal to the num_stack_outputs parameter.
  • proof: StarkProof - proof of program execution. StarkProof 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, ProgramInputs, ProofOptions};

// 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,
    &ProgramInputs::none(),   // we won't provide any inputs
    1,                        // we'll return one item from the stack
    &ProofOptions::default(), // we'll be using default options
)
.unwrap();

// the output should be 8
assert_eq!(vec![8], outputs);

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.
  • no_std does not rely on the Rust standard library and enables compilation to WebAssembly.

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.