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.
6 #ifndef BITCOIN_SCRIPT_INTERPRETER_H
7 #define BITCOIN_SCRIPT_INTERPRETER_H
9 #include "script_error.h"
20 /** Signature hash types/flags */
26 SIGHASH_ANYONECANPAY = 0x80,
29 /** Script verification flags */
32 SCRIPT_VERIFY_NONE = 0,
34 // Evaluate P2SH subscripts (softfork safe, BIP16).
35 SCRIPT_VERIFY_P2SH = (1U << 0),
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),
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),
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),
49 // verify dummy stack item consumed by CHECKMULTISIG is of zero-length (softfork safe, BIP62 rule 7).
50 SCRIPT_VERIFY_NULLDUMMY = (1U << 4),
52 // Using a non-push operator in the scriptSig causes script failure (softfork safe, BIP62 rule 2).
53 SCRIPT_VERIFY_SIGPUSHONLY = (1U << 5),
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).
60 SCRIPT_VERIFY_MINIMALDATA = (1U << 6),
62 // Discourage use of NOPs reserved for upgrades (NOP1-10)
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)
74 uint256 SignatureHash(const CScript &scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType);
76 class BaseSignatureChecker
79 virtual bool CheckSig(const std::vector<unsigned char>& scriptSig, const std::vector<unsigned char>& vchPubKey, const CScript& scriptCode) const
84 virtual ~BaseSignatureChecker() {}
87 class SignatureChecker : public BaseSignatureChecker
90 const CTransaction& txTo;
94 virtual bool VerifySignature(const std::vector<unsigned char>& vchSig, const CPubKey& vchPubKey, const uint256& sighash) const;
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;
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);
104 #endif // BITCOIN_SCRIPT_INTERPRETER_H