Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/test/bip54_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Comment thread
darosior marked this conversation as resolved.
FILE* file = fsbridge::fopen(filename, "w");
fputs(json_str.c_str(), file);
fclose(file);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Copy link
Copy Markdown

@ariard ariard Mar 19, 2026

Choose a reason for hiding this comment

The 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",
Expand Down
3 changes: 2 additions & 1 deletion src/test/data/bip54_coinbases.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,5 @@
"valid": false,
"comment": "Block at height 4 with coinbase's nLockTime set to block's nTime minus 1 and maximum non-final nSequence."
}
]
]

3 changes: 2 additions & 1 deletion src/test/data/bip54_timestamps.json
Original file line number Diff line number Diff line change
Expand Up @@ -4130,4 +4130,5 @@
]
}
]
}
}

Loading