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
  1. theStack commented at 5:28 PM on December 2, 2024: contributor

    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.

  2. 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.
    1823594761
  3. real-or-random added the label assurance on Dec 2, 2024
  4. real-or-random added the label refactor/smell on Dec 2, 2024
  5. 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.

  6. real-or-random approved
  7. real-or-random commented at 8:30 AM on December 9, 2024: contributor

    utACK 1823594761046ae38e002781d65e9538dd211d27

  8. stratospher commented at 8:38 AM on February 24, 2025: contributor

    ACK 1823594. Got tests failures when passing public API flags to secp256k1_eckey_pubkey_serialize.

  9. real-or-random merged this on Feb 24, 2025
  10. real-or-random closed this on Feb 24, 2025

  11. hebasto referenced this in commit 0ee5708432 on Mar 10, 2025
  12. hebasto referenced this in commit dd59896431 on Mar 17, 2025
  13. fjahr referenced this in commit cd1404164e on Mar 23, 2025
  14. hebasto referenced this in commit 017ff1c67c on May 8, 2025
  15. hebasto referenced this in commit c31fcaaad3 on May 13, 2025
  16. fanquake referenced this in commit 8309a9747a on May 13, 2025
  17. vmta referenced this in commit 3a0314c68f on May 22, 2025
  18. janus referenced this in commit 498ffcb50b on Sep 7, 2025
  19. mllwchrry referenced this in commit 0537991dc0 on Feb 17, 2026
  20. DarkWindman referenced this in commit a3a08909c5 on Feb 19, 2026
  21. DarkWindman referenced this in commit 92dfca3199 on Feb 19, 2026
  22. mllwchrry referenced this in commit ec343f0b2f on Feb 20, 2026
  23. real-or-random referenced this in commit 6e071d18ba on Feb 23, 2026
  24. github-actions[bot] referenced this in commit 758d4e90b4 on Mar 1, 2026
  25. github-actions[bot] referenced this in commit 68a2178f22 on Mar 1, 2026
  26. github-actions[bot] referenced this in commit a8bc1a0b2b on Mar 1, 2026
  27. 0x000000000019d6689c085ae165831e934ff76 referenced this in commit 3b9450150d on Mar 2, 2026
  28. csjones referenced this in commit a4d92824ae on Mar 2, 2026

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