HomePhabricator

p2p: Don't process mutated blocks

Description

p2p: Don't process mutated blocks

Summary:

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).

PR description

This PR proposes to check for mutated blocks early as a defense-in-depth mitigation against attacks leveraging mutated blocks.

We introduce IsBlockMutated which catches all known forms of block malleation and use it to do an early mutation check whenever we receive a block message.

We have observed attacks that abused mutated blocks in the past, which could have been prevented by simply not processing mutated blocks (e.g. #27608 for which a regression test is included in this PR).

This concludes backport of core#29412
https://github.com/bitcoin/bitcoin/pull/29412/commits/95bddb930aa72edd40fdff52cf447202995b0dce
https://github.com/bitcoin/bitcoin/pull/29412/commits/e7669e1343aec4298fd30d539847963e6fa5619c
https://github.com/bitcoin/bitcoin/pull/29412/commits/66abce1d98115e41f394bc4f4f52341960ddc839
https://github.com/bitcoin/bitcoin/pull/29412/commits/2d8495e0800f5332748cd50eaad801ff77671bba
https://github.com/bitcoin/bitcoin/pull/29412/commits/49257c0304828a185c273fcb99742c54bbef0c8e
https://github.com/bitcoin/bitcoin/pull/29412/commits/1ec6bbeb8d27d31647d1433ccb87b362f6d81f90
https://github.com/bitcoin/bitcoin/pull/29412/commits/d8087adc7ebd4ea05dd3843e5a92e8115fd7bbcc

Depends on D18005

Test Plan: ninja all check-all

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Subscribers: Fabien

Differential Revision: https://reviews.bitcoinabc.org/D18006

Details

Provenance
dergoegge <n.goeggi@gmail.com>Authored on Jan 19 2024, 11:49
PiRKCommitted on Tue, Apr 29, 19:32
PiRKPushed on Tue, Apr 29, 19:32
Reviewer
Restricted Project
Differential Revision
Restricted Differential Revision
Parents
rABC000c4a025a4d: [test] Add regression test for D16879
Branches
Unknown
Tags
Unknown

Event Timeline

PiRK added an edge: Restricted Differential Revision.