PRCYCoin  2.0.0.7rc1
P2P Digital Currency
interpreter.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2014 The Bitcoin 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 
86 uint256 SignatureHash(const CScript &scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType);
87 
89 {
90 public:
91  virtual bool CheckSig(const std::vector<unsigned char>& scriptSig, const std::vector<unsigned char>& vchPubKey, const CScript& scriptCode) const
92  {
93  return false;
94  }
95 
96  virtual bool CheckLockTime(const CScriptNum& nLockTime) const
97  {
98  return false;
99  }
100 
102 };
103 
105 {
106 private:
108  unsigned int nIn;
109 
110 protected:
111  virtual bool VerifySignature(const std::vector<unsigned char>& vchSig, const CPubKey& vchPubKey, const uint256& sighash) const;
112 
113 public:
114  TransactionSignatureChecker(const CTransaction* txToIn, unsigned int nInIn) : txTo(txToIn), nIn(nInIn) {}
115  bool CheckSig(const std::vector<unsigned char>& scriptSig, const std::vector<unsigned char>& vchPubKey, const CScript& scriptCode) const;
116  bool CheckLockTime(const CScriptNum& nLockTime) const;
117 };
118 
120 {
121 private:
123 
124 public:
125  MutableTransactionSignatureChecker(const CMutableTransaction* txToIn, unsigned int nInIn) : TransactionSignatureChecker(&txTo, nInIn), txTo(*txToIn) {}
126 };
127 
128 bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript& script, unsigned int flags, const BaseSignatureChecker& checker, ScriptError* error = NULL);
129 bool VerifyScript(const CScript& scriptSig, const CScript& scriptPubKey, unsigned int flags, const BaseSignatureChecker& checker, ScriptError* error = NULL);
130 
131 #endif // BITCOIN_SCRIPT_INTERPRETER_H
SIGHASH_ANYONECANPAY
@ SIGHASH_ANYONECANPAY
Definition: interpreter.h:27
SCRIPT_VERIFY_NULLDUMMY
@ SCRIPT_VERIFY_NULLDUMMY
Definition: interpreter.h:51
BaseSignatureChecker::~BaseSignatureChecker
virtual ~BaseSignatureChecker()
Definition: interpreter.h:101
TransactionSignatureChecker::TransactionSignatureChecker
TransactionSignatureChecker(const CTransaction *txToIn, unsigned int nInIn)
Definition: interpreter.h:114
transaction.h
VerifyScript
bool VerifyScript(const CScript &scriptSig, const CScript &scriptPubKey, unsigned int flags, const BaseSignatureChecker &checker, ScriptError *error=NULL)
Definition: interpreter.cpp:1163
flags
int flags
Definition: prcycoin-tx.cpp:297
SCRIPT_VERIFY_MINIMALDATA
@ SCRIPT_VERIFY_MINIMALDATA
Definition: interpreter.h:61
BaseSignatureChecker
Definition: interpreter.h:88
SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY
@ SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY
Definition: interpreter.h:83
TransactionSignatureChecker::VerifySignature
virtual bool VerifySignature(const std::vector< unsigned char > &vchSig, const CPubKey &vchPubKey, const uint256 &sighash) const
Definition: interpreter.cpp:1101
SignatureHash
uint256 SignatureHash(const CScript &scriptCode, const CTransaction &txTo, unsigned int nIn, int nHashType)
Definition: interpreter.cpp:1077
SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS
@ SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS
Definition: interpreter.h:71
MutableTransactionSignatureChecker
Definition: interpreter.h:119
CTransaction
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:269
ScriptError
enum ScriptError_t ScriptError
CScriptNum
Definition: script.h:190
TransactionSignatureChecker
Definition: interpreter.h:104
BaseSignatureChecker::CheckSig
virtual bool CheckSig(const std::vector< unsigned char > &scriptSig, const std::vector< unsigned char > &vchPubKey, const CScript &scriptCode) const
Definition: interpreter.h:91
TransactionSignatureChecker::CheckLockTime
bool CheckLockTime(const CScriptNum &nLockTime) const
Definition: interpreter.cpp:1127
SCRIPT_VERIFY_CLEANSTACK
@ SCRIPT_VERIFY_CLEANSTACK
Definition: interpreter.h:78
uint256
256-bit unsigned big integer.
Definition: uint256.h:38
SCRIPT_VERIFY_NONE
@ SCRIPT_VERIFY_NONE
Definition: interpreter.h:33
CScript
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:363
SIGHASH_NONE
@ SIGHASH_NONE
Definition: interpreter.h:25
SCRIPT_VERIFY_LOW_S
@ SCRIPT_VERIFY_LOW_S
Definition: interpreter.h:48
MutableTransactionSignatureChecker::txTo
const CTransaction txTo
Definition: interpreter.h:122
TransactionSignatureChecker::CheckSig
bool CheckSig(const std::vector< unsigned char > &scriptSig, const std::vector< unsigned char > &vchPubKey, const CScript &scriptCode) const
Definition: interpreter.cpp:1106
MutableTransactionSignatureChecker::MutableTransactionSignatureChecker
MutableTransactionSignatureChecker(const CMutableTransaction *txToIn, unsigned int nInIn)
Definition: interpreter.h:125
CPubKey
An encapsulated public key.
Definition: pubkey.h:37
EvalScript
bool EvalScript(std::vector< std::vector< unsigned char > > &stack, const CScript &script, unsigned int flags, const BaseSignatureChecker &checker, ScriptError *error=NULL)
Definition: interpreter.cpp:241
TransactionSignatureChecker::nIn
unsigned int nIn
Definition: interpreter.h:108
script_error.h
SCRIPT_VERIFY_SIGPUSHONLY
@ SCRIPT_VERIFY_SIGPUSHONLY
Definition: interpreter.h:54
TransactionSignatureChecker::txTo
const CTransaction * txTo
Definition: interpreter.h:107
SCRIPT_VERIFY_STRICTENC
@ SCRIPT_VERIFY_STRICTENC
Definition: interpreter.h:41
SCRIPT_VERIFY_P2SH
@ SCRIPT_VERIFY_P2SH
Definition: interpreter.h:36
SIGHASH_SINGLE
@ SIGHASH_SINGLE
Definition: interpreter.h:26
SIGHASH_ALL
@ SIGHASH_ALL
Definition: interpreter.h:24
CMutableTransaction
A mutable version of CTransaction.
Definition: transaction.h:384
SCRIPT_VERIFY_DERSIG
@ SCRIPT_VERIFY_DERSIG
Definition: interpreter.h:44
BaseSignatureChecker::CheckLockTime
virtual bool CheckLockTime(const CScriptNum &nLockTime) const
Definition: interpreter.h:96
error
bool error(const char *fmt, const Args &... args)
Definition: util.h:61