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