test: fix pushdata scripts #32270

pull instagibbs wants to merge 1 commits into bitcoin:master from instagibbs:2025-04-taproot_sample_fix changing 1 files +5 −5
  1. instagibbs commented at 7:11 pm on April 14, 2025: member

    The original scripts were done incorrectly, so they are changed to represent two different 2-byte pushes.

    Fixes #32114 (review)

  2. DrahtBot commented at 7:11 pm on April 14, 2025: contributor

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

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/32270.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK ajtowns, TheCharlatan
    Concept ACK rkrux

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

    Conflicts

    No conflicts as of last run.

  3. DrahtBot added the label Tests on Apr 14, 2025
  4. fanquake requested review from ajtowns on Apr 17, 2025
  5. in test/functional/feature_taproot.py:1244 in c679958eaf outdated
    1239@@ -1240,8 +1240,8 @@ def sample_spenders():
    1240     # Create a list of scripts which will be built into a taptree
    1241     scripts = [
    1242         # leaf label, followed by CScript
    1243-        ("encodeable_pushdata1", CScript([OP_DROP, OP_PUSHDATA1, b'aa' * 75])),
    1244-        ("nonstd_encodeable_pushdata1", CScript([OP_PUSHDATA1, b'aa'])),
    1245+        ("2byte_pushdata", CScript([OP_DROP, b'\xaa\xaa'])),
    1246+        ("nonstd_2byte_pushdata", CScript.fromhex("4c02aaaa")),
    


    rkrux commented at 7:08 pm on April 22, 2025:
    Shouldn’t this one be called nonstd_2byte_pushdata1 because it uses the PUSHDATA1 opcode? That’s what is mentioned in the comments of the previous PR and in the spender comment down below.

    rkrux commented at 7:09 pm on April 22, 2025:
    I’m guessing it’s intentional to have two different ways of creating CScript here? For better illustration.

    instagibbs commented at 8:20 pm on April 22, 2025:
    The python framework won’t let you construct a non-standard serialization natively, AFAIK. So we’re doing it manually.

    instagibbs commented at 8:21 pm on April 22, 2025:
    I was focusing on two different ways of pushing 2 bytes, not naming the specific opcode. If it would help legibility I can re-introduce the exact pushdata opcode name in use.

    rkrux commented at 10:53 am on April 23, 2025:
    This is fine but seeing pushdata1 in tutorial/nonminpushdata1 later in the spender comment seems unnecessary then.

    instagibbs commented at 1:36 pm on April 28, 2025:
    changed to push everywhere
  6. rkrux commented at 7:20 pm on April 22, 2025: contributor

    Concept ACK

    My bad I didn’t look at the scripts thoroughly in the previous PR and focussed more on the design of the examples.

    I debugged the scripts in the test and can indeed see the unintended script as described in this comment: #32114 (review)

    0('encodeable_pushdata1', CScript([OP_DROP, x('96616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161'), OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP, OP_NOP]))
    
  7. in test/functional/feature_taproot.py:1264 in c679958eaf outdated
    1262-    add_spender(spenders, comment="tutorial/pushdata1redux", tap=tap, leaf="encodeable_pushdata1", inputs=[b'\x00'], failure={"leaf": "dummyleaf"}, **ERR_NO_SUCCESS)
    1263+    add_spender(spenders, comment="tutorial/pushdataredux", tap=tap, leaf="2byte_pushdata", inputs=[b'\x00'], failure={"leaf": "dummyleaf"}, **ERR_NO_SUCCESS)
    1264 
    1265     # Spender that is non-standard but otherwise valid, with extraneous signature data from inner key for optional failure condition
    1266-    add_spender(spenders, comment="tutorial/nonminpushdata1", tap=tap, leaf="nonstd_encodeable_pushdata1", key=secs[0], standard=False, failure={"inputs": [getter("sign")]}, **ERR_CLEANSTACK)
    1267+    add_spender(spenders, comment="tutorial/nonminpushdata1", tap=tap, leaf="nonstd_2byte_pushdata", key=secs[0], standard=False, failure={"inputs": [getter("sign")]}, **ERR_CLEANSTACK)
    


    rkrux commented at 11:35 am on April 23, 2025:

    I don’t have a firm grasp on script execution yet (as I have not dealt with enough script execution) and there are few things going on inside the “test_spenders” as well that I have not gone through in its entirety. These seem like focussed test cases that I am trying to reason through.

    Are following the ways these 3 tapscript scenarios executed?

    1. During script execution, the empty string witness data is dropped because of “OP_DROP” and the 2 byte data is left on the stack. I’m assuming this 2 byte data counts as 1 stack item (because the stack is a vector of vector) and that’s why script execution doesn’t lead to an error in script execution? References based on a quick look:
    1. The “2byte_pushdata” leaf is overridden with the “dummyleaf”, and because there is no “OP_DROP” now, thus after the script execution, there is the empty string witness data left that leads to the “Script evaluated without error but finished with a false/empty top stack element” error. This shows that the emptiness of the witness data is crucial for this spender case but not so much for the first spender case because in it any witness data gets dropped due to the subsequent “OP_DROP” - I tested with “\x11” and that test case passed.

    2. The “nonstd_2byte_pushdata” leaf contains no “OP_DROP”, and thus after script execution, multiple items are left on the stack: a signature from the “secs[0]” key & the 2 byte data that leads to the “Stack size must be exactly one after execution” error.

  8. in test/functional/feature_taproot.py:1243 in c679958eaf outdated
    1239@@ -1240,8 +1240,8 @@ def sample_spenders():
    1240     # Create a list of scripts which will be built into a taptree
    1241     scripts = [
    1242         # leaf label, followed by CScript
    1243-        ("encodeable_pushdata1", CScript([OP_DROP, OP_PUSHDATA1, b'aa' * 75])),
    1244-        ("nonstd_encodeable_pushdata1", CScript([OP_PUSHDATA1, b'aa'])),
    1245+        ("2byte_pushdata", CScript([OP_DROP, b'\xaa\xaa'])),
    


    TheCharlatan commented at 9:19 am on April 24, 2025:
    Maybe call this just 2byte_push, since there is no pushdata going on here?

    instagibbs commented at 1:36 pm on April 28, 2025:
    done
  9. instagibbs force-pushed on Apr 28, 2025
  10. DrahtBot added the label CI failed on Apr 28, 2025
  11. DrahtBot removed the label CI failed on May 2, 2025
  12. DrahtBot added the label Needs rebase on May 6, 2025
  13. TheCharlatan commented at 1:53 pm on May 20, 2025: contributor
    Would ACK once rebased.
  14. test: fix pushdata scripts
    The original scripts were done incorrectly,
    so they are changed to represent two
    different 2-byte pushes.
    f66b14d2ec
  15. instagibbs force-pushed on May 20, 2025
  16. instagibbs commented at 2:39 pm on May 20, 2025: member
    @TheCharlatan rebased
  17. DrahtBot removed the label Needs rebase on May 20, 2025
  18. ajtowns commented at 4:09 pm on May 26, 2025: contributor
    ACK f66b14d2ecb0db991d255be49d6ff6ec361569b5
  19. DrahtBot requested review from rkrux on May 26, 2025
  20. DrahtBot requested review from TheCharlatan on May 26, 2025
  21. fanquake requested review from fjahr on May 27, 2025
  22. TheCharlatan approved
  23. TheCharlatan commented at 10:45 am on May 27, 2025: contributor
    Re-ACK f66b14d2ecb0db991d255be49d6ff6ec361569b5
  24. fanquake merged this on May 27, 2025
  25. fanquake closed this on May 27, 2025


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: 2025-06-15 09:13 UTC

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