diff --git a/Cargo.toml b/Cargo.toml index 1ce899fb..a452b187 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,11 @@ serde_json = "1.0.105" hex = "0.4" rand_chacha = "0.3.1" +# Added to make sure we are able to build the lib in the CI. +# Notice this will never be loaded for someone using this lib as dep. +[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dev-dependencies] +getrandom = { version = "0.2", features = ["js"] } + [dependencies] subtle = "2.4" ff = { version = "0.13.0", default-features = false, features = ["std"] } @@ -35,11 +40,10 @@ serde = { version = "1.0", default-features = false, optional = true } serde_arrays = { version = "0.1.0", optional = true } hex = { version = "0.4", optional = true, default-features = false, features = ["alloc", "serde"] } blake2b_simd = "1" -maybe-rayon = { version = "0.1.0", default-features = false } +rayon = "1.8" [features] -default = ["bits", "multicore"] -multicore = ["maybe-rayon/threads"] +default = ["bits"] asm = [] bits = ["ff/bits"] bn256-table = [] diff --git a/src/fft.rs b/src/fft.rs index 6eb3487e..00eca39a 100644 --- a/src/fft.rs +++ b/src/fft.rs @@ -1,4 +1,3 @@ -use crate::multicore; pub use crate::{CurveAffine, CurveExt}; use ff::Field; use group::{GroupOpsOwned, ScalarMulOwned}; @@ -38,7 +37,7 @@ pub fn best_fft>(a: &mut [G], omega: Scalar, r } - let threads = multicore::current_num_threads(); + let threads = rayon::current_num_threads(); let log_threads = threads.ilog2(); let n = a.len(); assert_eq!(n, 1 << log_n); @@ -107,7 +106,7 @@ pub fn recursive_butterfly_arithmetic>( a[1] -= &t; } else { let (left, right) = a.split_at_mut(n / 2); - multicore::join( + rayon::join( || recursive_butterfly_arithmetic(left, n / 2, twiddle_chunk * 2, twiddles), || recursive_butterfly_arithmetic(right, n / 2, twiddle_chunk * 2, twiddles), ); diff --git a/src/lib.rs b/src/lib.rs index b28ed89e..cba3af3a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,7 +3,6 @@ pub mod ff_ext; pub mod fft; pub mod hash_to_curve; pub mod msm; -pub mod multicore; pub mod serde; pub mod bn256; diff --git a/src/msm.rs b/src/msm.rs index 1a3709c1..7ac24655 100644 --- a/src/msm.rs +++ b/src/msm.rs @@ -4,8 +4,6 @@ use ff::PrimeField; use group::Group; use pasta_curves::arithmetic::CurveAffine; -use crate::multicore; - fn get_booth_index(window_index: usize, window_size: usize, el: &[u8]) -> i32 { // Booth encoding: // * step by `window` size @@ -155,12 +153,12 @@ pub fn small_multiexp(coeffs: &[C::Scalar], bases: &[C]) -> C::C pub fn best_multiexp(coeffs: &[C::Scalar], bases: &[C]) -> C::Curve { assert_eq!(coeffs.len(), bases.len()); - let num_threads = multicore::current_num_threads(); + let num_threads = rayon::current_num_threads(); if coeffs.len() > num_threads { let chunk = coeffs.len() / num_threads; let num_chunks = coeffs.chunks(chunk).len(); let mut results = vec![C::Curve::identity(); num_chunks]; - multicore::scope(|scope| { + rayon::scope(|scope| { let chunk = coeffs.len() / num_threads; for ((coeffs, bases), acc) in coeffs @@ -186,10 +184,7 @@ mod test { use std::ops::Neg; - use crate::{ - bn256::{Fr, G1Affine, G1}, - multicore, - }; + use crate::bn256::{Fr, G1Affine, G1}; use ark_std::{end_timer, start_timer}; use ff::{Field, PrimeField}; use group::{Curve, Group}; @@ -200,12 +195,12 @@ mod test { fn best_multiexp(coeffs: &[C::Scalar], bases: &[C]) -> C::Curve { assert_eq!(coeffs.len(), bases.len()); - let num_threads = multicore::current_num_threads(); + let num_threads = rayon::current_num_threads(); if coeffs.len() > num_threads { let chunk = coeffs.len() / num_threads; let num_chunks = coeffs.chunks(chunk).len(); let mut results = vec![C::Curve::identity(); num_chunks]; - multicore::scope(|scope| { + rayon::scope(|scope| { let chunk = coeffs.len() / num_threads; for ((coeffs, bases), acc) in coeffs diff --git a/src/multicore.rs b/src/multicore.rs deleted file mode 100644 index d8323553..00000000 --- a/src/multicore.rs +++ /dev/null @@ -1,16 +0,0 @@ -pub use maybe_rayon::{ - iter::{IntoParallelIterator, IntoParallelRefMutIterator, ParallelIterator}, - join, scope, Scope, -}; - -#[cfg(feature = "multicore")] -pub use maybe_rayon::{ - current_num_threads, - iter::{IndexedParallelIterator, IntoParallelRefIterator}, - slice::ParallelSliceMut, -}; - -#[cfg(not(feature = "multicore"))] -pub fn current_num_threads() -> usize { - 1 -}