Skip to content

Conversation

@guggero
Copy link
Contributor

@guggero guggero commented May 5, 2022

Something I noticed when taking a closer look at how the btcec V2 library works.
Not sure if this is really necessary or not, any thoughts, @Roasbeef?
The unit tests all passed fine without this, but maybe this could be an edge case?

@guggero guggero requested a review from Roasbeef May 5, 2022 15:38
@guggero guggero mentioned this pull request May 5, 2022
1 task
secp.ScalarBaseMultNonConst(new(secp.ModNScalar).SetInt(1), &g)

// Get -G by negating the Y axis.
// Get -G by negating the Y axis. We normalize first, so we can negate
Copy link
Member

Choose a reason for hiding this comment

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

Are we doing this anywhere else across our packages? Agree that it's safer to first map to affine coordinate, and one always needs to normalize after modifying any of the field elements.

One way we can try to trigger a failure here would be using a quickcheck test which may eventually hit an edge case that causes an issue to be triggered here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are we doing this anywhere else across our packages?

Not that I'm aware of. But I need to check the lnd codebase that we always to the normalize after modifying field elements.

I added some quickcheck tests and also increased the number of iterations. Both works fine with and without this diff. So I guess it can't hurt to add it anyway?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah agreed, in the future we should spin this out into methods in the btcec package to make things generally easy to use.

@guggero guggero force-pushed the btcec-v2-negation branch from 5285da1 to ff122f3 Compare May 6, 2022 11:24
@guggero guggero force-pushed the btcec-v2-negation branch from ff122f3 to d63b815 Compare May 6, 2022 11:29
Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

LGTM 🐇

@guggero guggero merged commit 3e49f4c into master May 9, 2022
@guggero guggero deleted the btcec-v2-negation branch May 9, 2022 08:58
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.

3 participants