mirror of
https://github.com/logos-storage/zk-benchmarks.git
synced 2026-01-05 07:13:08 +00:00
blake2 bench added, build.sh and run.sh added
This commit is contained in:
parent
de7edef382
commit
1c7f257fea
10
hash/sp1/bench/blake2/Cargo.toml
Normal file
10
hash/sp1/bench/blake2/Cargo.toml
Normal file
@ -0,0 +1,10 @@
|
||||
[workspace]
|
||||
[package]
|
||||
version = "0.1.0"
|
||||
name = "blake2-program"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
sp1-zkvm = { git = "https://github.com/succinctlabs/sp1.git" }
|
||||
blake2 = "0.10.6"
|
||||
|
||||
BIN
hash/sp1/bench/blake2/elf/riscv32im-succinct-zkvm-elf
Executable file
BIN
hash/sp1/bench/blake2/elf/riscv32im-succinct-zkvm-elf
Executable file
Binary file not shown.
23
hash/sp1/bench/blake2/src/main.rs
Normal file
23
hash/sp1/bench/blake2/src/main.rs
Normal file
@ -0,0 +1,23 @@
|
||||
|
||||
#![no_main]
|
||||
sp1_zkvm::entrypoint!(main);
|
||||
|
||||
//The patched sha2 rust crate https://github.com/sp1-patches/RustCrypto-hashes
|
||||
use blake2::Digest;
|
||||
use blake2::Blake2b;
|
||||
pub fn main() {
|
||||
|
||||
let input = sp1_zkvm::io::read::<Vec<u8>>();
|
||||
|
||||
// create a Blake2b512 object
|
||||
let mut hasher = Blake2b::new();
|
||||
|
||||
// write input message
|
||||
hasher.update(input);
|
||||
|
||||
// read hash digest
|
||||
let result: [u8;32] = hasher.finalize().into();
|
||||
|
||||
sp1_zkvm::io::write(&result);
|
||||
|
||||
}
|
||||
9
hash/sp1/bench/build.sh
Executable file
9
hash/sp1/bench/build.sh
Executable file
@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
cd blake2
|
||||
cargo prove build
|
||||
cd ../keccak
|
||||
cargo prove build
|
||||
cd ../sha256
|
||||
cargo prove build
|
||||
cd ../script
|
||||
cargo build --release
|
||||
@ -6,4 +6,4 @@ edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
sp1-zkvm = { git = "https://github.com/succinctlabs/sp1.git" }
|
||||
sha3 = "0.10.8"
|
||||
tiny-keccak = { git = "https://github.com/succinctlabs/tiny-keccak-private", branch = "patch-v2.0.2", features = ["keccak"] }
|
||||
Binary file not shown.
@ -1,20 +1,21 @@
|
||||
|
||||
#![no_main]
|
||||
sp1_zkvm::entrypoint!(main);
|
||||
use sha3::{Digest, Keccak256};
|
||||
|
||||
use tiny_keccak::{Hasher, Keccak};
|
||||
pub fn main() {
|
||||
|
||||
let input = sp1_zkvm::io::read::<Vec<u8>>();
|
||||
|
||||
// create a keccak object
|
||||
let mut hasher = Keccak256::new();
|
||||
let mut hasher = Keccak::v256();
|
||||
|
||||
// write input message
|
||||
hasher.update(input);
|
||||
hasher.update(&input);
|
||||
|
||||
// read hash digest
|
||||
let result: [u8;32] = hasher.finalize().into();
|
||||
let mut result: [u8;32] = [0;32];
|
||||
|
||||
hasher.finalize(&mut result);
|
||||
|
||||
sp1_zkvm::io::write(&result);
|
||||
}
|
||||
|
||||
15
hash/sp1/bench/run.sh
Executable file
15
hash/sp1/bench/run.sh
Executable file
@ -0,0 +1,15 @@
|
||||
#!/bin/bash
|
||||
if [ -z ${ZKBENCH_HASH_TYPE} ]; then
|
||||
ZKBENCH_HASH_TYPE="sha256"
|
||||
fi
|
||||
|
||||
if [ -z ${ZKBENCH_INPUT_SIZE_BYTES} ]; then
|
||||
ZKBENCH_INPUT_SIZE_BYTES=1024
|
||||
fi
|
||||
cd script
|
||||
echo "Running benchmarks with the following configurations:"
|
||||
echo "HASH = $ZKBENCH_HASH_TYPE"
|
||||
echo "Input Size (Bytes) = $ZKBENCH_INPUT_SIZE_BYTES"
|
||||
|
||||
# Run the benchmarks
|
||||
./target/release/bench-script $ZKBENCH_HASH_TYPE $ZKBENCH_INPUT_SIZE_BYTES
|
||||
43
hash/sp1/bench/script/src/benches/blake2.rs
Normal file
43
hash/sp1/bench/script/src/benches/blake2.rs
Normal file
@ -0,0 +1,43 @@
|
||||
|
||||
use sp1_core::{SP1Prover, SP1Stdin, SP1Verifier};
|
||||
use rand::Rng;
|
||||
use hex::encode;
|
||||
|
||||
const BLAKE2_ELF: &[u8] = include_bytes!("../../../blake2/elf/riscv32im-succinct-zkvm-elf");
|
||||
|
||||
pub fn generate_random_bytes(length: usize) -> Vec<u8> {
|
||||
let mut rng = rand::thread_rng();
|
||||
(0..length).map(|_| rng.gen::<u8>()).collect()
|
||||
}
|
||||
|
||||
|
||||
pub fn blake2_benchmark(size: usize) {
|
||||
|
||||
// Generate proof.
|
||||
let mut stdin = SP1Stdin::new();
|
||||
let data = generate_random_bytes(size);
|
||||
|
||||
stdin.write(&data);
|
||||
|
||||
let t0 = std::time::Instant::now();
|
||||
let mut proof = SP1Prover::prove(BLAKE2_ELF, stdin).expect("proving failed");
|
||||
let t1 = t0.elapsed();
|
||||
// Read output.
|
||||
let hash_bytes = proof.stdout.read::<[u8;64]>();
|
||||
let hash = encode(hash_bytes);
|
||||
println!("hash: {}", hash);
|
||||
|
||||
// Verify proof.
|
||||
let t2 = std::time::Instant::now();
|
||||
SP1Verifier::verify(BLAKE2_ELF, &proof).expect("verification failed");
|
||||
let t3 = t2.elapsed();
|
||||
|
||||
// Save proof.
|
||||
proof
|
||||
.save("proof-with-io.json")
|
||||
.expect("saving proof failed");
|
||||
|
||||
println!("succesfully generated and verified proof for the program!");
|
||||
println!("Proof Generation Time: {:?}", t1);
|
||||
println!("Proof verification Time: {:?}", t3);
|
||||
}
|
||||
@ -30,6 +30,11 @@ fn main() {
|
||||
let _ = keccak_benchmark(size);
|
||||
}
|
||||
|
||||
"blake2" => {
|
||||
println!("Running blake2 benchmark: ");
|
||||
let _ = keccak_benchmark(size);
|
||||
}
|
||||
|
||||
_ => {
|
||||
println!("Wrong Benchmark Name!");
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user