Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement addition and multiplication operations for AffinePoint #112

Closed
wants to merge 3 commits into from

Conversation

FilipLaurentiu
Copy link
Contributor

@FilipLaurentiu FilipLaurentiu commented Jan 22, 2025

  • Feature

What is the current behavior?

Addition or multiplication not allowed

What is the new behavior?

AffinePoints could now be added or multiplied by an exponent

Does this introduce a breaking change?

No

Multiply `AffinePoint` by `Felt`
Copy link
Collaborator

@tdelabro tdelabro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain to me why is this something we want? Are are you sure there is no reason we could not want it to be implemented?

(I have no opinion, just trying to understand)

crates/starknet-types-core/src/curve/affine_point.rs Outdated Show resolved Hide resolved
crates/starknet-types-core/src/curve/affine_point.rs Outdated Show resolved Hide resolved
@@ -295,7 +295,7 @@ impl Felt {

/// Quotient and remainder between `self` and `rhs`.
pub fn div_rem(&self, rhs: &NonZeroFelt) -> (Self, Self) {
let (q, r) = self.0.representative().div_rem(&rhs.0.representative());
let (q, r) = self.representative().div_rem(&rhs.0.representative());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't this change the behaviour?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the self.representative() function returns self.0.representative() so it's the same.
I had to add the public function representative to get the representation of a Felt for the operate_with_self function in order to multiply the point with itself.
Adding representative() function to Felt and replace the old way of using it make the code cleaner.

@FilipLaurentiu
Copy link
Contributor Author

Can you explain to me why is this something we want? Are are you sure there is no reason we could not want it to be implemented?

(I have no opinion, just trying to understand)

starknet-rs library use this crate for their EC points representation. I am using starknet-rs for my project and I need these operations. The other option is to use the underlying lambdaworks_math library but this will add a new layer of abstraction and will make the code harder to understand. These are basic curve operation that are frequently used.

Another missing functionality is the ability to uncompress EC points that are used in Cairo

Implement `representative` function for `NonZeroFelt` and replace the `self.0.representative` with `self.representative` for all the places where it was used
@FilipLaurentiu
Copy link
Contributor Author

FilipLaurentiu commented Jan 24, 2025

Close this PR and open a new one with minimum changes and similar behavior as ProjectivePoint #114

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants