MCPcopy Create free account
hub / github.com/ElementsProject/elements / EvalScript

Function EvalScript

src/script/interpreter.cpp:579–2265  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

577const CHashWriter HASHER_TAPSIGHASH_ELEMENTS = TaggedHash("TapSighash/elements");
578
579bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript& script, unsigned int flags, const BaseSignatureChecker& checker, SigVersion sigversion, ScriptExecutionData& execdata, ScriptError* serror)
580{
581 static const CScriptNum bnZero(0);
582 static const CScriptNum bnOne(1);
583 // static const CScriptNum bnFalse(0);
584 // static const CScriptNum bnTrue(1);
585 static const valtype vchFalse(0);
586 static const valtype vchZero(0);
587 static const valtype vchTrue(1, 1);
588
589 // sigversion cannot be TAPROOT here, as it admits no script execution.
590 assert(sigversion == SigVersion::BASE || sigversion == SigVersion::WITNESS_V0 || sigversion == SigVersion::TAPSCRIPT);
591
592 CScript::const_iterator pc = script.begin();
593 CScript::const_iterator pend = script.end();
594 CScript::const_iterator pbegincodehash = script.begin();
595 opcodetype opcode;
596 valtype vchPushValue;
597 ConditionStack vfExec;
598 std::vector<valtype> altstack;
599 set_error(serror, SCRIPT_ERR_UNKNOWN_ERROR);
600 if ((sigversion == SigVersion::BASE || sigversion == SigVersion::WITNESS_V0) && script.size() > MAX_SCRIPT_SIZE) {
601 return set_error(serror, SCRIPT_ERR_SCRIPT_SIZE);
602 }
603 int nOpCount = 0;
604 bool fRequireMinimal = (flags & SCRIPT_VERIFY_MINIMALDATA) != 0;
605 uint32_t opcode_pos = 0;
606 execdata.m_codeseparator_pos = 0xFFFFFFFFUL;
607 execdata.m_codeseparator_pos_init = true;
608
609 try
610 {
611 for (; pc < pend; ++opcode_pos) {
612 bool fExec = vfExec.all_true();
613
614 //
615 // Read instruction
616 //
617 if (!script.GetOp(pc, opcode, vchPushValue))
618 return set_error(serror, SCRIPT_ERR_BAD_OPCODE);
619 if (vchPushValue.size() > MAX_SCRIPT_ELEMENT_SIZE)
620 return set_error(serror, SCRIPT_ERR_PUSH_SIZE);
621
622 if (sigversion == SigVersion::BASE || sigversion == SigVersion::WITNESS_V0) {
623 // Note how OP_RESERVED does not count towards the opcode limit.
624 if (opcode > OP_16 && ++nOpCount > MAX_OPS_PER_SCRIPT) {
625 return set_error(serror, SCRIPT_ERR_OP_COUNT);
626 }
627 }
628
629 // ELEMENTS:
630 // commented out opcodes are re-enabled in Elements
631 if (//opcode == OP_CAT ||
632 //opcode == OP_SUBSTR ||
633 //opcode == OP_LEFT ||
634 //opcode == OP_RIGHT ||
635 //opcode == OP_INVERT ||
636 //opcode == OP_AND ||

Callers 11

AreInputsStandardFunction · 0.85
IsWitnessStandardFunction · 0.85
ExecuteWitnessScriptFunction · 0.85
VerifyScriptFunction · 0.85
StacksMethod · 0.85
ReplaceRedeemScriptFunction · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85
FUZZ_TARGET_INITFunction · 0.85
FUZZ_TARGET_INITFunction · 0.85
VerifyNestedIfScriptFunction · 0.85

Calls 15

CheckMinimalPushFunction · 0.85
CastToBoolFunction · 0.85
popstackFunction · 0.85
swapFunction · 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_TARGET_INITFunction · 0.68
FUZZ_TARGET_INITFunction · 0.68