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