Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
no collect Vec
Browse files Browse the repository at this point in the history
  • Loading branch information
Achim Schneider committed Mar 18, 2023
1 parent dd3f809 commit db18dca
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 38 deletions.
14 changes: 4 additions & 10 deletions primitives/arkworks/src/ed_on_bls12_377.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,13 @@ use sp_std::vec::Vec;
pub fn msm(bases: Vec<u8>, scalars: Vec<u8>) -> Vec<u8> {
let bases: Vec<_> = bases
.chunks(twisted_edwards::Affine::<EdwardsConfig>::generator().serialized_size(Compress::No))
.into_iter()
.map(|a| {
deserialize_argument::<twisted_edwards::Affine<EdwardsConfig>>(a.collect::<Vec<_>>())
})
.into()
.map(|a| deserialize_argument::<twisted_edwards::Affine<EdwardsConfig>>(a))
.collect();
let scalars: Vec<_> = scalars
.chunks(<EdwardsConfig as CurveConfig>::ScalarField::zero().serialized_size(Compress::No))
.into_iter()
.map(|a| {
deserialize_argument::<<EdwardsConfig as CurveConfig>::ScalarField>(
a.collect::<Vec<_>>(),
)
})
.into()
.map(|a| deserialize_argument::<<EdwardsConfig as CurveConfig>::ScalarField>(a))
.collect();

let result = <EdwardsProjective as VariableBaseMSM>::msm(&bases, &scalars).unwrap();
Expand Down
24 changes: 8 additions & 16 deletions primitives/arkworks/src/ed_on_bls12_381.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,13 @@ use sp_std::vec::Vec;
pub fn te_msm(bases: Vec<u8>, scalars: Vec<u8>) -> Vec<u8> {
let bases: Vec<_> = bases
.chunks(TEAffine::<JubjubConfig>::generator().serialized_size(Compress::No))
.into_iter()
.map(|a| deserialize_argument::<TEAffine<JubjubConfig>>(a.collect::<Vec<_>>()))
.iter()
.map(|a| deserialize_argument::<TEAffine<JubjubConfig>>(a))
.collect();
let scalars: Vec<_> = scalars
.chunks(<JubjubConfig as CurveConfig>::ScalarField::zero().serialized_size(Compress::No))
.into_iter()
.map(|a| {
deserialize_argument::<<JubjubConfig as CurveConfig>::ScalarField>(
a.collect::<Vec<_>>(),
)
})
.iter()
.map(|a| deserialize_argument::<<JubjubConfig as CurveConfig>::ScalarField>(a))
.collect();

let result = <EdwardsProjective as VariableBaseMSM>::msm(&bases, &scalars).unwrap();
Expand All @@ -55,17 +51,13 @@ pub fn te_msm(bases: Vec<u8>, scalars: Vec<u8>) -> Vec<u8> {
pub fn sw_msm(bases: Vec<u8>, scalars: Vec<u8>) -> Vec<u8> {
let bases: Vec<_> = bases
.chunks(SWAffine::<JubjubConfig>::genrator().serialized_size(Compress::No))
.into_iter()
.map(|a| deserialize_argument::<SWAffine<JubjubConfig>>(a.collect::<Vec<_>>()))
.iter()
.map(|a| deserialize_argument::<SWAffine<JubjubConfig>>(a))
.collect();
let scalars: Vec<_> = scalars
.chunks(<JubjubConfig as CurveConfig>::ScalarField::zero().serialized_size(Compress::No))
.into_iter()
.map(|a| {
deserialize_argument::<<JubjubConfig as CurveConfig>::ScalarField>(
a.collect::<Vec<_>>(),
)
})
.iter()
.map(|a| deserialize_argument::<<JubjubConfig as CurveConfig>::ScalarField>(a))
.collect();

let result = <SWProjective as VariableBaseMSM>::msm(&bases, &scalars).unwrap();
Expand Down
24 changes: 12 additions & 12 deletions primitives/arkworks/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ pub fn multi_miller_loop_generic<Curve: Pairing>(
) -> Result<Vec<u8>, PairingError> {
let g1: Vec<_> = a_vec
.chunks(<Curve as Pairing>::G1Affine::generator().serialized_size(Compress::No))
.into_iter()
.map(|elem| deserialize_argument::<<Curve as Pairing>::G1Affine>(elem.collect::<Vec<_>>()))
.iter()
.map(|elem| deserialize_argument::<<Curve as Pairing>::G1Affine>(elem))
.collect();
let g2: Vec<_> = b_vec
.chunks(<Curve as Pairing>::G2Affine::generator().serialized_size(Compress::No))
.into_iter()
.map(|elem| deserialize_argument::<<Curve as Pairing>::G2Affine>(elem.collect::<Vec<_>>()))
.iter()
.map(|elem| deserialize_argument::<<Curve as Pairing>::G2Affine>(elem))
.collect();

let result = Curve::multi_miller_loop(g1, g2);
Expand All @@ -55,13 +55,13 @@ pub fn final_exponentiation_generic<Curve: Pairing>(
pub fn msm_g1_generic<Curve: Pairing>(bases: Vec<u8>, scalars: Vec<u8>) -> Vec<u8> {
let bases: Vec<_> = bases
.chunks(<Curve as Pairing>::G1Affine::generator().serialized_size(Compress::No))
.into_iter()
.map(|a| deserialize_argument::<<Curve as Pairing>::G1Affine>(a.collect::<Vec<_>>()))
.iter()
.map(|a| deserialize_argument::<<Curve as Pairing>::G1Affine>(a))
.collect();
let scalars: Vec<_> = scalars
.chunks(Curve::ScalarField::zero().serialized_size(Compress::No))
.into_iter()
.map(|a| deserialize_argument::<Curve::ScalarField>(a.collect::<Vec<_>>()))
.iter()
.map(|a| deserialize_argument::<Curve::ScalarField>(a))
.collect();

let result =
Expand All @@ -73,13 +73,13 @@ pub fn msm_g1_generic<Curve: Pairing>(bases: Vec<u8>, scalars: Vec<u8>) -> Vec<u
pub fn msm_g2_generic<Curve: Pairing>(bases: Vec<u8>, scalars: Vec<u8>) -> Vec<u8> {
let bases: Vec<_> = bases
.chunks(<Curve as Pairing>::G2Affine::generator().serialized_size(Compress::No))
.into_iter()
.map(|a| deserialize_argument::<<Curve as Pairing>::G2Affine>(a.collect::<Vec<_>>()))
.iter()
.map(|a| deserialize_argument::<<Curve as Pairing>::G2Affine>(a))
.collect();
let scalars: Vec<_> = scalars
.chunks(Curve::ScalarField::zero().serialized_size(Compress::No))
.into_iter()
.map(|a| deserialize_argument::<Curve::ScalarField>(a.collect::<Vec<_>>()))
.iter()
.map(|a| deserialize_argument::<Curve::ScalarField>(a))
.collect();

let result =
Expand Down

0 comments on commit db18dca

Please sign in to comment.