5#include <test/data/tx_invalid.json.h>
6#include <test/data/tx_valid.json.h>
43#include <boost/test/unit_test.hpp>
51typedef std::vector<unsigned char>
valtype;
61 if (strFlags.empty() || strFlags ==
"NONE")
return flags;
63 std::vector<std::string> words =
SplitString(strFlags,
',');
64 for (
const std::string& word : words)
67 BOOST_ERROR(
"Bad test: unknown verification flag '" << word <<
"'");
80 standard_flags_missing &= ~(pair.second);
82 return standard_flags_missing == 0;
94 for (
unsigned int i = 0; i < tx.
vin.size() && tx_valid; ++i) {
96 const CAmount amount = map_prevout_values.contains(input.
prevout) ? map_prevout_values.at(input.
prevout) : 0;
101 BOOST_ERROR(
"Bad test: " << strTest);
105 BOOST_CHECK_MESSAGE(tx_valid, strTest);
111 BOOST_CHECK_MESSAGE(!tx_valid, strTest);
114 return (tx_valid == expect_valid);
151 std::set<script_verify_flags> flags_combos;
154 if (
flags != flags_excluding_one) {
155 flags_combos.insert(flags_excluding_one);
165 BOOST_CHECK_MESSAGE(
CheckMapFlagNames(),
"mapFlagNames is missing a script verification flag");
169 for (
unsigned int idx = 0; idx <
tests.size(); idx++) {
171 std::string strTest = test.
write();
172 if (test[0].isArray())
176 BOOST_ERROR(
"Bad test: " << strTest);
180 std::map<COutPoint, CScript> mapprevOutScriptPubKeys;
181 std::map<COutPoint, int64_t> mapprevOutValues;
184 for (
unsigned int inpIdx = 0; inpIdx < inputs.
size(); inpIdx++) {
185 const UniValue& input = inputs[inpIdx];
191 if (vinput.
size() < 3 || vinput.
size() > 4)
197 mapprevOutScriptPubKeys[outpoint] =
ParseScript(vinput[2].get_str());
198 if (vinput.
size() >= 4)
200 mapprevOutValues[outpoint] = vinput[3].
getInt<int64_t>();
205 BOOST_ERROR(
"Bad test: " << strTest);
209 std::string transaction = test[1].
get_str();
221 if (~verify_flags !=
FillFlags(~verify_flags)) {
222 BOOST_ERROR(
"Bad test flags: " << strTest);
225 BOOST_CHECK_MESSAGE(
CheckTxScripts(tx, mapprevOutScriptPubKeys, mapprevOutValues, ~verify_flags, txdata, strTest,
true),
226 "Tx unexpectedly failed: " << strTest);
232 if (!
CheckTxScripts(tx, mapprevOutScriptPubKeys, mapprevOutValues,
flags, txdata, strTest,
true)) {
233 BOOST_ERROR(
"Tx unexpectedly failed with flag " <<
name <<
" unset: " << strTest);
237 if (!
CheckTxScripts(tx, mapprevOutScriptPubKeys, mapprevOutValues,
flags, txdata, strTest,
true)) {
238 BOOST_ERROR(
"Tx unexpectedly failed with random flags " <<
ToString(
flags.as_int()) <<
": " << strTest);
244 if (!
CheckTxScripts(tx, mapprevOutScriptPubKeys, mapprevOutValues, ~flags_excluding_one, txdata, strTest,
false)) {
245 BOOST_ERROR(
"Too many flags unset: " << strTest);
257 for (
unsigned int idx = 0; idx <
tests.size(); idx++) {
259 std::string strTest = test.
write();
260 if (test[0].isArray())
264 BOOST_ERROR(
"Bad test: " << strTest);
268 std::map<COutPoint, CScript> mapprevOutScriptPubKeys;
269 std::map<COutPoint, int64_t> mapprevOutValues;
272 for (
unsigned int inpIdx = 0; inpIdx < inputs.
size(); inpIdx++) {
273 const UniValue& input = inputs[inpIdx];
279 if (vinput.
size() < 3 || vinput.
size() > 4)
285 mapprevOutScriptPubKeys[outpoint] =
ParseScript(vinput[2].get_str());
286 if (vinput.
size() >= 4)
288 mapprevOutValues[outpoint] = vinput[3].
getInt<int64_t>();
293 BOOST_ERROR(
"Bad test: " << strTest);
297 std::string transaction = test[1].
get_str();
303 BOOST_CHECK_MESSAGE(test[2].get_str() ==
"BADTX", strTest);
311 if (verify_flags !=
FillFlags(verify_flags)) {
312 BOOST_ERROR(
"Bad test flags: " << strTest);
316 BOOST_CHECK_MESSAGE(
CheckTxScripts(tx, mapprevOutScriptPubKeys, mapprevOutValues, verify_flags, txdata, strTest,
false),
317 "Tx unexpectedly passed: " << strTest);
323 if (!
CheckTxScripts(tx, mapprevOutScriptPubKeys, mapprevOutValues,
flags, txdata, strTest,
false)) {
324 BOOST_ERROR(
"Tx unexpectedly passed with flag " <<
name <<
" set: " << strTest);
328 if (!
CheckTxScripts(tx, mapprevOutScriptPubKeys, mapprevOutValues,
flags, txdata, strTest,
false)) {
329 BOOST_ERROR(
"Tx unexpectedly passed with random flags " <<
name <<
": " << strTest);
335 if (!
CheckTxScripts(tx, mapprevOutScriptPubKeys, mapprevOutValues, flags_excluding_one, txdata, strTest,
true)) {
336 BOOST_ERROR(
"Too many flags set: " << strTest);
354 auto createTransaction =[](
size_t payloadSize) {
357 tx.
vout.emplace_back(1,
CScript() << OP_RETURN << std::vector<unsigned char>(payloadSize));
363 auto maxPayloadSize = maxTransactionSize - oversizedTransactionBaseSize;
373 BOOST_CHECK_MESSAGE(!
CheckTransaction(createTransaction(maxPayloadSize), state),
"Oversized transaction should be invalid");
381 unsigned char ch[] = {0x01, 0x00, 0x00, 0x00, 0x01, 0x6b, 0xff, 0x7f, 0xcd, 0x4f, 0x85, 0x65, 0xef, 0x40, 0x6d, 0xd5, 0xd6, 0x3d, 0x4f, 0xf9, 0x4f, 0x31, 0x8f, 0xe8, 0x20, 0x27, 0xfd, 0x4d, 0xc4, 0x51, 0xb0, 0x44, 0x74, 0x01, 0x9f, 0x74, 0xb4, 0x00, 0x00, 0x00, 0x00, 0x8c, 0x49, 0x30, 0x46, 0x02, 0x21, 0x00, 0xda, 0x0d, 0xc6, 0xae, 0xce, 0xfe, 0x1e, 0x06, 0xef, 0xdf, 0x05, 0x77, 0x37, 0x57, 0xde, 0xb1, 0x68, 0x82, 0x09, 0x30, 0xe3, 0xb0, 0xd0, 0x3f, 0x46, 0xf5, 0xfc, 0xf1, 0x50, 0xbf, 0x99, 0x0c, 0x02, 0x21, 0x00, 0xd2, 0x5b, 0x5c, 0x87, 0x04, 0x00, 0x76, 0xe4, 0xf2, 0x53, 0xf8, 0x26, 0x2e, 0x76, 0x3e, 0x2d, 0xd5, 0x1e, 0x7f, 0xf0, 0xbe, 0x15, 0x77, 0x27, 0xc4, 0xbc, 0x42, 0x80, 0x7f, 0x17, 0xbd, 0x39, 0x01, 0x41, 0x04, 0xe6, 0xc2, 0x6e, 0xf6, 0x7d, 0xc6, 0x10, 0xd2, 0xcd, 0x19, 0x24, 0x84, 0x78, 0x9a, 0x6c, 0xf9, 0xae, 0xa9, 0x93, 0x0b, 0x94, 0x4b, 0x7e, 0x2d, 0xb5, 0x34, 0x2b, 0x9d, 0x9e, 0x5b, 0x9f, 0xf7, 0x9a, 0xff, 0x9a, 0x2e, 0xe1, 0x97, 0x8d, 0xd7, 0xfd, 0x01, 0xdf, 0xc5, 0x22, 0xee, 0x02, 0x28, 0x3d, 0x3b, 0x06, 0xa9, 0xd0, 0x3a, 0xcf, 0x80, 0x96, 0x96, 0x8d, 0x7d, 0xbb, 0x0f, 0x91, 0x78, 0xff, 0xff, 0xff, 0xff, 0x02, 0x8b, 0xa7, 0x94, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x19, 0x76, 0xa9, 0x14, 0xba, 0xde, 0xec, 0xfd, 0xef, 0x05, 0x07, 0x24, 0x7f, 0xc8, 0xf7, 0x42, 0x41, 0xd7, 0x3b, 0xc0, 0x39, 0x97, 0x2d, 0x7b, 0x88, 0xac, 0x40, 0x94, 0xa8, 0x02, 0x00, 0x00, 0x00, 0x00, 0x19, 0x76, 0xa9, 0x14, 0xc1, 0x09, 0x32, 0x48, 0x3f, 0xec, 0x93, 0xed, 0x51, 0xf5, 0xfe, 0x95, 0xe7, 0x25, 0x59, 0xf2, 0xcc, 0x70, 0x43, 0xf9, 0x88, 0xac, 0x00, 0x00, 0x00, 0x00, 0x00};
382 std::vector<unsigned char> vch(ch, ch +
sizeof(ch) -1);
387 BOOST_CHECK_MESSAGE(state.
IsValid(),
"Simple deserialized transaction should be valid.");
390 tx.
vin.push_back(tx.
vin[0]);
398 std::vector<CMutableTransaction> dummyTransactions =
403 t1.vin[0].prevout.hash = dummyTransactions[0].GetHash();
404 t1.vin[0].prevout.n = 1;
405 t1.vin[0].scriptSig << std::vector<unsigned char>(65, 0);
406 t1.vin[1].prevout.hash = dummyTransactions[1].GetHash();
407 t1.vin[1].prevout.n = 0;
408 t1.vin[1].scriptSig << std::vector<unsigned char>(65, 0) << std::vector<unsigned char>(33, 4);
409 t1.vin[2].prevout.hash = dummyTransactions[1].GetHash();
410 t1.vin[2].prevout.n = 1;
411 t1.vin[2].scriptSig << std::vector<unsigned char>(65, 0) << std::vector<unsigned char>(33, 4);
413 t1.vout[0].nValue = 90*
CENT;
414 t1.vout[0].scriptPubKey <<
OP_1;
423 outputm.
vin.resize(1);
424 outputm.
vin[0].prevout.SetNull();
426 outputm.
vout.resize(1);
427 outputm.
vout[0].nValue = 1;
428 outputm.
vout[0].scriptPubKey = outscript;
432 assert(output->vin.size() == 1);
433 assert(output->vin[0] == outputm.
vin[0]);
434 assert(output->vout.size() == 1);
439 inputm.
vin.resize(1);
440 inputm.
vin[0].prevout.hash = output->GetHash();
441 inputm.
vin[0].prevout.n = 0;
442 inputm.
vout.resize(1);
443 inputm.
vout[0].nValue = 1;
455 assert(input.
vin[0].scriptWitness.stack == inputm.
vin[0].scriptWitness.stack);
472 }
else if (v.size() == 1 && v[0] >= 1 && v[0] <= 16) {
474 }
else if (v.size() == 1 && v[0] == 0x81) {
485 std::vector<valtype> stack;
488 stack.back() = std::vector<unsigned char>(redeemScript.
begin(), redeemScript.
end());
503 std::vector<int> sigHashes;
512 for(uint32_t ij = 0; ij < 4500; ij++) {
513 uint32_t i = mtx.
vin.size();
514 COutPoint outpoint{
Txid{
"0000000000000000000000000000000000000000000000000000000000000100"}, i};
516 mtx.
vin.resize(mtx.
vin.size() + 1);
517 mtx.
vin[i].prevout = outpoint;
520 mtx.
vout.resize(mtx.
vout.size() + 1);
521 mtx.
vout[i].nValue = 1000;
526 for(uint32_t i = 0; i < mtx.
vin.size(); i++) {
528 bool hashSigned =
SignSignature(keystore, scriptPubKey, mtx, i, 1000, sigHashes.at(i % sigHashes.size()), empty);
541 std::vector<Coin> coins;
542 for(uint32_t i = 0; i < mtx.
vin.size(); i++) {
553 for(uint32_t i = 0; i < mtx.
vin.size(); i++) {
554 std::vector<CScriptCheck> vChecks;
556 control.
Add(std::move(vChecks));
559 bool controlCheck = !control.
Complete().has_value();
589 CScript scriptPubkey1, scriptPubkey2, scriptPubkey1L, scriptPubkey2L, scriptMulti;
594 std::vector<CPubKey> oneandthree;
595 oneandthree.push_back(pubkey1);
596 oneandthree.push_back(pubkey3);
603 CScript destination_script_1, destination_script_2, destination_script_1L, destination_script_2L, destination_script_multi;
754 std::vector<CMutableTransaction> dummyTransactions =
759 t.vin[0].prevout.hash = dummyTransactions[0].GetHash();
760 t.vin[0].prevout.n = 1;
761 t.vin[0].scriptSig << std::vector<unsigned char>(65, 0);
763 t.vout[0].nValue = 90*
CENT;
767 constexpr auto CheckIsStandard = [](
const auto&
t,
const unsigned int max_op_return_relay =
MAX_OP_RETURN_RELAY) {
772 constexpr auto CheckIsNotStandard = [](
const auto&
t,
const std::string& reason_in,
const unsigned int max_op_return_relay =
MAX_OP_RETURN_RELAY) {
786 t.vout.emplace_back(0,
t.vout[0].scriptPubKey);
791 t.vout[0].nValue = nDustThreshold - 1;
792 CheckIsNotStandard(
t,
"dust");
794 t.vout[0].nValue = nDustThreshold;
798 t.version = std::numeric_limits<uint32_t>::max();
799 CheckIsNotStandard(
t,
"version");
802 CheckIsNotStandard(
t,
"version");
805 CheckIsNotStandard(
t,
"version");
818 t.vout[0].nValue = 674 - 1;
819 CheckIsNotStandard(
t,
"dust");
821 t.vout[0].nValue = 674;
826 CheckIsNotStandard(
t,
"scriptpubkey");
829 t.vout[0].scriptPubKey =
CScript() <<
OP_RETURN <<
"04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3804678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"_hex;
831 CheckIsStandard(
t, 83);
834 CheckIsNotStandard(
t,
"datacarrier", 82);
842 t.vout[0].scriptPubKey =
CScript() <<
OP_RETURN <<
OP_RESERVED << -1 << 0 <<
"01"_hex << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12 << 13 << 14 << 15 << 16;
844 t.vout[0].scriptPubKey =
CScript() <<
OP_RETURN << 0 <<
"01"_hex << 2 <<
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"_hex;
849 CheckIsNotStandard(
t,
"scriptpubkey");
858 t.vout[0].scriptPubKey =
CScript() <<
OP_RETURN <<
"04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"_hex;
859 t.vout[0].nValue = 0;
860 t.vout[1].scriptPubKey =
CScript() <<
OP_RETURN <<
"04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"_hex;
861 t.vout[1].nValue = 0;
864 t.vout[0].scriptPubKey =
CScript() <<
OP_RETURN <<
"04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"_hex;
872 t.vout[0].scriptPubKey =
CScript() <<
OP_RETURN <<
"04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3804678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"_hex;
873 t.vout[1].scriptPubKey =
CScript() <<
OP_RETURN <<
"04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3804678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"_hex;
874 const auto datacarrier_size =
t.vout[0].scriptPubKey.size() +
t.vout[1].scriptPubKey.size();
876 CheckIsStandard(
t, datacarrier_size);
877 CheckIsNotStandard(
t,
"datacarrier", datacarrier_size-1);
884 t.vin[0].scriptSig =
CScript() << std::vector<unsigned char>(1647, 0);
887 t.vin[0].scriptSig =
CScript() << std::vector<unsigned char>(1648, 0);
888 CheckIsNotStandard(
t,
"scriptsig-size");
893 << std::vector<unsigned char>(75, 0)
894 << std::vector<unsigned char>(235, 0)
895 << std::vector<unsigned char>(1234, 0)
899 const std::vector<unsigned char> non_push_ops = {
904 while (pc <
t.vin[0].scriptSig.end()) {
907 t.vin[0].scriptSig.GetOp(pc, opcode);
912 int index = prev_pc -
t.vin[0].scriptSig.begin();
913 unsigned char orig_op = *prev_pc;
915 for (
auto op : non_push_ops) {
916 t.vin[0].scriptSig[index] = op;
917 CheckIsNotStandard(
t,
"scriptsig-not-pushonly");
919 t.vin[0].scriptSig[index] = orig_op;
926 t.vout[0].scriptPubKey =
CScript() << OP_RETURN << std::vector<unsigned char>(19, 0);
936 t.vout[0].scriptPubKey =
CScript() << OP_RETURN << std::vector<unsigned char>(20, 0);
938 CheckIsNotStandard(
t,
"tx-size");
944 t.vin[0].scriptSig =
CScript() << std::vector<unsigned char>(65, 0);
948 CheckIsNotStandard(
t,
"bare-multisig");
957 t.vout[0].nValue = 576;
959 t.vout[0].nValue = 575;
960 CheckIsNotStandard(
t,
"dust");
964 t.vout[0].nValue = 672;
966 t.vout[0].nValue = 671;
967 CheckIsNotStandard(
t,
"dust");
971 t.vout[0].nValue = 546;
973 t.vout[0].nValue = 545;
974 CheckIsNotStandard(
t,
"dust");
977 t.vout[0].scriptPubKey =
CScript() << OP_HASH160 << std::vector<unsigned char>(20, 0) <<
OP_EQUAL;
978 t.vout[0].nValue = 540;
980 t.vout[0].nValue = 539;
981 CheckIsNotStandard(
t,
"dust");
984 t.vout[0].scriptPubKey =
CScript() << OP_0 << std::vector<unsigned char>(20, 0);
985 t.vout[0].nValue = 294;
987 t.vout[0].nValue = 293;
988 CheckIsNotStandard(
t,
"dust");
991 t.vout[0].scriptPubKey =
CScript() << OP_0 << std::vector<unsigned char>(32, 0);
992 t.vout[0].nValue = 330;
994 t.vout[0].nValue = 329;
995 CheckIsNotStandard(
t,
"dust");
998 t.vout[0].scriptPubKey =
CScript() << OP_1 << std::vector<unsigned char>(32, 0);
999 t.vout[0].nValue = 330;
1001 t.vout[0].nValue = 329;
1002 CheckIsNotStandard(
t,
"dust");
1005 for (
int op =
OP_1; op <=
OP_16; op += 1) {
1006 t.vout[0].scriptPubKey =
CScript() << (
opcodetype)op << std::vector<unsigned char>(2, 0);
1007 t.vout[0].nValue = 240;
1010 t.vout[0].nValue = 239;
1011 CheckIsNotStandard(
t,
"dust");
1017 t.vout[0].nValue = 240;
1019 t.vout[0].nValue = 239;
1020 CheckIsNotStandard(
t,
"dust");
1039 tx_create.
vout.reserve(p2sh_inputs_count);
1040 for (
unsigned i{0}; i < p2sh_inputs_count; ++i) {
1041 tx_create.
vout.emplace_back(424242 + i, max_sigops_p2sh);
1043 auto prev_txid{tx_create.
GetHash()};
1044 tx_max_sigops.
vin.reserve(p2sh_inputs_count);
1045 for (
unsigned i{0}; i < p2sh_inputs_count; ++i) {
1058 tx_create.
vout.emplace_back(424242, max_sigops_p2sh);
1059 prev_txid = tx_create.
GetHash();
1060 for (
unsigned i{0}; i < p2sh_inputs_count; ++i) {
1063 tx_max_sigops.
vin.emplace_back(prev_txid, p2sh_inputs_count,
CScript() <<
ToByteVector(max_sigops_redeem_script));
1068 std::string reject_reason(
"bad-txns-nonstandard-inputs");
1069 std::string sigop_limit_reject_debug_message(
"non-witness sigops exceed bip54 limit");
1074 BOOST_CHECK_EQUAL(validation_state.GetDebugMessage(), sigop_limit_reject_debug_message);
1082 unsigned p2pk_inputs_count{10};
1083 for (
unsigned i{0}; i < p2pk_inputs_count; ++i) {
1084 tx_create_p2pk.
vout.emplace_back(212121 + i, p2pk_script);
1086 prev_txid = tx_create_p2pk.
GetHash();
1087 tx_max_sigops.
vin.resize(p2sh_inputs_count);
1088 for (
unsigned i{0}; i < p2pk_inputs_count; ++i) {
1089 tx_max_sigops.
vin.emplace_back(prev_txid, i);
1104 prev_txid = tx_create_segwit.
GetHash();
1105 for (
unsigned i{0}; i < tx_create_segwit.
vout.size(); ++i) {
1106 tx_max_sigops.
vin.emplace_back(prev_txid, i);
1114 tx_create_p2pk.
vout.emplace_back(212121, p2pk_script);
1115 prev_txid = tx_create_p2pk.
GetHash();
1116 tx_max_sigops.
vin.resize(p2sh_inputs_count);
1117 ++p2pk_inputs_count;
1118 for (
unsigned i{0}; i < p2pk_inputs_count; ++i) {
1119 tx_max_sigops.
vin.emplace_back(prev_txid, i);
1122 auto legacy_sigop_count_p2pk = p2sh_inputs_count *
MAX_P2SH_SIGOPS + p2pk_inputs_count * 1;
1128 BOOST_CHECK_EQUAL(validation_state.GetDebugMessage(), sigop_limit_reject_debug_message);
1144 mtx.
vout.emplace_back(0, multisig);
1154 inputs.AddCoin(prevout,
Coin{{input_value,
CScript() <<
OP_TRUE}, 1, coinbase},
false);
1157 mtx.
vin.emplace_back(prevout);
1174 check_invalid(1 *
COIN,
1180 check_invalid(1 *
COIN,
1189 constexpr int height{100};
1193 auto check_final{[](
const std::vector<uint32_t>& sequences,
bool expected_final) {
1196 for (
const uint32_t
sequence : sequences) {
1212 constexpr int coin_height{100};
1216 auto check_min_height{[](uint32_t version,
int expected_min_height) {
1221 std::vector<int> prev_heights{coin_height};
1228 check_min_height(0, -1);
1229 check_min_height(1, -1);
1230 check_min_height(2, coin_height);
1231 check_min_height(std::numeric_limits<uint32_t>::max(), coin_height);
1252 tx_spend.vin.emplace_back(
Txid{}, 0);
1253 std::vector<std::vector<uint8_t>> sol_dummy;
1257 static_assert(std::variant_size_v<CTxDestination> == 9);
1264 tx_spend.vin[0].prevout.hash = tx_create.GetHash();
1271 tx_spend.vin[0].prevout.hash = tx_create.GetHash();
1279 tx_spend.vin[0].prevout.hash = tx_create.GetHash();
1283 tx_spend.vin[0].scriptSig.clear();
1289 tx_spend.vin[0].prevout.hash = tx_create.GetHash();
1294 redeem_script = tx_create.vout[0].scriptPubKey;
1297 tx_spend.vin[0].prevout.hash = tx_create.GetHash();
1301 tx_spend.vin[0].scriptSig.clear();
1307 tx_spend.vin[0].prevout.hash = tx_create.GetHash();
1312 redeem_script = tx_create.vout[0].scriptPubKey;
1315 tx_spend.vin[0].prevout.hash = tx_create.GetHash();
1319 tx_spend.vin[0].scriptSig.clear();
1325 tx_spend.vin[0].prevout.hash = tx_create.GetHash();
1330 redeem_script = tx_create.vout[0].scriptPubKey;
1333 tx_spend.vin[0].prevout.hash = tx_create.GetHash();
1337 tx_spend.vin[0].scriptSig.clear();
1343 tx_spend.vin[0].prevout.hash = tx_create.GetHash();
1348 redeem_script = tx_create.vout[0].scriptPubKey;
1351 tx_spend.vin[0].prevout.hash = tx_create.GetHash();
1355 tx_spend.vin[0].scriptSig.clear();
1360 tx_spend.vin[0].prevout.hash = tx_create.GetHash();
1365 redeem_script = tx_create.vout[0].scriptPubKey;
1368 tx_spend.vin[0].prevout.hash = tx_create.GetHash();
1372 tx_spend.vin[0].scriptSig.clear();
1377 for (
int i{2}; i <= 16; ++i) {
1380 tx_spend.vin[0].prevout.hash = tx_create.GetHash();
1385 redeem_script = tx_create.vout[0].scriptPubKey;
1388 tx_spend.vin[0].prevout.hash = tx_create.GetHash();
1392 tx_spend.vin[0].scriptSig.clear();
std::vector< unsigned char > valtype
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
const std::vector< unsigned char > ANCHOR_BYTES
Witness program for Pay-to-Anchor output script type.
constexpr CAmount MAX_MONEY
No amount larger than this (in satoshi) is valid.
int64_t CAmount
Amount in satoshis (Can be negative)
constexpr CAmount COIN
The amount of satoshis in one BTC.
#define Assert(val)
Identity function.
The block chain is a tree shaped structure starting with the genesis block at the root,...
RAII-style controller object for a CCheckQueue that guarantees the passed queue is finished before co...
std::optional< R > Complete()
void Add(std::vector< T > &&vChecks)
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Fee rate in satoshis per virtualbyte: CAmount / vB the feerate is represented internally as FeeFrac.
CAmount GetFeePerK() const
Return the fee in satoshis for a vsize of 1000 vbytes.
An encapsulated private key.
void MakeNewKey(bool fCompressed)
Generate a new private key using a cryptographic PRNG.
CPubKey GetPubKey() const
Compute the public key from a private key.
A reference to a CKey: the Hash160 of its serialized public key.
An outpoint - a combination of a transaction hash and an index n into its vout.
An encapsulated public key.
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
Serialized script, used inside transaction inputs and outputs.
static opcodetype EncodeOP_N(int n)
The basic transaction that is broadcasted on the network and contained in blocks.
const std::vector< CTxOut > vout
const std::vector< CTxIn > vin
An input of a transaction.
static constexpr uint32_t SEQUENCE_FINAL
Setting nSequence to this value for every input in a transaction disables nLockTime/IsFinalTx().
CScriptWitness scriptWitness
Only serialized through CTransaction.
static constexpr uint32_t MAX_SEQUENCE_NONFINAL
This is the maximum sequence number that enables both nLockTime and OP_CHECKLOCKTIMEVERIFY (BIP 65).
CTxOut out
unspent transaction output
bool fCoinBase
whether containing transaction was a coinbase
uint32_t nHeight
at which height this containing transaction was included in the active block chain
static CoinsViewEmpty & Get()
Double ended buffer combining vector and stream-like interfaces.
Fillable signing provider that keeps keys in an address->secret map.
virtual bool AddKeyPubKey(const CKey &key, const CPubKey &pubkey)
virtual bool AddCScript(const CScript &redeemScript)
BOOST_CHECK_EXCEPTION predicates to check the specific validation error.
A signature creator for transactions.
Valid signature cache, to avoid doing expensive ECDSA signature checking twice for every transaction ...
Minimal stream for reading from an existing byte array by std::span.
const std::string & get_str() const
std::string write(unsigned int prettyIndent=0, unsigned int indentLevel=0) const
const UniValue & get_array() const
std::string GetRejectReason() const
constexpr unsigned char * end()
constexpr unsigned char * begin()
void emplace_back(Args &&... args)
static constexpr script_verify_flags from_int(value_type f)
static transaction_identifier FromUint256(const uint256 &id)
static std::optional< transaction_identifier > FromHex(std::string_view hex)
void AddCoins(CCoinsViewCache &cache, const CTransaction &tx, int nHeight, bool check_for_overwrite)
Utility function to add all of a transaction's outputs to a cache.
static int32_t GetTransactionWeight(const CTransaction &tx)
TxValidationResult
A "reason" why a transaction was invalid, suitable for determining whether the provider of the transa...
@ TX_PREMATURE_SPEND
transaction spends a coinbase too early, or violates locktime/sequence locks
@ TX_CONSENSUS
invalid by consensus rules
constexpr unsigned int LOCKTIME_VERIFY_SEQUENCE
Flags for nSequence and nLockTime locks.
constexpr int COINBASE_MATURITY
Coinbase transaction outputs can only be spent after this number of new blocks (network rule)
constexpr unsigned int MAX_BLOCK_WEIGHT
The maximum allowed weight for a block, see BIP 141 (network rule)
constexpr int WITNESS_SCALE_FACTOR
CScript ParseScript(const std::string &s)
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_GT(excessive_headers.size(), MAX_HEADERS_SIZE)
BOOST_CHECK_EQUAL(headers.FindFirst("key"), "value")
BOOST_CHECK_EXCEPTION(HTTPHeaders{}.Read(reader), std::runtime_error, HasReason{"Empty HTTP header name"})
const std::map< std::string, script_verify_flag_name > & ScriptFlagNamesToEnum()
bool EvalScript(std::vector< std::vector< unsigned char > > &stack, const CScript &script, script_verify_flags flags, const BaseSignatureChecker &checker, SigVersion sigversion, ScriptExecutionData &execdata, ScriptError *serror)
bool VerifyScript(const CScript &scriptSig, const CScript &scriptPubKey, const CScriptWitness *witness, script_verify_flags flags, const BaseSignatureChecker &checker, ScriptError *serror)
constexpr int MAX_SCRIPT_VERIFY_FLAGS_BITS
@ BASE
Bare scripts and BIP16 P2SH-wrapped redeemscripts.
@ ASSERT_FAIL
Abort execution through assertion failure (for consensus code)
@ SCRIPT_VERIFY_STRICTENC
@ SCRIPT_VERIFY_CLEANSTACK
constexpr script_verify_flags SCRIPT_VERIFY_NONE
Script verification flags.
UniValue read_json(std::string_view jsondata)
CKey GenerateRandomKey(bool compressed) noexcept
bool CheckTxInputs(const CTransaction &tx, TxValidationState &state, const CCoinsViewCache &inputs, int nSpendHeight, CAmount &txfee)
Check whether all inputs of this transaction are valid (no double spends and amounts) This does not m...
""_hex is a compile-time user-defined literal returning a std::array<std::byte>, equivalent to ParseH...
std::vector< std::string > SplitString(std::string_view str, char sep)
std::string ToString(const T &t)
Locale-independent version of std::to_string.
#define BOOST_CHECK(expr)
TxValidationState ValidateInputsStandardness(const CTransaction &tx, const CCoinsViewCache &mapInputs)
Check transaction inputs.
bool SpendsNonAnchorWitnessProg(const CTransaction &tx, const CCoinsViewCache &prevouts)
Check whether this transaction spends any witness program but P2A, including not-yet-defined ones.
bool IsStandardTx(const CTransaction &tx, const std::optional< unsigned > &max_datacarrier_bytes, bool permit_bare_multisig, const CFeeRate &dust_relay_fee, std::string &reason)
Check for standard transaction types.
constexpr unsigned int MAX_OP_RETURN_RELAY
Default setting for -datacarriersize in vbytes.
constexpr unsigned int MAX_TX_LEGACY_SIGOPS
The maximum number of potentially executed legacy signature operations in a single standard tx.
constexpr script_verify_flags STANDARD_SCRIPT_VERIFY_FLAGS
Standard script verification flags that standard transactions will comply with.
constexpr decltype(CTransaction::version) TX_MAX_STANDARD_VERSION
constexpr bool DEFAULT_PERMIT_BAREMULTISIG
Default for -permitbaremultisig.
constexpr unsigned int DUST_RELAY_TX_FEE
Min feerate for defining dust.
constexpr unsigned int MAX_DUST_OUTPUTS_PER_TX
Maximum number of ephemeral dust outputs allowed.
constexpr unsigned int MAX_P2SH_SIGOPS
Maximum number of signature check operations in an IsStandard() P2SH script.
constexpr TransactionSerParams TX_NO_WITNESS
constexpr TransactionSerParams TX_WITH_WITNESS
std::shared_ptr< const CTransaction > CTransactionRef
opcodetype
Script opcodes.
constexpr int MAX_PUBKEYS_PER_MULTISIG
std::vector< unsigned char > ToByteVector(const T &in)
std::string ScriptErrorString(const ScriptError serror)
enum ScriptError_t ScriptError
@ SCRIPT_ERR_UNKNOWN_ERROR
static const int64_t values[]
A selection of numbers that do not trigger int64_t overflow when added/subtracted.
constexpr deserialize_type deserialize
uint64_t GetSerializeSize(const T &t)
constexpr size_t DEFAULT_SIGNATURE_CACHE_BYTES
bool ProduceSignature(const SigningProvider &provider, const BaseSignatureCreator &creator, const CScript &fromPubKey, SignatureData &sigdata)
Produce a script signature using a generic signature creator.
void UpdateInput(CTxIn &input, const SignatureData &data)
SignatureData DataFromTransaction(const CMutableTransaction &tx, unsigned int nIn, const CTxOut &txout)
Extract signature data from a transaction input, and insert it.
const SigningProvider & DUMMY_SIGNING_PROVIDER
TxoutType Solver(const CScript &scriptPubKey, std::vector< std::vector< unsigned char > > &vSolutionsRet)
Parse a scriptPubKey and identify script type for standard scripts.
CScript GetScriptForMultisig(int nRequired, const std::vector< CPubKey > &keys)
Generate a multisig script.
@ WITNESS_UNKNOWN
Only for Witness versions not already defined above.
@ ANCHOR
anyone can spend script
std::vector< Byte > ParseHex(std::string_view hex_str)
Like TryParseHex, but returns an empty vector on invalid input.
A mutable version of CTransaction.
std::vector< CTxOut > vout
Txid GetHash() const
Compute the hash of this CMutableTransaction.
void MergeSignatureData(SignatureData sigdata)
CTxDestination subtype to encode any future Witness version.
bool IsValidFlagCombination(script_verify_flags flags)
Flags that are not forbidden by an assert in script validation.
SignatureData CombineSignatures(const CMutableTransaction &input1, const CMutableTransaction &input2, const CTransactionRef tx)
std::set< script_verify_flags > ExcludeIndividualFlags(script_verify_flags flags)
script_verify_flags FillFlags(script_verify_flags flags)
bool CheckTxScripts(const CTransaction &tx, const std::map< COutPoint, CScript > &map_prevout_scriptPubKeys, const std::map< COutPoint, int64_t > &map_prevout_values, script_verify_flags flags, const PrecomputedTransactionData &txdata, const std::string &strTest, bool expect_valid)
static const std::map< std::string, script_verify_flag_name > & mapFlagNames
script_verify_flags TrimFlags(script_verify_flags flags)
std::vector< unsigned char > valtype
BOOST_AUTO_TEST_CASE(tx_valid)
script_verify_flags ParseScriptFlags(std::string strFlags)
static void ReplaceRedeemScript(CScript &script, const CScript &redeemScript)
static void CreateCreditAndSpend(const FillableSigningProvider &keystore, const CScript &outscript, CTransactionRef &output, CMutableTransaction &input, bool success=true)
static CScript PushAll(const std::vector< valtype > &values)
static void CheckWithFlag(const CTransactionRef &output, const CMutableTransaction &input, script_verify_flags flags, bool success)
std::vector< CMutableTransaction > SetupDummyInputs(FillableSigningProvider &keystoreRet, CCoinsViewCache &coinsRet, const std::array< CAmount, 4 > &nValues)
bool SignSignature(const SigningProvider &provider, const CScript &fromPubKey, CMutableTransaction &txTo, unsigned int nIn, const CAmount &amount, int nHashType, SignatureData &sig_data)
Produce a satisfying script (scriptSig or witness).
bool CheckTransaction(const CTransaction &tx, TxValidationState &state)
std::pair< int, int64_t > CalculateSequenceLocks(const CTransaction &tx, int flags, std::vector< int > &prevHeights, const CBlockIndex &block)
Calculates the block height and previous block's median time past at which the transaction will be co...
unsigned int GetLegacySigOpCount(const CTransaction &tx)
Auxiliary functions for transaction validation (ideally should not be exposed)
unsigned int GetP2SHSigOpCount(const CTransaction &tx, const CCoinsViewCache &inputs)
Count ECDSA signature operations in pay-to-script-hash inputs.
bool IsFinalTx(const CTransaction &tx, int nBlockHeight, int64_t nBlockTime)
Check if transaction is final and can be included in a block with the specified height and time.
constexpr std::array tests