| 13 | |
| 14 | |
| 15 | static void DuplicateInputs(benchmark::Bench& bench) |
| 16 | { |
| 17 | const auto testing_setup = MakeNoLogFileContext<const TestingSetup>(); |
| 18 | |
| 19 | const CScript SCRIPT_PUB{CScript(OP_TRUE)}; |
| 20 | |
| 21 | const CChainParams& chainparams = Params(); |
| 22 | |
| 23 | CBlock block{}; |
| 24 | CMutableTransaction coinbaseTx{}; |
| 25 | CMutableTransaction naughtyTx{}; |
| 26 | |
| 27 | LOCK(cs_main); |
| 28 | CBlockIndex* pindexPrev = testing_setup->m_node.chainman->ActiveChain().Tip(); |
| 29 | assert(pindexPrev != nullptr); |
| 30 | block.nBits = GetNextWorkRequired(pindexPrev, &block, chainparams.GetConsensus()); |
| 31 | block.nNonce = 0; |
| 32 | auto nHeight = pindexPrev->nHeight + 1; |
| 33 | |
| 34 | // Make a coinbase TX |
| 35 | coinbaseTx.vin.resize(1); |
| 36 | coinbaseTx.vin[0].prevout.SetNull(); |
| 37 | coinbaseTx.vout.resize(1); |
| 38 | coinbaseTx.vout[0].scriptPubKey = SCRIPT_PUB; |
| 39 | coinbaseTx.vout[0].nValue = GetBlockSubsidy(nHeight, chainparams.GetConsensus()); |
| 40 | coinbaseTx.vin[0].scriptSig = CScript() << nHeight << OP_0; |
| 41 | |
| 42 | |
| 43 | naughtyTx.vout.resize(1); |
| 44 | naughtyTx.vout[0].nValue = 0; |
| 45 | naughtyTx.vout[0].scriptPubKey = SCRIPT_PUB; |
| 46 | |
| 47 | uint64_t n_inputs = (((MAX_BLOCK_SERIALIZED_SIZE / WITNESS_SCALE_FACTOR) - (CTransaction(coinbaseTx).GetTotalSize() + CTransaction(naughtyTx).GetTotalSize())) / 41) - 100; |
| 48 | for (uint64_t x = 0; x < (n_inputs - 1); ++x) { |
| 49 | naughtyTx.vin.emplace_back(GetRandHash(), 0, CScript(), 0); |
| 50 | } |
| 51 | naughtyTx.vin.emplace_back(naughtyTx.vin.back()); |
| 52 | |
| 53 | block.vtx.push_back(MakeTransactionRef(std::move(coinbaseTx))); |
| 54 | block.vtx.push_back(MakeTransactionRef(std::move(naughtyTx))); |
| 55 | |
| 56 | block.hashMerkleRoot = BlockMerkleRoot(block); |
| 57 | |
| 58 | bench.run([&] { |
| 59 | BlockValidationState cvstate{}; |
| 60 | assert(!CheckBlock(block, cvstate, chainparams.GetConsensus(), false, false)); |
| 61 | assert(cvstate.GetRejectReason() == "bad-txns-inputs-duplicate"); |
| 62 | }); |
| 63 | } |
| 64 | |
| 65 | BENCHMARK(DuplicateInputs); |
nothing calls this directly
no test coverage detected