-
Notifications
You must be signed in to change notification settings - Fork 1k
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
UB in tests: Invalid pointer comparison in secp256k1_fe_inv_all_var #873
Comments
No. Thanks for reporting. Note that VERIFY_CHECKs are only active in the tests. Are you willing to open a PR? I think the right thing to check is |
Well ok, not really. We can check |
The non-overlapping status of the arrays is an important part of the interface. |
So after reading a bit on cppreference.com (which also has pages about C), I believe:
I believe that means that overlap can be checked by casting to intptr_t and doing the check we do now. It would rely on the assumption that subsequent array elements correspond to subsequent intptr_t values, which I expect to be universal, and even if not, wouldn't be UB. |
It's not necessarily true on platforms with segmented memory e.g. real-mode 16-bit dos. But I don't think that's a problem, because this is just a verify check. It's probably also not true for some bizarre environments like the compcert formalism for C. But again, no problem there. If there were come libsecp256k1 porting guide it might deserve a line in it. |
Ugh, yeah, I guess we can do this. I didn't expect that a pointer-to-int cast will ever "solve" a problem. By the way, I usually look stuff up in the standard directly:
Well, the current behavior isn't universal either. I guess we should add a comment to the line, and if we want we can also add a comment to assumptions.h. This is the closest thing to a porting guide that we currently have. |
Here's a simpler solution: Remove the function, it's currently unused. Was this function intended for ECDSA batch verification? |
It's for building the verify context, but its functionality was inlined into its parent function ( secp256k1_ge_set_all_gej_var ) to reduce the usage of scratch space in #553. I agree, it should probably just be removed. |
Haha, let's just remove it then. |
See #878. |
Is this
VERIFY_CHECK
pointer comparison insecp256k1_fe_inv_all_var
defined whenr
anda
are pointing to different objects?secp256k1/src/field_impl.h
Lines 266 to 273 in 98dac87
Nothing high priority of course, but perhaps worth fixing? :)
This pointer comparison was introduced as part of PR #16 ("Implement batch inversion of field elements") in f16be77 back in 2014.
The text was updated successfully, but these errors were encountered: