~ubuntu-branches/debian/sid/bitcoin/sid

« back to all changes in this revision

Viewing changes to src/script/interpreter.cpp

  • Committer: Package Import Robot
  • Author(s): Scott Howard
  • Date: 2015-07-29 15:45:52 UTC
  • mfrom: (1.1.23)
  • Revision ID: package-import@ubuntu.com-20150729154552-p5t8q38o0ekh1f09
Tags: 0.11.0-1
* New upstream release (Closes: #793622)
  - build on all archs, big endian is now supported
* Updated symbols file
* Added bitcoin-cli.1 manpage from contrib/debian/manpages
* Updated debian/copyright

Show diffs side-by-side

added added

removed removed

Lines of Context:
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.
5
5
 
60
60
static inline void popstack(vector<valtype>& stack)
61
61
{
62
62
    if (stack.empty())
63
 
        throw runtime_error("popstack() : stack empty");
 
63
        throw runtime_error("popstack(): stack empty");
64
64
    stack.pop_back();
65
65
}
66
66
 
1035
1035
 
1036
1036
uint256 SignatureHash(const CScript& scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType)
1037
1037
{
 
1038
    static const uint256 one(uint256S("0000000000000000000000000000000000000000000000000000000000000001"));
1038
1039
    if (nIn >= txTo.vin.size()) {
1039
1040
        //  nIn out of range
1040
 
        return 1;
 
1041
        return one;
1041
1042
    }
1042
1043
 
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
1047
 
            return 1;
 
1048
            return one;
1048
1049
        }
1049
1050
    }
1050
1051
 
1102
1103
        return false;
1103
1104
    if (stack.empty())
1104
1105
        return set_error(serror, SCRIPT_ERR_EVAL_FALSE);
1105
 
 
1106
1106
    if (CastToBool(stack.back()) == false)
1107
1107
        return set_error(serror, SCRIPT_ERR_EVAL_FALSE);
1108
1108
 
1113
1113
        if (!scriptSig.IsPushOnly())
1114
1114
            return set_error(serror, SCRIPT_ERR_SIG_PUSHONLY);
1115
1115
 
1116
 
        // stackCopy cannot be empty here, because if it was the
 
1116
        // Restore stack.
 
1117
        swap(stack, stackCopy);
 
1118
 
 
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());
1120
1123
 
1121
 
        const valtype& pubKeySerialized = stackCopy.back();
 
1124
        const valtype& pubKeySerialized = stack.back();
1122
1125
        CScript pubKey2(pubKeySerialized.begin(), pubKeySerialized.end());
1123
 
        popstack(stackCopy);
 
1126
        popstack(stack);
1124
1127
 
1125
 
        if (!EvalScript(stackCopy, pubKey2, flags, checker, serror))
 
1128
        if (!EvalScript(stack, pubKey2, flags, checker, serror))
1126
1129
            // serror is set
1127
1130
            return false;
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);
1132
 
        else
1133
 
            return set_success(serror);
 
1131
        if (stack.empty())
 
1132
            return set_error(serror, SCRIPT_ERR_EVAL_FALSE);
 
1133
        if (!CastToBool(stack.back()))
 
1134
            return set_error(serror, SCRIPT_ERR_EVAL_FALSE);
 
1135
    }
 
1136
 
 
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);
 
1146
        }
1134
1147
    }
1135
1148
 
1136
1149
    return set_success(serror);