From d79ebc133ef36ae67aef007cdecbdecb23af8d1e Mon Sep 17 00:00:00 2001 From: Lucas Meier Date: Wed, 31 Jan 2024 09:55:57 -0800 Subject: [PATCH] Rename AffineElement to AffinePoint to match min_curve --- src/ark_curve/edwards.rs | 2 +- src/ark_curve/element.rs | 34 ++++----- src/ark_curve/element/affine.rs | 30 ++++---- src/ark_curve/mod.rs | 2 +- src/ark_curve/ops/affine.rs | 118 ++++++++++++++++---------------- src/ark_curve/ops/projective.rs | 42 ++++++------ src/ark_curve/r1cs/element.rs | 6 +- src/ark_curve/r1cs/inner.rs | 6 +- src/ark_curve/rand.rs | 6 +- src/ark_curve/serialize.rs | 6 +- 10 files changed, 126 insertions(+), 126 deletions(-) diff --git a/src/ark_curve/edwards.rs b/src/ark_curve/edwards.rs index cfcd4b0..1ec03b5 100644 --- a/src/ark_curve/edwards.rs +++ b/src/ark_curve/edwards.rs @@ -12,7 +12,7 @@ pub struct Decaf377EdwardsConfig; // These types should not be exported. They are similar to `EdwardsAffine` and // `EdwardsProjective` from the `ark_ed_on_bls12_377` crate, except using our own // `Decaf377Config` that has the cofactor set to 1. Consumers of this -// library should use the `AffineElement` and `Element` (projective) +// library should use the `AffinePoint` and `Element` (projective) // types. pub type EdwardsAffine = Affine; pub type EdwardsProjective = Projective; diff --git a/src/ark_curve/element.rs b/src/ark_curve/element.rs index e15fd1a..7a61745 100644 --- a/src/ark_curve/element.rs +++ b/src/ark_curve/element.rs @@ -10,7 +10,7 @@ use crate::{ pub mod affine; pub mod projective; -pub use affine::AffineElement; +pub use affine::AffinePoint; pub use projective::Element; impl Valid for Element { @@ -20,7 +20,7 @@ impl Valid for Element { } impl ScalarMul for Element { - type MulBase = AffineElement; + type MulBase = AffinePoint; const NEGATION_IS_CHEAP: bool = true; @@ -29,7 +29,7 @@ impl ScalarMul for Element { let result = EdwardsProjective::batch_convert_to_mul_base(&bases_inner[..]); result .into_iter() - .map(|g| AffineElement { inner: g }) + .map(|g| AffinePoint { inner: g }) .collect::>() } } @@ -64,19 +64,19 @@ impl CurveGroup for Element { type BaseField = Fq; - type Affine = AffineElement; + type Affine = AffinePoint; // This type is supposed to represent an element of the entire elliptic // curve group, not just the prime-order subgroup. Since this is decaf, // this is just an `Element` again. - type FullGroup = AffineElement; + type FullGroup = AffinePoint; - fn normalize_batch(v: &[Self]) -> Vec { + fn normalize_batch(v: &[Self]) -> Vec { let v_inner = v.iter().map(|g| g.inner).collect::>(); let result = EdwardsProjective::normalize_batch(&v_inner[..]); result .into_iter() - .map(|g| AffineElement { inner: g }) + .map(|g| AffinePoint { inner: g }) .collect::>() } @@ -85,13 +85,13 @@ impl CurveGroup for Element { } } -impl Valid for AffineElement { +impl Valid for AffinePoint { fn check(&self) -> Result<(), ark_serialize::SerializationError> { Ok(()) } } -impl AffineRepr for AffineElement { +impl AffineRepr for AffinePoint { type Config = Decaf377EdwardsConfig; type ScalarField = Fr; @@ -105,7 +105,7 @@ impl AffineRepr for AffineElement { } fn zero() -> Self { - AffineElement { + AffinePoint { inner: EdwardsAffine::zero(), } } @@ -115,7 +115,7 @@ impl AffineRepr for AffineElement { } fn from_random_bytes(bytes: &[u8]) -> Option { - EdwardsAffine::from_random_bytes(bytes).map(|inner| AffineElement { inner }) + EdwardsAffine::from_random_bytes(bytes).map(|inner| AffinePoint { inner }) } fn mul_bigint(&self, other: impl AsRef<[u64]>) -> Self::Group { @@ -134,7 +134,7 @@ impl AffineRepr for AffineElement { } } -impl From for AffineElement { +impl From for AffinePoint { fn from(point: Element) -> Self { Self { inner: point.inner.into(), @@ -142,15 +142,15 @@ impl From for AffineElement { } } -impl From for Element { - fn from(point: AffineElement) -> Self { +impl From for Element { + fn from(point: AffinePoint) -> Self { Self { inner: point.inner.into(), } } } -impl From<&Element> for AffineElement { +impl From<&Element> for AffinePoint { fn from(point: &Element) -> Self { Self { inner: point.inner.into(), @@ -158,8 +158,8 @@ impl From<&Element> for AffineElement { } } -impl From<&AffineElement> for Element { - fn from(point: &AffineElement) -> Self { +impl From<&AffinePoint> for Element { + fn from(point: &AffinePoint) -> Self { Self { inner: point.inner.into(), } diff --git a/src/ark_curve/element/affine.rs b/src/ark_curve/element/affine.rs index f70dc50..4f6fb85 100644 --- a/src/ark_curve/element/affine.rs +++ b/src/ark_curve/element/affine.rs @@ -9,65 +9,65 @@ use zeroize::Zeroize; use crate::Element; #[derive(Copy, Clone)] -pub struct AffineElement { +pub struct AffinePoint { pub(crate) inner: EdwardsAffine, } -impl Hash for AffineElement { +impl Hash for AffinePoint { fn hash(&self, state: &mut H) { self.inner.hash(state); } } -impl Default for AffineElement { +impl Default for AffinePoint { fn default() -> Self { Element::default().into() } } -impl core::iter::Sum for Element { - fn sum>(iter: I) -> Self { +impl core::iter::Sum for Element { + fn sum>(iter: I) -> Self { iter.fold(Self::zero(), core::ops::Add::add) } } -impl<'a> core::iter::Sum<&'a AffineElement> for Element { - fn sum>(iter: I) -> Self { +impl<'a> core::iter::Sum<&'a AffinePoint> for Element { + fn sum>(iter: I) -> Self { iter.fold(Self::zero(), core::ops::Add::add) } } -impl PartialEq for AffineElement { - fn eq(&self, other: &AffineElement) -> bool { +impl PartialEq for AffinePoint { + fn eq(&self, other: &AffinePoint) -> bool { // Section 4.5 of Decaf paper self.inner.x * other.inner.y == self.inner.y * other.inner.x } } -impl Eq for AffineElement {} +impl Eq for AffinePoint {} -impl core::fmt::Debug for AffineElement { +impl core::fmt::Debug for AffinePoint { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { let element: Element = self.into(); f.write_fmt(format_args!( - "decaf377::AffineElement({})", + "decaf377::AffinePoint({})", hex::encode(&element.vartime_compress().0[..]) )) } } -impl Display for AffineElement { +impl Display for AffinePoint { fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult { let element: Element = self.into(); write!( f, - "decaf377::AffineElement({})", + "decaf377::AffinePoint({})", hex::encode(&element.vartime_compress().0[..]) ) } } -impl Zeroize for AffineElement { +impl Zeroize for AffinePoint { fn zeroize(&mut self) { self.inner.zeroize() } diff --git a/src/ark_curve/mod.rs b/src/ark_curve/mod.rs index f5a61be..aa347e0 100644 --- a/src/ark_curve/mod.rs +++ b/src/ark_curve/mod.rs @@ -12,7 +12,7 @@ pub mod serialize; pub use constants::ZETA; pub(crate) use edwards::{Decaf377EdwardsConfig, EdwardsProjective}; -pub use element::{AffineElement, Element}; +pub use element::{AffinePoint, Element}; pub use encoding::Encoding; mod on_curve; diff --git a/src/ark_curve/ops/affine.rs b/src/ark_curve/ops/affine.rs index 6626dfc..2568170 100644 --- a/src/ark_curve/ops/affine.rs +++ b/src/ark_curve/ops/affine.rs @@ -3,137 +3,137 @@ use core::ops::{Add, AddAssign, Mul, MulAssign, Neg, Sub, SubAssign}; use ark_ec::twisted_edwards::Projective; use crate::{ - ark_curve::element::AffineElement, ark_curve::Decaf377EdwardsConfig, ark_curve::Element, Fr, + ark_curve::element::AffinePoint, ark_curve::Decaf377EdwardsConfig, ark_curve::Element, Fr, }; -impl<'a, 'b> Add<&'b AffineElement> for &'a AffineElement { - type Output = AffineElement; +impl<'a, 'b> Add<&'b AffinePoint> for &'a AffinePoint { + type Output = AffinePoint; - fn add(self, other: &'b AffineElement) -> AffineElement { - AffineElement { + fn add(self, other: &'b AffinePoint) -> AffinePoint { + AffinePoint { inner: (self.inner + other.inner).into(), } } } -impl<'b> Add<&'b AffineElement> for AffineElement { +impl<'b> Add<&'b AffinePoint> for AffinePoint { type Output = Element; - fn add(self, other: &'b AffineElement) -> Element { + fn add(self, other: &'b AffinePoint) -> Element { (&self + other).into() } } -impl<'a> Add for &'a AffineElement { - type Output = AffineElement; - fn add(self, other: AffineElement) -> AffineElement { +impl<'a> Add for &'a AffinePoint { + type Output = AffinePoint; + fn add(self, other: AffinePoint) -> AffinePoint { self + &other } } -impl<'b> AddAssign<&'b AffineElement> for AffineElement { - fn add_assign(&mut self, other: &'b AffineElement) { - *self = AffineElement { +impl<'b> AddAssign<&'b AffinePoint> for AffinePoint { + fn add_assign(&mut self, other: &'b AffinePoint) { + *self = AffinePoint { inner: (self.inner + other.inner).into(), } } } -impl AddAssign for AffineElement { - fn add_assign(&mut self, other: AffineElement) { +impl AddAssign for AffinePoint { + fn add_assign(&mut self, other: AffinePoint) { *self += &other; } } -impl<'a, 'b> Sub<&'b AffineElement> for &'a AffineElement { - type Output = AffineElement; +impl<'a, 'b> Sub<&'b AffinePoint> for &'a AffinePoint { + type Output = AffinePoint; - fn sub(self, other: &'b AffineElement) -> AffineElement { - AffineElement { + fn sub(self, other: &'b AffinePoint) -> AffinePoint { + AffinePoint { inner: (self.inner - other.inner).into(), } } } -impl<'b> Sub<&'b AffineElement> for AffineElement { - type Output = AffineElement; +impl<'b> Sub<&'b AffinePoint> for AffinePoint { + type Output = AffinePoint; - fn sub(self, other: &'b AffineElement) -> AffineElement { + fn sub(self, other: &'b AffinePoint) -> AffinePoint { &self - other } } -impl<'a> Sub for &'a AffineElement { - type Output = AffineElement; +impl<'a> Sub for &'a AffinePoint { + type Output = AffinePoint; - fn sub(self, other: AffineElement) -> AffineElement { + fn sub(self, other: AffinePoint) -> AffinePoint { self - &other } } -impl Sub for AffineElement { - type Output = AffineElement; +impl Sub for AffinePoint { + type Output = AffinePoint; - fn sub(self, other: AffineElement) -> AffineElement { + fn sub(self, other: AffinePoint) -> AffinePoint { &self - &other } } -impl<'b> SubAssign<&'b AffineElement> for AffineElement { - fn sub_assign(&mut self, other: &'b AffineElement) { - *self = AffineElement { +impl<'b> SubAssign<&'b AffinePoint> for AffinePoint { + fn sub_assign(&mut self, other: &'b AffinePoint) { + *self = AffinePoint { inner: (self.inner - other.inner).into(), } } } -impl SubAssign for AffineElement { - fn sub_assign(&mut self, other: AffineElement) { +impl SubAssign for AffinePoint { + fn sub_assign(&mut self, other: AffinePoint) { *self -= &other; } } -impl Neg for AffineElement { +impl Neg for AffinePoint { type Output = Self; fn neg(self) -> Self { - AffineElement { inner: -self.inner } + AffinePoint { inner: -self.inner } } } -impl<'b> MulAssign<&'b Fr> for AffineElement { +impl<'b> MulAssign<&'b Fr> for AffinePoint { fn mul_assign(&mut self, point: &'b Fr) { let mut p: Projective = self.inner.into(); p *= *point; - *self = AffineElement { inner: p.into() } + *self = AffinePoint { inner: p.into() } } } -impl MulAssign for AffineElement { +impl MulAssign for AffinePoint { fn mul_assign(&mut self, other: Fr) { *self *= &other; } } -impl<'a, 'b> Mul<&'b Fr> for &'a AffineElement { - type Output = AffineElement; +impl<'a, 'b> Mul<&'b Fr> for &'a AffinePoint { + type Output = AffinePoint; - fn mul(self, point: &'b Fr) -> AffineElement { + fn mul(self, point: &'b Fr) -> AffinePoint { let mut p: Projective = self.inner.into(); p *= *point; - AffineElement { inner: p.into() } + AffinePoint { inner: p.into() } } } -impl<'a, 'b> Mul<&'b AffineElement> for &'a Fr { - type Output = AffineElement; +impl<'a, 'b> Mul<&'b AffinePoint> for &'a Fr { + type Output = AffinePoint; - fn mul(self, point: &'b AffineElement) -> AffineElement { + fn mul(self, point: &'b AffinePoint) -> AffinePoint { point * self } } -impl<'b> Mul<&'b Fr> for AffineElement { +impl<'b> Mul<&'b Fr> for AffinePoint { type Output = Element; fn mul(self, other: &'b Fr) -> Element { @@ -141,15 +141,15 @@ impl<'b> Mul<&'b Fr> for AffineElement { } } -impl<'a> Mul for &'a AffineElement { - type Output = AffineElement; +impl<'a> Mul for &'a AffinePoint { + type Output = AffinePoint; - fn mul(self, other: Fr) -> AffineElement { + fn mul(self, other: Fr) -> AffinePoint { self * &other } } -impl Mul for AffineElement { +impl Mul for AffinePoint { type Output = Element; fn mul(self, other: Fr) -> Element { @@ -157,26 +157,26 @@ impl Mul for AffineElement { } } -impl<'b> Mul<&'b AffineElement> for Fr { - type Output = AffineElement; +impl<'b> Mul<&'b AffinePoint> for Fr { + type Output = AffinePoint; - fn mul(self, other: &'b AffineElement) -> AffineElement { + fn mul(self, other: &'b AffinePoint) -> AffinePoint { &self * other } } -impl<'a> Mul for &'a Fr { - type Output = AffineElement; +impl<'a> Mul for &'a Fr { + type Output = AffinePoint; - fn mul(self, other: AffineElement) -> AffineElement { + fn mul(self, other: AffinePoint) -> AffinePoint { self * &other } } -impl Mul for Fr { - type Output = AffineElement; +impl Mul for Fr { + type Output = AffinePoint; - fn mul(self, other: AffineElement) -> AffineElement { + fn mul(self, other: AffinePoint) -> AffinePoint { &self * &other } } diff --git a/src/ark_curve/ops/projective.rs b/src/ark_curve/ops/projective.rs index 68610c6..da530bc 100644 --- a/src/ark_curve/ops/projective.rs +++ b/src/ark_curve/ops/projective.rs @@ -1,6 +1,6 @@ use core::ops::{Add, AddAssign, Mul, MulAssign, Neg, Sub, SubAssign}; -use crate::{ark_curve::element::projective::Element, ark_curve::AffineElement, Fr}; +use crate::{ark_curve::element::projective::Element, ark_curve::AffinePoint, Fr}; impl<'a, 'b> Add<&'b Element> for &'a Element { type Output = Element; @@ -186,36 +186,36 @@ impl Mul for Fr { } } -impl<'a> Add<&'a AffineElement> for Element { +impl<'a> Add<&'a AffinePoint> for Element { type Output = Element; - fn add(self, other: &'a AffineElement) -> Element { + fn add(self, other: &'a AffinePoint) -> Element { let element_other: Element = other.into(); &self + element_other } } -impl Add for Element { +impl Add for Element { type Output = Element; - fn add(self, other: AffineElement) -> Element { + fn add(self, other: AffinePoint) -> Element { &self + &other.into() } } -impl Add for AffineElement { +impl Add for AffinePoint { // Required to be `Element` to satisfy type bounds on // `AffineRepr::Group`. type Output = Element; - fn add(self, other: AffineElement) -> Element { + fn add(self, other: AffinePoint) -> Element { let other_element: Element = other.into(); let self_element: Element = other.into(); self_element + other_element } } -impl Add for AffineElement { +impl Add for AffinePoint { type Output = Element; fn add(self, other: Element) -> Element { @@ -223,7 +223,7 @@ impl Add for AffineElement { } } -impl<'a> Add<&'a Element> for AffineElement { +impl<'a> Add<&'a Element> for AffinePoint { type Output = Element; fn add(self, other: &'a Element) -> Element { @@ -231,46 +231,46 @@ impl<'a> Add<&'a Element> for AffineElement { } } -impl<'a> AddAssign<&'a AffineElement> for Element { - fn add_assign(&mut self, other: &'a AffineElement) { +impl<'a> AddAssign<&'a AffinePoint> for Element { + fn add_assign(&mut self, other: &'a AffinePoint) { let other_element: Element = other.into(); *self += other_element; } } -impl AddAssign for Element { - fn add_assign(&mut self, other: AffineElement) { +impl AddAssign for Element { + fn add_assign(&mut self, other: AffinePoint) { *self += &other; } } -impl<'a> SubAssign<&'a AffineElement> for Element { - fn sub_assign(&mut self, other: &'a AffineElement) { +impl<'a> SubAssign<&'a AffinePoint> for Element { + fn sub_assign(&mut self, other: &'a AffinePoint) { let other_element: Element = other.into(); *self -= other_element; } } -impl SubAssign for Element { - fn sub_assign(&mut self, other: AffineElement) { +impl SubAssign for Element { + fn sub_assign(&mut self, other: AffinePoint) { let other_element: Element = other.into(); *self -= other_element; } } -impl<'a> Sub<&'a AffineElement> for Element { +impl<'a> Sub<&'a AffinePoint> for Element { type Output = Element; - fn sub(self, other: &'a AffineElement) -> Element { + fn sub(self, other: &'a AffinePoint) -> Element { let other_element: Element = other.into(); &self - other_element } } -impl Sub for Element { +impl Sub for Element { type Output = Element; - fn sub(self, other: AffineElement) -> Element { + fn sub(self, other: AffinePoint) -> Element { &self - &other.into() } } diff --git a/src/ark_curve/r1cs/element.rs b/src/ark_curve/r1cs/element.rs index 7a4d368..036b4bd 100644 --- a/src/ark_curve/r1cs/element.rs +++ b/src/ark_curve/r1cs/element.rs @@ -8,7 +8,7 @@ use ark_std::vec::Vec; use crate::ark_curve::r1cs::{lazy::LazyElementVar, FqVar}; use crate::ark_curve::{edwards::EdwardsAffine, r1cs::inner::ElementVar as InnerElementVar}; -use crate::ark_curve::{AffineElement, Element}; +use crate::ark_curve::{AffinePoint, Element}; use crate::Fq; use super::inner::Decaf377EdwardsVar; @@ -149,8 +149,8 @@ impl AllocVar for ElementVar { } } -impl AllocVar for ElementVar { - fn new_variable>( +impl AllocVar for ElementVar { + fn new_variable>( cs: impl Into>, f: impl FnOnce() -> Result, mode: AllocationMode, diff --git a/src/ark_curve/r1cs/inner.rs b/src/ark_curve/r1cs/inner.rs index 5958e67..9f5a866 100644 --- a/src/ark_curve/r1cs/inner.rs +++ b/src/ark_curve/r1cs/inner.rs @@ -12,7 +12,7 @@ use ark_std::vec::Vec; use crate::ark_curve::{ constants::ZETA, edwards::EdwardsAffine, r1cs::fqvar_ext::FqVarExtension, r1cs::FqVar, - AffineElement, Decaf377EdwardsConfig, Element, + AffinePoint, Decaf377EdwardsConfig, Element, }; use crate::Fq; @@ -287,8 +287,8 @@ impl AllocVar for ElementVar { } } -impl AllocVar for ElementVar { - fn new_variable>( +impl AllocVar for ElementVar { + fn new_variable>( cs: impl Into>, f: impl FnOnce() -> Result, mode: AllocationMode, diff --git a/src/ark_curve/rand.rs b/src/ark_curve/rand.rs index 8dc8d61..4ac19d2 100644 --- a/src/ark_curve/rand.rs +++ b/src/ark_curve/rand.rs @@ -5,7 +5,7 @@ use ark_std::rand::{ Rng, }; -use crate::ark_curve::{edwards::EdwardsProjective, AffineElement, Element, Encoding}; +use crate::ark_curve::{edwards::EdwardsProjective, AffinePoint, Element, Encoding}; impl Distribution for Standard { #[inline] @@ -26,8 +26,8 @@ impl Distribution for Standard { } } -impl Distribution for Standard { - fn sample(&self, rng: &mut R) -> AffineElement { +impl Distribution for Standard { + fn sample(&self, rng: &mut R) -> AffinePoint { let point: Element = self.sample(rng); point.into() } diff --git a/src/ark_curve/serialize.rs b/src/ark_curve/serialize.rs index 3a76643..51bec81 100644 --- a/src/ark_curve/serialize.rs +++ b/src/ark_curve/serialize.rs @@ -3,9 +3,9 @@ use core::convert::TryInto; use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; use ark_std::io::{Read, Write}; -use crate::ark_curve::{AffineElement, Element, Encoding}; +use crate::ark_curve::{AffinePoint, Element, Encoding}; -impl CanonicalDeserialize for AffineElement { +impl CanonicalDeserialize for AffinePoint { fn deserialize_with_mode( reader: R, compress: ark_serialize::Compress, @@ -27,7 +27,7 @@ impl CanonicalDeserialize for AffineElement { } } -impl CanonicalSerialize for AffineElement { +impl CanonicalSerialize for AffinePoint { fn serialized_size(&self, compress: ark_serialize::Compress) -> usize { match compress { ark_serialize::Compress::Yes => 32,