Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

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/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 
35 enum
36 {
38 
39  // Evaluate P2SH subscripts (BIP16).
40  SCRIPT_VERIFY_P2SH = (1U << 0),
41 
42  // Passing a non-strict-DER signature or one with undefined hashtype to a checksig operation causes script failure.
43  // Evaluating a pubkey that is not (0x04 + 64 bytes) or (0x02 or 0x03 + 32 bytes) by checksig causes script failure.
44  // (not used or intended as a consensus rule).
46 
47  // Passing a non-strict-DER signature to a checksig operation causes script failure (BIP62 rule 1)
48  SCRIPT_VERIFY_DERSIG = (1U << 2),
49 
50  // Passing a non-strict-DER signature or one with S > order/2 to a checksig operation causes script failure
51  // (BIP62 rule 5).
52  SCRIPT_VERIFY_LOW_S = (1U << 3),
53 
54  // verify dummy stack item consumed by CHECKMULTISIG is of zero-length (BIP62 rule 7).
56 
57  // Using a non-push operator in the scriptSig causes script failure (BIP62 rule 2).
59 
60  // Require minimal encodings for all push operations (OP_0... OP_16, OP_1NEGATE where possible, direct
61  // pushes up to 75 bytes, OP_PUSHDATA up to 255 bytes, OP_PUSHDATA2 for anything larger). Evaluating
62  // any other push causes the script to fail (BIP62 rule 3).
63  // In addition, whenever a stack element is interpreted as a number, it must be of minimal length (BIP62 rule 4).
65 
66  // Discourage use of NOPs reserved for upgrades (NOP1-10)
67  //
68  // Provided so that nodes can avoid accepting or mining transactions
69  // containing executed NOP's whose meaning may change after a soft-fork,
70  // thus rendering the script invalid; with this flag set executing
71  // discouraged NOPs fails the script. This verification flag will never be
72  // a mandatory flag applied to scripts in a block. NOPs that are not
73  // executed, e.g. within an unexecuted IF ENDIF block, are *not* rejected.
74  // NOPs that have associated forks to give them new meaning (CLTV, CSV)
75  // are not subject to this rule.
77 
78  // Require that only a single stack element remains after evaluation. This changes the success criterion from
79  // "At least one stack element must remain, and when interpreted as a boolean, it must be true" to
80  // "Exactly one stack element must remain, and when interpreted as a boolean, it must be true".
81  // (BIP62 rule 6)
82  // Note: CLEANSTACK should never be used without P2SH.
84 
85  // Verify CHECKLOCKTIMEVERIFY
86  //
87  // See BIP65 for details.
89 
90  // support CHECKSEQUENCEVERIFY opcode
91  //
92  // See BIP112 for details
94 
95  // Signature(s) must be empty vector if an CHECK(MULTI)SIG operation failed
96  //
97  SCRIPT_VERIFY_NULLFAIL = (1U << 14),
98 };
99 
100 bool CheckSignatureEncoding(const std::vector<unsigned char> &vchSig, unsigned int flags, ScriptError* serror);
101 
103 {
105 
106  explicit PrecomputedTransactionData(const CTransaction& tx);
107 };
108 
110 {
112 };
113 
114 uint256 SignatureHash(const CScript &scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType, const CAmount& amount, SigVersion sigversion, const PrecomputedTransactionData* cache = nullptr);
115 
117 {
118 public:
119  virtual bool CheckSig(const std::vector<unsigned char>& scriptSig, const std::vector<unsigned char>& vchPubKey, const CScript& scriptCode, SigVersion sigversion) const
120  {
121  return false;
122  }
123 
124  virtual bool CheckLockTime(const CScriptNum& nLockTime) const
125  {
126  return false;
127  }
128 
129  virtual bool CheckSequence(const CScriptNum& nSequence) const
130  {
131  return false;
132  }
133 
135 };
136 
138 {
139 private:
141  unsigned int nIn;
144 
145 protected:
146  virtual bool VerifySignature(const std::vector<unsigned char>& vchSig, const CPubKey& vchPubKey, const uint256& sighash) const;
147 
148 public:
149  TransactionSignatureChecker(const CTransaction* txToIn, unsigned int nInIn, const CAmount& amountIn) : txTo(txToIn), nIn(nInIn), amount(amountIn), txdata(nullptr) {}
150  TransactionSignatureChecker(const CTransaction* txToIn, unsigned int nInIn, const CAmount& amountIn, const PrecomputedTransactionData& txdataIn) : txTo(txToIn), nIn(nInIn), amount(amountIn), txdata(&txdataIn) {}
151  bool CheckSig(const std::vector<unsigned char>& scriptSig, const std::vector<unsigned char>& vchPubKey, const CScript& scriptCode, SigVersion sigversion) const override;
152  bool CheckLockTime(const CScriptNum& nLockTime) const override;
153  bool CheckSequence(const CScriptNum& nSequence) const override;
154 };
155 
157 {
158 private:
160 
161 public:
162  MutableTransactionSignatureChecker(const CMutableTransaction* txToIn, unsigned int nInIn, const CAmount& amount) : TransactionSignatureChecker(&txTo, nInIn, amount), txTo(*txToIn) {}
163 };
164 
165 bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript& script, unsigned int flags, const BaseSignatureChecker& checker, SigVersion sigversion, ScriptError* error = nullptr);
166 bool VerifyScript(const CScript& scriptSig, const CScript& scriptPubKey, unsigned int flags, const BaseSignatureChecker& checker, ScriptError* error = nullptr);
167 
168 #endif // BITCOIN_SCRIPT_INTERPRETER_H
virtual bool CheckLockTime(const CScriptNum &nLockTime) const
Definition: interpreter.h:124
virtual ~BaseSignatureChecker()
Definition: interpreter.h:134
const PrecomputedTransactionData * txdata
Definition: interpreter.h:143
enum ScriptError_t ScriptError
virtual bool VerifySignature(const std::vector< unsigned char > &vchSig, const CPubKey &vchPubKey, const uint256 &sighash) const
bool CheckSequence(const CScriptNum &nSequence) const override
MutableTransactionSignatureChecker(const CMutableTransaction *txToIn, unsigned int nInIn, const CAmount &amount)
Definition: interpreter.h:162
int flags
Definition: dash-tx.cpp:462
bool CheckSignatureEncoding(const std::vector< unsigned char > &vchSig, unsigned int flags, ScriptError *serror)
TransactionSignatureChecker(const CTransaction *txToIn, unsigned int nInIn, const CAmount &amountIn, const PrecomputedTransactionData &txdataIn)
Definition: interpreter.h:150
bool CheckSig(const std::vector< unsigned char > &scriptSig, const std::vector< unsigned char > &vchPubKey, const CScript &scriptCode, SigVersion sigversion) const override
uint256 SignatureHash(const CScript &scriptCode, const CTransaction &txTo, unsigned int nIn, int nHashType, const CAmount &amount, SigVersion sigversion, const PrecomputedTransactionData *cache=nullptr)
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
bool EvalScript(std::vector< std::vector< unsigned char > > &stack, const CScript &script, unsigned int flags, const BaseSignatureChecker &checker, SigVersion sigversion, ScriptError *error=nullptr)
bool VerifyScript(const CScript &scriptSig, const CScript &scriptPubKey, unsigned int flags, const BaseSignatureChecker &checker, ScriptError *error=nullptr)
PrecomputedTransactionData(const CTransaction &tx)
An encapsulated public key.
Definition: pubkey.h:30
bool CheckLockTime(const CScriptNum &nLockTime) const override
TransactionSignatureChecker(const CTransaction *txToIn, unsigned int nInIn, const CAmount &amountIn)
Definition: interpreter.h:149
256-bit opaque blob.
Definition: uint256.h:123
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:389
virtual bool CheckSig(const std::vector< unsigned char > &scriptSig, const std::vector< unsigned char > &vchPubKey, const CScript &scriptCode, SigVersion sigversion) const
Definition: interpreter.h:119
virtual bool CheckSequence(const CScriptNum &nSequence) const
Definition: interpreter.h:129
bool error(const char *fmt, const Args &... args)
Definition: util.h:222
A mutable version of CTransaction.
Definition: transaction.h:291
The basic transaction that is broadcasted on the network and contained in blocks. ...
Definition: transaction.h:198
const CTransaction * txTo
Definition: interpreter.h:140
SigVersion
Definition: interpreter.h:109
Released under the MIT license