diff --git a/src/test/script_p2sh_tests.cpp b/src/test/script_p2sh_tests.cpp --- a/src/test/script_p2sh_tests.cpp +++ b/src/test/script_p2sh_tests.cpp @@ -115,12 +115,12 @@ for (int j = 0; j < 8; j++) { CScript sigSave = txTo[i].vin[0].scriptSig; txTo[i].vin[0].scriptSig = txTo[j].vin[0].scriptSig; - const CTxOut &output = txFrom.vout[txTo[i].vin[0].prevout.GetN()]; - bool sigOK = CScriptCheck( - output.scriptPubKey, output.nValue, CTransaction(txTo[i]), 0, - SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_STRICTENC | - SCRIPT_ENABLE_SIGHASH_FORKID, - false, txdata)(); + bool sigOK = + CScriptCheck(txFrom.vout[txTo[i].vin[0].prevout.GetN()], + CTransaction(txTo[i]), 0, + SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_STRICTENC | + SCRIPT_ENABLE_SIGHASH_FORKID, + false, txdata)(); if (i == j) { BOOST_CHECK_MESSAGE(sigOK, strprintf("VerifySignature %d %d", i, j)); diff --git a/src/test/transaction_tests.cpp b/src/test/transaction_tests.cpp --- a/src/test/transaction_tests.cpp +++ b/src/test/transaction_tests.cpp @@ -488,8 +488,7 @@ for (size_t i = 0; i < mtx.vin.size(); i++) { std::vector vChecks; - CTxOut &out = coins[tx.vin[i].prevout.GetN()].GetTxOut(); - CScriptCheck check(out.scriptPubKey, out.nValue, tx, i, + CScriptCheck check(coins[tx.vin[i].prevout.GetN()].GetTxOut(), tx, i, STANDARD_SCRIPT_VERIFY_FLAGS, false, txdata); vChecks.push_back(CScriptCheck()); check.swap(vChecks.back()); diff --git a/src/validation.h b/src/validation.h --- a/src/validation.h +++ b/src/validation.h @@ -581,8 +581,7 @@ */ class CScriptCheck { private: - CScript scriptPubKey; - Amount amount; + CTxOut m_tx_out; const CTransaction *ptxTo; unsigned int nIn; uint32_t nFlags; @@ -595,28 +594,25 @@ public: CScriptCheck() - : amount(), ptxTo(nullptr), nIn(0), nFlags(0), cacheStore(false), + : ptxTo(nullptr), nIn(0), nFlags(0), cacheStore(false), error(ScriptError::UNKNOWN), txdata(), pTxLimitSigChecks(nullptr), pBlockLimitSigChecks(nullptr) {} - CScriptCheck(const CScript &scriptPubKeyIn, const Amount amountIn, - const CTransaction &txToIn, unsigned int nInIn, - uint32_t nFlagsIn, bool cacheIn, + CScriptCheck(const CTxOut &outIn, const CTransaction &txToIn, + unsigned int nInIn, uint32_t nFlagsIn, bool cacheIn, const PrecomputedTransactionData &txdataIn, TxSigCheckLimiter *pTxLimitSigChecksIn = nullptr, CheckInputsLimiter *pBlockLimitSigChecksIn = nullptr) - : scriptPubKey(scriptPubKeyIn), amount(amountIn), ptxTo(&txToIn), - nIn(nInIn), nFlags(nFlagsIn), cacheStore(cacheIn), - error(ScriptError::UNKNOWN), txdata(txdataIn), + : m_tx_out(outIn), ptxTo(&txToIn), nIn(nInIn), nFlags(nFlagsIn), + cacheStore(cacheIn), error(ScriptError::UNKNOWN), txdata(txdataIn), pTxLimitSigChecks(pTxLimitSigChecksIn), pBlockLimitSigChecks(pBlockLimitSigChecksIn) {} bool operator()(); void swap(CScriptCheck &check) { - scriptPubKey.swap(check.scriptPubKey); std::swap(ptxTo, check.ptxTo); - std::swap(amount, check.amount); + std::swap(m_tx_out, check.m_tx_out); std::swap(nIn, check.nIn); std::swap(nFlags, check.nFlags); std::swap(cacheStore, check.cacheStore); diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -996,9 +996,9 @@ bool CScriptCheck::operator()() { const CScript &scriptSig = ptxTo->vin[nIn].scriptSig; - if (!VerifyScript(scriptSig, scriptPubKey, nFlags, - CachingTransactionSignatureChecker(ptxTo, nIn, amount, - cacheStore, txdata), + if (!VerifyScript(scriptSig, m_tx_out.scriptPubKey, nFlags, + CachingTransactionSignatureChecker( + ptxTo, nIn, m_tx_out.nValue, cacheStore, txdata), metrics, &error)) { return false; } @@ -1072,12 +1072,10 @@ // check that our caching is not introducing consensus failures through // additional data in, eg, the coins being spent being checked as a part // of CScriptCheck. - const CScript &scriptPubKey = coin.GetTxOut().scriptPubKey; - const Amount amount = coin.GetTxOut().nValue; // Verify signature - CScriptCheck check(scriptPubKey, amount, tx, i, flags, sigCacheStore, - txdata, &txLimitSigChecks, pBlockLimitSigChecks); + CScriptCheck check(coin.GetTxOut(), tx, i, flags, sigCacheStore, txdata, + &txLimitSigChecks, pBlockLimitSigChecks); if (pvChecks) { pvChecks->push_back(std::move(check)); } else if (!check()) { @@ -1094,7 +1092,7 @@ // NOT_STANDARD instead of CONSENSUS to avoid downstream users // splitting the network between upgraded and non-upgraded nodes // by banning CONSENSUS-failing data providers. - CScriptCheck check2(scriptPubKey, amount, tx, i, mandatoryFlags, + CScriptCheck check2(coin.GetTxOut(), tx, i, mandatoryFlags, sigCacheStore, txdata); if (check2()) { return state.Invalid(