mirror of
https://github.com/logos-storage/zk-benchmarks.git
synced 2026-01-11 10:13:06 +00:00
initial commit for sha2 and sha3 hash benchmarking
This commit is contained in:
parent
882b2218f9
commit
ce25376b1d
1
hash/jolt/bench/.gitignore
vendored
Normal file
1
hash/jolt/bench/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
target
|
||||||
3784
hash/jolt/bench/Cargo.lock
generated
Normal file
3784
hash/jolt/bench/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
22
hash/jolt/bench/Cargo.toml
Normal file
22
hash/jolt/bench/Cargo.toml
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
[package]
|
||||||
|
name = "bench"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[workspace]
|
||||||
|
members = ["guest"]
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
debug = 1
|
||||||
|
codegen-units = 1
|
||||||
|
lto = "fat"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
jolt = { package = "jolt-sdk", git = "https://github.com/a16z/jolt",rev = "4805d038f7b6e7ca5e7ef64aefa62213aecac01a", features = ["host"] }
|
||||||
|
guest = { path = "./guest" }
|
||||||
|
rand = "0.8.3"
|
||||||
|
|
||||||
|
[patch.crates-io]
|
||||||
|
ark-ff = { git = "https://github.com/a16z/arkworks-algebra", branch = "optimize/field-from-u64" }
|
||||||
|
ark-ec = { git = "https://github.com/a16z/arkworks-algebra", branch = "optimize/field-from-u64" }
|
||||||
|
ark-serialize = { git = "https://github.com/a16z/arkworks-algebra", branch = "optimize/field-from-u64" }
|
||||||
1
hash/jolt/bench/build.sh
Executable file
1
hash/jolt/bench/build.sh
Executable file
@ -0,0 +1 @@
|
|||||||
|
cargo build --release
|
||||||
16
hash/jolt/bench/guest/Cargo.toml
Normal file
16
hash/jolt/bench/guest/Cargo.toml
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
[package]
|
||||||
|
name = "guest"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "guest"
|
||||||
|
path = "./src/lib.rs"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
guest = []
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
jolt = { package = "jolt-sdk", git = "https://github.com/a16z/jolt", rev = "4805d038f7b6e7ca5e7ef64aefa62213aecac01a"}
|
||||||
|
sha2 = { version = "0.10.8", default-features = false }
|
||||||
|
sha3 = { version = "0.10.8", default-features = false }
|
||||||
23
hash/jolt/bench/guest/src/lib.rs
Normal file
23
hash/jolt/bench/guest/src/lib.rs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#![cfg_attr(feature = "guest", no_std)]
|
||||||
|
#![no_main]
|
||||||
|
|
||||||
|
use sha2::{Sha256, Digest};
|
||||||
|
use sha3::Keccak256;
|
||||||
|
|
||||||
|
// sha256
|
||||||
|
#[jolt::provable]
|
||||||
|
fn sha2(input: &[u8]) -> [u8; 32] {
|
||||||
|
let mut hasher = Sha256::new();
|
||||||
|
hasher.update(input);
|
||||||
|
let result = hasher.finalize();
|
||||||
|
Into::<[u8; 32]>::into(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
// keccak
|
||||||
|
#[jolt::provable]
|
||||||
|
fn sha3(input: &[u8]) -> [u8; 32] {
|
||||||
|
let mut hasher = Keccak256::new();
|
||||||
|
hasher.update(input);
|
||||||
|
let result = hasher.finalize();
|
||||||
|
Into::<[u8; 32]>::into(result)
|
||||||
|
}
|
||||||
1
hash/jolt/bench/run.sh
Executable file
1
hash/jolt/bench/run.sh
Executable file
@ -0,0 +1 @@
|
|||||||
|
./target/release/bench
|
||||||
3
hash/jolt/bench/rust-toolchain.toml
Normal file
3
hash/jolt/bench/rust-toolchain.toml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
[toolchain]
|
||||||
|
channel = "nightly-2024-08-01"
|
||||||
|
targets = ["riscv32im-unknown-none-elf"]
|
||||||
27
hash/jolt/bench/src/main.rs
Normal file
27
hash/jolt/bench/src/main.rs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
use rand::Rng;
|
||||||
|
|
||||||
|
fn generate_bytes(size: usize) -> Vec<u8> {
|
||||||
|
let mut rng = rand::thread_rng();
|
||||||
|
(0..size).map(|_| rng.gen()).collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn main() {
|
||||||
|
let (prove_sha2, verify_sha2) = guest::build_sha2();
|
||||||
|
let (prove_sha3, verify_sha3) = guest::build_sha3();
|
||||||
|
|
||||||
|
// random data
|
||||||
|
let binding = generate_bytes(1024);
|
||||||
|
let input = binding.as_slice();
|
||||||
|
|
||||||
|
let (output, proof) = prove_sha2(input);
|
||||||
|
let is_valid = verify_sha2(proof);
|
||||||
|
|
||||||
|
println!("sha2 output: {:?}", output);
|
||||||
|
println!("sha2 valid: {}", is_valid);
|
||||||
|
|
||||||
|
let (output, proof) = prove_sha3(input);
|
||||||
|
let is_valid = verify_sha3(proof);
|
||||||
|
|
||||||
|
println!("sha3 output: {:?}", output);
|
||||||
|
println!("sha3 valid: {}", is_valid);
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user