script for building & benchmark running added, code cleaning

This commit is contained in:
Manish Kumar 2023-11-09 22:03:38 +05:30
parent b2bdaac8b4
commit e564b28e8e
5 changed files with 13 additions and 74 deletions

4
hash/risc0/bench/build.sh Executable file
View File

@ -0,0 +1,4 @@
#!/bin/bash
# Run the 'cargo bench' command.
cargo build --release

View File

@ -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<u8> = 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<u8> = 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<u8> = 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);

View File

@ -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<u8>) {
// 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<u8> = 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<u8>) {
// 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]);
}

View File

@ -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<u8> = env::read();
let hash = sha::Impl::hash_bytes(&data);

4
hash/risc0/bench/run.sh Executable file
View File

@ -0,0 +1,4 @@
#!/bin/bash
# Run the 'cargo bench' command.
cargo bench