Changeset View
Changeset View
Standalone View
Standalone View
src/script/interpreter.cpp
Show First 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
static void CleanupScriptCode(CScript &scriptCode, | static void CleanupScriptCode(CScript &scriptCode, | ||||
const std::vector<uint8_t> &vchSig, | const std::vector<uint8_t> &vchSig, | ||||
uint32_t flags) { | uint32_t flags) { | ||||
// Drop the signature in scripts when SIGHASH_FORKID is not used. | // Drop the signature in scripts when SIGHASH_FORKID is not used. | ||||
SigHashType sigHashType = GetHashType(vchSig); | SigHashType sigHashType = GetHashType(vchSig); | ||||
if (!(flags & SCRIPT_ENABLE_SIGHASH_FORKID) || !sigHashType.hasForkId()) { | if (!(flags & SCRIPT_ENABLE_SIGHASH_FORKID) || !sigHashType.hasForkId()) { | ||||
scriptCode.FindAndDelete(CScript(vchSig)); | // scriptCode.FindAndDelete(CScript(vchSig)); | ||||
FindAndDelete(scriptCode, CScript(vchSig)); | |||||
} | } | ||||
} | } | ||||
static bool IsOpcodeDisabled(opcodetype opcode, uint32_t flags) { | static bool IsOpcodeDisabled(opcodetype opcode, uint32_t flags) { | ||||
switch (opcode) { | switch (opcode) { | ||||
case OP_INVERT: | case OP_INVERT: | ||||
case OP_2MUL: | case OP_2MUL: | ||||
case OP_2DIV: | case OP_2DIV: | ||||
case OP_MUL: | case OP_MUL: | ||||
case OP_LSHIFT: | case OP_LSHIFT: | ||||
case OP_RSHIFT: | case OP_RSHIFT: | ||||
// Disabled opcodes. | // Disabled opcodes. | ||||
return true; | return true; | ||||
default: | default: | ||||
break; | break; | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
int FindAndDelete(CScript &script, const CScript &b) { | |||||
int nFound = 0; | |||||
if (b.empty()) return nFound; | |||||
CScript result; | |||||
CScript::const_iterator pc = script.begin(), pc2 = script.begin(), | |||||
end = script.end(); | |||||
opcodetype opcode; | |||||
do { | |||||
result.insert(result.end(), pc2, pc); | |||||
while (static_cast<size_t>(end - pc) >= b.size() && | |||||
std::equal(b.begin(), b.end(), pc)) { | |||||
pc = pc + b.size(); | |||||
++nFound; | |||||
} | |||||
pc2 = pc; | |||||
} while (script.GetOp(pc, opcode)); | |||||
if (nFound > 0) { | |||||
result.insert(result.end(), pc2, end); | |||||
script = std::move(result); | |||||
} | |||||
return nFound; | |||||
} | |||||
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) { | 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); | ||||
▲ Show 20 Lines • Show All 1,661 Lines • Show Last 20 Lines |