diff --git a/Cargo.toml b/Cargo.toml index c0ab041..e87a04b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,7 @@ ark-std = { version = "0.4.0", default-features = false } ark-serialize = { version = "0.4.2", default-features = false } rand_core = { version = "0.6.4", default-features = false, optional = true } rand_chacha = { version = "0.3.1", default-features = false } +rayon = { version = "1.10", default-features = false, optional = true } zeroize = { version = "1.7.0", default-features = false } hmac = {version = "0.12.1", default-features = false, optional = true } digest = { version = "0.10.7", default-features = false } @@ -60,6 +61,7 @@ parallel = [ "ark-std/parallel", "ring-proof?/parallel", "fflonk?/parallel", + "rayon", ] ring = [ "bandersnatch", diff --git a/src/ring.rs b/src/ring.rs index c5bdd2b..9cc80ef 100644 --- a/src/ring.rs +++ b/src/ring.rs @@ -2,6 +2,9 @@ use crate::*; use ark_ec::short_weierstrass::SWCurveConfig; use pedersen::{PedersenSuite, Proof as PedersenProof}; +#[cfg(feature = "parallel")] +use rayon::prelude::*; + pub trait RingSuite: PedersenSuite { type Pairing: ark_ec::pairing::Pairing>; @@ -165,12 +168,18 @@ where } pub fn prover_key(&self, pks: &[AffinePoint]) -> ProverKey { + #[cfg(feature = "parallel")] + let pks = pks.par_iter().map(|p| p.into_sw()).collect(); + #[cfg(not(feature = "parallel"))] let pks = pks.iter().map(|p| p.into_sw()).collect(); ring_proof::index(self.pcs_params.clone(), &self.piop_params, pks).0 } pub fn verifier_key(&self, pks: &[AffinePoint]) -> VerifierKey { - let pks: Vec<_> = pks.iter().map(|p| p.into_sw()).collect(); + #[cfg(feature = "parallel")] + let pks = pks.par_iter().map(|p| p.into_sw()).collect(); + #[cfg(not(feature = "parallel"))] + let pks = pks.iter().map(|p| p.into_sw()).collect(); ring_proof::index(self.pcs_params.clone(), &self.piop_params, pks).1 }