Skip to content

Commit 6f6465c

Browse files
committed
scripted-diff: [validation] Rename CheckInputs to CheckInputScripts
CheckInputs() used to check no double spends, scripts & sigs and amounts. Since 832e074, the double spend and amount checks have been moved to CheckTxInputs(), and CheckInputs() now just validates input scripts. Rename the function to CheckInputScripts(). -BEGIN VERIFY SCRIPT- sed -i -E -e 's/CheckInputs\b/CheckInputScripts/g' $(git grep -l CheckInputs | grep -v doc/) -END VERIFY SCRIPT-
1 parent 2706162 commit 6f6465c

File tree

5 files changed

+33
-33
lines changed

5 files changed

+33
-33
lines changed

src/script/standard.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ extern unsigned nMaxDatacarrierBytes;
4747
* but in the future other flags may be added, such as a soft-fork to enforce
4848
* strict DER encoding.
4949
*
50-
* Failing one of these tests may trigger a DoS ban - see CheckInputs() for
50+
* Failing one of these tests may trigger a DoS ban - see CheckInputScripts() for
5151
* details.
5252
*/
5353
static const unsigned int MANDATORY_SCRIPT_VERIFY_FLAGS = SCRIPT_VERIFY_P2SH;

src/test/txvalidationcache_tests.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
#include <boost/test/unit_test.hpp>
1515

16-
bool CheckInputs(const CTransaction& tx, TxValidationState &state, const CCoinsViewCache &inputs, unsigned int flags, bool cacheSigStore, bool cacheFullScriptStore, PrecomputedTransactionData& txdata, std::vector<CScriptCheck> *pvChecks);
16+
bool CheckInputScripts(const CTransaction& tx, TxValidationState &state, const CCoinsViewCache &inputs, unsigned int flags, bool cacheSigStore, bool cacheFullScriptStore, PrecomputedTransactionData& txdata, std::vector<CScriptCheck> *pvChecks);
1717

1818
BOOST_AUTO_TEST_SUITE(tx_validationcache_tests)
1919

@@ -97,8 +97,8 @@ BOOST_FIXTURE_TEST_CASE(tx_mempool_block_doublespend, TestChain100Setup)
9797
BOOST_CHECK_EQUAL(mempool.size(), 0U);
9898
}
9999

100-
// Run CheckInputs (using CoinsTip()) on the given transaction, for all script
101-
// flags. Test that CheckInputs passes for all flags that don't overlap with
100+
// Run CheckInputScripts (using CoinsTip()) on the given transaction, for all script
101+
// flags. Test that CheckInputScripts passes for all flags that don't overlap with
102102
// the failing_flags argument, but otherwise fails.
103103
// CHECKLOCKTIMEVERIFY and CHECKSEQUENCEVERIFY (and future NOP codes that may
104104
// get reassigned) have an interaction with DISCOURAGE_UPGRADABLE_NOPS: if
@@ -125,8 +125,8 @@ static void ValidateCheckInputsForAllFlags(const CTransaction &tx, uint32_t fail
125125
// WITNESS requires P2SH
126126
test_flags |= SCRIPT_VERIFY_P2SH;
127127
}
128-
bool ret = CheckInputs(tx, state, &::ChainstateActive().CoinsTip(), test_flags, true, add_to_cache, txdata, nullptr);
129-
// CheckInputs should succeed iff test_flags doesn't intersect with
128+
bool ret = CheckInputScripts(tx, state, &::ChainstateActive().CoinsTip(), test_flags, true, add_to_cache, txdata, nullptr);
129+
// CheckInputScripts should succeed iff test_flags doesn't intersect with
130130
// failing_flags
131131
bool expected_return_value = !(test_flags & failing_flags);
132132
BOOST_CHECK_EQUAL(ret, expected_return_value);
@@ -135,21 +135,21 @@ static void ValidateCheckInputsForAllFlags(const CTransaction &tx, uint32_t fail
135135
if (ret && add_to_cache) {
136136
// Check that we get a cache hit if the tx was valid
137137
std::vector<CScriptCheck> scriptchecks;
138-
BOOST_CHECK(CheckInputs(tx, state, &::ChainstateActive().CoinsTip(), test_flags, true, add_to_cache, txdata, &scriptchecks));
138+
BOOST_CHECK(CheckInputScripts(tx, state, &::ChainstateActive().CoinsTip(), test_flags, true, add_to_cache, txdata, &scriptchecks));
139139
BOOST_CHECK(scriptchecks.empty());
140140
} else {
141141
// Check that we get script executions to check, if the transaction
142142
// was invalid, or we didn't add to cache.
143143
std::vector<CScriptCheck> scriptchecks;
144-
BOOST_CHECK(CheckInputs(tx, state, &::ChainstateActive().CoinsTip(), test_flags, true, add_to_cache, txdata, &scriptchecks));
144+
BOOST_CHECK(CheckInputScripts(tx, state, &::ChainstateActive().CoinsTip(), test_flags, true, add_to_cache, txdata, &scriptchecks));
145145
BOOST_CHECK_EQUAL(scriptchecks.size(), tx.vin.size());
146146
}
147147
}
148148
}
149149

150150
BOOST_FIXTURE_TEST_CASE(checkinputs_test, TestChain100Setup)
151151
{
152-
// Test that passing CheckInputs with one set of script flags doesn't imply
152+
// Test that passing CheckInputScripts with one set of script flags doesn't imply
153153
// that we would pass again with a different set of flags.
154154
{
155155
LOCK(cs_main);
@@ -204,16 +204,16 @@ BOOST_FIXTURE_TEST_CASE(checkinputs_test, TestChain100Setup)
204204
TxValidationState state;
205205
PrecomputedTransactionData ptd_spend_tx(spend_tx);
206206

207-
BOOST_CHECK(!CheckInputs(CTransaction(spend_tx), state, &::ChainstateActive().CoinsTip(), SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_DERSIG, true, true, ptd_spend_tx, nullptr));
207+
BOOST_CHECK(!CheckInputScripts(CTransaction(spend_tx), state, &::ChainstateActive().CoinsTip(), SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_DERSIG, true, true, ptd_spend_tx, nullptr));
208208

209209
// If we call again asking for scriptchecks (as happens in
210210
// ConnectBlock), we should add a script check object for this -- we're
211211
// not caching invalidity (if that changes, delete this test case).
212212
std::vector<CScriptCheck> scriptchecks;
213-
BOOST_CHECK(CheckInputs(CTransaction(spend_tx), state, &::ChainstateActive().CoinsTip(), SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_DERSIG, true, true, ptd_spend_tx, &scriptchecks));
213+
BOOST_CHECK(CheckInputScripts(CTransaction(spend_tx), state, &::ChainstateActive().CoinsTip(), SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_DERSIG, true, true, ptd_spend_tx, &scriptchecks));
214214
BOOST_CHECK_EQUAL(scriptchecks.size(), 1U);
215215

216-
// Test that CheckInputs returns true iff DERSIG-enforcing flags are
216+
// Test that CheckInputScripts returns true iff DERSIG-enforcing flags are
217217
// not present. Don't add these checks to the cache, so that we can
218218
// test later that block validation works fine in the absence of cached
219219
// successes.
@@ -272,7 +272,7 @@ BOOST_FIXTURE_TEST_CASE(checkinputs_test, TestChain100Setup)
272272
invalid_with_cltv_tx.vin[0].scriptSig = CScript() << vchSig << 100;
273273
TxValidationState state;
274274
PrecomputedTransactionData txdata(invalid_with_cltv_tx);
275-
BOOST_CHECK(CheckInputs(CTransaction(invalid_with_cltv_tx), state, ::ChainstateActive().CoinsTip(), SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY, true, true, txdata, nullptr));
275+
BOOST_CHECK(CheckInputScripts(CTransaction(invalid_with_cltv_tx), state, ::ChainstateActive().CoinsTip(), SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY, true, true, txdata, nullptr));
276276
}
277277

278278
// TEST CHECKSEQUENCEVERIFY
@@ -300,12 +300,12 @@ BOOST_FIXTURE_TEST_CASE(checkinputs_test, TestChain100Setup)
300300
invalid_with_csv_tx.vin[0].scriptSig = CScript() << vchSig << 100;
301301
TxValidationState state;
302302
PrecomputedTransactionData txdata(invalid_with_csv_tx);
303-
BOOST_CHECK(CheckInputs(CTransaction(invalid_with_csv_tx), state, &::ChainstateActive().CoinsTip(), SCRIPT_VERIFY_CHECKSEQUENCEVERIFY, true, true, txdata, nullptr));
303+
BOOST_CHECK(CheckInputScripts(CTransaction(invalid_with_csv_tx), state, &::ChainstateActive().CoinsTip(), SCRIPT_VERIFY_CHECKSEQUENCEVERIFY, true, true, txdata, nullptr));
304304
}
305305

306306
// TODO: add tests for remaining script flags
307307

308-
// Test that passing CheckInputs with a valid witness doesn't imply success
308+
// Test that passing CheckInputScripts with a valid witness doesn't imply success
309309
// for the same tx with a different witness.
310310
{
311311
CMutableTransaction valid_with_witness_tx;
@@ -362,12 +362,12 @@ BOOST_FIXTURE_TEST_CASE(checkinputs_test, TestChain100Setup)
362362
TxValidationState state;
363363
PrecomputedTransactionData txdata(tx);
364364
// This transaction is now invalid under segwit, because of the second input.
365-
BOOST_CHECK(!CheckInputs(CTransaction(tx), state, &::ChainstateActive().CoinsTip(), SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_WITNESS, true, true, txdata, nullptr));
365+
BOOST_CHECK(!CheckInputScripts(CTransaction(tx), state, &::ChainstateActive().CoinsTip(), SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_WITNESS, true, true, txdata, nullptr));
366366

367367
std::vector<CScriptCheck> scriptchecks;
368368
// Make sure this transaction was not cached (ie because the first
369369
// input was valid)
370-
BOOST_CHECK(CheckInputs(CTransaction(tx), state, &::ChainstateActive().CoinsTip(), SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_WITNESS, true, true, txdata, &scriptchecks));
370+
BOOST_CHECK(CheckInputScripts(CTransaction(tx), state, &::ChainstateActive().CoinsTip(), SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_WITNESS, true, true, txdata, &scriptchecks));
371371
// Should get 2 script checks back -- caching is on a whole-transaction basis.
372372
BOOST_CHECK_EQUAL(scriptchecks.size(), 2U);
373373
}

src/validation.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ std::unique_ptr<CBlockTreeDB> pblocktree;
183183
// See definition for documentation
184184
static void FindFilesToPruneManual(std::set<int>& setFilesToPrune, int nManualPruneHeight);
185185
static void FindFilesToPrune(std::set<int>& setFilesToPrune, uint64_t nPruneAfterHeight);
186-
bool CheckInputs(const CTransaction& tx, TxValidationState &state, const CCoinsViewCache &inputs, unsigned int flags, bool cacheSigStore, bool cacheFullScriptStore, PrecomputedTransactionData& txdata, std::vector<CScriptCheck> *pvChecks = nullptr);
186+
bool CheckInputScripts(const CTransaction& tx, TxValidationState &state, const CCoinsViewCache &inputs, unsigned int flags, bool cacheSigStore, bool cacheFullScriptStore, PrecomputedTransactionData& txdata, std::vector<CScriptCheck> *pvChecks = nullptr);
187187
static FILE* OpenUndoFile(const FlatFilePos &pos, bool fReadOnly = false);
188188
static FlatFileSeq BlockFileSeq();
189189
static FlatFileSeq UndoFileSeq();
@@ -399,15 +399,15 @@ static bool CheckInputsFromMempoolAndCache(const CTransaction& tx, TxValidationS
399399

400400
// pool.cs should be locked already, but go ahead and re-take the lock here
401401
// to enforce that mempool doesn't change between when we check the view
402-
// and when we actually call through to CheckInputs
402+
// and when we actually call through to CheckInputScripts
403403
LOCK(pool.cs);
404404

405405
assert(!tx.IsCoinBase());
406406
for (const CTxIn& txin : tx.vin) {
407407
const Coin& coin = view.AccessCoin(txin.prevout);
408408

409409
// At this point we haven't actually checked if the coins are all
410-
// available (or shouldn't assume we have, since CheckInputs does).
410+
// available (or shouldn't assume we have, since CheckInputScripts does).
411411
// So we just return failure if the inputs are not available here,
412412
// and then only have to check equivalence for available inputs.
413413
if (coin.IsSpent()) return false;
@@ -424,8 +424,8 @@ static bool CheckInputsFromMempoolAndCache(const CTransaction& tx, TxValidationS
424424
}
425425
}
426426

427-
// Call CheckInputs() to cache signature and script validity against current tip consensus rules.
428-
return CheckInputs(tx, state, view, flags, /* cacheSigStore = */ true, /* cacheFullSciptStore = */ true, txdata);
427+
// Call CheckInputScripts() to cache signature and script validity against current tip consensus rules.
428+
return CheckInputScripts(tx, state, view, flags, /* cacheSigStore = */ true, /* cacheFullSciptStore = */ true, txdata);
429429
}
430430

431431
namespace {
@@ -911,18 +911,18 @@ bool MemPoolAccept::PolicyScriptChecks(ATMPArgs& args, Workspace& ws, Precompute
911911

912912
// Check against previous transactions
913913
// This is done last to help prevent CPU exhaustion denial-of-service attacks.
914-
if (!CheckInputs(tx, state, m_view, scriptVerifyFlags, true, false, txdata)) {
914+
if (!CheckInputScripts(tx, state, m_view, scriptVerifyFlags, true, false, txdata)) {
915915
// SCRIPT_VERIFY_CLEANSTACK requires SCRIPT_VERIFY_WITNESS, so we
916916
// need to turn both off, and compare against just turning off CLEANSTACK
917917
// to see if the failure is specifically due to witness validation.
918-
TxValidationState state_dummy; // Want reported failures to be from first CheckInputs
919-
if (!tx.HasWitness() && CheckInputs(tx, state_dummy, m_view, scriptVerifyFlags & ~(SCRIPT_VERIFY_WITNESS | SCRIPT_VERIFY_CLEANSTACK), true, false, txdata) &&
920-
!CheckInputs(tx, state_dummy, m_view, scriptVerifyFlags & ~SCRIPT_VERIFY_CLEANSTACK, true, false, txdata)) {
918+
TxValidationState state_dummy; // Want reported failures to be from first CheckInputScripts
919+
if (!tx.HasWitness() && CheckInputScripts(tx, state_dummy, m_view, scriptVerifyFlags & ~(SCRIPT_VERIFY_WITNESS | SCRIPT_VERIFY_CLEANSTACK), true, false, txdata) &&
920+
!CheckInputScripts(tx, state_dummy, m_view, scriptVerifyFlags & ~SCRIPT_VERIFY_CLEANSTACK, true, false, txdata)) {
921921
// Only the witness is missing, so the transaction itself may be fine.
922922
state.Invalid(TxValidationResult::TX_WITNESS_MUTATED,
923923
state.GetRejectReason(), state.GetDebugMessage());
924924
}
925-
return false; // state filled in by CheckInputs
925+
return false; // state filled in by CheckInputScripts
926926
}
927927

928928
return true;
@@ -953,7 +953,7 @@ bool MemPoolAccept::ConsensusScriptChecks(ATMPArgs& args, Workspace& ws, Precomp
953953
// transactions into the mempool can be exploited as a DoS attack.
954954
unsigned int currentBlockScriptVerifyFlags = GetBlockScriptFlags(::ChainActive().Tip(), chainparams.GetConsensus());
955955
if (!CheckInputsFromMempoolAndCache(tx, state, m_view, m_pool, currentBlockScriptVerifyFlags, txdata)) {
956-
return error("%s: BUG! PLEASE REPORT THIS! CheckInputs failed against latest-block but not STANDARD flags %s, %s",
956+
return error("%s: BUG! PLEASE REPORT THIS! CheckInputScripts failed against latest-block but not STANDARD flags %s, %s",
957957
__func__, hash.ToString(), FormatStateMessage(state));
958958
}
959959

@@ -1485,7 +1485,7 @@ void InitScriptExecutionCache() {
14851485
*
14861486
* Non-static (and re-declared) in src/test/txvalidationcache_tests.cpp
14871487
*/
1488-
bool CheckInputs(const CTransaction& tx, TxValidationState &state, const CCoinsViewCache &inputs, unsigned int flags, bool cacheSigStore, bool cacheFullScriptStore, PrecomputedTransactionData& txdata, std::vector<CScriptCheck> *pvChecks) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
1488+
bool CheckInputScripts(const CTransaction& tx, TxValidationState &state, const CCoinsViewCache &inputs, unsigned int flags, bool cacheSigStore, bool cacheFullScriptStore, PrecomputedTransactionData& txdata, std::vector<CScriptCheck> *pvChecks) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
14891489
{
14901490
if (tx.IsCoinBase()) return true;
14911491

@@ -2132,11 +2132,11 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state,
21322132
std::vector<CScriptCheck> vChecks;
21332133
bool fCacheResults = fJustCheck; /* Don't cache results if we're actually connecting blocks (still consult the cache, though) */
21342134
TxValidationState tx_state;
2135-
if (fScriptChecks && !CheckInputs(tx, tx_state, view, flags, fCacheResults, fCacheResults, txdata[i], g_parallel_script_checks ? &vChecks : nullptr)) {
2135+
if (fScriptChecks && !CheckInputScripts(tx, tx_state, view, flags, fCacheResults, fCacheResults, txdata[i], g_parallel_script_checks ? &vChecks : nullptr)) {
21362136
// Any transaction validation failure in ConnectBlock is a block consensus failure
21372137
state.Invalid(BlockValidationResult::BLOCK_CONSENSUS,
21382138
tx_state.GetRejectReason(), tx_state.GetDebugMessage());
2139-
return error("ConnectBlock(): CheckInputs on %s failed with %s",
2139+
return error("ConnectBlock(): CheckInputScripts on %s failed with %s",
21402140
tx.GetHash().ToString(), FormatStateMessage(state));
21412141
}
21422142
control.Add(vChecks);

test/functional/feature_cltv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def run_test(self):
135135
block.hashMerkleRoot = block.calc_merkle_root()
136136
block.solve()
137137

138-
with self.nodes[0].assert_debug_log(expected_msgs=['CheckInputs on {} failed with non-mandatory-script-verify-flag (Negative locktime)'.format(block.vtx[-1].hash)]):
138+
with self.nodes[0].assert_debug_log(expected_msgs=['CheckInputScripts on {} failed with non-mandatory-script-verify-flag (Negative locktime)'.format(block.vtx[-1].hash)]):
139139
self.nodes[0].p2p.send_and_ping(msg_block(block))
140140
assert_equal(int(self.nodes[0].getbestblockhash(), 16), tip)
141141
self.nodes[0].p2p.sync_with_ping()

test/functional/feature_dersig.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def run_test(self):
120120
block.rehash()
121121
block.solve()
122122

123-
with self.nodes[0].assert_debug_log(expected_msgs=['CheckInputs on {} failed with non-mandatory-script-verify-flag (Non-canonical DER signature)'.format(block.vtx[-1].hash)]):
123+
with self.nodes[0].assert_debug_log(expected_msgs=['CheckInputScripts on {} failed with non-mandatory-script-verify-flag (Non-canonical DER signature)'.format(block.vtx[-1].hash)]):
124124
self.nodes[0].p2p.send_and_ping(msg_block(block))
125125
assert_equal(int(self.nodes[0].getbestblockhash(), 16), tip)
126126
self.nodes[0].p2p.sync_with_ping()

0 commit comments

Comments
 (0)