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

noble-secp256k1 is not handling properly the point at infinity #121

Merged
merged 6 commits into from
Feb 19, 2024

Conversation

Elli610
Copy link
Contributor

@Elli610 Elli610 commented Feb 19, 2024

the toAffine method encodes the point at infinity O in affine coordinates as (0, 0):

if ( this.equals(I)) return { x: 0n , y: 0n }; // fast - path for zero point

The code of fromAffine importing affine to projective is the following:

static fromAffine (p: AffinePoint) {
  return new Point (p.x , p.y , 1n) ;
}

As we can see, fromAffine does not check for (0, 0) to properly import O. This means that silent errors in the computation will occur when exporting and then importing O, which can happen with valid operations (such as (l − 1) · P + P where P is a point of order l).

A simple way to fix it:

static fromAffine (p: AffinePoint) {
  if ((p.x === 0n) && (p.y === 0n)) return new Point (0n , 1n , 0n);
  else return new Point (p.x , p.y , 1n) ;
}

Solved with @LeJamon

@paulmillr
Copy link
Owner

  1. use triple equality
  2. don’t usw the spaces around cases (formatting)

@Elli610
Copy link
Contributor Author

Elli610 commented Feb 19, 2024

  1. use triple equality
  2. don’t usw the spaces around cases (formatting)

done 👍🏻

@paulmillr
Copy link
Owner

Can you please revery all other formatting changes on other lines? Thanks.

@Elli610
Copy link
Contributor Author

Elli610 commented Feb 19, 2024

Can you please revery all other formatting changes on other lines? Thanks.

fixed

@paulmillr paulmillr merged commit d9aabe9 into paulmillr:main Feb 19, 2024
4 checks passed
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