Skip to content

Commit

Permalink
use correct deserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Achim Schneider committed Mar 19, 2023
1 parent b0df1e1 commit 9eacba9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
7 changes: 4 additions & 3 deletions primitives/arkworks/src/ed_on_bls12_377.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#![warn(missing_docs)]

use crate::utils::{deserialize_argument, serialize_iter_to_vec, serialize_result};
use crate::utils::{deserialize_iter_to_vec, serialize_result};
use ark_ec::{models::CurveConfig, twisted_edwards, AffineRepr, Group, VariableBaseMSM};
use ark_ed_on_bls12_377::{EdwardsConfig, EdwardsProjective};
use ark_ff::Zero;
Expand All @@ -28,9 +28,10 @@ use sp_std::vec::Vec;

/// Compute a multi scalar multiplication on G! through arkworks
pub fn msm(bases: Vec<u8>, scalars: Vec<u8>) -> Vec<u8> {
let bases: Vec<_> = serialize_iter_to_vec::<twisted_edwards::Affine<EdwardsConfig>>(bases);
let bases: Vec<_> =
deserialize_iter_to_vec::<twisted_edwards::Affine<EdwardsConfig>>(&bases).unwrap();
let scalars: Vec<_> =
serialize_iter_to_vec::<<EdwardsConfig as CurveConfig>::ScalarField>(scalars).unwrap();
deserialize_iter_to_vec::<<EdwardsConfig as CurveConfig>::ScalarField>(&scalars).unwrap();

let result = <EdwardsProjective as VariableBaseMSM>::msm(&bases, &scalars).unwrap();

Expand Down
12 changes: 6 additions & 6 deletions primitives/arkworks/src/ed_on_bls12_381.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#![warn(missing_docs)]

use crate::utils::{deserialize_argument, serialize_iter_to_vec, serialize_result};
use crate::utils::{deserialize_iter_to_vec, serialize_result};
use ark_ec::{
models::CurveConfig, short_weierstrass::Affine as SWAffine,
twisted_edwards::Affine as TEAffine, AffineRepr, Group, VariableBaseMSM,
Expand All @@ -31,9 +31,9 @@ use sp_std::vec::Vec;

/// Compute a multi scalar multiplication on G! through arkworks
pub fn te_msm(bases: Vec<u8>, scalars: Vec<u8>) -> Vec<u8> {
let bases: Vec<_> = serialize_iter_to_vec::<TEAffine<JubjubConfig>>(bases).unwrap();
let bases: Vec<_> = deserialize_iter_to_vec::<TEAffine<JubjubConfig>>(&bases).unwrap();
let scalars: Vec<_> =
serialize_iter_to_vec::<<JubjubConfig as CurveConfig>::ScalarField>(scalars).unwrap();
deserialize_iter_to_vec::<<JubjubConfig as CurveConfig>::ScalarField>(&scalars).unwrap();

let result = <EdwardsProjective as VariableBaseMSM>::msm(&bases, &scalars).unwrap();

Expand All @@ -42,11 +42,11 @@ pub fn te_msm(bases: Vec<u8>, scalars: Vec<u8>) -> Vec<u8> {

/// Compute a multi scalar multiplication on G! through arkworks
pub fn sw_msm(bases: Vec<u8>, scalars: Vec<u8>) -> Vec<u8> {
let bases: Vec<_> = serialize_iter_to_vec::<SWAffine<JubjubConfig>>(bases).unwrap();
let bases: Vec<_> = deserialize_iter_to_vec::<SWAffine<JubjubConfig>>(&bases).unwrap();
let scalars: Vec<_> =
serialize_iter_to_vec::<<JubjubConfig as CurveConfig>::ScalarField>(scalars).unwrap();
deserialize_iter_to_vec::<<JubjubConfig as CurveConfig>::ScalarField>(&scalars).unwrap();

let result = <SWProjective as VariableBaseMSM>::msm(&bases, &scalars[..]).unwrap();
let result = <SWProjective as VariableBaseMSM>::msm(&bases, &scalars).unwrap();

serialize_result(result)
}

0 comments on commit 9eacba9

Please sign in to comment.