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