@@ -1478,9 +1478,9 @@ bool GenericTransactionSignatureChecker<T>::CheckSequence(const CScriptNum& nSeq
1478
1478
template class GenericTransactionSignatureChecker <CTransaction>;
1479
1479
template class GenericTransactionSignatureChecker <CMutableTransaction>;
1480
1480
1481
- static bool ExecuteWitnessScript (std::vector<valtype>::const_iterator begin, std::vector< valtype>::const_iterator end , const CScript& scriptPubKey, unsigned int flags, SigVersion sigversion, const BaseSignatureChecker& checker, ScriptError* serror)
1481
+ static bool ExecuteWitnessScript (const Span< const valtype>& stack_span , const CScript& scriptPubKey, unsigned int flags, SigVersion sigversion, const BaseSignatureChecker& checker, ScriptError* serror)
1482
1482
{
1483
- std::vector<valtype> stack{begin, end};
1483
+ std::vector<valtype> stack{stack_span. begin (), stack_span. end () };
1484
1484
1485
1485
// Disallow stack item size > MAX_SCRIPT_ELEMENT_SIZE in witness stack
1486
1486
for (const valtype& elem : stack) {
@@ -1499,27 +1499,29 @@ static bool ExecuteWitnessScript(std::vector<valtype>::const_iterator begin, std
1499
1499
static bool VerifyWitnessProgram (const CScriptWitness& witness, int witversion, const std::vector<unsigned char >& program, unsigned int flags, const BaseSignatureChecker& checker, ScriptError* serror)
1500
1500
{
1501
1501
CScript scriptPubKey;
1502
+ Span<const valtype> stack = MakeSpan (witness.stack );
1502
1503
1503
1504
if (witversion == 0 ) {
1504
1505
if (program.size () == WITNESS_V0_SCRIPTHASH_SIZE) {
1505
1506
// Version 0 segregated witness program: SHA256(CScript) inside the program, CScript + inputs in witness
1506
- if (witness. stack .size () == 0 ) {
1507
+ if (stack.size () == 0 ) {
1507
1508
return set_error (serror, SCRIPT_ERR_WITNESS_PROGRAM_WITNESS_EMPTY);
1508
1509
}
1509
- scriptPubKey = CScript (witness.stack .back ().begin (), witness.stack .back ().end ());
1510
+ const valtype& script_bytes = SpanPopBack (stack);
1511
+ scriptPubKey = CScript (script_bytes.begin (), script_bytes.end ());
1510
1512
uint256 hashScriptPubKey;
1511
1513
CSHA256 ().Write (&scriptPubKey[0 ], scriptPubKey.size ()).Finalize (hashScriptPubKey.begin ());
1512
1514
if (memcmp (hashScriptPubKey.begin (), program.data (), 32 )) {
1513
1515
return set_error (serror, SCRIPT_ERR_WITNESS_PROGRAM_MISMATCH);
1514
1516
}
1515
- return ExecuteWitnessScript (witness. stack . begin (), witness. stack . end () - 1 , scriptPubKey, flags, SigVersion::WITNESS_V0, checker, serror);
1517
+ return ExecuteWitnessScript (stack, scriptPubKey, flags, SigVersion::WITNESS_V0, checker, serror);
1516
1518
} else if (program.size () == WITNESS_V0_KEYHASH_SIZE) {
1517
1519
// Special case for pay-to-pubkeyhash; signature + pubkey in witness
1518
- if (witness. stack .size () != 2 ) {
1520
+ if (stack.size () != 2 ) {
1519
1521
return set_error (serror, SCRIPT_ERR_WITNESS_PROGRAM_MISMATCH); // 2 items in witness
1520
1522
}
1521
1523
scriptPubKey << OP_DUP << OP_HASH160 << program << OP_EQUALVERIFY << OP_CHECKSIG;
1522
- return ExecuteWitnessScript (witness. stack . begin (), witness. stack . end () , scriptPubKey, flags, SigVersion::WITNESS_V0, checker, serror);
1524
+ return ExecuteWitnessScript (stack, scriptPubKey, flags, SigVersion::WITNESS_V0, checker, serror);
1523
1525
} else {
1524
1526
return set_error (serror, SCRIPT_ERR_WITNESS_PROGRAM_WRONG_LENGTH);
1525
1527
}
0 commit comments