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 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
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
Exact values
- ElligatorSwift encoding (64 bytes)
ec0adff257bbfe500c188c80b4fdd640f6b45a482bbc15fc7cef5931deff0aa186f6eb9bba7b85dc4dcc28b28722de1e3d9108b985e2967045668f66098e475b- x coordinate of the public key
19e965bc20fc40614e33f2f82d4eeff81b5e7516b12a5c6c0d6053527eba0923
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.
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
6aa28bfa1cdc7eb99581c48ff2898ef92d3aa1
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.
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
Exact bytes
- Packet
7530d2a18720162ac09c25329a60d75adf36eda3c3- Nonce
010000000000000000000000
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
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
Exact nonces and keys
- Packet 0 (epoch 0)
000000000000000000000000fdf5a3e3e75afc15a924373e58af505052731efa75c76a1fa3546954d60b50b1- Packet 1 (epoch 0)
010000000000000000000000fdf5a3e3e75afc15a924373e58af505052731efa75c76a1fa3546954d60b50b1- Packet 222 (epoch 0)
de0000000000000000000000fdf5a3e3e75afc15a924373e58af505052731efa75c76a1fa3546954d60b50b1- Packet 223 (epoch 0)
df0000000000000000000000fdf5a3e3e75afc15a924373e58af505052731efa75c76a1fa3546954d60b50b1- Packet 224 (epoch 1)
0000000001000000000000009eae3d0883a0713e8d97f44346027aa7f0dd1c6d65f7b97a08a676fe9bf6bd32- Packet 447 (epoch 1)
df00000001000000000000009eae3d0883a0713e8d97f44346027aa7f0dd1c6d65f7b97a08a676fe9bf6bd32- Packet 448 (epoch 2)
0000000002000000000000007bf2eccbbf396d1b84ad8ac01d96f7a236664d34f7db8517f8ff8fa3bfc290ff
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
Exact bytes
- v1 prefix
f9beb4d976657273696f6e0000000000- v2 initiator's first 16 bytes (Packet 1, initiator)
ec0adff257bbfe500c188c80b4fdd640
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
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.
-
↩ 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.
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.
-
↩ 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.
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
-
↩ 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.
-
↩ 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.
-
↩ 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.
BIP 324 L3 BIP 324 L523 BIP 324 L528
Quoted source text (3)
Layer: Peer Services
An unencrypted application layer '''contents''' is composed of:
a 12-byte ASCII message type (as in the v1 P2P protocol)
-
↩ 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.
BIP 324 L34 BIP 324 L34 BIP 324 L34
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.
even very basic checks, e.g., operators manually comparing protocol versions and session IDs (as supported by the proposed protocol), will expose the attacker.
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
-
↩ 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
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.
-
↩ 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.
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
-
↩ 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.
-
↩ 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.
BIP 324 L81 BIP 324 L83 BIP 324 L85 BIP 324 L87 BIP 324 L84
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.
* 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.
* 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.
* Compatibility: v2 clients will allow inbound v1 connections to minimize risk of network partitions.
* Shapable bytestream: It should be possible to shape the bytestream to increase resistance to traffic analysis (for example, to conceal block propagation)
-
↩ 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.
How and when to use them is out of scope for this document.
-
↩ 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.
BIP 324 L62 BIP 324 L64 BIP 324 L70–73 BIP 324 L72 BIP 324 L73 BIP 324 L75
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.
The primary requirement which existing protocols fail to meet is a sufficiently modular treatment of encryption and authentication.
* Neither offers a pseudorandom bytestream. * Neither offers native support for elliptic curve cryptography on the curve secp256k1 as otherwise used in Bitcoin.
* Neither offers shapability of the bytestream.
* Both provide a stream-based interface to the application layer, whereas Bitcoin requires a packet-based interface
this would negate the benefits of using them as off-the-shelf solution
-
↩ 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
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.
-
↩ 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)
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.
-
↩ 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:]
-
↩ 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.
May send up to 4095
-
↩ 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.
-
↩ 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.
#** Receive up to 4111 bytes, stopping when encountering the garbage terminator.
-
↩ 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.
BIP 324 L123 BIP 324 L127 BIP 324 L127
Quoted source text (3)
#** Send their 16-byte garbage terminator.
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.
Without garbage authentication, the garbage would be modifiable by a third party without consequences.
-
↩ 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.
BIP 324 L130 BIP 324 L133 BIP 324 L149
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.
Sends a '''version packet''' with empty content as well, to indicate support for the v2 P2P protocol.
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.
-
↩ 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.
BIP 324 L157 BIP 324 L160–163 BIP 324 L161–162
Quoted source text (3)
The total size of a packet is 20 bytes plus the length of its contents.
* A 3-byte encrypted '''length''' field, encoding the length of the '''contents''' (between ''0'' and ''224-1''
* 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'''.
-
↩ 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.
BIP 324 L414 BIP 324 L429–437 BIP 324 L435–437 BIP 324 L448
Quoted source text (4)
To provide re-keying every 224 packets, we specify two wrappers.
nonce = ((self.packet_counter % REKEY_INTERVAL).to_bytes(4, 'little') + (self.packet_counter // REKEY_INTERVAL).to_bytes(8, 'little'))
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]
rekeying every 224 chunks using the next 32 bytes of the block function output as new key
-
↩ 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.
either a one byte ID in range ''1..255''
-
↩ 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.
BIP 324 L170 BIP 324 L170 BIP 324 L169
Quoted source text (3)
The Poly1305 authentication tag only covers the encrypted plaintext, and not the encrypted length field.
as incorrect lengths will still trigger authentication failure for the overall packet (the plaintext length is implicitly authenticated by ChaCha20Poly1305).
* Length encryption keeps drawing pseudorandom bytes from the same ChaCha20 cipher for multiple packets, rather than incrementing the nonce for every packet.
-
↩ 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)
| <code>message_payload</code> || <code>message_length</code> || message payload
-
↩ 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.
-
↩ 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.
We do not believe protecting against that is a priority
-
↩ 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.
-
↩ 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.
An untrusted intermediary could falsely advertise a potential peer as supportive of v2 connections.
-
↩ 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