test: Fix utxo set hash serialisation signedness #29399

pull maflcko wants to merge 1 commits into bitcoin:master from maflcko:2402-test-fix-sign-2- changing 1 files +1 −3
  1. maflcko commented at 10:51 am on February 7, 2024: member

    It is unsigned in Bitcoin Core, so the tests should match it:

    https://github.com/bitcoin/bitcoin/blob/5b8990a1f3c49b0b02b7383c69e95320acbda13e/src/kernel/coinstats.cpp#L54

    Large positive values for the block height are too difficult to hit in tests, but it still seems fine to fix this.

    The bug was introduced when the code was written in 6ccc8fc067bf516cda7bc5d7d721945be5ac2003.

    (Lowercase i means signed, see https://docs.python.org/3/library/struct.html#format-characters)

  2. test: Fix utxo set hash serialisation signedness fa0ceae970
  3. DrahtBot commented at 10:51 am on February 7, 2024: contributor

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

    Code Coverage

    For detailed information about the code coverage, see the test coverage report.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK epiccurious, fjahr

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

  4. DrahtBot added the label Tests on Feb 7, 2024
  5. maflcko requested review from fjahr on Feb 7, 2024
  6. in test/functional/feature_utxo_set_hash.py:59 in fa0ceae970
    55@@ -58,7 +56,7 @@ def test_muhash_implementation(self):
    56                         continue
    57 
    58                     data = COutPoint(int(tx.rehash(), 16), n).serialize()
    59-                    data += struct.pack("<i", height * 2 + coinbase)
    60+                    data += (height * 2 + coinbase).to_bytes(4, "little")
    


    paplorinc commented at 11:13 am on February 7, 2024:

    I’m just looking around, I’m not a Bitcoin core expert. My understanding is that the unsigned little endian is <I, wouldn’t it make sense to change as little as possible here:

    0                    data += struct.pack("<I", height * 2 + coinbase)
    

    or if we want to mimic the C++ code:

    0                    data = struct.pack('<I', (height << 1) + coinbase)
    

    maflcko commented at 11:18 am on February 7, 2024:

    wouldn’t it make sense to change as little as possible here:

    No. struct.pack is brittle and confusing. Just look at all the bugs: #29400, #29399, #29363, fa3886b7c69cbbe564478f30bb2c35e9e6b1cffa, …

    Thus, struct.pack should be removed from all tests to avoid more bugs in the future.


    maflcko commented at 2:36 pm on February 9, 2024:
  7. in test/functional/feature_utxo_set_hash.py:61 in fa0ceae970
    55@@ -58,7 +56,7 @@ def test_muhash_implementation(self):
    56                         continue
    57 
    58                     data = COutPoint(int(tx.rehash(), 16), n).serialize()
    59-                    data += struct.pack("<i", height * 2 + coinbase)
    


    paplorinc commented at 11:16 am on February 7, 2024:
    if possible, can you cover it with a test that reproduces the error before this fix - and passes after it?

    maflcko commented at 11:19 am on February 7, 2024:
    No, Large positive values for the block height are too difficult to hit in tests, but it still seems fine to fix this.
  8. epiccurious commented at 3:55 pm on February 7, 2024: none
    Tested ACK fa0ceae970242d8d6bdef150c98f04c67b06e20c.
  9. epiccurious approved
  10. fjahr commented at 4:59 pm on February 9, 2024: contributor
    utACK fa0ceae970242d8d6bdef150c98f04c67b06e20c
  11. DrahtBot removed review request from fjahr on Feb 9, 2024
  12. maflcko commented at 7:58 am on February 12, 2024: member
    rfm? :)
  13. fanquake merged this on Feb 12, 2024
  14. fanquake closed this on Feb 12, 2024

  15. maflcko deleted the branch on Feb 12, 2024

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-03 07:12 UTC

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