mirror of
https://github.com/logos-storage/zk-benchmarks.git
synced 2026-01-04 06:43:09 +00:00
cycle prinitng removed in guest because it increases the overall cycle count
This commit is contained in:
parent
2a5def4a80
commit
d4085d4d0a
@ -8,7 +8,7 @@ edition = "2021"
|
||||
[dependencies]
|
||||
# If you want to try (experimental) std support, add `features = [ "std" ]` to risc0-zkvm
|
||||
risc0-zkvm = { path = "../../../external/risc0/risc0/zkvm", default-features = false,features = ["std"] }
|
||||
sha3 = "0.10.8"
|
||||
sha3 = { git = "https://github.com/risc0/RustCrypto-hashes", tag = "sha2-v0.10.6-risczero.0" }
|
||||
sha2 ={ git = "https://github.com/risc0/RustCrypto-hashes", tag = "sha2-v0.10.6-risczero.0" }
|
||||
risc0-zkp = {path = "../../../external/risc0/risc0/zkp"}
|
||||
blake3 = "1.5.0"
|
||||
|
||||
@ -7,7 +7,7 @@ use zkhash::poseidon2::poseidon2_instance_babybear::{/*POSEIDON2_BABYBEAR_16_PAR
|
||||
use zkhash::fields::babybear::FpBabyBear;
|
||||
use ark_serialize::{CanonicalSerialize, CanonicalDeserialize};
|
||||
use std::marker::PhantomData;
|
||||
use risc0_zkvm::guest::env::cycle_count;
|
||||
|
||||
|
||||
use ark_ff::PrimeField;
|
||||
|
||||
@ -100,21 +100,17 @@ pub fn main() {
|
||||
|
||||
let data: Vec<Vec<u8>> = env::read();
|
||||
|
||||
let cycles1 = cycle_count();
|
||||
let mut hash_data: Vec<FpBabyBear> = Vec::new();
|
||||
for i in 0..data.len() {
|
||||
let a_uncompressed = FpBabyBear::deserialize_uncompressed(&**data.get(i).unwrap()).unwrap();
|
||||
hash_data.push(a_uncompressed);
|
||||
}
|
||||
let cycles2 = cycle_count();
|
||||
|
||||
|
||||
let permutation = poseidon2::Poseidon2::new(&POSEIDON2_BABYBEAR_24_PARAMS);
|
||||
let mut merkle_tree = MerkleTree::new(permutation.clone());
|
||||
let cycles3 = cycle_count();
|
||||
|
||||
let hash_final = merkle_tree.accumulate(&hash_data);
|
||||
|
||||
let cycles4 = cycle_count();
|
||||
|
||||
let mut perm_seralised: Vec<Vec<u8>> = Vec::new();
|
||||
for i in 0..8 {
|
||||
@ -122,14 +118,8 @@ pub fn main() {
|
||||
hash_final.get(i).unwrap().serialize_uncompressed(&mut temp).unwrap();
|
||||
perm_seralised.push(temp);
|
||||
}
|
||||
let cycles6 = cycle_count();
|
||||
|
||||
|
||||
env::commit(&perm_seralised);
|
||||
|
||||
eprintln!("number of cycles for input builder: {:?}", cycles2 - cycles1);
|
||||
eprintln!("number of cycles for hash permutation builder: {:?}", cycles3 - cycles2);
|
||||
eprintln!("number of cycles for hash accumulation: {:?}", cycles4 - cycles3);
|
||||
|
||||
eprintln!("number of cycles for permutation seralisation: {:?}", cycles6 - cycles4);
|
||||
|
||||
}
|
||||
|
||||
@ -6,7 +6,6 @@ use std::marker::PhantomData;
|
||||
use std::sync::Arc;
|
||||
use risc0_core::field::Elem;
|
||||
use lazy_static::lazy_static;
|
||||
use risc0_zkvm::guest::env::cycle_count;
|
||||
|
||||
// This code is adapted from https://github.com/HorizenLabs/poseidon2/tree/main
|
||||
#[derive(Clone, Debug)]
|
||||
@ -1727,21 +1726,16 @@ pub fn main() {
|
||||
|
||||
let data: Vec<u32> = env::read();
|
||||
|
||||
let cycles1 = cycle_count();
|
||||
let mut hash_data: Vec<BabyBearElem> = Vec::new();
|
||||
for i in 0..data.len() {
|
||||
let a_uncompressed = BabyBearElem::from(*data.get(i).unwrap());
|
||||
hash_data.push(a_uncompressed);
|
||||
}
|
||||
let cycles2 = cycle_count();
|
||||
|
||||
|
||||
let permutation = Poseidon2::new(&POSEIDON2_BABYBEAR_24_PARAMS);
|
||||
let mut merkle_tree = MerkleTree::new(permutation.clone());
|
||||
let cycles3 = cycle_count();
|
||||
let hash_final = merkle_tree.accumulate(&hash_data);
|
||||
|
||||
let cycles4 = cycle_count();
|
||||
|
||||
let mut perm_seralised: Vec<u32> = Vec::new();
|
||||
for i in 0..8 {
|
||||
@ -1749,14 +1743,8 @@ pub fn main() {
|
||||
perm_seralised.push(temp);
|
||||
|
||||
}
|
||||
let cycles6 = cycle_count();
|
||||
|
||||
env::commit(&perm_seralised);
|
||||
|
||||
eprintln!("number of cycles for input builder: {:?}", cycles2 - cycles1);
|
||||
eprintln!("number of cycles for hash permutation builder: {:?}", cycles3 - cycles2);
|
||||
eprintln!("number of cycles for hash accumulation: {:?}", cycles4 - cycles3);
|
||||
|
||||
eprintln!("number of cycles for permutation seralisation: {:?}", cycles6 - cycles4);
|
||||
|
||||
}
|
||||
|
||||
@ -1,43 +1,33 @@
|
||||
#![no_main]
|
||||
use risc0_zkvm::{guest::env/* , sha::Digest*/};
|
||||
// use sha3::{Digest as _, Keccak256};
|
||||
use risc0_zkvm::guest::env;
|
||||
use zkhash::poseidon2::poseidon2;
|
||||
use zkhash::poseidon2::poseidon2_instance_bn256::POSEIDON2_BN256_PARAMS;
|
||||
use zkhash::merkle_tree::merkle_tree_fp::MerkleTree;
|
||||
use zkhash::fields::bn256::FpBN256;
|
||||
use ark_serialize::{CanonicalSerialize, CanonicalDeserialize};
|
||||
use risc0_zkvm::guest::env::cycle_count;
|
||||
|
||||
risc0_zkvm::guest::entry!(main);
|
||||
|
||||
pub fn main() {
|
||||
|
||||
let data: Vec<Vec<u8>> = env::read();
|
||||
let cycles1 = cycle_count();
|
||||
|
||||
let mut hash_data: Vec<FpBN256> = Vec::new();
|
||||
for i in 0..data.len() {
|
||||
let a_uncompressed = FpBN256::deserialize_uncompressed(&**data.get(i).unwrap()).unwrap();
|
||||
hash_data.push(a_uncompressed);
|
||||
}
|
||||
let cycles2 = cycle_count();
|
||||
|
||||
|
||||
let permutation = poseidon2::Poseidon2::new(&POSEIDON2_BN256_PARAMS);
|
||||
let mut merkle_tree = MerkleTree::new(permutation.clone());
|
||||
let cycles4 = cycle_count();
|
||||
let hash_final = merkle_tree.accumulate(&hash_data);
|
||||
let cycles5 = cycle_count();
|
||||
|
||||
|
||||
let hash_final = merkle_tree.accumulate(&hash_data);
|
||||
|
||||
let mut hash_bytes: Vec<u8> = Vec::new();
|
||||
hash_final.serialize_uncompressed(&mut hash_bytes).unwrap();
|
||||
|
||||
let cycles6 = cycle_count();
|
||||
|
||||
env::commit(&hash_bytes);
|
||||
|
||||
eprintln!("number of cycles for input builder: {:?}", cycles2 - cycles1);
|
||||
eprintln!("number of cycles for hash builder: {:?}", cycles4 - cycles2);
|
||||
eprintln!("number of cycles for hash calculation: {:?}", cycles5 - cycles4);
|
||||
eprintln!("number of cycles for hash serealisation: {:?}", cycles6 - cycles5);
|
||||
|
||||
}
|
||||
|
||||
@ -3,16 +3,14 @@
|
||||
use std::io::Read;
|
||||
use risc0_zkvm::{guest::env, sha, sha::Sha256};
|
||||
risc0_zkvm::guest::entry!(main);
|
||||
use risc0_zkvm::guest::env::cycle_count;
|
||||
|
||||
pub fn main() {
|
||||
let start = cycle_count();
|
||||
|
||||
let mut data = Vec::<u8>::new();
|
||||
env::stdin().read_to_end(&mut data).unwrap();
|
||||
let end = cycle_count();
|
||||
|
||||
let hash = sha::Impl::hash_bytes(&data);
|
||||
eprintln!("total cycle count for input: {:?}",end - start);
|
||||
eprintln!("total cycle count for hashing: {:?}",cycle_count());
|
||||
|
||||
env::commit(&hash)
|
||||
}
|
||||
|
||||
|
||||
@ -4,8 +4,7 @@
|
||||
use std::io::Read;
|
||||
use risc0_zkvm::guest::env;
|
||||
use sha2::{Sha256, Digest};
|
||||
use risc0_zkvm::guest::env::cycle_count;
|
||||
// use base16ct::lower::encode_str;
|
||||
|
||||
risc0_zkvm::guest::entry!(main);
|
||||
|
||||
pub fn main() {
|
||||
@ -14,10 +13,8 @@ pub fn main() {
|
||||
env::stdin().read_to_end(&mut data).unwrap();
|
||||
|
||||
let result = Sha256::digest(data);
|
||||
let c1 = cycle_count();
|
||||
eprintln!("total cycle count for hashing: {:?}",c1);
|
||||
|
||||
let result_bytes: [u8;32] = result.into();
|
||||
let c2 = cycle_count();
|
||||
eprintln!("cycle count to convert into bytes array: {:?}",c2-c1);
|
||||
|
||||
env::commit(&result_bytes)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user