From 4389714068d939abc97288c5b06ee23d399a19ad Mon Sep 17 00:00:00 2001 From: Achim Schneider Date: Sat, 18 Mar 2023 15:49:15 +0100 Subject: [PATCH] replace Vec> --- primitives/arkworks/src/bls12_377.rs | 6 ++-- primitives/arkworks/src/bls12_381.rs | 6 ++-- primitives/arkworks/src/bw6_761.rs | 6 ++-- primitives/arkworks/src/ed_on_bls12_377.rs | 2 +- primitives/arkworks/src/ed_on_bls12_381.rs | 4 +-- primitives/arkworks/src/utils.rs | 12 +++++--- primitives/arkworks/test/tests/bls12_377.rs | 9 ++---- .../arkworks/test/tests/bls12_381/mod.rs | 6 ++-- primitives/arkworks/test/tests/bw6_761.rs | 9 ++---- .../arkworks/test/tests/ed_on_bls12_377.rs | 2 +- .../arkworks/test/tests/ed_on_bls12_381.rs | 4 +-- primitives/io/src/lib.rs | 29 +++++++------------ 12 files changed, 42 insertions(+), 53 deletions(-) diff --git a/primitives/arkworks/src/bls12_377.rs b/primitives/arkworks/src/bls12_377.rs index cf5b380fb34a1..636e281c5c744 100644 --- a/primitives/arkworks/src/bls12_377.rs +++ b/primitives/arkworks/src/bls12_377.rs @@ -30,7 +30,7 @@ use sp_std::vec::Vec; /// Compute multi miller loop through arkworks -pub fn multi_miller_loop(a: Vec>, b: Vec>) -> Result, PairingError> { +pub fn multi_miller_loop(a: Vec, b: Vec) -> Result, PairingError> { multi_miller_loop_generic::(a, b) } @@ -40,11 +40,11 @@ pub fn final_exponentiation(target: Vec) -> Result, PairingError> { } /// Compute a multi scalar multiplication on G! through arkworks -pub fn msm_g1(bases: Vec>, scalars: Vec>) -> Vec { +pub fn msm_g1(bases: Vec, scalars: Vec) -> Vec { msm_g1_generic::(bases, scalars) } /// Compute a multi scalar multiplication on G! through arkworks -pub fn msm_g2(bases: Vec>, scalars: Vec>) -> Vec { +pub fn msm_g2(bases: Vec, scalars: Vec) -> Vec { msm_g2_generic::(bases, scalars) } diff --git a/primitives/arkworks/src/bls12_381.rs b/primitives/arkworks/src/bls12_381.rs index 10ef613fee115..0852f269f4f49 100644 --- a/primitives/arkworks/src/bls12_381.rs +++ b/primitives/arkworks/src/bls12_381.rs @@ -29,7 +29,7 @@ use ark_bls12_381::Bls12_381; use sp_std::vec::Vec; /// Compute multi miller loop through arkworks -pub fn multi_miller_loop(a: Vec>, b: Vec>) -> Result, PairingError> { +pub fn multi_miller_loop(a: Vec, b: Vec) -> Result, PairingError> { multi_miller_loop_generic::(a, b) } @@ -39,11 +39,11 @@ pub fn final_exponentiation(target: Vec) -> Result, PairingError> { } /// Compute a multi scalar multiplication on G! through arkworks -pub fn msm_g1(bases: Vec>, scalars: Vec>) -> Vec { +pub fn msm_g1(bases: Vec, scalars: Vec) -> Vec { msm_g1_generic::(bases, scalars) } /// Compute a multi scalar multiplication on G! through arkworks -pub fn msm_g2(bases: Vec>, scalars: Vec>) -> Vec { +pub fn msm_g2(bases: Vec, scalars: Vec) -> Vec { msm_g2_generic::(bases, scalars) } diff --git a/primitives/arkworks/src/bw6_761.rs b/primitives/arkworks/src/bw6_761.rs index 9a3330cfe7443..1de24dd45eb7f 100644 --- a/primitives/arkworks/src/bw6_761.rs +++ b/primitives/arkworks/src/bw6_761.rs @@ -29,7 +29,7 @@ use ark_bw6_761::BW6_761; use sp_std::vec::Vec; /// Compute multi miller loop through arkworks -pub fn multi_miller_loop(a: Vec>, b: Vec>) -> Result, PairingError> { +pub fn multi_miller_loop(a: Vec, b: Vec) -> Result, PairingError> { multi_miller_loop_generic::(a, b) } @@ -39,11 +39,11 @@ pub fn final_exponentiation(target: Vec) -> Result, PairingError> { } /// Compute a multi scalar multiplication on G! through arkworks -pub fn msm_g1(bases: Vec>, scalars: Vec>) -> Vec { +pub fn msm_g1(bases: Vec, scalars: Vec) -> Vec { msm_g1_generic::(bases, scalars) } /// Compute a multi scalar multiplication on G! through arkworks -pub fn msm_g2(bases: Vec>, scalars: Vec>) -> Vec { +pub fn msm_g2(bases: Vec, scalars: Vec) -> Vec { msm_g2_generic::(bases, scalars) } diff --git a/primitives/arkworks/src/ed_on_bls12_377.rs b/primitives/arkworks/src/ed_on_bls12_377.rs index 2a6797ab751bf..242006b305666 100644 --- a/primitives/arkworks/src/ed_on_bls12_377.rs +++ b/primitives/arkworks/src/ed_on_bls12_377.rs @@ -25,7 +25,7 @@ use ark_ed_on_bls12_377::{EdwardsConfig, EdwardsProjective}; use sp_std::vec::Vec; /// Compute a multi scalar multiplication on G! through arkworks -pub fn msm(bases: Vec>, scalars: Vec>) -> Vec { +pub fn msm(bases: Vec, scalars: Vec) -> Vec { let bases: Vec<_> = bases .iter() .map(|a| deserialize_argument::>(a)) diff --git a/primitives/arkworks/src/ed_on_bls12_381.rs b/primitives/arkworks/src/ed_on_bls12_381.rs index 745123a9c854d..a13c55731a926 100644 --- a/primitives/arkworks/src/ed_on_bls12_381.rs +++ b/primitives/arkworks/src/ed_on_bls12_381.rs @@ -28,7 +28,7 @@ use ark_ed_on_bls12_381::{EdwardsProjective, JubjubConfig, SWProjective}; use sp_std::vec::Vec; /// Compute a multi scalar multiplication on G! through arkworks -pub fn te_msm(bases: Vec>, scalars: Vec>) -> Vec { +pub fn te_msm(bases: Vec, scalars: Vec) -> Vec { let bases: Vec<_> = bases .iter() .map(|a| deserialize_argument::>(a)) @@ -44,7 +44,7 @@ pub fn te_msm(bases: Vec>, scalars: Vec>) -> Vec { } /// Compute a multi scalar multiplication on G! through arkworks -pub fn sw_msm(bases: Vec>, scalars: Vec>) -> Vec { +pub fn sw_msm(bases: Vec, scalars: Vec) -> Vec { let bases: Vec<_> = bases .iter() .map(|a| deserialize_argument::>(a)) diff --git a/primitives/arkworks/src/utils.rs b/primitives/arkworks/src/utils.rs index 83873668036df..0e3609a9f567d 100644 --- a/primitives/arkworks/src/utils.rs +++ b/primitives/arkworks/src/utils.rs @@ -16,14 +16,16 @@ pub fn deserialize_argument(argument: &Vec) -> } pub fn multi_miller_loop_generic( - a_vec: Vec>, - b_vec: Vec>, + a_vec: Vec, + b_vec: Vec, ) -> Result, PairingError> { let g1: Vec<_> = a_vec + .chunks(::G1Affine.serialized_size(Compress::No)) .iter() .map(|elem| deserialize_argument::<::G1Affine>(elem)) .collect(); let g2: Vec<_> = b_vec + .chunks(::G2Affine.serialized_size(Compress::No)) .iter() .map(|elem| deserialize_argument::<::G2Affine>(elem)) .collect(); @@ -46,8 +48,9 @@ pub fn final_exponentiation_generic( } } -pub fn msm_g1_generic(bases: Vec>, scalars: Vec>) -> Vec { +pub fn msm_g1_generic(bases: Vec, scalars: Vec) -> Vec { let bases: Vec<_> = bases + .chunks(::G1Affine.serialized_size(Compress::No)) .iter() .map(|a| deserialize_argument::<::G1Affine>(a)) .collect(); @@ -60,8 +63,9 @@ pub fn msm_g1_generic(bases: Vec>, scalars: Vec> serialize_result(result) } -pub fn msm_g2_generic(bases: Vec>, scalars: Vec>) -> Vec { +pub fn msm_g2_generic(bases: Vec, scalars: Vec) -> Vec { let bases: Vec<_> = bases + .chunks(::G2Affine.serialized_size(Compress::No)) .iter() .map(|a| deserialize_argument::<::G2Affine>(a)) .collect(); diff --git a/primitives/arkworks/test/tests/bls12_377.rs b/primitives/arkworks/test/tests/bls12_377.rs index 9926767bafc05..5907f96827cb8 100644 --- a/primitives/arkworks/test/tests/bls12_377.rs +++ b/primitives/arkworks/test/tests/bls12_377.rs @@ -6,19 +6,16 @@ use sp_arkworks::PairingError; pub struct Host {} impl HostFunctions for Host { - fn bls12_377_multi_miller_loop( - a: Vec>, - b: Vec>, - ) -> Result, PairingError> { + fn bls12_377_multi_miller_loop(a: Vec, b: Vec) -> Result, PairingError> { sp_io::elliptic_curves::bls12_377_multi_miller_loop(a, b) } fn bls12_377_final_exponentiation(f12: Vec) -> Result, PairingError> { sp_io::elliptic_curves::bls12_377_final_exponentiation(f12) } - fn bls12_377_msm_g1(bases: Vec>, bigints: Vec>) -> Vec { + fn bls12_377_msm_g1(bases: Vec, bigints: Vec) -> Vec { sp_io::elliptic_curves::bls12_377_msm_g1(bases, bigints) } - fn bls12_377_msm_g2(bases: Vec>, bigints: Vec>) -> Vec { + fn bls12_377_msm_g2(bases: Vec, bigints: Vec) -> Vec { sp_io::elliptic_curves::bls12_377_msm_g2(bases, bigints) } } diff --git a/primitives/arkworks/test/tests/bls12_381/mod.rs b/primitives/arkworks/test/tests/bls12_381/mod.rs index 1dacfb7b312ee..fd3cdd80bc128 100755 --- a/primitives/arkworks/test/tests/bls12_381/mod.rs +++ b/primitives/arkworks/test/tests/bls12_381/mod.rs @@ -14,16 +14,16 @@ use sp_ark_bls12_381::{ pub struct Host {} impl HostFunctions for Host { - fn bls12_381_multi_miller_loop(a: Vec>, b: Vec> ) -> Result, PairingError> { + fn bls12_381_multi_miller_loop(a: Vec, b: Vec ) -> Result, PairingError> { sp_io::elliptic_curves::bls12_381_multi_miller_loop(a, b) } fn bls12_381_final_exponentiation(f12: Vec) -> Result, PairingError> { sp_io::elliptic_curves::bls12_381_final_exponentiation(f12) } - fn bls12_381_msm_g1(bases: Vec>, bigints: Vec>) -> Vec { + fn bls12_381_msm_g1(bases: Vec, bigints: Vec) -> Vec { sp_io::elliptic_curves::bls12_381_msm_g1(bases, bigints) } - fn bls12_381_msm_g2(bases: Vec>, bigints: Vec>) -> Vec { + fn bls12_381_msm_g2(bases: Vec, bigints: Vec) -> Vec { sp_io::elliptic_curves::bls12_381_msm_g2(bases, bigints) } } diff --git a/primitives/arkworks/test/tests/bw6_761.rs b/primitives/arkworks/test/tests/bw6_761.rs index 7ff9d4ee0f8ef..758084fa143cf 100644 --- a/primitives/arkworks/test/tests/bw6_761.rs +++ b/primitives/arkworks/test/tests/bw6_761.rs @@ -7,19 +7,16 @@ use sp_arkworks::PairingError; pub struct Host; impl HostFunctions for Host { - fn bw6_761_multi_miller_loop( - a: Vec>, - b: Vec>, - ) -> Result, PairingError> { + fn bw6_761_multi_miller_loop(a: Vec, b: Vec) -> Result, PairingError> { sp_io::elliptic_curves::bw6_761_multi_miller_loop(a, b) } fn bw6_761_final_exponentiation(f12: Vec) -> Result, PairingError> { sp_io::elliptic_curves::bw6_761_final_exponentiation(f12) } - fn bw6_761_msm_g1(bases: Vec>, bigints: Vec>) -> Vec { + fn bw6_761_msm_g1(bases: Vec, bigints: Vec) -> Vec { sp_io::elliptic_curves::bw6_761_msm_g1(bases, bigints) } - fn bw6_761_msm_g2(bases: Vec>, bigints: Vec>) -> Vec { + fn bw6_761_msm_g2(bases: Vec, bigints: Vec) -> Vec { sp_io::elliptic_curves::bw6_761_msm_g2(bases, bigints) } } diff --git a/primitives/arkworks/test/tests/ed_on_bls12_377.rs b/primitives/arkworks/test/tests/ed_on_bls12_377.rs index 8b4a4d3d13784..1ac6e1728df30 100644 --- a/primitives/arkworks/test/tests/ed_on_bls12_377.rs +++ b/primitives/arkworks/test/tests/ed_on_bls12_377.rs @@ -5,7 +5,7 @@ use sp_ark_ed_on_bls12_377::HostFunctions; pub struct Host {} impl HostFunctions for Host { - fn ed_on_bls12_377_msm(bases: Vec>, scalars: Vec>) -> Vec { + fn ed_on_bls12_377_msm(bases: Vec, scalars: Vec) -> Vec { sp_io::elliptic_curves::ed_on_bls12_377_msm(bases, scalars) } } diff --git a/primitives/arkworks/test/tests/ed_on_bls12_381.rs b/primitives/arkworks/test/tests/ed_on_bls12_381.rs index a3bd0b5a82847..8dd9385860535 100644 --- a/primitives/arkworks/test/tests/ed_on_bls12_381.rs +++ b/primitives/arkworks/test/tests/ed_on_bls12_381.rs @@ -5,10 +5,10 @@ use sp_ark_ed_on_bls12_381::HostFunctions; pub struct Host {} impl HostFunctions for Host { - fn ed_on_bls12_381_te_msm(bases: Vec>, scalars: Vec>) -> Vec { + fn ed_on_bls12_381_te_msm(bases: Vec, scalars: Vec) -> Vec { sp_io::elliptic_curves::ed_on_bls12_381_te_msm(bases, scalars) } - fn ed_on_bls12_381_sw_msm(bases: Vec>, scalars: Vec>) -> Vec { + fn ed_on_bls12_381_sw_msm(bases: Vec, scalars: Vec) -> Vec { sp_io::elliptic_curves::ed_on_bls12_381_sw_msm(bases, scalars) } } diff --git a/primitives/io/src/lib.rs b/primitives/io/src/lib.rs index e3c57f13fe247..918b40f12c1b5 100644 --- a/primitives/io/src/lib.rs +++ b/primitives/io/src/lib.rs @@ -1128,10 +1128,7 @@ pub trait Crypto { #[runtime_interface] pub trait EllipticCurves { /// Compute a multi Miller loop on bls12_381 - fn bls12_381_multi_miller_loop( - a: Vec>, - b: Vec>, - ) -> Result, PairingError> { + fn bls12_381_multi_miller_loop(a: Vec, b: Vec) -> Result, PairingError> { sp_arkworks::bls12_381::multi_miller_loop(a, b) } @@ -1141,20 +1138,17 @@ pub trait EllipticCurves { } /// Compute a msm on G1 for bls12_381 - fn bls12_381_msm_g1(bases: Vec>, scalars: Vec>) -> Vec { + fn bls12_381_msm_g1(bases: Vec, scalars: Vec) -> Vec { sp_arkworks::bls12_381::msm_g1(bases, scalars) } /// Compute a msm on G2 for bls12_381 - fn bls12_381_msm_g2(bases: Vec>, scalars: Vec>) -> Vec { + fn bls12_381_msm_g2(bases: Vec, scalars: Vec) -> Vec { sp_arkworks::bls12_381::msm_g2(bases, scalars) } /// Compute a multi Miller loop for bls12_377 - fn bls12_377_multi_miller_loop( - a: Vec>, - b: Vec>, - ) -> Result, PairingError> { + fn bls12_377_multi_miller_loop(a: Vec, b: Vec) -> Result, PairingError> { sp_arkworks::bls12_377::multi_miller_loop(a, b) } @@ -1174,10 +1168,7 @@ pub trait EllipticCurves { } /// Compute a multi Miller loop on bw6_761 - fn bw6_761_multi_miller_loop( - a: Vec>, - b: Vec>, - ) -> Result, PairingError> { + fn bw6_761_multi_miller_loop(a: Vec, b: Vec) -> Result, PairingError> { sp_arkworks::bw6_761::multi_miller_loop(a, b) } @@ -1187,27 +1178,27 @@ pub trait EllipticCurves { } /// Compute a msm on G1 for bw6_761 - fn bw6_761_msm_g1(bases: Vec>, bigints: Vec>) -> Vec { + fn bw6_761_msm_g1(bases: Vec, bigints: Vec) -> Vec { sp_arkworks::bw6_761::msm_g1(bases, bigints) } /// Compute a msm on G2 for bw6_761 - fn bw6_761_msm_g2(bases: Vec>, bigints: Vec>) -> Vec { + fn bw6_761_msm_g2(bases: Vec, bigints: Vec) -> Vec { sp_arkworks::bw6_761::msm_g2(bases, bigints) } /// Compute twisted edwards msm on ed_on_bls12_381 - fn ed_on_bls12_381_te_msm(bases: Vec>, scalars: Vec>) -> Vec { + fn ed_on_bls12_381_te_msm(bases: Vec, scalars: Vec) -> Vec { sp_arkworks::ed_on_bls12_381::te_msm(bases, scalars) } /// Compute short weierstrass msm on ed_on_bls12_381 - fn ed_on_bls12_381_sw_msm(bases: Vec>, scalars: Vec>) -> Vec { + fn ed_on_bls12_381_sw_msm(bases: Vec, scalars: Vec) -> Vec { sp_arkworks::ed_on_bls12_381::sw_msm(bases, scalars) } /// Compute msm on ed_on_bls12_377 - fn ed_on_bls12_377_msm(bases: Vec>, scalars: Vec>) -> Vec { + fn ed_on_bls12_377_msm(bases: Vec, scalars: Vec) -> Vec { sp_arkworks::ed_on_bls12_377::msm(bases, scalars) } }