p2p: Use separate compact block nonce per network #36955

Open
mzumsande wants to merge 1 commit from 202611_cb_fingerprint into master AGit
mzumsande commented 2026-11-23 17:36:21 +00:00 (Migrated from github.com)

This issue was reported by ajtowns on IRC some time ago.

For compact blocks, when we serve the last compact block from cache, we use a single nonce for all peers currently.
This means anyone can request the most recent tip as a compact block via getdata(MSG_CMPCT_BLOCK) over a clearnet and a tor connection and then compare the nonces - if they match it's the same node.

Fix this by using a different nonce per network/bind (CNode::m_network_key).
This means a little bit more work in NewPoWValidBlock where we will now create CBlockHeaderAndShortTxIDs objects for each network on which a peer has made us their hb peer. More instances may be created later when serving non-hb peers via GETDATA. Note that while on master, the CBlockHeaderAndShortTxIDs was created eagerly, and its serialization lazily, we now create both objects lazily.

From a high-level point of view, there are various remaining fingerprinting vectors even with this fix, some hard to fix, but I do think that we should be fixing at least the most obvious ones.

This issue was reported by ajtowns on IRC some time ago. For compact blocks, when we serve the last compact block from cache, we use a single nonce for all peers currently. This means anyone can request the most recent tip as a compact block via `getdata(MSG_CMPCT_BLOCK)` over a clearnet and a tor connection and then compare the nonces - if they match it's the same node. Fix this by using a different nonce per network/bind (`CNode::m_network_key`). This means a little bit more work in `NewPoWValidBlock` where we will now create `CBlockHeaderAndShortTxIDs` objects for each network on which a peer has made us their hb peer. More instances may be created later when serving non-hb peers via `GETDATA`. Note that while on master, the `CBlockHeaderAndShortTxIDs` was created eagerly, and its serialization lazily, we now create both objects lazily. From a high-level point of view, there are various remaining fingerprinting vectors even with this fix, some hard to fix, but I do think that we should be fixing at least the most obvious ones.
DrahtBot commented 2026-11-23 17:36:31 +00:00 (Migrated from github.com)

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

External sites

Reviews

See the guideline and AI policy for information on the review process.

Type Reviewers
Concept ACK instagibbs, fjahr, ismaelsadeeq

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #36787 (cmpctblock: Cache serialized cmpctblock msg for relay [part of prefill series] by davidgumberg)
  • #36372 (p2p: replace full outbound peers that don't support tx relay (take 2) by fjahr)
  • #35561 (net: move some CNodeState fields to Peer by Crypt-iQ)
  • #35558 (p2p: Prefill compact blocks by davidgumberg)
  • #35522 (refactor: Extract per-message helpers from SendMessages() (move-only) by pablomartin4btc)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/36955 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36955.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36955#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. | Type | Reviewers | | ---- | --------- | | Concept ACK | [instagibbs](https://github.com/bitcoin/bitcoin/pull/36955#issuecomment-7109863664), [fjahr](https://github.com/bitcoin/bitcoin/pull/36955#issuecomment-7115493199), [ismaelsadeeq](https://github.com/bitcoin/bitcoin/pull/36955#issuecomment-7132665234) | If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore. <!--174a7506f384e20aa4161008e828411d--> ### Conflicts Reviewers, this pull request conflicts with the following ones: * [#36787](https://github.com/bitcoin/bitcoin/pull/36787) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36787.svg"></sub> (cmpctblock: Cache serialized cmpctblock msg for relay [part of prefill series] by davidgumberg) * [#36372](https://github.com/bitcoin/bitcoin/pull/36372) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36372.svg"></sub> (p2p: replace full outbound peers that don't support tx relay (take 2) by fjahr) * [#35561](https://github.com/bitcoin/bitcoin/pull/35561) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35561.svg"></sub> (net: move some CNodeState fields to Peer by Crypt-iQ) * [#35558](https://github.com/bitcoin/bitcoin/pull/35558) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35558.svg"></sub> (p2p: Prefill compact blocks by davidgumberg) * [#35522](https://github.com/bitcoin/bitcoin/pull/35522) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35522.svg"></sub> (refactor: Extract per-message helpers from SendMessages() (move-only) by pablomartin4btc) If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. <!--5faf32d7da4f0f540f40219e4f7537a3-->
instagibbs commented 2026-11-23 18:14:16 +00:00 (Migrated from github.com)

concept ACK

concept ACK
First-time contributor

🔵 Suggestion · Outbound onion connections remain linkable through the cached nonce

Ordinary outbound onion peers sharing a local Tor proxy still receive the same cached tip nonce, preserving pre-existing linkage between those connections even though this PR separates networks.

Location: src/net_processing.cpp:2234 (head).

🔵 Suggestion · The new nonce test leaves the SendMessages lookup unchecked

A wrong network key confined to the changed SendMessages compact-block lookup would leave all new nonce assertions passing.

Location: src/net_processing.cpp:6257 (head).

Review coverage was incomplete.


Reviewed: ee20048dda7f · Review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:155929f7ce9143494f69bf908ed23fe132d4051ff090b4c8655aba8e5ddfc5d2:1f24a658028970752593279d1bd02789c26badbd714483fb933d9c079e9b6c5c --> <!-- ralph-base:dbe9eacd17ae1cc24581081613123a40b44a9f31 --> <!-- ralph-head:ee20048dda7fc2e69f02e67c1527cc52da10f5fd --> <!-- ralph-case:0db046dd771ac549180160ca638b7bd8a0e95125c3bc4daba591a149d630c02b --> **🔵 Suggestion · Outbound onion connections remain linkable through the cached nonce** Ordinary outbound onion peers sharing a local Tor proxy still receive the same cached tip nonce, preserving pre-existing linkage between those connections even though this PR separates networks. Location: [`src/net_processing.cpp:2234`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/ee20048dda7fc2e69f02e67c1527cc52da10f5fd/src/net_processing.cpp#L2234>) (head). **🔵 Suggestion · The new nonce test leaves the `SendMessages` lookup unchecked** A wrong network key confined to the changed `SendMessages` compact-block lookup would leave all new nonce assertions passing. Location: [`src/net_processing.cpp:6257`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/ee20048dda7fc2e69f02e67c1527cc52da10f5fd/src/net_processing.cpp#L6257>) (head). Review coverage was incomplete. <!-- Review tier: sensitive --> --- Reviewed: [`ee20048dda7f`](<https://git.fish.foo/bitcoin/bitcoin/commit/ee20048dda7fc2e69f02e67c1527cc52da10f5fd>) · [Review report](<https://review.fish.foo/report/36955-ee20048dda7fc2e69f02e67c1527cc52da10f5fd-3006-1.html>) · [Previous reports](<https://review.fish.foo/traces/36955/>) [permalink](<https://review.fish.foo/report/36955-ee20048dda7fc2e69f02e67c1527cc52da10f5fd-3006-1.html>)
mzumsande commented 2026-11-23 18:26:24 +00:00 (Migrated from github.com)

The Ralph comment reminds me of an old conversation:
https://github.com/bitcoin/bitcoin/pull/33464#pullrequestreview-3813897610

As a follow-up, I think we can give every outbound onion connection a separate network_id, because they all look distinct to external observers.

Just to add this info also here for others reading this: this is not helpful because both current functions of network_id, inv scheduling and getaddr caching, do not apply to outbounds anyway (https://github.com/bitcoin/bitcoin/pull/34456). If we use network_id for additional things in the future, we could revisit.

So maybe we should revisit it with this PR, which also affects outbounds?

The Ralph comment reminds me of an old conversation: https://github.com/bitcoin/bitcoin/pull/33464#pullrequestreview-3813897610 >> As a follow-up, I think we can give every outbound onion connection a separate network_id, because they all look distinct to external observers. >Just to add this info also here for others reading this: this is not helpful because both current functions of network_id, inv scheduling and getaddr caching, do not apply to outbounds anyway (https://github.com/bitcoin/bitcoin/pull/34456). If we use network_id for additional things in the future, we could revisit. So maybe we should revisit it with this PR, which also affects outbounds?
fjahr commented 2026-11-23 22:13:54 +00:00 (Migrated from github.com)

Concept ACK

Concept ACK
ismaelsadeeq commented 2026-11-24 13:19:26 +00:00 (Migrated from github.com)

Concept ACK

Concept ACK
0xB10C commented 2026-12-04 04:30:33 +00:00 (Migrated from github.com)

@davidgumberg how would this work together with prefilling?

@davidgumberg how would this work together with prefilling?
mzumsande (Migrated from github.com) reviewed 2026-12-04 11:44:19 +00:00
mzumsande (Migrated from github.com) left a comment

Good point, I didn't think about #35558 when opening this PR. I don't think they are mutually exclusive (we could have the prefilled blocks cache keyed by network), but prefilling would introduce a different fingerprint vector, albeit weaker than the nonce.
I'm not sure how much prefilled blocks would differ among nodes, but even if it turned out to be significant, there could be various possible strategies to avoid it.

But also, I'm not sure how important or useful it is to prefill blocks on privacy networks in the first place:
As far as I can see, the TCP window reasoning of #35558 may not apply when the queried CNode::m_sock is not the connection to the peer but the local proxy/damon. Has this been tested?
In addition, Tor and I2p are probably not on the critical path for network-wide propagation/selfish mining issues anyway.

Good point, I didn't think about #35558 when opening this PR. I don't think they are mutually exclusive (we could have the prefilled blocks cache keyed by network), but prefilling would introduce a different fingerprint vector, albeit weaker than the nonce. I'm not sure how much prefilled blocks would differ among nodes, but even if it turned out to be significant, there could be various possible strategies to avoid it. But also, I'm not sure how important or useful it is to prefill blocks on privacy networks in the first place: As far as I can see, the TCP window reasoning of #35558 may not apply when the queried `CNode::m_sock` is not the connection to the peer but the local proxy/damon. Has this been tested? In addition, Tor and I2p are probably not on the critical path for network-wide propagation/selfish mining issues anyway.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!36955
No description provided.