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