mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 16:02:38 +00:00
net: don’t self advertise tor exit node ip addresses in outbound connections #35578
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!35578
Loading…
Reference in a new issue
No description provided.
Delete branch "2026-05-self-adv-tor-exit"
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?
GetLocalAddrFromPeer- we advertise the "IP address we think we are" and sometimes replace it with what "IP address the peer thinks we are".Example: when a node running both Tor and clearnet via a SOCKS5 proxy connects to a clearnet peer (
proxy=127.0.0.1:9050, listen=1, discover=1(or)onion=127.0.0.1:9050), the "IP address the peer thinks we are" is the Tor exit node's IP address and doesn't make sense to relay it. 55-76% of all tor exit nodes were present in various addrman snapshots I checked (my node and the ones from b10c’s peer.observer) from now and few years ago. would be nice to not unnecessarily relay these tor exit IPs since they end up being stored as fresh and gossiped from multiple sources entries in our addrman.an advanced node runner might have a proxy whose ip address is also a reachable inbound address. I've personally not used such a proxy but 1 difference for them is that they'd need to explicitly set
-externalip=<addr>to self-advertise their proxy address. i feel it’s an acceptable tradeoff and would imagine they are already using-externalip=<addr>config flag as they are explicitly managing their node's public address.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
No conflicts as of last run.
Concept ACK, it makes sense to me to not advertise an address we know we can't be reached on. I think this is the case when using
-proxy, as we specifically say "make outbound connections through this SOCKS5" but don't expect inbound connections via this socket. There seems to be something calledBIND-request for SOCKS5 proxies, but I don't think that's widely supported (and not implemented in Bitcoin Core).I've looked at the number of connections my nodes make to Tor exit node IPs in this post: In mid 2026, my nodes each make between 7.5 to 12.5 connection attempts per day to Tor exit node IPs.
While nearly all of these connection attempts fail (as expected), there's about 20 IPs where I've seen some connections to Tor exit node IPs succeed over the last years. I assume these are hosts that run (or ran at some point) a Tor exit node and a Bitcoin node, which isn't too unexpected.
Hm are we sure this is being used like this? With just
-proxyset, we wouldn't be listening and not self-announcing.github.com/bitcoin/bitcoin@93012d7ff9/src/init.cpp (L812-L825)github.com/bitcoin/bitcoin@93012d7ff9/src/net_processing.cpp (L5475-L5476)good point. it's either this or people using
onion=127.0.0.1:9050.even though there is the soft-set init parameter interactions which does
proxy=127.0.0.1:9050->listen=0anddiscover=0- I wouldn't be surprised if people end up overriding it.listen=1is overriden to allow inbound connections without having to deal with the clearnet firewall rules. I've seen/done this a lot.discover=1and its interaction with other parameters can be confusing to users. It makes a node's own IP discoverable to peers (the node advertises it). That IP is obtained from the node's own machine, and (less obviously) also from what peers report the node's address to be.-externalip=<ip>can be used (keeping the soft-setdiscover=0) - the node then advertises only the address we specified inexternalip, and not the peer-reported view of a node's IP.-externalip=<ip>is used with explicitdiscover=1override in the bitcoin.conf then again the peer-report view of a node's ip can be advertised.quick GitHub search shows
proxy=127.0.0.1:9050, listen=1, discover=1use here and here. unsure if it's common/rare/how many people use it like this though.Concept ACK
It makes sense not to advertise these addresses, as they are not useful.
i used this list https://check.torproject.org/torbulkexitlist to check for tor exit nodes.
On master, I noticed that sometimes clearnet outbound peers would send me their own addresses as my address, and I would occasionally self-advertise those same addresses back to them. I think this PR fixes that only for proxy, but maybe we should also add check so that a peer does not send us their own address.
tested
412aa3d1fdwithlisten=1 proxy=127.0.0.1:9050 discover=1My logs show that even when the score flip favoured the peers reported address for an outbound clearnet (tor_proxied ) peer , we do not advertise it , instead we now always fallback to advertising our own adress that we know.
Logs
Maybe add a comment? to explain a bit on why there's a proxy check here
An alternative approach would be to check whether an outbound connection is proxied before we even check if
IsPeerAddrLocalGood(), since the result isn't useful if we won't use the address anyway.I think its possible to test this in
net_tests.cppsimilar toget_local_addr_for_peer_portbut using
SetProxy()and verifying that we dont relay what the peer told us.I tried this locally
Concept ACK
I wonder if it is really all explained by misconfigurations, overriding defaults, and if everyone would be running this branch, the exit nodes would stop being relayed.
Maybe it could also due to transparent torification where users do not change any defaults but the traffic is rerouted via tor externally, e.g. by an OS such as Whonix? In that case, the fix might not solve the problem completely.
@stratospher what is the status here? There are a few unaddressed comments.
I don't think this use case would work with this patch. ex: tor exits who are also running bitcoin nodes.
I guess we should mention in the release notes that they now need to explicitly set
externalip=<addr>.@mzumsande good point! I don't think we have a way to know unless we see it in action in the P2P network and this patch obviously won't work for systems running transparent torrification. but we can try to reduce it from core's end when people override defaults.
even though it's not a problem currently, ~95% of the tor exit IPs don't have ports in
p2p-bad-ports.md. some examples: 1031 tor exit IPs on port 443 (I vaguely remember some discussion on 443 being a good option for core as well), 705 tor exit IPs on port 9001, 276 tor exit IPs on port 9002.if we ever switch to non default ports - it might get problematic for the tor exits. so I think it's still good to reduce unnecessary connection attempts to tor exits from our side (this is not an issue currently).
done both in the latest push. thanks!
CI failure is unrelated. could someone start the failed CI job again? thanks!
the latest push adds tests, a comment and a release note.
🔵 Suggestion · A fatal assertion can leave the IPv4 proxy set for later
net_testscasesA failed
BOOST_REQUIREafterSetProxywould skip proxy cleanup and cause secondary failures in later advertisement tests.Location:
src/test/net_tests.cpp:781(head).🔵 Suggestion · Proxy coverage misses unrelated-network configurations
Although production checks the peer's network correctly, the test would also pass a predicate that suppresses peer-observed IPv4 addresses whenever any network has a proxy.
Location:
src/test/net_tests.cpp:759(head).Review coverage was incomplete.
Reviewed:
3c6293a3f537· Review report · Previous reportspermalink
🐙 This pull request conflicts with the target branch and needs rebase.
looks like
b403937was done in https://github.com/bitcoin/bitcoin/pull/36177. I've removed it.🐙 This pull request conflicts with the target branch and needs rebase.