Skip to content

Commit

Permalink
template: add input to guest and write to journal from guest (risc0#1044
Browse files Browse the repository at this point in the history
)
  • Loading branch information
SchmErik authored Oct 27, 2023
1 parent aa2c802 commit d19163f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ jobs:
--guest-name test_method \
template-test
shell: bash
- run: cargo build --release --manifest-path ${{ runner.temp }}/template-test/Cargo.toml
- run: cargo run --release --manifest-path ${{ runner.temp }}/template-test/Cargo.toml
- run: ${{ runner.temp }}/template-test/target/release/host

crates-validator:
Expand Down
26 changes: 16 additions & 10 deletions templates/rust-starter/host/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,32 @@ use methods::{
use risc0_zkvm::{default_prover, ExecutorEnv};

fn main() {
// First, we construct an executor environment
let env = ExecutorEnv::builder().build().unwrap();

// TODO: add guest input to the executor environment using
// An executor environment describes the configurations for the zkVM
// including program inputs.
// An default ExecutorEnv can be created like so:
// `let env = ExecutorEnv::builder().build().unwrap();`
// However, this `env` does not have any inputs.
//
// To add add guest input to the executor environment, use
// ExecutorEnvBuilder::write().
// To access this method, you'll need to use the alternate construction
// ExecutorEnv::builder(), which creates an ExecutorEnvBuilder. When you're
// done adding input, call ExecutorEnvBuilder::build().
// To access this method, you'll need to use ExecutorEnv::builder(), which
// creates an ExecutorEnvBuilder. When you're done adding input, call
// ExecutorEnvBuilder::build().

// For example:
// let env = ExecutorEnv::builder().write(&input).unwrap().build().unwrap();
let input: u32 = 15*2^27 + 1;
let env = ExecutorEnv::builder().write(&input).unwrap().build().unwrap();

// Obtain the default prover.
let prover = default_prover();

// Produce a receipt by proving the specified ELF binary.
let receipt = prover.prove_elf(env, {{guest_elf}}).unwrap();

// TODO: Implement code for transmitting or serializing the receipt for
// other parties to verify here
// TODO: Implement code for retrieving receipt journal here.

// For example:
let _output: u32 = receipt.journal.decode().unwrap();

// Optional: Verify receipt to confirm that recipients will also be able to
// verify your receipt
Expand Down
8 changes: 8 additions & 0 deletions templates/rust-starter/methods/guest/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,12 @@ risc0_zkvm::guest::entry!(main);

pub fn main() {
// TODO: Implement your guest code here

// read the input
let input: u32 = env::read();

// TODO: do something with the input

// write public output to the journal
env::commit(&input);
}

0 comments on commit d19163f

Please sign in to comment.