mirror of
https://github.com/logos-storage/zk-benchmarks.git
synced 2026-01-03 22:33:06 +00:00
poseidon2 benchmark over babybear
This commit is contained in:
parent
739f15ef9e
commit
8c6118980f
56
hash/jolt/bench/Cargo.lock
generated
56
hash/jolt/bench/Cargo.lock
generated
@ -213,6 +213,12 @@ dependencies = [
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.86"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da"
|
||||
|
||||
[[package]]
|
||||
name = "ark-bn254"
|
||||
version = "0.4.0"
|
||||
@ -1296,6 +1302,8 @@ dependencies = [
|
||||
"blake2",
|
||||
"blake3",
|
||||
"jolt-sdk",
|
||||
"risc0-core 0.18.0",
|
||||
"risc0-zkp",
|
||||
"sha2",
|
||||
"sha3",
|
||||
]
|
||||
@ -2505,6 +2513,54 @@ dependencies = [
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "risc0-core"
|
||||
version = "0.18.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "08605aec93ea22ed83f7f81f42e2d7287a5b0c749d8671f94de9d5994020045c"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"rand_core 0.6.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "risc0-core"
|
||||
version = "1.0.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "047cc26c68c092d664ded7488dcac0462d9e31190e1598a7820fe4246d313583"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"rand_core 0.6.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "risc0-zkp"
|
||||
version = "1.0.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ae55272541351a2391e5051519b33bfdf41f5648216827cc2cb94a49b6937380"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"blake2",
|
||||
"bytemuck",
|
||||
"cfg-if",
|
||||
"digest 0.10.7",
|
||||
"hex",
|
||||
"hex-literal",
|
||||
"paste",
|
||||
"rand_core 0.6.4",
|
||||
"risc0-core 1.0.5",
|
||||
"risc0-zkvm-platform",
|
||||
"serde",
|
||||
"sha2",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "risc0-zkvm-platform"
|
||||
version = "1.0.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "16735dab52ae8bf0dc30df78fce901b674f469dfd7b5f5dfddd54caea22f14d5"
|
||||
|
||||
[[package]]
|
||||
name = "rlp"
|
||||
version = "0.5.2"
|
||||
|
||||
@ -3,16 +3,18 @@ name = "guest"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# [[bin]]
|
||||
# name = "guest"
|
||||
# path = "./src/lib.rs"
|
||||
[[bin]]
|
||||
name = "guest"
|
||||
path = "./src/lib.rs"
|
||||
|
||||
[features]
|
||||
guest = []
|
||||
|
||||
[dependencies]
|
||||
jolt = { package = "jolt-sdk", git = "https://github.com/a16z/jolt", rev = "4805d038f7b6e7ca5e7ef64aefa62213aecac01a"}
|
||||
jolt = { package = "jolt-sdk", git = "https://github.com/a16z/jolt", rev = "4805d038f7b6e7ca5e7ef64aefa62213aecac01a", features = ["guest-std"]}
|
||||
sha2 = { version = "0.10.8", default-features = false }
|
||||
sha3 = { version = "0.10.8", default-features = false }
|
||||
blake3 = { version = "1.5.4", default-features = false }
|
||||
blake2 = { version = "0.10.6", default-features = false }
|
||||
blake2 = { version = "0.10.6", default-features = false }
|
||||
risc0-zkp = { version = "1.0.5", default-features = false }
|
||||
risc0-core = { version = "=0.18.0", default-features = false }
|
||||
@ -1,4 +1,4 @@
|
||||
#![cfg_attr(feature = "guest", no_std)]
|
||||
// #![cfg_attr(feature = "guest", no_std)]
|
||||
#![no_main]
|
||||
|
||||
use sha2::{Sha256, Digest};
|
||||
@ -6,6 +6,12 @@ use sha3::Keccak256;
|
||||
use blake3::hash;
|
||||
use blake2::Blake2s256;
|
||||
|
||||
use risc0_zkp::core::hash::poseidon2::Poseidon2HashSuite;
|
||||
use risc0_zkp::field::baby_bear::BabyBearElem;
|
||||
|
||||
extern crate alloc;
|
||||
use alloc::vec::Vec;
|
||||
|
||||
// sha256
|
||||
#[jolt::provable]
|
||||
fn sha2(input: &[u8]) -> [u8; 32] {
|
||||
@ -39,3 +45,19 @@ fn blake2(input: &[u8]) -> [u8; 32] {
|
||||
let result = hasher.finalize();
|
||||
Into::<[u8; 32]>::into(result)
|
||||
}
|
||||
|
||||
// poseidon2 over babybear
|
||||
#[jolt::provable(stack_size = 10000, memory_size = 100000000)]
|
||||
//TODO: input should be made u32
|
||||
fn poseidon2_babybear(input: &[u8]) -> String {
|
||||
let mut hash_data: Vec<BabyBearElem> = Vec::new();
|
||||
|
||||
for i in 0..input.len() {
|
||||
let a_uncompressed = BabyBearElem::from(input[i] as u32);
|
||||
hash_data.push(a_uncompressed);
|
||||
}
|
||||
let result = Poseidon2HashSuite::new_suite().hashfn.hash_elem_slice(hash_data.as_slice());
|
||||
|
||||
result.to_string()
|
||||
|
||||
}
|
||||
15
hash/jolt/bench/run_tree.sh
Executable file
15
hash/jolt/bench/run_tree.sh
Executable file
@ -0,0 +1,15 @@
|
||||
#!/bin/bash
|
||||
if [ -z ${ZKBENCH_HASH_TYPE_TREE} ]; then
|
||||
ZKBENCH_HASH_TYPE_TREE="poseidon2_babybear"
|
||||
fi
|
||||
|
||||
if [ -z ${ZKBENCH_TREE_DEPTH} ]; then
|
||||
ZKBENCH_TREE_DEPTH=2
|
||||
fi
|
||||
|
||||
echo "Running benchmarks with the following configurations:"
|
||||
echo "HASH = $ZKBENCH_HASH_TYPE_TREE"
|
||||
echo "Tree Depth = $ZKBENCH_TREE_DEPTH"
|
||||
|
||||
# Run the benchmarks
|
||||
RUST_LOG=info ./target/release/bench $ZKBENCH_HASH_TYPE_TREE $ZKBENCH_TREE_DEPTH
|
||||
@ -1,4 +1,5 @@
|
||||
pub mod sha2;
|
||||
pub mod sha3;
|
||||
pub mod blake3;
|
||||
pub mod blake2;
|
||||
pub mod blake2;
|
||||
pub mod poseidon2_babybear;
|
||||
56
hash/jolt/bench/src/benches/poseidon2_babybear.rs
Normal file
56
hash/jolt/bench/src/benches/poseidon2_babybear.rs
Normal file
@ -0,0 +1,56 @@
|
||||
use std::time::Instant;
|
||||
use ark_serialize::CanonicalSerialize;
|
||||
use rand::Rng;
|
||||
|
||||
extern crate alloc;
|
||||
use alloc::vec::Vec;
|
||||
|
||||
pub fn poseidon2_babybear_bench(mt_depth: usize) {
|
||||
|
||||
let t = (1 << mt_depth) * 8;
|
||||
let mut input: Vec<u8> = Vec::new();
|
||||
|
||||
for _ in 0..t {
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
let random_u32: u8 = rng.gen();
|
||||
input.push(random_u32);
|
||||
}
|
||||
|
||||
let (prove_poseidon2_babybear, verify_poseidon2_babybear, guest_build_time) = {
|
||||
|
||||
let start = Instant::now();
|
||||
let (prove, verify) = guest::build_poseidon2_babybear();
|
||||
let elapsed = start.elapsed();
|
||||
|
||||
(prove, verify, elapsed)
|
||||
};
|
||||
|
||||
let (output, proof, proving_time) = {
|
||||
|
||||
let start = Instant::now();
|
||||
let (output, proof) = prove_poseidon2_babybear(input.as_slice());
|
||||
let elapsed = start.elapsed();
|
||||
|
||||
(output, proof, elapsed)
|
||||
};
|
||||
|
||||
let mut proof_bytes = Vec::new();
|
||||
proof.serialize_compressed(&mut proof_bytes).unwrap();
|
||||
|
||||
let (is_valid, verification_time) = {
|
||||
|
||||
let start = Instant::now();
|
||||
let is_valid = verify_poseidon2_babybear(proof);
|
||||
let elapsed = start.elapsed();
|
||||
|
||||
(is_valid, elapsed)
|
||||
};
|
||||
|
||||
assert!(is_valid);
|
||||
println!("output: {:?}", hex::encode(output));
|
||||
println!("guest build time: {:?}", guest_build_time);
|
||||
println!("proving time: {:?}", proving_time);
|
||||
println!("verification time: {:?}", verification_time);
|
||||
println!("proof size: {:?} bytes", proof_bytes.len());
|
||||
}
|
||||
@ -7,6 +7,7 @@ use benches::{
|
||||
sha3::sha3_bench,
|
||||
blake3::blake3_bench,
|
||||
blake2::blake2_bench,
|
||||
poseidon2_babybear::poseidon2_babybear_bench,
|
||||
};
|
||||
|
||||
fn generate_bytes(size: usize) -> Vec<u8> {
|
||||
@ -55,6 +56,14 @@ pub fn main() {
|
||||
let input = generate_bytes(size);
|
||||
blake2_bench(input.clone());
|
||||
}
|
||||
|
||||
"poseidon2_babybear" => {
|
||||
println!("poseidon2_babybear Benchmarking: ");
|
||||
eprintln!("Tree Depth: {:?}", size);
|
||||
eprintln!("number of inputs {:?}", (1 << size) * 8);
|
||||
|
||||
poseidon2_babybear_bench(size);
|
||||
}
|
||||
|
||||
_ => {
|
||||
println!("Wrong Benchmark Name!");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user