mirror of
https://github.com/logos-storage/zk-benchmarks.git
synced 2026-01-03 06:13:11 +00:00
poseidon2 over risc0's native babybear
This commit is contained in:
parent
d5193cce6e
commit
ac71b3f2a7
19
hash/risc0/bench/Cargo.lock
generated
19
hash/risc0/bench/Cargo.lock
generated
@ -153,6 +153,7 @@ dependencies = [
|
||||
"hex",
|
||||
"methods",
|
||||
"rand",
|
||||
"risc0-core 0.18.0",
|
||||
"risc0-zkvm",
|
||||
"serde",
|
||||
"sha2 0.10.6",
|
||||
@ -1449,7 +1450,7 @@ dependencies = [
|
||||
"anyhow",
|
||||
"bytemuck",
|
||||
"log",
|
||||
"risc0-core",
|
||||
"risc0-core 0.19.1",
|
||||
"risc0-zkp",
|
||||
"tracing",
|
||||
]
|
||||
@ -1462,12 +1463,22 @@ checksum = "1a269d01b18cba24ee1a08f68726fc3623e8705ed79d158377d12e9129dcde2e"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"log",
|
||||
"risc0-core",
|
||||
"risc0-core 0.19.1",
|
||||
"risc0-zkp",
|
||||
"risc0-zkvm-platform",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "risc0-core"
|
||||
version = "0.18.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "08605aec93ea22ed83f7f81f42e2d7287a5b0c749d8671f94de9d5994020045c"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "risc0-core"
|
||||
version = "0.19.1"
|
||||
@ -1492,7 +1503,7 @@ dependencies = [
|
||||
"log",
|
||||
"paste",
|
||||
"rand_core",
|
||||
"risc0-core",
|
||||
"risc0-core 0.19.1",
|
||||
"risc0-zkvm-platform",
|
||||
"serde",
|
||||
"sha2 0.10.8",
|
||||
@ -1522,7 +1533,7 @@ dependencies = [
|
||||
"risc0-binfmt",
|
||||
"risc0-circuit-recursion",
|
||||
"risc0-circuit-rv32im",
|
||||
"risc0-core",
|
||||
"risc0-core 0.19.1",
|
||||
"risc0-zkp",
|
||||
"risc0-zkvm-platform",
|
||||
"rrs-lib",
|
||||
|
||||
@ -32,4 +32,5 @@ methods = { workspace = true }
|
||||
zkhash = { git = "https://github.com/HorizenLabs/poseidon2.git"}
|
||||
ark-ff = "0.4.2"
|
||||
hex = "0.4.3"
|
||||
ark-serialize = "0.4"
|
||||
ark-serialize = "0.4"
|
||||
risc0-core = "0.18.0"
|
||||
|
||||
17
hash/risc0/bench/methods/guest/Cargo.lock
generated
17
hash/risc0/bench/methods/guest/Cargo.lock
generated
@ -485,8 +485,10 @@ dependencies = [
|
||||
"ark-serialize",
|
||||
"blake3",
|
||||
"lazy_static",
|
||||
"rand",
|
||||
"risc0-core 0.18.0",
|
||||
"risc0-zkp",
|
||||
"risc0-zkp-core",
|
||||
"risc0-zkvm",
|
||||
"sha2 0.10.6",
|
||||
"sha3",
|
||||
@ -748,6 +750,21 @@ dependencies = [
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "risc0-zkp-core"
|
||||
version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3dfd3bb0b4f2a4250d7332c3d647418502449e773b176552aae869537c4a96bf"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bytemuck",
|
||||
"paste",
|
||||
"rand",
|
||||
"rand_core",
|
||||
"serde",
|
||||
"sha2 0.10.8",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "risc0-zkvm"
|
||||
version = "0.19.0"
|
||||
|
||||
@ -16,4 +16,6 @@ zkhash = { git = "https://github.com/HorizenLabs/poseidon2.git"}
|
||||
ark-serialize = "0.4"
|
||||
ark-ff = "0.4.2"
|
||||
risc0-core = "0.18.0"
|
||||
lazy_static = "1.4"
|
||||
lazy_static = "1.4"
|
||||
risc0-zkp-core = "0.10.0"
|
||||
rand = "0.8.5"
|
||||
1761
hash/risc0/bench/methods/guest/src/bin/poseidon2_babybear_native.rs
Normal file
1761
hash/risc0/bench/methods/guest/src/bin/poseidon2_babybear_native.rs
Normal file
File diff suppressed because it is too large
Load Diff
@ -28,7 +28,7 @@ echo "Input Size (KB) = $ZKBENCH_INPUT_SIZE_KB"
|
||||
|
||||
# Run the benchmarks using cargo run
|
||||
# Check if the environment variable is set to "poseidon2_bn128"
|
||||
if [[ "$ZKBENCH_HASH_TYPE" == "poseidon2_bn128" || "$ZKBENCH_HASH_TYPE" == "poseidon2_babybear" ]]; then
|
||||
if [[ "$ZKBENCH_HASH_TYPE" == "poseidon2_bn128" || "$ZKBENCH_HASH_TYPE" == "poseidon2_babybear" || "$ZKBENCH_HASH_TYPE" == "poseidon2_babybear_native" ]]; then
|
||||
# echo "Running Poseidon2 benchmark over bn128 field"
|
||||
CARGO_BUILD_JOBS=$ZKBENCH_NTHREADS cargo run $ZKBENCH_HASH_TYPE $ZKBENCH_TREE_DEPTH
|
||||
else
|
||||
|
||||
@ -3,4 +3,5 @@ pub mod keccak;
|
||||
pub mod blake2b;
|
||||
pub mod blake3;
|
||||
pub mod poseidon2_bn128;
|
||||
pub mod poseidon2_babybear;
|
||||
pub mod poseidon2_babybear;
|
||||
pub mod poseidon2_babybear_native;
|
||||
@ -51,8 +51,7 @@ pub fn poseidon2_babybear_bench(mt_depth: usize) {
|
||||
output_deseralised.push(Scalar::deserialize_uncompressed(&**output.get(i).unwrap()).unwrap());
|
||||
}
|
||||
|
||||
eprintln!("size: {:?}", output_deseralised);
|
||||
// let hash_final = FpBabyBear::deserialize_uncompressed(&*output).unwrap();
|
||||
eprintln!("hash: {:?}", output_deseralised);
|
||||
|
||||
// verify your receipt
|
||||
receipt.verify(POSEIDON2_BABYBEAR_ID).unwrap();
|
||||
|
||||
56
hash/risc0/bench/src/benches/poseidon2_babybear_native.rs
Normal file
56
hash/risc0/bench/src/benches/poseidon2_babybear_native.rs
Normal file
@ -0,0 +1,56 @@
|
||||
#![allow(non_snake_case)]
|
||||
use methods::{
|
||||
POSEIDON2_BABYBEAR_NATIVE_ELF,
|
||||
POSEIDON2_BABYBEAR_NATIVE_ID
|
||||
};
|
||||
use risc0_zkvm::{
|
||||
default_prover,
|
||||
ExecutorEnv
|
||||
};
|
||||
use std::time::Instant;
|
||||
// use risc0_core::field::baby_bear::BabyBearElem;
|
||||
use rand::Rng;
|
||||
|
||||
pub fn poseidon2_babybear_native_bench(mt_depth: usize) {
|
||||
|
||||
let t = (1 << mt_depth) * 8;
|
||||
let mut input: Vec<u32> = Vec::new();
|
||||
|
||||
for _ in 0..t {
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
let random_u32: u32 = rng.gen();
|
||||
input.push(random_u32);
|
||||
}
|
||||
|
||||
let env = ExecutorEnv::builder().write(&input).unwrap().build().unwrap();
|
||||
|
||||
// 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_elf(env, POSEIDON2_BABYBEAR_NATIVE_ELF).unwrap();
|
||||
let elapsed_time = start_time.elapsed();
|
||||
|
||||
// For example:
|
||||
let output: Vec<u32> = receipt.journal.decode().unwrap();
|
||||
|
||||
// let mut output_deseralised: Vec<Scalar> = Vec::new();
|
||||
|
||||
// for i in 0..output.len() {
|
||||
// output_deseralised.push(Scalar::deserialize_uncompressed(&**output.get(i).unwrap()).unwrap());
|
||||
// }
|
||||
|
||||
eprintln!("hash: {:?}", output);
|
||||
// let hash_final = FpBabyBear::deserialize_uncompressed(&*output).unwrap();
|
||||
|
||||
// verify your receipt
|
||||
receipt.verify(POSEIDON2_BABYBEAR_NATIVE_ID).unwrap();
|
||||
|
||||
|
||||
eprintln!("Total time: {:?}", elapsed_time);
|
||||
// eprintln!("Hash: {:?}", hash_final);
|
||||
|
||||
|
||||
}
|
||||
@ -3,12 +3,7 @@ use methods::{
|
||||
};
|
||||
use risc0_zkvm::{default_prover, ExecutorEnv};
|
||||
use zkhash::{fields::{bn256::FpBN256, utils::random_scalar}/* , poseidon2::poseidon2_instance_bn256::POSEIDON2_BN256_PARAMS*/};
|
||||
// use zkhash::poseidon2::poseidon2::Poseidon2;
|
||||
// use std::convert::TryFrom;
|
||||
use std::time::Instant;
|
||||
// use zkhash::merkle_tree::merkle_tree_fp::MerkleTree;
|
||||
// use std::convert::TryInto;
|
||||
// use hex::encode_to_slice;
|
||||
use ark_serialize::{CanonicalSerialize, CanonicalDeserialize};
|
||||
|
||||
|
||||
@ -47,51 +42,4 @@ pub fn poseidon2_bn128_bench(mt_depth: usize) {
|
||||
eprintln!("Total time: {:?}", elapsed_time);
|
||||
eprintln!("Hash: {:?}", hash_final);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// let input2:[Scalar;16] = [Scalar::from(1), Scalar::from(2), Scalar::from(3), Scalar::from(4),Scalar::from(5), Scalar::from(6), Scalar::from(7), Scalar::from(8),Scalar::from(9), Scalar::from(10), Scalar::from(11), Scalar::from(12), Scalar::from(13), Scalar::from(14), Scalar::from(15), Scalar::from(16)];
|
||||
// let hash = merkle_tree.accumulate(&input2);
|
||||
|
||||
// let hash_string = hash.0.to_string();
|
||||
// // eprintln!("merkle hash: {:?}",hex::encode(hash_string));
|
||||
// eprintln!("merkle hash: {:?}", hash_string);
|
||||
|
||||
// let x = hash.0.0;
|
||||
// eprintln!("from: {:x}{:x}{:x}{:x}", x[0],x[1], x[2], x[3]);
|
||||
// eprintln!("scalar: {:?}", Scalar::from(4));
|
||||
|
||||
// let a = Scalar::from(4);
|
||||
// let mut uncompressed_bytes = Vec::new();
|
||||
// a.serialize_uncompressed(&mut uncompressed_bytes).unwrap();
|
||||
// eprintln!("compress: {:?}", uncompressed_bytes);
|
||||
|
||||
// let a_uncompressed = Scalar::deserialize_uncompressed(&*uncompressed_bytes).unwrap();
|
||||
// eprintln!("uncompress: {:?}", a_uncompressed);
|
||||
|
||||
// let t = poseidon2.get_t();
|
||||
// let input1: Vec<Scalar> = (0..t).map(|_| random_scalar()).collect();
|
||||
// let perm = poseidon2.permutation(&input1);
|
||||
// eprintln!("output: {:?}", perm);
|
||||
|
||||
// let env = ExecutorEnv::builder().write(&input).unwrap().build().unwrap();
|
||||
|
||||
// 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_elf(env, POSEIDON2_BN128_ELF).unwrap();
|
||||
// let elapsed_time = start_time.elapsed();
|
||||
|
||||
// // For example:
|
||||
// let _output: sha::Digest = receipt.journal.decode().unwrap();
|
||||
|
||||
// // verify your receipt
|
||||
// receipt.verify(POSEIDON2_BN128_ID).unwrap();
|
||||
|
||||
|
||||
// eprintln!("Total time: {:?}", elapsed_time);
|
||||
// eprintln!("Hash: {:?}", _output);
|
||||
}
|
||||
@ -6,6 +6,7 @@ use benches::{
|
||||
blake3::blake3_bench,
|
||||
poseidon2_bn128::poseidon2_bn128_bench,
|
||||
poseidon2_babybear::poseidon2_babybear_bench,
|
||||
poseidon2_babybear_native::poseidon2_babybear_native_bench,
|
||||
};
|
||||
use rand::Rng;
|
||||
|
||||
@ -63,6 +64,13 @@ fn main() {
|
||||
poseidon2_babybear_bench(size_kb);
|
||||
}
|
||||
|
||||
"poseidon2_babybear_native" => {
|
||||
println!("Poseidon2 Benchmarking on the BabyBear field: ");
|
||||
eprintln!("Tree Depth: {:?}", size_kb);
|
||||
eprintln!("number of inputs {:?}", (1 << size_kb) * 8);
|
||||
poseidon2_babybear_native_bench(size_kb);
|
||||
}
|
||||
|
||||
_ => {
|
||||
println!("Wrong Benchmark Name!");
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user