MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / EvalScript

Function EvalScript

src/script/interpreter.cpp:417–1249  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

415}
416
417bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript& script, script_verify_flags flags, const BaseSignatureChecker& checker, SigVersion sigversion, ScriptExecutionData& execdata, ScriptError* serror)
418{
419 static const CScriptNum bnZero(0);
420 static const CScriptNum bnOne(1);
421 // static const CScriptNum bnFalse(0);
422 // static const CScriptNum bnTrue(1);
423 static const valtype vchFalse(0);
424 // static const valtype vchZero(0);
425 static const valtype vchTrue(1, 1);
426
427 // sigversion cannot be TAPROOT here, as it admits no script execution.
428 assert(sigversion == SigVersion::BASE || sigversion == SigVersion::WITNESS_V0 || sigversion == SigVersion::TAPSCRIPT);
429
430 CScript::const_iterator pc = script.begin();
431 CScript::const_iterator pend = script.end();
432 CScript::const_iterator pbegincodehash = script.begin();
433 opcodetype opcode;
434 valtype vchPushValue;
435 ConditionStack vfExec;
436 std::vector<valtype> altstack;
437 set_error(serror, SCRIPT_ERR_UNKNOWN_ERROR);
438 if ((sigversion == SigVersion::BASE || sigversion == SigVersion::WITNESS_V0) && script.size() > MAX_SCRIPT_SIZE) {
439 return set_error(serror, SCRIPT_ERR_SCRIPT_SIZE);
440 }
441 int nOpCount = 0;
442 bool fRequireMinimal = (flags & SCRIPT_VERIFY_MINIMALDATA) != 0;
443 uint32_t opcode_pos = 0;
444 execdata.m_codeseparator_pos = 0xFFFFFFFFUL;
445 execdata.m_codeseparator_pos_init = true;
446
447 try
448 {
449 for (; pc < pend; ++opcode_pos) {
450 bool fExec = vfExec.all_true();
451
452 //
453 // Read instruction
454 //
455 if (!script.GetOp(pc, opcode, vchPushValue))
456 return set_error(serror, SCRIPT_ERR_BAD_OPCODE);
457 if (vchPushValue.size() > MAX_SCRIPT_ELEMENT_SIZE)
458 return set_error(serror, SCRIPT_ERR_PUSH_SIZE);
459
460 if (sigversion == SigVersion::BASE || sigversion == SigVersion::WITNESS_V0) {
461 // Note how OP_RESERVED does not count towards the opcode limit.
462 if (opcode > OP_16 && ++nOpCount > MAX_OPS_PER_SCRIPT) {
463 return set_error(serror, SCRIPT_ERR_OP_COUNT);
464 }
465 }
466
467 if (opcode == OP_CAT ||
468 opcode == OP_SUBSTR ||
469 opcode == OP_LEFT ||
470 opcode == OP_RIGHT ||
471 opcode == OP_INVERT ||
472 opcode == OP_AND ||
473 opcode == OP_OR ||
474 opcode == OP_XOR ||

Callers 11

IsWitnessStandardFunction · 0.85
ExecuteWitnessScriptFunction · 0.85
VerifyScriptFunction · 0.85
StacksMethod · 0.85
ReplaceRedeemScriptFunction · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85
FUZZ_TARGETFunction · 0.85
FUZZ_TARGETFunction · 0.85
VerifyNestedIfScriptFunction · 0.85

Calls 15

set_errorFunction · 0.85
CheckMinimalPushFunction · 0.85
CastToBoolFunction · 0.85
popstackFunction · 0.85
CRIPEMD160Class · 0.85
CSHA1Class · 0.85
CSHA256Class · 0.85
CHash160Class · 0.85
CHash256Class · 0.85
EvalChecksigFunction · 0.85
CheckSignatureEncodingFunction · 0.85
CheckPubKeyEncodingFunction · 0.85

Tested by 4

ReplaceRedeemScriptFunction · 0.68
BOOST_AUTO_TEST_CASEFunction · 0.68
FUZZ_TARGETFunction · 0.68
FUZZ_TARGETFunction · 0.68