@@ -1412,6 +1412,18 @@ uint256 GetSpentAmountsSHA256(const std::vector<CTxOut>& outputs_spent)
14121412 HashWriter ss{};
14131413 for (const auto & txout : outputs_spent) {
14141414 ss << txout.nValue ;
1415+
1416+ }
1417+ return ss.GetSHA256 ();
1418+ }
1419+
1420+ /* * Compute the (single) SHA256 of the concatenation of all scriptSigs in a tx. */
1421+ template <class T >
1422+ uint256 GetScriptSigsSHA256 (const T& txTo)
1423+ {
1424+ HashWriter ss{};
1425+ for (const auto & in : txTo.vin ) {
1426+ ss << in.scriptSig ;
14151427 }
14161428 return ss.GetSHA256 ();
14171429}
@@ -1426,6 +1438,38 @@ uint256 GetSpentScriptsSHA256(const std::vector<CTxOut>& outputs_spent)
14261438 return ss.GetSHA256 ();
14271439}
14281440
1441+ template <typename TxType>
1442+ uint256 GetDefaultCheckTemplateVerifyHashWithScript (
1443+ const TxType& tx, const uint256& outputs_hash, const uint256& sequences_hash,
1444+ const uint256& scriptSig_hash, const uint32_t input_index)
1445+ {
1446+ auto h = HashWriter{}
1447+ << tx.version
1448+ << tx.nLockTime
1449+ << scriptSig_hash
1450+ << uint32_t (tx.vin .size ())
1451+ << sequences_hash
1452+ << uint32_t (tx.vout .size ())
1453+ << outputs_hash
1454+ << input_index;
1455+ return h.GetSHA256 ();
1456+ }
1457+
1458+ template <typename TxType>
1459+ uint256 GetDefaultCheckTemplateVerifyHashEmptyScript (
1460+ const TxType& tx, const uint256& outputs_hash, const uint256& sequences_hash,
1461+ const uint32_t input_index)
1462+ {
1463+ auto h = HashWriter{}
1464+ << tx.version
1465+ << tx.nLockTime
1466+ << uint32_t (tx.vin .size ())
1467+ << sequences_hash
1468+ << uint32_t (tx.vout .size ())
1469+ << outputs_hash
1470+ << input_index;
1471+ return h.GetSHA256 ();
1472+ }
14291473
14301474} // namespace
14311475
@@ -1434,16 +1478,12 @@ uint256 GetDefaultCheckTemplateVerifyHash(const TxType& tx, uint32_t input_index
14341478 return GetDefaultCheckTemplateVerifyHash (tx, GetOutputsSHA256 (tx), GetSequencesSHA256 (tx), input_index);
14351479}
14361480
1437- template <typename TxType>
1438- static bool NoScriptSigs (const TxType& tx)
1439- {
1440- return std::all_of (tx.vin .begin (), tx.vin .end (), [](const CTxIn& c) { return c.scriptSig .empty (); });
1441- }
1442-
14431481template <typename TxType>
14441482uint256 GetDefaultCheckTemplateVerifyHash (
14451483 const TxType& tx, const uint256& outputs_hash, const uint256& sequences_hash, const uint32_t input_index) {
1446- return NoScriptSigs (tx) ? GetDefaultCheckTemplateVerifyHashEmptyScript (tx, outputs_hash, sequences_hash, input_index) :
1484+ bool skip_scriptSigs = std::find_if (tx.vin .begin (), tx.vin .end (),
1485+ [](const CTxIn& c) { return c.scriptSig != CScript (); }) == tx.vin .end ();
1486+ return skip_scriptSigs ? GetDefaultCheckTemplateVerifyHashEmptyScript (tx, outputs_hash, sequences_hash, input_index) :
14471487 GetDefaultCheckTemplateVerifyHashWithScript (tx, outputs_hash, sequences_hash, GetScriptSigsSHA256 (tx), input_index);
14481488}
14491489
@@ -1856,20 +1896,13 @@ bool GenericTransactionSignatureChecker<T>::CheckSequence(const CScriptNum& nSeq
18561896}
18571897
18581898template <class T >
1859- bool GenericTransactionSignatureChecker<T>::CheckDefaultCheckTemplateVerifyHash(const std::span< const unsigned char >& hash) const
1899+ bool GenericTransactionSignatureChecker<T>::CheckDefaultCheckTemplateVerifyHash(const std::vector< unsigned char >& hash) const
18601900{
18611901 // Should already be checked before calling...
18621902 assert (hash.size () == 32 );
1863- if (txdata && txdata->m_bip119_ctv_ready ) {
1864- assert (txTo != nullptr );
1865- uint256 hash_tmpl = txdata->m_scriptSigs_single_hash .IsNull () ?
1866- GetDefaultCheckTemplateVerifyHashEmptyScript (*txTo, txdata->m_outputs_single_hash , txdata->m_sequences_single_hash , nIn) :
1867- GetDefaultCheckTemplateVerifyHashWithScript (*txTo, txdata->m_outputs_single_hash , txdata->m_sequences_single_hash ,
1868- txdata->m_scriptSigs_single_hash , nIn);
1869- return std::equal (hash_tmpl.begin (), hash_tmpl.end (), hash.data ());
1870- } else {
1871- return HandleMissingData (m_mdb);
1872- }
1903+ assert (txTo != nullptr );
1904+ uint256 hash_tmpl = GetDefaultCheckTemplateVerifyHash (*txTo, nIn);
1905+ return std::equal (hash_tmpl.begin (), hash_tmpl.end (), hash.data ());
18731906}
18741907// explicit instantiation
18751908template class GenericTransactionSignatureChecker <CTransaction>;
0 commit comments