mirror of
https://github.com/vacp2p/nescience-zkvm-testing.git
synced 2026-01-09 15:18:09 -05:00
60 lines
2.0 KiB
Rust
60 lines
2.0 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::{
|
|
GUEST_NULLIFIER_TEST_ELF, GUEST_NULLIFIER_TEST_ID
|
|
};
|
|
use risc0_zkvm::{default_prover, ExecutorEnv};
|
|
use std::time::Instant;
|
|
|
|
fn main() {
|
|
// Initialize tracing. In order to view logs, run `RUST_LOG=info cargo run`
|
|
tracing_subscriber::fmt()
|
|
.with_env_filter(tracing_subscriber::filter::EnvFilter::from_default_env())
|
|
.init();
|
|
|
|
// An executor environment describes the configurations for the zkVM
|
|
// including program inputs.
|
|
// A default ExecutorEnv can be created like so:
|
|
// `let env = ExecutorEnv::builder().build().unwrap();`
|
|
// However, this `env` does not have any inputs.
|
|
//
|
|
// To 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 * u32::pow(2, 27) + 1;
|
|
let env = ExecutorEnv::builder()
|
|
.write(&input)
|
|
.unwrap()
|
|
.build()
|
|
.unwrap();
|
|
|
|
// Obtain the default prover.
|
|
let prover = default_prover();
|
|
|
|
let now = Instant::now();
|
|
// Proof information by proving the specified ELF binary.
|
|
// This struct contains the receipt along with statistics about execution of the guest
|
|
let prove_info = prover
|
|
.prove(env, GUEST_NULLIFIER_TEST_ELF)
|
|
.unwrap();
|
|
println!("Proving time: {:?}", now.elapsed());
|
|
|
|
// extract the receipt.
|
|
let receipt = prove_info.receipt;
|
|
|
|
// TODO: Implement code for retrieving receipt journal here.
|
|
|
|
// For example:
|
|
let _output: u32 = receipt.journal.decode().unwrap();
|
|
|
|
// The receipt was verified at the end of proving, but the below code is an
|
|
// example of how someone else could verify this receipt.
|
|
receipt
|
|
.verify(GUEST_NULLIFIER_TEST_ID)
|
|
.unwrap();
|
|
}
|