Bitcoin Core 32.99.0
P2P Digital Currency
txvalidationcache_tests.cpp
Go to the documentation of this file.
1// Copyright (c) 2011-present The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
6#include <key.h>
7#include <random.h>
8#include <script/sigcache.h>
9#include <script/sign.h>
12#include <txmempool.h>
13#include <util/chaintype.h>
14#include <validation.h>
15
16#include <boost/test/unit_test.hpp>
17
20 : TestChain100Setup{ChainType::REGTEST, {.extra_args = {"-testactivationheight=dersig@102"}}} {}
21};
22
24 const CCoinsViewCache& inputs, script_verify_flags flags, bool cacheSigStore,
25 bool cacheFullScriptStore, PrecomputedTransactionData& txdata,
26 ValidationCache& validation_cache,
27 std::vector<CScriptCheck>* pvChecks) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
28
29BOOST_AUTO_TEST_SUITE(txvalidationcache_tests)
30
31BOOST_FIXTURE_TEST_CASE(tx_mempool_block_doublespend, Dersig100Setup)
32{
33 // Make sure skipping validation of transactions that were
34 // validated going into the memory pool does not allow
35 // double-spends in blocks to pass validation when they should not.
36
37 CScript scriptPubKey = CScript() << ToByteVector(coinbaseKey.GetPubKey()) << OP_CHECKSIG;
38
39 const auto ToMemPool = [this](const CMutableTransaction& tx) {
41
42 const MempoolAcceptResult result = m_node.chainman->ProcessTransaction(MakeTransactionRef(tx));
44 };
45
46 // Create a double-spend of mature coinbase txn:
47 std::vector<CMutableTransaction> spends;
48 spends.resize(2);
49 for (int i = 0; i < 2; i++)
50 {
51 spends[i].version = 1;
52 spends[i].vin = {CTxIn{m_coinbase_txns[0]->GetHash(), 0}};
53 spends[i].vout = {CTxOut{11*CENT, scriptPubKey}};
54
55 // Sign:
56 std::vector<unsigned char> vchSig;
57 uint256 hash = SignatureHash(scriptPubKey, spends[i], 0, SIGHASH_ALL, 0, SigVersion::BASE);
58 BOOST_CHECK(coinbaseKey.Sign(hash, vchSig));
59 vchSig.push_back((unsigned char)SIGHASH_ALL);
60 spends[i].vin[0].scriptSig << vchSig;
61 }
62
63 CBlock block;
64
65 // Test 1: block with both of those transactions should be rejected.
66 block = CreateAndProcessBlock(spends, scriptPubKey);
67 {
69 BOOST_CHECK(m_node.chainman->ActiveChain().Tip()->GetBlockHash() != block.GetHash());
70 }
71
72 // Test 2: ... and should be rejected if spend1 is in the memory pool
73 BOOST_CHECK(ToMemPool(spends[0]));
74 block = CreateAndProcessBlock(spends, scriptPubKey);
75 {
77 BOOST_CHECK(m_node.chainman->ActiveChain().Tip()->GetBlockHash() != block.GetHash());
78 }
79 BOOST_CHECK_EQUAL(m_node.mempool->size(), 1U);
81 BOOST_CHECK_EQUAL(m_node.mempool->size(), 0U);
82
83 // Test 3: ... and should be rejected if spend2 is in the memory pool
84 BOOST_CHECK(ToMemPool(spends[1]));
85 block = CreateAndProcessBlock(spends, scriptPubKey);
86 {
88 BOOST_CHECK(m_node.chainman->ActiveChain().Tip()->GetBlockHash() != block.GetHash());
89 }
90 BOOST_CHECK_EQUAL(m_node.mempool->size(), 1U);
92 BOOST_CHECK_EQUAL(m_node.mempool->size(), 0U);
93
94 // Final sanity test: first spend in *m_node.mempool, second in block, that's OK:
95 std::vector<CMutableTransaction> oneSpend;
96 oneSpend.push_back(spends[0]);
97 BOOST_CHECK(ToMemPool(spends[1]));
98 block = CreateAndProcessBlock(oneSpend, scriptPubKey);
99 {
100 LOCK(cs_main);
101 BOOST_CHECK(m_node.chainman->ActiveChain().Tip()->GetBlockHash() == block.GetHash());
102 }
103 // spends[1] should have been removed from the mempool when the
104 // block with spends[0] is accepted:
105 BOOST_CHECK_EQUAL(m_node.mempool->size(), 0U);
106}
107
108// Run CheckInputScripts (using CoinsTip()) on the given transaction, for all script
109// flags. Test that CheckInputScripts passes for all flags that don't overlap with
110// the failing_flags argument, but otherwise fails.
111// CHECKLOCKTIMEVERIFY and CHECKSEQUENCEVERIFY (and future NOP codes that may
112// get reassigned) have an interaction with DISCOURAGE_UPGRADABLE_NOPS: if
113// the script flags used contain DISCOURAGE_UPGRADABLE_NOPS but don't contain
114// CHECKLOCKTIMEVERIFY (or CHECKSEQUENCEVERIFY), but the script does contain
115// OP_CHECKLOCKTIMEVERIFY (or OP_CHECKSEQUENCEVERIFY), then script execution
116// should fail.
117static void ValidateCheckInputsForAllFlags(const CTransaction &tx, script_verify_flags failing_flags, bool add_to_cache, CCoinsViewCache& active_coins_tip, ValidationCache& validation_cache) EXCLUSIVE_LOCKS_REQUIRED(::cs_main)
118{
120
121 FastRandomContext insecure_rand(true);
122
123 for (int count = 0; count < 10000; ++count) {
124 TxValidationState state;
125
126 // Randomly selects flag combinations
128
129 // Filter out incompatible flag choices
130 if ((test_flags & SCRIPT_VERIFY_CLEANSTACK)) {
131 // CLEANSTACK requires P2SH and WITNESS, see VerifyScript() in
132 // script/interpreter.cpp
134 }
135 if ((test_flags & SCRIPT_VERIFY_TAPROOT)) {
136 // TAPROOT requires WITNESS
137 test_flags |= SCRIPT_VERIFY_WITNESS;
138 }
139 if ((test_flags & SCRIPT_VERIFY_WITNESS)) {
140 // WITNESS requires P2SH
141 test_flags |= SCRIPT_VERIFY_P2SH;
142 }
143 bool ret = CheckInputScripts(tx, state, &active_coins_tip, test_flags, true, add_to_cache, txdata, validation_cache, nullptr);
144 // CheckInputScripts should succeed iff test_flags doesn't intersect with
145 // failing_flags
146 bool expected_return_value = !(test_flags & failing_flags);
147 BOOST_CHECK_EQUAL(ret, expected_return_value);
148
149 // Test the caching
150 if (ret && add_to_cache) {
151 // Check that we get a cache hit if the tx was valid
152 std::vector<CScriptCheck> scriptchecks;
153 BOOST_CHECK(CheckInputScripts(tx, state, &active_coins_tip, test_flags, true, add_to_cache, txdata, validation_cache, &scriptchecks));
154 BOOST_CHECK(scriptchecks.empty());
155 } else {
156 // Check that we get script executions to check, if the transaction
157 // was invalid, or we didn't add to cache.
158 std::vector<CScriptCheck> scriptchecks;
159 BOOST_CHECK(CheckInputScripts(tx, state, &active_coins_tip, test_flags, true, add_to_cache, txdata, validation_cache, &scriptchecks));
160 BOOST_CHECK_EQUAL(scriptchecks.size(), tx.vin.size());
161 }
162 }
163}
164
166{
167 // Test that passing CheckInputScripts with one set of script flags doesn't imply
168 // that we would pass again with a different set of flags.
169 CScript p2pk_scriptPubKey = CScript() << ToByteVector(coinbaseKey.GetPubKey()) << OP_CHECKSIG;
170 CScript p2sh_scriptPubKey = GetScriptForDestination(ScriptHash(p2pk_scriptPubKey));
171 CScript p2pkh_scriptPubKey = GetScriptForDestination(PKHash(coinbaseKey.GetPubKey()));
172 CScript p2wpkh_scriptPubKey = GetScriptForDestination(WitnessV0KeyHash(coinbaseKey.GetPubKey()));
173 CScript p2tr_scriptPubKey = GetScriptForDestination(WitnessV1Taproot(XOnlyPubKey(coinbaseKey.GetPubKey())));
174
176 BOOST_CHECK(keystore.AddKey(coinbaseKey));
177 BOOST_CHECK(keystore.AddCScript(p2pk_scriptPubKey));
178
179 // flags to test: SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY, SCRIPT_VERIFY_CHECKSEQUENCE_VERIFY, SCRIPT_VERIFY_NULLDUMMY, uncompressed pubkey thing
180
181 // Create 2 outputs that match the three scripts above, spending the first
182 // coinbase tx.
183 CMutableTransaction spend_tx;
184
185 spend_tx.version = 1;
186 spend_tx.vin = {CTxIn{m_coinbase_txns[0]->GetHash(), 0}};
187 spend_tx.vout = {
188 CTxOut{11*CENT, p2sh_scriptPubKey},
189 CTxOut{11*CENT, p2wpkh_scriptPubKey},
190 CTxOut{11*CENT, CScript() << OP_CHECKLOCKTIMEVERIFY << OP_DROP << ToByteVector(coinbaseKey.GetPubKey()) << OP_CHECKSIG},
191 CTxOut{11*CENT, CScript() << OP_CHECKSEQUENCEVERIFY << OP_DROP << ToByteVector(coinbaseKey.GetPubKey()) << OP_CHECKSIG},
192 CTxOut{11*CENT, p2tr_scriptPubKey},
193 };
194
195 // Sign, with a non-DER signature
196 {
197 std::vector<unsigned char> vchSig;
198 uint256 hash = SignatureHash(p2pk_scriptPubKey, spend_tx, 0, SIGHASH_ALL, 0, SigVersion::BASE);
199 BOOST_CHECK(coinbaseKey.Sign(hash, vchSig));
200 vchSig.push_back((unsigned char) 0); // padding byte makes this non-DER
201 vchSig.push_back((unsigned char)SIGHASH_ALL);
202 spend_tx.vin[0].scriptSig << vchSig;
203 }
204
205 // Test that invalidity under a set of flags doesn't preclude validity
206 // under other (eg consensus) flags.
207 // spend_tx is invalid according to DERSIG
208 {
209 LOCK(cs_main);
210
211 TxValidationState state;
212 PrecomputedTransactionData ptd_spend_tx;
213
214 BOOST_CHECK(!CheckInputScripts(CTransaction(spend_tx), state, &m_node.chainman->ActiveChainstate().CoinsTip(), SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_DERSIG, true, true, ptd_spend_tx, m_node.chainman->m_validation_cache, nullptr));
215
216 // If we call again asking for scriptchecks (as happens in
217 // ConnectBlock), we should add a script check object for this -- we're
218 // not caching invalidity (if that changes, delete this test case).
219 std::vector<CScriptCheck> scriptchecks;
220 BOOST_CHECK(CheckInputScripts(CTransaction(spend_tx), state, &m_node.chainman->ActiveChainstate().CoinsTip(), SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_DERSIG, true, true, ptd_spend_tx, m_node.chainman->m_validation_cache, &scriptchecks));
221 BOOST_CHECK_EQUAL(scriptchecks.size(), 1U);
222
223 // Test that CheckInputScripts returns true iff DERSIG-enforcing flags are
224 // not present. Don't add these checks to the cache, so that we can
225 // test later that block validation works fine in the absence of cached
226 // successes.
227 ValidateCheckInputsForAllFlags(CTransaction(spend_tx), SCRIPT_VERIFY_DERSIG | SCRIPT_VERIFY_LOW_S | SCRIPT_VERIFY_STRICTENC, false, m_node.chainman->ActiveChainstate().CoinsTip(), m_node.chainman->m_validation_cache);
228 }
229
230 // And if we produce a block with this tx, it should be valid (DERSIG not
231 // enabled yet), even though there's no cache entry.
232 CBlock block;
233
234 block = CreateAndProcessBlock({spend_tx}, p2pk_scriptPubKey);
235 LOCK(cs_main);
236 BOOST_CHECK(m_node.chainman->ActiveChain().Tip()->GetBlockHash() == block.GetHash());
237 BOOST_CHECK(m_node.chainman->ActiveChainstate().CoinsTip().GetBestBlock() == block.GetHash());
238
239 // Test P2SH: construct a transaction that is valid without P2SH, and
240 // then test validity with P2SH.
241 {
242 CMutableTransaction invalid_under_p2sh_tx;
243 invalid_under_p2sh_tx.version = 1;
244 invalid_under_p2sh_tx.vin = {CTxIn{spend_tx.GetHash(), 0}};
245 invalid_under_p2sh_tx.vout = {CTxOut{11*CENT, p2pk_scriptPubKey}};
246 std::vector<unsigned char> vchSig2(p2pk_scriptPubKey.begin(), p2pk_scriptPubKey.end());
247 invalid_under_p2sh_tx.vin[0].scriptSig << vchSig2;
248
249 ValidateCheckInputsForAllFlags(CTransaction(invalid_under_p2sh_tx), SCRIPT_VERIFY_P2SH, true, m_node.chainman->ActiveChainstate().CoinsTip(), m_node.chainman->m_validation_cache);
250 }
251
252 // Test CHECKLOCKTIMEVERIFY
253 {
254 CMutableTransaction invalid_with_cltv_tx;
255 invalid_with_cltv_tx.version = 1;
256 invalid_with_cltv_tx.nLockTime = 100;
257 invalid_with_cltv_tx.vin = {CTxIn{spend_tx.GetHash(), 2, {}, /*nSequenceIn=*/0}};
258 invalid_with_cltv_tx.vout = {CTxOut{11*CENT, p2pk_scriptPubKey}};
259
260 // Sign
261 std::vector<unsigned char> vchSig;
262 uint256 hash = SignatureHash(spend_tx.vout[2].scriptPubKey, invalid_with_cltv_tx, 0, SIGHASH_ALL, 0, SigVersion::BASE);
263 BOOST_CHECK(coinbaseKey.Sign(hash, vchSig));
264 vchSig.push_back((unsigned char)SIGHASH_ALL);
265 invalid_with_cltv_tx.vin[0].scriptSig = CScript() << vchSig << 101;
266
267 ValidateCheckInputsForAllFlags(CTransaction(invalid_with_cltv_tx), SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY, true, m_node.chainman->ActiveChainstate().CoinsTip(), m_node.chainman->m_validation_cache);
268
269 // Make it valid, and check again
270 invalid_with_cltv_tx.vin[0].scriptSig = CScript() << vchSig << 100;
271 TxValidationState state;
273 BOOST_CHECK(CheckInputScripts(CTransaction(invalid_with_cltv_tx), state, m_node.chainman->ActiveChainstate().CoinsTip(), SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY, true, true, txdata, m_node.chainman->m_validation_cache, nullptr));
274 }
275
276 // TEST CHECKSEQUENCEVERIFY
277 {
278 CMutableTransaction invalid_with_csv_tx;
279 invalid_with_csv_tx.version = 2;
280 invalid_with_csv_tx.vin = {CTxIn{spend_tx.GetHash(), 3, {}, /*nSequenceIn=*/100}};
281 invalid_with_csv_tx.vout = {CTxOut{11*CENT, p2pk_scriptPubKey}};
282
283 // Sign
284 std::vector<unsigned char> vchSig;
285 uint256 hash = SignatureHash(spend_tx.vout[3].scriptPubKey, invalid_with_csv_tx, 0, SIGHASH_ALL, 0, SigVersion::BASE);
286 BOOST_CHECK(coinbaseKey.Sign(hash, vchSig));
287 vchSig.push_back((unsigned char)SIGHASH_ALL);
288 invalid_with_csv_tx.vin[0].scriptSig = CScript() << vchSig << 101;
289
290 ValidateCheckInputsForAllFlags(CTransaction(invalid_with_csv_tx), SCRIPT_VERIFY_CHECKSEQUENCEVERIFY, true, m_node.chainman->ActiveChainstate().CoinsTip(), m_node.chainman->m_validation_cache);
291
292 // Make it valid, and check again
293 invalid_with_csv_tx.vin[0].scriptSig = CScript() << vchSig << 100;
294 TxValidationState state;
296 BOOST_CHECK(CheckInputScripts(CTransaction(invalid_with_csv_tx), state, &m_node.chainman->ActiveChainstate().CoinsTip(), SCRIPT_VERIFY_CHECKSEQUENCEVERIFY, true, true, txdata, m_node.chainman->m_validation_cache, nullptr));
297 }
298
299 // TODO: add tests for remaining script flags
300
301 // Test that passing CheckInputScripts with a valid witness doesn't imply success
302 // for the same tx with a different witness.
303 {
304 CMutableTransaction valid_with_witness_tx;
305 valid_with_witness_tx.version = 1;
306 valid_with_witness_tx.vin = {CTxIn{spend_tx.GetHash(), 1}};
307 valid_with_witness_tx.vout = {CTxOut{11*CENT, p2pk_scriptPubKey}};
308
309 // Sign
310 SignatureData sigdata;
311 BOOST_CHECK(ProduceSignature(keystore, MutableTransactionSignatureCreator(valid_with_witness_tx, 0, 11 * CENT, {.sighash_type = SIGHASH_DEFAULT}), spend_tx.vout[1].scriptPubKey, sigdata));
312 UpdateInput(valid_with_witness_tx.vin[0], sigdata);
313
314 // This should be valid under all script flags.
315 ValidateCheckInputsForAllFlags(CTransaction(valid_with_witness_tx), 0, true, m_node.chainman->ActiveChainstate().CoinsTip(), m_node.chainman->m_validation_cache);
316
317 // Remove the witness, and check that it is now invalid.
318 valid_with_witness_tx.vin[0].scriptWitness.SetNull();
319 ValidateCheckInputsForAllFlags(CTransaction(valid_with_witness_tx), SCRIPT_VERIFY_WITNESS, true, m_node.chainman->ActiveChainstate().CoinsTip(), m_node.chainman->m_validation_cache);
320 }
321
322 // Test a Taproot (witness v1) key-path spend, to exercise the Schnorr branch of the signature cache.
323 {
325 tr_tx.vin = {CTxIn{spend_tx.GetHash(), 4}};
326 tr_tx.vout = {CTxOut{11*CENT, p2pk_scriptPubKey}};
327
328 // Sign P2TR output for key-path spending (i.e. add Schnorr signature to witness stack)
329 FlatSigningProvider tr_keystore;
330 tr_keystore.keys.emplace(coinbaseKey.GetPubKey().GetID(), coinbaseKey);
331 const std::map<COutPoint, Coin> coins{
332 {tr_tx.vin[0].prevout, Coin(spend_tx.vout[4], /*nHeightIn=*/0, /*fCoinBaseIn=*/false)}
333 };
334 std::map<int, bilingual_str> input_errors;
335 BOOST_REQUIRE(SignTransaction(tr_tx, &tr_keystore, coins, {.sighash_type = SIGHASH_DEFAULT}, input_errors));
336 auto& witness_stack = tr_tx.vin[0].scriptWitness.stack;
337 BOOST_REQUIRE(witness_stack.size() == 1 && witness_stack[0].size() == 64);
338
339 // Invalidate signature; an invalid Taproot key-path spend is only invalid if SCRIPT_VERIFY_TAPROOT is set
340 witness_stack[0][63] ^= 0x01; // damage signature
341 ValidateCheckInputsForAllFlags(CTransaction(tr_tx), SCRIPT_VERIFY_TAPROOT, true, m_node.chainman->ActiveChainstate().CoinsTip(), m_node.chainman->m_validation_cache);
342 witness_stack[0][63] ^= 0x01; // repair signature
343
344 // A valid Taproot key-path spend is valid under all flags
345 ValidateCheckInputsForAllFlags(CTransaction(tr_tx), 0, true, m_node.chainman->ActiveChainstate().CoinsTip(), m_node.chainman->m_validation_cache);
346 }
347
348 {
349 // Test a transaction with multiple inputs.
351
352 tx.version = 1;
353 tx.vin = {
354 CTxIn{spend_tx.GetHash(), 0},
355 CTxIn{spend_tx.GetHash(), 1},
356 };
357 tx.vout = {CTxOut{22*CENT, p2pk_scriptPubKey}};
358
359 // Sign
360 for (int i = 0; i < 2; ++i) {
361 SignatureData sigdata;
362 BOOST_CHECK(ProduceSignature(keystore, MutableTransactionSignatureCreator(tx, i, 11 * CENT, {.sighash_type = SIGHASH_DEFAULT}), spend_tx.vout[i].scriptPubKey, sigdata));
363 UpdateInput(tx.vin[i], sigdata);
364 }
365
366 // This should be valid under all script flags
367 ValidateCheckInputsForAllFlags(CTransaction(tx), 0, true, m_node.chainman->ActiveChainstate().CoinsTip(), m_node.chainman->m_validation_cache);
368
369 // Check that if the second input is invalid, but the first input is
370 // valid, the transaction is not cached.
371 // Invalidate vin[1]
372 tx.vin[1].scriptWitness.SetNull();
373
374 TxValidationState state;
376 // This transaction is now invalid under segwit, because of the second input.
377 BOOST_CHECK(!CheckInputScripts(CTransaction(tx), state, &m_node.chainman->ActiveChainstate().CoinsTip(), SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_WITNESS, true, true, txdata, m_node.chainman->m_validation_cache, nullptr));
378
379 std::vector<CScriptCheck> scriptchecks;
380 // Make sure this transaction was not cached (ie because the first
381 // input was valid)
382 BOOST_CHECK(CheckInputScripts(CTransaction(tx), state, &m_node.chainman->ActiveChainstate().CoinsTip(), SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_WITNESS, true, true, txdata, m_node.chainman->m_validation_cache, &scriptchecks));
383 // Should get 2 script checks back -- caching is on a whole-transaction basis.
384 BOOST_CHECK_EQUAL(scriptchecks.size(), 2U);
385 }
386}
387
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
int ret
node::NodeContext m_node
Definition: bitcoin-gui.cpp:48
int flags
Definition: bitcoin-tx.cpp:530
ChainType
Definition: chaintype.h:12
uint256 GetHash() const
Definition: block.cpp:14
Definition: block.h:74
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Definition: coins.h:437
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:406
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:281
An input of a transaction.
Definition: transaction.h:62
An output of a transaction.
Definition: transaction.h:140
A UTXO entry.
Definition: coins.h:46
Fast randomness source.
Definition: random.h:386
Fillable signing provider that keeps keys in an address->secret map.
virtual bool AddCScript(const CScript &redeemScript)
virtual bool AddKey(const CKey &key)
A signature creator for transactions.
Definition: sign.h:54
I randrange(I range) noexcept
Generate a random integer in the range [0..range), with range > 0.
Definition: random.h:254
Convenience class for initializing and passing the script execution cache and signature cache.
Definition: validation.h:370
iterator begin()
Definition: prevector.h:255
iterator end()
Definition: prevector.h:257
static constexpr script_verify_flags from_int(value_type f)
Definition: verify_flags.h:35
256-bit opaque blob.
Definition: uint256.h:196
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
Definition: cs_main.cpp:8
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EQUAL(headers.FindFirst("key"), "value")
uint256 SignatureHash(const CScript &scriptCode, const T &txTo, unsigned int nIn, int32_t nHashType, const CAmount &amount, SigVersion sigversion, const PrecomputedTransactionData *cache, SigHashCache *sighash_cache)
constexpr script_verify_flags::value_type MAX_SCRIPT_VERIFY_FLAGS
Definition: interpreter.h:160
@ BASE
Bare scripts and BIP16 P2SH-wrapped redeemscripts.
@ SIGHASH_DEFAULT
Taproot only; implied when sighash byte is missing, and equivalent to SIGHASH_ALL.
Definition: interpreter.h:37
@ SIGHASH_ALL
Definition: interpreter.h:32
@ CONFLICT
Removed for conflict with in-block transaction.
#define BOOST_CHECK(expr)
Definition: object.cpp:16
static CTransactionRef MakeTransactionRef(Tx &&txIn)
Definition: transaction.h:404
void SignTransaction(CMutableTransaction &mtx, const SigningProvider *keystore, const std::map< COutPoint, Coin > &coins, const UniValue &hashType, UniValue &result)
Sign a transaction with the given keystore and previous transactions.
@ OP_CHECKSIG
Definition: script.h:191
@ OP_CHECKLOCKTIMEVERIFY
Definition: script.h:198
@ OP_DROP
Definition: script.h:125
@ OP_CHECKSEQUENCEVERIFY
Definition: script.h:200
std::vector< unsigned char > ToByteVector(const T &in)
Definition: script.h:68
constexpr CAmount CENT
Definition: setup_common.h:41
bool ProduceSignature(const SigningProvider &provider, const BaseSignatureCreator &creator, const CScript &fromPubKey, SignatureData &sigdata)
Produce a script signature using a generic signature creator.
Definition: sign.cpp:745
void UpdateInput(CTxIn &input, const SignatureData &data)
Definition: sign.cpp:918
A mutable version of CTransaction.
Definition: transaction.h:358
std::vector< CTxOut > vout
Definition: transaction.h:360
Txid GetHash() const
Compute the hash of this CMutableTransaction.
Definition: transaction.cpp:69
std::vector< CTxIn > vin
Definition: transaction.h:359
std::map< CKeyID, CKey > keys
Validation result for a transaction evaluated by MemPoolAccept (single or package).
Definition: validation.h:134
const ResultType m_result_type
Result type.
Definition: validation.h:143
Testing fixture that pre-creates a 100-block REGTEST-mode block chain.
Definition: setup_common.h:139
std::unique_ptr< CTxMemPool > mempool
Definition: context.h:71
std::unique_ptr< ChainstateManager > chainman
Definition: context.h:76
#define LOCK(cs)
Definition: sync.h:268
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
Definition: sync.h:299
static int count
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:49
static void ValidateCheckInputsForAllFlags(const CTransaction &tx, script_verify_flags failing_flags, bool add_to_cache, CCoinsViewCache &active_coins_tip, ValidationCache &validation_cache) EXCLUSIVE_LOCKS_REQUIRED(
BOOST_FIXTURE_TEST_CASE(tx_mempool_block_doublespend, Dersig100Setup)
bool CheckInputScripts(const CTransaction &tx, TxValidationState &state, const CCoinsViewCache &inputs, script_verify_flags flags, bool cacheSigStore, bool cacheFullScriptStore, PrecomputedTransactionData &txdata, ValidationCache &validation_cache, std::vector< CScriptCheck > *pvChecks) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Check whether all of this transaction's input scripts succeed.