Skip to content

Commit

Permalink
Rename AffineElement to AffinePoint to match min_curve
Browse files Browse the repository at this point in the history
  • Loading branch information
cronokirby committed Jan 31, 2024
1 parent 6bf191e commit 525e752
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 117 deletions.
34 changes: 17 additions & 17 deletions src/ark_curve/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -20,7 +20,7 @@ impl Valid for Element {
}

impl ScalarMul for Element {
type MulBase = AffineElement;
type MulBase = AffinePoint;

const NEGATION_IS_CHEAP: bool = true;

Expand All @@ -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::<Vec<_>>()
}
}
Expand Down Expand Up @@ -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<AffineElement> {
fn normalize_batch(v: &[Self]) -> Vec<AffinePoint> {
let v_inner = v.iter().map(|g| g.inner).collect::<Vec<_>>();
let result = EdwardsProjective::normalize_batch(&v_inner[..]);
result
.into_iter()
.map(|g| AffineElement { inner: g })
.map(|g| AffinePoint { inner: g })
.collect::<Vec<_>>()
}

Expand All @@ -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;
Expand All @@ -105,7 +105,7 @@ impl AffineRepr for AffineElement {
}

fn zero() -> Self {
AffineElement {
AffinePoint {
inner: EdwardsAffine::zero(),
}
}
Expand All @@ -115,7 +115,7 @@ impl AffineRepr for AffineElement {
}

fn from_random_bytes(bytes: &[u8]) -> Option<Self> {
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 {
Expand All @@ -134,32 +134,32 @@ impl AffineRepr for AffineElement {
}
}

impl From<Element> for AffineElement {
impl From<Element> for AffinePoint {
fn from(point: Element) -> Self {
Self {
inner: point.inner.into(),
}
}
}

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(),
}
}
}

impl From<&Element> for AffineElement {
impl From<&Element> for AffinePoint {
fn from(point: &Element) -> Self {
Self {
inner: point.inner.into(),
}
}
}

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(),
}
Expand Down
26 changes: 13 additions & 13 deletions src/ark_curve/element/affine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,44 @@ 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<H: core::hash::Hasher>(&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<AffineElement> for Element {
fn sum<I: Iterator<Item = AffineElement>>(iter: I) -> Self {
impl core::iter::Sum<AffinePoint> for Element {
fn sum<I: Iterator<Item = AffinePoint>>(iter: I) -> Self {
iter.fold(Self::zero(), core::ops::Add::add)
}
}

impl<'a> core::iter::Sum<&'a AffineElement> for Element {
fn sum<I: Iterator<Item = &'a AffineElement>>(iter: I) -> Self {
impl<'a> core::iter::Sum<&'a AffinePoint> for Element {
fn sum<I: Iterator<Item = &'a AffinePoint>>(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!(
Expand All @@ -56,7 +56,7 @@ impl core::fmt::Debug for AffineElement {
}
}

impl Display for AffineElement {
impl Display for AffinePoint {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
let element: Element = self.into();
write!(
Expand All @@ -67,7 +67,7 @@ impl Display for AffineElement {
}
}

impl Zeroize for AffineElement {
impl Zeroize for AffinePoint {
fn zeroize(&mut self) {
self.inner.zeroize()
}
Expand Down
2 changes: 1 addition & 1 deletion src/ark_curve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub mod serialize;

pub use constants::ZETA;

Check warning on line 13 in src/ark_curve/mod.rs

View workflow job for this annotation

GitHub Actions / Check

unused import: `constants::ZETA`

Check warning on line 13 in src/ark_curve/mod.rs

View workflow job for this annotation

GitHub Actions / Test Suite (r1cs,u32_backend)

unused import: `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;
Expand Down
Loading

0 comments on commit 525e752

Please sign in to comment.