test: Fix SegwitV0SignatureMsg nLockTime signedness #29400

pull maflcko wants to merge 1 commits into bitcoin:master from maflcko:2402-test-fix-sign-3- changing 1 files +1 −1
  1. maflcko commented at 11:10 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/script/interpreter.cpp#L1611

    The bug was introduced when the code was written in 330b0f31ee5719d94f9e52dfc83c5d82168241f9.

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

  2. test: Fix SegwitV0SignatureMsg nLockTime signedness fab15723b0
  3. DrahtBot commented at 11:10 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, Eunovo, achow101

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

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #29401 (test: Remove struct.pack from almost all places by maflcko)

    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.

  4. DrahtBot added the label Tests on Feb 7, 2024
  5. maflcko commented at 11:13 am on February 7, 2024: member

    This can be tested by passing a transaction with a large locktime and then observing the error:

    0struct.error: 'i' format requires -2147483648 <= number <= 2147483647
    
  6. in test/functional/test_framework/script.py:750 in fab15723b0
    746@@ -747,7 +747,7 @@ def SegwitV0SignatureMsg(script, txTo, inIdx, hashtype, amount):
    747     ss += struct.pack("<q", amount)
    748     ss += struct.pack("<I", txTo.vin[inIdx].nSequence)
    749     ss += ser_uint256(hashOutputs)
    750-    ss += struct.pack("<i", txTo.nLockTime)
    751+    ss += txTo.nLockTime.to_bytes(4, "little")
    


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

    Could we keep the format?

    0    struct.pack("<I", txTo.nLockTime)
    

    In the instructions you’ve mentioned it’s reproducible - can you add a test that fails before this change, but passes after?


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

    Yes, you can try this with the following diff:

     0diff --git a/test/functional/p2p_segwit.py b/test/functional/p2p_segwit.py
     1index d316c4b602..708e4d7e8f 100755
     2--- a/test/functional/p2p_segwit.py
     3+++ b/test/functional/p2p_segwit.py
     4@@ -1663,6 +1663,7 @@ class SegWitTest(BitcoinTestFramework):
     5         pubkeyhash = hash160(pubkey)
     6         script_pkh = key_to_p2wpkh_script(pubkey)
     7         tx = CTransaction()
     8+        tx.nLockTime = 0xffffffff
     9         tx.vin.append(CTxIn(COutPoint(temp_utxos[0].sha256, temp_utxos[0].n), b""))
    10         tx.vout.append(CTxOut(temp_utxos[0].nValue, script_pkh))
    11         tx.wit.vtxinwit.append(CTxInWitness())
    

    To add a test, you may have to disable the locktime by setting the sequence number to the right value as well.

    I am happy to push a commit that adds a test, if someone writes one.


    Eunovo commented at 5:00 am on February 21, 2024:

    can you add a test that fails before this change, but passes after?

    Wouldn’t that mean that we added a test that tests the test-framework?


    maflcko commented at 8:13 am on February 21, 2024:

    can you add a test that fails before this change, but passes after?

    Wouldn’t that mean that we added a test that tests the test-framework?

    Yes, it should be possible to write an internal python unit test to check the behavior of SegwitV0SignatureMsg. An alternative would be to extend a python functional test to cover more values of nLockTime and compare the SegwitV0SignatureMsg behavior against Bitcoin Core via the RPC interface.

  7. epiccurious commented at 8:57 pm on February 7, 2024: none
    Tested ACK fab15723b0518acbb1015e64df47dcac0187e92f.
  8. epiccurious approved
  9. Eunovo commented at 4:59 am on February 21, 2024: none
    Tested ACK https://github.com/bitcoin/bitcoin/pull/29400/commits/fab15723b0518acbb1015e64df47dcac0187e92f Reproduced the error by setting nLockTime to 2147483648
  10. maflcko assigned achow101 on Feb 21, 2024
  11. achow101 commented at 6:05 pm on February 21, 2024: member
    ACK fab15723b0518acbb1015e64df47dcac0187e92f
  12. achow101 merged this on Feb 21, 2024
  13. achow101 closed this on Feb 21, 2024

  14. maflcko deleted the branch on Feb 22, 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