diff --git a/bench-templates/Cargo.toml b/bench-templates/Cargo.toml index eef16ed44..0d092c639 100644 --- a/bench-templates/Cargo.toml +++ b/bench-templates/Cargo.toml @@ -28,4 +28,4 @@ paste.workspace = true [features] asm = [ "ark-ff/asm" ] -parallel = [ "ark-std/parallel", "ark-ff/parallel", "ark-ec/parallel", ] +parallel = [ "ark-std/parallel", "ark-ff/parallel", "ark-ec/parallel", "ark-serialize/parallel" ] diff --git a/ec/Cargo.toml b/ec/Cargo.toml index 67568d3b2..481ef290e 100644 --- a/ec/Cargo.toml +++ b/ec/Cargo.toml @@ -41,4 +41,4 @@ hex.workspace = true [features] default = [] std = [ "ark-std/std", "ark-ff/std", "ark-serialize/std" ] -parallel = [ "std", "rayon", "ark-std/parallel" ] +parallel = [ "std", "rayon", "ark-std/parallel", "ark-serialize/parallel" ] diff --git a/ec/src/models/short_weierstrass/group.rs b/ec/src/models/short_weierstrass/group.rs index 8f1139ea7..4fab24306 100644 --- a/ec/src/models/short_weierstrass/group.rs +++ b/ec/src/models/short_weierstrass/group.rs @@ -604,7 +604,9 @@ impl Valid for Projective

{ self.into_affine().check() } - fn batch_check<'a>(batch: impl Iterator) -> Result<(), SerializationError> + fn batch_check<'a>( + batch: impl Iterator + Send, + ) -> Result<(), SerializationError> where Self: 'a, { diff --git a/ec/src/models/twisted_edwards/group.rs b/ec/src/models/twisted_edwards/group.rs index 3a1777cba..f267001b0 100644 --- a/ec/src/models/twisted_edwards/group.rs +++ b/ec/src/models/twisted_edwards/group.rs @@ -457,7 +457,9 @@ impl Valid for Projective

{ self.into_affine().check() } - fn batch_check<'a>(batch: impl Iterator) -> Result<(), SerializationError> + fn batch_check<'a>( + batch: impl Iterator + Send, + ) -> Result<(), SerializationError> where Self: 'a, { diff --git a/ff/Cargo.toml b/ff/Cargo.toml index 3e5c8c0cc..a967ee305 100644 --- a/ff/Cargo.toml +++ b/ff/Cargo.toml @@ -44,5 +44,5 @@ hex.workspace = true [features] default = [] std = [ "ark-std/std", "ark-serialize/std", "itertools/use_std" ] -parallel = [ "std", "rayon", "ark-std/parallel" ] +parallel = [ "std", "rayon", "ark-std/parallel", "ark-serialize/parallel" ] asm = [] diff --git a/poly/Cargo.toml b/poly/Cargo.toml index 3e7037850..ba0371a36 100644 --- a/poly/Cargo.toml +++ b/poly/Cargo.toml @@ -30,8 +30,8 @@ criterion = "0.5.1" [features] default = [] -std = [ "ark-std/std", "ark-ff/std" ] -parallel = [ "std", "ark-ff/parallel", "rayon", "ark-std/parallel" ] +std = [ "ark-std/std", "ark-ff/std", "ark-serialize/std" ] +parallel = [ "std", "ark-ff/parallel", "rayon", "ark-std/parallel", "ark-serialize/parallel" ] [[bench]] diff --git a/serialize-derive/src/deserialize.rs b/serialize-derive/src/deserialize.rs index 1a812d05e..fd4566f42 100644 --- a/serialize-derive/src/deserialize.rs +++ b/serialize-derive/src/deserialize.rs @@ -78,7 +78,7 @@ fn impl_valid(ast: &syn::DeriveInput) -> TokenStream { Ok(()) } #[allow(unused_mut, unused_variables)] - fn batch_check<'a>(batch: impl Iterator ) -> Result<(), ark_serialize::SerializationError> + fn batch_check<'a>(batch: impl Iterator + Send) -> Result<(), ark_serialize::SerializationError> where Self: 'a { diff --git a/serialize/Cargo.toml b/serialize/Cargo.toml index 226b8091e..1451e0b7f 100644 --- a/serialize/Cargo.toml +++ b/serialize/Cargo.toml @@ -20,6 +20,7 @@ ark-serialize-derive = { workspace = true, optional = true } ark-std.workspace = true digest.workspace = true num-bigint.workspace = true +rayon = { workspace = true, optional = true } [dev-dependencies] sha2.workspace = true @@ -30,5 +31,6 @@ ark-test-curves = { workspace = true, default-features = false, features = [ "bl [features] default = [] -std = [ "ark-std/std", ] +parallel = [ "rayon" ] +std = [ "ark-std/std" ] derive = [ "ark-serialize-derive" ] diff --git a/serialize/src/impls.rs b/serialize/src/impls.rs index f10cdd3d9..9d2341ceb 100644 --- a/serialize/src/impls.rs +++ b/serialize/src/impls.rs @@ -227,7 +227,9 @@ impl Valid for Option { } #[inline] - fn batch_check<'a>(batch: impl Iterator) -> Result<(), SerializationError> + fn batch_check<'a>( + batch: impl Iterator + Send, + ) -> Result<(), SerializationError> where Self: 'a, { @@ -304,34 +306,6 @@ impl CanonicalSerialize for Rc { } } -impl Valid for Rc { - #[inline] - fn check(&self) -> Result<(), SerializationError> { - self.as_ref().check() - } - - #[inline] - fn batch_check<'a>(batch: impl Iterator) -> Result<(), SerializationError> - where - Self: 'a, - { - T::batch_check(batch.map(|v| v.as_ref())) - } -} - -impl CanonicalDeserialize for Rc { - #[inline] - fn deserialize_with_mode( - reader: R, - compress: Compress, - validate: Validate, - ) -> Result { - Ok(Rc::new(T::deserialize_with_mode( - reader, compress, validate, - )?)) - } -} - #[cfg(target_has_atomic = "ptr")] impl CanonicalSerialize for ark_std::sync::Arc { #[inline] @@ -358,7 +332,9 @@ impl Valid for ark_std::sync::Arc { #[inline] - fn batch_check<'a>(batch: impl Iterator) -> Result<(), SerializationError> + fn batch_check<'a>( + batch: impl Iterator + Send, + ) -> Result<(), SerializationError> where Self: 'a, { @@ -410,7 +386,9 @@ where #[inline] - fn batch_check<'a>(batch: impl Iterator) -> Result<(), SerializationError> + fn batch_check<'a>( + batch: impl Iterator + Send, + ) -> Result<(), SerializationError> where Self: 'a, { @@ -463,7 +441,9 @@ impl Valid for [T; N] { } #[inline] - fn batch_check<'a>(batch: impl Iterator) -> Result<(), SerializationError> + fn batch_check<'a>( + batch: impl Iterator + Send, + ) -> Result<(), SerializationError> where Self: 'a, { @@ -511,7 +491,9 @@ impl Valid for Vec { } #[inline] - fn batch_check<'a>(batch: impl Iterator) -> Result<(), SerializationError> + fn batch_check<'a>( + batch: impl Iterator + Send, + ) -> Result<(), SerializationError> where Self: 'a, { @@ -605,7 +587,9 @@ impl Valid for VecDeque { } #[inline] - fn batch_check<'a>(batch: impl Iterator) -> Result<(), SerializationError> + fn batch_check<'a>( + batch: impl Iterator + Send, + ) -> Result<(), SerializationError> where Self: 'a, { @@ -664,7 +648,9 @@ impl Valid for LinkedList { } #[inline] - fn batch_check<'a>(batch: impl Iterator) -> Result<(), SerializationError> + fn batch_check<'a>( + batch: impl Iterator + Send, + ) -> Result<(), SerializationError> where Self: 'a, { @@ -918,7 +904,9 @@ impl Valid for BTreeSet { } #[inline] - fn batch_check<'a>(batch: impl Iterator) -> Result<(), SerializationError> + fn batch_check<'a>( + batch: impl Iterator + Send, + ) -> Result<(), SerializationError> where Self: 'a, { diff --git a/serialize/src/lib.rs b/serialize/src/lib.rs index 1276a92d5..d30386d6e 100644 --- a/serialize/src/lib.rs +++ b/serialize/src/lib.rs @@ -62,10 +62,12 @@ pub enum Validate { No, } -pub trait Valid: Sized { +pub trait Valid: Sized + Sync { fn check(&self) -> Result<(), SerializationError>; - fn batch_check<'a>(batch: impl Iterator) -> Result<(), SerializationError> + fn batch_check<'a>( + batch: impl Iterator + Send, + ) -> Result<(), SerializationError> where Self: 'a, { diff --git a/serialize/src/test.rs b/serialize/src/test.rs index bcd56b17a..090bc0c5b 100644 --- a/serialize/src/test.rs +++ b/serialize/src/test.rs @@ -202,10 +202,6 @@ fn test_bool() { #[test] fn test_rc_arc() { - use ark_std::rc::Rc; - test_serialize(Rc::new(Dummy)); - test_serialize(Rc::new(10u64)); - use ark_std::sync::Arc; test_serialize(Arc::new(Dummy)); test_serialize(Arc::new(10u64));