mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 12:20:38 +00:00
net: make address overlap impossible when relaying addresses #36954
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!36954
Loading…
Reference in a new issue
No description provided.
Delete branch "tor_i2p_addr_overlap"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
CService::GetKey()didn't include the network in the output. So in theory it would be possible for two I2P and Tor addresses to have the same output fromCService::GetKey().This would have unexpected results when used in the per-peer bloom filter of known addresses - we may wrongfully assume that a peer knows
foo.onionwhen we have sent to themfoo.i2p.To make this impossible - include the network in
CService::GetKey().Addrman already includes the network separately so it does not need this change. The code would be simplest if addrman also uses
GetKey()with the network but that would mess the positions of addresses in existent databases (peers.dat). So, keep a variant of network-lessGetKey()for addrman.Thanks, l0rinc for pointing me into this. I think it is minor but also the change is minor, so worth fixing IMO.
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.
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:
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.
Earlier concerns neither republished nor resolved: 1 suggestion. See the Run archive linked from the Review report for their assessments.
🔵 Suggestion · Network-inclusive
GetKey()serializes the port twiceThe network-inclusive key carries two redundant port bytes into the relay filter, although uniqueness and legacy addrman placement remain correct.
Location:
src/netaddress.cpp:907(head).🔵 Suggestion · The default
GetKey()obscures the bucketing-key choiceCurrent bucketing is correct, but default
GetKey()now selects the relay format even in addrman tests, obscuring which key each caller intends.Location:
src/netaddress.h:564(head).Reviewed:
6b6bf6fda777· Review report · Previous reportspermalink
Both IPv6 and CJDNS use 16 bytes, so there could be an overlap like with Tor and I2P. The first of those 16 bytes identifies the address as CJDNS. While such an address is also a valid IPv6 address, it is globally unroutable on the public internet.
shouldn't this rather be a
breakand anAssertUnreachable()after the switch for this to be guaranteed exhaustive?There are two things here: 1. values for
m_netthat should never be set and 2. ensure that the switch handles all enum values.For example here there are two asserts to handle each one of 1. and 2.:
github.com/bitcoin/bitcoin@edcac28380/src/netaddress.cpp (L487-L501)and here just 1. is checked:
github.com/bitcoin/bitcoin@edcac28380/src/netaddress.cpp (L111-L136)The new code I added is like in the second example, handling only 1. To handle 2. one must conclude every
casewith areturnso that the assert after the switch becomes unreachable. This is omitted in places where some work has to be done after the switch.If you want to add the assert, it would be possible with a lambda, but up to you:
Cool pattern, I wasn't aware of it. I like it. The surrounding code does not use it though, so for now I will leave it as it is for now.
Concept ACK
I think it would be simpler to reuse the BIP155 serialization here, if there is no requirement for compatibility with the old non-
include_networkformat.This will
assert(false);if used on aNET_INTERNALaddress, so that may still need to be handled separately if that's a possibility.Simpler. Like.
NET_INTERNALworks. No need to handle.github.com/bitcoin/bitcoin@0bc1e88dd3/src/netaddress.h (L376-L390)f5a425dee31eaa93aecbd8d5d7e459207f51937e...6b6bf6fda7777ad430f73a9b07c9c58ebc366eea: rebase, take suggestion to use bip155 serialization and add tests to ensure addrman bucketing rules do not change unintended due toGetKey()changes.I considered including the network unconditionally in
GetKey()to make the code simpler and accept addrman rebucketing. To assess the scale of the rebucketing I took a full addrman'speers.dat:new table: 65512 addresses
tried table: 15259 addresses
after loading that file with unconditional-with-network-GetKey() the collisions resulted in:
new table: 42905 addresses
tried table: 9431 addresses
I assume that this is going to be more or less the same for every full addrman and better with addrmans that have less addresses. I think that is too much, so I leave the option to preserve the bucketing (have network-less-GetKey()).
Done.