-
Notifications
You must be signed in to change notification settings - Fork 208
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
fix and verify compressed
argument in _eckey_pubkey_serialize calls
#300
base: master
Are you sure you want to change the base?
fix and verify compressed
argument in _eckey_pubkey_serialize calls
#300
Conversation
In several calls of the internal function `secp256k1_eckey_pubkey_serialize`, the public API flag `SECP256K1_EC_COMPRESSED` is passed, which is meant to be only used for the public function `secp256k1_ec_pubkey_serialize`. It works as intended in all of those cases (it wouldn't for `..._UNCOMPRESSED` though), but it's still kind of a type mismatch that can't be detected by the compiler. To avoid cases like this in the future, a VERIFY_CHECK is added that the `compressed` parameter needs to be either 0 or 1.
LGTM |
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
@@ -35,6 +36,8 @@ static int secp256k1_eckey_pubkey_parse(secp256k1_ge *elem, const unsigned char | |||
} | |||
|
|||
static int secp256k1_eckey_pubkey_serialize(secp256k1_ge *elem, unsigned char *pub, size_t *size, int compressed) { | |||
VERIFY_CHECK(compressed == 0 || compressed == 1); |
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 if we want to touch this upstream file. It's also a nice goal to keep the diff to upstream minimal. Ideally, the diff to upstream would just be added modules and changes to build system, README, etc... But yeah, we've modified upstream files in the past. If we think that this is a reasonable change, we could PR it to upstream, of course.
Same is true for the modification to secp256k1.c
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.
We should just rebase on upstream's musig module now.
Due to similarity to the public API function `secp256k1_ec_pubkey_serialize`, public API flags like `SECP256K1_EC_COMPRESSED` are sometimes mistakingly passed to newly proposed code (this is currently the case for several modules in secp256k1-zkp, see BlockstreamResearch/secp256k1-zkp#300). which is currently not detected. To avoid this in the future, a VERIFY_CHECK is added to check that the `compressed` argument is either 0 or 1.
In several calls of the internal function
secp256k1_eckey_pubkey_serialize
, the public API flagSECP256K1_EC_COMPRESSED
is passed, which is meant to be only used for the public functionsecp256k1_ec_pubkey_serialize
. It works as intended in all of those cases (it wouldn't forSECP256K1_EC_UNCOMPRESSED
though), but it's still kind of a type mismatch that can't be detected by the compiler. To avoid cases like this in the future, a VERIFY_CHECK is added that thecompressed
parameter needs to be either 0 or 1.