Disallow automatic conversion between disparate hash types #17938

pull Empact wants to merge 8 commits into bitcoin:master from Empact:hash-conversion changing 11 files +122 −42
  1. Empact commented at 0:53 am on January 16, 2020: member

    This bases the script/standard hash types, TxDestination-related and CScriptID on a base template which does not silently convert the underlying uintN type.

    Inspired by and built on #17924. Commits are small and focused to ease review.

    Note some of these changes may be relative to existing bugs of the same sort as #17924. See particularly “Convert CPubKey to WitnessV0KeyHash directly” and “Remove an apparently unnecessary conversion”.

  2. DrahtBot commented at 2:54 am on January 16, 2020: member

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #19326 (Simplify hash.h interface using Spans by sipa)
    • #19183 ([WIP DONOTMERGE] Replace boost with C++17 by MarcoFalke)
    • #19114 (scripted-diff: TxoutType C++11 scoped enum class by MarcoFalke)
    • #16841 (Replace GetScriptForWitness with GetScriptForDestination by meshcollider)
    • #15294 ([moveonly] wallet: Extract RipeMd160 by Empact)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  3. DrahtBot added the label GUI on Jan 16, 2020
  4. DrahtBot added the label RPC/REST/ZMQ on Jan 16, 2020
  5. DrahtBot added the label Tests on Jan 16, 2020
  6. DrahtBot added the label Wallet on Jan 16, 2020
  7. instagibbs commented at 5:34 pm on January 16, 2020: member
    concept ACK, will review deeper if base is merged
  8. Empact force-pushed on Jan 16, 2020
  9. fanquake removed the label GUI on Jan 17, 2020
  10. fanquake removed the label Tests on Jan 17, 2020
  11. Sjors commented at 8:57 am on January 17, 2020: member
    Code review ACK 730267fd969cded98982b6c6762080dca2332939
  12. Empact commented at 6:05 pm on January 17, 2020: member
    @instagibbs rebased now that #17924 is merged
  13. Empact commented at 10:48 pm on January 29, 2020: member
    @instagibbs how about a review?
  14. laanwj commented at 2:08 pm on February 5, 2020: member
    Concept ACK, I like the idea of using explicit and separate types here to prevent non-sensible conversions, if you can use language features to avoid bugs that’s very good.
  15. Empact requested review from Sjors on Feb 6, 2020
  16. Empact requested review from ryanofsky on Feb 6, 2020
  17. Empact requested review from achow101 on Feb 6, 2020
  18. Empact requested review from instagibbs on Feb 6, 2020
  19. practicalswift commented at 6:46 am on February 11, 2020: contributor
    Concept ACK: explicit conversion is better (and safer!) than implicit conversion
  20. DrahtBot added the label Needs rebase on Feb 25, 2020
  21. Empact force-pushed on Feb 28, 2020
  22. DrahtBot removed the label Needs rebase on Feb 28, 2020
  23. Empact commented at 2:04 am on February 28, 2020: member
    Rebased, dropped one commit, as #17577 removed the relevant verifymessage conversion.
  24. DrahtBot added the label Needs rebase on Mar 9, 2020
  25. Empact force-pushed on Mar 10, 2020
  26. Empact commented at 11:56 am on March 10, 2020: member
    Rebased after merge of #18115
  27. Sjors commented at 1:31 pm on March 10, 2020: member
    Travis sad.
  28. DrahtBot removed the label Needs rebase on Mar 10, 2020
  29. Empact force-pushed on Mar 11, 2020
  30. laanwj commented at 4:00 pm on March 19, 2020: member
    ACK 4b7de7c402270388794203496728c4baa56c4877
  31. achow101 approved
  32. achow101 commented at 7:49 pm on June 11, 2020: member
    ACK 4b7de7c402270388794203496728c4baa56c4877
  33. meshcollider commented at 8:46 am on June 17, 2020: contributor
    Code review ACK 4b7de7c402270388794203496728c4baa56c4877
  34. meshcollider commented at 8:56 am on June 17, 2020: contributor

    There is a build error unfortunately

    0wallet/scriptpubkeyman.cpp:2054:25: error: no matching function for call to CKeyID::CKeyID(const PKHash&)
    1     CKeyID key_id(pkhash);
    2                         ^
    
  35. MarcoFalke added the label Waiting for author on Jun 17, 2020
  36. Empact force-pushed on Jun 18, 2020
  37. Empact commented at 10:38 pm on June 18, 2020: member

    Rebased, and the fix is in https://github.com/bitcoin/bitcoin/pull/17938/commits/1236555761b79c44f4bc9676260321b8c7095a6f

    I’m not sure what’s up with Appveyor, and I’m happy to squash.

  38. MarcoFalke commented at 11:47 am on June 19, 2020: member
    I think it makes sense to squash fixup commits that fix a compile-failure. Otherwise it is not possible to compile earlier commits.
  39. Prefer explicit uint160 conversion 0a5ea32ce6
  40. Prefer explicit CScriptID construction 3fcc468123
  41. Convert CPubKey to WitnessV0KeyHash directly
    The round-tripping through PKHash has no effect, and is
    potentially misleading as such.
    a9e451f144
  42. Use explicit conversion from PKHash -> CKeyID
    These types are equivalent, in data etc, so they need only their
    data cast across.
    
    Note a function is used rather than a casting
    operator as CKeyID is defined at a lower level than script/standard
    2c54217f91
  43. Use explicit conversion from WitnessV0KeyHash -> CKeyID
    These types are equivalent, in data etc, so they need only their
    data cast across.
    f32c1e07fd
  44. Explicitly support conversion between equivalent hash types
    ScriptHash <-> CScriptID
    CKeyID -> PKHash
    PKHash -> WitnessV0KeyHash
    966a22d859
  45. Remove an apparently unnecessary conversion
    CScript -> CScriptID -> ScriptHash is unnecessary because
    ScriptHash and CScriptID do the same thing.
    fa9ef2cdbe
  46. Disallow automatic conversion between hash types
    A templated BaseHash does not allow for automatic conversion, thus
    conversions much be explicitly allowed / whitelisted, which will
    reduce the risk of unintended conversions.
    4d7369125a
  47. Empact force-pushed on Jun 19, 2020
  48. Empact commented at 8:04 pm on June 19, 2020: member
    Squashed the fix and rebased.
  49. achow101 commented at 10:24 pm on June 19, 2020: member

    ACK 4d7369125a82214ea42b808a32b71b315a5c3c72

    Only change since last is to handle a newly introduced conversion. That’s also a good example of the benefits that this PR brings.

  50. meshcollider commented at 8:03 am on June 21, 2020: contributor
    re-utACK 4d7369125a82214ea42b808a32b71b315a5c3c72
  51. meshcollider merged this on Jun 21, 2020
  52. meshcollider closed this on Jun 21, 2020

  53. Empact deleted the branch on Jun 21, 2020
  54. Fabcien referenced this in commit 79bd38319d on Feb 3, 2021
  55. MarcoFalke removed the label Waiting for author on Apr 4, 2021
  56. 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: 2024-07-01 10:13 UTC

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