Address prime_field_inv(a: int, n: int)
a == n case
#114
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What was wrong?
Bounty hunter Nguyen Thoi Minh Quan found this issue:
"inv0(x): This function returns the multiplicative inverse of x in
F, extended to all of F by fixing inv0(0) == 0"
I.e. inv(0, 7) = inv(7, 7) = 0
In finite field F_7: 0 = 7.
How was it fixed?
Nguyen Thoi Minh Quan:
py_ecc/py_ecc/utils.py
Line 24 in dd38b1f
Assign a = a % n in the 1st line of the function prime_field_inv
My first quick scan is that this edge case would not happen via BLS API calls. Also, py-ecc is not a constant-time implementation. Anyway, good to be more careful. 👍
secp256k1
also has aninv
function.py_ecc/py_ecc/secp256k1/secp256k1.py
Lines 46 to 56 in dd38b1f
However, unlike BLS, the
a == n
case is undefined here so I didn't change this function./cc @JustinDrake