Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update blake2 requirement from 0.9 to 0.10 #51

Merged
merged 3 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
8 changes: 4 additions & 4 deletions src/gkr_round_sumcheck/test.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -59,9 +59,9 @@ fn test_circuit<F: Field>(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);
Expand All @@ -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();

Expand Down
6 changes: 3 additions & 3 deletions src/ml_sumcheck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -40,7 +40,7 @@ impl<F: Field> MLSumcheck<F> {
///
/// $$\sum_{i=0}^{n}C_i\cdot\prod_{j=0}^{m_i}P_{ij}$$
pub fn prove(polynomial: &ListOfProductsOfPolynomials<F>) -> Result<Proof<F>, 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)
}

Expand Down Expand Up @@ -75,7 +75,7 @@ impl<F: Field> MLSumcheck<F> {
claimed_sum: F,
proof: &Proof<F>,
) -> Result<SubClaim<F>, 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)
}

Expand Down
14 changes: 7 additions & 7 deletions src/ml_sumcheck/test.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -129,9 +129,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,
Expand All @@ -152,9 +152,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,
Expand All @@ -172,9 +172,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,
Expand Down
18 changes: 9 additions & 9 deletions src/rng.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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(),
}
}

Expand All @@ -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);
Expand All @@ -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() {
Expand All @@ -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;
Expand Down Expand Up @@ -171,6 +171,6 @@ mod tests {

#[test]
fn test_blake2s_hashing() {
test_deterministic_pseudorandom_generator::<Blake2s512Rng, Fr>(5)
test_deterministic_pseudorandom_generator::<Blake2b512Rng, Fr>(5)
}
}
Loading