From 839e3448e11a9b168b83be89a6013eaec7696164 Mon Sep 17 00:00:00 2001 From: Manish Kumar Date: Wed, 24 Apr 2024 23:15:15 +0530 Subject: [PATCH] plonky2 version changed to 0.2.2, build.sh and run.sh added --- hash/plonky2/Cargo.toml | 9 +++++---- hash/plonky2/build.sh | 8 ++++++++ hash/plonky2/run.sh | 15 +++++++++++++++ hash/plonky2/src/bench/keccak.rs | 2 +- hash/plonky2/src/bench/poseidon.rs | 19 +++++++++++++++++-- hash/plonky2/src/bench/sha256/sha.rs | 2 -- hash/risc0/external/risc0 | 2 +- 7 files changed, 47 insertions(+), 10 deletions(-) create mode 100755 hash/plonky2/build.sh create mode 100755 hash/plonky2/run.sh diff --git a/hash/plonky2/Cargo.toml b/hash/plonky2/Cargo.toml index 615fea1..cc7a85d 100644 --- a/hash/plonky2/Cargo.toml +++ b/hash/plonky2/Cargo.toml @@ -1,14 +1,15 @@ [package] -name = "plonky2" +name = "plonky2_hash_benchmarks" version = "0.1.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -plonky2_u32 ={ git = "https://github.com/0xPolygonZero/plonky2-u32"} -plonky2_field ={ git = "https://github.com/0xPolygonZero/plonky2"} -plonky2 = "0.1.4" + +# TODO: This can be later changed to original github +plonky2_u32 ={ git = "https://github.com/man2706kum/plonky2-u32.git"} +plonky2 = "0.2.2" rand = "0.8.3" anyhow = "1.0.79" sha2 = "0.10" diff --git a/hash/plonky2/build.sh b/hash/plonky2/build.sh new file mode 100755 index 0000000..749ad6c --- /dev/null +++ b/hash/plonky2/build.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +# Set nightly as the default toolchain +rustup override set nightly + +# Build +cargo build + diff --git a/hash/plonky2/run.sh b/hash/plonky2/run.sh new file mode 100755 index 0000000..9f1d247 --- /dev/null +++ b/hash/plonky2/run.sh @@ -0,0 +1,15 @@ +#!/bin/bash +if [ -z ${ZKBENCH_HASH_TYPE} ]; then +ZKBENCH_HASH_TYPE="poseidon" +fi + +if [ -z ${ZKBENCH_INPUT_SIZE_BYTES} ]; then +ZKBENCH_INPUT_SIZE_BYTES=4 +fi + +echo "Running benchmarks with the following configurations:" +echo "HASH = $ZKBENCH_HASH_TYPE" +echo "Input Size (Bytes) = $ZKBENCH_INPUT_SIZE_BYTES" + +# Run the benchmarks +./target/debug/plonky2_hash_benchmarks $ZKBENCH_HASH_TYPE $ZKBENCH_INPUT_SIZE_BYTES \ No newline at end of file diff --git a/hash/plonky2/src/bench/keccak.rs b/hash/plonky2/src/bench/keccak.rs index 785e853..ac7a356 100644 --- a/hash/plonky2/src/bench/keccak.rs +++ b/hash/plonky2/src/bench/keccak.rs @@ -19,7 +19,7 @@ -pub fn keccak_bench(size: usize) { +pub fn keccak_bench(_size: usize) { } diff --git a/hash/plonky2/src/bench/poseidon.rs b/hash/plonky2/src/bench/poseidon.rs index 706f040..1f176eb 100644 --- a/hash/plonky2/src/bench/poseidon.rs +++ b/hash/plonky2/src/bench/poseidon.rs @@ -10,6 +10,7 @@ use plonky2::plonk::circuit_builder::CircuitBuilder; use plonky2::plonk::circuit_data::CircuitConfig; use plonky2::plonk::config::{/*AlgebraicHasher,*/ GenericConfig, PoseidonGoldilocksConfig}; use rand::Rng; +use std::time; fn generate_data(size: usize) -> Vec { // let mut rng = rand::thread_rng(); @@ -56,9 +57,23 @@ pub fn poseidon_bench(depth: usize) -> Result<()> { let data = builder.build::(); - let proof = data.prove(pw)?; + let (proof_generation_time, proof) = { - data.verify(proof) + let start = time::Instant::now(); + let proof = data.prove(pw)?; + let end_time = start.elapsed(); + (end_time, proof) + }; + + let (verification_time, result) = { + let start = time::Instant::now(); + let result = data.verify(proof); + let end_time = start.elapsed(); + (end_time, result) + }; + eprintln!("proof generation time: {:?}", proof_generation_time); + eprintln!("verification time: {:?}", verification_time); + result } diff --git a/hash/plonky2/src/bench/sha256/sha.rs b/hash/plonky2/src/bench/sha256/sha.rs index 7d092e9..0d52002 100644 --- a/hash/plonky2/src/bench/sha256/sha.rs +++ b/hash/plonky2/src/bench/sha256/sha.rs @@ -1,6 +1,5 @@ use plonky2::iop::target::BoolTarget; use plonky2::hash::hash_types::RichField; -use plonky2::iop::target::Target; use plonky2::plonk::circuit_builder::CircuitBuilder; use plonky2::field::extension::Extendable; use plonky2_u32::gadgets::arithmetic_u32::{CircuitBuilderU32, U32Target}; @@ -9,7 +8,6 @@ use plonky2::plonk::config::PoseidonGoldilocksConfig; use plonky2::plonk::config::GenericConfig; use plonky2::plonk::circuit_data::CircuitConfig; use plonky2::iop::witness::{PartialWitness, WitnessWrite}; -// use rand::Rng; use sha2::{Digest, Sha256}; use super::sigma::big_sigma0; use super::sigma::big_sigma1; diff --git a/hash/risc0/external/risc0 b/hash/risc0/external/risc0 index 1742ef8..02fad7a 160000 --- a/hash/risc0/external/risc0 +++ b/hash/risc0/external/risc0 @@ -1 +1 @@ -Subproject commit 1742ef8098d246871055501a0559811c9a8fece4 +Subproject commit 02fad7a498764d5c6cc851f246813b73b41c30b8