Due to similarity to the public API function secp256k1_ec_pubkey_serialize, public API flags like SECP256K1_EC_COMPRESSED are sometimes mistakingly passed to secp256k1_eckey_pubkey_serialize in newly proposed code (this is currently the case for several modules in secp256k1-zkp, see https://github.com/BlockstreamResearch/secp256k1-zkp/pull/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.
Verify `compressed` argument in `secp256k1_eckey_pubkey_serialize` #1642
pull theStack wants to merge 1 commits into bitcoin-core:master from theStack:202412-verify-compressed-argument-in-_eckey_pubkey_serialize changing 2 files +4 −1-
theStack commented at 5:28 PM on December 2, 2024: contributor
-
1823594761
Verify `compressed` argument in `secp256k1_eckey_pubkey_serialize`
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 https://github.com/BlockstreamResearch/secp256k1-zkp/pull/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.
- real-or-random added the label assurance on Dec 2, 2024
- real-or-random added the label refactor/smell on Dec 2, 2024
-
in src/eckey_impl.h:39 in 1823594761
35 | @@ -35,6 +36,8 @@ static int secp256k1_eckey_pubkey_parse(secp256k1_ge *elem, const unsigned char 36 | } 37 | 38 | static int secp256k1_eckey_pubkey_serialize(secp256k1_ge *elem, unsigned char *pub, size_t *size, int compressed) { 39 | + VERIFY_CHECK(compressed == 0 || compressed == 1);
real-or-random commented at 8:30 AM on December 9, 2024:In other places, we simply rely on C's int-as-bool convention, so I suggest adding a comment that explains why we enforce 0/1 in this case.
real-or-random approvedreal-or-random commented at 8:30 AM on December 9, 2024: contributorutACK 1823594761046ae38e002781d65e9538dd211d27
stratospher commented at 8:38 AM on February 24, 2025: contributorACK 1823594. Got tests failures when passing public API flags to
secp256k1_eckey_pubkey_serialize.real-or-random merged this on Feb 24, 2025real-or-random closed this on Feb 24, 2025hebasto referenced this in commit 0ee5708432 on Mar 10, 2025hebasto referenced this in commit dd59896431 on Mar 17, 2025fjahr referenced this in commit cd1404164e on Mar 23, 2025hebasto referenced this in commit 017ff1c67c on May 8, 2025hebasto referenced this in commit c31fcaaad3 on May 13, 2025fanquake referenced this in commit 8309a9747a on May 13, 2025vmta referenced this in commit 3a0314c68f on May 22, 2025janus referenced this in commit 498ffcb50b on Sep 7, 2025mllwchrry referenced this in commit 0537991dc0 on Feb 17, 2026DarkWindman referenced this in commit a3a08909c5 on Feb 19, 2026DarkWindman referenced this in commit 92dfca3199 on Feb 19, 2026mllwchrry referenced this in commit ec343f0b2f on Feb 20, 2026real-or-random referenced this in commit 6e071d18ba on Feb 23, 2026github-actions[bot] referenced this in commit 758d4e90b4 on Mar 1, 2026github-actions[bot] referenced this in commit 68a2178f22 on Mar 1, 2026github-actions[bot] referenced this in commit a8bc1a0b2b on Mar 1, 20260x000000000019d6689c085ae165831e934ff76 referenced this in commit 3b9450150d on Mar 2, 2026csjones referenced this in commit a4d92824ae on Mar 2, 2026ContributorsLabels
github-metadata-mirror
This is a metadata mirror of the GitHub repository bitcoin-core/secp256k1. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-05-19 06:52 UTC
This is a metadata mirror of the GitHub repository bitcoin-core/secp256k1. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-05-19 06:52 UTC