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

New testEcc tests in 2.1.0 break @noble/secp256k1 #13

Closed
landabaso opened this issue Sep 27, 2022 · 4 comments
Closed

New testEcc tests in 2.1.0 break @noble/secp256k1 #13

landabaso opened this issue Sep 27, 2022 · 4 comments

Comments

@landabaso
Copy link

landabaso commented Sep 27, 2022

Ecpair 2.1.0 testEcc has additional new tests with code like this:

ecc.privateAdd(
        h('0000000000000000000000000000000000000000000000000000000000000001'),
        h('0000000000000000000000000000000000000000000000000000000000000000'),
      )

which breaks noble-secp256k1, because noble expects the private key > 0.

See:
https://github.com/paulmillr/noble-secp256k1/blob/1.7.0/index.ts#L1024

I understand this is not strictly a bug. Or is it?
Anyway, I thought about sharing this with you in case you agree on tweaking the tests to avoid 0 priv keys.

@landabaso landabaso changed the title New tests break @noble/secp256k1 New testEcc tests in 2.1.0 break @noble/secp256k1 Sep 27, 2022
@junderw
Copy link
Member

junderw commented Sep 27, 2022

I don't see any code for privateAdd, so I assume this is a bug in the wrapper code you created/use.

privateAdd args are (privkey, scalar) so the second arg can be from 0 to curve order -1.

Please file a bug report with whoever maintains the wrapper.

edit: curve order -1, not 2^256-1

@landabaso
Copy link
Author

You're right. I just did. Thanks!

@landabaso
Copy link
Author

landabaso commented Sep 28, 2022

I don't want to open another issue because I somehow feel this is somewhat related.

I'm still working to make noble & ecpair work together after new versions of both libraries.

There's this other test in ecpair:

  // -3 + 3 == 0
  assert(
    ecc.privateAdd(
      h('fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd036413e'),
      h('0000000000000000000000000000000000000000000000000000000000000003'),
    ) === null,
  );

I end up having a point that is zero but not a null.

Does it need to return null because this operation is invalid (& noble should throw)?

EDIT: Yeah, I guess this is the reason. I updated my wrapper to validate returned values from noble-ecc and everything runs smooth.

@junderw
Copy link
Member

junderw commented Sep 28, 2022

Yes. The output of privateAdd is a privateKey. And 0 is an invalid privateKey which should return null.

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

No branches or pull requests

2 participants