MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / VerifyScript

Function VerifyScript

src/script/interpreter.cpp:1515–1632  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1513}
1514
1515bool VerifyScript(const CScript& scriptSig, const CScript& scriptPubKey, const CScriptWitness* witness, unsigned int flags, const BaseSignatureChecker& checker, ScriptError* serror)
1516{
1517 static const CScriptWitness emptyWitness;
1518 if (witness == nullptr) {
1519 witness = &emptyWitness;
1520 }
1521 bool hadWitness = false;
1522
1523 set_error(serror, SCRIPT_ERR_UNKNOWN_ERROR);
1524
1525 if ((flags & SCRIPT_VERIFY_SIGPUSHONLY) != 0 && !scriptSig.IsPushOnly()) {
1526 return set_error(serror, SCRIPT_ERR_SIG_PUSHONLY);
1527 }
1528
1529 std::vector<std::vector<unsigned char> > stack, stackCopy;
1530 if (!EvalScript(stack, scriptSig, flags, checker, SigVersion::BASE, serror))
1531 // serror is set
1532 return false;
1533 if (flags & SCRIPT_VERIFY_P2SH)
1534 stackCopy = stack;
1535 if (!EvalScript(stack, scriptPubKey, flags, checker, SigVersion::BASE, serror))
1536 // serror is set
1537 return false;
1538 if (stack.empty())
1539 return set_error(serror, SCRIPT_ERR_EVAL_FALSE);
1540 if (CastToBool(stack.back()) == false)
1541 return set_error(serror, SCRIPT_ERR_EVAL_FALSE);
1542
1543 // Bare witness programs
1544 int witnessversion;
1545 std::vector<unsigned char> witnessprogram;
1546 if (flags & SCRIPT_VERIFY_WITNESS) {
1547 if (scriptPubKey.IsWitnessProgram(witnessversion, witnessprogram)) {
1548 hadWitness = true;
1549 if (scriptSig.size() != 0) {
1550 // The scriptSig must be _exactly_ CScript(), otherwise we reintroduce malleability.
1551 return set_error(serror, SCRIPT_ERR_WITNESS_MALLEATED);
1552 }
1553 if (!VerifyWitnessProgram(*witness, witnessversion, witnessprogram, flags, checker, serror)) {
1554 return false;
1555 }
1556 // Bypass the cleanstack check at the end. The actual stack is obviously not clean
1557 // for witness programs.
1558 stack.resize(1);
1559 }
1560 }
1561
1562 // Additional validation for spend-to-script-hash transactions:
1563 if ((flags & SCRIPT_VERIFY_P2SH) && scriptPubKey.IsPayToScriptHash())
1564 {
1565 // scriptSig must be literals-only or validation fails
1566 if (!scriptSig.IsPushOnly())
1567 return set_error(serror, SCRIPT_ERR_SIG_PUSHONLY);
1568
1569 // Restore stack.
1570 swap(stack, stackCopy);
1571
1572 // stack cannot be empty here, because if it was the

Callers 14

operator()Method · 0.85
verify_scriptFunction · 0.85
ProduceSignatureFunction · 0.85
DataFromTransactionFunction · 0.85
IsSolvableFunction · 0.85
VerifyWithFlagFunction · 0.85
VerifyFunction · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85
CheckWithFlagFunction · 0.85
DoTestFunction · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85

Calls 15

EvalScriptFunction · 0.85
CastToBoolFunction · 0.85
VerifyWitnessProgramFunction · 0.85
popstackFunction · 0.85
set_successFunction · 0.85
IsPushOnlyMethod · 0.80
IsWitnessProgramMethod · 0.80
IsPayToScriptHashMethod · 0.80
set_errorFunction · 0.70
CScriptClass · 0.70
emptyMethod · 0.45
sizeMethod · 0.45

Tested by 7

VerifyWithFlagFunction · 0.68
VerifyFunction · 0.68
BOOST_AUTO_TEST_CASEFunction · 0.68
CheckWithFlagFunction · 0.68
DoTestFunction · 0.68
BOOST_AUTO_TEST_CASEFunction · 0.68
BOOST_AUTO_TEST_CASEFunction · 0.68