forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 9
A couple improvements to BIP 54 test vectors #110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ajtowns
merged 4 commits into
bitcoin-inquisition:29.x
from
darosior:2603_inquisition_bip54_tests_improvements
May 7, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
9b4962f
qa: add newline at EOF when generating BIP 54 test vectors
darosior f329627
qa: correct typos in BIP 54 test vectors
darosior 27957d2
qa: add a Taproot-annex case to BIP 54 txsize test vectors
darosior fc24db4
qa: add newline at EOF in BIP 54 json test vectors
darosior File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,7 +53,8 @@ static void WriteJSONTestVectors(const std::vector<T>& test_vectors, std::string | |
| for (const auto& test_vector: test_vectors) { | ||
| json_vectors.push_back(test_vector.GetJson()); | ||
| } | ||
| const auto json_str{json_vectors.write(4)}; | ||
| auto json_str{json_vectors.write(4)}; | ||
| json_str += '\n'; | ||
| FILE* file = fsbridge::fopen(filename, "w"); | ||
| fputs(json_str.c_str(), file); | ||
| fclose(file); | ||
|
|
@@ -860,7 +861,7 @@ BOOST_AUTO_TEST_CASE(bip54_legacy_sigops) | |
| tx_copy2.vin[idx].scriptSig << OP_0 << sig << ToByteVector(redeem_script); | ||
| BOOST_REQUIRE(VerifyTxin(spk, tx_copy2, idx)); | ||
|
|
||
| CheckExceedsBIP54Limits(CTransaction(tx_copy2), coins, test_vectors, "Mixed input types reaching exactly 2500 BIP54-sigops + a P2SH input with 1-of-1 CHECMULTISIG"); | ||
| CheckExceedsBIP54Limits(CTransaction(tx_copy2), coins, test_vectors, "Mixed input types reaching exactly 2500 BIP54-sigops + a P2SH input with 1-of-1 CHECKMULTISIG"); | ||
| } | ||
|
|
||
| // Adding an input spending an invalid Script but containing a CHECKSIG will | ||
|
|
@@ -1249,7 +1250,7 @@ BOOST_AUTO_TEST_CASE(bip54_legacy_sigops) | |
| tx2.vin.emplace_back(tx_create.GetHash(), 0); | ||
|
|
||
| // CheckSigopsBIP54 will return false because there is 126 CMS that account for 20 each. | ||
| CheckExceedsBIP54Limits(CTransaction(tx2), coins, test_vectors, "Invalid bare script with 126 CHECMULTISIGs each accounted for 20 BIP54-sigops"); | ||
| CheckExceedsBIP54Limits(CTransaction(tx2), coins, test_vectors, "Invalid bare script with 126 CHECKMULTISIGs each accounted for 20 BIP54-sigops"); | ||
| } | ||
|
|
||
| // Note this is also a limitation for legitimate Scripts, for instance if the arguments to | ||
|
|
@@ -1560,6 +1561,18 @@ BOOST_AUTO_TEST_CASE(bip54_txsize) | |
| RecordTestCase(test_vectors, CTransaction{tx_copy}, /*valid=*/false, "A 64-byte Segwit transaction (1 p2tr input, 1 p2a output)."); | ||
| } | ||
|
|
||
| // A semi-realistic 64-byte transaction: 1 Taproot input with an annex, 1 OP_RETURN output. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe a test case for a segwit v2+ to verify the validity is not changed by the novel BIP54 checks. ofc, no reason why it would change anything for v2 - v16. don’t remember if there is already another test case for it elsewhere. |
||
| { | ||
| CMutableTransaction tx_copy{tx}; | ||
| tx_copy.vout.back().scriptPubKey << OP_RETURN << "ab01"_hex_v; | ||
| auto sig{"5a78b5a14a2527feb02c08b8124e74c3b9bcc1bd3dba1fbfa87f1c930f28a46fea2bf375105dfd835e212c9127aad4976c46ef86be02edbb681e6f38f9a9e06f01"_hex_v_u8}; | ||
| tx_copy.vin.back().scriptWitness.stack.emplace_back(std::move(sig)); | ||
| auto annex{"4242ffab2121"_hex_v_u8}; | ||
| tx_copy.vin.back().scriptWitness.stack.emplace_back(std::move(annex)); | ||
| Assert(GetSerializeSize(TX_NO_WITNESS(tx_copy)) == INVALID_TX_NONWITNESS_SIZE); | ||
| RecordTestCase(test_vectors, CTransaction{tx_copy}, /*valid=*/false, "A 64-byte Segwit transaction (1 p2tr input with annex, 1 OP_RETURN output)."); | ||
| } | ||
|
|
||
| // Historical 64-byte transactions. Taken from Chris Stewart's BIP53. | ||
| constexpr std::string_view historical_txs_hex[]{ | ||
| "0200000001deb98691723fa71260ffca6ea0a7bc0a63b0a8a366e1b585caad47fb269a2ce401000000030251b201000000010000000000000000016a00000000", | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4130,4 +4130,5 @@ | |
| ] | ||
| } | ||
| ] | ||
| } | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.