Skip to content

Test: Add legacy script edge case spender test - #36455

Open
benthecarman wants to merge 2 commits into
bitcoin:masterfrom
benthecarman:taproot-legacy-edge-spenders
Open

benthecarman wants to merge 2 commits into
bitcoin:masterfrom
benthecarman:taproot-legacy-edge-spenders

Conversation

@benthecarman

@benthecarman benthecarman commented Oct 7, 2026 •

Copy link
Copy Markdown
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

@DrahtBot DrahtBot added the Tests label Oct 7, 2026
@DrahtBot

DrahtBot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

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

External sites

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 <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #36990 (test: replace hard-coded RPC error codes by l0rinc)
  • #36699 (test: strengthen the tapscript CHECKMULTISIG asset tests and dump the expected error by azuchi)
  • #35793 (Implement BIP 54 (Consensus Cleanup) without mainnet activation by darosior)
  • #29491 ([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.

@fanquake

Copy link
Copy Markdown
Member

cc @instagibbs

cc @marcofleon can you look at bitcoin-core/qa-assets#297.

@instagibbs

Copy link
Copy Markdown
Member

ACK fcfd8aa

Though IIUC these will still be dropped on regeneration?

@sedited

sedited commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

Though IIUC these will still be dropped on regeneration?

Should these even go into the functional tests then?

@benthecarman
benthecarman force-pushed the taproot-legacy-edge-spenders branch from fcfd8aa to 660c159 Compare October 21, 2026 17:21
@benthecarman

Copy link
Copy Markdown
Contributor Author

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

@instagibbs instagibbs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reACK 660c159

Comment thread test/functional/feature_taproot.py Outdated

# == Legacy script edge cases ==

# These cover script interpreter edge cases that other implementations have gotten wrong.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dont think we need this comment

fanquake added a commit that referenced this pull request Oct 21, 2026
5a4cd70 Test: Add P2SH scriptSig stack-size boundary tests (benthecarman)

Pull request description:

  VerifyScript runs a P2SH scriptPubKey on the stack the scriptSig leaves before handling the redeemScript. The 20-byte push in HASH160 <20> EQUAL adds one item, so a scriptSig that leaves 1,000 items fails with STACK_SIZE, while 999 items is valid.

  An implementation that checks the redeemScript hash without running the scriptPubKey accepts the 1,000-item spend. No existing vector leaves the scriptSig at this boundary, so such an implementation can pass every row.

  Add 999 and 1,000 item cases with P2SH and WITNESS, and the 1,000 item case with no flags, which fails the same way because the scriptPubKey always runs. Also add the same boundary during redeemScript evaluation, where the restored stack plus the redeemScript's pushes reach 1,000 and 1,001 items.

  The same case is added as a feature_taproot spender in #36455, so its dump can be added to the script assets (bitcoin-core/qa-assets#297).

  These were discovered by finding gaps in an alternate implementation (rbitcoin)

ACKs for top commit:
  ekzyis:
    ACK 5a4cd70
  instagibbs:
    ACK 5a4cd70

Tree-SHA512: 05a8dc547e109daf346a63ad450a26870a4ee158a251eb2c08ba643d48225373e4744ab3dc5c5debfa112e94516d505c563807a8381224b98a0dc348adf389f8

@darosior darosior left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@sedited

sedited commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

@benthecarman how do you want to proceed here?

@benthecarman
benthecarman force-pushed the taproot-legacy-edge-spenders branch from 660c159 to 7989d32 Compare November 4, 2026 21:32
@benthecarman benthecarman changed the title Test: Add legacy script edge cases to taproot test Test: Add legacy script edge case spender test Nov 4, 2026
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.
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.
@benthecarman

Copy link
Copy Markdown
Contributor Author

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

@benthecarman
benthecarman force-pushed the taproot-legacy-edge-spenders branch from 7989d32 to d7e3279 Compare November 4, 2026 21:35
sedited added a commit that referenced this pull request Nov 5, 2026
5d2fb8d Test: Add script vectors for interpreter edges (benthecarman)

Pull request description:

  Add script_tests.json and tx_invalid.json vectors for edge cases that
  other implementations have gotten wrong, including CSV with -2, IFDUP
  on negative zero, ROLL with duplicate values, a taproot output key
  that is not a valid x coordinate, and single-flag STRICTENC, LOW_S and
  NULLFAIL cases.

  Some policy cases were only caught by the tx_valid harness adding
  flags back, which implementations copying the JSON don't replicate.

  Related: #36455

  These were discovered by finding gaps in an alternate implementation (bitcoin-s)

ACKs for top commit:
  darosior:
    ACK 5d2fb8d
  sedited:
    LGTM ACK 5d2fb8d, but waiting on resolution here: #36455 (review)

Tree-SHA512: 7c3d1b40fbb4436637ff82d71faa6df7d0349307bb85c37f127be6dee8ec045f46081963a20d8bd03c97c6af02d8c90e1a19123c1bf7bc801dfb8a4843a62af1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants