Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pefontana committed Oct 23, 2023
1 parent ee74daa commit 0ddba75
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
17 changes: 8 additions & 9 deletions crates/starknet-types-core/src/curve/affine_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ use lambdaworks_math::cyclic_group::IsGroup;
use lambdaworks_math::elliptic_curve::short_weierstrass::curves::stark_curve::StarkCurve;
use lambdaworks_math::elliptic_curve::short_weierstrass::point::ShortWeierstrassProjectivePoint;
use lambdaworks_math::elliptic_curve::traits::{EllipticCurveError, FromAffine};
use lambdaworks_math::field::element::FieldElement;
use lambdaworks_math::field::fields::fft_friendly::stark_252_prime_field::Stark252PrimeField;
use lambdaworks_math::unsigned_integer::traits::IsUnsignedInteger;

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AffinePoint(pub(crate) ShortWeierstrassProjectivePoint<StarkCurve>);

impl AffinePoint {
Expand All @@ -23,13 +22,13 @@ impl AffinePoint {
}

/// Returns the `x` coordinate of the point.
pub fn x(&self) -> &FieldElement<Stark252PrimeField> {
self.0.x()
pub fn x(&self) -> Felt {
Felt(*self.0.x())
}

/// Returns the `y` coordinate of the point.
pub fn y(&self) -> &FieldElement<Stark252PrimeField> {
self.0.y()
pub fn y(&self) -> Felt {
Felt(*self.0.y())
}
}

Expand All @@ -47,17 +46,17 @@ impl ops::AddAssign<&AffinePoint> for AffinePoint {
}
}

impl ops::Mul<&Felt> for &AffinePoint {
impl ops::Mul<Felt> for &AffinePoint {
type Output = AffinePoint;

fn mul(self, rhs: &Felt) -> AffinePoint {
fn mul(self, rhs: Felt) -> AffinePoint {
AffinePoint(self.0.operate_with_self(rhs.0.representative()))
}
}

impl<T> ops::Mul<T> for &AffinePoint
where
T: IsUnsignedInteger, // Asumiendo que "exponent" es una trait
T: IsUnsignedInteger,
{
type Output = AffinePoint;

Expand Down
18 changes: 8 additions & 10 deletions crates/starknet-types-core/src/curve/projective_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ use lambdaworks_math::cyclic_group::IsGroup;
use lambdaworks_math::elliptic_curve::short_weierstrass::curves::stark_curve::StarkCurve;
use lambdaworks_math::elliptic_curve::short_weierstrass::point::ShortWeierstrassProjectivePoint;
use lambdaworks_math::elliptic_curve::traits::{EllipticCurveError, FromAffine};
use lambdaworks_math::field::element::FieldElement;
use lambdaworks_math::field::fields::fft_friendly::stark_252_prime_field::Stark252PrimeField;
use lambdaworks_math::unsigned_integer::traits::IsUnsignedInteger;

use crate::curve::affine_point::AffinePoint;
Expand All @@ -32,18 +30,18 @@ impl ProjectivePoint {
}

/// Returns the `x` coordinate of the point.
pub fn x(&self) -> &FieldElement<Stark252PrimeField> {
self.0.x()
pub fn x(&self) -> Felt {
Felt(*self.0.x())
}

/// Returns the `y` coordinate of the point.
pub fn y(&self) -> &FieldElement<Stark252PrimeField> {
self.0.y()
pub fn y(&self) -> Felt {
Felt(*self.0.y())
}

/// Returns the `z` coordinate of the point.
pub fn z(&self) -> &FieldElement<Stark252PrimeField> {
self.0.z()
pub fn z(&self) -> Felt {
Felt(*self.0.z())
}
}

Expand All @@ -61,10 +59,10 @@ impl ops::AddAssign<&ProjectivePoint> for ProjectivePoint {
}
}

impl ops::Mul<&Felt> for &ProjectivePoint {
impl ops::Mul<Felt> for &ProjectivePoint {
type Output = ProjectivePoint;

fn mul(self, rhs: &Felt) -> ProjectivePoint {
fn mul(self, rhs: Felt) -> ProjectivePoint {
ProjectivePoint(self.0.operate_with_self(rhs.0.representative()))
}
}
Expand Down

0 comments on commit 0ddba75

Please sign in to comment.