Changeset View
Changeset View
Standalone View
Standalone View
src/script/interpreter.cpp
Show First 20 Lines • Show All 96 Lines • ▼ Show 20 Lines | switch (opcode) { | ||||
break; | break; | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
bool EvalScript(std::vector<valtype> &stack, const CScript &script, | bool EvalScript(std::vector<valtype> &stack, const CScript &script, | ||||
uint32_t flags, const BaseSignatureChecker &checker, | uint32_t flags, const BaseSignatureChecker &checker, | ||||
ScriptError *serror) { | ScriptExecutionMetrics &metrics, ScriptError *serror) { | ||||
static const CScriptNum bnZero(0); | static const CScriptNum bnZero(0); | ||||
static const CScriptNum bnOne(1); | static const CScriptNum bnOne(1); | ||||
static const valtype vchFalse(0); | static const valtype vchFalse(0); | ||||
static const valtype vchTrue(1, 1); | static const valtype vchTrue(1, 1); | ||||
CScript::const_iterator pc = script.begin(); | CScript::const_iterator pc = script.begin(); | ||||
CScript::const_iterator pend = script.end(); | CScript::const_iterator pend = script.end(); | ||||
CScript::const_iterator pbegincodehash = script.begin(); | CScript::const_iterator pbegincodehash = script.begin(); | ||||
▲ Show 20 Lines • Show All 766 Lines • ▼ Show 20 Lines | try { | ||||
// codeseparator | // codeseparator | ||||
CScript scriptCode(pbegincodehash, pend); | CScript scriptCode(pbegincodehash, pend); | ||||
// Remove signature for pre-fork scripts | // Remove signature for pre-fork scripts | ||||
CleanupScriptCode(scriptCode, vchSig, flags); | CleanupScriptCode(scriptCode, vchSig, flags); | ||||
fSuccess = checker.CheckSig(vchSig, vchPubKey, | fSuccess = checker.CheckSig(vchSig, vchPubKey, | ||||
scriptCode, flags); | scriptCode, flags); | ||||
metrics.nSigChecks += 1; | |||||
if (!fSuccess && (flags & SCRIPT_VERIFY_NULLFAIL)) { | if (!fSuccess && (flags & SCRIPT_VERIFY_NULLFAIL)) { | ||||
return set_error(serror, | return set_error(serror, | ||||
ScriptError::SIG_NULLFAIL); | ScriptError::SIG_NULLFAIL); | ||||
} | } | ||||
} | } | ||||
popstack(stack); | popstack(stack); | ||||
Show All 31 Lines | try { | ||||
bool fSuccess = false; | bool fSuccess = false; | ||||
if (vchSig.size()) { | if (vchSig.size()) { | ||||
valtype vchHash(32); | valtype vchHash(32); | ||||
CSHA256() | CSHA256() | ||||
.Write(vchMessage.data(), vchMessage.size()) | .Write(vchMessage.data(), vchMessage.size()) | ||||
.Finalize(vchHash.data()); | .Finalize(vchHash.data()); | ||||
fSuccess = checker.VerifySignature( | fSuccess = checker.VerifySignature( | ||||
vchSig, CPubKey(vchPubKey), uint256(vchHash)); | vchSig, CPubKey(vchPubKey), uint256(vchHash)); | ||||
metrics.nSigChecks += 1; | |||||
if (!fSuccess && (flags & SCRIPT_VERIFY_NULLFAIL)) { | if (!fSuccess && (flags & SCRIPT_VERIFY_NULLFAIL)) { | ||||
return set_error(serror, | return set_error(serror, | ||||
ScriptError::SIG_NULLFAIL); | ScriptError::SIG_NULLFAIL); | ||||
} | } | ||||
} | } | ||||
popstack(stack); | popstack(stack); | ||||
▲ Show 20 Lines • Show All 138 Lines • ▼ Show 20 Lines | try { | ||||
scriptCode, flags)) { | scriptCode, flags)) { | ||||
// This can fail if the signature is empty, | // This can fail if the signature is empty, | ||||
// which also is a NULLFAIL error as the | // which also is a NULLFAIL error as the | ||||
// bitfield should have been null in this | // bitfield should have been null in this | ||||
// situation. | // situation. | ||||
return set_error(serror, | return set_error(serror, | ||||
ScriptError::SIG_NULLFAIL); | ScriptError::SIG_NULLFAIL); | ||||
} | } | ||||
// this is guaranteed to execute exactly | |||||
// nSigsCount times (if not script error) | |||||
metrics.nSigChecks += 1; | |||||
} | } | ||||
if ((checkBits >> iKey) != 0) { | if ((checkBits >> iKey) != 0) { | ||||
// This is a sanity check and should be | // This is a sanity check and should be | ||||
// unrecheable. | // unrecheable. | ||||
return set_error( | return set_error( | ||||
serror, ScriptError::INVALID_BIT_COUNT); | serror, ScriptError::INVALID_BIT_COUNT); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | |||||
// If the operation failed, we may require that all | // If the operation failed, we may require that all | ||||
// signatures must be empty vector | // signatures must be empty vector | ||||
if (!fSuccess && (flags & SCRIPT_VERIFY_NULLFAIL) && | if (!fSuccess && (flags & SCRIPT_VERIFY_NULLFAIL) && | ||||
!areAllSignaturesNull) { | !areAllSignaturesNull) { | ||||
return set_error(serror, | return set_error(serror, | ||||
ScriptError::SIG_NULLFAIL); | ScriptError::SIG_NULLFAIL); | ||||
} | } | ||||
if (!areAllSignaturesNull) { | |||||
// This is not identical to the number of actual | |||||
// ECDSA verifies, but, it is an upper bound | |||||
// that can be easily determined without doing | |||||
// CPU-intensive checks. | |||||
metrics.nSigChecks += nKeysCount; | |||||
} | |||||
} | } | ||||
// Clean up stack of all arguments | // Clean up stack of all arguments | ||||
for (size_t i = 0; i < idxDummy; i++) { | for (size_t i = 0; i < idxDummy; i++) { | ||||
popstack(stack); | popstack(stack); | ||||
} | } | ||||
stack.push_back(fSuccess ? vchTrue : vchFalse); | stack.push_back(fSuccess ? vchTrue : vchFalse); | ||||
▲ Show 20 Lines • Show All 599 Lines • Show Last 20 Lines |