From a44062ad8a52300949a4051bfb18d3981bebaa3d Mon Sep 17 00:00:00 2001 From: mmagician Date: Sat, 11 Nov 2023 13:16:33 +0100 Subject: [PATCH 1/3] Enable parallel commitment in hyrax amend --- poly-commit/Cargo.toml | 2 +- poly-commit/src/hyrax/mod.rs | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/poly-commit/Cargo.toml b/poly-commit/Cargo.toml index 1c2a6347..5379ba6d 100644 --- a/poly-commit/Cargo.toml +++ b/poly-commit/Cargo.toml @@ -17,7 +17,7 @@ ark-crypto-primitives = {version = "^0.4.0", default-features = false, features ark-std = { version = "^0.4.0", default-features = false } blake2 = { version = "0.10", default-features = false } merlin = { version = "3.0.0", default-features = false } - +rand = { version = "0.8.0" } ark-relations = { version = "^0.4.0", default-features = false, optional = true } ark-r1cs-std = { version = "^0.4.0", default-features = false, optional = true } diff --git a/poly-commit/src/hyrax/mod.rs b/poly-commit/src/hyrax/mod.rs index 887fa255..307eec85 100644 --- a/poly-commit/src/hyrax/mod.rs +++ b/poly-commit/src/hyrax/mod.rs @@ -231,6 +231,7 @@ impl> /// /// Panics if `rng` is None, since Hyrax requires randomness in order to /// commit to a polynomial + #[allow(unused_variables)] fn commit<'a>( ck: &Self::CommitterKey, polynomials: impl IntoIterator>, @@ -248,10 +249,11 @@ impl> let mut coms = Vec::new(); let mut rands = Vec::new(); + #[cfg(not(feature = "parallel"))] let rng_inner = rng.expect("Committing to polynomials requires a random generator"); for l_poly in polynomials { - let mut com_rands = Vec::new(); + // let mut com_rands = Vec::new(); let label = l_poly.label(); let poly = l_poly.polynomial(); @@ -272,15 +274,16 @@ impl> let m = flat_to_matrix_column_major(&poly.to_evaluations(), dim, dim); // Commiting to the matrix with one multi-commitment per row - let row_coms = m - .iter() + let (row_coms, com_rands): (Vec<_>, Vec<_>) = cfg_iter!(m) .map(|row| { + #[cfg(not(feature = "parallel"))] let (c, r) = Self::pedersen_commit(ck, row, None, Some(rng_inner)); - // Storing the randomness used in the commitment - com_rands.push(r); - c + #[cfg(feature = "parallel")] + let (c, r) = + Self::pedersen_commit(ck, row, None, Some(&mut rand::thread_rng())); + (c, r) }) - .collect(); + .unzip(); let com = HyraxCommitment { row_coms }; let l_comm = LabeledCommitment::new(label.to_string(), com, Some(1)); From 3a7a8be313ebf51148f0341fd21802a291c210b5 Mon Sep 17 00:00:00 2001 From: mmagician Date: Sat, 11 Nov 2023 13:16:04 +0100 Subject: [PATCH 2/3] make `rand` optional --- poly-commit/Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/poly-commit/Cargo.toml b/poly-commit/Cargo.toml index 5379ba6d..57c68b85 100644 --- a/poly-commit/Cargo.toml +++ b/poly-commit/Cargo.toml @@ -17,7 +17,7 @@ ark-crypto-primitives = {version = "^0.4.0", default-features = false, features ark-std = { version = "^0.4.0", default-features = false } blake2 = { version = "0.10", default-features = false } merlin = { version = "3.0.0", default-features = false } -rand = { version = "0.8.0" } +rand = { version = "0.8.0", optional = true } ark-relations = { version = "^0.4.0", default-features = false, optional = true } ark-r1cs-std = { version = "^0.4.0", default-features = false, optional = true } @@ -55,4 +55,4 @@ default = [ "std", "parallel" ] std = [ "ark-ff/std", "ark-ec/std", "ark-poly/std", "ark-std/std", "ark-relations/std", "ark-serialize/std", "ark-crypto-primitives/std"] r1cs = [ "ark-relations", "ark-r1cs-std", "hashbrown", "ark-crypto-primitives/r1cs"] print-trace = [ "ark-std/print-trace" ] -parallel = [ "std", "ark-ff/parallel", "ark-ec/parallel", "ark-poly/parallel", "ark-std/parallel", "rayon" ] +parallel = [ "std", "ark-ff/parallel", "ark-ec/parallel", "ark-poly/parallel", "ark-std/parallel", "rayon", "rand" ] From 7efce972f3cc470c2ba1e48b808dcbdac6bbb240 Mon Sep 17 00:00:00 2001 From: mmagician Date: Sat, 11 Nov 2023 13:19:32 +0100 Subject: [PATCH 3/3] remove dead code --- poly-commit/src/hyrax/mod.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/poly-commit/src/hyrax/mod.rs b/poly-commit/src/hyrax/mod.rs index 307eec85..6ce4a444 100644 --- a/poly-commit/src/hyrax/mod.rs +++ b/poly-commit/src/hyrax/mod.rs @@ -253,8 +253,6 @@ impl> let rng_inner = rng.expect("Committing to polynomials requires a random generator"); for l_poly in polynomials { - // let mut com_rands = Vec::new(); - let label = l_poly.label(); let poly = l_poly.polynomial();