-
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
Make ec_ arithmetic more consistent and add documentation #671
Comments
What do people think about adding |
I think that's a good idea. we should try to make the API breakage gradual. |
Sounds good to me. Should do that sooner rather than later because schnorrsig PR currently has |
Ok. The only possible drawback is that we may want to rethink these functions anyway in the future (hash based? Add BIP32 module? Taproot module?). But I don't think that should stop us now from renaming. |
As brought up by @afk11 on #secp256k1 there are a couple of undocumented and inconsistent surprises in the ec arithmetic functions (that is
secp256k1_ec_pub/privkey_neg
,_tweak_add
andtweak_mul
.In particular:
Right now,
ec_privkey_neg
,ec_privkey_tweak_add
andec_privkey_tweak_mul
do not fail if the seckey is invalid, but they may give unexpected results in that case (f.e. secp256k1_ec_privkey_negate and invalid privkeys #488). In order to avoid that, the user should callec_seckey_verify
before calling these functions, but that's not documented. Alternatively, these functions could callec_seckey_verify
themselves. In any case we should define what a validseckey
is (in the documentation ofec_seckey_verify
for example) and refer to that in the argument documentation of other functions.ec_privkey_tweak_add
andec_privkey_tweak_mul
can fail (return 0). As a result the seckey argument will be zeroized. This is not documented. There's conflicting ideas whether this is a good idea:ec_privkey_tweak_add
andtweak_mul
(EDIT: actually the privkey can not overflow in these functions)privkey_tweak_add
andprivkey_tweak_mul
fail if the resulting privkey is 0 but not if it overflows. That's not ideal because you won't be able to sign for it. Additionally, the documentation forprivkey_tweak_add
is wrong:returns: [...] 0 the resulting private key [...] would be invalid (only when the tweak is the complement of the corresponding private key)
(same forpubkey_tweak_add
). An overflowing private key is also invalid.All this behavior should be tested
See naming: privkey vs seckey #670 for naming improvements (seckey vs. privkey)
The text was updated successfully, but these errors were encountered: