Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

theStack
Copy link
Contributor

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 SECP256K1_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 the compressed parameter needs to be either 0 or 1.

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.
@apoelstra
Copy link
Contributor

LGTM

Copy link
Collaborator

@real-or-random real-or-random left a 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);
Copy link
Collaborator

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

Copy link
Collaborator

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.

theStack added a commit to theStack/secp256k1 that referenced this pull request Dec 2, 2024
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants