Merge branch 'hash_benchmark' into composition

This commit is contained in:
Manish Kumar 2024-01-23 13:55:56 +05:30
commit 3794c4aaf9
9 changed files with 47 additions and 3556 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@
build
target
a.out
Cargo.lock

File diff suppressed because it is too large Load Diff

View File

@ -2,10 +2,10 @@ name: "Hashes benchmarking using risc0 prover"
author:
timeout: 1000
params:
[ HASH_TYPE: [ "poseidon2_babybear", "poseidon2_babybear_native", "poseidon2_bn128"]
[ HASH_TYPE_TREE: [ "poseidon2_babybear", "poseidon2_babybear_native", "poseidon2_bn128"]
, TREE_DEPTH: [ 2, 4, 8, 16 ]
]
tags: risc0, $HASH_TYPE
tags: risc0, $HASH_TYPE_TREE
comments:
The benchmarks includes for poseidon2(merkle hashing) over bn128 and babybear.
the hashing is done inside the guest and receipt is received which is verified.

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
#!/bin/bash
if [ -z ${ZKBENCH_HASH_TYPE} ]; then
ZKBENCH_HASH_TYPE="poseidon2_babybear_native"
if [ -z ${ZKBENCH_HASH_TYPE_TREE} ]; then
ZKBENCH_HASH_TYPE_TREE="poseidon2_babybear_native"
fi
if [ -z ${ZKBENCH_TREE_DEPTH} ]; then
@ -8,8 +8,8 @@ ZKBENCH_TREE_DEPTH=2
fi
echo "Running benchmarks with the following configurations:"
echo "HASH = $ZKBENCH_HASH_TYPE"
echo "HASH = $ZKBENCH_HASH_TYPE_TREE"
echo "Tree Depth = $ZKBENCH_TREE_DEPTH"
# Run the benchmarks
./target/release/benchmark $ZKBENCH_HASH_TYPE $ZKBENCH_TREE_DEPTH
./target/release/benchmark $ZKBENCH_HASH_TYPE_TREE $ZKBENCH_TREE_DEPTH

View File

@ -1,4 +1,5 @@
pub mod sha256;
pub mod sha256_accelerated;
pub mod keccak;
pub mod blake2b;
pub mod blake3;

View File

@ -1,10 +1,9 @@
use benchmark_methods::{
SHA256_ELF, SHA256_ID, SHA256_ACCELERATED_ELF, SHA256_ACCELERATED_ID
SHA256_ELF, SHA256_ID
};
use risc0_zkvm::{default_prover, ExecutorEnv};
use risc0_zkvm::{ sha};
use std::time::Instant;
use hex::encode;
pub fn sha_bench(input: Vec<u8>) {
let env = ExecutorEnv::builder().write(&input).unwrap().build().unwrap();
@ -30,25 +29,4 @@ pub fn sha_bench(input: Vec<u8>) {
eprintln!("Hash: {:?}", _output);
let env = ExecutorEnv::builder().write(&input).unwrap().build().unwrap();
eprintln!("\n------RustCrypto sha hashing(accelerated)------\n");
// Obtain the default prover.
let prover = default_prover();
let start_time = Instant::now();
// Produce a receipt by proving the specified ELF binary.
let receipt = prover.prove(env, SHA256_ACCELERATED_ELF).unwrap();
let elapsed_time = start_time.elapsed();
// verify your receipt
receipt.verify(SHA256_ACCELERATED_ID).unwrap();
let elapsed_time2 = start_time.elapsed();
let _output: [u8;32] = receipt.journal.decode().unwrap();
let hash = encode(_output);
eprintln!("Total time: {:?}", elapsed_time2);
eprintln!("Verification time: {:?}", elapsed_time2 - elapsed_time);
eprintln!("Hash: {:?}", hash);
}

View File

@ -0,0 +1,30 @@
use benchmark_methods::{
SHA256_ACCELERATED_ELF, SHA256_ACCELERATED_ID
};
use risc0_zkvm::{default_prover, ExecutorEnv};
use std::time::Instant;
use hex::encode;
pub fn sha_accelerated_bench(input: Vec<u8>) {
let env = ExecutorEnv::builder().write(&input).unwrap().build().unwrap();
eprintln!("\n------RustCrypto sha hashing(accelerated)------\n");
// Obtain the default prover.
let prover = default_prover();
let start_time = Instant::now();
// Produce a receipt by proving the specified ELF binary.
let receipt = prover.prove(env, SHA256_ACCELERATED_ELF).unwrap();
let elapsed_time = start_time.elapsed();
// verify your receipt
receipt.verify(SHA256_ACCELERATED_ID).unwrap();
let elapsed_time2 = start_time.elapsed();
let _output: [u8;32] = receipt.journal.decode().unwrap();
let hash = encode(_output);
eprintln!("Total time: {:?}", elapsed_time2);
eprintln!("Verification time: {:?}", elapsed_time2 - elapsed_time);
eprintln!("Hash: {:?}", hash);
}

View File

@ -1,6 +1,7 @@
mod benches;
use benches::{
sha256::sha_bench,
sha256_accelerated::sha_accelerated_bench,
keccak::keccak_bench,
blake2b::blake2b_bench,
blake3::blake3_bench,
@ -22,7 +23,7 @@ fn main() {
let args: Vec<String> = std::env::args().collect();
if args.len() != 3 {
println!("Wrong number of arguments");
println!("Wrong number of arguments! The program expects two arguments: <hash_type> and <size>");
// Exit the program with a non-zero exit code
process::exit(1);
}
@ -37,6 +38,12 @@ fn main() {
let input = generate_bytes(size);
sha_bench(input.clone());
}
"sha256_accelerated" => {
println!("Accelerated SHA256 Benchmarking: ");
eprintln!("data size(bytes): {:?}", size);
let input = generate_bytes(size);
sha_accelerated_bench(input.clone());
}
"keccak" => {
println!("KECCAK Benchmarking: ");
eprintln!("data size(bytes): {:?}", size);