Fabcoin Core  0.16.2
P2P Digital Currency
interpreter.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2017 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 FABCOIN_SCRIPT_INTERPRETER_H
7 #define FABCOIN_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 
21 typedef std::vector<unsigned char> valtype;
23 enum
24 {
29 };
30 
32 enum
33 {
35 
36  // Evaluate P2SH subscripts (softfork safe, BIP16).
37  SCRIPT_VERIFY_P2SH = (1U << 0),
38 
39  // Passing a non-strict-DER signature or one with undefined hashtype to a checksig operation causes script failure.
40  // Evaluating a pubkey that is not (0x04 + 64 bytes) or (0x02 or 0x03 + 32 bytes) by checksig causes script failure.
41  // (softfork safe, but not used or intended as a consensus rule).
43 
44  // Passing a non-strict-DER signature to a checksig operation causes script failure (softfork safe, BIP62 rule 1)
45  SCRIPT_VERIFY_DERSIG = (1U << 2),
46 
47  // Passing a non-strict-DER signature or one with S > order/2 to a checksig operation causes script failure
48  // (softfork safe, BIP62 rule 5).
49  SCRIPT_VERIFY_LOW_S = (1U << 3),
50 
51  // verify dummy stack item consumed by CHECKMULTISIG is of zero-length (softfork safe, BIP62 rule 7).
53 
54  // Using a non-push operator in the scriptSig causes script failure (softfork safe, BIP62 rule 2).
56 
57  // Require minimal encodings for all push operations (OP_0... OP_16, OP_1NEGATE where possible, direct
58  // pushes up to 75 bytes, OP_PUSHDATA up to 255 bytes, OP_PUSHDATA2 for anything larger). Evaluating
59  // any other push causes the script to fail (BIP62 rule 3).
60  // In addition, whenever a stack element is interpreted as a number, it must be of minimal length (BIP62 rule 4).
61  // (softfork safe)
63 
64  // Discourage use of NOPs reserved for upgrades (NOP1-10)
65  //
66  // Provided so that nodes can avoid accepting or mining transactions
67  // containing executed NOP's whose meaning may change after a soft-fork,
68  // thus rendering the script invalid; with this flag set executing
69  // discouraged NOPs fails the script. This verification flag will never be
70  // a mandatory flag applied to scripts in a block. NOPs that are not
71  // executed, e.g. within an unexecuted IF ENDIF block, are *not* rejected.
73 
74  // Require that only a single stack element remains after evaluation. This changes the success criterion from
75  // "At least one stack element must remain, and when interpreted as a boolean, it must be true" to
76  // "Exactly one stack element must remain, and when interpreted as a boolean, it must be true".
77  // (softfork safe, BIP62 rule 6)
78  // Note: CLEANSTACK should never be used without P2SH or WITNESS.
80 
81  // Verify CHECKLOCKTIMEVERIFY
82  //
83  // See BIP65 for details.
85 
86  // support CHECKSEQUENCEVERIFY opcode
87  //
88  // See BIP112 for details
90 
91  // Support segregated witness
92  //
93  SCRIPT_VERIFY_WITNESS = (1U << 11),
94 
95  // Making v1-v16 witness program non-standard
96  //
98 
99  // Segwit script only: Require the argument of OP_IF/NOTIF to be exactly 0x01 or empty vector
100  //
102 
103  // Signature(s) must be empty vector if an CHECK(MULTI)SIG operation failed
104  //
106 
107  // Public keys in segregated witness scripts must be compressed
108  //
110  // Performs the compiled byte code
111  //
112  SCRIPT_EXEC_BYTE_CODE = (1U << 30),
113 };
114 
115 bool CheckSignatureEncoding(const std::vector<unsigned char> &vchSig, unsigned int flags, ScriptError* serror);
116 
118 {
120 
122 };
123 
125 {
128 };
129 
130 uint256 SignatureHash(const CScript &scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType, const CAmount& amount, SigVersion sigversion, const PrecomputedTransactionData* cache = nullptr);
131 
133 {
134 public:
135  virtual bool CheckSig(const std::vector<unsigned char>& scriptSig, const std::vector<unsigned char>& vchPubKey, const CScript& scriptCode, SigVersion sigversion) const
136  {
137  return false;
138  }
139 
140  virtual bool CheckLockTime(const CScriptNum& nLockTime) const
141  {
142  return false;
143  }
144 
145  virtual bool CheckSequence(const CScriptNum& nSequence) const
146  {
147  return false;
148  }
149 
151 };
152 
154 {
155 private:
157  unsigned int nIn;
160 
161 protected:
162  virtual bool VerifySignature(const std::vector<unsigned char>& vchSig, const CPubKey& vchPubKey, const uint256& sighash) const;
163 
164 public:
165  TransactionSignatureChecker(const CTransaction* txToIn, unsigned int nInIn, const CAmount& amountIn) : txTo(txToIn), nIn(nInIn), amount(amountIn), txdata(nullptr) {}
166  TransactionSignatureChecker(const CTransaction* txToIn, unsigned int nInIn, const CAmount& amountIn, const PrecomputedTransactionData& txdataIn) : txTo(txToIn), nIn(nInIn), amount(amountIn), txdata(&txdataIn) {}
167  bool CheckSig(const std::vector<unsigned char>& scriptSig, const std::vector<unsigned char>& vchPubKey, const CScript& scriptCode, SigVersion sigversion) const override;
168  bool CheckLockTime(const CScriptNum& nLockTime) const override;
169  bool CheckSequence(const CScriptNum& nSequence) const override;
170 };
171 
173 {
174 private:
176 
177 public:
178  MutableTransactionSignatureChecker(const CMutableTransaction* txToIn, unsigned int nInIn, const CAmount& amountIn) : TransactionSignatureChecker(&txTo, nInIn, amountIn), txTo(*txToIn) {}
179 };
180 
181 bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript& script, unsigned int flags, const BaseSignatureChecker& checker, SigVersion sigversion, ScriptError* error = nullptr);
182 bool VerifyScript(const CScript& scriptSig, const CScript& scriptPubKey, const CScriptWitness* witness, unsigned int flags, const BaseSignatureChecker& checker, ScriptError* serror = nullptr);
183 
184 size_t CountWitnessSigOps(const CScript& scriptSig, const CScript& scriptPubKey, const CScriptWitness* witness, unsigned int flags);
185 
186 bool IsLowDERSignature(const valtype &vchSig, ScriptError* serror = NULL, bool haveHashType = true);
187 bool IsDERSignature(const valtype &vchSig, ScriptError* serror = NULL, bool haveHashType = true);
188 bool IsCompressedOrUncompressedPubKey(const valtype &vchPubKey);
189 #endif // FABCOIN_SCRIPT_INTERPRETER_H
MutableTransactionSignatureChecker(const CMutableTransaction *txToIn, unsigned int nInIn, const CAmount &amountIn)
Definition: interpreter.h:178
bool IsLowDERSignature(const valtype &vchSig, ScriptError *serror=NULL, bool haveHashType=true)
virtual ~BaseSignatureChecker()
Definition: interpreter.h:150
bool error(const char *fmt, const Args &...args)
Definition: util.h:178
const PrecomputedTransactionData * txdata
Definition: interpreter.h:159
bool VerifyScript(const CScript &scriptSig, const CScript &scriptPubKey, const CScriptWitness *witness, unsigned int flags, const BaseSignatureChecker &checker, ScriptError *serror=nullptr)
enum ScriptError_t ScriptError
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:166
#define nullptr
Definition: eqcuda.hpp:22
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 lius (Can be negative)
Definition: amount.h:15
bool EvalScript(std::vector< std::vector< unsigned char > > &stack, const CScript &script, unsigned int flags, const BaseSignatureChecker &checker, SigVersion sigversion, ScriptError *error=nullptr)
bool IsCompressedOrUncompressedPubKey(const valtype &vchPubKey)
Definition: interpreter.cpp:65
PrecomputedTransactionData(const CTransaction &tx)
An encapsulated public key.
Definition: pubkey.h:39
virtual bool CheckLockTime(const CScriptNum &nLockTime) const
Definition: interpreter.h:140
TransactionSignatureChecker(const CTransaction *txToIn, unsigned int nInIn, const CAmount &amountIn)
Definition: interpreter.h:165
std::vector< unsigned char > valtype
Definition: interpreter.h:19
bool IsDERSignature(const valtype &vchSig, ScriptError *serror=NULL, bool haveHashType=true)
virtual bool CheckSequence(const CScriptNum &nSequence) const
Definition: interpreter.h:145
256-bit opaque blob.
Definition: uint256.h:132
size_t CountWitnessSigOps(const CScript &scriptSig, const CScript &scriptPubKey, const CScriptWitness *witness, unsigned int flags)
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:417
bool VerifySignature(const Coin &coin, const uint256 txFromHash, const CTransaction &txTo, unsigned int nIn, unsigned int flags)
Definition: sign.cpp:228
A mutable version of CTransaction.
Definition: transaction.h:390
std::vector< unsigned char > valtype
Definition: fascstate.h:17
The basic transaction that is broadcasted on the network and contained in blocks. ...
Definition: transaction.h:275
const CTransaction * txTo
Definition: interpreter.h:156
virtual bool CheckSig(const std::vector< unsigned char > &scriptSig, const std::vector< unsigned char > &vchPubKey, const CScript &scriptCode, SigVersion sigversion) const
Definition: interpreter.h:135
SigVersion
Definition: interpreter.h:124