Raven Core  3.0.0
P2P Digital Currency
interpreter.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2016 The Bitcoin Core developers
3 // Copyright (c) 2017-2019 The Raven Core developers
4 // Distributed under the MIT software license, see the accompanying
5 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 
7 #ifndef RAVEN_SCRIPT_INTERPRETER_H
8 #define RAVEN_SCRIPT_INTERPRETER_H
9 
10 #include "script_error.h"
11 #include "primitives/transaction.h"
12 
13 #include <vector>
14 #include <stdint.h>
15 #include <string>
16 
17 class CPubKey;
18 
19 class CScript;
20 
21 class CTransaction;
22 
23 class uint256;
24 
26 enum
27 {
32 };
33 
35 enum
36 {
38 
39  // Evaluate P2SH subscripts (softfork safe, 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  // (softfork safe, but not used or intended as a consensus rule).
46 
47  // Passing a non-strict-DER signature to a checksig operation causes script failure (softfork safe, 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  // (softfork safe, BIP62 rule 5).
52  SCRIPT_VERIFY_LOW_S = (1U << 3),
53 
54  // verify dummy stack item consumed by CHECKMULTISIG is of zero-length (softfork safe, BIP62 rule 7).
56 
57  // Using a non-push operator in the scriptSig causes script failure (softfork safe, 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).
64  // (softfork safe)
66 
67  // Discourage use of NOPs reserved for upgrades (NOP1-10)
68  //
69  // Provided so that nodes can avoid accepting or mining transactions
70  // containing executed NOP's whose meaning may change after a soft-fork,
71  // thus rendering the script invalid; with this flag set executing
72  // discouraged NOPs fails the script. This verification flag will never be
73  // a mandatory flag applied to scripts in a block. NOPs that are not
74  // executed, e.g. within an unexecuted IF ENDIF block, are *not* rejected.
76 
77  // Require that only a single stack element remains after evaluation. This changes the success criterion from
78  // "At least one stack element must remain, and when interpreted as a boolean, it must be true" to
79  // "Exactly one stack element must remain, and when interpreted as a boolean, it must be true".
80  // (softfork safe, BIP62 rule 6)
81  // Note: CLEANSTACK should never be used without P2SH or WITNESS.
83 
84  // Verify CHECKLOCKTIMEVERIFY
85  //
86  // See BIP65 for details.
88 
89  // support CHECKSEQUENCEVERIFY opcode
90  //
91  // See BIP112 for details
93 
94  // Support segregated witness
95  //
96  SCRIPT_VERIFY_WITNESS = (1U << 11),
97 
98  // Making v1-v16 witness program non-standard
99  //
101 
102  // Segwit script only: Require the argument of OP_IF/NOTIF to be exactly 0x01 or empty vector
103  //
105 
106  // Signature(s) must be empty vector if an CHECK(MULTI)SIG operation failed
107  //
109 
110  // Public keys in segregated witness scripts must be compressed
111  //
113 };
114 
115 bool CheckSignatureEncoding(const std::vector<unsigned char> &vchSig, unsigned int flags, ScriptError *serror);
116 
118 {
120  bool ready = false;
121 
122  explicit PrecomputedTransactionData(const CTransaction &tx);
123 };
124 
126 {
129 };
130 
131 uint256 SignatureHash(const CScript &scriptCode, const CTransaction &txTo, unsigned int nIn, int nHashType, const CAmount &amount, SigVersion sigversion, const PrecomputedTransactionData *cache = nullptr);
132 
134 {
135 public:
136  virtual bool CheckSig(const std::vector<unsigned char> &scriptSig, const std::vector<unsigned char> &vchPubKey, const CScript &scriptCode, SigVersion sigversion) const
137  {
138  return false;
139  }
140 
141  virtual bool CheckLockTime(const CScriptNum &nLockTime) const
142  {
143  return false;
144  }
145 
146  virtual bool CheckSequence(const CScriptNum &nSequence) const
147  {
148  return false;
149  }
150 
152 };
153 
155 {
156 private:
158  unsigned int nIn;
161 
162 protected:
163  virtual bool VerifySignature(const std::vector<unsigned char> &vchSig, const CPubKey &vchPubKey, const uint256 &sighash) const;
164 
165 public:
166  TransactionSignatureChecker(const CTransaction *txToIn, unsigned int nInIn, const CAmount &amountIn) : txTo(txToIn), nIn(nInIn), amount(amountIn), txdata(nullptr) {}
167 
168  TransactionSignatureChecker(const CTransaction *txToIn, unsigned int nInIn, const CAmount &amountIn, const PrecomputedTransactionData &txdataIn) : txTo(txToIn), nIn(nInIn), amount(amountIn), txdata(&txdataIn) {}
169 
170  bool CheckSig(const std::vector<unsigned char> &scriptSig, const std::vector<unsigned char> &vchPubKey, const CScript &scriptCode, SigVersion sigversion) const override;
171 
172  bool CheckLockTime(const CScriptNum &nLockTime) const override;
173 
174  bool CheckSequence(const CScriptNum &nSequence) const override;
175 };
176 
178 {
179 private:
181 
182 public:
183  MutableTransactionSignatureChecker(const CMutableTransaction *txToIn, unsigned int nInIn, const CAmount &amountIn) : TransactionSignatureChecker(&txTo, nInIn, amountIn), txTo(*txToIn) {}
184 };
185 
186 bool EvalScript(std::vector<std::vector<unsigned char> > &stack, const CScript &script, unsigned int flags, const BaseSignatureChecker &checker, SigVersion sigversion, ScriptError *error = nullptr);
187 
188 bool VerifyScript(const CScript &scriptSig, const CScript &scriptPubKey, const CScriptWitness *witness, unsigned int flags, const BaseSignatureChecker &checker, ScriptError *serror = nullptr);
189 
190 size_t CountWitnessSigOps(const CScript &scriptSig, const CScript &scriptPubKey, const CScriptWitness *witness, unsigned int flags);
191 
192 #endif // RAVEN_SCRIPT_INTERPRETER_H
MutableTransactionSignatureChecker(const CMutableTransaction *txToIn, unsigned int nInIn, const CAmount &amountIn)
Definition: interpreter.h:183
virtual bool CheckLockTime(const CScriptNum &nLockTime) const
Definition: interpreter.h:141
virtual ~BaseSignatureChecker()
Definition: interpreter.h:151
const PrecomputedTransactionData * txdata
Definition: interpreter.h:160
bool VerifyScript(const CScript &scriptSig, const CScript &scriptPubKey, const CScriptWitness *witness, unsigned int flags, const BaseSignatureChecker &checker, ScriptError *serror=nullptr)
enum ScriptError_t ScriptError
int flags
Definition: raven-tx.cpp:500
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:168
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 corbies (Can be negative)
Definition: amount.h:13
bool EvalScript(std::vector< std::vector< unsigned char > > &stack, const CScript &script, unsigned int flags, const BaseSignatureChecker &checker, SigVersion sigversion, ScriptError *error=nullptr)
PrecomputedTransactionData(const CTransaction &tx)
An encapsulated public key.
Definition: pubkey.h:40
TransactionSignatureChecker(const CTransaction *txToIn, unsigned int nInIn, const CAmount &amountIn)
Definition: interpreter.h:166
256-bit opaque blob.
Definition: uint256.h:123
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:396
virtual bool CheckSig(const std::vector< unsigned char > &scriptSig, const std::vector< unsigned char > &vchPubKey, const CScript &scriptCode, SigVersion sigversion) const
Definition: interpreter.h:136
virtual bool CheckSequence(const CScriptNum &nSequence) const
Definition: interpreter.h:146
bool error(const char *fmt, const Args &... args)
Definition: util.h:168
A mutable version of CTransaction.
Definition: transaction.h:389
The basic transaction that is broadcasted on the network and contained in blocks. ...
Definition: transaction.h:270
const CTransaction * txTo
Definition: interpreter.h:157
SigVersion
Definition: interpreter.h:125