PIVX Core  5.6.99
P2P Digital Currency
script.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2014 The Bitcoin developers
3 // Copyright (c) 2014-2015 The Dash developers
4 // Copyright (c) 2016-2021 The PIVX Core developers
5 // Distributed under the MIT software license, see the accompanying
6 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
7 
8 #ifndef PIVX_SCRIPT_SCRIPT_H
9 #define PIVX_SCRIPT_SCRIPT_H
10 
11 #include <assert.h>
12 #include <climits>
13 #include <limits>
14 #include <stdexcept>
15 #include <stdint.h>
16 #include <string.h>
17 #include <string>
18 #include <vector>
19 
20 #include "crypto/common.h"
21 #include "memusage.h"
22 #include "prevector.h"
23 #include "pubkey.h"
24 
25 typedef std::vector<unsigned char> valtype;
26 
27 static const unsigned int MAX_SCRIPT_ELEMENT_SIZE = 520; // bytes
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 template <typename T>
43 std::vector<unsigned char> ToByteVector(const T& in)
44 {
45  return std::vector<unsigned char>(in.begin(), in.end());
46 }
47 
50 {
51  // push value
52  OP_0 = 0x00,
54  OP_PUSHDATA1 = 0x4c,
55  OP_PUSHDATA2 = 0x4d,
56  OP_PUSHDATA4 = 0x4e,
57  OP_1NEGATE = 0x4f,
58  OP_RESERVED = 0x50,
59  OP_1 = 0x51,
61  OP_2 = 0x52,
62  OP_3 = 0x53,
63  OP_4 = 0x54,
64  OP_5 = 0x55,
65  OP_6 = 0x56,
66  OP_7 = 0x57,
67  OP_8 = 0x58,
68  OP_9 = 0x59,
69  OP_10 = 0x5a,
70  OP_11 = 0x5b,
71  OP_12 = 0x5c,
72  OP_13 = 0x5d,
73  OP_14 = 0x5e,
74  OP_15 = 0x5f,
75  OP_16 = 0x60,
76 
77  // control
78  OP_NOP = 0x61,
79  OP_VER = 0x62,
80  OP_IF = 0x63,
81  OP_NOTIF = 0x64,
82  OP_VERIF = 0x65,
83  OP_VERNOTIF = 0x66,
84  OP_ELSE = 0x67,
85  OP_ENDIF = 0x68,
86  OP_VERIFY = 0x69,
87  OP_RETURN = 0x6a,
88 
89  // stack ops
90  OP_TOALTSTACK = 0x6b,
92  OP_2DROP = 0x6d,
93  OP_2DUP = 0x6e,
94  OP_3DUP = 0x6f,
95  OP_2OVER = 0x70,
96  OP_2ROT = 0x71,
97  OP_2SWAP = 0x72,
98  OP_IFDUP = 0x73,
99  OP_DEPTH = 0x74,
100  OP_DROP = 0x75,
101  OP_DUP = 0x76,
102  OP_NIP = 0x77,
103  OP_OVER = 0x78,
104  OP_PICK = 0x79,
105  OP_ROLL = 0x7a,
106  OP_ROT = 0x7b,
107  OP_SWAP = 0x7c,
108  OP_TUCK = 0x7d,
109 
110  // splice ops
111  OP_CAT = 0x7e,
112  OP_SUBSTR = 0x7f,
113  OP_LEFT = 0x80,
114  OP_RIGHT = 0x81,
115  OP_SIZE = 0x82,
116 
117  // bit logic
118  OP_INVERT = 0x83,
119  OP_AND = 0x84,
120  OP_OR = 0x85,
121  OP_XOR = 0x86,
122  OP_EQUAL = 0x87,
124  OP_RESERVED1 = 0x89,
125  OP_RESERVED2 = 0x8a,
126 
127  // numeric
128  OP_1ADD = 0x8b,
129  OP_1SUB = 0x8c,
130  OP_2MUL = 0x8d,
131  OP_2DIV = 0x8e,
132  OP_NEGATE = 0x8f,
133  OP_ABS = 0x90,
134  OP_NOT = 0x91,
135  OP_0NOTEQUAL = 0x92,
136 
137  OP_ADD = 0x93,
138  OP_SUB = 0x94,
139  OP_MUL = 0x95,
140  OP_DIV = 0x96,
141  OP_MOD = 0x97,
142  OP_LSHIFT = 0x98,
143  OP_RSHIFT = 0x99,
144 
145  OP_BOOLAND = 0x9a,
146  OP_BOOLOR = 0x9b,
147  OP_NUMEQUAL = 0x9c,
150  OP_LESSTHAN = 0x9f,
154  OP_MIN = 0xa3,
155  OP_MAX = 0xa4,
156 
157  OP_WITHIN = 0xa5,
158 
159  // crypto
160  OP_RIPEMD160 = 0xa6,
161  OP_SHA1 = 0xa7,
162  OP_SHA256 = 0xa8,
163  OP_HASH160 = 0xa9,
164  OP_HASH256 = 0xaa,
166  OP_CHECKSIG = 0xac,
170 
171  // expansion
172  OP_NOP1 = 0xb0,
173  OP_NOP2 = 0xb1,
175  OP_NOP3 = 0xb2,
176  OP_NOP4 = 0xb3,
177  OP_NOP5 = 0xb4,
178  OP_NOP6 = 0xb5,
179  OP_NOP7 = 0xb6,
180  OP_NOP8 = 0xb7,
181  OP_NOP9 = 0xb8,
182  OP_NOP10 = 0xb9,
183 
184  // zerocoin
188 
189  // cold staking
190  OP_CHECKCOLDSTAKEVERIFY_LOF = 0xd1, // last output free for masternode/budget payments
192 
193  // exchange address, NOP but identifies as an address not allowing private outputs
195 
197 };
198 
199 const char* GetOpName(opcodetype opcode);
200 
201 class scriptnum_error : public std::runtime_error
202 {
203 public:
204  explicit scriptnum_error(const std::string& str) : std::runtime_error(str) {}
205 };
206 
208 {
217 public:
218 
219  explicit CScriptNum(const int64_t& n)
220  {
221  m_value = n;
222  }
223 
224  static const size_t nDefaultMaxNumSize = 4;
225 
226  explicit CScriptNum(const std::vector<unsigned char>& vch, bool fRequireMinimal,
227  const size_t nMaxNumSize = nDefaultMaxNumSize)
228  {
229  if (vch.size() > nMaxNumSize) {
230  throw scriptnum_error("script number overflow");
231  }
232  if (fRequireMinimal && vch.size() > 0) {
233  // Check that the number is encoded with the minimum possible
234  // number of bytes.
235  //
236  // If the most-significant-byte - excluding the sign bit - is zero
237  // then we're not minimal. Note how this test also rejects the
238  // negative-zero encoding, 0x80.
239  if ((vch.back() & 0x7f) == 0) {
240  // One exception: if there's more than one byte and the most
241  // significant bit of the second-most-significant-byte is set
242  // it would conflict with the sign bit. An example of this case
243  // is +-255, which encode to 0xff00 and 0xff80 respectively.
244  // (big-endian).
245  if (vch.size() <= 1 || (vch[vch.size() - 2] & 0x80) == 0) {
246  throw scriptnum_error("non-minimally encoded script number");
247  }
248  }
249  }
250  m_value = set_vch(vch);
251  }
252 
253  inline bool operator==(const int64_t& rhs) const { return m_value == rhs; }
254  inline bool operator!=(const int64_t& rhs) const { return m_value != rhs; }
255  inline bool operator<=(const int64_t& rhs) const { return m_value <= rhs; }
256  inline bool operator< (const int64_t& rhs) const { return m_value < rhs; }
257  inline bool operator>=(const int64_t& rhs) const { return m_value >= rhs; }
258  inline bool operator> (const int64_t& rhs) const { return m_value > rhs; }
259 
260  inline bool operator==(const CScriptNum& rhs) const { return operator==(rhs.m_value); }
261  inline bool operator!=(const CScriptNum& rhs) const { return operator!=(rhs.m_value); }
262  inline bool operator<=(const CScriptNum& rhs) const { return operator<=(rhs.m_value); }
263  inline bool operator< (const CScriptNum& rhs) const { return operator< (rhs.m_value); }
264  inline bool operator>=(const CScriptNum& rhs) const { return operator>=(rhs.m_value); }
265  inline bool operator> (const CScriptNum& rhs) const { return operator> (rhs.m_value); }
266 
267  inline CScriptNum operator+( const int64_t& rhs) const { return CScriptNum(m_value + rhs);}
268  inline CScriptNum operator-( const int64_t& rhs) const { return CScriptNum(m_value - rhs);}
269  inline CScriptNum operator+( const CScriptNum& rhs) const { return operator+(rhs.m_value); }
270  inline CScriptNum operator-( const CScriptNum& rhs) const { return operator-(rhs.m_value); }
271 
272  inline CScriptNum& operator+=( const CScriptNum& rhs) { return operator+=(rhs.m_value); }
273  inline CScriptNum& operator-=( const CScriptNum& rhs) { return operator-=(rhs.m_value); }
274 
275  inline CScriptNum operator-() const
276  {
277  assert(m_value != std::numeric_limits<int64_t>::min());
278  return CScriptNum(-m_value);
279  }
280 
281  inline CScriptNum& operator=( const int64_t& rhs)
282  {
283  m_value = rhs;
284  return *this;
285  }
286 
287  inline CScriptNum& operator+=( const int64_t& rhs)
288  {
289  assert(rhs == 0 || (rhs > 0 && m_value <= std::numeric_limits<int64_t>::max() - rhs) ||
290  (rhs < 0 && m_value >= std::numeric_limits<int64_t>::min() - rhs));
291  m_value += rhs;
292  return *this;
293  }
294 
295  inline CScriptNum& operator-=( const int64_t& rhs)
296  {
297  assert(rhs == 0 || (rhs > 0 && m_value >= std::numeric_limits<int64_t>::min() + rhs) ||
298  (rhs < 0 && m_value <= std::numeric_limits<int64_t>::max() + rhs));
299  m_value -= rhs;
300  return *this;
301  }
302 
303  int getint() const
304  {
305  if (m_value > std::numeric_limits<int>::max())
306  return std::numeric_limits<int>::max();
307  else if (m_value < std::numeric_limits<int>::min())
308  return std::numeric_limits<int>::min();
309  return m_value;
310  }
311 
312  std::vector<unsigned char> getvch() const
313  {
314  return serialize(m_value);
315  }
316 
317  static std::vector<unsigned char> serialize(const int64_t& value)
318  {
319  if(value == 0)
320  return std::vector<unsigned char>();
321 
322  std::vector<unsigned char> result;
323  const bool neg = value < 0;
324  uint64_t absvalue = neg ? ~static_cast<uint64_t>(value) + 1 : static_cast<uint64_t>(value);
325 
326  while(absvalue)
327  {
328  result.push_back(absvalue & 0xff);
329  absvalue >>= 8;
330  }
331 
332 // - If the most significant byte is >= 0x80 and the value is positive, push a
333 // new zero-byte to make the significant byte < 0x80 again.
334 
335 // - If the most significant byte is >= 0x80 and the value is negative, push a
336 // new 0x80 byte that will be popped off when converting to an integral.
337 
338 // - If the most significant byte is < 0x80 and the value is negative, add
339 // 0x80 to it, since it will be subtracted and interpreted as a negative when
340 // converting to an integral.
341 
342  if (result.back() & 0x80)
343  result.push_back(neg ? 0x80 : 0);
344  else if (neg)
345  result.back() |= 0x80;
346 
347  return result;
348  }
349 
350 private:
351  static int64_t set_vch(const std::vector<unsigned char>& vch)
352  {
353  if (vch.empty())
354  return 0;
355 
356  int64_t result = 0;
357  for (size_t i = 0; i != vch.size(); ++i)
358  result |= static_cast<int64_t>(vch[i]) << 8*i;
359 
360  // If the input vector's most significant byte is 0x80, remove it from
361  // the result's msb and return a negative.
362  if (vch.back() & 0x80)
363  return -((int64_t)(result & ~(0x80ULL << (8 * (vch.size() - 1)))));
364 
365  return result;
366  }
367 
368  int64_t m_value;
369 };
370 
378 
380 class CScript : public CScriptBase
381 {
382 protected:
383  CScript& push_int64(int64_t n)
384  {
385  if (n == -1 || (n >= 1 && n <= 16))
386  {
387  push_back(n + (OP_1 - 1));
388  }
389  else if (n == 0)
390  {
391  push_back(OP_0);
392  }
393  else
394  {
395  *this << CScriptNum::serialize(n);
396  }
397  return *this;
398  }
399 public:
400  CScript() { }
401  CScript(const_iterator pbegin, const_iterator pend) : CScriptBase(pbegin, pend) { }
402  CScript(std::vector<unsigned char>::const_iterator pbegin, std::vector<unsigned char>::const_iterator pend) : CScriptBase(pbegin, pend) { }
403  CScript(const unsigned char* pbegin, const unsigned char* pend) : CScriptBase(pbegin, pend) { }
404 
406 
408  {
409  reserve(size() + b.size());
410  insert(end(), b.begin(), b.end());
411  return *this;
412  }
413 
414  friend CScript operator+(const CScript& a, const CScript& b)
415  {
416  CScript ret = a;
417  ret += b;
418  return ret;
419  }
420 
421  explicit CScript(int64_t b) { operator<<(b); }
422 
423  explicit CScript(opcodetype b) { operator<<(b); }
424  explicit CScript(const CScriptNum& b) { operator<<(b); }
425  explicit CScript(const std::vector<unsigned char>& b) { operator<<(b); }
426 
427 
428  CScript& operator<<(int64_t b) { return push_int64(b); }
429 
431  {
432  if (opcode < 0 || opcode > 0xff)
433  throw std::runtime_error("CScript::operator<<() : invalid opcode");
434  insert(end(), (unsigned char)opcode);
435  return *this;
436  }
437 
439  {
440  *this << b.getvch();
441  return *this;
442  }
443 
444  CScript& operator<<(const std::vector<unsigned char>& b)
445  {
446  if (b.size() < OP_PUSHDATA1)
447  {
448  insert(end(), (unsigned char)b.size());
449  }
450  else if (b.size() <= 0xff)
451  {
452  insert(end(), OP_PUSHDATA1);
453  insert(end(), (unsigned char)b.size());
454  }
455  else if (b.size() <= 0xffff)
456  {
457  insert(end(), OP_PUSHDATA2);
458  uint8_t data[2];
459  WriteLE16(data, b.size());
460  insert(end(), data, data + sizeof(data));
461  }
462  else
463  {
464  insert(end(), OP_PUSHDATA4);
465  uint8_t data[4];
466  WriteLE32(data, b.size());
467  insert(end(), data, data + sizeof(data));
468  }
469  insert(end(), b.begin(), b.end());
470  return *this;
471  }
472 
474  {
475  // I'm not sure if this should push the script or concatenate scripts.
476  // If there's ever a use for pushing a script onto a script, delete this member fn
477  assert(!"Warning: Pushing a CScript onto a CScript with << is probably not intended, use + to concatenate!");
478  return *this;
479  }
480 
482  {
483  std::vector<unsigned char> vchKey = key.Raw();
484  return (*this) << vchKey;
485  }
486 
487 
488  bool GetOp(iterator& pc, opcodetype& opcodeRet, std::vector<unsigned char>& vchRet)
489  {
490  // Wrapper so it can be called with either iterator or const_iterator
491  const_iterator pc2 = pc;
492  bool fRet = GetOp2(pc2, opcodeRet, &vchRet);
493  pc = begin() + (pc2 - begin());
494  return fRet;
495  }
496 
497  bool GetOp(iterator& pc, opcodetype& opcodeRet)
498  {
499  const_iterator pc2 = pc;
500  bool fRet = GetOp2(pc2, opcodeRet, nullptr);
501  pc = begin() + (pc2 - begin());
502  return fRet;
503  }
504 
505  bool GetOp(const_iterator& pc, opcodetype& opcodeRet, std::vector<unsigned char>& vchRet) const
506  {
507  return GetOp2(pc, opcodeRet, &vchRet);
508  }
509 
510  bool GetOp(const_iterator& pc, opcodetype& opcodeRet) const
511  {
512  return GetOp2(pc, opcodeRet, nullptr);
513  }
514 
515  bool GetOp2(const_iterator& pc, opcodetype& opcodeRet, std::vector<unsigned char>* pvchRet) const
516  {
517  opcodeRet = OP_INVALIDOPCODE;
518  if (pvchRet)
519  pvchRet->clear();
520  if (pc >= end())
521  return false;
522 
523  // Read instruction
524  if (end() - pc < 1)
525  return false;
526  unsigned int opcode = *pc++;
527 
528  // Immediate operand
529  if (opcode <= OP_PUSHDATA4)
530  {
531  unsigned int nSize = 0;
532  if (opcode < OP_PUSHDATA1)
533  {
534  nSize = opcode;
535  }
536  else if (opcode == OP_PUSHDATA1)
537  {
538  if (end() - pc < 1)
539  return false;
540  nSize = *pc++;
541  }
542  else if (opcode == OP_PUSHDATA2)
543  {
544  if (end() - pc < 2)
545  return false;
546  nSize = ReadLE16(&pc[0]);
547  pc += 2;
548  }
549  else if (opcode == OP_PUSHDATA4)
550  {
551  if (end() - pc < 4)
552  return false;
553  nSize = ReadLE32(&pc[0]);
554  pc += 4;
555  }
556  if (end() - pc < 0 || (unsigned int)(end() - pc) < nSize)
557  return false;
558  if (pvchRet)
559  pvchRet->assign(pc, pc + nSize);
560  pc += nSize;
561  }
562 
563  opcodeRet = static_cast<opcodetype>(opcode);
564  return true;
565  }
566 
568  static int DecodeOP_N(opcodetype opcode)
569  {
570  if (opcode == OP_0)
571  return 0;
572  assert(opcode >= OP_1 && opcode <= OP_16);
573  return (int)opcode - (int)(OP_1 - 1);
574  }
575  static opcodetype EncodeOP_N(int n)
576  {
577  assert(n >= 0 && n <= 16);
578  if (n == 0)
579  return OP_0;
580  return (opcodetype)(OP_1+n-1);
581  }
582 
583  int FindAndDelete(const CScript& b)
584  {
585  int nFound = 0;
586  if (b.empty())
587  return nFound;
588  CScript result;
589  iterator pc = begin(), pc2 = begin();
590  opcodetype opcode;
591  do
592  {
593  result.insert(result.end(), pc2, pc);
594  while (static_cast<size_t>(end() - pc) >= b.size() && std::equal(b.begin(), b.end(), pc))
595  {
596  pc = pc + b.size();
597  ++nFound;
598  }
599  pc2 = pc;
600  }
601  while (GetOp(pc, opcode));
602 
603  if (nFound > 0) {
604  result.insert(result.end(), pc2, end());
605  *this = result;
606  }
607 
608  return nFound;
609  }
610  int Find(opcodetype op) const
611  {
612  int nFound = 0;
613  opcodetype opcode;
614  for (const_iterator pc = begin(); pc != end() && GetOp(pc, opcode);)
615  if (opcode == op)
616  ++nFound;
617  return nFound;
618  }
619 
627  unsigned int GetSigOpCount(bool fAccurate) const;
628 
633  unsigned int GetSigOpCount(const CScript& scriptSig) const;
634 
635  bool IsPayToPublicKeyHash() const;
636  bool IsPayToScriptHash() const;
637  bool IsPayToColdStaking() const;
638  bool IsPayToColdStakingLOF() const;
639  bool IsPayToExchangeAddress() const;
640  bool StartsWithOpcode(const opcodetype opcode) const;
641  bool IsZerocoinMint() const;
642  bool IsZerocoinSpend() const;
643  bool IsZerocoinPublicSpend() const;
644 
646  bool IsPushOnly(const_iterator pc) const;
647  bool IsPushOnly() const;
648 
654  bool IsUnspendable() const
655  {
656  return (size() > 0 && *begin() == OP_RETURN) || (size() > MAX_SCRIPT_SIZE);
657  }
658 
659  void clear()
660  {
661  // The default prevector::clear() does not release memory
663  shrink_to_fit();
664  }
665 
666  size_t DynamicMemoryUsage() const;
667 };
668 
669 
670 #endif // PIVX_SCRIPT_SCRIPT_H
An encapsulated public key.
Definition: pubkey.h:44
std::vector< unsigned char > Raw() const
Definition: pubkey.h:217
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:381
CScript(const_iterator pbegin, const_iterator pend)
Definition: script.h:401
bool IsPayToScriptHash() const
Definition: script.cpp:223
bool IsUnspendable() const
Returns whether the script is guaranteed to fail at execution, regardless of the initial stack.
Definition: script.h:654
CScript & operator<<(const CScriptNum &b)
Definition: script.h:438
CScript(const CScriptNum &b)
Definition: script.h:424
bool IsPayToColdStakingLOF() const
Definition: script.cpp:249
CScript(int64_t b)
Definition: script.h:421
friend CScript operator+(const CScript &a, const CScript &b)
Definition: script.h:414
bool StartsWithOpcode(const opcodetype opcode) const
Definition: script.cpp:265
SERIALIZE_METHODS(CScript, obj)
Definition: script.h:405
CScript & operator<<(const std::vector< unsigned char > &b)
Definition: script.h:444
void clear()
Definition: script.h:659
size_t DynamicMemoryUsage() const
Definition: script.cpp:307
CScript(std::vector< unsigned char >::const_iterator pbegin, std::vector< unsigned char >::const_iterator pend)
Definition: script.h:402
static int DecodeOP_N(opcodetype opcode)
Encode/decode small integers:
Definition: script.h:568
bool IsPushOnly() const
Definition: script.cpp:302
CScript(opcodetype b)
Definition: script.h:423
bool IsZerocoinSpend() const
Definition: script.cpp:275
int Find(opcodetype op) const
Definition: script.h:610
CScript & operator<<(const CPubKey &key)
Definition: script.h:481
bool GetOp(iterator &pc, opcodetype &opcodeRet)
Definition: script.h:497
CScript()
Definition: script.h:400
bool IsZerocoinPublicSpend() const
Definition: script.cpp:280
bool GetOp(iterator &pc, opcodetype &opcodeRet, std::vector< unsigned char > &vchRet)
Definition: script.h:488
unsigned int GetSigOpCount(bool fAccurate) const
Pre-version-0.6, Bitcoin always counted CHECKMULTISIGs as 20 sigops.
Definition: script.cpp:164
bool GetOp(const_iterator &pc, opcodetype &opcodeRet) const
Definition: script.h:510
CScript & operator<<(const CScript &b)
Definition: script.h:473
CScript(const unsigned char *pbegin, const unsigned char *pend)
Definition: script.h:403
bool GetOp2(const_iterator &pc, opcodetype &opcodeRet, std::vector< unsigned char > *pvchRet) const
Definition: script.h:515
int FindAndDelete(const CScript &b)
Definition: script.h:583
bool IsZerocoinMint() const
Definition: script.cpp:270
CScript & operator<<(int64_t b)
Definition: script.h:428
CScript(const std::vector< unsigned char > &b)
Definition: script.h:425
bool IsPayToPublicKeyHash() const
Definition: script.cpp:212
bool IsPayToColdStaking() const
Definition: script.cpp:233
CScript & push_int64(int64_t n)
Definition: script.h:383
bool GetOp(const_iterator &pc, opcodetype &opcodeRet, std::vector< unsigned char > &vchRet) const
Definition: script.h:505
bool IsPayToExchangeAddress() const
Definition: script.cpp:254
static opcodetype EncodeOP_N(int n)
Definition: script.h:575
CScript & operator<<(opcodetype opcode)
Definition: script.h:430
CScript & operator+=(const CScript &b)
Definition: script.h:407
int64_t m_value
Definition: script.h:368
CScriptNum operator-(const int64_t &rhs) const
Definition: script.h:268
CScriptNum operator+(const int64_t &rhs) const
Definition: script.h:267
static std::vector< unsigned char > serialize(const int64_t &value)
Definition: script.h:317
CScriptNum operator-(const CScriptNum &rhs) const
Definition: script.h:270
CScriptNum & operator+=(const CScriptNum &rhs)
Definition: script.h:272
bool operator==(const CScriptNum &rhs) const
Definition: script.h:260
bool operator<=(const CScriptNum &rhs) const
Definition: script.h:262
bool operator==(const int64_t &rhs) const
Definition: script.h:253
bool operator<(const int64_t &rhs) const
Definition: script.h:256
CScriptNum(const std::vector< unsigned char > &vch, bool fRequireMinimal, const size_t nMaxNumSize=nDefaultMaxNumSize)
Definition: script.h:226
CScriptNum & operator+=(const int64_t &rhs)
Definition: script.h:287
static const size_t nDefaultMaxNumSize
Definition: script.h:224
bool operator>=(const int64_t &rhs) const
Definition: script.h:257
CScriptNum & operator-=(const CScriptNum &rhs)
Definition: script.h:273
bool operator<=(const int64_t &rhs) const
Definition: script.h:255
CScriptNum(const int64_t &n)
Numeric opcodes (OP_1ADD, etc) are restricted to operating on 4-byte integers.
Definition: script.h:219
CScriptNum & operator=(const int64_t &rhs)
Definition: script.h:281
bool operator!=(const int64_t &rhs) const
Definition: script.h:254
bool operator>=(const CScriptNum &rhs) const
Definition: script.h:264
bool operator>(const int64_t &rhs) const
Definition: script.h:258
static int64_t set_vch(const std::vector< unsigned char > &vch)
Definition: script.h:351
int getint() const
Definition: script.h:303
std::vector< unsigned char > getvch() const
Definition: script.h:312
CScriptNum operator-() const
Definition: script.h:275
bool operator!=(const CScriptNum &rhs) const
Definition: script.h:261
CScriptNum & operator-=(const int64_t &rhs)
Definition: script.h:295
CScriptNum operator+(const CScriptNum &rhs) const
Definition: script.h:269
Implements a drop-in replacement for std::vector<T> which stores up to N elements directly (without h...
Definition: prevector.h:38
bool empty() const
Definition: prevector.h:281
void shrink_to_fit()
Definition: prevector.h:334
void clear()
Definition: prevector.h:338
size_type size() const
Definition: prevector.h:277
value_type * data()
Definition: prevector.h:526
iterator begin()
Definition: prevector.h:285
iterator end()
Definition: prevector.h:287
void reserve(size_type new_capacity)
Definition: prevector.h:328
iterator insert(iterator pos, const T &value)
Definition: prevector.h:342
void push_back(const T &value)
Definition: prevector.h:435
scriptnum_error(const std::string &str)
Definition: script.h:204
#define T(expected, seed, data)
Definition: uint256.h:212
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:377
std::vector< unsigned char > ToByteVector(const T &in)
Definition: script.h:43
const char * GetOpName(opcodetype opcode)
Definition: script.cpp:14
opcodetype
Script opcodes.
Definition: script.h:50
@ OP_NUMNOTEQUAL
Definition: script.h:149
@ OP_RESERVED1
Definition: script.h:124
@ OP_2
Definition: script.h:61
@ OP_SHA256
Definition: script.h:162
@ OP_PUSHDATA4
Definition: script.h:56
@ OP_NOP5
Definition: script.h:177
@ OP_RIGHT
Definition: script.h:114
@ OP_BOOLAND
Definition: script.h:145
@ OP_CHECKMULTISIG
Definition: script.h:168
@ OP_NEGATE
Definition: script.h:132
@ OP_IF
Definition: script.h:80
@ OP_13
Definition: script.h:72
@ OP_ROT
Definition: script.h:106
@ OP_SWAP
Definition: script.h:107
@ OP_1NEGATE
Definition: script.h:57
@ OP_VERNOTIF
Definition: script.h:83
@ OP_CHECKSIG
Definition: script.h:166
@ OP_CHECKLOCKTIMEVERIFY
Definition: script.h:174
@ OP_LESSTHAN
Definition: script.h:150
@ OP_16
Definition: script.h:75
@ OP_LEFT
Definition: script.h:113
@ OP_14
Definition: script.h:73
@ OP_NOP10
Definition: script.h:182
@ OP_2DIV
Definition: script.h:131
@ OP_INVALIDOPCODE
Definition: script.h:196
@ OP_NOT
Definition: script.h:134
@ OP_EQUAL
Definition: script.h:122
@ OP_NUMEQUAL
Definition: script.h:147
@ OP_MOD
Definition: script.h:141
@ OP_NOTIF
Definition: script.h:81
@ OP_4
Definition: script.h:63
@ OP_10
Definition: script.h:69
@ OP_SIZE
Definition: script.h:115
@ OP_3DUP
Definition: script.h:94
@ OP_ZEROCOINSPEND
Definition: script.h:186
@ OP_ENDIF
Definition: script.h:85
@ OP_NOP1
Definition: script.h:172
@ OP_DUP
Definition: script.h:101
@ OP_GREATERTHAN
Definition: script.h:151
@ OP_NOP
Definition: script.h:78
@ OP_NOP2
Definition: script.h:173
@ OP_CHECKCOLDSTAKEVERIFY
Definition: script.h:191
@ OP_VERIF
Definition: script.h:82
@ OP_TOALTSTACK
Definition: script.h:90
@ OP_CODESEPARATOR
Definition: script.h:165
@ OP_RIPEMD160
Definition: script.h:160
@ OP_MIN
Definition: script.h:154
@ OP_ZEROCOINMINT
Definition: script.h:185
@ OP_HASH256
Definition: script.h:164
@ OP_MAX
Definition: script.h:155
@ OP_1SUB
Definition: script.h:129
@ OP_FROMALTSTACK
Definition: script.h:91
@ OP_SUB
Definition: script.h:138
@ OP_FALSE
Definition: script.h:53
@ OP_NUMEQUALVERIFY
Definition: script.h:148
@ OP_OVER
Definition: script.h:103
@ OP_NOP8
Definition: script.h:180
@ OP_DIV
Definition: script.h:140
@ OP_HASH160
Definition: script.h:163
@ OP_2DUP
Definition: script.h:93
@ OP_NIP
Definition: script.h:102
@ OP_2MUL
Definition: script.h:130
@ OP_NOP4
Definition: script.h:176
@ OP_NOP3
Definition: script.h:175
@ OP_1
Definition: script.h:59
@ OP_LESSTHANOREQUAL
Definition: script.h:152
@ OP_2DROP
Definition: script.h:92
@ OP_TRUE
Definition: script.h:60
@ OP_DEPTH
Definition: script.h:99
@ OP_NOP9
Definition: script.h:181
@ OP_VER
Definition: script.h:79
@ OP_VERIFY
Definition: script.h:86
@ OP_RESERVED2
Definition: script.h:125
@ OP_12
Definition: script.h:71
@ OP_ADD
Definition: script.h:137
@ OP_CHECKCOLDSTAKEVERIFY_LOF
Definition: script.h:190
@ OP_CHECKMULTISIGVERIFY
Definition: script.h:169
@ OP_NOP7
Definition: script.h:179
@ OP_8
Definition: script.h:67
@ OP_BOOLOR
Definition: script.h:146
@ OP_XOR
Definition: script.h:121
@ OP_DROP
Definition: script.h:100
@ OP_MUL
Definition: script.h:139
@ OP_WITHIN
Definition: script.h:157
@ OP_ELSE
Definition: script.h:84
@ OP_15
Definition: script.h:74
@ OP_CHECKSIGVERIFY
Definition: script.h:167
@ OP_PUSHDATA1
Definition: script.h:54
@ OP_TUCK
Definition: script.h:108
@ OP_2OVER
Definition: script.h:95
@ OP_0NOTEQUAL
Definition: script.h:135
@ OP_9
Definition: script.h:68
@ OP_3
Definition: script.h:62
@ OP_11
Definition: script.h:70
@ OP_SHA1
Definition: script.h:161
@ OP_SUBSTR
Definition: script.h:112
@ OP_GREATERTHANOREQUAL
Definition: script.h:153
@ OP_RSHIFT
Definition: script.h:143
@ OP_2SWAP
Definition: script.h:97
@ OP_PUSHDATA2
Definition: script.h:55
@ OP_2ROT
Definition: script.h:96
@ OP_6
Definition: script.h:65
@ OP_INVERT
Definition: script.h:118
@ OP_0
Definition: script.h:52
@ OP_ABS
Definition: script.h:133
@ OP_LSHIFT
Definition: script.h:142
@ OP_RETURN
Definition: script.h:87
@ OP_EXCHANGEADDR
Definition: script.h:194
@ OP_IFDUP
Definition: script.h:98
@ OP_PICK
Definition: script.h:104
@ OP_AND
Definition: script.h:119
@ OP_EQUALVERIFY
Definition: script.h:123
@ OP_CAT
Definition: script.h:111
@ OP_RESERVED
Definition: script.h:58
@ OP_1ADD
Definition: script.h:128
@ OP_7
Definition: script.h:66
@ OP_ZEROCOINPUBLICSPEND
Definition: script.h:187
@ OP_OR
Definition: script.h:120
@ OP_ROLL
Definition: script.h:105
@ OP_NOP6
Definition: script.h:178
@ OP_5
Definition: script.h:64
std::vector< unsigned char > valtype
Definition: script.h:25
#define READWRITEAS(type, obj)
Definition: serialize.h:184