refactor: Move (de)ser helpers from musig and eckey to group - #1915
Conversation
|
I agree that these helpers should not be specific to musig, so Concept ACK on moving them out. But the question is where to move them. I had never considered the purpose of So in some sense, But if not I think one way out is to move all (de)serialization functions to Alternatively, we could make separate |
7f7d071 to
103289a
Compare
|
Concept ACK Agree that |
Done in a new first commit, that also takes care of the dependency issue I mentioned in the description. I had thought about moving to group as well but having the (de)ser functions there already made me think it was the better choice, aside from being a smaller change. But I agree that moving both to group is the most consistent approach.
Hm, not sure if I understand you correctly because pubkey_tweak doesn't seem to fit so well with the privkey functions. My suggestion (pushed in the third commit) would be to simply rename the files eckey.h -> eckey_tweak.h and leave the function names unchanged. That is a very easy to review change and seems to make everything pretty consistent unless you insist that the file name always need to appear exactly in the funciton name as a namespace. At least historically that doesn't always seem to be the case. |
Oh, sure! I had missed this.
That makes sense. Though now that I see it, I have a slight preference of dropping that commit entirely. (Sorry for the back and forth!) The renaming doesn't give us much except a better description of the module. But
Either way is fine with me in the end. Also, if you want, you can add another commit that renames |
Also rename them to secp256k1_ge_serialize_ext33 and secp256k1_ge_parse_ext33 to make the 33-byte format explicit.
f3bebc5 to
bfd40bd
Compare
Sure, that's a different perspective that I hadn't really considered. Dropped that part again.
Done |
theStack
left a comment
There was a problem hiding this comment.
ACK bfd40bd
Unrelated to this refactoring PR, but noticing only now: what's a bit odd is that the ge serialize and parse functions (formerly _eckey_pubkey_{parse,serialize33,serialize65}) are not symmetric, as the latter also accepts hybrid pubkeys (i.e. 65 bytes with first byte being 0x06/0x07 rather than 0x04) as input, which we likely only ever need in a single API function (secp256k1_ec_pubkey_parse) for legacy reasons. Maybe a further split-up into e.g. "ge_parse33", "ge_parse65", and "ge_parse65_with_hybrid" would make sense for being explicit and symmetric, so the weird/exotic one stands out. As I'm writing this I notice that the silentpayments lightclient PR unintentionally accepts encodings in hybrid pubkey format for the prevouts summary.
These two helpers,
secp256k1_musig_ge_serialize_extandsecp256k1_musig_ge_parse_ext, aren't really musig-specific. They (de)serialize a group element that can also be the point at infinity. This moves them toeckeyassecp256k1_eckey_serialize_extandsecp256k1_eckey_parse_ext. They can't move further down to group.h because they depend on othereckeyfunctions internally. There should be no functional change here.I stumbled upon this while working on #1754 where I would want to reuse these helpers in that module, so it is split out of that. But the change seems to make sense on its own as well, so I wouldn't consider this prep work alone.