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