One framing of the problem: “Honest nodes are not as reachable as attacker-controlled nodes. This gives attackers an extra advantage when trying to occupy outbound connection slots.”
With that framing, I think having some sort of holepunching would be very valuable. Option 2 seems like a good start, given that the % of nodes advertising a Tor address (already have Tor working) is quite high.
I came up with option 6: coordinator-less hole punching
Every option so far needs a coordinator, because two nodes behind NATs have to (a) learn each other’s IP:port and (b) agree on when to fire. In option 6 addresses come from normal addr-relay, and holepunch timing is derived from the next blocks (e.g. header timestamp) that arrive.
A node that wants to hole punch announces a new addrv2 type with its hole-punchable IP:port and an ephemeral EC public key P. Nodes keep their ephemeral private key p.
Nodes receiving it store the address and calculate a ECDH shared secret with P_other and p_own.
On every new block, each node computes SHA256(tag || shared_secret || block_hash) for every entry it had received before the block. It sorts the resulting hashes and keeps the few lowest. Those are the peers it tries this round.
For each candidate, it calls connect() to that IP:port from its punch port and leaves the socket pending.
Both sides derive the same shared secret, which also causes them to derive the same hash. Two peers find themself through being their sets of the lowest hash candidates. The timing is derived from the block header (exact way is tbd) and the same for both nodes. We don’t need the timing to be exact. During testing, a few seconds plus or minus didn’t matter. So clocks can be slightly out of sync.
The (next) block hash is used to stop an attacker from grinding. Without it, someone with my P could try private keys until their hash is tiny and be my top pick forever. When using the block hash as salt, there’s nothing to grind, since the block doesn’t exist yet when they publish their key. Nodes just have to ignore blocks they heard about before receiving the address. Privacy-wise, two public keys don’t reveal the shared secret, so an outside observer can’t tell who connects to whom or when. Participation is public though, since both sides publish an IP:port.
Both sides have to announce and have each other’s address, so success depends on how widely these spread. Additionally, it needs careful design of an holepunch address manager and rate-limiting to mitigate an attacker flooding the node with fake addresses or public keys that will never result in a holepunch connection.
Wouldn’t it also be effective for an attacker to flood with real addresses/public keys, to attempt to monopolize all connections made via this mechanism?
To maintain 8 connections to 100k peers, you’d need ~1M active ports; but for the actual address sharing step, I think you’d likely only need to advertise ~10k ports (800k connections cycling once a week is about 800 per block, so with 10k attacker addresses advertised at any one time, you should be an early match against each victim – about 85% of honest nodes will have the top two matches be attackers, in that scenario; and even when that happens, the odds of the other peer not having an attacker’s node at a higher ranked seems very low?
Yes, that’s the main downside we discussed in-person too. I’m lagging behind a bit with writing up the current ideas here (still traveling).
For sharing addresses between two home nodes, idea is to use a “message board” instead of “normal” address relay. Listening nodes can announce a service bit that they are acting as message boards for holepunching peers (next to being a normal node). Home nodes connect to them (probably via short-lived connections; but maybe long-lived is fine too) from the same port as they would do the hole puch and tell the message board about their IP. They don’t do any other relay of these connections. The board only adds the home node IP:port if it matches what it sees (protects against someone spamming the boards with fake IPs). The board also tells the home node about the IPs of the other home nodes that announced to it. If we use short-lived connections, a home-node probably has to refresh it’s own IP periodically to avoid the entry becoming stale and to learn about other home-nodes that registered on the board after it did. Board entries aren’t relayed (other than to the home-nodes who’ve chosen a node as message board). A home node chooses multiple boards from it’s addrman. The hope is that at minimum one choosen board is honest (same as home-nodes currently hope that one choose node is honest).
Then, the method described above for selecting deriving who to connect to and when happens. My instinct is that this should be more reliable than address relay. We don’t need to rely on addr-relay working well for good home node endpoints to spread across the network symmetrically (we need the peers endpoint and the peer needs ours) and it’s significantly more expensive for someone to produce failures with fake peer-endpoints: You either need a lot of IPs or you need to control many boards (in distinct netgroups / AS with asmap).
IPv6 needs a special rule as it’s cheap to get many IPs.
There’s more details in this LLM-written spec, which I don’t think is ready for human consumption yet.
In that case, honest message board nodes aren’t helping each other out, so an attacker will probably advertise the same ips/ports on every message board, while honest nodes will only appear on a few, which seems like it gives an additional multiplicative advantage to the attacker? (Attacker controlled message boards will presumably just give connections to the attacker either way ofc)
I think there’s probably two high-priority goals we should consider for p2p connectivity:
high probability of having a connection to an honest node (to avoid censorship)
low probability of having a connection to a particular attacker (to avoid spying, denial of service, or targeted exploits)
Obviously if our code and p2p protocol is perfect, and there are no vulnerabilities or privacy leaks possible from a peer connecting to our node, then (2) isn’t worth worrying about; but I don’t think that’s how things are today.
I think hole punching has a high risk of making the second goal worse – making it easier for an attacker to get a direct connection to more honest nodes. I don’t think the message board does much to improve the first goal – if you can find an honest message board node, generally you could just stay connected to it for blocks and txs; and if you can’t find an honest message board node, you’re screwed anyway in this model?
To be clear, that feature defaulting to on also makes goal 2 worse, as far as I can see. I think we haven’t seen much increased reachability as a result of that change, so I guess I’m thinking about that goal as something of a revealed preference from Bitcoin users, and seeing if it seems rational after the fact.
(writing down WIP thoughts here. Still thinking about how the interaction with a board could look like).
Both short-lived and long-lived connections have trade-offs. Periodical short-lived connections would refresh a home-node IP in a board periodically by connecting+handshake, sending it’s address, and receiving addresses from the board. A long lived connection to the board would stay open for as long as the home-node wants to receive or make a connection. These connections are very light-weight and only consists of ping/pong as well as holepunch-addr-relay (board telling the home node about candidates to punch with).
On long-lived connections, the boards can push newly registered home-nodes to connected nodes shortly after they registered. With a short-lived connection, a home node has to register with the board and fetch from the board, wait until other nodes fetched its entry from the board, and then re-fetch entries from the board. This makes short-lived connections generally slower in finding endpoints, they require more connections to succeed (which might be a problem if inbound slots on boards are full), require slightly more bandwidth (one handshake+ping/pong vs multiple handshakes), and short-lived entries might be stale more often as long-lived connections can be removed from a board shortly after the connection drops. Short-lived ones need to remain on the board for some X minutes until the next reconnect is scheduled (+ maybe some grace).
With a home-node making short-lived connections, you also need to keep the NAT and firewall mapping alive (routers might expire this after a few minutes of inactivity). This can be done by making one (or all) outbound connections from the hole punch port.
Long-lived connections are more costly to board nodes, so boards might limit how many to maintain. Short-lived ones are cheaper and a board can store many more candidates (up to a limit), which might be better for finding a more diverse set of peers, but worse in case an attacker attacks a board?
I have a slight preference for long-lived connections at the moment, as they make hole-punching more reliable and raises the cost for an attacker a bit (one connection every N minutes is slightly cheaper than maintaining a connection for longer).
My current thoughts are: (Assuming only IPv4 for now and long-lived connections), an attacker can control as many entries on all boards as he has access to IPv4 addresses he can sustain long-lived connections from. An home-node would want to sample candidates from a few boards, and deduplicate by IPv4. Boards and home-nodes would want to also limit by netgroup/AS, which makes it slightly more expensive for an attacker (as his IPs need to come from different netgroups/ASNs) with the trade-off of causing some netgroups/AS with many home-nodes to fail more often (or we could also use the netgroup/AS in the shared secret).
Today, the way for an attacker to get more direct connections seems to be to run more nodes accepting inbound connections in a more diverse set of netgroups / AS (as some entities like e.g. this, this, or this seem to be doing already). Accepting and maintaining long-lived inbounds on many IPs is more expensive for an attacker than making long-lived outbound connections (to boards and home nodes) or accepting hole-puches. So I tend to agree. Would treating them as “inbounds” (in terms of fast we relay) on both sides help? I guess only for the spy-angle. They’d still be able to DoS and otherwise exploit.
One thing that came up in an in-person discussion was: Today, the network partly relies on nodes in Hetzner, AWS, Google Cloud and Digital Ocean to offer inbound connections. If these don’t want or can’t allow you to run nodes on their platform anymore, then there’s a need for something that connects home-nodes together. They create direct edges between two home-nodes that currently are only connected via other’s. Hole punching would change topology from a hub topology (where the hubs are the reachable nodes in data centers) to a more “mesh” topology.
With fewer honest nodes being able to accept inbounds than today (e.g. ban on Bitcoin nodes in data centers), it might actually be preferable to have hole-punching to address the anti-censorship goal. You only need one board that has a few honest home-nodes for the hole punching to work at some point. The board node might not have enough resources (bandwidth or CPU) to handle the new need for connection slots to serve blocks and txs to, but can share addresses of home-nodes in a low-bandwidth fashion, which then have CPU and bandwidth resources for inbound slots.
I agree that on the other hand we want to avoid a situation where e.g. “Sorry honey, we can’t watch Netflix right now, someone is DoSing our internet by downloading blocks from my hole-punch home node.”…
My idea was to have a board node mode in Bitcoin Core, so each normal listening node eventually (when and if on-by-default) can act as a board. However, I think there’s nothing stopping people from running other software that acts a board. Maybe even with higher limits and performance, as you don’t need to handle transaction and block relay, and care a bit less about resource usage. Along the way, we should probably make sure to limit what other non-Bitcoin infrastructure can use these boards to store information.. (even if they hard to maintain an open connection for storing an address and 32 bytes of data).
It probably makes sense to rerun these numbers to see if things changed now. However, I’m not sure it’s fair to come to the conclusion that Bitcoin users prefer their home nodes to be unreachable. Checking if more reachable nodes in ISPs vs cloud show up measures router and ISP compatibility and not user consent or preference.
I guess I’m more worried about home ISPs preventing you from running a bitcoin node than all data centres doing so – it’s much harder to get a new ISP (or move house) than it is to fire up a different VPS; and it’s likewise potentially more damaging if a p2p exploit compromises your home network rather than a random VPS. The VPS provider is likely getting explicitly paid by the node operator as well, unlike the ISP who might figure “they’ll keep paying for netflix and facebook”.
I think of the topology today as two layer – a mesh of listening nodes each connected to each other, with end-points having long-term connections to a handful of random points within that mesh. Listening nodes get better performance vs higher risk (and to a small extent higher cost), while end-points get the opposite. Attackers and spy-nodes can occur at either layer, of course.
I think having more short-lived connections (perhaps lasting a few hours or a day) relaying blocks and transactions might be an interesting trade-off in this space – it reduces the risk of an attack somewhat (the attacker has to get lucky repeatedly), makes the network topology more dynamic (so attacks relying on knowing the topology are harder), and perhaps equalises the behaviour of high-uptime nodes vs new nodes which might be beneficial. Not really sure how to analyse/think about that in a concrete way though.
Possibly we should think of “outbound” and “inbound” with “chosen-partner” (I don’t think this guy is an attacker, so can prioritise them higher) vs “just-a-stranger”; so pairings might be something like:
For option 6 without a board but relying on addr-relay of addrv2(a, P) self-annoucements as mentioned in #22:
When looking into address-relay a bit more in a simulator (unrelated to hole-punching), I noticed that home-nodes (or unreachable nodes in general) receive self-annoucement far less reliable than listening nodes. Listening nodes have a lot more connections that can tell it about a self-announcement. Home-nodes only have 8 connections that could relay an address to it. We only forward an address to up to 2 peers (both also ask for getaddr on their outbound connections).
Since option 6 relies on addr self-announcements arriving at both home-nodes, I think it’s probably going to be very unreliable.
The addr relay algos we use currently wouldn’t be suitable anyway – they’re designed to prioritise long-lived addresses (announced infrequently, gets remembered/reused for a long time), whereas hole-punching data is extremely short-lived and becomes invalid after the first successful connection.
Ah, that’s cleverer behaviour from SO_REUSEADDR/PORT than I was expecting.
I was thinking the scenario for honest peers was “I’d like an additional connection, I’ll use new port number N for it, and try the holepunch-y scheme. [five minutes later] Great, it worked! No more holepunching for me for now!” which only leaves a small window for an attacker to make the connection. Doesn’t help if the attacker is constantly trying to make connections, while honest nodes are only trying rarely, but that is hard in general without adding a cost to making connections (money or PoW) or adding identity.
If you do have ports open long-term for multiple successful holepunch connection, I suppose you have to split messages into listening and connecting pairs – otherwise mapping long-term listening ports to each other, you’d just have them fill all their connection slots up with other long-term peers, and new peers would have no one to connect to.
For an attacker trying to connect to an honest peer behind a NAT, I guess the process would be:
find their announcement
publish 100 or 1000 holepunch requests in the same place
figure out which ones are at the top of the honest peer’s priority list and attempt connections via those IPs/ports
keep trying every block until a connection goes through
which still seems like it makes it a bit too easy for spys/attackers to have a direct connection to your node.
The thing that seems most compelling to me is being able to hole-punch to your own node (eg to get trusted data, to avoid random nodes spying on your requests, or to query indexes that aren’t widely available), so adding two-way auth to p2p, and adding a way to interactively trigger/coordinate hole-punching would be better. I’m not really sure an intermediary is desirable there though, so maybe that’s really just “connect via tor/i2p; authenticate; switch the connection to direct tcp via holepunch to improve performance”.
Have not fully thought this through, but wanted to note it here:
A few ways of raising the cost against an attacker that wants to fill up slots at a board came to mind:
generally, you limit number of slots on a board
when full, the board evicts connections based on a score. The score consists of e.g. hash(board IP | node IP | date). A “more zero-bits” score is preferred over a “less zero-bits” one.
honest nodes can calculate the boards they should try to connect to per day to not to get evicted
An attacker can try to spam and connect with his IPs to multiple boards, but will get evicted by honest nodes over time. To get more slots at more boards, an attacker needs to buy more IPs. As an observer, you can tell that an attacker-board is likely full of attacker-controlled IPs, as the IPs the board offers are all (compared to an honest board) “less zero-bits”.
One down side: that this allows (if you know which home-node IPs are currently looking for a connection) to guess who might be connected to which board. This also gives you a set of home-nodes potentially opening a connection. But everyone at a board can already learn about who else is at a board.
Another one: As home-nodes fill up their slots, less of them are going to be present on boards. More room for attackers.
Concretely: in the context of bugs like CVE-2026-117350 (tcp stack bug in bitcoin), CVS-2026-117349 (protocol bug in bitcoin) and CVE-2026-98432 (tcp bug in linux), isn’t it more sensible for home users not to be listening for incoming connections, as a precautionary measure?