17 releases (8 breaking)

Uses new Rust 2021

0.11.1 Aug 13, 2022
0.10.0 Jun 24, 2022

#17 in #risc-v

Download history 129/week @ 2022-06-01 104/week @ 2022-06-08 50/week @ 2022-06-15 71/week @ 2022-06-22 56/week @ 2022-06-29 55/week @ 2022-07-06 73/week @ 2022-07-13 45/week @ 2022-07-20 49/week @ 2022-07-27 62/week @ 2022-08-03 106/week @ 2022-08-10 26/week @ 2022-08-17 37/week @ 2022-08-24 13/week @ 2022-08-31 18/week @ 2022-09-07 31/week @ 2022-09-14

105 downloads per month

Apache-2.0

285KB
6.5K SLoC

risc0-zkvm-guest

The RISC Zero ZKVM's guest-side RISC-V APIs.

Code that is validated by the RISC Zero zkVM is run inside the guest. In the minimal case, an entrypoint (the guest's "main" function) must be provided by calling [entry]. The code executed when the entrypoint function is called is what will be proven by the zkVM and available for verification later. In almost all practical cases, the guest will want to read private input data using [env::read] and commit public output data using [env::commit]; additional I/O functionality is also available in [mod@env].

For example[^starter-ex], the following guest code proves a number is composite by multiplying two unsigned integers, and panicking if either is 1 or if the multiplication overflows:

use risc0_zkvm_guest::env;

risc0_zkvm_guest::entry!(main);

pub fn main() {
    // Load the first number from the host
    let a: u64 = env::read();
    // Load the second number from the host
    let b: u64 = env::read();
    // Verify that neither of them are 1 (i.e. nontrivial factors)
    if a == 1 || b == 1 {
        panic!("Trivial factors")
    }
    // Compute the product while being careful with integer overflow
    let product = a.checked_mul(b).expect("Integer overflow");
    env::commit(&product);
}

Notice how [entry] is used to indicate the entrypoint, [env::read] is used to load the two factors, and [env::commit] is used to make their composite product publically available.

[^starter-ex]: The example is based on the Risc Zero Rust Starter repository.

Dependencies

~1.4–4MB
~81K SLoC