@@ -1492,13 +1492,13 @@ bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState& state, const C
14921492
14931493 // Check against previous transactions
14941494 // This is done last to help prevent CPU exhaustion denial-of-service attacks.
1495- CachedHashes cachedHashes (tx);
1496- if (!CheckInputs (tx, state, view, true , scriptVerifyFlags, true , cachedHashes )) {
1495+ PrecomputedTransactionData txdata (tx);
1496+ if (!CheckInputs (tx, state, view, true , scriptVerifyFlags, true , txdata )) {
14971497 // SCRIPT_VERIFY_CLEANSTACK requires SCRIPT_VERIFY_WITNESS, so we
14981498 // need to turn both off, and compare against just turning off CLEANSTACK
14991499 // to see if the failure is specifically due to witness validation.
1500- if (CheckInputs (tx, state, view, true , scriptVerifyFlags & ~(SCRIPT_VERIFY_WITNESS | SCRIPT_VERIFY_CLEANSTACK), true , cachedHashes ) &&
1501- !CheckInputs (tx, state, view, true , scriptVerifyFlags & ~SCRIPT_VERIFY_CLEANSTACK, true , cachedHashes )) {
1500+ if (CheckInputs (tx, state, view, true , scriptVerifyFlags & ~(SCRIPT_VERIFY_WITNESS | SCRIPT_VERIFY_CLEANSTACK), true , txdata ) &&
1501+ !CheckInputs (tx, state, view, true , scriptVerifyFlags & ~SCRIPT_VERIFY_CLEANSTACK, true , txdata )) {
15021502 // Only the witness is wrong, so the transaction itself may be fine.
15031503 state.SetCorruptionPossible ();
15041504 }
@@ -1514,7 +1514,7 @@ bool AcceptToMemoryPoolWorker(CTxMemPool& pool, CValidationState& state, const C
15141514 // There is a similar check in CreateNewBlock() to prevent creating
15151515 // invalid blocks, however allowing such transactions into the mempool
15161516 // can be exploited as a DoS attack.
1517- if (!CheckInputs (tx, state, view, true , MANDATORY_SCRIPT_VERIFY_FLAGS, true , cachedHashes ))
1517+ if (!CheckInputs (tx, state, view, true , MANDATORY_SCRIPT_VERIFY_FLAGS, true , txdata ))
15181518 {
15191519 return error (" %s: BUG! PLEASE REPORT THIS! ConnectInputs failed against MANDATORY but not STANDARD flags %s, %s" ,
15201520 __func__, hash.ToString (), FormatStateMessage (state));
@@ -1911,7 +1911,7 @@ void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, int nHeight)
19111911bool CScriptCheck::operator ()() {
19121912 const CScript &scriptSig = ptxTo->vin [nIn].scriptSig ;
19131913 const CScriptWitness *witness = (nIn < ptxTo->wit .vtxinwit .size ()) ? &ptxTo->wit .vtxinwit [nIn].scriptWitness : NULL ;
1914- if (!VerifyScript (scriptSig, scriptPubKey, witness, nFlags, CachingTransactionSignatureChecker (ptxTo, nIn, amount, cacheStore, *cachedHashes ), &error)) {
1914+ if (!VerifyScript (scriptSig, scriptPubKey, witness, nFlags, CachingTransactionSignatureChecker (ptxTo, nIn, amount, cacheStore, *txdata ), &error)) {
19151915 return false ;
19161916 }
19171917 return true ;
@@ -1970,7 +1970,7 @@ bool CheckTxInputs(const CTransaction& tx, CValidationState& state, const CCoins
19701970}
19711971}// namespace Consensus
19721972
1973- bool CheckInputs (const CTransaction& tx, CValidationState &state, const CCoinsViewCache &inputs, bool fScriptChecks , unsigned int flags, bool cacheStore, CachedHashes& cachedHashes , std::vector<CScriptCheck> *pvChecks)
1973+ bool CheckInputs (const CTransaction& tx, CValidationState &state, const CCoinsViewCache &inputs, bool fScriptChecks , unsigned int flags, bool cacheStore, PrecomputedTransactionData& txdata , std::vector<CScriptCheck> *pvChecks)
19741974{
19751975 if (!tx.IsCoinBase ())
19761976 {
@@ -1997,7 +1997,7 @@ bool CheckInputs(const CTransaction& tx, CValidationState &state, const CCoinsVi
19971997 assert (coins);
19981998
19991999 // Verify signature
2000- CScriptCheck check (*coins, tx, i, flags, cacheStore, &cachedHashes );
2000+ CScriptCheck check (*coins, tx, i, flags, cacheStore, &txdata );
20012001 if (pvChecks) {
20022002 pvChecks->push_back (CScriptCheck ());
20032003 check.swap (pvChecks->back ());
@@ -2010,7 +2010,7 @@ bool CheckInputs(const CTransaction& tx, CValidationState &state, const CCoinsVi
20102010 // avoid splitting the network between upgraded and
20112011 // non-upgraded nodes.
20122012 CScriptCheck check2 (*coins, tx, i,
2013- flags & ~STANDARD_NOT_MANDATORY_VERIFY_FLAGS, cacheStore, &cachedHashes );
2013+ flags & ~STANDARD_NOT_MANDATORY_VERIFY_FLAGS, cacheStore, &txdata );
20142014 if (check2 ())
20152015 return state.Invalid (false , REJECT_NONSTANDARD, strprintf (" non-mandatory-script-verify-flag (%s)" , ScriptErrorString (check.GetScriptError ())));
20162016 }
@@ -2406,8 +2406,8 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
24062406 std::vector<std::pair<uint256, CDiskTxPos> > vPos;
24072407 vPos.reserve (block.vtx .size ());
24082408 blockundo.vtxundo .reserve (block.vtx .size () - 1 );
2409- std::vector<CachedHashes> cachedHashes ;
2410- cachedHashes .reserve (block.vtx .size ()); // Required so that pointers to individual CachedHashes don't get invalidated
2409+ std::vector<PrecomputedTransactionData> txdata ;
2410+ txdata .reserve (block.vtx .size ()); // Required so that pointers to individual PrecomputedTransactionData don't get invalidated
24112411 for (unsigned int i = 0 ; i < block.vtx .size (); i++)
24122412 {
24132413 const CTransaction &tx = block.vtx [i];
@@ -2454,14 +2454,14 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
24542454 return state.DoS (100 , error (" ConnectBlock(): too many sigops" ),
24552455 REJECT_INVALID, " bad-blk-sigops" );
24562456
2457- cachedHashes .emplace_back (tx);
2457+ txdata .emplace_back (tx);
24582458 if (!tx.IsCoinBase ())
24592459 {
24602460 nFees += view.GetValueIn (tx)-tx.GetValueOut ();
24612461
24622462 std::vector<CScriptCheck> vChecks;
24632463 bool fCacheResults = fJustCheck ; /* Don't cache results if we're actually connecting blocks (still consult the cache, though) */
2464- if (!CheckInputs (tx, state, view, fScriptChecks , flags, fCacheResults , cachedHashes [i], nScriptCheckThreads ? &vChecks : NULL ))
2464+ if (!CheckInputs (tx, state, view, fScriptChecks , flags, fCacheResults , txdata [i], nScriptCheckThreads ? &vChecks : NULL ))
24652465 return error (" ConnectBlock(): CheckInputs on %s failed with %s" ,
24662466 tx.GetHash ().ToString (), FormatStateMessage (state));
24672467 control.Add (vChecks);
0 commit comments