mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-10 03:47:29 -03:00
[validation] Introduce IsBlockMutated
Github-Pull: #29412
Rebased-From: 66abce1d98
This commit is contained in:
parent
4f5baac6ca
commit
8804c368f5
2 changed files with 23 additions and 0 deletions
|
@ -3644,6 +3644,26 @@ bool HasValidProofOfWork(const std::vector<CBlockHeader>& headers, const Consens
|
|||
[&](const auto& header) { return CheckProofOfWork(header.GetHash(), header.nBits, consensusParams);});
|
||||
}
|
||||
|
||||
bool IsBlockMutated(const CBlock& block, bool check_witness_root)
|
||||
{
|
||||
BlockValidationState state;
|
||||
if (!CheckMerkleRoot(block, state)) {
|
||||
LogPrint(BCLog::VALIDATION, "Block mutated: %s\n", state.ToString());
|
||||
return true;
|
||||
}
|
||||
|
||||
if (block.vtx.empty() || !block.vtx[0]->IsCoinBase()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!CheckWitnessMalleation(block, check_witness_root, state)) {
|
||||
LogPrint(BCLog::VALIDATION, "Block mutated: %s\n", state.ToString());
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
arith_uint256 CalculateHeadersWork(const std::vector<CBlockHeader>& headers)
|
||||
{
|
||||
arith_uint256 total_work{0};
|
||||
|
|
|
@ -352,6 +352,9 @@ bool TestBlockValidity(BlockValidationState& state,
|
|||
/** Check with the proof of work on each blockheader matches the value in nBits */
|
||||
bool HasValidProofOfWork(const std::vector<CBlockHeader>& headers, const Consensus::Params& consensusParams);
|
||||
|
||||
/** Check if a block has been mutated (with respect to its merkle root and witness commitments). */
|
||||
bool IsBlockMutated(const CBlock& block, bool check_witness_root);
|
||||
|
||||
/** Return the sum of the work on a given set of headers */
|
||||
arith_uint256 CalculateHeadersWork(const std::vector<CBlockHeader>& headers);
|
||||
|
||||
|
|
Loading…
Reference in a new issue