diff --git a/src/group.rs b/src/group.rs index c55cc25..a284210 100644 --- a/src/group.rs +++ b/src/group.rs @@ -1,28 +1,26 @@ -use ark_ec::{ - msm::VariableBaseMSM, -}; -use ark_ff::{PrimeField}; +use crate::errors::ProofVerifyError; +use ark_ec::msm::VariableBaseMSM; +use ark_ff::PrimeField; use digest::DynDigest; use lazy_static::lazy_static; use num_bigint::BigInt; -use crate::errors::ProofVerifyError; use lazy_static::lazy_static; use num_bigint::BigInt; use super::scalar::Scalar; use ark_ec::{AffineCurve, ProjectiveCurve}; +use ark_ec::{AffineCurve, ProjectiveCurve}; +use ark_serialize::*; use ark_serialize::*; use core::borrow::Borrow; use core::ops::{Mul, MulAssign}; -use ark_ec::{ProjectiveCurve, AffineCurve}; -use ark_serialize::*; pub type GroupElement = ark_bls12_377::G1Projective; pub type GroupElementAffine = ark_bls12_377::G1Affine; pub type CurveField = ark_bls12_377::Fq; -#[derive(Clone, Eq, PartialEq, Hash, Debug, CanonicalSerialize, CanonicalDeserialize)] +#[derive(Clone, Eq, PartialEq, Hash, Debug, CanonicalSerialize, CanonicalDeserialize)] pub struct CompressedGroup(pub Vec); lazy_static! { @@ -51,23 +49,21 @@ impl CompressGroupElement for GroupElement { } impl DecompressGroupElement for GroupElement { - fn decompress(encoded: &CompressedGroup) -> Option - { - - let res = GroupElement::deserialize(&*encoded.0); - if res.is_err() { - println!("{:?}", res); - None - } else { - Some(res.unwrap()) - } + fn decompress(encoded: &CompressedGroup) -> Option { + let res = GroupElement::deserialize(&*encoded.0); + if res.is_err() { + println!("{:?}", res); + None + } else { + Some(res.unwrap()) + } } -} +} impl UnpackGroupElement for CompressedGroup { fn unpack(&self) -> Result { let encoded = self.0.clone(); - GroupElement::decompress(self).ok_or_else(|| ProofVerifyError::DecompressionError(encoded)) + GroupElement::decompress(self).ok_or_else(|| ProofVerifyError::DecompressionError(encoded)) } } @@ -76,13 +72,15 @@ pub trait VartimeMultiscalarMul { } impl VartimeMultiscalarMul for GroupElement { - fn vartime_multiscalar_mul( - scalars: &[Scalar], - points: &[GroupElement], -) -> GroupElement{ - let repr_scalars= scalars.into_iter().map(|S| S.borrow().into_repr()).collect::::BigInt>>(); - let aff_points = points.into_iter().map(|P| P.borrow().into_affine()).collect::>(); - VariableBaseMSM::multi_scalar_mul(aff_points.as_slice(), repr_scalars.as_slice()) -} + fn vartime_multiscalar_mul(scalars: &[Scalar], points: &[GroupElement]) -> GroupElement { + let repr_scalars = scalars + .into_iter() + .map(|S| S.borrow().into_repr()) + .collect::::BigInt>>(); + let aff_points = points + .into_iter() + .map(|P| P.borrow().into_affine()) + .collect::>(); + VariableBaseMSM::multi_scalar_mul(aff_points.as_slice(), repr_scalars.as_slice()) + } } -