Bitcoin Core 31.99.0
P2P Digital Currency
script.h
Go to the documentation of this file.
1// Copyright (c) 2009-2010 Satoshi Nakamoto
2// Copyright (c) 2009-present The Bitcoin Core developers
3// Distributed under the MIT software license, see the accompanying
4// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6#ifndef BITCOIN_SCRIPT_SCRIPT_H
7#define BITCOIN_SCRIPT_SCRIPT_H
8
9#include <attributes.h>
10#include <crypto/common.h>
11#include <prevector.h>
12#include <serialize.h>
13#include <uint256.h>
14#include <util/hash_type.h>
15
16#include <cassert>
17#include <cstddef>
18#include <cstdint>
19#include <iterator>
20#include <limits>
21#include <span>
22#include <stdexcept>
23#include <string>
24#include <type_traits>
25#include <utility>
26#include <vector>
27
28// Maximum number of bytes pushable to the stack
29static const unsigned int MAX_SCRIPT_ELEMENT_SIZE = 520;
30
31// Maximum number of non-push operations per script
32static const int MAX_OPS_PER_SCRIPT = 201;
33
34// Maximum number of public keys per multisig
35static const int MAX_PUBKEYS_PER_MULTISIG = 20;
36
38static constexpr unsigned int MAX_PUBKEYS_PER_MULTI_A = 999;
39
40// Maximum script length in bytes
41static const int MAX_SCRIPT_SIZE = 10000;
42
43// Maximum number of values on script interpreter stack
44static const int MAX_STACK_SIZE = 1000;
45
46// Threshold for nLockTime: below this value it is interpreted as block number,
47// otherwise as UNIX timestamp.
48static const unsigned int LOCKTIME_THRESHOLD = 500000000; // Tue Nov 5 00:53:20 1985 UTC
49
50// Maximum nLockTime. Since a lock time indicates the last invalid timestamp, a
51// transaction with this lock time will never be valid unless lock time
52// checking is disabled (by setting all input sequence numbers to
53// SEQUENCE_FINAL).
54static const uint32_t LOCKTIME_MAX = 0xFFFFFFFFU;
55
56// Tag for input annex. If there are at least two witness elements for a transaction input,
57// and the first byte of the last element is 0x50, this last element is called annex, and
58// has meanings independent of the script
59static constexpr unsigned int ANNEX_TAG = 0x50;
60
61// Validation weight per passing signature (Tapscript only, see BIP 342).
62static constexpr int64_t VALIDATION_WEIGHT_PER_SIGOP_PASSED{50};
63
64// How much weight budget is added to the witness size (Tapscript only, see BIP 342).
65static constexpr int64_t VALIDATION_WEIGHT_OFFSET{50};
66
67template <typename T>
68std::vector<unsigned char> ToByteVector(const T& in)
69{
70 return std::vector<unsigned char>(in.begin(), in.end());
71}
72
75{
76 // push value
77 OP_0 = 0x00,
82 OP_1NEGATE = 0x4f,
84 OP_1 = 0x51,
86 OP_2 = 0x52,
87 OP_3 = 0x53,
88 OP_4 = 0x54,
89 OP_5 = 0x55,
90 OP_6 = 0x56,
91 OP_7 = 0x57,
92 OP_8 = 0x58,
93 OP_9 = 0x59,
94 OP_10 = 0x5a,
95 OP_11 = 0x5b,
96 OP_12 = 0x5c,
97 OP_13 = 0x5d,
98 OP_14 = 0x5e,
99 OP_15 = 0x5f,
100 OP_16 = 0x60,
101
102 // control
103 OP_NOP = 0x61,
104 OP_VER = 0x62,
105 OP_IF = 0x63,
106 OP_NOTIF = 0x64,
107 OP_VERIF = 0x65,
109 OP_ELSE = 0x67,
110 OP_ENDIF = 0x68,
111 OP_VERIFY = 0x69,
112 OP_RETURN = 0x6a,
113
114 // stack ops
117 OP_2DROP = 0x6d,
118 OP_2DUP = 0x6e,
119 OP_3DUP = 0x6f,
120 OP_2OVER = 0x70,
121 OP_2ROT = 0x71,
122 OP_2SWAP = 0x72,
123 OP_IFDUP = 0x73,
124 OP_DEPTH = 0x74,
125 OP_DROP = 0x75,
126 OP_DUP = 0x76,
127 OP_NIP = 0x77,
128 OP_OVER = 0x78,
129 OP_PICK = 0x79,
130 OP_ROLL = 0x7a,
131 OP_ROT = 0x7b,
132 OP_SWAP = 0x7c,
133 OP_TUCK = 0x7d,
134
135 // splice ops
136 OP_CAT = 0x7e,
137 OP_SUBSTR = 0x7f,
138 OP_LEFT = 0x80,
139 OP_RIGHT = 0x81,
140 OP_SIZE = 0x82,
141
142 // bit logic
143 OP_INVERT = 0x83,
144 OP_AND = 0x84,
145 OP_OR = 0x85,
146 OP_XOR = 0x86,
147 OP_EQUAL = 0x87,
151
152 // numeric
153 OP_1ADD = 0x8b,
154 OP_1SUB = 0x8c,
155 OP_2MUL = 0x8d,
156 OP_2DIV = 0x8e,
157 OP_NEGATE = 0x8f,
158 OP_ABS = 0x90,
159 OP_NOT = 0x91,
161
162 OP_ADD = 0x93,
163 OP_SUB = 0x94,
164 OP_MUL = 0x95,
165 OP_DIV = 0x96,
166 OP_MOD = 0x97,
167 OP_LSHIFT = 0x98,
168 OP_RSHIFT = 0x99,
169
171 OP_BOOLOR = 0x9b,
179 OP_MIN = 0xa3,
180 OP_MAX = 0xa4,
181
182 OP_WITHIN = 0xa5,
183
184 // crypto
186 OP_SHA1 = 0xa7,
187 OP_SHA256 = 0xa8,
195
196 // expansion
197 OP_NOP1 = 0xb0,
202 OP_NOP4 = 0xb3,
203 OP_NOP5 = 0xb4,
204 OP_NOP6 = 0xb5,
205 OP_NOP7 = 0xb6,
206 OP_NOP8 = 0xb7,
207 OP_NOP9 = 0xb8,
208 OP_NOP10 = 0xb9,
209
210 // Opcode added by BIP 342 (Tapscript)
212
214};
215
216// Maximum value that an opcode can be
217static const unsigned int MAX_OPCODE = OP_NOP10;
218
219std::string GetOpName(opcodetype opcode);
220
221class scriptnum_error : public std::runtime_error
222{
223public:
224 explicit scriptnum_error(const std::string& str) : std::runtime_error(str) {}
225};
226
228{
237public:
238
239 explicit CScriptNum(const int64_t& n)
240 {
241 m_value = n;
242 }
243
244 static const size_t nDefaultMaxNumSize = 4;
245
246 explicit CScriptNum(const std::vector<unsigned char>& vch, bool fRequireMinimal,
247 const size_t nMaxNumSize = nDefaultMaxNumSize)
248 {
249 if (vch.size() > nMaxNumSize) {
250 throw scriptnum_error("script number overflow");
251 }
252 if (fRequireMinimal && vch.size() > 0) {
253 // Check that the number is encoded with the minimum possible
254 // number of bytes.
255 //
256 // If the most-significant-byte - excluding the sign bit - is zero
257 // then we're not minimal. Note how this test also rejects the
258 // negative-zero encoding, 0x80.
259 if ((vch.back() & 0x7f) == 0) {
260 // One exception: if there's more than one byte and the most
261 // significant bit of the second-most-significant-byte is set
262 // it would conflict with the sign bit. An example of this case
263 // is +-255, which encode to 0xff00 and 0xff80 respectively.
264 // (big-endian).
265 if (vch.size() <= 1 || (vch[vch.size() - 2] & 0x80) == 0) {
266 throw scriptnum_error("non-minimally encoded script number");
267 }
268 }
269 }
270 m_value = set_vch(vch);
271 }
272
273 inline bool operator==(const int64_t& rhs) const { return m_value == rhs; }
274 inline auto operator<=>(const int64_t& rhs) const { return m_value <=> rhs; }
275
276 inline bool operator==(const CScriptNum& rhs) const { return operator==(rhs.m_value); }
277 inline auto operator<=>(const CScriptNum& rhs) const { return operator<=>(rhs.m_value); }
278
279 inline CScriptNum operator+( const int64_t& rhs) const { return CScriptNum(m_value + rhs);}
280 inline CScriptNum operator-( const int64_t& rhs) const { return CScriptNum(m_value - rhs);}
281 inline CScriptNum operator+( const CScriptNum& rhs) const { return operator+(rhs.m_value); }
282 inline CScriptNum operator-( const CScriptNum& rhs) const { return operator-(rhs.m_value); }
283
284 inline CScriptNum& operator+=( const CScriptNum& rhs) { return operator+=(rhs.m_value); }
285 inline CScriptNum& operator-=( const CScriptNum& rhs) { return operator-=(rhs.m_value); }
286
287 inline CScriptNum operator&( const int64_t& rhs) const { return CScriptNum(m_value & rhs);}
288 inline CScriptNum operator&( const CScriptNum& rhs) const { return operator&(rhs.m_value); }
289
290 inline CScriptNum& operator&=( const CScriptNum& rhs) { return operator&=(rhs.m_value); }
291
292 inline CScriptNum operator-() const
293 {
294 assert(m_value != std::numeric_limits<int64_t>::min());
295 return CScriptNum(-m_value);
296 }
297
298 inline CScriptNum& operator=( const int64_t& rhs)
299 {
300 m_value = rhs;
301 return *this;
302 }
303
304 inline CScriptNum& operator+=( const int64_t& rhs)
305 {
306 assert(rhs == 0 || (rhs > 0 && m_value <= std::numeric_limits<int64_t>::max() - rhs) ||
307 (rhs < 0 && m_value >= std::numeric_limits<int64_t>::min() - rhs));
308 m_value += rhs;
309 return *this;
310 }
311
312 inline CScriptNum& operator-=( const int64_t& rhs)
313 {
314 assert(rhs == 0 || (rhs > 0 && m_value >= std::numeric_limits<int64_t>::min() + rhs) ||
315 (rhs < 0 && m_value <= std::numeric_limits<int64_t>::max() + rhs));
316 m_value -= rhs;
317 return *this;
318 }
319
320 inline CScriptNum& operator&=( const int64_t& rhs)
321 {
322 m_value &= rhs;
323 return *this;
324 }
325
326 int getint() const
327 {
328 if (m_value > std::numeric_limits<int>::max())
329 return std::numeric_limits<int>::max();
330 else if (m_value < std::numeric_limits<int>::min())
331 return std::numeric_limits<int>::min();
332 return m_value;
333 }
334
335 int64_t GetInt64() const { return m_value; }
336
337 std::vector<unsigned char> getvch() const
338 {
339 return serialize(m_value);
340 }
341
342 static std::vector<unsigned char> serialize(const int64_t& value)
343 {
344 if(value == 0)
345 return std::vector<unsigned char>();
346
347 std::vector<unsigned char> result;
348 const bool neg = value < 0;
349 uint64_t absvalue = neg ? ~static_cast<uint64_t>(value) + 1 : static_cast<uint64_t>(value);
350
351 while(absvalue)
352 {
353 result.push_back(absvalue & 0xff);
354 absvalue >>= 8;
355 }
356
357// - If the most significant byte is >= 0x80 and the value is positive, push a
358// new zero-byte to make the significant byte < 0x80 again.
359
360// - If the most significant byte is >= 0x80 and the value is negative, push a
361// new 0x80 byte that will be popped off when converting to an integral.
362
363// - If the most significant byte is < 0x80 and the value is negative, add
364// 0x80 to it, since it will be subtracted and interpreted as a negative when
365// converting to an integral.
366
367 if (result.back() & 0x80)
368 result.push_back(neg ? 0x80 : 0);
369 else if (neg)
370 result.back() |= 0x80;
371
372 return result;
373 }
374
375private:
376 static int64_t set_vch(const std::vector<unsigned char>& vch)
377 {
378 if (vch.empty())
379 return 0;
380
381 int64_t result = 0;
382 for (size_t i = 0; i != vch.size(); ++i)
383 result |= static_cast<int64_t>(vch[i]) << 8*i;
384
385 // If the input vector's most significant byte is 0x80, remove it from
386 // the result's msb and return a negative.
387 if (vch.back() & 0x80)
388 return -((int64_t)(result & ~(0x80ULL << (8 * (vch.size() - 1)))));
389
390 return result;
391 }
392
393 int64_t m_value;
394};
395
401
402bool GetScriptOp(CScriptBase::const_iterator& pc, CScriptBase::const_iterator end, opcodetype& opcodeRet, std::vector<unsigned char>* pvchRet);
403
405class CScript : public CScriptBase
406{
407private:
408 inline void AppendDataSize(const uint32_t size)
409 {
410 if (size < OP_PUSHDATA1) {
411 insert(end(), static_cast<value_type>(size));
412 } else if (size <= 0xff) {
414 insert(end(), static_cast<value_type>(size));
415 } else if (size <= 0xffff) {
417 value_type data[2];
419 insert(end(), std::cbegin(data), std::cend(data));
420 } else {
422 value_type data[4];
424 insert(end(), std::cbegin(data), std::cend(data));
425 }
426 }
427
428 void AppendData(std::span<const value_type> data)
429 {
430 insert(end(), data.begin(), data.end());
431 }
432
433protected:
434 CScript& push_int64(int64_t n)
435 {
436 if (n == -1 || (n >= 1 && n <= 16))
437 {
438 push_back(n + (OP_1 - 1));
439 }
440 else if (n == 0)
441 {
443 }
444 else
445 {
446 *this << CScriptNum::serialize(n);
447 }
448 return *this;
449 }
450
451public:
452 CScript() = default;
453 template <std::input_iterator InputIterator>
454 CScript(InputIterator first, InputIterator last) : CScriptBase{first, last} { }
455
456 SERIALIZE_METHODS(CScript, obj) { READWRITE(AsBase<CScriptBase>(obj)); }
457
458 explicit CScript(int64_t b) { operator<<(b); }
459 explicit CScript(opcodetype b) { operator<<(b); }
460 explicit CScript(const CScriptNum& b) { operator<<(b); }
461 // delete non-existent constructor to defend against future introduction
462 // e.g. via prevector
463 explicit CScript(const std::vector<unsigned char>& b) = delete;
464
466 CScript& operator<<(const CScript& b) = delete;
467
468 CScript& operator<<(int64_t b) LIFETIMEBOUND { return push_int64(b); }
469
471 {
472 if (opcode < 0 || opcode > 0xff)
473 throw std::runtime_error("CScript::operator<<(): invalid opcode");
474 insert(end(), (unsigned char)opcode);
475 return *this;
476 }
477
479 {
480 *this << b.getvch();
481 return *this;
482 }
483
484 CScript& operator<<(std::span<const std::byte> b) LIFETIMEBOUND
485 {
486 AppendDataSize(b.size());
487 AppendData({reinterpret_cast<const value_type*>(b.data()), b.size()});
488 return *this;
489 }
490
491 // For compatibility reasons. In new code, prefer using std::byte instead of uint8_t.
492 CScript& operator<<(std::span<const value_type> b) LIFETIMEBOUND
493 {
494 return *this << std::as_bytes(b);
495 }
496
497 bool GetOp(const_iterator& pc, opcodetype& opcodeRet, std::vector<unsigned char>& vchRet) const
498 {
499 return GetScriptOp(pc, end(), opcodeRet, &vchRet);
500 }
501
502 bool GetOp(const_iterator& pc, opcodetype& opcodeRet) const
503 {
504 return GetScriptOp(pc, end(), opcodeRet, nullptr);
505 }
506
508 static int DecodeOP_N(opcodetype opcode)
509 {
510 if (opcode == OP_0)
511 return 0;
512 assert(opcode >= OP_1 && opcode <= OP_16);
513 return (int)opcode - (int)(OP_1 - 1);
514 }
515 static opcodetype EncodeOP_N(int n)
516 {
517 assert(n >= 0 && n <= 16);
518 if (n == 0)
519 return OP_0;
520 return (opcodetype)(OP_1+n-1);
521 }
522
530 unsigned int GetSigOpCount(bool fAccurate) const;
531
536 unsigned int GetSigOpCount(const CScript& scriptSig) const;
537
538 /*
539 * OP_1 <0x4e73>
540 */
541 bool IsPayToAnchor() const;
544 static bool IsPayToAnchor(int version, const std::vector<unsigned char>& program);
545
546 bool IsPayToScriptHash() const;
547 bool IsPayToWitnessScriptHash() const;
548 bool IsWitnessProgram(int& version, std::vector<unsigned char>& program) const;
549
550 bool IsPayToTaproot() const;
551
553 bool IsPushOnly(const_iterator pc) const;
554 bool IsPushOnly() const;
555
557 bool HasValidOps() const;
558
564 bool IsUnspendable() const
565 {
566 return (size() > 0 && *begin() == OP_RETURN) || (size() > MAX_SCRIPT_SIZE);
567 }
568
569 void clear()
570 {
571 // The default prevector::clear() does not release memory
574 }
575};
576
578{
579 // Note that this encodes the data elements being pushed, rather than
580 // encoding them as a CScript that pushes them.
581 std::vector<std::vector<unsigned char> > stack;
582
583 // Some compilers complain without a default constructor
584 CScriptWitness() = default;
585
586 bool IsNull() const { return stack.empty(); }
587
588 void SetNull() { stack.clear(); stack.shrink_to_fit(); }
589
590 std::string ToString() const;
591
592 bool operator==(const CScriptWitness&) const = default;
593};
594
596class CScriptID : public BaseHash<uint160>
597{
598public:
600 explicit CScriptID(const CScript& in);
601 explicit CScriptID(const uint160& in) : BaseHash(in) {}
602};
603
605bool IsOpSuccess(const opcodetype& opcode);
606
607bool CheckMinimalPush(const std::vector<unsigned char>& data, opcodetype opcode);
608
610template<typename... Ts>
611CScript BuildScript(Ts&&... inputs)
612{
613 CScript ret;
614 int cnt{0};
615
616 ([&ret, &cnt] (Ts&& input) {
617 if constexpr (std::is_same_v<std::remove_cv_t<std::remove_reference_t<Ts>>, CScript>) {
618 // If it is a CScript, extend ret with it. Move or copy the first element instead.
619 if (cnt == 0) {
620 ret = std::forward<Ts>(input);
621 } else {
622 ret.insert(ret.end(), input.begin(), input.end());
623 }
624 } else {
625 // Otherwise invoke CScript::operator<<.
626 ret << input;
627 }
628 cnt++;
629 } (std::forward<Ts>(inputs)), ...);
630
631 return ret;
632}
633
634#endif // BITCOIN_SCRIPT_SCRIPT_H
#define LIFETIMEBOUND
Definition: attributes.h:16
int ret
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:406
bool IsPayToScriptHash() const
Definition: script.cpp:224
CScript(InputIterator first, InputIterator last)
Definition: script.h:454
bool IsUnspendable() const
Returns whether the script is guaranteed to fail at execution, regardless of the initial stack.
Definition: script.h:564
CScript()=default
CScript & operator<<(const CScript &b)=delete
Delete non-existent operator to defend against future introduction.
CScript(const CScriptNum &b)
Definition: script.h:460
void AppendData(std::span< const value_type > data)
Definition: script.h:428
CScript & push_int64(int64_t n)
Definition: script.h:434
CScript(int64_t b)
Definition: script.h:458
SERIALIZE_METHODS(CScript, obj)
Definition: script.h:456
CScript & operator<<(std::span< const value_type > b) LIFETIMEBOUND
Definition: script.h:492
void clear()
Definition: script.h:569
static int DecodeOP_N(opcodetype opcode)
Encode/decode small integers:
Definition: script.h:508
bool IsPushOnly() const
Definition: script.cpp:283
CScript(opcodetype b)
Definition: script.h:459
bool IsPayToWitnessScriptHash() const
Definition: script.cpp:233
void AppendDataSize(const uint32_t size)
Definition: script.h:408
unsigned int GetSigOpCount(bool fAccurate) const
Pre-version-0.6, Bitcoin always counted CHECKMULTISIGs as 20 sigops.
Definition: script.cpp:159
bool HasValidOps() const
Check if the script contains valid OP_CODES.
Definition: script.cpp:300
CScript(const std::vector< unsigned char > &b)=delete
bool GetOp(const_iterator &pc, opcodetype &opcodeRet) const
Definition: script.h:502
CScript & operator<<(opcodetype opcode) LIFETIMEBOUND
Definition: script.h:470
CScript & operator<<(const CScriptNum &b) LIFETIMEBOUND
Definition: script.h:478
CScript & operator<<(std::span< const std::byte > b) LIFETIMEBOUND
Definition: script.h:484
bool IsPayToTaproot() const
Definition: script.cpp:241
bool IsPayToAnchor() const
Definition: script.cpp:207
bool GetOp(const_iterator &pc, opcodetype &opcodeRet, std::vector< unsigned char > &vchRet) const
Definition: script.h:497
bool IsWitnessProgram(int &version, std::vector< unsigned char > &program) const
Definition: script.cpp:250
CScript & operator<<(int64_t b) LIFETIMEBOUND
Definition: script.h:468
static opcodetype EncodeOP_N(int n)
Definition: script.h:515
A reference to a CScript: the Hash160 of its serialization.
Definition: script.h:597
CScriptID()
Definition: script.h:599
CScriptID(const uint160 &in)
Definition: script.h:601
int64_t m_value
Definition: script.h:393
static std::vector< unsigned char > serialize(const int64_t &value)
Definition: script.h:342
CScriptNum & operator-=(const CScriptNum &rhs)
Definition: script.h:285
CScriptNum & operator-=(const int64_t &rhs)
Definition: script.h:312
CScriptNum operator-(const int64_t &rhs) const
Definition: script.h:280
CScriptNum operator+(const int64_t &rhs) const
Definition: script.h:279
CScriptNum & operator+=(const CScriptNum &rhs)
Definition: script.h:284
CScriptNum operator-(const CScriptNum &rhs) const
Definition: script.h:282
auto operator<=>(const CScriptNum &rhs) const
Definition: script.h:277
bool operator==(const CScriptNum &rhs) const
Definition: script.h:276
CScriptNum & operator&=(const CScriptNum &rhs)
Definition: script.h:290
bool operator==(const int64_t &rhs) const
Definition: script.h:273
CScriptNum(const std::vector< unsigned char > &vch, bool fRequireMinimal, const size_t nMaxNumSize=nDefaultMaxNumSize)
Definition: script.h:246
std::vector< unsigned char > getvch() const
Definition: script.h:337
auto operator<=>(const int64_t &rhs) const
Definition: script.h:274
static const size_t nDefaultMaxNumSize
Definition: script.h:244
CScriptNum operator&(const int64_t &rhs) const
Definition: script.h:287
CScriptNum operator&(const CScriptNum &rhs) const
Definition: script.h:288
CScriptNum & operator+=(const int64_t &rhs)
Definition: script.h:304
CScriptNum(const int64_t &n)
Numeric opcodes (OP_1ADD, etc) are restricted to operating on 4-byte integers.
Definition: script.h:239
int64_t GetInt64() const
Definition: script.h:335
static int64_t set_vch(const std::vector< unsigned char > &vch)
Definition: script.h:376
CScriptNum & operator&=(const int64_t &rhs)
Definition: script.h:320
int getint() const
Definition: script.h:326
CScriptNum operator-() const
Definition: script.h:292
CScriptNum & operator=(const int64_t &rhs)
Definition: script.h:298
CScriptNum operator+(const CScriptNum &rhs) const
Definition: script.h:281
Implements a drop-in replacement for std::vector<T> which stores up to N elements directly (without h...
Definition: prevector.h:37
void shrink_to_fit()
Definition: prevector.h:299
void clear()
Definition: prevector.h:303
size_type size() const
Definition: prevector.h:247
value_type * data()
Definition: prevector.h:464
iterator begin()
Definition: prevector.h:255
T value_type
Definition: prevector.h:45
iterator end()
Definition: prevector.h:257
iterator insert(iterator pos, const T &value)
Definition: prevector.h:307
void push_back(const T &value)
Definition: prevector.h:392
scriptnum_error(const std::string &str)
Definition: script.h:224
160-bit opaque blob.
Definition: uint256.h:184
void WriteLE32(B *ptr, uint32_t x)
Definition: common.h:50
void WriteLE16(B *ptr, uint16_t x)
Definition: common.h:43
Definition: common.h:30
static constexpr int64_t VALIDATION_WEIGHT_PER_SIGOP_PASSED
Definition: script.h:62
static const unsigned int LOCKTIME_THRESHOLD
Definition: script.h:48
static const unsigned int MAX_OPCODE
Definition: script.h:217
std::string GetOpName(opcodetype opcode)
Definition: script.cpp:19
bool CheckMinimalPush(const std::vector< unsigned char > &data, opcodetype opcode)
Definition: script.cpp:373
static const unsigned int MAX_SCRIPT_ELEMENT_SIZE
Definition: script.h:29
static const int MAX_SCRIPT_SIZE
Definition: script.h:41
opcodetype
Script opcodes.
Definition: script.h:75
@ OP_NUMNOTEQUAL
Definition: script.h:174
@ OP_RESERVED1
Definition: script.h:149
@ OP_2
Definition: script.h:86
@ OP_SHA256
Definition: script.h:187
@ OP_PUSHDATA4
Definition: script.h:81
@ OP_NOP5
Definition: script.h:203
@ OP_RIGHT
Definition: script.h:139
@ OP_BOOLAND
Definition: script.h:170
@ OP_CHECKMULTISIG
Definition: script.h:193
@ OP_NEGATE
Definition: script.h:157
@ OP_IF
Definition: script.h:105
@ OP_13
Definition: script.h:97
@ OP_ROT
Definition: script.h:131
@ OP_SWAP
Definition: script.h:132
@ OP_1NEGATE
Definition: script.h:82
@ OP_VERNOTIF
Definition: script.h:108
@ OP_CHECKSIG
Definition: script.h:191
@ OP_CHECKLOCKTIMEVERIFY
Definition: script.h:198
@ OP_LESSTHAN
Definition: script.h:175
@ OP_16
Definition: script.h:100
@ OP_LEFT
Definition: script.h:138
@ OP_14
Definition: script.h:98
@ OP_NOP10
Definition: script.h:208
@ OP_2DIV
Definition: script.h:156
@ OP_INVALIDOPCODE
Definition: script.h:213
@ OP_NOT
Definition: script.h:159
@ OP_EQUAL
Definition: script.h:147
@ OP_NUMEQUAL
Definition: script.h:172
@ OP_MOD
Definition: script.h:166
@ OP_NOTIF
Definition: script.h:106
@ OP_4
Definition: script.h:88
@ OP_10
Definition: script.h:94
@ OP_SIZE
Definition: script.h:140
@ OP_3DUP
Definition: script.h:119
@ OP_ENDIF
Definition: script.h:110
@ OP_NOP1
Definition: script.h:197
@ OP_DUP
Definition: script.h:126
@ OP_GREATERTHAN
Definition: script.h:176
@ OP_NOP
Definition: script.h:103
@ OP_NOP2
Definition: script.h:199
@ OP_VERIF
Definition: script.h:107
@ OP_TOALTSTACK
Definition: script.h:115
@ OP_CODESEPARATOR
Definition: script.h:190
@ OP_RIPEMD160
Definition: script.h:185
@ OP_MIN
Definition: script.h:179
@ OP_HASH256
Definition: script.h:189
@ OP_MAX
Definition: script.h:180
@ OP_1SUB
Definition: script.h:154
@ OP_FROMALTSTACK
Definition: script.h:116
@ OP_SUB
Definition: script.h:163
@ OP_FALSE
Definition: script.h:78
@ OP_NUMEQUALVERIFY
Definition: script.h:173
@ OP_OVER
Definition: script.h:128
@ OP_NOP8
Definition: script.h:206
@ OP_DIV
Definition: script.h:165
@ OP_HASH160
Definition: script.h:188
@ OP_2DUP
Definition: script.h:118
@ OP_NIP
Definition: script.h:127
@ OP_2MUL
Definition: script.h:155
@ OP_NOP4
Definition: script.h:202
@ OP_NOP3
Definition: script.h:201
@ OP_1
Definition: script.h:84
@ OP_LESSTHANOREQUAL
Definition: script.h:177
@ OP_2DROP
Definition: script.h:117
@ OP_TRUE
Definition: script.h:85
@ OP_DEPTH
Definition: script.h:124
@ OP_NOP9
Definition: script.h:207
@ OP_VER
Definition: script.h:104
@ OP_VERIFY
Definition: script.h:111
@ OP_RESERVED2
Definition: script.h:150
@ OP_12
Definition: script.h:96
@ OP_ADD
Definition: script.h:162
@ OP_CHECKMULTISIGVERIFY
Definition: script.h:194
@ OP_NOP7
Definition: script.h:205
@ OP_8
Definition: script.h:92
@ OP_BOOLOR
Definition: script.h:171
@ OP_XOR
Definition: script.h:146
@ OP_DROP
Definition: script.h:125
@ OP_MUL
Definition: script.h:164
@ OP_WITHIN
Definition: script.h:182
@ OP_CHECKSIGADD
Definition: script.h:211
@ OP_ELSE
Definition: script.h:109
@ OP_15
Definition: script.h:99
@ OP_CHECKSIGVERIFY
Definition: script.h:192
@ OP_PUSHDATA1
Definition: script.h:79
@ OP_TUCK
Definition: script.h:133
@ OP_2OVER
Definition: script.h:120
@ OP_0NOTEQUAL
Definition: script.h:160
@ OP_9
Definition: script.h:93
@ OP_3
Definition: script.h:87
@ OP_11
Definition: script.h:95
@ OP_SHA1
Definition: script.h:186
@ OP_SUBSTR
Definition: script.h:137
@ OP_GREATERTHANOREQUAL
Definition: script.h:178
@ OP_RSHIFT
Definition: script.h:168
@ OP_2SWAP
Definition: script.h:122
@ OP_PUSHDATA2
Definition: script.h:80
@ OP_2ROT
Definition: script.h:121
@ OP_6
Definition: script.h:90
@ OP_INVERT
Definition: script.h:143
@ OP_0
Definition: script.h:77
@ OP_ABS
Definition: script.h:158
@ OP_LSHIFT
Definition: script.h:167
@ OP_RETURN
Definition: script.h:112
@ OP_IFDUP
Definition: script.h:123
@ OP_PICK
Definition: script.h:129
@ OP_AND
Definition: script.h:144
@ OP_EQUALVERIFY
Definition: script.h:148
@ OP_CAT
Definition: script.h:136
@ OP_RESERVED
Definition: script.h:83
@ OP_1ADD
Definition: script.h:153
@ OP_7
Definition: script.h:91
@ OP_OR
Definition: script.h:145
@ OP_ROLL
Definition: script.h:130
@ OP_NOP6
Definition: script.h:204
@ OP_5
Definition: script.h:89
@ OP_CHECKSEQUENCEVERIFY
Definition: script.h:200
static constexpr unsigned int MAX_PUBKEYS_PER_MULTI_A
The limit of keys in OP_CHECKSIGADD-based scripts.
Definition: script.h:38
bool GetScriptOp(CScriptBase::const_iterator &pc, CScriptBase::const_iterator end, opcodetype &opcodeRet, std::vector< unsigned char > *pvchRet)
Definition: script.cpp:313
static const int MAX_STACK_SIZE
Definition: script.h:44
bool IsOpSuccess(const opcodetype &opcode)
Test for OP_SUCCESSx opcodes as defined by BIP342.
Definition: script.cpp:365
static const int MAX_OPS_PER_SCRIPT
Definition: script.h:32
static constexpr int64_t VALIDATION_WEIGHT_OFFSET
Definition: script.h:65
CScript BuildScript(Ts &&... inputs)
Build a script by concatenating other scripts, or any argument accepted by CScript::operator<<.
Definition: script.h:611
static const int MAX_PUBKEYS_PER_MULTISIG
Definition: script.h:35
std::vector< unsigned char > ToByteVector(const T &in)
Definition: script.h:68
static const uint32_t LOCKTIME_MAX
Definition: script.h:54
static constexpr unsigned int ANNEX_TAG
Definition: script.h:59
#define READWRITE(...)
Definition: serialize.h:147
bool operator==(const CScriptWitness &) const =default
CScriptWitness()=default
std::string ToString() const
Definition: script.cpp:288
std::vector< std::vector< unsigned char > > stack
Definition: script.h:581
bool IsNull() const
Definition: script.h:586
void SetNull()
Definition: script.h:588
assert(!tx.IsCoinBase())