p2p: add assertion for BlockTransactionsRequest indexes
What changed, and why it matters
This commit adds a safety check in Bitcoin Core's network message handling for a specific message type (GETBLOCKTXN). After reading the message, it verifies that a list of transaction indexes is strictly increasing. This is a defensive coding change: it does not fix a known exploit, but adds an assertion to catch invariant violations that could theoretically lead to incorrect behavior or crashes in compact block reconstruction. The change is small and uses the non-fatal Assume() macro, meaning a violation in release builds may not necessarily stop execution.
No immediate action required. Treat as routine hardening. Review whether Assume() is sufficient or whether a malformed index sequence should trigger peer disconnection or request rejection, given that an invariant violation could indicate a deserialization bug or malicious input.
Security signals we found
Defensive invariant check added after deserialization
Compact block transaction index ordering validation
Use of Assume() rather than fatal error handling
Evidence from the diff
In PeerManagerImpl::ProcessMessage for NetMsgType::GETBLOCKTXN, after deserializing a BlockTransactionsRequest, the patch loops through req.indexes and calls Assume(req.indexes[i] > req.indexes[i-1]). This validates the differential encoding invariant that DifferenceFormatter is supposed to enforce during deserialization. Assume() is a non-fatal assertion macro used in Bitcoin Core for sanity checks; in release builds it typically logs or does nothing, while in debug builds it may assert. The commit does not change protocol behavior, parsing logic, or add new validation rules visible to peers.
Changed components
src/net_processing.cppGETBLOCKTXN message handlingBlockTransactionsRequest deserializationCompact block relay (BIP 152)Inspect captured patch +5 / −0
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index 5e0651aa..b26abab8 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -4135,6 +4135,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;
{
Why this scored 27/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.