1
1
// Copyright (c) 2009-2010 Satoshi Nakamoto
2
// Copyright (c) 2009-2014 The Bitcoin developers
2
// Copyright (c) 2009-2014 The Bitcoin Core developers
3
3
// Distributed under the MIT software license, see the accompanying
4
4
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
1036
1036
uint256 SignatureHash(const CScript& scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType)
1038
static const uint256 one(uint256S("0000000000000000000000000000000000000000000000000000000000000001"));
1038
1039
if (nIn >= txTo.vin.size()) {
1039
1040
// nIn out of range
1043
1044
// Check for invalid use of SIGHASH_SINGLE
1044
1045
if ((nHashType & 0x1f) == SIGHASH_SINGLE) {
1045
1046
if (nIn >= txTo.vout.size()) {
1046
1047
// nOut out of range
1113
1113
if (!scriptSig.IsPushOnly())
1114
1114
return set_error(serror, SCRIPT_ERR_SIG_PUSHONLY);
1116
// stackCopy cannot be empty here, because if it was the
1117
swap(stack, stackCopy);
1119
// stack cannot be empty here, because if it was the
1117
1120
// P2SH HASH <> EQUAL scriptPubKey would be evaluated with
1118
1121
// an empty stack and the EvalScript above would return false.
1119
assert(!stackCopy.empty());
1122
assert(!stack.empty());
1121
const valtype& pubKeySerialized = stackCopy.back();
1124
const valtype& pubKeySerialized = stack.back();
1122
1125
CScript pubKey2(pubKeySerialized.begin(), pubKeySerialized.end());
1123
popstack(stackCopy);
1125
if (!EvalScript(stackCopy, pubKey2, flags, checker, serror))
1128
if (!EvalScript(stack, pubKey2, flags, checker, serror))
1126
1129
// serror is set
1128
if (stackCopy.empty())
1129
return set_error(serror, SCRIPT_ERR_EVAL_FALSE);
1130
if (!CastToBool(stackCopy.back()))
1131
return set_error(serror, SCRIPT_ERR_EVAL_FALSE);
1133
return set_success(serror);
1132
return set_error(serror, SCRIPT_ERR_EVAL_FALSE);
1133
if (!CastToBool(stack.back()))
1134
return set_error(serror, SCRIPT_ERR_EVAL_FALSE);
1137
// The CLEANSTACK check is only performed after potential P2SH evaluation,
1138
// as the non-P2SH evaluation of a P2SH script will obviously not result in
1139
// a clean stack (the P2SH inputs remain).
1140
if ((flags & SCRIPT_VERIFY_CLEANSTACK) != 0) {
1141
// Disallow CLEANSTACK without P2SH, as otherwise a switch CLEANSTACK->P2SH+CLEANSTACK
1142
// would be possible, which is not a softfork (and P2SH should be one).
1143
assert((flags & SCRIPT_VERIFY_P2SH) != 0);
1144
if (stack.size() != 1) {
1145
return set_error(serror, SCRIPT_ERR_CLEANSTACK);
1136
1149
return set_success(serror);