MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / IsBlockMutated

Function IsBlockMutated

src/validation.cpp:4037–4066  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4035}
4036
4037bool IsBlockMutated(const CBlock& block, bool check_witness_root)
4038{
4039 BlockValidationState state;
4040 if (!CheckMerkleRoot(block, state)) {
4041 LogDebug(BCLog::VALIDATION, "Block mutated: %s\n", state.ToString());
4042 return true;
4043 }
4044
4045 if (block.vtx.empty() || !block.vtx[0]->IsCoinBase()) {
4046 // Consider the block mutated if any transaction is 64 bytes in size (see 3.1
4047 // in "Weaknesses in Bitcoin’s Merkle Root Construction":
4048 // https://lists.linuxfoundation.org/pipermail/bitcoin-dev/attachments/20190225/a27d8837/attachment-0001.pdf).
4049 //
4050 // Note: This is not a consensus change as this only applies to blocks that
4051 // don't have a coinbase transaction and would therefore already be invalid.
4052 return std::any_of(block.vtx.begin(), block.vtx.end(),
4053 [](auto& tx) { return GetSerializeSize(TX_NO_WITNESS(tx)) == 64; });
4054 } else {
4055 // Theoretically it is still possible for a block with a 64 byte
4056 // coinbase transaction to be mutated but we neglect that possibility
4057 // here as it requires at least 224 bits of work.
4058 }
4059
4060 if (!CheckWitnessMalleation(block, check_witness_root, state)) {
4061 LogDebug(BCLog::VALIDATION, "Block mutated: %s\n", state.ToString());
4062 return true;
4063 }
4064
4065 return false;
4066}
4067
4068arith_uint256 CalculateClaimedHeadersWork(std::span<const CBlockHeader> headers)
4069{

Callers 2

ProcessMessageMethod · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85

Calls 9

CheckMerkleRootFunction · 0.85
any_ofClass · 0.85
GetSerializeSizeFunction · 0.85
CheckWitnessMalleationFunction · 0.85
ToStringMethod · 0.45
emptyMethod · 0.45
IsCoinBaseMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by 1

BOOST_AUTO_TEST_CASEFunction · 0.68