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

Function VerifyScript

src/script/interpreter.cpp:1348–1416  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1346}
1347
1348bool VerifyScript(const CScript& scriptSig, const CScript& scriptPubKey, unsigned int flags, const BaseSignatureChecker& checker, ScriptError* serror)
1349{
1350 set_error(serror, SCRIPT_ERR_UNKNOWN_ERROR);
1351
1352 // If FORKID is enabled, we also ensure strict encoding.
1353 if (flags & SCRIPT_ENABLE_SIGHASH_FORKID) {
1354 flags |= SCRIPT_VERIFY_STRICTENC;
1355 }
1356
1357 if ((flags & SCRIPT_VERIFY_SIGPUSHONLY) != 0 && !scriptSig.IsPushOnly()) {
1358 return set_error(serror, SCRIPT_ERR_SIG_PUSHONLY);
1359 }
1360
1361 vector<vector<unsigned char> > stack, stackCopy;
1362 if (!EvalScript(stack, scriptSig, flags, checker, serror))
1363 // serror is set
1364 return false;
1365 if (flags & SCRIPT_VERIFY_P2SH)
1366 stackCopy = stack;
1367 if (!EvalScript(stack, scriptPubKey, flags, checker, serror))
1368 // serror is set
1369 return false;
1370 if (stack.empty())
1371 return set_error(serror, SCRIPT_ERR_EVAL_FALSE);
1372 if (CastToBool(stack.back()) == false)
1373 return set_error(serror, SCRIPT_ERR_EVAL_FALSE);
1374
1375 // Additional validation for spend-to-script-hash transactions:
1376 if ((flags & SCRIPT_VERIFY_P2SH) && scriptPubKey.IsPayToScriptHash())
1377 {
1378 // scriptSig must be literals-only or validation fails
1379 if (!scriptSig.IsPushOnly())
1380 return set_error(serror, SCRIPT_ERR_SIG_PUSHONLY);
1381
1382 // Restore stack.
1383 swap(stack, stackCopy);
1384
1385 // stack cannot be empty here, because if it was the
1386 // P2SH HASH <> EQUAL scriptPubKey would be evaluated with
1387 // an empty stack and the EvalScript above would return false.
1388 assert(!stack.empty());
1389
1390 const valtype& pubKeySerialized = stack.back();
1391 CScript pubKey2(pubKeySerialized.begin(), pubKeySerialized.end());
1392 popstack(stack);
1393
1394 if (!EvalScript(stack, pubKey2, flags, checker, serror))
1395 // serror is set
1396 return false;
1397 if (stack.empty())
1398 return set_error(serror, SCRIPT_ERR_EVAL_FALSE);
1399 if (!CastToBool(stack.back()))
1400 return set_error(serror, SCRIPT_ERR_EVAL_FALSE);
1401 }
1402
1403 // The CLEANSTACK check is only performed after potential P2SH evaluation,
1404 // as the non-P2SH evaluation of a P2SH script will obviously not result in
1405 // a clean stack (the P2SH inputs remain).

Callers 10

MutateTxSignFunction · 0.85
signrawtransactionFunction · 0.85
operator()Method · 0.85
verify_scriptFunction · 0.85
ProduceSignatureFunction · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85
DoTestFunction · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85
VerifyFunction · 0.85

Calls 11

EvalScriptFunction · 0.85
CastToBoolFunction · 0.85
popstackFunction · 0.85
set_successFunction · 0.85
IsPushOnlyMethod · 0.80
IsPayToScriptHashMethod · 0.80
set_errorFunction · 0.70
emptyMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45

Tested by 5

BOOST_AUTO_TEST_CASEFunction · 0.68
DoTestFunction · 0.68
BOOST_AUTO_TEST_CASEFunction · 0.68
BOOST_AUTO_TEST_CASEFunction · 0.68
VerifyFunction · 0.68