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