Bitcoin Core  22.99.0
P2P Digital Currency
script_standard_tests.cpp
Go to the documentation of this file.
1 // Copyright (c) 2017-2021 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #include <test/data/bip341_wallet_vectors.json.h>
6 
7 #include <key.h>
8 #include <key_io.h>
9 #include <script/script.h>
10 #include <script/signingprovider.h>
11 #include <script/standard.h>
12 #include <test/util/setup_common.h>
13 #include <util/strencodings.h>
14 
15 #include <boost/test/unit_test.hpp>
16 
17 #include <univalue.h>
18 
19 
20 BOOST_FIXTURE_TEST_SUITE(script_standard_tests, BasicTestingSetup)
21 
22 BOOST_AUTO_TEST_CASE(dest_default_is_no_dest)
23 {
24  CTxDestination dest;
26 }
27 
28 BOOST_AUTO_TEST_CASE(script_standard_Solver_success)
29 {
30  CKey keys[3];
31  CPubKey pubkeys[3];
32  for (int i = 0; i < 3; i++) {
33  keys[i].MakeNewKey(true);
34  pubkeys[i] = keys[i].GetPubKey();
35  }
36 
37  CScript s;
38  std::vector<std::vector<unsigned char> > solutions;
39 
40  // TxoutType::PUBKEY
41  s.clear();
42  s << ToByteVector(pubkeys[0]) << OP_CHECKSIG;
44  BOOST_CHECK_EQUAL(solutions.size(), 1U);
45  BOOST_CHECK(solutions[0] == ToByteVector(pubkeys[0]));
46 
47  // TxoutType::PUBKEYHASH
48  s.clear();
49  s << OP_DUP << OP_HASH160 << ToByteVector(pubkeys[0].GetID()) << OP_EQUALVERIFY << OP_CHECKSIG;
51  BOOST_CHECK_EQUAL(solutions.size(), 1U);
52  BOOST_CHECK(solutions[0] == ToByteVector(pubkeys[0].GetID()));
53 
54  // TxoutType::SCRIPTHASH
55  CScript redeemScript(s); // initialize with leftover P2PKH script
56  s.clear();
57  s << OP_HASH160 << ToByteVector(CScriptID(redeemScript)) << OP_EQUAL;
59  BOOST_CHECK_EQUAL(solutions.size(), 1U);
60  BOOST_CHECK(solutions[0] == ToByteVector(CScriptID(redeemScript)));
61 
62  // TxoutType::MULTISIG
63  s.clear();
64  s << OP_1 <<
65  ToByteVector(pubkeys[0]) <<
66  ToByteVector(pubkeys[1]) <<
69  BOOST_CHECK_EQUAL(solutions.size(), 4U);
70  BOOST_CHECK(solutions[0] == std::vector<unsigned char>({1}));
71  BOOST_CHECK(solutions[1] == ToByteVector(pubkeys[0]));
72  BOOST_CHECK(solutions[2] == ToByteVector(pubkeys[1]));
73  BOOST_CHECK(solutions[3] == std::vector<unsigned char>({2}));
74 
75  s.clear();
76  s << OP_2 <<
77  ToByteVector(pubkeys[0]) <<
78  ToByteVector(pubkeys[1]) <<
79  ToByteVector(pubkeys[2]) <<
82  BOOST_CHECK_EQUAL(solutions.size(), 5U);
83  BOOST_CHECK(solutions[0] == std::vector<unsigned char>({2}));
84  BOOST_CHECK(solutions[1] == ToByteVector(pubkeys[0]));
85  BOOST_CHECK(solutions[2] == ToByteVector(pubkeys[1]));
86  BOOST_CHECK(solutions[3] == ToByteVector(pubkeys[2]));
87  BOOST_CHECK(solutions[4] == std::vector<unsigned char>({3}));
88 
89  // TxoutType::NULL_DATA
90  s.clear();
91  s << OP_RETURN <<
92  std::vector<unsigned char>({0}) <<
93  std::vector<unsigned char>({75}) <<
94  std::vector<unsigned char>({255});
96  BOOST_CHECK_EQUAL(solutions.size(), 0U);
97 
98  // TxoutType::WITNESS_V0_KEYHASH
99  s.clear();
100  s << OP_0 << ToByteVector(pubkeys[0].GetID());
102  BOOST_CHECK_EQUAL(solutions.size(), 1U);
103  BOOST_CHECK(solutions[0] == ToByteVector(pubkeys[0].GetID()));
104 
105  // TxoutType::WITNESS_V0_SCRIPTHASH
106  uint256 scriptHash;
107  CSHA256().Write(redeemScript.data(), redeemScript.size())
108  .Finalize(scriptHash.begin());
109 
110  s.clear();
111  s << OP_0 << ToByteVector(scriptHash);
113  BOOST_CHECK_EQUAL(solutions.size(), 1U);
114  BOOST_CHECK(solutions[0] == ToByteVector(scriptHash));
115 
116  // TxoutType::WITNESS_V1_TAPROOT
117  s.clear();
120  BOOST_CHECK_EQUAL(solutions.size(), 1U);
121  BOOST_CHECK(solutions[0] == ToByteVector(uint256::ZERO));
122 
123  // TxoutType::WITNESS_UNKNOWN
124  s.clear();
127  BOOST_CHECK_EQUAL(solutions.size(), 2U);
128  BOOST_CHECK(solutions[0] == std::vector<unsigned char>{16});
129  BOOST_CHECK(solutions[1] == ToByteVector(uint256::ONE));
130 
131  // TxoutType::NONSTANDARD
132  s.clear();
133  s << OP_9 << OP_ADD << OP_11 << OP_EQUAL;
135 }
136 
137 BOOST_AUTO_TEST_CASE(script_standard_Solver_failure)
138 {
139  CKey key;
140  CPubKey pubkey;
141  key.MakeNewKey(true);
142  pubkey = key.GetPubKey();
143 
144  CScript s;
145  std::vector<std::vector<unsigned char> > solutions;
146 
147  // TxoutType::PUBKEY with incorrectly sized pubkey
148  s.clear();
149  s << std::vector<unsigned char>(30, 0x01) << OP_CHECKSIG;
151 
152  // TxoutType::PUBKEYHASH with incorrectly sized key hash
153  s.clear();
154  s << OP_DUP << OP_HASH160 << ToByteVector(pubkey) << OP_EQUALVERIFY << OP_CHECKSIG;
156 
157  // TxoutType::SCRIPTHASH with incorrectly sized script hash
158  s.clear();
159  s << OP_HASH160 << std::vector<unsigned char>(21, 0x01) << OP_EQUAL;
161 
162  // TxoutType::MULTISIG 0/2
163  s.clear();
164  s << OP_0 << ToByteVector(pubkey) << OP_1 << OP_CHECKMULTISIG;
166 
167  // TxoutType::MULTISIG 2/1
168  s.clear();
169  s << OP_2 << ToByteVector(pubkey) << OP_1 << OP_CHECKMULTISIG;
171 
172  // TxoutType::MULTISIG n = 2 with 1 pubkey
173  s.clear();
174  s << OP_1 << ToByteVector(pubkey) << OP_2 << OP_CHECKMULTISIG;
176 
177  // TxoutType::MULTISIG n = 1 with 0 pubkeys
178  s.clear();
179  s << OP_1 << OP_1 << OP_CHECKMULTISIG;
181 
182  // TxoutType::NULL_DATA with other opcodes
183  s.clear();
184  s << OP_RETURN << std::vector<unsigned char>({75}) << OP_ADD;
186 
187  // TxoutType::WITNESS_UNKNOWN with incorrect program size
188  s.clear();
189  s << OP_0 << std::vector<unsigned char>(19, 0x01);
191 }
192 
193 BOOST_AUTO_TEST_CASE(script_standard_ExtractDestination)
194 {
195  CKey key;
196  CPubKey pubkey;
197  key.MakeNewKey(true);
198  pubkey = key.GetPubKey();
199 
200  CScript s;
201  CTxDestination address;
202 
203  // TxoutType::PUBKEY
204  s.clear();
205  s << ToByteVector(pubkey) << OP_CHECKSIG;
206  BOOST_CHECK(ExtractDestination(s, address));
207  BOOST_CHECK(std::get<PKHash>(address) == PKHash(pubkey));
208 
209  // TxoutType::PUBKEYHASH
210  s.clear();
211  s << OP_DUP << OP_HASH160 << ToByteVector(pubkey.GetID()) << OP_EQUALVERIFY << OP_CHECKSIG;
212  BOOST_CHECK(ExtractDestination(s, address));
213  BOOST_CHECK(std::get<PKHash>(address) == PKHash(pubkey));
214 
215  // TxoutType::SCRIPTHASH
216  CScript redeemScript(s); // initialize with leftover P2PKH script
217  s.clear();
218  s << OP_HASH160 << ToByteVector(CScriptID(redeemScript)) << OP_EQUAL;
219  BOOST_CHECK(ExtractDestination(s, address));
220  BOOST_CHECK(std::get<ScriptHash>(address) == ScriptHash(redeemScript));
221 
222  // TxoutType::MULTISIG
223  s.clear();
224  s << OP_1 << ToByteVector(pubkey) << OP_1 << OP_CHECKMULTISIG;
225  BOOST_CHECK(!ExtractDestination(s, address));
226 
227  // TxoutType::NULL_DATA
228  s.clear();
229  s << OP_RETURN << std::vector<unsigned char>({75});
230  BOOST_CHECK(!ExtractDestination(s, address));
231 
232  // TxoutType::WITNESS_V0_KEYHASH
233  s.clear();
234  s << OP_0 << ToByteVector(pubkey.GetID());
235  BOOST_CHECK(ExtractDestination(s, address));
236  WitnessV0KeyHash keyhash;
237  CHash160().Write(pubkey).Finalize(keyhash);
238  BOOST_CHECK(std::get<WitnessV0KeyHash>(address) == keyhash);
239 
240  // TxoutType::WITNESS_V0_SCRIPTHASH
241  s.clear();
242  WitnessV0ScriptHash scripthash;
243  CSHA256().Write(redeemScript.data(), redeemScript.size()).Finalize(scripthash.begin());
244  s << OP_0 << ToByteVector(scripthash);
245  BOOST_CHECK(ExtractDestination(s, address));
246  BOOST_CHECK(std::get<WitnessV0ScriptHash>(address) == scripthash);
247 
248  // TxoutType::WITNESS_UNKNOWN with unknown version
249  s.clear();
250  s << OP_1 << ToByteVector(pubkey);
251  BOOST_CHECK(ExtractDestination(s, address));
252  WitnessUnknown unk;
253  unk.length = 33;
254  unk.version = 1;
255  std::copy(pubkey.begin(), pubkey.end(), unk.program);
256  BOOST_CHECK(std::get<WitnessUnknown>(address) == unk);
257 }
258 
259 BOOST_AUTO_TEST_CASE(script_standard_GetScriptFor_)
260 {
261  CKey keys[3];
262  CPubKey pubkeys[3];
263  for (int i = 0; i < 3; i++) {
264  keys[i].MakeNewKey(true);
265  pubkeys[i] = keys[i].GetPubKey();
266  }
267 
268  CScript expected, result;
269 
270  // PKHash
271  expected.clear();
272  expected << OP_DUP << OP_HASH160 << ToByteVector(pubkeys[0].GetID()) << OP_EQUALVERIFY << OP_CHECKSIG;
273  result = GetScriptForDestination(PKHash(pubkeys[0]));
274  BOOST_CHECK(result == expected);
275 
276  // CScriptID
277  CScript redeemScript(result);
278  expected.clear();
279  expected << OP_HASH160 << ToByteVector(CScriptID(redeemScript)) << OP_EQUAL;
280  result = GetScriptForDestination(ScriptHash(redeemScript));
281  BOOST_CHECK(result == expected);
282 
283  // CNoDestination
284  expected.clear();
286  BOOST_CHECK(result == expected);
287 
288  // GetScriptForRawPubKey
289  expected.clear();
290  expected << ToByteVector(pubkeys[0]) << OP_CHECKSIG;
291  result = GetScriptForRawPubKey(pubkeys[0]);
292  BOOST_CHECK(result == expected);
293 
294  // GetScriptForMultisig
295  expected.clear();
296  expected << OP_2 <<
297  ToByteVector(pubkeys[0]) <<
298  ToByteVector(pubkeys[1]) <<
299  ToByteVector(pubkeys[2]) <<
301  result = GetScriptForMultisig(2, std::vector<CPubKey>(pubkeys, pubkeys + 3));
302  BOOST_CHECK(result == expected);
303 
304  // WitnessV0KeyHash
305  expected.clear();
306  expected << OP_0 << ToByteVector(pubkeys[0].GetID());
308  BOOST_CHECK(result == expected);
309  result = GetScriptForDestination(WitnessV0KeyHash(pubkeys[0].GetID()));
310  BOOST_CHECK(result == expected);
311 
312  // WitnessV0ScriptHash (multisig)
313  CScript witnessScript;
314  witnessScript << OP_1 << ToByteVector(pubkeys[0]) << OP_1 << OP_CHECKMULTISIG;
315 
316  uint256 scriptHash;
317  CSHA256().Write(witnessScript.data(), witnessScript.size())
318  .Finalize(scriptHash.begin());
319 
320  expected.clear();
321  expected << OP_0 << ToByteVector(scriptHash);
322  result = GetScriptForDestination(WitnessV0ScriptHash(witnessScript));
323  BOOST_CHECK(result == expected);
324 }
325 
326 BOOST_AUTO_TEST_CASE(script_standard_taproot_builder)
327 {
368  BOOST_CHECK_EQUAL(TaprootBuilder::ValidDepths({2,2,2,3,4,5,6,7,8,9,10,11,12,14,14,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,31,31,31,31,31,31,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,128}), true);
369  BOOST_CHECK_EQUAL(TaprootBuilder::ValidDepths({128,128,127,126,125,124,123,122,121,120,119,118,117,116,115,114,113,112,111,110,109,108,107,106,105,104,103,102,101,100,99,98,97,96,95,94,93,92,91,90,89,88,87,86,85,84,83,82,81,80,79,78,77,76,75,74,73,72,71,70,69,68,67,66,65,64,63,62,61,60,59,58,57,56,55,54,53,52,51,50,49,48,47,46,45,44,43,42,41,40,39,38,37,36,35,34,33,32,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1}), true);
370  BOOST_CHECK_EQUAL(TaprootBuilder::ValidDepths({129,129,128,127,126,125,124,123,122,121,120,119,118,117,116,115,114,113,112,111,110,109,108,107,106,105,104,103,102,101,100,99,98,97,96,95,94,93,92,91,90,89,88,87,86,85,84,83,82,81,80,79,78,77,76,75,74,73,72,71,70,69,68,67,66,65,64,63,62,61,60,59,58,57,56,55,54,53,52,51,50,49,48,47,46,45,44,43,42,41,40,39,38,37,36,35,34,33,32,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1}), false);
371 
372  XOnlyPubKey key_inner{ParseHex("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798")};
373  XOnlyPubKey key_1{ParseHex("c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5")};
374  XOnlyPubKey key_2{ParseHex("f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9")};
375  CScript script_1 = CScript() << ToByteVector(key_1) << OP_CHECKSIG;
376  CScript script_2 = CScript() << ToByteVector(key_2) << OP_CHECKSIG;
377  uint256 hash_3 = uint256S("31fe7061656bea2a36aa60a2f7ef940578049273746935d296426dc0afd86b68");
378 
379  TaprootBuilder builder;
380  BOOST_CHECK(builder.IsValid() && builder.IsComplete());
381  builder.Add(2, script_2, 0xc0);
382  BOOST_CHECK(builder.IsValid() && !builder.IsComplete());
383  builder.AddOmitted(2, hash_3);
384  BOOST_CHECK(builder.IsValid() && !builder.IsComplete());
385  builder.Add(1, script_1, 0xc0);
386  BOOST_CHECK(builder.IsValid() && builder.IsComplete());
387  builder.Finalize(key_inner);
388  BOOST_CHECK(builder.IsValid() && builder.IsComplete());
389  BOOST_CHECK_EQUAL(EncodeDestination(builder.GetOutput()), "bc1pj6gaw944fy0xpmzzu45ugqde4rz7mqj5kj0tg8kmr5f0pjq8vnaqgynnge");
390 }
391 
392 BOOST_AUTO_TEST_CASE(bip341_spk_test_vectors)
393 {
394  using control_set = decltype(TaprootSpendData::scripts)::mapped_type;
395 
396  UniValue tests;
397  tests.read((const char*)json_tests::bip341_wallet_vectors, sizeof(json_tests::bip341_wallet_vectors));
398 
399  const auto& vectors = tests["scriptPubKey"];
400 
401  for (const auto& vec : vectors.getValues()) {
402  TaprootBuilder spktest;
403  std::map<std::pair<CScript, int>, int> scriptposes;
404  std::function<void (const UniValue&, int)> parse_tree = [&](const UniValue& node, int depth) {
405  if (node.isNull()) return;
406  if (node.isObject()) {
407  auto script_bytes = ParseHex(node["script"].get_str());
408  CScript script(script_bytes.begin(), script_bytes.end());
409  int idx = node["id"].get_int();
410  int leaf_version = node["leafVersion"].get_int();
411  scriptposes[{script, leaf_version}] = idx;
412  spktest.Add(depth, script, leaf_version);
413  } else {
414  parse_tree(node[0], depth + 1);
415  parse_tree(node[1], depth + 1);
416  }
417  };
418  parse_tree(vec["given"]["scriptTree"], 0);
419  spktest.Finalize(XOnlyPubKey(ParseHex(vec["given"]["internalPubkey"].get_str())));
420  BOOST_CHECK_EQUAL(HexStr(GetScriptForDestination(spktest.GetOutput())), vec["expected"]["scriptPubKey"].get_str());
421  BOOST_CHECK_EQUAL(EncodeDestination(spktest.GetOutput()), vec["expected"]["bip350Address"].get_str());
422  auto spend_data = spktest.GetSpendData();
423  BOOST_CHECK_EQUAL(vec["intermediary"]["merkleRoot"].isNull(), spend_data.merkle_root.IsNull());
424  if (!spend_data.merkle_root.IsNull()) {
425  BOOST_CHECK_EQUAL(vec["intermediary"]["merkleRoot"].get_str(), HexStr(spend_data.merkle_root));
426  }
427  BOOST_CHECK_EQUAL(spend_data.scripts.size(), scriptposes.size());
428  for (const auto& scriptpos : scriptposes) {
429  BOOST_CHECK(spend_data.scripts[scriptpos.first] == control_set{ParseHex(vec["expected"]["scriptPathControlBlocks"][scriptpos.second].get_str())});
430  }
431  }
432 }
433 
ParseHex
std::vector< unsigned char > ParseHex(const char *psz)
Definition: strencodings.cpp:84
WitnessUnknown
CTxDestination subtype to encode any future Witness version.
Definition: standard.h:125
CSHA256::Write
CSHA256 & Write(const unsigned char *data, size_t len)
Definition: sha256.cpp:689
Solver
TxoutType Solver(const CScript &scriptPubKey, std::vector< std::vector< unsigned char >> &vSolutionsRet)
Parse a scriptPubKey and identify script type for standard scripts.
Definition: standard.cpp:144
CKey::MakeNewKey
void MakeNewKey(bool fCompressed)
Generate a new private key using a cryptographic PRNG.
Definition: key.cpp:160
TaprootSpendData::scripts
std::map< std::pair< CScript, int >, std::set< std::vector< unsigned char >, ShortestVectorFirstComparator > > scripts
Map from (script, leaf_version) to (sets of) control blocks.
Definition: standard.h:219
key_io.h
setup_common.h
TxoutType::NONSTANDARD
@ NONSTANDARD
TxoutType::WITNESS_UNKNOWN
@ WITNESS_UNKNOWN
Only for Witness versions not already defined above.
GetScriptForDestination
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
Definition: standard.cpp:310
WitnessUnknown::version
unsigned int version
Definition: standard.h:127
OP_ADD
@ OP_ADD
Definition: script.h:154
OP_CHECKMULTISIG
@ OP_CHECKMULTISIG
Definition: script.h:185
TaprootBuilder::GetSpendData
TaprootSpendData GetSpendData() const
Compute spending data (after Finalize()).
Definition: standard.cpp:464
BaseHash::begin
unsigned char * begin()
Definition: hash_type.h:18
WitnessUnknown::length
unsigned int length
Definition: standard.h:128
XOnlyPubKey
Definition: pubkey.h:224
OP_3
@ OP_3
Definition: script.h:79
UniValue::read
bool read(const char *raw, size_t len)
Definition: univalue_read.cpp:259
BOOST_FIXTURE_TEST_SUITE
#define BOOST_FIXTURE_TEST_SUITE(a, b)
Definition: object.cpp:14
CScript::clear
void clear()
Definition: script.h:549
BOOST_AUTO_TEST_SUITE_END
BOOST_AUTO_TEST_SUITE_END()
TxoutType::WITNESS_V1_TAPROOT
@ WITNESS_V1_TAPROOT
UniValue
Definition: univalue.h:17
WitnessV0KeyHash
Definition: standard.h:109
signingprovider.h
OP_9
@ OP_9
Definition: script.h:85
CPubKey::begin
const unsigned char * begin() const
Definition: pubkey.h:114
OP_1
@ OP_1
Definition: script.h:76
strencodings.h
OP_0
@ OP_0
Definition: script.h:69
TxoutType::WITNESS_V0_SCRIPTHASH
@ WITNESS_V0_SCRIPTHASH
OP_RETURN
@ OP_RETURN
Definition: script.h:104
ToByteVector
std::vector< unsigned char > ToByteVector(const T &in)
Definition: script.h:60
TxoutType::PUBKEY
@ PUBKEY
CTxDestination
std::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:157
TaprootBuilder::GetOutput
WitnessV1Taproot GetOutput()
Compute scriptPubKey (after Finalize()).
Definition: standard.cpp:462
OP_16
@ OP_16
Definition: script.h:92
IsValidDestination
bool IsValidDestination(const CTxDestination &dest)
Check whether a CTxDestination is a CNoDestination.
Definition: standard.cpp:332
GetScriptForRawPubKey
CScript GetScriptForRawPubKey(const CPubKey &pubKey)
Generate a P2PK script for the given pubkey.
Definition: standard.cpp:315
GetScriptForMultisig
CScript GetScriptForMultisig(int nRequired, const std::vector< CPubKey > &keys)
Generate a multisig script.
Definition: standard.cpp:320
CHash160
A hasher class for Bitcoin's 160-bit hash (SHA-256 + RIPEMD-160).
Definition: hash.h:49
OP_EQUAL
@ OP_EQUAL
Definition: script.h:139
CPubKey::end
const unsigned char * end() const
Definition: pubkey.h:115
univalue.h
CHash160::Finalize
void Finalize(Span< unsigned char > output)
Definition: hash.h:55
TaprootBuilder::Add
TaprootBuilder & Add(int depth, const CScript &script, int leaf_version, bool track=true)
Add a new script at a certain depth in the tree.
Definition: standard.cpp:428
standard.h
BasicTestingSetup
Basic testing setup.
Definition: setup_common.h:83
OP_2
@ OP_2
Definition: script.h:78
TxoutType::SCRIPTHASH
@ SCRIPTHASH
uint256::ZERO
static const uint256 ZERO
Definition: uint256.h:131
uint256
256-bit opaque blob.
Definition: uint256.h:126
uint256S
uint256 uint256S(const char *str)
Definition: uint256.h:139
CSHA256::Finalize
void Finalize(unsigned char hash[OUTPUT_SIZE])
Definition: sha256.cpp:715
CKey::GetPubKey
CPubKey GetPubKey() const
Compute the public key from a private key.
Definition: key.cpp:187
CScript
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:405
TaprootBuilder::ValidDepths
static bool ValidDepths(const std::vector< int > &depths)
Check if a list of depths is legal (will lead to IsComplete()).
Definition: standard.cpp:405
TaprootBuilder::IsComplete
bool IsComplete() const
Return whether there were either no leaves, or the leaves form a Huffman tree.
Definition: standard.h:308
script.h
ExtractDestination
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a standard scriptPubKey for the destination address.
Definition: standard.cpp:213
CNoDestination
Definition: standard.h:73
OP_HASH160
@ OP_HASH160
Definition: script.h:180
TxoutType::NULL_DATA
@ NULL_DATA
unspendable OP_RETURN script that carries data
TxoutType::PUBKEYHASH
@ PUBKEYHASH
PKHash
Definition: standard.h:79
key.h
CPubKey
An encapsulated public key.
Definition: pubkey.h:33
CKey
An encapsulated private key.
Definition: key.h:26
Hash160
uint160 Hash160(const T1 &in1)
Compute the 160-bit hash an object.
Definition: hash.h:92
prevector::data
value_type * data()
Definition: prevector.h:528
prevector::size
size_type size() const
Definition: prevector.h:282
CHash160::Write
CHash160 & Write(Span< const unsigned char > input)
Definition: hash.h:62
TxoutType::MULTISIG
@ MULTISIG
CSHA256
A hasher class for SHA-256.
Definition: sha256.h:13
TaprootBuilder::IsValid
bool IsValid() const
Return true if so far all input was valid.
Definition: standard.h:306
node
Definition: init.h:22
OP_EQUALVERIFY
@ OP_EQUALVERIFY
Definition: script.h:140
TaprootBuilder::Finalize
TaprootBuilder & Finalize(const XOnlyPubKey &internal_key)
Finalize the construction.
Definition: standard.cpp:451
TaprootBuilder
Utility class to construct Taproot outputs from internal key and script tree.
Definition: standard.h:225
TxoutType::WITNESS_V0_KEYHASH
@ WITNESS_V0_KEYHASH
WitnessV0ScriptHash
Definition: standard.h:102
CScriptID
A reference to a CScript: the Hash160 of its serialization (see script.h)
Definition: standard.h:25
HexStr
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
Definition: strencodings.cpp:511
OP_CHECKSIG
@ OP_CHECKSIG
Definition: script.h:183
OP_11
@ OP_11
Definition: script.h:87
TaprootBuilder::AddOmitted
TaprootBuilder & AddOmitted(int depth, const uint256 &hash)
Like Add(), but for a Merkle node with a given hash to the tree.
Definition: standard.cpp:441
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(dest_default_is_no_dest)
Definition: script_standard_tests.cpp:22
ScriptHash
Definition: standard.h:89
base_blob::begin
unsigned char * begin()
Definition: uint256.h:60
OP_DUP
@ OP_DUP
Definition: script.h:118
EncodeDestination
std::string EncodeDestination(const CTxDestination &dest)
Definition: key_io.cpp:276
BOOST_CHECK
#define BOOST_CHECK(expr)
Definition: object.cpp:17
BOOST_CHECK_EQUAL
#define BOOST_CHECK_EQUAL(v1, v2)
Definition: object.cpp:18
WitnessUnknown::program
unsigned char program[40]
Definition: standard.h:129
CPubKey::GetID
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
Definition: pubkey.h:164
uint256::ONE
static const uint256 ONE
Definition: uint256.h:132