pubkey: Assert CPubKey's ECCVerifyHandle precondition #17275

pull practicalswift wants to merge 1 commits into bitcoin:master from practicalswift:assert-CPubKey-preconditions changing 1 files +6 −0
  1. practicalswift commented at 9:50 PM on October 27, 2019: contributor

    Assert CPubKey's ECCVerifyHandle precondition.

    This makes it more clear for fuzzing harness writers and others that ECCVerifyHandle is expected to be held when interacting with CPubKey.

    Related PR #17274.

  2. fanquake requested review from sipa on Oct 27, 2019
  3. laanwj commented at 10:06 AM on October 28, 2019: member

    Concept ACK, I think the "Users of this module must hold an ECCVerifyHandle." message is unclear, doesn't provide context. what about a more direct "secp256k1_context_verify must be initialized to use CPubKey"

  4. laanwj added the label Tests on Oct 28, 2019
  5. fanquake added the label Waiting for author on Oct 28, 2019
  6. pubkey: Assert CPubKey's ECCVerifyHandle precondition d8daa8f371
  7. practicalswift force-pushed on Oct 28, 2019
  8. practicalswift commented at 3:10 PM on October 28, 2019: contributor

    @laanwj

    I've now changed to the suggested wording.

    The old wording was taken from here:

    https://github.com/bitcoin/bitcoin/blob/773026044f9d87462de4809fbb339e42c52d0a76/src/pubkey.h#L227-L227

    Please re-review :)

  9. practicalswift commented at 11:44 PM on October 29, 2019: contributor

    @fanquake No longer waiting for author? :)

  10. fanquake removed the label Waiting for author on Oct 30, 2019
  11. practicalswift commented at 9:25 AM on November 14, 2019: contributor

    @laanwj Would you mind reviewing? :)

  12. practicalswift commented at 6:06 PM on December 6, 2019: contributor

    I think it would be good to have these assertions in.

    Without these it is possible for someone to mess up and have a NULL secp256k1_context_verify passed to the secp256k1-functions (by forgetting the ECCVerifyHandle pre-conditiion).

    Consider the following example:

    bool CPubKey::IsFullyValid() const {
        if (!IsValid())
            return false;
        secp256k1_pubkey pubkey;
        return secp256k1_ec_pubkey_parse(secp256k1_context_verify, &pubkey, vch, size());
    }
    

    That function will return also in cases where secp256k1_context_verify == nullptr.

    I think it would be good to guard against those sharp edges by adding the suggested assertions :)

    In this case:

    bool CPubKey::IsFullyValid() const {
        if (!IsValid())
            return false;
        secp256k1_pubkey pubkey;
        assert(secp256k1_context_verify && "secp256k1_context_verify must be initialized to use CPubKey.");
        return secp256k1_ec_pubkey_parse(secp256k1_context_verify, &pubkey, vch, size());
    }
    
  13. sipa approved
  14. sipa commented at 6:22 PM on December 6, 2019: member

    ACK d8daa8f3711909223b117b8faa82daca87fc942d

  15. MarcoFalke referenced this in commit da1af855f9 on Dec 6, 2019
  16. MarcoFalke merged this on Dec 6, 2019
  17. MarcoFalke closed this on Dec 6, 2019

  18. sidhujag referenced this in commit ac4deea33b on Dec 6, 2019
  19. jasonbcox referenced this in commit 0948e1d200 on Nov 6, 2020
  20. sidhujag referenced this in commit ff5075ef31 on Nov 10, 2020
  21. practicalswift deleted the branch on Apr 10, 2021
  22. PastaPastaPasta referenced this in commit 58e61ac7ee on Jun 27, 2021
  23. PastaPastaPasta referenced this in commit 930a04b5d8 on Jun 28, 2021
  24. PastaPastaPasta referenced this in commit f404eadf02 on Jun 29, 2021
  25. PastaPastaPasta referenced this in commit c7808dcc9e on Jul 1, 2021
  26. PastaPastaPasta referenced this in commit 4b12666027 on Jul 1, 2021
  27. PastaPastaPasta referenced this in commit e3810c3f2e on Jul 14, 2021
  28. PastaPastaPasta referenced this in commit 0045bdd257 on Jul 14, 2021
  29. PastaPastaPasta referenced this in commit 65bac012ff on Jul 15, 2021
  30. DrahtBot locked this on Aug 18, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-16 00:14 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me