Skip to content
BIP ATLAS

BIP 0324

What changes when nodes encrypt their traffic?

Blocks and transactions are public. The conversation between two nodes need not be. BIP 324 changes what someone listening on the wire can read.

A Bitcoin transaction will eventually be public, but the route it takes through the network says something too. Who sent it first? When did a particular node receive it? With v1 transport, someone able to watch the connections can read the messages and study their source and timing.12

BIP 324 introduces an encrypted transport, v2. The nodes still exchange the same messages about blocks, transactions and peers. What changes is the conversation on the wire: a passive listener sees random-looking bytes instead of readable Bitcoin messages.345

Source revision
bitcoin/bips @ 3a10b5b
Source checked
1 October 2026
Review state
Awaiting review
Source details

This chapter is an independent explanation, not the proposal itself. Preamble fields are shown as the pinned files record them, without author e-mail addresses. Status is the proposal’s own field. It is not an endorsement or a sign of consensus.

BIP 324: Version 2 P2P Encrypted Transport Protocol

BIP
324
Layer
Peer Services
Title
Version 2 P2P Encrypted Transport Protocol
Authors
Dhruv Mehta
Tim Ruffing
Jonas Schnelli
Pieter Wuille
Status
Deployed
Type
Specification
Assigned
2019-03-08
License
BSD-3-Clause
Version
1.0.2
Replaces
151

Pinned source · Reader view on bips.dev
SHA-256 14de484a709946348effa8264991cf124a34ecdaf0a3f9d68a42313287625ad8
Git blob 2b3caff37f5b589d7d42eba0eaf36c42eab332c5

Fig. A17.1 Listening is different from joining the conversation

Listening is different from joining the conversationSchematic comparison. On v1, a passive listener reads the messages between node A and node B. On v2, the same listener cannot read the contents, though packet sizes and timing remain visible. An active attacker can instead establish one encrypted connection with each node. The session IDs A and B differ; comparing them through another channel can reveal the interception. v2 does not authenticate the peer.V1 / READABLE ON THE WIRENODE ANODE Bversion · tx · blockA LISTENER CAN READ THE MESSAGESV2 / SAME PATH, ENCRYPTED CONTENTSNODE ANODE BencryptedHIDDEN CONTENTS · VISIBLE SIZES & TIMINGV2 / THE ATTACKER JOINS INNODE ANODE BATTACKERSESSION ASESSION BA ≠ BCOMPARE IDs THROUGH ANOTHER CHANNEL
Encryption blocks passive reading. An attacker can still take an active role between the peers; comparing session IDs through another channel can expose that interception.146789

What an eavesdropper has to do now

Encryption raises the cost of observation. Instead of quietly recording readable traffic, an attacker needs to become involved: intercept a connection throughout its life, cause a downgrade to v1, or run a node that honest peers connect to. The authors’ aim is to make large-scale surveillance and tampering more expensive.4610

There is an important limit here. The handshake does not authenticate the peer. A node can establish an encrypted connection to an attacker’s node just as it can to any other node. Encryption protects the bytes in transit; it does not establish a trusted identity for the endpoint.8

An honest connection gives both ends the same session ID. An attacker inserted between them establishes separate connections, giving the ends different IDs. Operators can compare these IDs over another channel. The mismatch becomes useful evidence only when someone actually makes that comparison.7

Even without reading a message, a listener can observe packet sizes and timing. Those patterns can still identify v2 traffic. The design provides ways to vary the traffic, but it does not promise that an encrypted Bitcoin connection becomes invisible.911

Why the authors chose a new transport

v2 encrypts, but it does not authenticate the peer. Nothing in the handshake tells a node who it is talking to; the BIP says so plainly. The authors argue that in a permissionless network authentication only makes sense in specific settings, such as two nodes run by the same operator, and that it should be added separately, if at all.8

Why not use TLS or Noise? The authors’ answer has several parts. Neither treats authentication as a separate, optional layer. Neither produces a pseudorandom byte stream that can be shaped to resemble other traffic. Neither supports secp256k1 natively, and both hand the application a stream where Bitcoin wants packets. Fixing all of that would forfeit the benefit of reusing them.12

Agree on a secret across an open wire

The nodes begin by exchanging fresh public keys. Each combines its private key with the other side’s public information to derive a shared secret. That secret never has to cross the wire. From it they derive keys for sending and receiving, along with their session ID.131415

But the first message needs care. If the key exchange began with a recognisable Bitcoin marker, a network filter could identify it before any encryption started. The public keys therefore use ElligatorSwift encoding: 64 bytes designed to look uniformly random to a passive observer.2413

Fig. A17.2 The opening should give nothing away

64 bytes that look randomThe initiator's first message in BIP 324 vector Packet 1, initiator: a 64-byte ElligatorSwift encoding of its ephemeral public key, ec0adff257bbfe500c188c80b4fdd640f6b45a482bbc15fc7cef5931deff0aa186f6eb9bba7b85dc4dcc28b28722de1e3d9108b985e2967045668f66098e475b, in two 32-byte halves u and t, optionally followed by up to 4095 bytes of garbage. Every 64-byte string encodes some point, so a uniformly chosen encoding looks like random bytes. The key's x coordinate is 19e965bc20fc40614e33f2f82d4eeff81b5e7516b12a5c6c0d6053527eba0923, computed from the vector's private key; this site does not implement ElligatorSwift decoding, so that the 64 bytes decode to it is the vector's claim.THE INITIATOR'S FIRST BYTES ON THE WIREec0adff257bbfe500c188c80b4fdd640f6b45a482bbc15fc7cef5931deff0aa186f6eb9bba7b85dc4dcc28b28722de1e3d9108b985e2967045668f66098e475but64 B · ELLIGATORSWIFT · ANY 64 BYTES ARE VALIDGARBAGE · 0 TO 4,095 B · OPTIONALx = 19e965bc20fc4061…COMPUTED FROM THE PRIVATE KEY. THAT THE 64 BYTESDECODE TO IT IS THE VECTOR'S CLAIM: NOT DECODED HERE
Exact values
ElligatorSwift encoding (64 bytes)
ec0adff257bbfe500c188c80b4fdd640f6b45a482bbc15fc7cef5931deff0aa186f6eb9bba7b85dc4dcc28b28722de1e3d9108b985e2967045668f66098e475b
x coordinate of the public key
19e965bc20fc40614e33f2f82d4eeff81b5e7516b12a5c6c0d6053527eba0923
The encoded public key looks like random bytes. This example takes the decoded point from the published vector; the site does not implement ElligatorSwift decoding.131617

A peer can also append garbage bytes to its key. These vary the length of the opening message, so an observer cannot rely on one fixed length. Each side later sends a terminator derived from the shared secret, which tells the other side where that garbage ends.151618

Encrypted packets follow the terminator. The first packet authenticates the garbage already sent, so a change to those bytes makes authentication fail. An empty version packet announces v2. Decoy packets may precede it. The responder can include its version packet in its first response without waiting for another round trip.1920

Step through the handshake below. Watch what crosses the open network and what stays inside each node. Public encodings cross the wire; the keys derived from the exchange stay at its ends.141517

Fig. A17.3 Follow the opening exchange

Static view: the first vector at the last step. With JavaScript you can step through the handshake, choose among 5 published vectors and compare v1 framing.

From two public keys to an encrypted packetBIP 324 vector Packet 0, initiator, seen from the initiator. Step 5 of 5, packet: Every later byte belongs to an encrypted packet. Packet 0 from the initiator: 83 bytes for 63 bytes of contents. On each side: shared secret e500c670f1b32f60e05009bddcdbfa7153afb19c20479583a54b43d85b3433a8, session ID d083d09c1bdf71795b39a9534601cf7c7a7e767e578c44a17dfaf43a3c18f98c. The listener on the wire sees: keys + garbage: random; terminators: random; 83 b packet: size, timing; never the secret or the keys.THIS SIDEINITIATORSECRET e500c670…4 CIPHER KEYSSESSION d083d09c…PEERRESPONDERSECRET e500c670…4 CIPHER KEYSSESSION d083d09c…OPEN NETWORK64 B KEY64 B KEYTERMINATORSHDR+CTAGPACKET 0 · 83 BLISTENER SEESKEYS + GARBAGE: RANDOMTERMINATORS: RANDOM83 B PACKET: SIZE, TIMINGSECRET, KEYS: NOT ON THE WIRE
From two public keys to an encrypted packetBIP 324 vector Packet 0, initiator, seen from the initiator. Step 5 of 5, packet: Every later byte belongs to an encrypted packet. Packet 0 from the initiator: 83 bytes for 63 bytes of contents. On each side: shared secret e500c670f1b32f60e05009bddcdbfa7153afb19c20479583a54b43d85b3433a8, session ID d083d09c1bdf71795b39a9534601cf7c7a7e767e578c44a17dfaf43a3c18f98c. The listener on the wire sees: keys + garbage: random; terminators: random; 83 b packet: size, timing; never the secret or the keys.THIS SIDEINITIATORe500c670…4 KEYSID d083d09c…PEERRESPONDERe500c670…4 KEYSID d083d09c…OPEN NETWORK64 B KEY64 B KEYTERMINATORSHDR+CPACKET 0 · 83 BLISTENER SEESKEYS + GARBAGE: RANDOMTERMINATORS: RANDOM83 B PACKET: SIZE, TIMINGSECRET, KEYS: NOT ON THE WIRE

Step 5 of 5, packet: Every later byte belongs to an encrypted packet. Packet 0 from the initiator: 83 bytes for 63 bytes of contents.

Exact values for this vector
Shared secret
e500c670f1b32f60e05009bddcdbfa7153afb19c20479583a54b43d85b3433a8
Session ID
d083d09c1bdf71795b39a9534601cf7c7a7e767e578c44a17dfaf43a3c18f98c
Packet 0: length, tag
6aa28b fa1cdc7eb99581c48ff2898ef92d3aa1

BIP 324 packet_encoding_test_vectors.csv, line 4. Recomputed by the tested model and equal to the vector; ElligatorSwift decodings are the vector's own, not computed here.

Step through the exchange, then compare the peer’s view with the listener’s. The ElligatorSwift decodings are supplied by the source vectors.911141516171920212223

Notice that the peers know much more than the listener. Both derive secret material locally from the exchange. Sending the public encodings does not mean sending the resulting cipher keys or session ID. Those remain off the wire, even though both ends can calculate them.71415

The key schedule and the end of the garbage

Both sides then decode the other’s 64 bytes to an X coordinate and compute X-only ECDH. The result is hashed together with both 64-byte encodings exactly as sent, initiator’s first, so an attacker cannot alter an encoding without breaking the rest of the stream. HKDF-SHA256, salted with the label “bitcoin_v2_shared_secret” and the network magic, expands that secret into the session ID, four cipher keys (a length key and a payload key in each direction) and two 16-byte garbage terminators.1415

The authors explain that the terminator exists because the receiver has to find where the garbage ends. Scanning for a fixed 16-byte sequence is cheap, whereas trying to authenticate a packet at every offset would mean recomputing a Poly1305 tag for every byte received. A receiver reads at most 4111 bytes, 4095 of garbage and the terminator, before giving up.1618

For packets 223 and 448, the published vectors supply only the last 128 bytes of ciphertext. Those suffixes are what the build compares. ElligatorSwift decodings are taken from the vectors.17

Read enough to know where a packet ends

Once the handshake is over, the receiver needs to separate the incoming stream into packets. That poses a small puzzle: it has to know a packet’s length before it can collect and authenticate the whole thing. BIP 324 therefore encrypts the length separately from the packet’s header and contents.2124

The length uses its own ChaCha20 stream. The header and contents use ChaCha20-Poly1305, ending in an authentication tag. The length itself is not covered by that tag, but tampering with it still causes packet authentication to fail. Decryption and checking are part of receiving each packet.2124

Fig. A17.4 A packet has two encrypted parts

One packet, byte by bytePacket 1 of vector Packet 1, initiator, all 21 bytes: 7530d2a18720162ac09c25329a60d75adf36eda3c3. Bytes 0 to 2 are the length, encrypted with its own ChaCha20 stream and not covered by the tag; the next 2 are the header and contents, encrypted with ChaCha20-Poly1305; the last 16 are the Poly1305 tag. The endpoints recover the length 010000 (1, little-endian), the header 00 and the contents 8e.ON THE WIRE · PACKET 1 · 21 B035217530d2a18720162ac09c25329a60d75adf36eda3c3LENGTHHDR+CTAG · 16 BLENGTH: OWN CHACHA20 STREAM, NOT IN THE TAGHEADER + CONTENTS (2 B): CHACHA20-POLY1305WHAT THE ENDPOINTS RECOVER010000008eLENGTH 1 (LE) · HEADER 00 · CONTENTS
Exact bytes
Packet
7530d2a18720162ac09c25329a60d75adf36eda3c3
Nonce
010000000000000000000000
All 21 bytes of a published packet with 1 byte of contents. The length is encrypted separately; the tag covers the header and contents.172124

One header flag tells the receiver to ignore a packet after checking it. That creates a decoy: it travels through the encrypted connection but carries no application message for the node to act on. Decoys offer a way to shape traffic; BIP 324 leaves the policy for sending them to implementations.1011

For a real message, the contents begin with its type. Common types can use a short identifier. Other messages use a zero byte followed by the familiar v1 command name. The application still receives the same kind of Bitcoin message after the transport has checked and unpacked it.525

Fig. A17.5 The wrapper around a message

Framing, v1 and v2Per message, v1 sends a 24-byte header in the clear: network magic, 4 bytes; command, 12 ASCII bytes, 12 bytes; payload length, 4 bytes; checksum, 4 bytes, then the payload. v2 sends 21 bytes besides the payload for a ping message: encrypted length, 3 bytes; header (ignore bit), 1 bytes; message type ID 18, 1 bytes; Poly1305 tag, 16 bytes; none of it in the clear. A type without a short ID takes 13 bytes instead of 1.V1 · 24 B IN THE CLEARMAGIC4COMMAND12LENGTH4CHECKSUM4PAYLOADV2 · PING · 21 B, NONE IN THE CLEARLEN3HDR1ID1PAYLOADTAG16ID 18 = PING · NUMBERS ARE BYTES
v1 adds a 24-byte cleartext header. v2 adds 21 bytes for a message with a short ID.212325

Encrypting the connection does not necessarily make that wrapper larger. The short-ID case above uses less overhead than v1; the long form uses 33 bytes. The authors also estimate that encryption and authentication cost about as much as the checksum calculation they replace.2326

Packet sizes and header bits

After the handshake every byte on the wire belongs to a packet. A packet is 20 bytes plus its contents: a 3-byte length, encrypted, then ChaCha20-Poly1305 over a 1-byte header and the contents, ending in a 16-byte tag. Contents can be up to 2^24 − 1 bytes.21

BIP 324 defines one header flag, the highest bit, called the ignore bit; the other bits are ignored for now. A packet with it set is a decoy: the receiver checks that it decrypts and throws it away. Decoys are the protocol’s main means of shaping traffic, which the authors want to make it possible to conceal block propagation; how and when to send them is left out of scope.1011

Leave old conversations behind

Suppose an attacker obtains a node’s current traffic keys. How much of a previously recorded conversation becomes readable? v2 limits that exposure by changing both cipher keys every 224 packets. Once old keys are discarded, the current keys do not let the attacker derive earlier ones.2227

Fig. A17.6 The key changes as the conversation continues

Nonces and keys across a rekeyThe responder's payload cipher in a published BIP 324 vector. Each epoch is 224 packets. Packet 0: nonce 000000000000000000000000, epoch 0, key fdf5a3e3e75afc15a924373e58af505052731efa75c76a1fa3546954d60b50b1; Packet 1: nonce 010000000000000000000000, epoch 0, key fdf5a3e3e75afc15a924373e58af505052731efa75c76a1fa3546954d60b50b1; Packet 222: nonce de0000000000000000000000, epoch 0, key fdf5a3e3e75afc15a924373e58af505052731efa75c76a1fa3546954d60b50b1; Packet 223: nonce df0000000000000000000000, epoch 0, key fdf5a3e3e75afc15a924373e58af505052731efa75c76a1fa3546954d60b50b1; Packet 224: nonce 000000000100000000000000, epoch 1, key 9eae3d0883a0713e8d97f44346027aa7f0dd1c6d65f7b97a08a676fe9bf6bd32; Packet 447: nonce df0000000100000000000000, epoch 1, key 9eae3d0883a0713e8d97f44346027aa7f0dd1c6d65f7b97a08a676fe9bf6bd32; Packet 448: nonce 000000000200000000000000, epoch 2, key 7bf2eccbbf396d1b84ad8ac01d96f7a236664d34f7db8517f8ff8fa3bfc290ff. After every 224th packet the new key is the first 32 bytes of encrypting 32 zero bytes under the old key, with the nonce's packet field set to 0xffffffff.224PACKETS PER KEY223 → 224PACKET 223 · NONCEdf0000000000000000000000PACKET 224 · NONCE000000000100000000000000PACKET (4 B LE, HEAVY) ‖ EPOCH (8 B LE)EACH KEY MADE FROM THE ONE BEFOREEPOCH 0fdf5a3e3…EPOCH 19eae3d08…EPOCH 27bf2eccb…NEW KEY = FIRST 32 B OF ENCRYPTING 32 ZERO BYTESUNDER THE OLD KEY, NONCE PACKET FIELD 0xffffffff
Exact nonces and keys
Packet 0 (epoch 0)
000000000000000000000000
fdf5a3e3e75afc15a924373e58af505052731efa75c76a1fa3546954d60b50b1
Packet 1 (epoch 0)
010000000000000000000000
fdf5a3e3e75afc15a924373e58af505052731efa75c76a1fa3546954d60b50b1
Packet 222 (epoch 0)
de0000000000000000000000
fdf5a3e3e75afc15a924373e58af505052731efa75c76a1fa3546954d60b50b1
Packet 223 (epoch 0)
df0000000000000000000000
fdf5a3e3e75afc15a924373e58af505052731efa75c76a1fa3546954d60b50b1
Packet 224 (epoch 1)
000000000100000000000000
9eae3d0883a0713e8d97f44346027aa7f0dd1c6d65f7b97a08a676fe9bf6bd32
Packet 447 (epoch 1)
df0000000100000000000000
9eae3d0883a0713e8d97f44346027aa7f0dd1c6d65f7b97a08a676fe9bf6bd32
Packet 448 (epoch 2)
000000000200000000000000
7bf2eccbbf396d1b84ad8ac01d96f7a236664d34f7db8517f8ff8fa3bfc290ff
The packet counter starts a new epoch when the key changes. The earlier epoch uses a different key.1722

This is forward secrecy within a session. It protects traffic from before the last rekey against theft of the current keys. It does not refresh the public-key exchange during the connection. The precise key and nonce updates are separate from what the application is sending.2227

How each cipher replaces its key

Both ciphers change their keys every 224 packets. The payload cipher’s nonce counts packets within the current epoch and numbers the epoch. The key changes after the 224th packet: the new key is the first 32 bytes of encrypting 32 zero bytes under the old key, with the nonce’s packet field set to 0xffffffff. The length cipher replaces its key with the next 32 bytes of its own stream and moves to the next nonce.22

Keep talking to older nodes

A node accepting connections has to recognise older peers too. It examines the first 16 bytes. The network magic followed by “version” and padding identifies the start of v1; when those bytes match, the responder switches to that transport.28

Fig. A17.7 Recognising the old greeting

v1 or v2?A responder looks at the first 16 bytes it receives. Every v1 connection starts with f9beb4d976657273696f6e0000000000: the network magic f9beb4d9, the ASCII command "version" and zero padding; if they match, it speaks v1. A v2 initiator's first 16 bytes are the start of its 64-byte key, in vector Packet 1, initiator: ec0adff257bbfe500c188c80b4fdd640.A V1 PEER ALWAYS STARTS WITHf9beb4d9version0000000000MAGIC"VERSION"PADDINGA V2 INITIATOR STARTS WITH ITS KEYec0adff257bbfe500c188c80b4fdd640MATCH: SPEAK V1 · OTHERWISE: CONTINUE AS V2
Exact bytes
v1 prefix
f9beb4d976657273696f6e0000000000
v2 initiator's first 16 bytes (Packet 1, initiator)
ec0adff257bbfe500c188c80b4fdd640
v1 has a fixed opening. A v2 initiator’s random-looking key almost never matches it.28

Nodes advertise v2 support using the NODE_P2P_V2 service flag. That advertisement travels through untrusted relays, so it is not a guarantee. If a connection is closed immediately after a v2 attempt, a node is encouraged to retry v1. Accepting inbound v1 connections helps avoid splitting the network.1029

The result is an upgrade to how peers communicate. It leaves blocks, transactions, scripts and consensus rules as they were. A node receiving an encrypted message still has to apply all the usual checks to what that message says.5

Source notes

BIP 324 was assigned in 2019 and is recorded as Deployed in the pinned source. The examples use published packet vectors, with their ElligatorSwift decodings supplied rather than calculated by this site.1730

Evidence

Each numbered marker in the text points here, and the ↩ links lead back to the text. Quotes are verbatim from the BIP files at commit 3a10b5b, wiki markup included. Links open the exact lines. Labels say what kind of statement each entry is: a rule, the author’s rationale, history, a test vector, or our own inference.

  1. ↩ a b Author’s rationale The authors note that v1 peers talk over unencrypted, unauthenticated connections; the data is public but metadata can reveal private information, such as a transaction's source and timing to a global passive attacker.

    Quoted source text (2)

    peers talk to each other over unencrypted and unauthenticated connections.

    BIP 324, line 26

    While the relayed data itself is public in nature, the associated metadata may reveal private information and hamper privacy of users. For example, a global passive attacker eavesdropping on all Bitcoin P2P connections can trivially identify the source and timing of a transaction.

    BIP 324, line 28
  2. ↩ a b Author’s rationale The authors note v1 connections can be tampered with cheaply, and are self-revealing because they start with fixed magic bytes, which enables censorship.

    Quoted source text (2)

    Since connections are unauthenticated, they can be tampered with at a low cost and often even with a low risk of detection.

    BIP 324, line 29

    The protocol is self-revealing. For example, deep packet inspection can identify a P2P connection trivially because connections start with a fixed sequence of magic bytes. The ability to detect connections enables censorship

    BIP 324, line 30
  3. ↩ Rule BIP 324 proposes a new P2P transport with opportunistic encryption, a mild bandwidth reduction, and upgrade negotiation before application messages.

    Quoted source text (1)

    This document proposes a new Bitcoin P2P transport protocol, which features opportunistic encryption, a mild bandwidth reduction, and the ability to negotiate upgrades before exchanging application messages.

    BIP 324, line 20
  4. ↩ a b c d Author’s rationale v2 aims to raise the cost of these attacks mainly through unauthenticated, opportunistic encryption, and makes the bytestream pseudorandom to a passive eavesdropper.

    Quoted source text (1)

    This proposal for a new P2P protocol version (v2) aims to improve upon this by raising the costs for performing these attacks substantially, primarily through the use of unauthenticated, opportunistic transport encryption. In addition, the bytestream on the wire is made pseudorandom (i.e., indistinguishable from uniformly random bytes) to a passive eavesdropper.

    BIP 324, line 32
  5. ↩ a b c Editorial inference v2 changes only how P2P messages are carried: payloads and message types are those of the v1 protocol, and the BIP sits in the Peer Services layer, not consensus.

    Quoted source text (3)

    Layer: Peer Services

    BIP 324, line 3

    An unencrypted application layer '''contents''' is composed of:

    BIP 324, line 523

    a 12-byte ASCII message type (as in the v1 P2P protocol)

    BIP 324, line 528
  6. ↩ a b Author’s rationale The authors argue encryption forces an eavesdropper to become active: a persistent MitM, downgrading to v1, or running its own nodes; for manual connections, comparing session IDs would expose an attacker.

    Quoted source text (3)

    Encryption, even when it is unauthenticated and only used when both endpoints support v2, impedes eavesdropping by forcing the attacker to become active: either by performing a persistent man-in-the-middle (MitM) attack, by downgrading connections to v1, or by spinning up their own nodes and getting honest nodes to make connections to them.

    BIP 324, line 34

    even very basic checks, e.g., operators manually comparing protocol versions and session IDs (as supported by the proposed protocol), will expose the attacker.

    BIP 324, line 34

    Active attacks at scale are more resource intensive in general, but in the case of manual, deliberate connections (as opposed to automatic, random ones), they are also in principle detectable

    BIP 324, line 34
  7. ↩ a b c Author’s rationale A session ID derived from the Diffie-Hellman negotiation identifies the channel; operators can compare it out of band, so an active MitM risks detection.

    Quoted source text (2)

    * Observability of active attacks: A session ID identifying the encrypted channel uniquely is derived deterministically from a Diffie-Hellman negotiation. An active man-in-the-middle attacker is forced to incur a risk of being detected as peer operators can compare session IDs manually

    BIP 324, line 82

    v2 clients supporting this proposal may present the entire session ID (encoded as a hex string) to the node operator to allow for manual, out of band comparison with the peer node operator.

    BIP 324, line 329
  8. ↩ a b c Author’s rationale The proposal does not include peer authentication; the authors argue authentication should be addressed separately, if desired, and the session ID provides a basis for it.

    Quoted source text (2)

    The communication protocol establishing that the communication partner's identity matches who we expect them to be, through some public key mechanism. The proposal in this document does '''not''' include such a mechanism.

    BIP 324, line 42

    As a consequence, we believe that authentication should be addressed separately (if desired), and this proposal aims to provide a solid technical basis for future protocol upgrades, including the addition of optional authentication

    BIP 324, line 44
  9. ↩ a b c Author’s rationale Traffic analysis of packet lengths and timing, and active attacks, can still reveal that v2 is in use.

    Quoted source text (1)

    Traffic analysis, e.g., observing packet lengths and timing, as well as active attacks can still reveal that the Bitcoin v2 P2P protocol is in use.

    BIP 324, line 48
  10. ↩ a b c d Author’s rationale Goals include confidentiality against passive attacks, a pseudorandom and shapable bytestream, forward secrecy, upgradability, accepting inbound v1, and low overhead.

    Quoted source text (5)

    * Confidentiality against passive attacks: A passive attacker having recorded a v2 P2P bytestream (without timing and fragmentation information) must not be able to determine the plaintext being exchanged by the nodes.

    BIP 324, line 81

    * Pseudorandom bytestream: A passive attacker having recorded a v2 P2P bytestream (without timing information and fragmentation information) must not be able to distinguish it from a uniformly random bytestream.

    BIP 324, line 83

    * Forward secrecy: An eavesdropping attacker who compromises a peer's sessions secrets should not be able to decrypt past session traffic, except for the latest few packets.

    BIP 324, line 85

    * Compatibility: v2 clients will allow inbound v1 connections to minimize risk of network partitions.

    BIP 324, line 87

    * Shapable bytestream: It should be possible to shape the bytestream to increase resistance to traffic analysis (for example, to conceal block propagation)

    BIP 324, line 84
  11. ↩ a b c d Rule Packets with the ignore bit set are decoys, ignored apart from verifying they decrypt; they are the main shapability mechanism.

    Quoted source text (2)

    Encrypted packets have an '''ignore bit''', which makes them '''decoy packets''' if set. Decoy packets are to be ignored by the receiver apart from verifying they decrypt correctly. Either peer may send such decoy packets at any point from here on. These form the primary shapability mechanism in the protocol.

    BIP 324, line 126

    How and when to use them is out of scope for this document.

    BIP 324, line 126
  12. ↩ Author’s rationale The authors argue TLS and Noise are unsuitable: they lack a modular treatment of authentication, a pseudorandom and shapable bytestream, native secp256k1 support, and a packet interface.

    Quoted source text (6)

    While it would be possible to rely on an off-the-shelf transport encryption protocol such as TLS or Noise, the specific requirements of the Bitcoin P2P network laid out above make these protocols an unsuitable choice.

    BIP 324, line 62

    The primary requirement which existing protocols fail to meet is a sufficiently modular treatment of encryption and authentication.

    BIP 324, line 64

    * Neither offers a pseudorandom bytestream. * Neither offers native support for elliptic curve cryptography on the curve secp256k1 as otherwise used in Bitcoin.

    BIP 324, lines 70–73

    * Neither offers shapability of the bytestream.

    BIP 324, line 72

    * Both provide a stream-based interface to the application layer, whereas Bitcoin requires a packet-based interface

    BIP 324, line 73

    this would negate the benefits of using them as off-the-shelf solution

    BIP 324, line 75
  13. ↩ a b c Rule Each side sends a 64-byte ElligatorSwift encoding of an ephemeral public key; every 512-bit string is a valid encoding, so encodings sampled uniformly look random.

    Quoted source text (2)

    Generates a random ephemeral secp256k1 private key and sends a corresponding 64-byte ElligatorSwift

    BIP 324, line 112

    While a random 256-bit string has about 50% chance of being a valid X coordinate on the secp256k1 curve, every 512-bit string is a valid ElligatorSwift encoding of a curve point, making the encoded point indistinguishable from random when using an encoder that can sample uniformly.

    BIP 324, line 112
  14. ↩ a b c d e Rule Both sides compute X-only ECDH and hash it with the exact 64-byte encodings sent (initiator's first), so the encodings cannot be modified without a full MitM.

    Quoted source text (2)

    def v2_ecdh(priv, ellswift_theirs, ellswift_ours, initiating): ecdh_point_x32 = ellswift_ecdh_xonly(ellswift_theirs, priv) if initiating: # Initiating, place our public key encoding first. return sha256_tagged("bip324_ellswift_xonly_ecdh", ellswift_ours + ellswift_theirs + ecdh_point_x32)

    BIP 324, lines 214–221

    This makes sure that an attacker cannot modify the public key encoding used without modifying the rest of the stream. If a third party wants the ability to modify stream bytes, they need to perform a full MitM attack on the connection.

    BIP 324, line 121
  15. ↩ a b c d e f Rule HKDF-SHA256, salted with "bitcoin_v2_shared_secret" and the network magic, derives the session ID, four cipher keys and the two 16-byte garbage terminators.

    Quoted source text (1)

    # Include NETWORK_MAGIC to ensure a connection between nodes on different networks will immediately fail prk = HKDF_Extract(Hash=sha256, salt=b'bitcoin_v2_shared_secret' + NETWORK_MAGIC, ikm=ecdh_secret) peer.session_id = HKDF_Expand(Hash=sha256, PRK=prk, info=b'session_id', L=32) # Initialize the packet encryption ciphers. initiator_L = HKDF_Expand(Hash=sha256, PRK=prk, info=b'initiator_L', L=32) initiator_P = HKDF_Expand(Hash=sha256, PRK=prk, info=b'initiator_P', L=32) responder_L = HKDF_Expand(Hash=sha256, PRK=prk, info=b'responder_L', L=32) responder_P = HKDF_Expand(Hash=sha256, PRK=prk, info=b'responder_P', L=32) garbage_terminators = HKDF_Expand(Hash=sha256, PRK=prk, info=b'garbage_terminators', L=32) initiator_garbage_terminator = garbage_terminators[:16] responder_garbage_terminator = garbage_terminators[16:]

    BIP 324, lines 296–308
  16. ↩ a b c d Rule Each side may send up to 4095 bytes of garbage after its public key, for shapability and to avoid a recognizable 64-byte pattern.

    Quoted source text (2)

    bytes of arbitrary data after their public key, called '''garbage''', providing a form of shapability and avoiding a recognizable pattern of exactly 64 bytes.

    BIP 324, line 113

    May send up to 4095

    BIP 324, line 113
  17. ↩ a b c d e f g Test vector This site's model reproduces all seven BIP 324 packet-encoding vectors: x(ours), X-only ECDH, shared secret, all HKDF outputs, session ID, the full packet for the three vectors that publish one and the published last 128 bytes for the other four, including packets after two, three and four rekeys and one of the largest size allowed (2^24 - 1 bytes of contents). ElligatorSwift decoding is not implemented: the model takes the decoded X coordinates from the vectors.

    Quoted source text (1)

    * [[bip-0324/packet_encoding_test_vectors.csv|Packet encoding vectors]] illustrate the lifecycle of the authenticated encryption scheme proposed in this document.

    BIP 324, line 589
  18. ↩ a b Author’s rationale A fixed 16-byte terminator is used because scanning for a byte sequence is much faster than trying to authenticate a packet at every offset; a receiver reads at most 4111 bytes looking for it.

    Quoted source text (2)

    While it is in principle possible to use the first packet after the garbage directly as a terminator (scan until a valid packet follows), this would be significantly slower than just scanning for a fixed byte sequence, as it would require recomputing a Poly1305 tag after every received byte.

    BIP 324, line 123

    #** Receive up to 4111 bytes, stopping when encountering the garbage terminator.

    BIP 324, line 124
  19. ↩ a b Rule Each side sends its 16-byte garbage terminator; the first encrypted packet in each direction authenticates the garbage sent as associated data, so a third party cannot modify it without consequence.

    Quoted source text (3)

    #** Send their 16-byte garbage terminator.

    BIP 324, line 123

    the first encrypted packet that will be sent in that direction (regardless of it being a decoy packet or not) will make use of the associated authenticated data (AAD) feature of the AEAD to authenticate the garbage that has been sent in that direction.

    BIP 324, line 127

    Without garbage authentication, the garbage would be modifiable by a third party without consequences.

    BIP 324, line 127
  20. ↩ a b Rule After the terminators, the responder and initiator each send a version packet with empty contents to indicate v2 support; other contents are reserved for future versions.

    Quoted source text (3)

    Sends a '''version packet''' with empty content, to indicate support for the v2 P2P protocol proposed by this document. Any other value for content is reserved for future versions.

    BIP 324, line 130

    Sends a '''version packet''' with empty content as well, to indicate support for the v2 P2P protocol.

    BIP 324, line 133

    Note that the version negotiation phase does not need to wait for the key exchange phase to complete; version packets can be sent immediately after sending the garbage terminator.

    BIP 324, line 149
  21. ↩ a b c d e f Rule A packet is a 3-byte encrypted length, then ChaCha20Poly1305 over a 1-byte header and the contents; a packet is 20 bytes plus its contents, which may be up to 2^24 - 1 bytes.

    Quoted source text (3)

    The total size of a packet is 20 bytes plus the length of its contents.

    BIP 324, line 157

    * A 3-byte encrypted '''length''' field, encoding the length of the '''contents''' (between ''0'' and ''224-1''

    BIP 324, lines 160–163

    * An authenticated encryption of the '''plaintext''', which consists of: ** A 1-byte '''header''' which consists of transport layer protocol flags. Currently, only the highest bit is defined as the '''ignore bit'''.

    BIP 324, lines 161–162
  22. ↩ a b c d e Rule Both ciphers rekey every 224 messages. The AEAD's nonce is the packet number within the epoch and the epoch number; its new key is the first 32 bytes of encrypting 32 zero bytes under the old key with the nonce's packet field set to 0xffffffff. The length cipher takes the next 32 bytes of its own keystream as its new key.

    Quoted source text (4)

    To provide re-keying every 224 packets, we specify two wrappers.

    BIP 324, line 414

    nonce = ((self.packet_counter % REKEY_INTERVAL).to_bytes(4, 'little') + (self.packet_counter // REKEY_INTERVAL).to_bytes(8, 'little'))

    BIP 324, lines 429–437

    if (self.packet_counter + 1) % REKEY_INTERVAL == 0: rekey_nonce = b"\xFF\xFF\xFF\xFF" + nonce[4:] self.key = aead_chacha20_poly1305_encrypt(self.key, rekey_nonce, b"", b"\x00" * 32)[:32]

    BIP 324, lines 435–437

    rekeying every 224 chunks using the next 32 bytes of the block function output as new key

    BIP 324, line 448
  23. ↩ a b c Test vector A v1 message header is 24 bytes (magic, command, length, checksum); a v2 packet adds 20 bytes plus a 1-byte type ID for listed types, 21 bytes in all, or 33 with a 13-byte type.

    Quoted source text (2)

    The total size of a packet is 20 bytes plus the length of its contents.

    BIP 324, line 157

    either a one byte ID in range ''1..255''

    BIP 324, line 528
  24. ↩ a b c Rule The length field is encrypted with a separate ChaCha20 stream but not covered by the Poly1305 tag; incorrect lengths still make the packet fail authentication.

    Quoted source text (3)

    The Poly1305 authentication tag only covers the encrypted plaintext, and not the encrypted length field.

    BIP 324, line 170

    as incorrect lengths will still trigger authentication failure for the overall packet (the plaintext length is implicitly authenticated by ChaCha20Poly1305).

    BIP 324, line 170

    * Length encryption keeps drawing pseudorandom bytes from the same ChaCha20 cipher for multiple packets, rather than incrementing the nonce for every packet.

    BIP 324, line 169
  25. ↩ a b Rule Application contents are a message type, a 1-byte ID or 0x00 plus the 12-byte ASCII type as in v1, followed by the message payload.

    Quoted source text (2)

    | <code>message_type</code> || 1 or 13 || either a one byte ID in range ''1..255'' or <code>b'\x00'</code> followed by a 12-byte ASCII message type (as in the v1 P2P protocol)

    BIP 324, line 528

    | <code>message_payload</code> || <code>message_length</code> || message payload

    BIP 324, line 530
  26. ↩ Author’s rationale Encrypting and authenticating a v2 message costs roughly as much as v1's truncated double-SHA256 checksum.

    Quoted source text (1)

    Each v1 P2P message uses a double-SHA256 checksum truncated to 4 bytes. Roughly the same amount of computation power is required for encrypting and authenticating a v2 P2P message as proposed.

    BIP 324, line 519
  27. ↩ a b Author’s rationale Rekeying gives forward secrecy within a session: an attacker who compromises current secrets cannot derive past keys; ECDH is not refreshed.

    Quoted source text (2)

    Re-keying ensures [https://eprint.iacr.org/2001/035.pdf forward secrecy within a session], i.e., an attacker compromising the current session secrets cannot derive past encryption keys in the same session.

    BIP 324, line 174

    We do not believe protecting against that is a priority

    BIP 324, line 174
  28. ↩ a b Rule The responder treats a connection as v1 if the first 16 bytes match the network magic followed by "version" and padding.

    Quoted source text (1)

    Waits until one byte is received which does not match the 16 bytes consisting of the network magic followed by "version\x00\x00\x00\x00\x00". If the first 16 bytes do match, the connection is treated as using the v1 protocol instead.

    BIP 324, line 115
  29. ↩ Rule v2 support is signalled with the NODE_P2P_V2 = (1 << 11) service flag; clients met with immediate disconnection are encouraged to retry with v1.

    Quoted source text (2)

    Peers supporting the v2 transport protocol signal support by advertising the <code>NODE_P2P_V2 = (1 << 11)</code> service flag in addr relay. If met with immediate disconnection when establishing a v2 connection, clients implementing this proposal are encouraged to retry connecting using the v1 protocol.

    BIP 324, line 581

    An untrusted intermediary could falsely advertise a potential peer as supportive of v2 connections.

    BIP 324, line 581
  30. ↩ History BIP 324 (Mehta, Ruffing, Schnelli, Wuille), a Peer Services specification assigned in 2019, is recorded as Deployed and replaces BIP 151.

    Quoted source text (1)

    Layer: Peer Services Title: Version 2 P2P Encrypted Transport Protocol Authors: Dhruv Mehta <dhruv@bip324.com> Tim Ruffing <crypto@timruffing.de> Jonas Schnelli <dev@jonasschnelli.ch> Pieter Wuille <bitcoin-dev@wuille.net> Status: Deployed Type: Specification Assigned: 2019-03-08 License: BSD-3-Clause Version: 1.0.2 Replaces: 151

    BIP 324, lines 3–14