| 4035 | } |
| 4036 | |
| 4037 | bool 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 | |
| 4068 | arith_uint256 CalculateClaimedHeadersWork(std::span<const CBlockHeader> headers) |
| 4069 | { |