MCPcopy Create free account
hub / github.com/LUX-Core/lux / VerifyScript

Function VerifyScript

src/script/interpreter.cpp:1454–1573  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1452}
1453
1454bool VerifyScript(const CScript& scriptSig, const CScript& scriptPubKey, const CScriptWitness* witness, unsigned int flags, const BaseSignatureChecker& checker, ScriptError* serror)
1455{
1456 static const CScriptWitness emptyWitness;
1457 if (witness == nullptr) {
1458 witness = &emptyWitness;
1459 }
1460 bool hadWitness = false;
1461
1462 set_error(serror, SCRIPT_ERR_UNKNOWN_ERROR);
1463
1464 if ((flags & SCRIPT_VERIFY_SIGPUSHONLY) != 0 && !scriptSig.IsPushOnly()) {
1465 return set_error(serror, SCRIPT_ERR_SIG_PUSHONLY);
1466 }
1467
1468 vector<vector<unsigned char> > stack, stackCopy;
1469 if (!EvalScript(stack, scriptSig, flags, checker, SIGVERSION_BASE, serror))
1470 // serror is set
1471 return false;
1472 if (flags & SCRIPT_VERIFY_P2SH)
1473 stackCopy = stack;
1474 if (!EvalScript(stack, scriptPubKey, flags, checker, SIGVERSION_BASE, serror))
1475 // serror is set
1476 return false;
1477 if (stack.empty()) {
1478 return set_error(serror, SCRIPT_ERR_EVAL_FALSE);
1479 }
1480
1481 if (CastToBool(stack.back()) == false) {
1482 return set_error(serror, SCRIPT_ERR_EVAL_FALSE);
1483 }
1484
1485 // Bare witness programs
1486 int witnessversion;
1487 std::vector<unsigned char> witnessprogram;
1488 if (flags & SCRIPT_VERIFY_WITNESS) {
1489 if (scriptPubKey.IsWitnessProgram(witnessversion, witnessprogram)) {
1490 hadWitness = true;
1491 if (scriptSig.size() != 0) {
1492 // The scriptSig must be _exactly_ CScript(), otherwise we reintroduce malleability.
1493 return set_error(serror, SCRIPT_ERR_WITNESS_MALLEATED);
1494 }
1495 if (!VerifyWitnessProgram(*witness, witnessversion, witnessprogram, flags, checker, serror)) {
1496 return false;
1497 }
1498 // Bypass the cleanstack check at the end. The actual stack is obviously not clean
1499 // for witness programs.
1500 stack.resize(1);
1501 }
1502 }
1503
1504 // Additional validation for spend-to-script-hash transactions:
1505 if ((flags & SCRIPT_VERIFY_P2SH) && scriptPubKey.IsPayToScriptHash())
1506 {
1507 // scriptSig must be literals-only or validation fails
1508 if (!scriptSig.IsPushOnly())
1509 return set_error(serror, SCRIPT_ERR_SIG_PUSHONLY);
1510
1511 // Restore stack.

Callers 15

MutateTxSignFunction · 0.85
SignatureValidMethod · 0.85
CheckProofMethod · 0.85
signrawtransactionFunction · 0.85
operator()Method · 0.85
verify_scriptFunction · 0.85
ProduceSignatureFunction · 0.85
IsSolvableFunction · 0.85
VerifyWithFlagFunction · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85
CheckWithFlagFunction · 0.85
DoTestFunction · 0.85

Calls 15

EvalScriptFunction · 0.85
CastToBoolFunction · 0.85
VerifyWitnessProgramFunction · 0.85
popstackFunction · 0.85
set_successFunction · 0.85
IsPushOnlyMethod · 0.80
backMethod · 0.80
IsWitnessProgramMethod · 0.80
IsPayToScriptHashMethod · 0.80
set_errorFunction · 0.70
CScriptClass · 0.70
swapFunction · 0.50

Tested by 7

VerifyWithFlagFunction · 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
VerifyFunction · 0.68