risc0-demo/host/src/main.rs~

43 lines
1.5 KiB
Rust

// These constants represent the RISC-V ELF and the image ID generated by risc0-build.
// The ELF is used for proving and the ID is used for verification.
use methods::{
METHOD_ELF, METHOD_ID
};
use risc0_zkvm::{default_prover, ExecutorEnv};
fn main() {
// Initialize tracing. In order to view logs, run `RUST_LOG=info cargo run`
env_logger::init();
// 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 ExecutorEnv::builder(), which
// creates an ExecutorEnvBuilder. When you're done adding input, call
// ExecutorEnvBuilder::build().
// For example:
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, METHOD_ELF).unwrap();
// 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
receipt.verify(METHOD_ID).unwrap();
}