]> Git Repo - VerusCoin.git/blame - src/script/interpreter.h
Merge pull request #484 from jl777/dPoW
[VerusCoin.git] / src / script / interpreter.h
CommitLineData
da03e6ed 1// Copyright (c) 2009-2010 Satoshi Nakamoto
f914f1a7 2// Copyright (c) 2009-2014 The Bitcoin Core developers
2d79bba3 3// Distributed under the MIT software license, see the accompanying
da03e6ed 4// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
84738627
PJ
6#ifndef BITCOIN_SCRIPT_INTERPRETER_H
7#define BITCOIN_SCRIPT_INTERPRETER_H
da03e6ed 8
ab9edbd6 9#include "script_error.h"
858809a3 10#include "primitives/transaction.h"
ab9edbd6 11
da03e6ed 12#include <vector>
13#include <stdint.h>
14#include <string>
6aae9d1a 15#include <climits>
da03e6ed 16
5c1e798a 17class CPubKey;
da03e6ed 18class CScript;
19class CTransaction;
5eed8c21 20class uint256;
da03e6ed 21
6aae9d1a
TH
22/** Special case nIn for signing JoinSplits. */
23const unsigned int NOT_AN_INPUT = UINT_MAX;
24
da03e6ed 25/** Signature hash types/flags */
26enum
27{
28 SIGHASH_ALL = 1,
29 SIGHASH_NONE = 2,
30 SIGHASH_SINGLE = 3,
31 SIGHASH_ANYONECANPAY = 0x80,
32};
33
34/** Script verification flags */
35enum
36{
37 SCRIPT_VERIFY_NONE = 0,
da03e6ed 38
9df9cf5a
PW
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.
98b135f9
PW
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).
9df9cf5a
PW
45 SCRIPT_VERIFY_STRICTENC = (1U << 1),
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).
55 SCRIPT_VERIFY_NULLDUMMY = (1U << 4),
d752ba86
PW
56
57 // Using a non-push operator in the scriptSig causes script failure (softfork safe, BIP62 rule 2).
58 SCRIPT_VERIFY_SIGPUSHONLY = (1U << 5),
698c6abb
PW
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)
03914234
PT
65 SCRIPT_VERIFY_MINIMALDATA = (1U << 6),
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.
b6e03cc5
PW
75 SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS = (1U << 7),
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.
82 SCRIPT_VERIFY_CLEANSTACK = (1U << 8),
4fa7a048
PT
83
84 // Verify CHECKLOCKTIMEVERIFY
85 //
86 // See BIP65 for details.
87 SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY = (1U << 9),
9df9cf5a 88};
da03e6ed 89
90uint256 SignatureHash(const CScript &scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType);
c7829ea7 91
5c1e798a
PW
92class BaseSignatureChecker
93{
94public:
e790c370 95 virtual bool CheckSig(const std::vector<unsigned char>& scriptSig, const std::vector<unsigned char>& vchPubKey, const CScript& scriptCode) const
5c1e798a
PW
96 {
97 return false;
98 }
99
4fa7a048
PT
100 virtual bool CheckLockTime(const CScriptNum& nLockTime) const
101 {
102 return false;
103 }
104
5c1e798a
PW
105 virtual ~BaseSignatureChecker() {}
106};
107
858809a3 108class TransactionSignatureChecker : public BaseSignatureChecker
c7829ea7
PW
109{
110private:
9fddceda 111 const CTransaction* txTo;
c7829ea7
PW
112 unsigned int nIn;
113
5c1e798a 114protected:
e790c370 115 virtual bool VerifySignature(const std::vector<unsigned char>& vchSig, const CPubKey& vchPubKey, const uint256& sighash) const;
5c1e798a 116
c7829ea7 117public:
9fddceda 118 TransactionSignatureChecker(const CTransaction* txToIn, unsigned int nInIn) : txTo(txToIn), nIn(nInIn) {}
e790c370 119 bool CheckSig(const std::vector<unsigned char>& scriptSig, const std::vector<unsigned char>& vchPubKey, const CScript& scriptCode) const;
4fa7a048 120 bool CheckLockTime(const CScriptNum& nLockTime) const;
c7829ea7
PW
121};
122
858809a3
PW
123class MutableTransactionSignatureChecker : public TransactionSignatureChecker
124{
125private:
126 const CTransaction txTo;
127
128public:
9fddceda 129 MutableTransactionSignatureChecker(const CMutableTransaction* txToIn, unsigned int nInIn) : TransactionSignatureChecker(&txTo, nInIn), txTo(*txToIn) {}
858809a3
PW
130};
131
ab9edbd6
CF
132bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript& script, unsigned int flags, const BaseSignatureChecker& checker, ScriptError* error = NULL);
133bool VerifyScript(const CScript& scriptSig, const CScript& scriptPubKey, unsigned int flags, const BaseSignatureChecker& checker, ScriptError* error = NULL);
da03e6ed 134
84738627 135#endif // BITCOIN_SCRIPT_INTERPRETER_H
This page took 0.140033 seconds and 4 git commands to generate.