diff --git a/hash/risc0/bench/build.sh b/hash/risc0/bench/build.sh new file mode 100755 index 0000000..6870477 --- /dev/null +++ b/hash/risc0/bench/build.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +# Run the 'cargo bench' command. +cargo build --release diff --git a/hash/risc0/bench/host/benches/sha256_benchmarks.rs b/hash/risc0/bench/host/benches/sha256_benchmarks.rs index c695809..c53e015 100644 --- a/hash/risc0/bench/host/benches/sha256_benchmarks.rs +++ b/hash/risc0/bench/host/benches/sha256_benchmarks.rs @@ -40,53 +40,13 @@ fn sha256_benchmarks(c: &mut Criterion) { }); } -// fn sha256_benchmarks_2(c: &mut Criterion) { -// c.bench_function("Benchmarking sha256 on 1KB of random data:", |b| { -// //generating 1kb of random data in a vector of u8 -// let mut data = [0u8; 64]; -// rand::thread_rng().fill_bytes(&mut data); -// let input: Vec = data.to_vec(); - -// // println!("{:?}", input); -// b.iter(|| { -// sha_bench(input.clone()); -// }); -// }); - -// // c.bench_function("Benchmarking sha256 on 2KB of random data:", |b| { -// // //generating 2kb of random data in a vector of u8 -// // let mut data = [0u8; 128]; -// // rand::thread_rng().fill_bytes(&mut data); -// // let input: Vec = data.to_vec(); - -// // // println!("{:?}", input); -// // b.iter(|| { -// // sha_bench(input.clone()); - -// // }); -// // }); - -// // c.bench_function("Benchmarking sha256 on 10KB of random data:", |b| { -// // //generating 10kb of random data in a vector of u8 -// // let mut data = [0u8; 1280]; -// // rand::thread_rng().fill_bytes(&mut data); -// // let input: Vec = data.to_vec(); - -// // b.iter(|| { -// // sha_bench(input.clone()); -// // }); -// // }); - -// } - criterion_group!( name = benches; // Setting the sample size to 10 for quick benchmarks // Becuase running default number of samples(100) takes a lot of time config = Criterion::default().sample_size(10); - targets = sha256_benchmarks //, sha256_benchmarks_2 + targets = sha256_benchmarks ); -// criterion_group!(benches, sha256_bench); criterion_main!(benches); diff --git a/hash/risc0/bench/host/src/lib.rs b/hash/risc0/bench/host/src/lib.rs index 2d48276..3db39b1 100644 --- a/hash/risc0/bench/host/src/lib.rs +++ b/hash/risc0/bench/host/src/lib.rs @@ -1,5 +1,3 @@ -// 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 }; @@ -7,21 +5,7 @@ use risc0_zkvm::{default_prover, ExecutorEnv}; use risc0_zkvm::{ sha}; pub fn sha_bench(input: Vec) { - // 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 input: Vec = data.to_vec(); + // Build an executor environment with the input. let env = ExecutorEnv::builder().write(&input).unwrap().build().unwrap(); // Obtain the default prover. @@ -30,17 +14,16 @@ pub fn sha_bench(input: Vec) { // 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: sha::Digest = receipt.journal.decode().unwrap(); - // println!("output: {:?}", _output); - // Optional: Verify receipt to confirm that recipients will also be able to + // verify your receipt receipt.verify(METHOD_ID).unwrap(); } #[allow(dead_code)] fn main() { + // This is a dummy call for the sha256 execution. + // Benchmarking does not depend on this. sha_bench(vec![97, 98, 99, 100, 101, 102, 103, 104]); } diff --git a/hash/risc0/bench/methods/guest/src/main.rs b/hash/risc0/bench/methods/guest/src/main.rs index ceffa06..aa4473f 100644 --- a/hash/risc0/bench/methods/guest/src/main.rs +++ b/hash/risc0/bench/methods/guest/src/main.rs @@ -1,22 +1,10 @@ #![no_main] -// If you want to try std support, also update the guest Cargo.toml file - use risc0_zkvm::{guest::env, sha, sha::Sha256}; 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); let data: Vec = env::read(); let hash = sha::Impl::hash_bytes(&data); diff --git a/hash/risc0/bench/run.sh b/hash/risc0/bench/run.sh new file mode 100755 index 0000000..fb14795 --- /dev/null +++ b/hash/risc0/bench/run.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +# Run the 'cargo bench' command. +cargo bench