Skip to content

Create privbcast tool, swap out in-node implementation for node-less driving - #5

Open
instagibbs wants to merge 27 commits into
masterfrom
privbcast-in-node
Open

instagibbs wants to merge 27 commits into
masterfrom
privbcast-in-node

Conversation

@instagibbs

@instagibbs instagibbs commented Sep 24, 2026 •

Copy link
Copy Markdown
Owner

The currently deployed private broadcast feature has a fundamental weakness: It is tied to the node's peer, mempool, gossip, and other state.

Rather than play whackamole with the surface level symptoms, we can completely remove these issues via correctness through construction: Do not let the local bitcoin node influence the private broadcast operation whenever possible.

The goal is one thing: broadcast a transaction without ever revealing the sender's permanent
identity, its IP address or its onion address. Everything else here serves that.

This PR consists of a number of steps which can be merged sequentially:

  1. (optional) Shrink one leak when mempool acceptance checks locally caches validity of the proposed transaction
  2. Refactor net transport for re-use
  3. Introduce the bitcoin-privbcast tool, which does not need nor use a local node to operate
  4. Introduce 1P1C package relay for the tool
  5. Using the tool as a library, thinly wrap it in a simpler scheduler inside bitcoind, and swap it in for RPC usage

Even if we get to step 3 only for a given release, the tool is of use on its own, and would offer much higher assurances for users who seek additional privacy, though the final steps are significantly smaller.

The design is specified in doc/design/private-broadcast-tool.md: goals, threat model, invariants, parameters, interface, assumptions and non-goals. Usage is in doc/private-broadcast.md.

Compared with -privatebroadcast on master

master This PR
Peers the node's address manager per job: the release DNS seeds resolved through Tor (RESOLVE), and onion peers from the release fixed-seed list
Networks Tor, I2P, IPv4/IPv6 through the proxy Tor only: onion peers, and IPv4/IPv6 peers through Tor exits
Transport v2 or v1 v2 (BIP324) only
Connections at once 3 per transaction when submitted (all share a cap of 64), each up to 3 min at most 6 per job; in bitcoind up to 18 jobs overlap
Connections in total more with every re-send at most 24 recipients per job, after 4 RESOLVE streams per DNS seed
Retries a new peer every 2-3 min until the transaction comes back or fails a test accept, up to 1000 times none; the schedule is drawn when the job starts
Duration open-ended a job's scheduled work ends within 568 s
Peer profile NODE_NONE, no wtxid relay, announces by txid NODE_WITNESS, protocol 70017, wtxid relay required (BIP339)
Packages no one parent and its child
Without a node no the bitcoin-privbcast program

Given up: I2P, peers that speak only v1, the node's address manager, and re-sending when the transaction does not come back. The remedy for a transaction that did not arrive is another job.

The commits after cb3aff3 come from writing the spec: the receive cap raised to 128 KiB, a seed's kept answers made independent of their arrival order, tie_order dropped from the report, the functional tests checking the spec from outside (exit statuses, RPC codes, outcomes and what scripted peers receive, not message text), RPC help aligned, and the spec and user guide themselves. They will be folded into the steps above.

@instagibbs
instagibbs force-pushed the privbcast-in-node branch 14 times, most recently from 9891ab1 to f3439ca Compare September 28, 2026 18:58
A test_accept left the transaction's inputs in the coins cache and its
signatures and scripts in the validation caches. That records, inside
the node, that the transaction was validated before it was public, and
a peer can probe it by timing a later submission of the same inputs.

Uncache the coins fetched for the check (as the package path already
does), skip ConsensusScriptChecks(), which on a test_accept only warms
the script cache and cross-checks policy against consensus flags, and
run the script checks with an explicit CachePolicy::READ_ONLY. The
existing "don't store" flag was not usable for this: it has
block-connection semantics and consumes a matched entry, marking it for
eviction, which would have changed the fate of signatures already
cached. STORE (mempool acceptance) and CONSUME (block connection) keep
their previous behaviour.

The database's own caches and the OS page cache are still warmed by the
coin lookup, as by any UTXO read.
…cpp}

A standalone program that speaks the P2P transports must be able to
link them without CConnman and the rest of net.cpp. Pure move into
bitcoin_common; net.h keeps including the new header, so nothing else
changes.
Take the command byte as a parameter and return the reply's bound address, so a second SOCKS5 command can reuse the greeting, authentication and reply handling. Socks5() sends CONNECT as before.
Resolving a name through the Tor proxy keeps the lookup off the host's resolver and inside a circuit. The Tor RESOLVE command returns a single numeric address.

A caller that relies on stream isolation must know the proxy actually selected username/password authentication, since Tor derives isolation from the credentials: require_auth fails the exchange otherwise.

Make the isolation-credential counter atomic so concurrent streams never share credentials. Existing callers are unchanged.
@instagibbs
instagibbs force-pushed the privbcast-in-node branch 4 times, most recently from 9a2e3ff to 6c73b5d Compare September 29, 2026 18:07
A caller on a fixed schedule must bound the whole exchange in absolute time: an optional Socks5Deadline caps the local stages at the per-stage timeout and lets the proxy's reply, where the remote work happens, use the remaining budget, never past the deadline.

Socks5Params also carries a per-stage timeout, an interrupt, a proxy connect timeout and isolation credentials, so a caller inside the node need not read or trigger the process-wide settings. Unset fields keep the process-wide behavior.
Announce a final transaction so that nothing a recipient observes can be tied to the user's node and nothing the network does can steer the sender. Both properties hold by construction: the tool is a separate process with no address manager, ban list, connection table, caches, RPC or wallet, and every decision that shapes traffic is fixed when the job starts.
Each connection speaks one constant profile, serves the transaction once on the request its advertised services make possible, and closes on the PONG. All wire-visible values are compile-time constants shared by all users.

Unit tests fix the session's profile and its strict deadlines; the fuzz target drives the session with arbitrary messages, callbacks and ticks.
Discovery resolves the release DNS seeds through Tor RESOLVE and takes onion peers from the bundled fixed seeds, all on separate isolated streams with one absolute deadline.
An attempt dials one candidate through the connector, completes a v2 handshake and drives a session over it. There is no v1 fallback. The result records whether a failure came before the INV was handed to the transport; the job retries only those.

RunSession takes any Transport, so the unit tests drive it over a v1 transport, including the receive cap and a peer close. The fuzz target runs attempts against a scripted hostile peer that speaks v2, or only v1 so our handshake fails.
Delivery uses six slots: three open together at delivery start (two exit-path, one onion), one onion slot opens at a time drawn in 35-180 s, and two exit-path slots at times drawn in 185-240 s, at least 5 s apart. A slot that fails before announcing tries its next pre-assigned peer 50-60 s later, at most three times. Every time is drawn when the job starts, so nothing observed later moves it. Input parsing covers the bounded stdin read, the loopback-only -tor argument and the bundled fixed-seed list.

Unit tests fix the schedule and assignment arithmetic, input parsing and attempt decisions, and run whole jobs through the connector seam at a fraction of real time so scheduling rules (missed and empty opportunities, exit status, cancellation reaching a blocked connector) are checked without Tor. Fuzz targets cover discovery freezing with assignment, and input parsing.
Input is the transaction hex on stdin, output a JSON report; acceptance is checked beforehand with testmempoolaccept and receipt observed with getmempoolentry. Regtest-only flags exist for the tests. doc/design/private-broadcast-tool.md states the principle.

The functional test runs jobs against the framework's SOCKS5 server, extended with RESOLVE, a delayed CONNECT reply and a larger backlog, with one behaviour per seed so every outcome path is taken on every run, and checks a bystander node's state is untouched.
…man/PeerManager implementation

A job uses the node's Tor SOCKS5 proxy (GetProxy(NET_ONION)) wherever it
listens, trusted like the node's other proxy settings; the standalone tool
refuses a proxy that is not on loopback, since SOCKS5 carries destinations
and the per-stream credentials in plaintext up to the proxy.
instagibbs pushed a commit that referenced this pull request Nov 10, 2026
…:__pad_and_output

fa3821e test: Add missing suppression for race:std::__1::__pad_and_output (MarcoFalke)

Pull request description:

  From https://github.com/bitcoin/bitcoin/actions/runs/41684419453/job/126086262840?pr=35990#step:11:8669:

  ```
  WARNING: ThreadSanitizer: data race (pid=17903)
    Write of size 8 at 0x7ff5c1990c20 by thread T12 (mutexes: write M0):
      #0 width /llvm-project/libcxx/include/ios:498:18 (libc++.so.1+0xd3816) (BuildId: 6e001266114c9106207bb18363e2d5a09b534306)
      #1 std::__1::ostreambuf_iterator<char, std::__1::char_traits<char>> std::__1::__pad_and_output[abi:dee230102]<char, std::__1::char_traits<char>>(std::__1::ostreambuf_iterator<char, std::__1::char_traits<char>>, char const*, char const*, char const*, std::__1::ios_base&, char) /llvm-project/libcxx/include/__locale_dir/pad_and_output.h:67:9 (libc++.so.1+0xd3816)
      #2 std::__1::ostreambuf_iterator<char, std::__1::char_traits<char>> std::__1::num_put<char, std::__1::ostreambuf_iterator<char, std::__1::char_traits<char>>>::__do_put_integral[abi:dee230102]<long long>(std::__1::ostreambuf_iterator<char, std::__1::char_traits<char>>, std::__1::ios_base&, char, long long) const /llvm-project/libcxx/include/__locale_dir/num.h:907:10 (libc++.so.1+0xbcfa0) (BuildId: 6e001266114c9106207bb18363e2d5a09b534306)
      #3 std::__1::num_put<char, std::__1::ostreambuf_iterator<char, std::__1::char_traits<char>>>::do_put(std::__1::ostreambuf_iterator<char, std::__1::char_traits<char>>, std::__1::ios_base&, char, long long) const /llvm-project/libcxx/include/__locale_dir/num.h:919:16 (libc++.so.1+0xbcb79) (BuildId: 6e001266114c9106207bb18363e2d5a09b534306)
      #4 put /llvm-project/libcxx/include/__locale_dir/num.h:780:12 (libc++.so.1+0x9b40c) (BuildId: 6e001266114c9106207bb18363e2d5a09b534306)
      #5 std::__1::basic_ostream<char, std::__1::char_traits<char>>& std::__1::basic_ostream<char, std::__1::char_traits<char>>::__put_num[abi:dee230102]<long long>(long long) /llvm-project/libcxx/include/__ostream/basic_ostream.h:104:21 (libc++.so.1+0x9b40c)
      #6 std::__1::basic_ostream<char, std::__1::char_traits<char>>::operator<<(long long) /llvm-project/libcxx/include/__ostream/basic_ostream.h:316:10 (libc++.so.1+0x9b2a0) (BuildId: 6e001266114c9106207bb18363e2d5a09b534306)
      #7 KernelLog::LogMessage(btck::LogEntry const&) /home/runner/work/_temp/src/bitcoin-chainstate.cpp:49:33 (bitcoin-chainstate+0xf2667) (BuildId: cff46198c8fd29997404a749cd55fdd6fcb3e865)

ACKs for top commit:
  fanquake:
    utACK fa3821e

Tree-SHA512: 383705fe33e429d40baaf7811a3edd6ce5164c423a1450c7a7a5d749d1ba44b8dac7a1270cbb593fcd0888dd9a2efbe7507650adf69b2f46ac09db4488cb9aec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant