Skip to content

Commit 35fe039

Browse files
committed
Rename to PrecomputedTransactionData
1 parent ab48c5e commit 35fe039

File tree

8 files changed

+39
-39
lines changed

8 files changed

+39
-39
lines changed

src/main.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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)
19111911
bool 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);

src/main.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class CScriptCheck;
3838
class CTxMemPool;
3939
class CValidationInterface;
4040
class CValidationState;
41-
class CachedHashes;
41+
class PrecomputedTransactionData;
4242

4343
struct CNodeStateStats;
4444
struct LockPoints;
@@ -348,7 +348,7 @@ int64_t GetTransactionSigOpCost(const CTransaction& tx, const CCoinsViewCache& i
348348
* instead of being performed inline.
349349
*/
350350
bool CheckInputs(const CTransaction& tx, CValidationState &state, const CCoinsViewCache &view, bool fScriptChecks,
351-
unsigned int flags, bool cacheStore, CachedHashes& cachedHashes, std::vector<CScriptCheck> *pvChecks = NULL);
351+
unsigned int flags, bool cacheStore, PrecomputedTransactionData& txdata, std::vector<CScriptCheck> *pvChecks = NULL);
352352

353353
/** Apply the effects of this transaction on the UTXO set represented by view */
354354
void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, int nHeight);
@@ -422,13 +422,13 @@ class CScriptCheck
422422
unsigned int nFlags;
423423
bool cacheStore;
424424
ScriptError error;
425-
CachedHashes *cachedHashes;
425+
PrecomputedTransactionData *txdata;
426426

427427
public:
428428
CScriptCheck(): amount(0), ptxTo(0), nIn(0), nFlags(0), cacheStore(false), error(SCRIPT_ERR_UNKNOWN_ERROR) {}
429-
CScriptCheck(const CCoins& txFromIn, const CTransaction& txToIn, unsigned int nInIn, unsigned int nFlagsIn, bool cacheIn, CachedHashes* cachedHashesIn) :
429+
CScriptCheck(const CCoins& txFromIn, const CTransaction& txToIn, unsigned int nInIn, unsigned int nFlagsIn, bool cacheIn, PrecomputedTransactionData* txdataIn) :
430430
scriptPubKey(txFromIn.vout[txToIn.vin[nInIn].prevout.n].scriptPubKey), amount(txFromIn.vout[txToIn.vin[nInIn].prevout.n].nValue),
431-
ptxTo(&txToIn), nIn(nInIn), nFlags(nFlagsIn), cacheStore(cacheIn), error(SCRIPT_ERR_UNKNOWN_ERROR), cachedHashes(cachedHashesIn) { }
431+
ptxTo(&txToIn), nIn(nInIn), nFlags(nFlagsIn), cacheStore(cacheIn), error(SCRIPT_ERR_UNKNOWN_ERROR), txdata(txdataIn) { }
432432

433433
bool operator()();
434434

@@ -440,7 +440,7 @@ class CScriptCheck
440440
std::swap(nFlags, check.nFlags);
441441
std::swap(cacheStore, check.cacheStore);
442442
std::swap(error, check.error);
443-
std::swap(cachedHashes, check.cachedHashes);
443+
std::swap(txdata, check.txdata);
444444
}
445445

446446
ScriptError GetScriptError() const { return error; }

src/script/bitcoinconsensus.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ static int verify_script(const unsigned char *scriptPubKey, unsigned int scriptP
8484

8585
// Regardless of the verification result, the tx did not error.
8686
set_error(err, bitcoinconsensus_ERR_OK);
87-
CachedHashes cachedHashes(tx);
88-
return VerifyScript(tx.vin[nIn].scriptSig, CScript(scriptPubKey, scriptPubKey + scriptPubKeyLen), nIn < tx.wit.vtxinwit.size() ? &tx.wit.vtxinwit[nIn].scriptWitness : NULL, flags, TransactionSignatureChecker(&tx, nIn, amount, cachedHashes), NULL);
87+
PrecomputedTransactionData txdata(tx);
88+
return VerifyScript(tx.vin[nIn].scriptSig, CScript(scriptPubKey, scriptPubKey + scriptPubKeyLen), nIn < tx.wit.vtxinwit.size() ? &tx.wit.vtxinwit[nIn].scriptWitness : NULL, flags, TransactionSignatureChecker(&tx, nIn, amount, txdata), NULL);
8989
} catch (const std::exception&) {
9090
return set_error(err, bitcoinconsensus_ERR_TX_DESERIALIZE); // Error deserializing
9191
}

src/script/interpreter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,14 +1134,14 @@ uint256 GetOutputsHash(const CTransaction& txTo) {
11341134

11351135
} // anon namespace
11361136

1137-
CachedHashes::CachedHashes(const CTransaction& txTo)
1137+
PrecomputedTransactionData::PrecomputedTransactionData(const CTransaction& txTo)
11381138
{
11391139
hashPrevouts = GetPrevoutHash(txTo);
11401140
hashSequence = GetSequenceHash(txTo);
11411141
hashOutputs = GetOutputsHash(txTo);
11421142
}
11431143

1144-
uint256 SignatureHash(const CScript& scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType, const CAmount& amount, SigVersion sigversion, const CachedHashes* cache)
1144+
uint256 SignatureHash(const CScript& scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType, const CAmount& amount, SigVersion sigversion, const PrecomputedTransactionData* cache)
11451145
{
11461146
if (sigversion == SIGVERSION_WITNESS_V0) {
11471147
uint256 hashPrevouts;
@@ -1229,7 +1229,7 @@ bool TransactionSignatureChecker::CheckSig(const vector<unsigned char>& vchSigIn
12291229
int nHashType = vchSig.back();
12301230
vchSig.pop_back();
12311231

1232-
uint256 sighash = SignatureHash(scriptCode, *txTo, nIn, nHashType, amount, sigversion, this->cachedHashes);
1232+
uint256 sighash = SignatureHash(scriptCode, *txTo, nIn, nHashType, amount, sigversion, this->txdata);
12331233

12341234
if (!VerifySignature(vchSig, pubkey, sighash))
12351235
return false;

src/script/interpreter.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,11 @@ enum
9898

9999
bool CheckSignatureEncoding(const std::vector<unsigned char> &vchSig, unsigned int flags, ScriptError* serror);
100100

101-
struct CachedHashes
101+
struct PrecomputedTransactionData
102102
{
103103
uint256 hashPrevouts, hashSequence, hashOutputs;
104104

105-
CachedHashes(const CTransaction& tx);
105+
PrecomputedTransactionData(const CTransaction& tx);
106106
};
107107

108108
enum SigVersion
@@ -111,7 +111,7 @@ enum SigVersion
111111
SIGVERSION_WITNESS_V0 = 1,
112112
};
113113

114-
uint256 SignatureHash(const CScript &scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType, const CAmount& amount, SigVersion sigversion, const CachedHashes* cache = NULL);
114+
uint256 SignatureHash(const CScript &scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType, const CAmount& amount, SigVersion sigversion, const PrecomputedTransactionData* cache = NULL);
115115

116116
class BaseSignatureChecker
117117
{
@@ -140,14 +140,14 @@ class TransactionSignatureChecker : public BaseSignatureChecker
140140
const CTransaction* txTo;
141141
unsigned int nIn;
142142
const CAmount amount;
143-
const CachedHashes* cachedHashes;
143+
const PrecomputedTransactionData* txdata;
144144

145145
protected:
146146
virtual bool VerifySignature(const std::vector<unsigned char>& vchSig, const CPubKey& vchPubKey, const uint256& sighash) const;
147147

148148
public:
149-
TransactionSignatureChecker(const CTransaction* txToIn, unsigned int nInIn, const CAmount& amountIn) : txTo(txToIn), nIn(nInIn), amount(amountIn), cachedHashes(NULL) {}
150-
TransactionSignatureChecker(const CTransaction* txToIn, unsigned int nInIn, const CAmount& amountIn, const CachedHashes& cachedHashesIn) : txTo(txToIn), nIn(nInIn), amount(amountIn), cachedHashes(&cachedHashesIn) {}
149+
TransactionSignatureChecker(const CTransaction* txToIn, unsigned int nInIn, const CAmount& amountIn) : txTo(txToIn), nIn(nInIn), amount(amountIn), txdata(NULL) {}
150+
TransactionSignatureChecker(const CTransaction* txToIn, unsigned int nInIn, const CAmount& amountIn, const PrecomputedTransactionData& txdataIn) : txTo(txToIn), nIn(nInIn), amount(amountIn), txdata(&txdataIn) {}
151151
bool CheckSig(const std::vector<unsigned char>& scriptSig, const std::vector<unsigned char>& vchPubKey, const CScript& scriptCode, SigVersion sigversion) const;
152152
bool CheckLockTime(const CScriptNum& nLockTime) const;
153153
bool CheckSequence(const CScriptNum& nSequence) const;

src/script/sigcache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class CachingTransactionSignatureChecker : public TransactionSignatureChecker
2222
bool store;
2323

2424
public:
25-
CachingTransactionSignatureChecker(const CTransaction* txToIn, unsigned int nInIn, const CAmount& amount, bool storeIn, CachedHashes& cachedHashesIn) : TransactionSignatureChecker(txToIn, nInIn, amount, cachedHashesIn), store(storeIn) {}
25+
CachingTransactionSignatureChecker(const CTransaction* txToIn, unsigned int nInIn, const CAmount& amount, bool storeIn, PrecomputedTransactionData& txdataIn) : TransactionSignatureChecker(txToIn, nInIn, amount, txdataIn), store(storeIn) {}
2626

2727
bool VerifySignature(const std::vector<unsigned char>& vchSig, const CPubKey& vchPubKey, const uint256& sighash) const;
2828
};

src/test/script_P2SH_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,12 @@ BOOST_AUTO_TEST_CASE(sign)
108108
// All of the above should be OK, and the txTos have valid signatures
109109
// Check to make sure signature verification fails if we use the wrong ScriptSig:
110110
for (int i = 0; i < 8; i++) {
111-
CachedHashes cachedHashes(txTo[i]);
111+
PrecomputedTransactionData txdata(txTo[i]);
112112
for (int j = 0; j < 8; j++)
113113
{
114114
CScript sigSave = txTo[i].vin[0].scriptSig;
115115
txTo[i].vin[0].scriptSig = txTo[j].vin[0].scriptSig;
116-
bool sigOK = CScriptCheck(CCoins(txFrom, 0), txTo[i], 0, SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_STRICTENC, false, &cachedHashes)();
116+
bool sigOK = CScriptCheck(CCoins(txFrom, 0), txTo[i], 0, SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_STRICTENC, false, &txdata)();
117117
if (i == j)
118118
BOOST_CHECK_MESSAGE(sigOK, strprintf("VerifySignature %d %d", i, j));
119119
else

src/test/transaction_tests.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ BOOST_AUTO_TEST_CASE(tx_valid)
154154
BOOST_CHECK_MESSAGE(CheckTransaction(tx, state), strTest);
155155
BOOST_CHECK(state.IsValid());
156156

157-
CachedHashes cachedHashes(tx);
157+
PrecomputedTransactionData txdata(tx);
158158
for (unsigned int i = 0; i < tx.vin.size(); i++)
159159
{
160160
if (!mapprevOutScriptPubKeys.count(tx.vin[i].prevout))
@@ -170,7 +170,7 @@ BOOST_AUTO_TEST_CASE(tx_valid)
170170
unsigned int verify_flags = ParseScriptFlags(test[2].get_str());
171171
const CScriptWitness *witness = (i < tx.wit.vtxinwit.size()) ? &tx.wit.vtxinwit[i].scriptWitness : NULL;
172172
BOOST_CHECK_MESSAGE(VerifyScript(tx.vin[i].scriptSig, mapprevOutScriptPubKeys[tx.vin[i].prevout],
173-
witness, verify_flags, TransactionSignatureChecker(&tx, i, amount, cachedHashes), &err),
173+
witness, verify_flags, TransactionSignatureChecker(&tx, i, amount, txdata), &err),
174174
strTest);
175175
BOOST_CHECK_MESSAGE(err == SCRIPT_ERR_OK, ScriptErrorString(err));
176176
}
@@ -239,7 +239,7 @@ BOOST_AUTO_TEST_CASE(tx_invalid)
239239
CValidationState state;
240240
fValid = CheckTransaction(tx, state) && state.IsValid();
241241

242-
CachedHashes cachedHashes(tx);
242+
PrecomputedTransactionData txdata(tx);
243243
for (unsigned int i = 0; i < tx.vin.size() && fValid; i++)
244244
{
245245
if (!mapprevOutScriptPubKeys.count(tx.vin[i].prevout))
@@ -255,7 +255,7 @@ BOOST_AUTO_TEST_CASE(tx_invalid)
255255
}
256256
const CScriptWitness *witness = (i < tx.wit.vtxinwit.size()) ? &tx.wit.vtxinwit[i].scriptWitness : NULL;
257257
fValid = VerifyScript(tx.vin[i].scriptSig, mapprevOutScriptPubKeys[tx.vin[i].prevout],
258-
witness, verify_flags, TransactionSignatureChecker(&tx, i, amount, cachedHashes), &err);
258+
witness, verify_flags, TransactionSignatureChecker(&tx, i, amount, txdata), &err);
259259
}
260260
BOOST_CHECK_MESSAGE(!fValid, strTest);
261261
BOOST_CHECK_MESSAGE(err != SCRIPT_ERR_OK, ScriptErrorString(err));
@@ -469,7 +469,7 @@ BOOST_AUTO_TEST_CASE(test_big_witness_transaction) {
469469
WithOrVersion(&ssout, 0) >> tx;
470470

471471
// check all inputs concurrently, with the cache
472-
CachedHashes cachedHashes(tx);
472+
PrecomputedTransactionData txdata(tx);
473473
boost::thread_group threadGroup;
474474
CCheckQueue<CScriptCheck> scriptcheckqueue(128);
475475
CCheckQueueControl<CScriptCheck> control(&scriptcheckqueue);
@@ -489,7 +489,7 @@ BOOST_AUTO_TEST_CASE(test_big_witness_transaction) {
489489

490490
for(uint32_t i = 0; i < mtx.vin.size(); i++) {
491491
std::vector<CScriptCheck> vChecks;
492-
CScriptCheck check(coins, tx, i, SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_WITNESS, false, &cachedHashes);
492+
CScriptCheck check(coins, tx, i, SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_WITNESS, false, &txdata);
493493
vChecks.push_back(CScriptCheck());
494494
check.swap(vChecks.back());
495495
control.Add(vChecks);

0 commit comments

Comments
 (0)