Dash Core  0.12.2.1
P2P Digital Currency
interpreter.h
Go to the documentation of this file.
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_INTERPRETER_H
7 #define BITCOIN_SCRIPT_INTERPRETER_H
8 
9 #include "script_error.h"
10 #include "primitives/transaction.h"
11 
12 #include <vector>
13 #include <stdint.h>
14 #include <string>
15 
16 class CPubKey;
17 class CScript;
18 class CTransaction;
19 class uint256;
20 
22 enum
23 {
28 };
29 
31 enum
32 {
34 
35  // Evaluate P2SH subscripts (softfork safe, BIP16).
36  SCRIPT_VERIFY_P2SH = (1U << 0),
37 
38  // Passing a non-strict-DER signature or one with undefined hashtype to a checksig operation causes script failure.
39  // Evaluating a pubkey that is not (0x04 + 64 bytes) or (0x02 or 0x03 + 32 bytes) by checksig causes script failure.
40  // (softfork safe, but not used or intended as a consensus rule).
42 
43  // Passing a non-strict-DER signature to a checksig operation causes script failure (softfork safe, BIP62 rule 1)
44  SCRIPT_VERIFY_DERSIG = (1U << 2),
45 
46  // Passing a non-strict-DER signature or one with S > order/2 to a checksig operation causes script failure
47  // (softfork safe, BIP62 rule 5).
48  SCRIPT_VERIFY_LOW_S = (1U << 3),
49 
50  // verify dummy stack item consumed by CHECKMULTISIG is of zero-length (softfork safe, BIP62 rule 7).
52 
53  // Using a non-push operator in the scriptSig causes script failure (softfork safe, BIP62 rule 2).
55 
56  // Require minimal encodings for all push operations (OP_0... OP_16, OP_1NEGATE where possible, direct
57  // pushes up to 75 bytes, OP_PUSHDATA up to 255 bytes, OP_PUSHDATA2 for anything larger). Evaluating
58  // any other push causes the script to fail (BIP62 rule 3).
59  // In addition, whenever a stack element is interpreted as a number, it must be of minimal length (BIP62 rule 4).
60  // (softfork safe)
62 
63  // Discourage use of NOPs reserved for upgrades (NOP1-10)
64  //
65  // Provided so that nodes can avoid accepting or mining transactions
66  // containing executed NOP's whose meaning may change after a soft-fork,
67  // thus rendering the script invalid; with this flag set executing
68  // discouraged NOPs fails the script. This verification flag will never be
69  // a mandatory flag applied to scripts in a block. NOPs that are not
70  // executed, e.g. within an unexecuted IF ENDIF block, are *not* rejected.
72 
73  // Require that only a single stack element remains after evaluation. This changes the success criterion from
74  // "At least one stack element must remain, and when interpreted as a boolean, it must be true" to
75  // "Exactly one stack element must remain, and when interpreted as a boolean, it must be true".
76  // (softfork safe, BIP62 rule 6)
77  // Note: CLEANSTACK should never be used without P2SH.
79 
80  // Verify CHECKLOCKTIMEVERIFY
81  //
82  // See BIP65 for details.
84 
85  // support CHECKSEQUENCEVERIFY opcode
86  //
87  // See BIP112 for details
89 };
90 
91 bool CheckSignatureEncoding(const std::vector<unsigned char> &vchSig, unsigned int flags, ScriptError* serror);
92 
93 uint256 SignatureHash(const CScript &scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType);
94 
96 {
97 public:
98  virtual bool CheckSig(const std::vector<unsigned char>& scriptSig, const std::vector<unsigned char>& vchPubKey, const CScript& scriptCode) const
99  {
100  return false;
101  }
102 
103  virtual bool CheckLockTime(const CScriptNum& nLockTime) const
104  {
105  return false;
106  }
107 
108  virtual bool CheckSequence(const CScriptNum& nSequence) const
109  {
110  return false;
111  }
112 
114 };
115 
117 {
118 private:
120  unsigned int nIn;
121 
122 protected:
123  virtual bool VerifySignature(const std::vector<unsigned char>& vchSig, const CPubKey& vchPubKey, const uint256& sighash) const;
124 
125 public:
126  TransactionSignatureChecker(const CTransaction* txToIn, unsigned int nInIn) : txTo(txToIn), nIn(nInIn) {}
127  bool CheckSig(const std::vector<unsigned char>& scriptSig, const std::vector<unsigned char>& vchPubKey, const CScript& scriptCode) const;
128  bool CheckLockTime(const CScriptNum& nLockTime) const;
129  bool CheckSequence(const CScriptNum& nSequence) const;
130 };
131 
133 {
134 private:
136 
137 public:
138  MutableTransactionSignatureChecker(const CMutableTransaction* txToIn, unsigned int nInIn) : TransactionSignatureChecker(&txTo, nInIn), txTo(*txToIn) {}
139 };
140 
141 bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript& script, unsigned int flags, const BaseSignatureChecker& checker, ScriptError* error = NULL);
142 bool VerifyScript(const CScript& scriptSig, const CScript& scriptPubKey, unsigned int flags, const BaseSignatureChecker& checker, ScriptError* error = NULL);
143 
144 #endif // BITCOIN_SCRIPT_INTERPRETER_H
virtual bool CheckSig(const std::vector< unsigned char > &scriptSig, const std::vector< unsigned char > &vchPubKey, const CScript &scriptCode) const
Definition: interpreter.h:98
enum ScriptError_t ScriptError
uint256 SignatureHash(const CScript &scriptCode, const CTransaction &txTo, unsigned int nIn, int nHashType)
int flags
Definition: dash-tx.cpp:326
bool CheckSignatureEncoding(const std::vector< unsigned char > &vchSig, unsigned int flags, ScriptError *serror)
bool CheckLockTime(const CScriptNum &nLockTime) const
bool CheckSig(const std::vector< unsigned char > &scriptSig, const std::vector< unsigned char > &vchPubKey, const CScript &scriptCode) const
virtual bool CheckLockTime(const CScriptNum &nLockTime) const
Definition: interpreter.h:103
static bool error(const char *format)
Definition: util.h:131
bool CheckSequence(const CScriptNum &nSequence) const
const CTransaction * txTo
Definition: interpreter.h:119
bool VerifyScript(const CScript &scriptSig, const CScript &scriptPubKey, unsigned int flags, const BaseSignatureChecker &checker, ScriptError *error=NULL)
virtual bool CheckSequence(const CScriptNum &nSequence) const
Definition: interpreter.h:108
virtual bool VerifySignature(const std::vector< unsigned char > &vchSig, const CPubKey &vchPubKey, const uint256 &sighash) const
Definition: pubkey.h:37
MutableTransactionSignatureChecker(const CMutableTransaction *txToIn, unsigned int nInIn)
Definition: interpreter.h:138
TransactionSignatureChecker(const CTransaction *txToIn, unsigned int nInIn)
Definition: interpreter.h:126
bool EvalScript(std::vector< std::vector< unsigned char > > &stack, const CScript &script, unsigned int flags, const BaseSignatureChecker &checker, ScriptError *error=NULL)
virtual ~BaseSignatureChecker()
Definition: interpreter.h:113