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

Parallelize TE to SW mapping #15

Merged
merged 1 commit into from
May 30, 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: 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
Loading