]> Git Repo - VerusCoin.git/blob - src/script/interpreter.h
Merge pull request #5170
[VerusCoin.git] / src / script / interpreter.h
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
11 #include <vector>
12 #include <stdint.h>
13 #include <string>
14
15 class CPubKey;
16 class CScript;
17 class CTransaction;
18 class uint256;
19
20 /** Signature hash types/flags */
21 enum
22 {
23     SIGHASH_ALL = 1,
24     SIGHASH_NONE = 2,
25     SIGHASH_SINGLE = 3,
26     SIGHASH_ANYONECANPAY = 0x80,
27 };
28
29 /** Script verification flags */
30 enum
31 {
32     SCRIPT_VERIFY_NONE      = 0,
33
34     // Evaluate P2SH subscripts (softfork safe, BIP16).
35     SCRIPT_VERIFY_P2SH      = (1U << 0),
36
37     // Passing a non-strict-DER signature or one with undefined hashtype to a checksig operation causes script failure.
38     // Evaluating a pubkey that is not (0x04 + 64 bytes) or (0x02 or 0x03 + 32 bytes) by checksig causes script failure.
39     // (softfork safe, but not used or intended as a consensus rule).
40     SCRIPT_VERIFY_STRICTENC = (1U << 1),
41
42     // Passing a non-strict-DER signature to a checksig operation causes script failure (softfork safe, BIP62 rule 1)
43     SCRIPT_VERIFY_DERSIG    = (1U << 2),
44
45     // Passing a non-strict-DER signature or one with S > order/2 to a checksig operation causes script failure
46     // (softfork safe, BIP62 rule 5).
47     SCRIPT_VERIFY_LOW_S     = (1U << 3),
48
49     // verify dummy stack item consumed by CHECKMULTISIG is of zero-length (softfork safe, BIP62 rule 7).
50     SCRIPT_VERIFY_NULLDUMMY = (1U << 4),
51
52     // Using a non-push operator in the scriptSig causes script failure (softfork safe, BIP62 rule 2).
53     SCRIPT_VERIFY_SIGPUSHONLY = (1U << 5),
54
55     // Require minimal encodings for all push operations (OP_0... OP_16, OP_1NEGATE where possible, direct
56     // pushes up to 75 bytes, OP_PUSHDATA up to 255 bytes, OP_PUSHDATA2 for anything larger). Evaluating
57     // any other push causes the script to fail (BIP62 rule 3).
58     // In addition, whenever a stack element is interpreted as a number, it must be of minimal length (BIP62 rule 4).
59     // (softfork safe)
60     SCRIPT_VERIFY_MINIMALDATA = (1U << 6),
61
62     // Discourage use of NOPs reserved for upgrades (NOP1-10)
63     //
64     // Provided so that nodes can avoid accepting or mining transactions
65     // containing executed NOP's whose meaning may change after a soft-fork,
66     // thus rendering the script invalid; with this flag set executing
67     // discouraged NOPs fails the script. This verification flag will never be
68     // a mandatory flag applied to scripts in a block. NOPs that are not
69     // executed, e.g.  within an unexecuted IF ENDIF block, are *not* rejected.
70     SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS  = (1U << 7)
71
72 };
73
74 uint256 SignatureHash(const CScript &scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType);
75
76 class BaseSignatureChecker
77 {
78 public:
79     virtual bool CheckSig(const std::vector<unsigned char>& scriptSig, const std::vector<unsigned char>& vchPubKey, const CScript& scriptCode) const
80     {
81         return false;
82     }
83
84     virtual ~BaseSignatureChecker() {}
85 };
86
87 class SignatureChecker : public BaseSignatureChecker
88 {
89 private:
90     const CTransaction& txTo;
91     unsigned int nIn;
92
93 protected:
94     virtual bool VerifySignature(const std::vector<unsigned char>& vchSig, const CPubKey& vchPubKey, const uint256& sighash) const;
95
96 public:
97     SignatureChecker(const CTransaction& txToIn, unsigned int nInIn) : txTo(txToIn), nIn(nInIn) {}
98     bool CheckSig(const std::vector<unsigned char>& scriptSig, const std::vector<unsigned char>& vchPubKey, const CScript& scriptCode) const;
99 };
100
101 bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript& script, unsigned int flags, const BaseSignatureChecker& checker, ScriptError* error = NULL);
102 bool VerifyScript(const CScript& scriptSig, const CScript& scriptPubKey, unsigned int flags, const BaseSignatureChecker& checker, ScriptError* error = NULL);
103
104 #endif // BITCOIN_SCRIPT_INTERPRETER_H
This page took 0.0286 seconds and 4 git commands to generate.