5 #include <test/data/tx_invalid.json.h> 6 #include <test/data/tx_valid.json.h> 39 #include <boost/test/unit_test.hpp> 47 typedef std::vector<unsigned char>
valtype;
79 if (strFlags.empty() || strFlags ==
"NONE")
return flags;
81 std::vector<std::string> words =
SplitString(strFlags,
',');
82 for (
const std::string& word : words)
85 BOOST_ERROR(
"Bad test: unknown verification flag '" << word <<
"'");
96 standard_flags_missing &= ~(pair.second);
98 return standard_flags_missing == 0;
107 std::map<std::string, unsigned int>::const_iterator it =
mapFlagNames.begin();
109 if (
flags & it->second) {
110 ret += it->first +
",";
114 return ret.substr(0,
ret.size() - 1);
121 const std::map<COutPoint, int64_t>& map_prevout_values,
unsigned int flags,
124 bool tx_valid =
true;
126 for (
unsigned int i = 0; i < tx.
vin.size() && tx_valid; ++i) {
128 const CAmount amount = map_prevout_values.count(input.
prevout) ? map_prevout_values.at(input.
prevout) : 0;
133 BOOST_ERROR(
"Bad test: " << strTest);
137 BOOST_CHECK_MESSAGE(tx_valid, strTest);
143 BOOST_CHECK_MESSAGE(!tx_valid, strTest);
146 return (tx_valid == expect_valid);
183 std::set<unsigned int> flags_combos;
185 const unsigned int flags_excluding_one =
TrimFlags(
flags & ~(pair.second));
186 if (
flags != flags_excluding_one) {
187 flags_combos.insert(flags_excluding_one);
197 BOOST_CHECK_MESSAGE(
CheckMapFlagNames(),
"mapFlagNames is missing a script verification flag");
201 for (
unsigned int idx = 0; idx <
tests.size(); idx++) {
203 std::string strTest = test.
write();
204 if (test[0].isArray())
208 BOOST_ERROR(
"Bad test: " << strTest);
212 std::map<COutPoint, CScript> mapprevOutScriptPubKeys;
213 std::map<COutPoint, int64_t> mapprevOutValues;
216 for (
unsigned int inpIdx = 0; inpIdx < inputs.
size(); inpIdx++) {
217 const UniValue& input = inputs[inpIdx];
223 if (vinput.
size() < 3 || vinput.
size() > 4)
229 mapprevOutScriptPubKeys[outpoint] =
ParseScript(vinput[2].get_str());
230 if (vinput.
size() >= 4)
232 mapprevOutValues[outpoint] = vinput[3].
getInt<int64_t>();
237 BOOST_ERROR(
"Bad test: " << strTest);
241 std::string transaction = test[1].
get_str();
253 if (~verify_flags !=
FillFlags(~verify_flags)) {
254 BOOST_ERROR(
"Bad test flags: " << strTest);
257 BOOST_CHECK_MESSAGE(
CheckTxScripts(tx, mapprevOutScriptPubKeys, mapprevOutValues, ~verify_flags, txdata, strTest,
true),
258 "Tx unexpectedly failed: " << strTest);
264 if (!
CheckTxScripts(tx, mapprevOutScriptPubKeys, mapprevOutValues,
flags, txdata, strTest,
true)) {
265 BOOST_ERROR(
"Tx unexpectedly failed with flag " <<
name <<
" unset: " << strTest);
269 if (!
CheckTxScripts(tx, mapprevOutScriptPubKeys, mapprevOutValues,
flags, txdata, strTest,
true)) {
270 BOOST_ERROR(
"Tx unexpectedly failed with random flags " <<
ToString(
flags) <<
": " << strTest);
276 if (!
CheckTxScripts(tx, mapprevOutScriptPubKeys, mapprevOutValues, ~flags_excluding_one, txdata, strTest,
false)) {
277 BOOST_ERROR(
"Too many flags unset: " << strTest);
289 for (
unsigned int idx = 0; idx <
tests.size(); idx++) {
291 std::string strTest = test.
write();
292 if (test[0].isArray())
296 BOOST_ERROR(
"Bad test: " << strTest);
300 std::map<COutPoint, CScript> mapprevOutScriptPubKeys;
301 std::map<COutPoint, int64_t> mapprevOutValues;
304 for (
unsigned int inpIdx = 0; inpIdx < inputs.
size(); inpIdx++) {
305 const UniValue& input = inputs[inpIdx];
311 if (vinput.
size() < 3 || vinput.
size() > 4)
317 mapprevOutScriptPubKeys[outpoint] =
ParseScript(vinput[2].get_str());
318 if (vinput.
size() >= 4)
320 mapprevOutValues[outpoint] = vinput[3].
getInt<int64_t>();
325 BOOST_ERROR(
"Bad test: " << strTest);
329 std::string transaction = test[1].
get_str();
335 BOOST_CHECK_MESSAGE(test[2].get_str() ==
"BADTX", strTest);
343 if (verify_flags !=
FillFlags(verify_flags)) {
344 BOOST_ERROR(
"Bad test flags: " << strTest);
348 BOOST_CHECK_MESSAGE(
CheckTxScripts(tx, mapprevOutScriptPubKeys, mapprevOutValues, verify_flags, txdata, strTest,
false),
349 "Tx unexpectedly passed: " << strTest);
355 if (!
CheckTxScripts(tx, mapprevOutScriptPubKeys, mapprevOutValues,
flags, txdata, strTest,
false)) {
356 BOOST_ERROR(
"Tx unexpectedly passed with flag " <<
name <<
" set: " << strTest);
360 if (!
CheckTxScripts(tx, mapprevOutScriptPubKeys, mapprevOutValues,
flags, txdata, strTest,
false)) {
361 BOOST_ERROR(
"Tx unexpectedly passed with random flags " <<
name <<
": " << strTest);
367 if (!
CheckTxScripts(tx, mapprevOutScriptPubKeys, mapprevOutValues, flags_excluding_one, txdata, strTest,
true)) {
368 BOOST_ERROR(
"Too many flags set: " << strTest);
386 auto createTransaction =[](
size_t payloadSize) {
395 auto maxPayloadSize = maxTransactionSize - oversizedTransactionBaseSize;
405 BOOST_CHECK_MESSAGE(!
CheckTransaction(createTransaction(maxPayloadSize), state),
"Oversized transaction should be invalid");
413 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};
414 std::vector<unsigned char> vch(ch, ch +
sizeof(ch) -1);
422 tx.
vin.push_back(tx.
vin[0]);
431 std::vector<CMutableTransaction> dummyTransactions =
436 t1.vin[0].prevout.hash = dummyTransactions[0].GetHash();
437 t1.vin[0].prevout.n = 1;
438 t1.vin[0].scriptSig << std::vector<unsigned char>(65, 0);
439 t1.vin[1].prevout.hash = dummyTransactions[1].GetHash();
440 t1.vin[1].prevout.n = 0;
441 t1.vin[1].scriptSig << std::vector<unsigned char>(65, 0) << std::vector<unsigned char>(33, 4);
442 t1.vin[2].prevout.hash = dummyTransactions[1].GetHash();
443 t1.vin[2].prevout.n = 1;
444 t1.vin[2].scriptSig << std::vector<unsigned char>(65, 0) << std::vector<unsigned char>(33, 4);
446 t1.vout[0].nValue = 90*
CENT;
447 t1.vout[0].scriptPubKey <<
OP_1;
456 outputm.
vin.resize(1);
457 outputm.
vin[0].prevout.SetNull();
459 outputm.
vout.resize(1);
460 outputm.
vout[0].nValue = 1;
461 outputm.
vout[0].scriptPubKey = outscript;
465 assert(output->vin.size() == 1);
466 assert(output->vin[0] == outputm.
vin[0]);
467 assert(output->vout.size() == 1);
472 inputm.
vin.resize(1);
473 inputm.
vin[0].prevout.hash = output->GetHash();
474 inputm.
vin[0].prevout.n = 0;
475 inputm.
vout.resize(1);
476 inputm.
vout[0].nValue = 1;
488 assert(input.
vin[0].scriptWitness.stack == inputm.
vin[0].scriptWitness.stack);
505 }
else if (v.size() == 1 && v[0] >= 1 && v[0] <= 16) {
507 }
else if (v.size() == 1 && v[0] == 0x81) {
518 std::vector<valtype> stack;
521 stack.back() = std::vector<unsigned char>(redeemScript.
begin(), redeemScript.
end());
536 std::vector<int> sigHashes;
545 for(uint32_t ij = 0; ij < 4500; ij++) {
546 uint32_t i = mtx.
vin.size();
547 COutPoint outpoint(
Txid::FromHex(
"0000000000000000000000000000000000000000000000000000000000000100").value(), i);
549 mtx.
vin.resize(mtx.
vin.size() + 1);
550 mtx.
vin[i].prevout = outpoint;
553 mtx.
vout.resize(mtx.
vout.size() + 1);
554 mtx.
vout[i].nValue = 1000;
559 for(uint32_t i = 0; i < mtx.
vin.size(); i++) {
561 bool hashSigned =
SignSignature(keystore, scriptPubKey, mtx, i, 1000, sigHashes.at(i % sigHashes.size()), empty);
574 std::vector<Coin> coins;
575 for(uint32_t i = 0; i < mtx.
vin.size(); i++) {
586 for(uint32_t i = 0; i < mtx.
vin.size(); i++) {
587 std::vector<CScriptCheck> vChecks;
589 control.
Add(std::move(vChecks));
592 bool controlCheck = !control.
Complete().has_value();
622 CScript scriptPubkey1, scriptPubkey2, scriptPubkey1L, scriptPubkey2L, scriptMulti;
627 std::vector<CPubKey> oneandthree;
628 oneandthree.push_back(pubkey1);
629 oneandthree.push_back(pubkey3);
636 CScript destination_script_1, destination_script_2, destination_script_1L, destination_script_2L, destination_script_multi;
788 std::vector<CMutableTransaction> dummyTransactions =
793 t.vin[0].prevout.hash = dummyTransactions[0].GetHash();
794 t.vin[0].prevout.n = 1;
795 t.vin[0].scriptSig << std::vector<unsigned char>(65, 0);
797 t.vout[0].nValue = 90*
CENT;
801 constexpr
auto CheckIsStandard = [](
const auto&
t) {
806 constexpr
auto CheckIsNotStandard = [](
const auto&
t,
const std::string& reason_in) {
820 t.vout.emplace_back(0,
t.vout[0].scriptPubKey);
825 t.vout[0].nValue = nDustThreshold - 1;
826 CheckIsNotStandard(
t,
"dust");
828 t.vout[0].nValue = nDustThreshold;
832 t.version = std::numeric_limits<uint32_t>::max();
833 CheckIsNotStandard(
t,
"version");
836 CheckIsNotStandard(
t,
"version");
839 CheckIsNotStandard(
t,
"version");
852 t.vout[0].nValue = 674 - 1;
853 CheckIsNotStandard(
t,
"dust");
855 t.vout[0].nValue = 674;
860 CheckIsNotStandard(
t,
"scriptpubkey");
863 t.vout[0].scriptPubKey =
CScript() <<
OP_RETURN <<
"04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3804678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"_hex;
868 t.vout[0].scriptPubKey =
CScript() <<
OP_RETURN <<
"04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3804678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3800"_hex;
870 CheckIsNotStandard(
t,
"scriptpubkey");
878 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;
880 t.vout[0].scriptPubKey =
CScript() <<
OP_RETURN << 0 <<
"01"_hex << 2 <<
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"_hex;
885 CheckIsNotStandard(
t,
"scriptpubkey");
894 t.vout[0].scriptPubKey =
CScript() <<
OP_RETURN <<
"04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"_hex;
895 t.vout[0].nValue = 0;
896 t.vout[1].scriptPubKey =
CScript() <<
OP_RETURN <<
"04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"_hex;
897 t.vout[1].nValue = 0;
898 CheckIsNotStandard(
t,
"multi-op-return");
900 t.vout[0].scriptPubKey =
CScript() <<
OP_RETURN <<
"04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"_hex;
902 CheckIsNotStandard(
t,
"multi-op-return");
906 CheckIsNotStandard(
t,
"multi-op-return");
913 t.vin[0].scriptSig =
CScript() << std::vector<unsigned char>(1647, 0);
916 t.vin[0].scriptSig =
CScript() << std::vector<unsigned char>(1648, 0);
917 CheckIsNotStandard(
t,
"scriptsig-size");
922 << std::vector<unsigned char>(75, 0)
923 << std::vector<unsigned char>(235, 0)
924 << std::vector<unsigned char>(1234, 0)
928 const std::vector<unsigned char> non_push_ops = {
933 while (pc <
t.vin[0].scriptSig.end()) {
936 t.vin[0].scriptSig.GetOp(pc, opcode);
941 int index = prev_pc -
t.vin[0].scriptSig.begin();
942 unsigned char orig_op = *prev_pc;
944 for (
auto op : non_push_ops) {
945 t.vin[0].scriptSig[index] = op;
946 CheckIsNotStandard(
t,
"scriptsig-not-pushonly");
948 t.vin[0].scriptSig[index] = orig_op;
955 t.vout[0].scriptPubKey =
CScript() << OP_RETURN << std::vector<unsigned char>(19, 0);
965 t.vout[0].scriptPubKey =
CScript() << OP_RETURN << std::vector<unsigned char>(20, 0);
967 CheckIsNotStandard(
t,
"tx-size");
973 t.vin[0].scriptSig =
CScript() << std::vector<unsigned char>(65, 0);
977 CheckIsNotStandard(
t,
"bare-multisig");
986 t.vout[0].nValue = 576;
988 t.vout[0].nValue = 575;
989 CheckIsNotStandard(
t,
"dust");
993 t.vout[0].nValue = 672;
995 t.vout[0].nValue = 671;
996 CheckIsNotStandard(
t,
"dust");
1000 t.vout[0].nValue = 546;
1002 t.vout[0].nValue = 545;
1003 CheckIsNotStandard(
t,
"dust");
1006 t.vout[0].scriptPubKey =
CScript() << OP_HASH160 << std::vector<unsigned char>(20, 0) <<
OP_EQUAL;
1007 t.vout[0].nValue = 540;
1009 t.vout[0].nValue = 539;
1010 CheckIsNotStandard(
t,
"dust");
1013 t.vout[0].scriptPubKey =
CScript() << OP_0 << std::vector<unsigned char>(20, 0);
1014 t.vout[0].nValue = 294;
1016 t.vout[0].nValue = 293;
1017 CheckIsNotStandard(
t,
"dust");
1020 t.vout[0].scriptPubKey =
CScript() << OP_0 << std::vector<unsigned char>(32, 0);
1021 t.vout[0].nValue = 330;
1023 t.vout[0].nValue = 329;
1024 CheckIsNotStandard(
t,
"dust");
1027 t.vout[0].scriptPubKey =
CScript() << OP_1 << std::vector<unsigned char>(32, 0);
1028 t.vout[0].nValue = 330;
1030 t.vout[0].nValue = 329;
1031 CheckIsNotStandard(
t,
"dust");
1034 for (
int op =
OP_1; op <=
OP_16; op += 1) {
1035 t.vout[0].scriptPubKey =
CScript() << (
opcodetype)op << std::vector<unsigned char>(2, 0);
1036 t.vout[0].nValue = 240;
1039 t.vout[0].nValue = 239;
1040 CheckIsNotStandard(
t,
"dust");
1044 t.vout[0].scriptPubKey =
CScript() << OP_1 << std::vector<unsigned char>{0x4e, 0x73};
1046 t.vout[0].nValue = 240;
1048 t.vout[0].nValue = 239;
1049 CheckIsNotStandard(
t,
"dust");
1069 tx_create.
vout.reserve(p2sh_inputs_count);
1070 for (
unsigned i{0}; i < p2sh_inputs_count; ++i) {
1071 tx_create.
vout.emplace_back(424242 + i, max_sigops_p2sh);
1073 auto prev_txid{tx_create.
GetHash()};
1074 tx_max_sigops.
vin.reserve(p2sh_inputs_count);
1075 for (
unsigned i{0}; i < p2sh_inputs_count; ++i) {
1088 tx_create.
vout.emplace_back(424242, max_sigops_p2sh);
1089 prev_txid = tx_create.
GetHash();
1090 for (
unsigned i{0}; i < p2sh_inputs_count; ++i) {
1093 tx_max_sigops.
vin.emplace_back(prev_txid, p2sh_inputs_count,
CScript() <<
ToByteVector(max_sigops_redeem_script));
1103 unsigned p2pk_inputs_count{10};
1104 for (
unsigned i{0}; i < p2pk_inputs_count; ++i) {
1105 tx_create_p2pk.
vout.emplace_back(212121 + i, p2pk_script);
1107 prev_txid = tx_create_p2pk.
GetHash();
1108 tx_max_sigops.
vin.resize(p2sh_inputs_count);
1109 for (
unsigned i{0}; i < p2pk_inputs_count; ++i) {
1110 tx_max_sigops.
vin.emplace_back(prev_txid, i);
1125 prev_txid = tx_create_segwit.
GetHash();
1126 for (
unsigned i{0}; i < tx_create_segwit.
vout.size(); ++i) {
1127 tx_max_sigops.
vin.emplace_back(prev_txid, i);
1135 tx_create_p2pk.
vout.emplace_back(212121, p2pk_script);
1136 prev_txid = tx_create_p2pk.
GetHash();
1137 tx_max_sigops.
vin.resize(p2sh_inputs_count);
1138 ++p2pk_inputs_count;
1139 for (
unsigned i{0}; i < p2pk_inputs_count; ++i) {
1140 tx_max_sigops.
vin.emplace_back(prev_txid, i);
std::shared_ptr< const CTransaction > CTransactionRef
CScript GetScriptForMultisig(int nRequired, const std::vector< CPubKey > &keys)
Generate a multisig script.
Valid signature cache, to avoid doing expensive ECDSA signature checking twice for every transaction ...
std::vector< std::string > SplitString(std::string_view str, char sep)
std::vector< Byte > ParseHex(std::string_view hex_str)
Like TryParseHex, but returns an empty vector on invalid input.
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.
static const int WITNESS_SCALE_FACTOR
enum ScriptError_t ScriptError
static const unsigned int MAX_OP_RETURN_RELAY
Default setting for -datacarriersize.
CPubKey GetPubKey() const
Compute the public key from a private key.
bool VerifyScript(const CScript &scriptSig, const CScript &scriptPubKey, const CScriptWitness *witness, unsigned int flags, const BaseSignatureChecker &checker, ScriptError *serror)
CScriptWitness scriptWitness
Only serialized through CTransaction.
size_t GetSerializeSize(const T &t)
virtual bool AddCScript(const CScript &redeemScript)
constexpr deserialize_type deserialize
CTxOut out
unspent transaction output
bool CheckTxScripts(const CTransaction &tx, const std::map< COutPoint, CScript > &map_prevout_scriptPubKeys, const std::map< COutPoint, int64_t > &map_prevout_values, unsigned int flags, const PrecomputedTransactionData &txdata, const std::string &strTest, bool expect_valid)
unsigned int fCoinBase
whether containing transaction was a coinbase
const std::string & get_str() const
const UniValue & get_array() const
Bare scripts and BIP16 P2SH-wrapped redeemscripts.
static const int64_t values[]
A selection of numbers that do not trigger int64_t overflow when added/subtracted.
UniValue read_json(std::string_view jsondata)
RAII-style controller object for a CCheckQueue that guarantees the passed queue is finished before co...
static constexpr bool DEFAULT_PERMIT_BAREMULTISIG
Default for -permitbaremultisig.
A signature creator for transactions.
std::string FormatScriptFlags(unsigned int flags)
static constexpr unsigned int STANDARD_SCRIPT_VERIFY_FLAGS
Standard script verification flags that standard transactions will comply with.
static int32_t GetTransactionWeight(const CTransaction &tx)
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
const std::vector< CTxIn > vin
static constexpr unsigned int MAX_DUST_OUTPUTS_PER_TX
Maximum number of ephemeral dust outputs allowed.
std::vector< unsigned char > valtype
constexpr unsigned char * begin()
static const unsigned int MAX_BLOCK_WEIGHT
The maximum allowed weight for a block, see BIP 141 (network rule)
CKey GenerateRandomKey(bool compressed) noexcept
constexpr std::array tests
unsigned int FillFlags(unsigned int flags)
int64_t CAmount
Amount in satoshis (Can be negative)
static decltype(CTransaction::version) constexpr TX_MAX_STANDARD_VERSION
bool AreInputsStandard(const CTransaction &tx, const CCoinsViewCache &mapInputs)
Check transaction inputs to mitigate two potential denial-of-service attacks:
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.
uint32_t nHeight
at which height this containing transaction was included in the active block chain ...
void push_back(const T &value)
Abort execution through assertion failure (for consensus code)
Abstract view on the open txout dataset.
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
An input of a transaction.
Double ended buffer combining vector and stream-like interfaces.
const SigningProvider & DUMMY_SIGNING_PROVIDER
BOOST_AUTO_TEST_SUITE_END()
An encapsulated public key.
Fillable signing provider that keeps keys in an address->secret map.
std::string ScriptErrorString(const ScriptError serror)
std::vector< CMutableTransaction > SetupDummyInputs(FillableSigningProvider &keystoreRet, CCoinsViewCache &coinsRet, const std::array< CAmount, 4 > &nValues)
opcodetype
Script opcodes.
void MakeNewKey(bool fCompressed)
Generate a new private key using a cryptographic PRNG.
const std::vector< CTxOut > vout
static constexpr unsigned int MAX_P2SH_SIGOPS
Maximum number of signature check operations in an IsStandard() P2SH script.
static void CreateCreditAndSpend(const FillableSigningProvider &keystore, const CScript &outscript, CTransactionRef &output, CMutableTransaction &input, bool success=true)
std::string write(unsigned int prettyIndent=0, unsigned int indentLevel=0) const
""_hex is a compile-time user-defined literal returning a std::array<std::byte>, equivalent to ParseH...
void MergeSignatureData(SignatureData sigdata)
SignatureData CombineSignatures(const CMutableTransaction &input1, const CMutableTransaction &input2, const CTransactionRef tx)
Txid GetHash() const
Compute the hash of this CMutableTransaction.
An outpoint - a combination of a transaction hash and an index n into its vout.
std::vector< CTxOut > vout
static constexpr unsigned int MAX_TX_LEGACY_SIGOPS
The maximum number of potentially executed legacy signature operations in a single standard tx...
void Add(std::vector< T > &&vChecks)
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).
BOOST_AUTO_TEST_CASE(tx_valid)
static CScript PushAll(const std::vector< valtype > &values)
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
std::vector< unsigned char > valtype
static constexpr unsigned int DUST_RELAY_TX_FEE
Min feerate for defining dust.
std::vector< unsigned char > ToByteVector(const T &in)
static void ReplaceRedeemScript(CScript &script, const CScript &redeemScript)
static opcodetype EncodeOP_N(int n)
bool IsValidFlagCombination(unsigned flags)
Flags that are not forbidden by an assert in script validation.
SignatureData DataFromTransaction(const CMutableTransaction &tx, unsigned int nIn, const CTxOut &txout)
Extract signature data from a transaction input, and insert it.
#define BOOST_CHECK_EQUAL(v1, v2)
Serialized script, used inside transaction inputs and outputs.
unsigned int GetP2SHSigOpCount(const CTransaction &tx, const CCoinsViewCache &inputs)
Count ECDSA signature operations in pay-to-script-hash inputs.
constexpr unsigned char * end()
std::set< unsigned int > ExcludeIndividualFlags(unsigned int flags)
A reference to a CKey: the Hash160 of its serialized public key.
void UpdateInput(CTxIn &input, const SignatureData &data)
GenericTransactionSignatureChecker< CTransaction > TransactionSignatureChecker
Fee rate in satoshis per kilovirtualbyte: CAmount / kvB.
static constexpr CAmount MAX_MONEY
No amount larger than this (in satoshi) is valid.
bool ProduceSignature(const SigningProvider &provider, const BaseSignatureCreator &creator, const CScript &fromPubKey, SignatureData &sigdata)
Produce a script signature using a generic signature creator.
A mutable version of CTransaction.
virtual bool AddKeyPubKey(const CKey &key, const CPubKey &pubkey)
static constexpr size_t DEFAULT_SIGNATURE_CACHE_BYTES
static constexpr CAmount CENT
unsigned int ParseScriptFlags(std::string strFlags)
An encapsulated private key.
The basic transaction that is broadcasted on the network and contained in blocks. ...
CCoinsView that adds a memory cache for transactions to another CCoinsView.
std::string GetRejectReason() const
CScript ParseScript(const std::string &s)
bool EvalScript(std::vector< std::vector< unsigned char > > &stack, const CScript &script, unsigned int flags, const BaseSignatureChecker &checker, SigVersion sigversion, ScriptExecutionData &execdata, ScriptError *serror)
std::optional< R > Complete()
bool CheckTransaction(const CTransaction &tx, TxValidationState &state)
CAmount GetFeePerK() const
Return the fee in satoshis for a vsize of 1000 vbytes.
static void CheckWithFlag(const CTransactionRef &output, const CMutableTransaction &input, uint32_t flags, bool success)
static std::optional< transaction_identifier > FromHex(std::string_view hex)
unsigned int TrimFlags(unsigned int flags)
std::string ToString(const T &t)
Locale-independent version of std::to_string.
static std::map< std::string, unsigned int > mapFlagNames
#define Assert(val)
Identity function.
void emplace_back(Args &&... args)
static constexpr TransactionSerParams TX_NO_WITNESS
static constexpr TransactionSerParams TX_WITH_WITNESS
#define BOOST_CHECK(expr)