Test: Add legacy script edge case spender test #36455

pull benthecarman wants to merge 2 commits into bitcoin:master from benthecarman:taproot-legacy-edge-spenders changing 5 files +972 −800
  1. benthecarman commented at 7:18 PM on October 7, 2026: contributor

    Move the spender framework from feature_taproot.py to test_framework/spenders.py, and use it in a new feature_legacy_script.py test for script edge cases that other implementations have gotten wrong: CSV with -2, a 5-byte operand whose value fits in 1 byte, IFDUP on negative or non-minimal zero, ROLL with duplicate values, OP_16 in a P2SH scriptSig, and a P2SH scriptSig that leaves 1,000 items for the scriptPubKey to run on.

    The first commit is move-only. The new test supports --dumptests like feature_taproot.py, which is how the cases get into the script assets.

    These were discovered by finding gaps in alternate implementations (bitcoin-s and rbitcoin)

    Script assets: bitcoin-core/qa-assets#297

  2. DrahtBot added the label Tests on Oct 7, 2026
  3. DrahtBot commented at 7:19 PM on October 7, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    External sites

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process.

    Type Reviewers
    ACK instagibbs

    If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #36699 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36699.svg"></sub> (test: strengthen the tapscript CHECKMULTISIG asset tests and dump the expected error by azuchi)
    • #36466 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36466.svg"></sub> (policy: make unstructured Taproot annexes standard by RobinLinus)
    • #35793 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35793.svg"></sub> (Implement BIP 54 (Consensus Cleanup) without mainnet activation by darosior)
    • #29491 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/29491.svg"></sub> ([EXPERIMENTAL] Schnorr batch verification for blocks by fjahr)

    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.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  4. fanquake commented at 6:20 AM on October 16, 2026: member
  5. instagibbs commented at 1:11 PM on October 19, 2026: member

    ACK fcfd8aa09b482531b61c9481d169a54b66ea0cee

    Though IIUC these will still be dropped on regeneration?

  6. sedited commented at 1:28 PM on October 19, 2026: contributor

    Though IIUC these will still be dropped on regeneration?

    Should these even go into the functional tests then?

  7. benthecarman force-pushed on Oct 21, 2026
  8. benthecarman commented at 5:25 PM on October 21, 2026: contributor

    Though IIUC these will still be dropped on regeneration?

    I tested this and they don't.

    Should these even go into the functional tests then?

    Since they survive regeneration and add coverage, I don't see why not. The dumps are how they get into the script assets.

    I also moved the P2SH stack-size spender here from #36465, as you suggested there. I'll update qa-assets#297 as well

  9. in test/functional/feature_taproot.py:1261 in 660c159220
    1255 | @@ -1248,6 +1256,30 @@ def zero_fn(h):
    1256 |                  standard = hashtype in VALID_SIGHASHES_ECDSA and (p2sh or witv0)
    1257 |                  add_spender(spenders, "compat/nocsa", hashtype=hashtype, p2sh=p2sh, witv0=witv0, standard=standard, script=CScript([OP_IF, OP_11, pubkey1, OP_CHECKSIGADD, OP_12, OP_EQUAL, OP_ELSE, pubkey1, OP_CHECKSIG, OP_ENDIF]), key=eckey1, sigops_weight=4-3*witv0, inputs=[getter("sign"), b''], failure={"inputs": [getter("sign"), b'\x01']}, **ERR_BAD_OPCODE)
    1258 |  
    1259 | +    # == Legacy script edge cases ==
    1260 | +
    1261 | +    # These cover script interpreter edge cases that other implementations have gotten wrong.
    


    instagibbs commented at 5:29 PM on October 21, 2026:

    dont think we need this comment

  10. instagibbs approved
  11. instagibbs commented at 5:29 PM on October 21, 2026: member

    reACK 660c1592205fb80b258e9926db80575d5e7957ae

  12. fanquake referenced this in commit de96f3ae6d on Oct 21, 2026
  13. darosior commented at 3:31 PM on October 22, 2026: member

    Test coverage for surprising consensus-critical logic should take precedence, so not a blocker, but i dislike that this adds legacy-only cases to a test supposed to test Taproot logic. If we find the framework of this test is useful, which clearly is the case, then i think it should be exported to other non-Taproot specific tests. But also non-Taproot script test cases need less structure, so if you can just add those to script_tests.json & co as part of #36458 that's also a refactor we can punt down to another time.

  14. sedited commented at 9:08 PM on November 4, 2026: contributor

    @benthecarman how do you want to proceed here?

  15. benthecarman force-pushed on Nov 4, 2026
  16. benthecarman renamed this:
    Test: Add legacy script edge cases to taproot test
    Test: Add legacy script edge case spender test
    on Nov 4, 2026
  17. Test: Move spender framework out of feature_taproot
    Move the context signing framework, the spender helpers, and the
    test_spenders() runner from feature_taproot.py to a new
    test_framework/spenders.py module, so that tests other than the
    Taproot one can use them and dump script assets.
    
    The runner methods go in a SpenderTestMixin class, since the test
    framework's metaclass doesn't allow an intermediate subclass of
    BitcoinTestFramework.
    
    Move-only, apart from imports and the mixin declaration.
    5673572ca7
  18. Test: Add legacy script edge case spender test
    Add feature_legacy_script.py, which uses the spender framework for
    script edge cases that other implementations have gotten wrong: CSV
    with -2, a 5-byte operand whose value fits in 1 byte, IFDUP on
    negative or non-minimal zero, ROLL with duplicate values, OP_16 in a
    P2SH scriptSig, and a P2SH scriptSig that leaves 1,000 items for the
    scriptPubKey to run on.
    
    None of the current script assets catch an interpreter that gets
    these wrong. Like feature_taproot.py, the test can dump its cases
    with --dumptests, so list it in the script assets minimizer
    instructions.
    d7e3279392
  19. benthecarman commented at 9:33 PM on November 4, 2026: contributor

    Moved the test infra out of the taproot specific stuff so we do this in a more clean way

  20. benthecarman force-pushed on Nov 4, 2026
  21. sedited referenced this in commit d206226b49 on Nov 5, 2026

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: 2026-11-18 16:51 UTC

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