Bitcoin ABC  0.24.7
P2P Digital Currency
script.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2016 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 <cassert>
14 #include <climits>
15 #include <cstdint>
16 #include <cstring>
17 #include <limits>
18 #include <stdexcept>
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. Thresold is Tue Nov 5 00:53:20 1985 UTC
39 static const unsigned int LOCKTIME_THRESHOLD = 500000000;
40 
41 template <typename T> std::vector<uint8_t> ToByteVector(const T &in) {
42  return std::vector<uint8_t>(in.begin(), in.end());
43 }
44 
46 enum opcodetype {
47  // push value
48  OP_0 = 0x00,
50  OP_PUSHDATA1 = 0x4c,
51  OP_PUSHDATA2 = 0x4d,
52  OP_PUSHDATA4 = 0x4e,
53  OP_1NEGATE = 0x4f,
54  OP_RESERVED = 0x50,
55  OP_1 = 0x51,
57  OP_2 = 0x52,
58  OP_3 = 0x53,
59  OP_4 = 0x54,
60  OP_5 = 0x55,
61  OP_6 = 0x56,
62  OP_7 = 0x57,
63  OP_8 = 0x58,
64  OP_9 = 0x59,
65  OP_10 = 0x5a,
66  OP_11 = 0x5b,
67  OP_12 = 0x5c,
68  OP_13 = 0x5d,
69  OP_14 = 0x5e,
70  OP_15 = 0x5f,
71  OP_16 = 0x60,
72 
73  // control
74  OP_NOP = 0x61,
75  OP_VER = 0x62,
76  OP_IF = 0x63,
77  OP_NOTIF = 0x64,
78  OP_VERIF = 0x65,
79  OP_VERNOTIF = 0x66,
80  OP_ELSE = 0x67,
81  OP_ENDIF = 0x68,
82  OP_VERIFY = 0x69,
83  OP_RETURN = 0x6a,
84 
85  // stack ops
86  OP_TOALTSTACK = 0x6b,
88  OP_2DROP = 0x6d,
89  OP_2DUP = 0x6e,
90  OP_3DUP = 0x6f,
91  OP_2OVER = 0x70,
92  OP_2ROT = 0x71,
93  OP_2SWAP = 0x72,
94  OP_IFDUP = 0x73,
95  OP_DEPTH = 0x74,
96  OP_DROP = 0x75,
97  OP_DUP = 0x76,
98  OP_NIP = 0x77,
99  OP_OVER = 0x78,
100  OP_PICK = 0x79,
101  OP_ROLL = 0x7a,
102  OP_ROT = 0x7b,
103  OP_SWAP = 0x7c,
104  OP_TUCK = 0x7d,
105 
106  // splice ops
107  OP_CAT = 0x7e,
108  OP_SPLIT = 0x7f, // after monolith upgrade (May 2018)
109  OP_NUM2BIN = 0x80, // after monolith upgrade (May 2018)
110  OP_BIN2NUM = 0x81, // after monolith upgrade (May 2018)
111  OP_SIZE = 0x82,
112 
113  // bit logic
114  OP_INVERT = 0x83,
115  OP_AND = 0x84,
116  OP_OR = 0x85,
117  OP_XOR = 0x86,
118  OP_EQUAL = 0x87,
120  OP_RESERVED1 = 0x89,
121  OP_RESERVED2 = 0x8a,
122 
123  // numeric
124  OP_1ADD = 0x8b,
125  OP_1SUB = 0x8c,
126  OP_2MUL = 0x8d,
127  OP_2DIV = 0x8e,
128  OP_NEGATE = 0x8f,
129  OP_ABS = 0x90,
130  OP_NOT = 0x91,
131  OP_0NOTEQUAL = 0x92,
132 
133  OP_ADD = 0x93,
134  OP_SUB = 0x94,
135  OP_MUL = 0x95,
136  OP_DIV = 0x96,
137  OP_MOD = 0x97,
138  OP_LSHIFT = 0x98,
139  OP_RSHIFT = 0x99,
140 
141  OP_BOOLAND = 0x9a,
142  OP_BOOLOR = 0x9b,
143  OP_NUMEQUAL = 0x9c,
146  OP_LESSTHAN = 0x9f,
150  OP_MIN = 0xa3,
151  OP_MAX = 0xa4,
152 
153  OP_WITHIN = 0xa5,
154 
155  // crypto
156  OP_RIPEMD160 = 0xa6,
157  OP_SHA1 = 0xa7,
158  OP_SHA256 = 0xa8,
159  OP_HASH160 = 0xa9,
160  OP_HASH256 = 0xaa,
162  OP_CHECKSIG = 0xac,
166 
167  // expansion
168  OP_NOP1 = 0xb0,
173  OP_NOP4 = 0xb3,
174  OP_NOP5 = 0xb4,
175  OP_NOP6 = 0xb5,
176  OP_NOP7 = 0xb6,
177  OP_NOP8 = 0xb7,
178  OP_NOP9 = 0xb8,
179  OP_NOP10 = 0xb9,
180 
181  // More crypto
184 
185  // additional byte string operations
187 
188  // The first op_code value after all defined opcodes
190 
191  // multi-byte opcodes
194 
196 };
197 
198 // Maximum value that an opcode can be
199 static const unsigned int MAX_OPCODE = FIRST_UNDEFINED_OP_VALUE - 1;
200 
201 std::string GetOpName(opcodetype opcode);
202 
207 bool CheckMinimalPush(const std::vector<uint8_t> &data, opcodetype opcode);
208 
209 class scriptnum_error : public std::runtime_error {
210 public:
211  explicit scriptnum_error(const std::string &str)
212  : std::runtime_error(str) {}
213 };
214 
215 class CScriptNum {
225 public:
226  static const size_t MAXIMUM_ELEMENT_SIZE = 4;
227 
228  explicit CScriptNum(const int64_t &n) { m_value = n; }
229 
230  explicit CScriptNum(const std::vector<uint8_t> &vch, bool fRequireMinimal,
231  const size_t nMaxNumSize = MAXIMUM_ELEMENT_SIZE) {
232  if (vch.size() > nMaxNumSize) {
233  throw scriptnum_error("script number overflow");
234  }
235  if (fRequireMinimal && !IsMinimallyEncoded(vch, nMaxNumSize)) {
236  throw scriptnum_error("non-minimally encoded script number");
237  }
238  m_value = set_vch(vch);
239  }
240 
241  static bool IsMinimallyEncoded(
242  const std::vector<uint8_t> &vch,
243  const size_t nMaxNumSize = CScriptNum::MAXIMUM_ELEMENT_SIZE);
244 
245  static bool MinimallyEncode(std::vector<uint8_t> &data);
246 
247  inline bool operator==(const int64_t &rhs) const { return m_value == rhs; }
248  inline bool operator!=(const int64_t &rhs) const { return m_value != rhs; }
249  inline bool operator<=(const int64_t &rhs) const { return m_value <= rhs; }
250  inline bool operator<(const int64_t &rhs) const { return m_value < rhs; }
251  inline bool operator>=(const int64_t &rhs) const { return m_value >= rhs; }
252  inline bool operator>(const int64_t &rhs) const { return m_value > rhs; }
253 
254  inline bool operator==(const CScriptNum &rhs) const {
255  return operator==(rhs.m_value);
256  }
257  inline bool operator!=(const CScriptNum &rhs) const {
258  return operator!=(rhs.m_value);
259  }
260  inline bool operator<=(const CScriptNum &rhs) const {
261  return operator<=(rhs.m_value);
262  }
263  inline bool operator<(const CScriptNum &rhs) const {
264  return operator<(rhs.m_value);
265  }
266  inline bool operator>=(const CScriptNum &rhs) const {
267  return operator>=(rhs.m_value);
268  }
269  inline bool operator>(const CScriptNum &rhs) const {
270  return operator>(rhs.m_value);
271  }
272 
273  inline CScriptNum operator+(const int64_t &rhs) const {
274  return CScriptNum(m_value + rhs);
275  }
276  inline CScriptNum operator-(const int64_t &rhs) const {
277  return CScriptNum(m_value - rhs);
278  }
279  inline CScriptNum operator+(const CScriptNum &rhs) const {
280  return operator+(rhs.m_value);
281  }
282  inline CScriptNum operator-(const CScriptNum &rhs) const {
283  return operator-(rhs.m_value);
284  }
285 
286  inline CScriptNum operator/(const int64_t &rhs) const {
287  return CScriptNum(m_value / rhs);
288  }
289  inline CScriptNum operator/(const CScriptNum &rhs) const {
290  return operator/(rhs.m_value);
291  }
292 
293  inline CScriptNum operator%(const int64_t &rhs) const {
294  return CScriptNum(m_value % rhs);
295  }
296  inline CScriptNum operator%(const CScriptNum &rhs) const {
297  return operator%(rhs.m_value);
298  }
299 
300  inline CScriptNum &operator+=(const CScriptNum &rhs) {
301  return operator+=(rhs.m_value);
302  }
303  inline CScriptNum &operator-=(const CScriptNum &rhs) {
304  return operator-=(rhs.m_value);
305  }
306 
307  inline CScriptNum operator&(const int64_t &rhs) const {
308  return CScriptNum(m_value & rhs);
309  }
310  inline CScriptNum operator&(const CScriptNum &rhs) const {
311  return operator&(rhs.m_value);
312  }
313 
314  inline CScriptNum &operator&=(const CScriptNum &rhs) {
315  return operator&=(rhs.m_value);
316  }
317 
318  inline CScriptNum operator-() const {
319  assert(m_value != std::numeric_limits<int64_t>::min());
320  return CScriptNum(-m_value);
321  }
322 
323  inline CScriptNum &operator=(const int64_t &rhs) {
324  m_value = rhs;
325  return *this;
326  }
327 
328  inline CScriptNum &operator+=(const int64_t &rhs) {
329  assert(
330  rhs == 0 ||
331  (rhs > 0 && m_value <= std::numeric_limits<int64_t>::max() - rhs) ||
332  (rhs < 0 && m_value >= std::numeric_limits<int64_t>::min() - rhs));
333  m_value += rhs;
334  return *this;
335  }
336 
337  inline CScriptNum &operator-=(const int64_t &rhs) {
338  assert(
339  rhs == 0 ||
340  (rhs > 0 && m_value >= std::numeric_limits<int64_t>::min() + rhs) ||
341  (rhs < 0 && m_value <= std::numeric_limits<int64_t>::max() + rhs));
342  m_value -= rhs;
343  return *this;
344  }
345 
346  inline CScriptNum &operator&=(const int64_t &rhs) {
347  m_value &= rhs;
348  return *this;
349  }
350 
351  int getint() const {
352  if (m_value > std::numeric_limits<int>::max()) {
353  return std::numeric_limits<int>::max();
354  } else if (m_value < std::numeric_limits<int>::min()) {
355  return std::numeric_limits<int>::min();
356  }
357  return m_value;
358  }
359 
360  std::vector<uint8_t> getvch() const { return serialize(m_value); }
361 
362  static std::vector<uint8_t> serialize(const int64_t &value) {
363  if (value == 0) {
364  return {};
365  }
366 
367  std::vector<uint8_t> result;
368  const bool neg = value < 0;
369  uint64_t absvalue = neg ? ~static_cast<uint64_t>(value) + 1
370  : static_cast<uint64_t>(value);
371 
372  while (absvalue) {
373  result.push_back(absvalue & 0xff);
374  absvalue >>= 8;
375  }
376 
377  // - If the most significant byte is >= 0x80 and the value is positive,
378  // push a new zero-byte to make the significant byte < 0x80 again.
379  // - If the most significant byte is >= 0x80 and the value is negative,
380  // push a new 0x80 byte that will be popped off when converting to an
381  // integral.
382  // - If the most significant byte is < 0x80 and the value is negative,
383  // add 0x80 to it, since it will be subtracted and interpreted as a
384  // negative when converting to an integral.
385  if (result.back() & 0x80) {
386  result.push_back(neg ? 0x80 : 0);
387  } else if (neg) {
388  result.back() |= 0x80;
389  }
390 
391  return result;
392  }
393 
394 private:
395  static int64_t set_vch(const std::vector<uint8_t> &vch) {
396  if (vch.empty()) {
397  return 0;
398  }
399 
400  int64_t result = 0;
401  for (size_t i = 0; i != vch.size(); ++i) {
402  result |= int64_t(vch[i]) << 8 * i;
403  }
404 
405  // If the input vector's most significant byte is 0x80, remove it from
406  // the result's msb and return a negative.
407  if (vch.back() & 0x80) {
408  return -int64_t(result & ~(0x80ULL << (8 * (vch.size() - 1))));
409  }
410 
411  return result;
412  }
413 
414  int64_t m_value;
415 };
416 
424 
426  CScriptBase::const_iterator end, opcodetype &opcodeRet,
427  std::vector<uint8_t> *pvchRet);
428 
430 class CScript : public CScriptBase {
431 protected:
432  CScript &push_int64(int64_t n) {
433  if (n == -1 || (n >= 1 && n <= 16)) {
434  push_back(n + (OP_1 - 1));
435  } else if (n == 0) {
436  push_back(OP_0);
437  } else {
438  *this << CScriptNum::serialize(n);
439  }
440  return *this;
441  }
442 
443 public:
444  CScript() {}
446  : CScriptBase(pbegin, pend) {}
447  CScript(std::vector<uint8_t>::const_iterator pbegin,
448  std::vector<uint8_t>::const_iterator pend)
449  : CScriptBase(pbegin, pend) {}
450  CScript(const uint8_t *pbegin, const uint8_t *pend)
451  : CScriptBase(pbegin, pend) {}
452 
454 
455  explicit CScript(int64_t b) { operator<<(b); }
456  explicit CScript(opcodetype b) { operator<<(b); }
457  explicit CScript(const CScriptNum &b) { operator<<(b); }
458  // delete non-existent constructor to defend against future introduction
459  // e.g. via prevector
460  explicit CScript(const std::vector<uint8_t> &b) = delete;
461 
463  CScript &operator<<(const CScript &b) = delete;
464 
465  CScript &operator<<(int64_t b) { return push_int64(b); }
466 
468  if (opcode < 0 || opcode > 0xff) {
469  throw std::runtime_error("CScript::operator<<(): invalid opcode");
470  }
471  insert(end(), uint8_t(opcode));
472  return *this;
473  }
474 
476  *this << b.getvch();
477  return *this;
478  }
479 
480  CScript &operator<<(const std::vector<uint8_t> &b) {
481  if (b.size() < OP_PUSHDATA1) {
482  insert(end(), uint8_t(b.size()));
483  } else if (b.size() <= 0xff) {
484  insert(end(), OP_PUSHDATA1);
485  insert(end(), uint8_t(b.size()));
486  } else if (b.size() <= 0xffff) {
487  insert(end(), OP_PUSHDATA2);
488  uint8_t _data[2];
489  WriteLE16(_data, b.size());
490  insert(end(), _data, _data + sizeof(_data));
491  } else {
492  insert(end(), OP_PUSHDATA4);
493  uint8_t _data[4];
494  WriteLE32(_data, b.size());
495  insert(end(), _data, _data + sizeof(_data));
496  }
497  insert(end(), b.begin(), b.end());
498  return *this;
499  }
500 
501  bool GetOp(const_iterator &pc, opcodetype &opcodeRet,
502  std::vector<uint8_t> &vchRet) const {
503  return GetScriptOp(pc, end(), opcodeRet, &vchRet);
504  }
505 
506  bool GetOp(const_iterator &pc, opcodetype &opcodeRet) const {
507  return GetScriptOp(pc, end(), opcodeRet, nullptr);
508  }
509 
511  static int DecodeOP_N(opcodetype opcode) {
512  if (opcode == OP_0) {
513  return 0;
514  }
515 
516  assert(opcode >= OP_1 && opcode <= OP_16);
517  return int(opcode) - int(OP_1 - 1);
518  }
519  static opcodetype EncodeOP_N(int n) {
520  assert(n >= 0 && n <= 16);
521  if (n == 0) {
522  return OP_0;
523  }
524 
525  return (opcodetype)(OP_1 + n - 1);
526  }
527 
528  bool IsPayToScriptHash() const;
529  bool IsCommitment(const std::vector<uint8_t> &data) const;
530  bool IsWitnessProgram(int &version, std::vector<uint8_t> &program) const;
531  bool IsWitnessProgram() const;
532 
537  bool IsPushOnly(const_iterator pc) const;
538  bool IsPushOnly() const;
539 
541  bool HasValidOps() const;
542 
548  bool IsUnspendable() const {
549  return (size() > 0 && *begin() == OP_RETURN) ||
550  (size() > MAX_SCRIPT_SIZE);
551  }
552 
553  void clear() {
554  // The default prevector::clear() does not release memory
556  shrink_to_fit();
557  }
558 };
559 
560 #endif // BITCOIN_SCRIPT_SCRIPT_H
CScriptNum::operator-
CScriptNum operator-() const
Definition: script.h:318
scriptnum_error::scriptnum_error
scriptnum_error(const std::string &str)
Definition: script.h:211
OP_NOP1
@ OP_NOP1
Definition: script.h:168
OP_ROT
@ OP_ROT
Definition: script.h:102
CScript::CScript
CScript(const uint8_t *pbegin, const uint8_t *pend)
Definition: script.h:450
CScript::CScript
CScript(const_iterator pbegin, const_iterator pend)
Definition: script.h:445
OP_NUMEQUALVERIFY
@ OP_NUMEQUALVERIFY
Definition: script.h:144
OP_0
@ OP_0
Definition: script.h:48
CScriptNum::operator<=
bool operator<=(const int64_t &rhs) const
Definition: script.h:249
prevector::insert
iterator insert(iterator pos, const T &value)
Definition: prevector.h:443
OP_SWAP
@ OP_SWAP
Definition: script.h:103
CheckMinimalPush
bool CheckMinimalPush(const std::vector< uint8_t > &data, opcodetype opcode)
Check whether the given stack element data would be minimally pushed using the given opcode.
Definition: script.cpp:268
CScript::CScript
CScript(std::vector< uint8_t >::const_iterator pbegin, std::vector< uint8_t >::const_iterator pend)
Definition: script.h:447
OP_2MUL
@ OP_2MUL
Definition: script.h:126
CScriptNum::operator!=
bool operator!=(const CScriptNum &rhs) const
Definition: script.h:257
CScriptNum::operator&
CScriptNum operator&(const CScriptNum &rhs) const
Definition: script.h:310
CScriptNum::operator&=
CScriptNum & operator&=(const int64_t &rhs)
Definition: script.h:346
LOCKTIME_THRESHOLD
static const unsigned int LOCKTIME_THRESHOLD
Definition: script.h:39
OP_INVERT
@ OP_INVERT
Definition: script.h:114
prevector::const_iterator
Definition: prevector.h:139
OP_RESERVED
@ OP_RESERVED
Definition: script.h:54
OP_TOALTSTACK
@ OP_TOALTSTACK
Definition: script.h:86
OP_LESSTHANOREQUAL
@ OP_LESSTHANOREQUAL
Definition: script.h:148
OP_OR
@ OP_OR
Definition: script.h:116
WriteLE32
static void WriteLE32(uint8_t *ptr, uint32_t x)
Definition: common.h:40
OP_NOP
@ OP_NOP
Definition: script.h:74
OP_2SWAP
@ OP_2SWAP
Definition: script.h:93
OP_RSHIFT
@ OP_RSHIFT
Definition: script.h:139
OP_3DUP
@ OP_3DUP
Definition: script.h:90
OP_7
@ OP_7
Definition: script.h:62
OP_0NOTEQUAL
@ OP_0NOTEQUAL
Definition: script.h:131
CScriptNum::set_vch
static int64_t set_vch(const std::vector< uint8_t > &vch)
Definition: script.h:395
OP_BIN2NUM
@ OP_BIN2NUM
Definition: script.h:110
prevector::clear
void clear()
Definition: prevector.h:441
OP_NOP7
@ OP_NOP7
Definition: script.h:176
OP_SHA1
@ OP_SHA1
Definition: script.h:157
OP_2OVER
@ OP_2OVER
Definition: script.h:91
CScript::SERIALIZE_METHODS
SERIALIZE_METHODS(CScript, obj)
Definition: script.h:453
OP_NOP3
@ OP_NOP3
Definition: script.h:172
OP_11
@ OP_11
Definition: script.h:66
OP_10
@ OP_10
Definition: script.h:65
OP_PREFIX_BEGIN
@ OP_PREFIX_BEGIN
Definition: script.h:192
CScript::HasValidOps
bool HasValidOps() const
Check if the script contains valid OP_CODES.
Definition: script.cpp:501
CScriptNum::getint
int getint() const
Definition: script.h:351
CScriptNum::CScriptNum
CScriptNum(const int64_t &n)
Definition: script.h:228
OP_NOP5
@ OP_NOP5
Definition: script.h:174
scriptnum_error
Definition: script.h:209
OP_ABS
@ OP_ABS
Definition: script.h:129
OP_1ADD
@ OP_1ADD
Definition: script.h:124
OP_NOP2
@ OP_NOP2
Definition: script.h:170
CScript::EncodeOP_N
static opcodetype EncodeOP_N(int n)
Definition: script.h:519
OP_HASH160
@ OP_HASH160
Definition: script.h:159
OP_SHA256
@ OP_SHA256
Definition: script.h:158
GetScriptOp
bool GetScriptOp(CScriptBase::const_iterator &pc, CScriptBase::const_iterator end, opcodetype &opcodeRet, std::vector< uint8_t > *pvchRet)
Definition: script.cpp:447
CScript::DecodeOP_N
static int DecodeOP_N(opcodetype opcode)
Encode/decode small integers:
Definition: script.h:511
OP_GREATERTHAN
@ OP_GREATERTHAN
Definition: script.h:147
OP_VERIF
@ OP_VERIF
Definition: script.h:78
CScriptNum::operator==
bool operator==(const int64_t &rhs) const
Definition: script.h:247
MAX_STACK_SIZE
static const int MAX_STACK_SIZE
Definition: script.h:35
CScriptNum::operator<
bool operator<(const int64_t &rhs) const
Definition: script.h:250
OP_NUM2BIN
@ OP_NUM2BIN
Definition: script.h:109
OP_INVALIDOPCODE
@ OP_INVALIDOPCODE
Definition: script.h:195
CScript::IsPayToScriptHash
bool IsPayToScriptHash() const
Definition: script.cpp:373
CScriptNum::operator-=
CScriptNum & operator-=(const int64_t &rhs)
Definition: script.h:337
CScript::operator<<
CScript & operator<<(const std::vector< uint8_t > &b)
Definition: script.h:480
OP_WITHIN
@ OP_WITHIN
Definition: script.h:153
OP_BOOLAND
@ OP_BOOLAND
Definition: script.h:141
READWRITEAS
#define READWRITEAS(type, obj)
Definition: serialize.h:180
CScript::clear
void clear()
Definition: script.h:553
OP_DROP
@ OP_DROP
Definition: script.h:96
OP_MIN
@ OP_MIN
Definition: script.h:150
CScriptNum::operator==
bool operator==(const CScriptNum &rhs) const
Definition: script.h:254
CScriptNum::operator+
CScriptNum operator+(const int64_t &rhs) const
Definition: script.h:273
OP_MOD
@ OP_MOD
Definition: script.h:137
CScriptNum
Definition: script.h:215
OP_XOR
@ OP_XOR
Definition: script.h:117
OP_LESSTHAN
@ OP_LESSTHAN
Definition: script.h:146
CScriptNum::operator%
CScriptNum operator%(const CScriptNum &rhs) const
Definition: script.h:296
MAX_SCRIPT_SIZE
static const int MAX_SCRIPT_SIZE
Definition: script.h:32
OP_NOTIF
@ OP_NOTIF
Definition: script.h:77
prevector::end
iterator end()
Definition: prevector.h:392
OP_2ROT
@ OP_2ROT
Definition: script.h:92
OP_RIPEMD160
@ OP_RIPEMD160
Definition: script.h:156
prevector::push_back
void push_back(const T &value)
Definition: prevector.h:531
OP_MAX
@ OP_MAX
Definition: script.h:151
OP_RETURN
@ OP_RETURN
Definition: script.h:83
OP_6
@ OP_6
Definition: script.h:61
CScriptNum::operator!=
bool operator!=(const int64_t &rhs) const
Definition: script.h:248
OP_NUMNOTEQUAL
@ OP_NUMNOTEQUAL
Definition: script.h:145
OP_1SUB
@ OP_1SUB
Definition: script.h:125
CScriptNum::operator=
CScriptNum & operator=(const int64_t &rhs)
Definition: script.h:323
CScriptNum::operator&
CScriptNum operator&(const int64_t &rhs) const
Definition: script.h:307
OP_2DROP
@ OP_2DROP
Definition: script.h:88
CScriptNum::operator+
CScriptNum operator+(const CScriptNum &rhs) const
Definition: script.h:279
CScript::CScript
CScript()
Definition: script.h:444
OP_CHECKSEQUENCEVERIFY
@ OP_CHECKSEQUENCEVERIFY
Definition: script.h:171
CScriptNum::operator>=
bool operator>=(const CScriptNum &rhs) const
Definition: script.h:266
OP_14
@ OP_14
Definition: script.h:69
CScriptNum::operator>=
bool operator>=(const int64_t &rhs) const
Definition: script.h:251
OP_3
@ OP_3
Definition: script.h:58
OP_VERNOTIF
@ OP_VERNOTIF
Definition: script.h:79
GetOpName
std::string GetOpName(opcodetype opcode)
Definition: script.cpp:14
CScriptNum::operator+=
CScriptNum & operator+=(const CScriptNum &rhs)
Definition: script.h:300
OP_CHECKSIGVERIFY
@ OP_CHECKSIGVERIFY
Definition: script.h:163
OP_PUSHDATA4
@ OP_PUSHDATA4
Definition: script.h:52
OP_IFDUP
@ OP_IFDUP
Definition: script.h:94
CScriptNum::m_value
int64_t m_value
Definition: script.h:414
OP_VER
@ OP_VER
Definition: script.h:75
OP_2DIV
@ OP_2DIV
Definition: script.h:127
OP_NEGATE
@ OP_NEGATE
Definition: script.h:128
CScript::IsPushOnly
bool IsPushOnly() const
Definition: script.cpp:443
OP_DUP
@ OP_DUP
Definition: script.h:97
CScriptNum::IsMinimallyEncoded
static bool IsMinimallyEncoded(const std::vector< uint8_t > &vch, const size_t nMaxNumSize=CScriptNum::MAXIMUM_ELEMENT_SIZE)
Definition: script.cpp:299
CScriptNum::operator/
CScriptNum operator/(const int64_t &rhs) const
Definition: script.h:286
OP_CHECKDATASIG
@ OP_CHECKDATASIG
Definition: script.h:182
CScriptNum::operator&=
CScriptNum & operator&=(const CScriptNum &rhs)
Definition: script.h:314
OP_CHECKDATASIGVERIFY
@ OP_CHECKDATASIGVERIFY
Definition: script.h:183
OP_CHECKMULTISIG
@ OP_CHECKMULTISIG
Definition: script.h:164
OP_NOT
@ OP_NOT
Definition: script.h:130
OP_AND
@ OP_AND
Definition: script.h:115
OP_2
@ OP_2
Definition: script.h:57
OP_VERIFY
@ OP_VERIFY
Definition: script.h:82
MAX_OPS_PER_SCRIPT
static const int MAX_OPS_PER_SCRIPT
Definition: script.h:26
CScriptNum::operator%
CScriptNum operator%(const int64_t &rhs) const
Definition: script.h:293
OP_BOOLOR
@ OP_BOOLOR
Definition: script.h:142
CScriptNum::operator+=
CScriptNum & operator+=(const int64_t &rhs)
Definition: script.h:328
OP_4
@ OP_4
Definition: script.h:59
OP_PREFIX_END
@ OP_PREFIX_END
Definition: script.h:193
OP_OVER
@ OP_OVER
Definition: script.h:99
OP_CHECKLOCKTIMEVERIFY
@ OP_CHECKLOCKTIMEVERIFY
Definition: script.h:169
OP_HASH256
@ OP_HASH256
Definition: script.h:160
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:467
OP_CHECKSIG
@ OP_CHECKSIG
Definition: script.h:162
CScript
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:430
CScriptNum::getvch
std::vector< uint8_t > getvch() const
Definition: script.h:360
CScriptNum::operator-=
CScriptNum & operator-=(const CScriptNum &rhs)
Definition: script.h:303
OP_9
@ OP_9
Definition: script.h:64
OP_PUSHDATA1
@ OP_PUSHDATA1
Definition: script.h:50
OP_5
@ OP_5
Definition: script.h:60
OP_NOP9
@ OP_NOP9
Definition: script.h:178
OP_NOP4
@ OP_NOP4
Definition: script.h:173
CScript::IsWitnessProgram
bool IsWitnessProgram() const
Definition: script.cpp:419
OP_ADD
@ OP_ADD
Definition: script.h:133
OP_ROLL
@ OP_ROLL
Definition: script.h:101
OP_REVERSEBYTES
@ OP_REVERSEBYTES
Definition: script.h:186
ScriptError::OP_RETURN
@ OP_RETURN
OP_NOP8
@ OP_NOP8
Definition: script.h:177
OP_16
@ OP_16
Definition: script.h:71
CScriptNum::operator>
bool operator>(const CScriptNum &rhs) const
Definition: script.h:269
CScript::CScript
CScript(int64_t b)
Definition: script.h:455
CScript::CScript
CScript(opcodetype b)
Definition: script.h:456
OP_PICK
@ OP_PICK
Definition: script.h:100
prevector
Implements a drop-in replacement for std::vector<T> which stores up to N elements directly (without h...
Definition: prevector.h:38
OP_SIZE
@ OP_SIZE
Definition: script.h:111
OP_CODESEPARATOR
@ OP_CODESEPARATOR
Definition: script.h:161
CScriptNum::MinimallyEncode
static bool MinimallyEncode(std::vector< uint8_t > &data)
Definition: script.cpp:327
OP_NUMEQUAL
@ OP_NUMEQUAL
Definition: script.h:143
OP_SUB
@ OP_SUB
Definition: script.h:134
CScriptNum::serialize
static std::vector< uint8_t > serialize(const int64_t &value)
Definition: script.h:362
prevector::shrink_to_fit
void shrink_to_fit()
Definition: prevector.h:439
OP_RESERVED1
@ OP_RESERVED1
Definition: script.h:120
common.h
OP_TUCK
@ OP_TUCK
Definition: script.h:104
CScript::GetOp
bool GetOp(const_iterator &pc, opcodetype &opcodeRet) const
Definition: script.h:506
CScript::IsCommitment
bool IsCommitment(const std::vector< uint8_t > &data) const
Definition: script.cpp:379
OP_LSHIFT
@ OP_LSHIFT
Definition: script.h:138
CScript::operator<<
CScript & operator<<(int64_t b)
Definition: script.h:465
CScript::GetOp
bool GetOp(const_iterator &pc, opcodetype &opcodeRet, std::vector< uint8_t > &vchRet) const
Definition: script.h:501
OP_12
@ OP_12
Definition: script.h:67
ToByteVector
std::vector< uint8_t > ToByteVector(const T &in)
Definition: script.h:41
OP_2DUP
@ OP_2DUP
Definition: script.h:89
OP_FROMALTSTACK
@ OP_FROMALTSTACK
Definition: script.h:87
OP_PUSHDATA2
@ OP_PUSHDATA2
Definition: script.h:51
prevector::data
value_type * data()
Definition: prevector.h:610
OP_DIV
@ OP_DIV
Definition: script.h:136
CScript::operator<<
CScript & operator<<(const CScriptNum &b)
Definition: script.h:475
OP_TRUE
@ OP_TRUE
Definition: script.h:56
prevector::size
size_type size() const
Definition: prevector.h:386
OP_EQUAL
@ OP_EQUAL
Definition: script.h:118
OP_NOP10
@ OP_NOP10
Definition: script.h:179
prevector::begin
iterator begin()
Definition: prevector.h:390
CScriptNum::operator-
CScriptNum operator-(const CScriptNum &rhs) const
Definition: script.h:282
OP_1NEGATE
@ OP_1NEGATE
Definition: script.h:53
OP_GREATERTHANOREQUAL
@ OP_GREATERTHANOREQUAL
Definition: script.h:149
serialize.h
OP_RESERVED2
@ OP_RESERVED2
Definition: script.h:121
OP_MUL
@ OP_MUL
Definition: script.h:135
CScriptNum::operator-
CScriptNum operator-(const int64_t &rhs) const
Definition: script.h:276
OP_IF
@ OP_IF
Definition: script.h:76
MAX_SCRIPT_ELEMENT_SIZE
static const unsigned int MAX_SCRIPT_ELEMENT_SIZE
Definition: script.h:23
prevector.h
OP_SPLIT
@ OP_SPLIT
Definition: script.h:108
OP_DEPTH
@ OP_DEPTH
Definition: script.h:95
CScriptNum::operator<
bool operator<(const CScriptNum &rhs) const
Definition: script.h:263
CScriptNum::operator>
bool operator>(const int64_t &rhs) const
Definition: script.h:252
CScript::IsUnspendable
bool IsUnspendable() const
Returns whether the script is guaranteed to fail at execution, regardless of the initial stack.
Definition: script.h:548
OP_CHECKMULTISIGVERIFY
@ OP_CHECKMULTISIGVERIFY
Definition: script.h:165
OP_CAT
@ OP_CAT
Definition: script.h:107
MAX_OPCODE
static const unsigned int MAX_OPCODE
Definition: script.h:199
OP_13
@ OP_13
Definition: script.h:68
OP_NIP
@ OP_NIP
Definition: script.h:98
CScript::push_int64
CScript & push_int64(int64_t n)
Definition: script.h:432
CScriptNum::operator<=
bool operator<=(const CScriptNum &rhs) const
Definition: script.h:260
CScript::CScript
CScript(const CScriptNum &b)
Definition: script.h:457
OP_NOP6
@ OP_NOP6
Definition: script.h:175
OP_EQUALVERIFY
@ OP_EQUALVERIFY
Definition: script.h:119
OP_1
@ OP_1
Definition: script.h:55
FIRST_UNDEFINED_OP_VALUE
@ FIRST_UNDEFINED_OP_VALUE
Definition: script.h:189
OP_8
@ OP_8
Definition: script.h:63
CScriptNum::operator/
CScriptNum operator/(const CScriptNum &rhs) const
Definition: script.h:289
WriteLE16
static void WriteLE16(uint8_t *ptr, uint16_t x)
Definition: common.h:35
MAX_PUBKEYS_PER_MULTISIG
static const int MAX_PUBKEYS_PER_MULTISIG
Definition: script.h:29
OP_ELSE
@ OP_ELSE
Definition: script.h:80
opcodetype
opcodetype
Script opcodes.
Definition: script.h:46
CScriptBase
prevector< 28, uint8_t > CScriptBase
We use a prevector for the script to reduce the considerable memory overhead of vectors in cases wher...
Definition: script.h:423
OP_FALSE
@ OP_FALSE
Definition: script.h:49
CScriptNum::MAXIMUM_ELEMENT_SIZE
static const size_t MAXIMUM_ELEMENT_SIZE
Numeric opcodes (OP_1ADD, etc) are restricted to operating on 4-byte integers.
Definition: script.h:226
OP_15
@ OP_15
Definition: script.h:70
CScriptNum::CScriptNum
CScriptNum(const std::vector< uint8_t > &vch, bool fRequireMinimal, const size_t nMaxNumSize=MAXIMUM_ELEMENT_SIZE)
Definition: script.h:230
OP_ENDIF
@ OP_ENDIF
Definition: script.h:81