Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
252BOOST_AUTO_TEST_CASE(merkle_test_BlockWitness)253{254CBlock block;256constexpr size_t vtx_count{3};257block.vtx.resize(vtx_count);258for (std::size_t pos = 0; pos < vtx_count; pos++) {259CMutableTransaction mtx;260mtx.nLockTime = pos;261block.vtx[pos] = MakeTransactionRef(std::move(mtx));262}264uint256 blockWitness = BlockWitnessMerkleRoot(block);266std::vector<uint256> hashes;267hashes.resize(vtx_count); // Odd count exercises leaf duplication in ComputeMerkleRoot (which can append one extra hash).268hashes[0] = uint256::ZERO; // The witness hash of the coinbase is 0.269for (size_t pos{1}; pos < vtx_count; ++pos) {270hashes[pos] = block.vtx[pos]->GetWitnessHash().ToUint256();271}273uint256 merkleRootofHashes = ComputeMerkleRoot(hashes);274BOOST_CHECK_EQUAL(merkleRootofHashes, blockWitness);275}276BOOST_AUTO_TEST_SUITE_END()
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.