Merge bitcoin/bitcoin#33252: p2p: add DifferenceFormatter fuzz target and invariant check

65a10fc3c5 p2p: add assertion for BlockTransactionsRequest indexes (frankomosh)
58be359f6b fuzz: add a target for DifferenceFormatter Class (frankomosh)

Pull request description:

  Adds a fuzz test for the [`DifferenceFormatter`](e3f416dbf7/src/blockencodings.h (L22-L42)) (used in [`BlockTransactionsRequest`](https://github.com/bitcoin/bitcoin/blob/master/src/blockencodings.h#L44-L54), [BIP 152](https://github.com/bitcoin/bips/blob/master/bip-0152.mediawiki)). The DifferenceFormatter class implements differential encoding for compact block transactions (BIP 152). This PR ensures that its strictly-monotonic property is maintained. It complements the tests in [`blocktransactionsrequest_deserialize`](9703b7e6d5/src/test/fuzz/deserialize.cpp (L314)).

  Additionally, there's an added invariant check after GETBLOCKTXN deserialization in `net_processing.cpp`.

ACKs for top commit:
  Crypt-iQ:
    tACK 65a10fc3c5
  achow101:
    ACK 65a10fc3c5
  dergoegge:
    Code review ACK 65a10fc3c5

Tree-SHA512: 70659cf045e99bb5f753763c7ddac094cb2883c202c899276cbe616889afa053b2d5e831f99d6386d4d1e4118cd35fa0b14b54667853fe067f6efe2eb77b4097
This commit is contained in:
Ava Chow
2025-10-24 10:12:11 -07:00
3 changed files with 38 additions and 0 deletions

View File

@@ -4118,6 +4118,11 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
if (msg_type == NetMsgType::GETBLOCKTXN) {
BlockTransactionsRequest req;
vRecv >> req;
// Verify differential encoding invariant: indexes must be strictly increasing
// DifferenceFormatter should guarantee this property during deserialization
for (size_t i = 1; i < req.indexes.size(); ++i) {
Assume(req.indexes[i] > req.indexes[i-1]);
}
std::shared_ptr<const CBlock> recent_block;
{