util: Refactor message hashing into a utility function #17557

pull jkczyz wants to merge 6 commits into bitcoin:master from jkczyz:2019-11-hash-message changing 21 files +128 −149
  1. jkczyz commented at 0:13 am on November 22, 2019: contributor

    The code used to produce a message hash when signing and verifying messages was repeated in a few locations. Additionally, the “magic” text used to prefix the message before hashing is unrelated to validation. Create a utility function for this code rather than spreading it across multiple files.

    For prior discussion, see #17399 (review).

    The topmost three commits are for this PR. The remaining are from #17399, which this is based on. Please review that before this PR.

  2. Refactor FormatStateMessage into ValidationState 7239d01b0f
  3. Remove ValidationState's constructor 74700371c8
  4. Templatize ValidationState instead of subclassing
    This removes boilerplate code in the subclasses which otherwise only
    differ by the result type.
    2948ebd29d
  5. Remove unused util/validation.h includes 38b1f7e9ed
  6. Refactor message hashing into a utility function
    The code used to produce a message hash when signing and verifying
    messages was repeated in a few locations. Additionally, the "magic" text
    used to prefix the message before hashing is unrelated to validation.
    Create a utility function for this code rather than spreading it across
    multiple files.
    ec9b0aad35
  7. Add a unit test for HashMessage
    The purpose of using a preamble or "magic" text as part of signing and
    verifying a message was not given when the code was repeated in a few
    locations. Make a test showing how it is used to prevent inadvertently
    signing a transaction.
    07531c35d6
  8. fanquake added the label Refactoring on Nov 22, 2019
  9. fanquake added the label Utils/log/libs on Nov 22, 2019
  10. DrahtBot commented at 0:41 am on November 22, 2019: 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:

    • #17624 (net: Fix an uninitialized read in ProcessMessage(…, “tx”, …) when receiving a transaction we already have by practicalswift)
    • #17577 (refactor: deduplicate the message sign/verify code by vasild)
    • #17485 (net processing: Don’t reach into CBlockIndex to check for block mutation by jnewbery)
    • #17479 (Return BlockValidationState from ProcessNewBlock if CheckBlock/AcceptBlock fails by jnewbery)
    • #16702 (p2p: supplying and using asmap to improve IP bucketing in addrman by naumenkogs)
    • #16688 (log: Add validation interface logging by jkczyz)
    • #16658 (validation: Rename CheckInputs to CheckInputScripts by jnewbery)
    • #15606 ([experimental] UTXO snapshots by jamesob)

    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.

  11. jkczyz commented at 6:10 pm on February 28, 2020: contributor
    Closing as this has been taken care of by #17577.
  12. jkczyz closed this on Feb 28, 2020

  13. DrahtBot locked this on Feb 15, 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-11-17 12:12 UTC

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