aboutsummaryrefslogtreecommitdiff
path: root/src/net_processing.cpp
diff options
context:
space:
mode:
authordergoegge <n.goeggi@gmail.com>2024-01-19 15:25:01 +0000
committerdergoegge <n.goeggi@gmail.com>2024-02-27 14:19:15 +0000
commit49257c0304828a185c273fcb99742c54bbef0c8e (patch)
tree3ef73740943a30c34e01a3ab95cea8ef93e9d86c /src/net_processing.cpp
parent2d8495e0800f5332748cd50eaad801ff77671bba (diff)
[net processing] Don't process mutated blocks
We preemptively perform a block mutation check before further processing a block message (similar to early sanity checks on other messsage types). The main reasons for this change are as follows: - `CBlock::GetHash()` is a foot-gun without a prior mutation check, as the hash returned only commits to the header but not to the actual transactions (`CBlock::vtx`) contained in the block. - We have observed attacks that abused mutated blocks in the past, which could have been prevented by simply not processing mutated blocks (e.g. https://github.com/bitcoin/bitcoin/pull/27608).
Diffstat (limited to 'src/net_processing.cpp')
-rw-r--r--src/net_processing.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index c8da927763..5c3ec5f700 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -4719,6 +4719,16 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
LogPrint(BCLog::NET, "received block %s peer=%d\n", pblock->GetHash().ToString(), pfrom.GetId());
+ const CBlockIndex* prev_block{WITH_LOCK(m_chainman.GetMutex(), return m_chainman.m_blockman.LookupBlockIndex(pblock->hashPrevBlock))};
+
+ if (IsBlockMutated(/*block=*/*pblock,
+ /*check_witness_root=*/DeploymentActiveAfter(prev_block, m_chainman, Consensus::DEPLOYMENT_SEGWIT))) {
+ LogDebug(BCLog::NET, "Received mutated block from peer=%d\n", peer->m_id);
+ Misbehaving(*peer, 100, "mutated block");
+ WITH_LOCK(cs_main, RemoveBlockRequest(pblock->GetHash(), peer->m_id));
+ return;
+ }
+
bool forceProcessing = false;
const uint256 hash(pblock->GetHash());
bool min_pow_checked = false;
@@ -4734,7 +4744,6 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
mapBlockSource.emplace(hash, std::make_pair(pfrom.GetId(), true));
// Check work on this block against our anti-dos thresholds.
- const CBlockIndex* prev_block = m_chainman.m_blockman.LookupBlockIndex(pblock->hashPrevBlock);
if (prev_block && prev_block->nChainWork + CalculateHeadersWork({pblock->GetBlockHeader()}) >= GetAntiDoSWorkThreshold()) {
min_pow_checked = true;
}