mirror of
https://github.com/logos-storage/zk-benchmarks.git
synced 2026-01-08 00:33:12 +00:00
poseidon2 input changed to vec<u32>, blake2s replaced with blake2b
This commit is contained in:
parent
8c6118980f
commit
3e7b01097e
@ -4,7 +4,7 @@
|
||||
use sha2::{Sha256, Digest};
|
||||
use sha3::Keccak256;
|
||||
use blake3::hash;
|
||||
use blake2::Blake2s256;
|
||||
use blake2::Blake2b512;
|
||||
|
||||
use risc0_zkp::core::hash::poseidon2::Poseidon2HashSuite;
|
||||
use risc0_zkp::field::baby_bear::BabyBearElem;
|
||||
@ -39,25 +39,27 @@ fn blake3(input: &[u8]) -> [u8; 32] {
|
||||
|
||||
// blake2
|
||||
#[jolt::provable]
|
||||
fn blake2(input: &[u8]) -> [u8; 32] {
|
||||
let mut hasher = Blake2s256::new();
|
||||
fn blake2(input: &[u8]) -> Vec<u8> {
|
||||
let mut hasher = Blake2b512::new();
|
||||
hasher.update(input);
|
||||
let result = hasher.finalize();
|
||||
Into::<[u8; 32]>::into(result)
|
||||
|
||||
result.to_vec()
|
||||
}
|
||||
|
||||
// poseidon2 over babybear
|
||||
#[jolt::provable(stack_size = 10000, memory_size = 100000000)]
|
||||
//TODO: input should be made u32
|
||||
fn poseidon2_babybear(input: &[u8]) -> String {
|
||||
fn poseidon2_babybear(input: Vec<u32>) -> Vec<u32> {
|
||||
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()
|
||||
let mut binding = Poseidon2HashSuite::new_suite().hashfn.hash_elem_slice(hash_data.as_slice());
|
||||
let result = binding.as_mut_words().to_vec();
|
||||
|
||||
result
|
||||
|
||||
}
|
||||
@ -8,12 +8,12 @@ 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();
|
||||
let mut input: Vec<u32> = Vec::new();
|
||||
|
||||
for _ in 0..t {
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
let random_u32: u8 = rng.gen();
|
||||
let random_u32: u32 = rng.gen();
|
||||
input.push(random_u32);
|
||||
}
|
||||
|
||||
@ -29,7 +29,7 @@ pub fn poseidon2_babybear_bench(mt_depth: usize) {
|
||||
let (output, proof, proving_time) = {
|
||||
|
||||
let start = Instant::now();
|
||||
let (output, proof) = prove_poseidon2_babybear(input.as_slice());
|
||||
let (output, proof) = prove_poseidon2_babybear(input);
|
||||
let elapsed = start.elapsed();
|
||||
|
||||
(output, proof, elapsed)
|
||||
@ -47,8 +47,13 @@ pub fn poseidon2_babybear_bench(mt_depth: usize) {
|
||||
(is_valid, elapsed)
|
||||
};
|
||||
|
||||
let mut output_bytes: Vec<u8> = Vec::new();
|
||||
for i in 0..8 {
|
||||
output_bytes.extend_from_slice(output[i].to_be_bytes().as_slice());
|
||||
}
|
||||
|
||||
assert!(is_valid);
|
||||
println!("output: {:?}", hex::encode(output));
|
||||
println!("output: {:?}", hex::encode(&output_bytes));
|
||||
println!("guest build time: {:?}", guest_build_time);
|
||||
println!("proving time: {:?}", proving_time);
|
||||
println!("verification time: {:?}", verification_time);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user