Repository navigation
Test: Add legacy script edge case spender test - #36455
benthecarman wants to merge 2 commits into
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. External sites
ReviewsSee the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsReviewers, this pull request conflicts with the following ones:
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. |
|
cc @instagibbs cc @marcofleon can you look at bitcoin-core/qa-assets#297. |
|
ACK fcfd8aa Though IIUC these will still be dropped on regeneration? |
Should these even go into the functional tests then? |
fcfd8aa to
660c159
Compare
I tested this and they don't.
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 |
|
|
||
| # == Legacy script edge cases == | ||
|
|
||
| # These cover script interpreter edge cases that other implementations have gotten wrong. |
There was a problem hiding this comment.
dont think we need this comment
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
left a comment
There was a problem hiding this comment.
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.
|
@benthecarman how do you want to proceed here? |
660c159 to
7989d32
Compare
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.
|
Moved the test infra out of the taproot specific stuff so we do this in a more clean way |
7989d32 to
d7e3279
Compare
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

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