-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Removes _fe_equal_var
, and unwanted _fe_normalize_weak
calls (in tests)
#1062
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
Conversation
fe_equal_var
and remove unwanted _fe_normalize_weak
callsfe_equal_var
in doc and remove unwanted _fe_normalize_weak
calls
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept ACK
I think then we should add (#ifdef VERIFY) magnitude checks to secp256k1_fe_equal_var and secp256k1_fe_equal.
If you're up to it, I think the other field function could need an audit for similar checks.
In Lines 132 to 135 in a1102b1
Here, the secp256k1_fe_sqr function ensures that t1->magnitude = 1 but there is no guarantee for the magnitude of a to be one since it is passed into the function. Hence, some fe_sqrt tests are failing after adding magnitude checks inside fe_equal .
We could do |
@siv2r Regarding I think it might be better to just say that both inputs to the equals methods can be magnitude <= 8 too (indeed tied to the mul/sqr limit whatever it is or changes to). There's no real obstacle to the implementation(s) (just change the third argument to _fe_negate to 8) and no performance hit AFAICT. |
It's only used in a single var-time caller, so technically it could be changed to sqrt_var, but preferably not. |
Apparently Edited because I first thought |
Oh, Okay. Then, creating a new function for
Yes, I think this might be a better approach since it keeps the functionality of both After this, I felt we needed to remove the secp256k1/src/modules/extrakeys/tests_impl.h Lines 75 to 77 in a1102b1
Even here, the magnitude of y is two, so modifying the _fe_sqrt function (which I suggested) is a bad idea.
|
Hehe ok, and here it's basically an oversight. This is just test code, so |
|
While I'm on the subject, the other callers to |
77f5323
to
08186e8
Compare
addressed #1062 (comment) and #1062 (review) (detailed explanation in 08186e8). |
I also benchmarked the
|
fe_equal_var
in doc and remove unwanted _fe_normalize_weak
callsfe_verify
checks
fe_verify
checksfe_verify
checks
@peterdettman Good points. Do you think we should remove |
Yeah, pretty much. Until there's a performance-sensitive caller for whom a != b is the expected result, I don't see any value in |
08186e8
to
d40ea5f
Compare
addressed #1061 |
@siv2r Do you plan to also remove the (If you want to add it here, I think it's really ok to add it on top of the existing commits, no need to rewrite the existing commits). |
Okay, I will remove |
|
I missed the "field: add magnitude check and _fe_verify check for internal field APIs" commit being added here before writing #1066 (which duplicates some of its efforts, but also goes a lot further in a number of ways). Feel free to keep it in (and I'll rebase), but if you think #1066 covers everything you're doing here, perhaps it's easier to leave that for that PR. |
No worries, I will rebase this PR. |
Ok, merging #1066 took a while.... This PR here needs rebase now. :) |
ea1225b
to
315275f
Compare
Rebased. #1066 took care of all the magnitude and
|
@@ -2967,7 +2967,6 @@ static int check_fe_equal(const secp256k1_fe *a, const secp256k1_fe *b) { | |||
secp256k1_fe an = *a; | |||
secp256k1_fe bn = *b; | |||
secp256k1_fe_normalize_weak(&an); | |||
secp256k1_fe_normalize_var(&bn); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why normalize_var
was used on bn
. I assumed it intended to set bn
's magnitude to 1 for the fe_equal
call. So, I removed it. Please let me know if that's not the case, and I'll revert this.
All test cases passed with this change.
Nice. :)
Can you update the PR title and the initial comment, so that they reflect the current status? |
fe_verify
checks_fe_equal_var
, and unwanted _fe_normalize_weak
calls (in tests)
Needs rebase again, sorry, but should be trivial. :) Thanks for updating the PR title. Can you also update the initial post/PR description (e.g., replace the contents with #1062 (comment) )? It's just cosmetic, but the text of will be added to the merge commit, so it makes sense to keep this updated. |
It is not neccessary for the second argument in `secp256k1_fe_equal_var` (or `secp256k1_fe_equal`) to have magnitude = 1. Hence, removed the `secp256k1_fe_normalize_weak` call for those argument.
`fe_equal_var` hits a fast path only when the inputs are unequal, which is uncommon among its callers (public key parsing, ECDSA verify).
315275f
to
54058d1
Compare
Rebased and updated the description. I forgot about the merge commit including the description too. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK 54058d1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Until there's a performance-sensitive caller for whom a != b is the expected result, I don't see any value in _fe_equal_var.
I don't think we know what the expected result of the caller is. The difference seems to be negligible though.
ACK 54058d1
Fixes #946 and #1061
Changes:
fe_normalize_weak
calls to the second argument offe_equal
fe_equal_var