From a8034ed1f6c2be72670e97b38f2082aa4efdf603 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 8 Dec 2021 01:35:25 +0000 Subject: [PATCH 1/2] Update blake2 requirement from 0.9 to 0.10 Updates the requirements on [blake2](https://github.com/RustCrypto/hashes) to permit the latest version. - [Release notes](https://github.com/RustCrypto/hashes/releases) - [Commits](https://github.com/RustCrypto/hashes/compare/groestl-v0.9.0...blake2-v0.10.0) --- updated-dependencies: - dependency-name: blake2 dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 11fb80d..f1c0f90 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,8 +20,8 @@ ark-ff = { version = "0.4.0", default-features = false } ark-serialize = { version = "0.4.0", default-features = false, features = ["derive"] } ark-std = { version = "0.4.0", default-features = false } ark-poly = { version = "0.4.0", default-features = false } -blake2 = { version = "0.9", default-features = false } hashbrown = { version = "0.14.0" } +blake2 = { version = "0.10", default-features = false } rayon = { version = "1", optional = true } [dev-dependencies] From 94e46fdcd3d4e5f4f9480b6ea6768112a8757609 Mon Sep 17 00:00:00 2001 From: mmagician Date: Thu, 25 Jan 2024 16:13:24 +0100 Subject: [PATCH 2/2] replace Blake2s with Blake2b --- src/gkr_round_sumcheck/test.rs | 8 ++++---- src/ml_sumcheck/mod.rs | 6 +++--- src/ml_sumcheck/test.rs | 14 +++++++------- src/rng.rs | 18 +++++++++--------- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/gkr_round_sumcheck/test.rs b/src/gkr_round_sumcheck/test.rs index 9719e31..c9899a9 100644 --- a/src/gkr_round_sumcheck/test.rs +++ b/src/gkr_round_sumcheck/test.rs @@ -1,5 +1,5 @@ use crate::gkr_round_sumcheck::GKRRoundSumcheck; -use crate::rng::{Blake2s512Rng, FeedableRNG}; +use crate::rng::{Blake2b512Rng, FeedableRNG}; use ark_ff::Field; use ark_poly::{DenseMultilinearExtension, MultilinearExtension, SparseMultilinearExtension}; use ark_std::rand::RngCore; @@ -59,9 +59,9 @@ fn test_circuit(nv: usize) { let (f1, f2, f3) = random_gkr_instance(nv, &mut rng); let g: Vec<_> = (0..nv).map(|_| F::rand(&mut rng)).collect(); let claimed_sum = calculate_sum_naive(&f1, &f2, &f3, &g); - let mut rng = Blake2s512Rng::setup(); + let mut rng = Blake2b512Rng::setup(); let proof = GKRRoundSumcheck::prove(&mut rng, &f1, &f2, &f3, &g); - rng = Blake2s512Rng::setup(); + rng = Blake2b512Rng::setup(); let subclaim = GKRRoundSumcheck::verify(&mut rng, f2.num_vars, &proof, claimed_sum) .expect("verification failed"); let result = subclaim.verify_subclaim(&f1, &f2, &f3, &g); @@ -80,7 +80,7 @@ fn test_extract() { let (f1, f2, f3) = random_gkr_instance(nv, &mut rng); let g: Vec<_> = (0..nv).map(|_| Fr::rand(&mut rng)).collect(); let expected_sum = calculate_sum_naive(&f1, &f2, &f3, &g); - let mut rng = Blake2s512Rng::setup(); + let mut rng = Blake2b512Rng::setup(); let proof = GKRRoundSumcheck::prove(&mut rng, &f1, &f2, &f3, &g); let actual_sum = proof.extract_sum(); diff --git a/src/ml_sumcheck/mod.rs b/src/ml_sumcheck/mod.rs index 4fd2f9f..52c8ad0 100644 --- a/src/ml_sumcheck/mod.rs +++ b/src/ml_sumcheck/mod.rs @@ -4,7 +4,7 @@ use crate::ml_sumcheck::data_structures::{ListOfProductsOfPolynomials, Polynomia use crate::ml_sumcheck::protocol::prover::{ProverMsg, ProverState}; use crate::ml_sumcheck::protocol::verifier::SubClaim; use crate::ml_sumcheck::protocol::IPForMLSumcheck; -use crate::rng::{Blake2s512Rng, FeedableRNG}; +use crate::rng::{Blake2b512Rng, FeedableRNG}; use ark_ff::Field; use ark_std::marker::PhantomData; use ark_std::vec::Vec; @@ -40,7 +40,7 @@ impl MLSumcheck { /// /// $$\sum_{i=0}^{n}C_i\cdot\prod_{j=0}^{m_i}P_{ij}$$ pub fn prove(polynomial: &ListOfProductsOfPolynomials) -> Result, crate::Error> { - let mut fs_rng = Blake2s512Rng::setup(); + let mut fs_rng = Blake2b512Rng::setup(); Self::prove_as_subprotocol(&mut fs_rng, polynomial).map(|r| r.0) } @@ -72,7 +72,7 @@ impl MLSumcheck { claimed_sum: F, proof: &Proof, ) -> Result, crate::Error> { - let mut fs_rng = Blake2s512Rng::setup(); + let mut fs_rng = Blake2b512Rng::setup(); Self::verify_as_subprotocol(&mut fs_rng, polynomial_info, claimed_sum, proof) } diff --git a/src/ml_sumcheck/test.rs b/src/ml_sumcheck/test.rs index 415f5ff..6d92755 100644 --- a/src/ml_sumcheck/test.rs +++ b/src/ml_sumcheck/test.rs @@ -1,7 +1,7 @@ use crate::ml_sumcheck::data_structures::ListOfProductsOfPolynomials; use crate::ml_sumcheck::protocol::IPForMLSumcheck; use crate::ml_sumcheck::MLSumcheck; -use crate::rng::Blake2s512Rng; +use crate::rng::Blake2b512Rng; use crate::rng::FeedableRNG; use ark_ff::Field; use ark_poly::{DenseMultilinearExtension, MultilinearExtension}; @@ -128,9 +128,9 @@ fn test_trivial_polynomial() { test_polynomial(nv, num_multiplicands_range, num_products); test_protocol(nv, num_multiplicands_range, num_products); - let mut prover_rng = Blake2s512Rng::setup(); + let mut prover_rng = Blake2b512Rng::setup(); prover_rng.feed(b"Test Trivial Works").unwrap(); - let mut verifier_rng = Blake2s512Rng::setup(); + let mut verifier_rng = Blake2b512Rng::setup(); verifier_rng.feed(b"Test Trivial Works").unwrap(); test_polynomial_as_subprotocol( nv, @@ -151,9 +151,9 @@ fn test_normal_polynomial() { test_polynomial(nv, num_multiplicands_range, num_products); test_protocol(nv, num_multiplicands_range, num_products); - let mut prover_rng = Blake2s512Rng::setup(); + let mut prover_rng = Blake2b512Rng::setup(); prover_rng.feed(b"Test Trivial Works").unwrap(); - let mut verifier_rng = Blake2s512Rng::setup(); + let mut verifier_rng = Blake2b512Rng::setup(); verifier_rng.feed(b"Test Trivial Works").unwrap(); test_polynomial_as_subprotocol( nv, @@ -171,9 +171,9 @@ fn test_normal_polynomial_different_transcripts_fails() { let num_multiplicands_range = (4, 9); let num_products = 5; - let mut prover_rng = Blake2s512Rng::setup(); + let mut prover_rng = Blake2b512Rng::setup(); prover_rng.feed(b"Test Trivial Works").unwrap(); - let mut verifier_rng = Blake2s512Rng::setup(); + let mut verifier_rng = Blake2b512Rng::setup(); verifier_rng.feed(b"Test Trivial Fails").unwrap(); test_polynomial_as_subprotocol( nv, diff --git a/src/rng.rs b/src/rng.rs index fd9cf9e..c61d20d 100644 --- a/src/rng.rs +++ b/src/rng.rs @@ -2,7 +2,7 @@ use ark_serialize::CanonicalSerialize; use ark_std::rand::RngCore; use ark_std::vec::Vec; -use blake2::{Blake2s, Digest}; +use blake2::{Blake2b512, Digest}; /// Random Field Element Generator where randomness `feed` adds entropy for the output. /// /// Implementation should support all types of input that has `ToBytes` trait. @@ -19,17 +19,17 @@ pub trait FeedableRNG: RngCore { } /// 512-bits digest hash pseudorandom generator -pub struct Blake2s512Rng { +pub struct Blake2b512Rng { /// current digest instance - current_digest: Blake2s, + current_digest: Blake2b512, } -impl FeedableRNG for Blake2s512Rng { +impl FeedableRNG for Blake2b512Rng { type Error = crate::Error; fn setup() -> Self { Self { - current_digest: Blake2s::new(), + current_digest: Blake2b512::new(), } } @@ -41,7 +41,7 @@ impl FeedableRNG for Blake2s512Rng { } } -impl RngCore for Blake2s512Rng { +impl RngCore for Blake2b512Rng { fn next_u32(&mut self) -> u32 { let mut temp = [0u8; 4]; self.fill_bytes(&mut temp); @@ -61,7 +61,7 @@ impl RngCore for Blake2s512Rng { fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), ark_std::rand::Error> { let mut digest = self.current_digest.clone(); let mut output = digest.finalize(); - let output_size = Blake2s::output_size(); + let output_size = Blake2b512::output_size(); let mut ptr = 0; let mut digest_ptr = 0; while ptr < dest.len() { @@ -86,7 +86,7 @@ mod tests { use ark_std::rand::Rng; use ark_std::rand::RngCore; - use crate::rng::{Blake2s512Rng, FeedableRNG}; + use crate::rng::{Blake2b512Rng, FeedableRNG}; use ark_serialize::CanonicalSerialize; use ark_std::test_rng; use ark_std::vec::Vec; @@ -171,6 +171,6 @@ mod tests { #[test] fn test_blake2s_hashing() { - test_deterministic_pseudorandom_generator::(5) + test_deterministic_pseudorandom_generator::(5) } }