19#include <test/data/bip341_wallet_vectors.json.h>
20#include <test/data/script_tests.json.h>
32#include <boost/test/unit_test.hpp>
111 BOOST_ERROR(
"Unknown scripterror enumeration value, update script_errors in script_tests.cpp.");
120 BOOST_ERROR(
"Unknown scripterror \"" <<
name <<
"\" in test description");
139 for (
int i = 0; i < 256; ++i) {
145 BOOST_CHECK_MESSAGE(
VerifyScript(scriptSig, scriptPubKey, &scriptWitness,
combined_flags,
MutableTransactionSignatureChecker(&tx, 0,
txCredit.
vout[0].nValue,
MissingDataBehavior::ASSERT_FAIL), &err) ==
expect, message +
strprintf(
" (with flags %x)",
combined_flags.as_int()));
152 std::vector<unsigned char> r, s;
156 while (s.size() < 33) {
157 s.insert(s.begin(), 0x00);
173 vchSig.push_back(4 + r.size() + s.size());
175 vchSig.push_back(r.size());
178 vchSig.push_back(s.size());
184const unsigned char vchKey0[32] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1};
185const unsigned char vchKey1[32] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0};
186const unsigned char vchKey2[32] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0};
190 CKey key0, key0C, key1, key1C, key2, key2C;
191 CPubKey pubkey0, pubkey0C, pubkey0H;
202 *
const_cast<unsigned char*
>(pubkey0H.
data()) = 0x06 | (pubkey0H[64] & 1);
216enum class WitnessMode {
234 bool havePush{
false};
235 std::vector<unsigned char> push;
244 spendTx.
vin[0].scriptSig << push;
249 void DoPush(
const std::vector<unsigned char>&
data)
260 if (
wm == WitnessMode::PKH) {
265 }
else if (
wm == WitnessMode::SH) {
266 witscript = scriptPubKey;
272 redeemscript = scriptPubKey;
288 spendTx.
vin[0].scriptSig <<
_op;
292 TestBuilder&
Num(
int num)
295 spendTx.
vin[0].scriptSig << num;
299 TestBuilder& Push(
const std::string& hex)
314 std::vector<unsigned char>
vchSig, r,
s;
323 }
while (
lenR != r.size() ||
lenS !=
s.size());
336 TestBuilder& Push(
const CPubKey& pubkey)
344 DoPush(std::vector<unsigned char>(redeemscript.
begin(), redeemscript.
end()));
350 DoPush(std::vector<unsigned char>(witscript.
begin(), witscript.
end()));
354 TestBuilder&
EditPush(
unsigned int pos,
const std::string&
hexin,
const std::string&
hexout)
361 push.erase(push.begin() + pos, push.begin() + pos +
datain.size());
369 assert(pos < push.size());
376 TestBuilder copy = *
this;
378 test.
DoTest(creditTx->vout[0].scriptPubKey, spendTx.
vin[0].scriptSig, scriptWitness, flags, comment, scriptError, nValue);
386 scriptWitness.
stack.push_back(push);
395 if (!scriptWitness.
stack.empty()) {
397 for (
unsigned i = 0; i < scriptWitness.
stack.size(); i++) {
407 array.push_back(comment);
422 while ((pos =
ret.find(
" \n", pos)) != std::string::npos) {
423 ret.replace(pos, 2,
"\n");
436 std::vector<TestBuilder>
tests;
440 ).PushSig(
keys.key0));
447 ).PushSig(
keys.key1).Push(
keys.pubkey1C));
449 "P2PKH, bad pubkey", 0
453 "P2PK anyonecanpay", 0
456 "P2PK anyonecanpay marked with normal hashtype", 0
461 ).PushSig(
keys.key0).PushRedeem());
468 ).PushSig(
keys.key0).Push(
keys.pubkey0).PushRedeem());
470 "P2SH(P2PKH), bad sig but no VERIFY_P2SH", 0,
true
471 ).PushSig(
keys.key0).DamagePush(10).PushRedeem());
478 ).Num(0).PushSig(
keys.key0).PushSig(
keys.key1).PushSig(
keys.key2));
485 ).Num(0).PushSig(
keys.key1).PushSig(
keys.key2).PushRedeem());
491 "P2PK with too much R padding but no DERSIG", 0
492 ).PushSig(
keys.key1,
SIGHASH_ALL, 31, 32).EditPush(1,
"43021F",
"44022000"));
497 "P2PK with too much S padding but no DERSIG", 0
498 ).PushSig(
keys.key1,
SIGHASH_ALL).EditPush(1,
"44",
"45").EditPush(37,
"20",
"2100"));
503 "P2PK with too little R padding but no DERSIG", 0
504 ).PushSig(
keys.key1,
SIGHASH_ALL, 33, 32).EditPush(1,
"45022100",
"440220"));
509 "P2PK NOT with bad sig with too much R padding but no DERSIG", 0
510 ).PushSig(
keys.key2,
SIGHASH_ALL, 31, 32).EditPush(1,
"43021F",
"44022000").DamagePush(10));
515 "P2PK NOT with too much R padding but no DERSIG", 0
522 "BIP66 example 1, without DERSIG", 0
523 ).PushSig(
keys.key1,
SIGHASH_ALL, 33, 32).EditPush(1,
"45022100",
"440220"));
528 "BIP66 example 2, without DERSIG", 0
534 "BIP66 example 3, without DERSIG", 0
540 "BIP66 example 4, without DERSIG", 0
546 "BIP66 example 5, without DERSIG", 0
552 "BIP66 example 6, without DERSIG", 0
558 "BIP66 example 7, without DERSIG", 0
559 ).Num(0).PushSig(
keys.key1,
SIGHASH_ALL, 33, 32).EditPush(1,
"45022100",
"440220").PushSig(
keys.key2));
564 "BIP66 example 8, without DERSIG", 0
570 "BIP66 example 9, without DERSIG", 0
576 "BIP66 example 10, without DERSIG", 0
577 ).Num(0).Num(0).PushSig(
keys.key2,
SIGHASH_ALL, 33, 32).EditPush(1,
"45022100",
"440220"));
582 "BIP66 example 11, without DERSIG", 0
588 "BIP66 example 12, without DERSIG", 0
589 ).Num(0).PushSig(
keys.key1,
SIGHASH_ALL, 33, 32).EditPush(1,
"45022100",
"440220").Num(0));
592 ).Num(0).PushSig(
keys.key1,
SIGHASH_ALL, 33, 32).EditPush(1,
"45022100",
"440220").Num(0));
594 "P2PK with multi-byte hashtype, without DERSIG", 0
601 "P2PK with high S but no LOW_S", 0
608 "P2PK with hybrid pubkey but no STRICTENC", 0
614 "P2PK NOT with hybrid pubkey but no STRICTENC", 0
620 "P2PK NOT with invalid hybrid pubkey but no STRICTENC", 0
626 "1-of-2 with the second 1 hybrid pubkey and no STRICTENC", 0
636 "P2PK with undefined hashtype but no STRICTENC", 0
637 ).PushSig(
keys.key1, 5));
642 "P2PK NOT with invalid sig and undefined hashtype but no STRICTENC", 0
643 ).PushSig(
keys.key1, 5).DamagePush(10));
649 "3-of-3 with nonzero dummy but no NULLDUMMY", 0
650 ).Num(1).PushSig(
keys.key0).PushSig(
keys.key1).PushSig(
keys.key2));
655 "3-of-3 NOT with invalid sig and nonzero dummy but no NULLDUMMY", 0
656 ).Num(1).PushSig(
keys.key0).PushSig(
keys.key1).PushSig(
keys.key2).DamagePush(10));
662 "2-of-2 with two identical keys and sigs pushed using OP_DUP but no SIGPUSHONLY", 0
668 "P2SH(P2PK) with non-push scriptSig but no P2SH or SIGPUSHONLY", 0,
true
669 ).PushSig(
keys.key2).Opcode(
OP_NOP8).PushRedeem());
681 ).Num(0).PushSig(
keys.key1).PushSig(
keys.key1));
684 ).Num(11).PushSig(
keys.key0));
690 ).Num(11).PushSig(
keys.key0).PushRedeem());
696 ).PushSig(
keys.key0).PushRedeem());
700 0, 1).PushWitSig(
keys.key0).PushWitRedeem());
703 0, 1).PushWitSig(
keys.key0).Push(
keys.pubkey0).AsWit());
706 0, 1).PushWitSig(
keys.key0).PushWitRedeem().PushRedeem());
709 0, 1).PushWitSig(
keys.key0).Push(
keys.pubkey0).AsWit().PushRedeem());
723 "Basic P2WSH with the wrong key but no WITNESS",
SCRIPT_VERIFY_P2SH,
false, WitnessMode::SH
724 ).PushWitSig(
keys.key0).PushWitRedeem());
726 "Basic P2WPKH with the wrong key but no WITNESS",
SCRIPT_VERIFY_P2SH,
false, WitnessMode::PKH
727 ).PushWitSig(
keys.key0).Push(
keys.pubkey1).AsWit());
729 "Basic P2SH(P2WSH) with the wrong key but no WITNESS",
SCRIPT_VERIFY_P2SH,
true, WitnessMode::SH
730 ).PushWitSig(
keys.key0).PushWitRedeem().PushRedeem());
732 "Basic P2SH(P2WPKH) with the wrong key but no WITNESS",
SCRIPT_VERIFY_P2SH,
true, WitnessMode::PKH
733 ).PushWitSig(
keys.key0).Push(
keys.pubkey1).AsWit().PushRedeem());
786 0, 1).PushWitSig(
keys.key0C).PushWitRedeem());
789 0, 1).PushWitSig(
keys.key0C).Push(
keys.pubkey0C).AsWit());
792 0, 1).PushWitSig(
keys.key0C).PushWitRedeem().PushRedeem());
795 0, 1).PushWitSig(
keys.key0C).Push(
keys.pubkey0C).AsWit().PushRedeem());
881 for (
unsigned int idx = 0; idx <
json_tests.size(); idx++) {
887#ifdef UPDATE_JSON_TESTS
890 for (TestBuilder& test :
tests) {
893#ifdef UPDATE_JSON_TESTS
902#ifdef UPDATE_JSON_TESTS
921 for (
unsigned int idx = 0; idx <
tests.size(); idx++) {
927 unsigned int pos = 0;
930 for (i = 0; i < test[pos].
size()-1; i++) {
938 }
else if (
element ==
"#CONTROLBLOCK#") {
956 if (test.
size() < 4 + pos)
958 if (test.
size() != 1) {
985 static const unsigned char direct[] = { 1, 0x5a };
991 std::vector<std::vector<unsigned char> >
directStack;
1050 std::vector<unsigned char>
vchSig;
1060 std::vector<CKey>
keys;
1081 txTo12.vout[0].nValue = 2;
1108 std::vector<CKey>
keys;
1109 keys.push_back(key1);
keys.push_back(key2);
1127 keys.push_back(key2);
keys.push_back(key2);
1133 keys.push_back(key2);
keys.push_back(key1);
1165 std::vector<std::vector<uint8_t>> unused;
1169#define CHECK_SCRIPT_STATIC_SIZE(script, expected_size) \
1171 BOOST_CHECK_EQUAL((script).size(), (expected_size)); \
1172 BOOST_CHECK_EQUAL((script).capacity(), CScriptBase::STATIC_SIZE); \
1173 BOOST_CHECK_EQUAL((script).allocated_memory(), 0); \
1176#define CHECK_SCRIPT_DYNAMIC_SIZE(script, expected_size, expected_extra) \
1178 BOOST_CHECK_EQUAL((script).size(), (expected_size)); \
1179 BOOST_CHECK_EQUAL((script).capacity(), (expected_extra)); \
1180 BOOST_CHECK_EQUAL((script).allocated_memory(), (expected_extra)); \
1277 std::vector<CKey>
keys;
1278 std::vector<CPubKey> pubkeys;
1279 for (
int i = 0; i < 3; i++)
1282 keys.push_back(key);
1342 std::vector<unsigned char>
sig1;
1346 std::vector<unsigned char>
sig2;
1350 std::vector<unsigned char>
sig3;
1402 const auto invalid_pubkey{
"173d36c8c9c9c9ffffffffffff0200000000021e1e37373721361818181818181e1e1e1e19000000000000000000b19292929292926b006c9b9b9292"_hex_u8};
1430 for (
int i=0; i<67000; i++) {
1439 std::vector<unsigned char>
data(i,
'\111');
1455 static const unsigned char direct[] = { 1 };
1462 std::vector<unsigned char>
data(65535,
'\x42');
1474 std::string
derSig(
"304502207fa7a6d1e0ee81132a269ad84e68d695483745cde8b541e3bf630749894e342a022100c1f7ab20e13e22fb95281a870f3dcf38d782e53023ee313d741ad0cfbc0c5090");
1475 std::string
pubKey(
"03b0da749730dc9b4b1f4a14d6902877a92541f5368778853d9c4a0cb7802dcfb2");
1497template <
typename T>
1501 return {span.
begin(), span.end()};
1637 Assert(
tests.read(json_tests::bip341_wallet_vectors));
1641 for (
const auto&
vec :
vectors.getValues()) {
1645 std::vector<CTxOut>
utxos;
1646 for (
const auto&
utxo_spent :
vec[
"given"][
"utxosSpent"].getValues()) {
1654 txdata.
Init(tx, std::vector<CTxOut>{
utxos},
true);
1663 for (
const auto& input :
vec[
"inputSpending"].getValues()) {
1664 int txinpos = input[
"given"][
"txinIndex"].getInt<
int>();
1665 int hashtype = input[
"given"][
"hashType"].getInt<
int>();
1674 if (!input[
"given"][
"merkleRoot"].isNull()) {
1675 merkle_root =
uint256{
ParseHex(input[
"given"][
"merkleRoot"].get_str())};
1691 BOOST_CHECK_EQUAL(
HexStr(pubkey.ComputeTapTweakHash(merkle_root.
IsNull() ?
nullptr : &merkle_root)), input[
"intermediary"][
"tweak"].get_str());
1696 sed.m_annex_present =
false;
1709 constexpr uint256 hash1{
"8ad69ec7cf41c2a4001fd1f738bf1e505ce2277acdcaa63fe4765192497f47a7"};
1710 constexpr uint256 hash2{
"f224a923cd0021ab202ab139cc56802ddb92dcfc172b9212261a539df79a112a"};
1711 constexpr uint256 result{
"a64c5b7b943315f9b805d7a7296bedfcfd08919270a1f7a1466e98f8693d8cd9"};
1718 constexpr uint256 tlc0{
"edbc10c272a1215dcdcc11d605b9027b5ad6ed97cd45521203f136767b5b9c06"};
1719 constexpr uint256 tlc2{
"8b5c4f90ae6bf76e259dbef5d8a59df06359c391b59263741b25eca76451b27a"};
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
int64_t CAmount
Amount in satoshis (Can be negative)
static CAmount AmountFromValue(const UniValue &value)
#define Assert(val)
Identity function.
A hasher class for Bitcoin's 160-bit hash (SHA-256 + RIPEMD-160).
CHash160 & Write(std::span< const unsigned char > input)
void Finalize(std::span< unsigned char > output)
An encapsulated private key.
bool Sign(const uint256 &hash, std::vector< unsigned char > &vchSig, bool grind=true, uint32_t test_case=0) const
Create a DER-serialized signature.
void MakeNewKey(bool fCompressed)
Generate a new private key using a cryptographic PRNG.
CPubKey GetPubKey() const
Compute the public key from a private key.
void Set(const T pbegin, const T pend, bool fCompressedIn)
Initialize using begin and end iterators to byte data.
An outpoint - a combination of a transaction hash and an index n into its vout.
An encapsulated public key.
const unsigned char * data() const
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
const unsigned char * end() const
const unsigned char * begin() const
A hasher class for SHA-256.
void Finalize(unsigned char hash[OUTPUT_SIZE])
CSHA256 & Write(const unsigned char *data, size_t len)
Serialized script, used inside transaction inputs and outputs.
A reference to a CScript: the Hash160 of its serialization.
The basic transaction that is broadcasted on the network and contained in blocks.
An output of a transaction.
Fillable signing provider that keeps keys in an address->secret map.
A writer stream (for serialization) that computes a 256-bit hash.
A signature creator for transactions.
uint64_t randbits(int bits) noexcept
Generate a random (bits)-bit integer.
Minimal stream for reading from an existing byte array by std::span.
Utility class to construct Taproot outputs from internal key and script tree.
TaprootSpendData GetSpendData() const
Compute spending data (after Finalize()).
TaprootBuilder & Add(int depth, std::span< const unsigned char > script, int leaf_version, bool track=true)
Add a new script at a certain depth in the tree.
TaprootBuilder & Finalize(const XOnlyPubKey &internal_key)
Finalize the construction.
const std::string & get_str() const
std::string write(unsigned int prettyIndent=0, unsigned int indentLevel=0) const
static const XOnlyPubKey NUMS_H
Nothing Up My Sleeve point H Used as an internal key for provably disabling the key path spend see BI...
constexpr bool IsNull() const
constexpr unsigned char * begin()
Implements a drop-in replacement for std::vector<T> which stores up to N elements directly (without h...
void push_back(const T &value)
static constexpr script_verify_flags from_int(value_type f)
static const PrecomputedData data
Precomputed COutPoint and CCoins values.
CScript ParseScript(const std::string &s)
std::string FormatScript(const CScript &script)
std::string ScriptToAsmStr(const CScript &script, const bool fAttemptSighashDecode)
Create the assembly string representation of a CScript object.
UniValue ValueFromAmount(const CAmount amount)
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
#define T(expected, seed, data)
std::string HexStr(const std::span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
uint256 ComputeTapbranchHash(std::span< const unsigned char > a, std::span< const unsigned char > b)
Compute the BIP341 tapbranch hash from two branches.
bool SignatureHashSchnorr(uint256 &hash_out, ScriptExecutionData &execdata, const T &tx_to, uint32_t in_pos, uint8_t hash_type, SigVersion sigversion, const PrecomputedTransactionData &cache, MissingDataBehavior mdb)
int FindAndDelete(CScript &script, const CScript &b)
uint256 ComputeTapleafHash(uint8_t leaf_version, std::span< const unsigned char > script)
Compute the BIP341 tapleaf hash from leaf version & script.
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)
uint256 SignatureHash(const CScript &scriptCode, const T &txTo, unsigned int nIn, int32_t nHashType, const CAmount &amount, SigVersion sigversion, const PrecomputedTransactionData *cache, SigHashCache *sighash_cache)
std::vector< std::string > GetScriptFlagNames(script_verify_flags flags)
bool VerifyScript(const CScript &scriptSig, const CScript &scriptPubKey, const CScriptWitness *witness, script_verify_flags flags, const BaseSignatureChecker &checker, ScriptError *serror)
const HashWriter HASHER_TAPSIGHASH
Hasher with tag "TapSighash" pre-fed to it.
constexpr int MAX_SCRIPT_VERIFY_FLAGS_BITS
@ TAPROOT
Witness v1 with 32-byte program, not BIP16 P2SH-wrapped, key path spending; see BIP 341.
@ BASE
Bare scripts and BIP16 P2SH-wrapped redeemscripts.
@ WITNESS_V0
Witness v0 (P2WPKH and P2WSH); see BIP 141.
GenericTransactionSignatureChecker< CMutableTransaction > MutableTransactionSignatureChecker
constexpr uint8_t TAPROOT_LEAF_TAPSCRIPT
@ ASSERT_FAIL
Abort execution through assertion failure (for consensus code)
@ FAIL
Just act as if the signature was invalid.
@ SCRIPT_VERIFY_NULLDUMMY
@ SCRIPT_VERIFY_STRICTENC
@ SCRIPT_VERIFY_CLEANSTACK
@ SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY
@ SCRIPT_VERIFY_SIGPUSHONLY
@ SCRIPT_VERIFY_WITNESS_PUBKEYTYPE
@ SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_WITNESS_PROGRAM
@ SCRIPT_VERIFY_MINIMALDATA
UniValue read_json(std::string_view jsondata)
CKey GenerateRandomKey(bool compressed) noexcept
FILE * fopen(const fs::path &p, const char *mode)
std::pair< opcodetype, std::vector< unsigned char > > Opcode
""_hex is a compile-time user-defined literal returning a std::array<std::byte>, equivalent to ParseH...
auto Join(const C &container, const S &separator, UnaryOp unary_op)
Join all container items.
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
constexpr TransactionSerParams TX_WITH_WITNESS
static CTransactionRef MakeTransactionRef(Tx &&txIn)
std::shared_ptr< const CTransaction > CTransactionRef
bool CheckMinimalPush(const std::vector< unsigned char > &data, opcodetype opcode)
opcodetype
Script opcodes.
constexpr unsigned int MAX_SCRIPT_ELEMENT_SIZE
std::vector< unsigned char > ToByteVector(const T &in)
std::string ScriptErrorString(const ScriptError serror)
enum ScriptError_t ScriptError
@ SCRIPT_ERR_OP_CODESEPARATOR
@ SCRIPT_ERR_SIG_PUSHONLY
@ SCRIPT_ERR_NUMEQUALVERIFY
@ SCRIPT_ERR_DISABLED_OPCODE
@ SCRIPT_ERR_INVALID_ALTSTACK_OPERATION
@ SCRIPT_ERR_DISCOURAGE_UPGRADABLE_WITNESS_PROGRAM
@ SCRIPT_ERR_TAPSCRIPT_EMPTY_PUBKEY
@ SCRIPT_ERR_TAPSCRIPT_MINIMALIF
@ SCRIPT_ERR_UNKNOWN_ERROR
@ SCRIPT_ERR_WITNESS_PROGRAM_WRONG_LENGTH
@ SCRIPT_ERR_SIG_HASHTYPE
@ SCRIPT_ERR_CHECKSIGVERIFY
@ SCRIPT_ERR_WITNESS_MALLEATED_P2SH
@ SCRIPT_ERR_WITNESS_MALLEATED
@ SCRIPT_ERR_DISCOURAGE_UPGRADABLE_NOPS
@ SCRIPT_ERR_INVALID_STACK_OPERATION
@ SCRIPT_ERR_WITNESS_UNEXPECTED
@ SCRIPT_ERR_NEGATIVE_LOCKTIME
@ SCRIPT_ERR_WITNESS_PROGRAM_MISMATCH
@ SCRIPT_ERR_SIG_NULLFAIL
@ SCRIPT_ERR_SIG_NULLDUMMY
@ SCRIPT_ERR_CHECKMULTISIGVERIFY
@ SCRIPT_ERR_UNSATISFIED_LOCKTIME
@ SCRIPT_ERR_WITNESS_PUBKEYTYPE
@ SCRIPT_ERR_SIG_FINDANDDELETE
@ SCRIPT_ERR_PUBKEY_COUNT
@ SCRIPT_ERR_WITNESS_PROGRAM_WITNESS_EMPTY
@ SCRIPT_ERR_UNBALANCED_CONDITIONAL
static std::string FormatScriptError(ScriptError_t err)
static TxoutType GetTxoutType(const CScript &output_script)
Return the TxoutType of a script without exposing Solver details.
static void NegateSignatureS(std::vector< unsigned char > &vchSig)
#define CHECK_SCRIPT_STATIC_SIZE(script, expected_size)
static ScriptError_t ParseScriptError(const std::string &name)
SignatureData CombineSignatures(const CTxOut &txout, const CMutableTransaction &tx, const SignatureData &scriptSig1, const SignatureData &scriptSig2)
static ScriptErrorDesc script_errors[]
static std::string FormatScriptFlags(script_verify_flags flags)
CScript ToScript(const T &byte_container)
#define CHECK_SCRIPT_DYNAMIC_SIZE(script, expected_size, expected_extra)
static CScript sign_multisig(const CScript &scriptPubKey, const std::vector< CKey > &keys, const CTransaction &transaction)
script_verify_flags ParseScriptFlags(std::string strFlags)
BOOST_AUTO_TEST_CASE(script_build)
static const script_verify_flags gFlags
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_seckey_negate(const secp256k1_context *ctx, unsigned char *seckey) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2)
Negates a secret key in place.
SECP256K1_API const secp256k1_context *const secp256k1_context_static
A built-in constant secp256k1 context object with static storage duration, to be used in conjunction ...
bool ProduceSignature(const SigningProvider &provider, const BaseSignatureCreator &creator, const CScript &fromPubKey, SignatureData &sigdata)
Produce a script signature using a generic signature creator.
static bool GetPubKey(const SigningProvider &provider, const SignatureData &sigdata, const CKeyID &address, CPubKey &pubkey)
SignatureData DataFromTransaction(const CMutableTransaction &tx, unsigned int nIn, const CTxOut &txout)
Extract signature data from a transaction input, and insert it.
std::pair< CPubKey, std::vector< unsigned char > > SigPair
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.
CScript GetScriptForRawPubKey(const CPubKey &pubKey)
Generate a P2PK script for the given pubkey.
@ NULL_DATA
unspendable OP_RETURN script that carries data
constexpr auto MakeUCharSpan(const V &v) -> decltype(UCharSpanCast(std::span{v}))
Like the std::span constructor, but for (const) unsigned char member types only.
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
std::vector< std::vector< unsigned char > > stack
A type to represent integers in the type system.
void Init(const T &tx, std::vector< CTxOut > &&spent_outputs, bool force=false)
Initialize this PrecomputedTransactionData with transaction data.
uint256 m_sequences_single_hash
bool m_bip341_taproot_ready
Whether the 5 fields above are initialized.
uint256 m_prevouts_single_hash
uint256 m_spent_amounts_single_hash
uint256 m_spent_scripts_single_hash
uint256 m_outputs_single_hash
bool m_annex_init
Whether m_annex_present and (when needed) m_annex_hash are initialized.
void DoTest(const CScript &scriptPubKey, const CScript &scriptSig, const CScriptWitness &scriptWitness, script_verify_flags flags, const std::string &message, int scriptError, CAmount nValue=0)
void MergeSignatureData(SignatureData sigdata)
std::map< CKeyID, SigPair > signatures
BIP 174 style partial signatures for the input. May contain all signatures necessary for producing a ...
CScript scriptSig
The scriptSig of an input. Contains complete signatures or the traditional partial signatures format.
std::vector< uint16_t > keys
FuzzedDataProvider provider
CMutableTransaction BuildSpendingTransaction(const CScript &scriptSig, const CScriptWitness &scriptWitness, const CTransaction &txCredit)
CMutableTransaction BuildCreditingTransaction(const CScript &scriptPubKey, CAmount nValue)
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_CHECK_NE(OneL.ToString(), ArrayToString(ZeroArray, 32))
constexpr std::array tests
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.