[validation] Introduce IsBlockMutated
This commit is contained in:
1 parent
e7669e1343
commit
66abce1d98
2 files changed
+23
No files matched your search
@@ -3824,6 +3824,26 @@ bool HasValidProofOfWork(const std::vector<CBlockHeader>& headers, const Consens
|
|||||||
[&](const auto& header) { return CheckProofOfWork(header.GetHash(), header.nBits, consensusParams);});
|
[&](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)) {
|
||||||
|
LogDebug(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)) {
|
||||||
|
LogDebug(BCLog::VALIDATION, "Block mutated: %s\n", state.ToString());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
arith_uint256 CalculateHeadersWork(const std::vector<CBlockHeader>& headers)
|
arith_uint256 CalculateHeadersWork(const std::vector<CBlockHeader>& headers)
|
||||||
{
|
{
|
||||||
arith_uint256 total_work{0};
|
arith_uint256 total_work{0};
|
||||||
|
|||||||
@@ -383,6 +383,9 @@ bool TestBlockValidity(BlockValidationState& state,
|
|||||||
/** Check with the proof of work on each blockheader matches the value in nBits */
|
/** 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);
|
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 */
|
/** Return the sum of the work on a given set of headers */
|
||||||
arith_uint256 CalculateHeadersWork(const std::vector<CBlockHeader>& headers);
|
arith_uint256 CalculateHeadersWork(const std::vector<CBlockHeader>& headers);
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user