Skip to content

Commit

Permalink
Parallelize TE to SW mapping (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
davxy authored May 30, 2024
1 parent 9344064 commit 0773854
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -60,6 +61,7 @@ parallel = [
"ark-std/parallel",
"ring-proof?/parallel",
"fflonk?/parallel",
"rayon",
]
ring = [
"bandersnatch",
Expand Down
11 changes: 10 additions & 1 deletion src/ring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ScalarField = BaseField<Self>>;

Expand Down Expand Up @@ -165,12 +168,18 @@ where
}

pub fn prover_key(&self, pks: &[AffinePoint<S>]) -> ProverKey<S> {
#[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<S>]) -> VerifierKey<S> {
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
}

Expand Down

0 comments on commit 0773854

Please sign in to comment.