Skip to content

Latest commit

 

History

History
249 lines (184 loc) · 12.9 KB

zip-0155.rst

File metadata and controls

249 lines (184 loc) · 12.9 KB
ZIP: 155
Title: addrv2 message
Owners: Daira Hopwood <daira@electriccoin.co>
Credits: Wladimir J. van der Laan
         Zancas Wilcox
Status: Proposed
Category: Network
Created: 2021-08-13
License: BSD-2-Clause
Discussions-To: <https://github.com/zcash/zips/issues/542>
Pull-Request: <https://github.com/zcash/zips/pull/543>

Terminology

The key words "MUST", "MUST NOT", "SHOULD", "SHOULD NOT", and "MAY" in this document are to be interpreted as described in RFC 2119.1

The term "network upgrade" in this document is to be interpreted as described in ZIP 200.2

The terms "Testnet" and "Mainnet" are to be interpreted as described in section 3.11 of the Zcash Protocol Specification3.

"P2P network" means the Zcash peer-to-peer network.

uint8, uint16, and uint32 denote unsigned integer data types of the corresponding length (8, 16, or 32 bits respectively).

Abstract

This document proposes a new P2P message to gossip longer node addresses over the P2P network. This is required to support new-generation onion addresses, I2P, and potentially other networks that have longer endpoint addresses than fit in the 128 bits of the current addr message.

Motivation

Tor v3 onion services are part of the stable release of Tor since version 0.3.2.9. They have various advantages compared to the old v2 onion services, among which better encryption and privacy4. These services have 256-bit addresses and thus do not fit in the existing addr message (unchanged from Bitcoin 5), which encapsulates onion addresses in OnionCat IPv6 addresses.

Other transport-layer protocols such as I2P have always used longer addresses. This change would make it possible to gossip such addresses over the P2P network, so that other peers can connect to them.

Specification

The addrv2 message is defined as a message where the command field is (NUL-padded) "addrv2". It is serialized in the standard encoding for P2P messages. Its format is similar to the current addr message format described in 6, with the difference that the fixed 16-byte IP address is replaced by a network ID and a variable-length address, and the services format has been changed to7.

This means that the message contains a serialized vector of the following structure:

Bytes Name Data Type Description
4 time uint32 Time that this node was last seen as connected to the network. A time in Unix epoch time format.
varies services CompactSize Service bits. A CompactSize-encoded bit field that is 64 bits wide.
1 networkID uint8 Network identifier. An 8-bit value that specifies which network is addressed.
varies sizeAddr CompactSize The length in bytes of addr.
sizeAddr addr uint8[sizeAddr] Network address. The interpretation depends on networkID.
2 port uint16 Network port. If not relevant for the network this MUST be 0.

One message can contain up to 1,000 addresses. Clients MUST reject messages with more addresses.

Field addr has a variable length, with a maximum of 512 bytes (4096 bits). Clients MUST reject messages with a longer addr field, irrespective of the network ID.

The list of reserved network IDs is as follows:

Network ID Enumeration Address length (bytes) Description
0x01 IPV4 4 IPv4 address (globally routed internet)
0x02 IPV6 16 IPv6 address (globally routed internet)
0x04 TORV3 32 Tor v3 onion service address
0x05 I2P 32 I2P overlay network address
0x06 CJDNS 16 Cjdns overlay network address

Network ID 0x03 is intentionally not assigned. In BIP 1558 it was assigned to Tor v2 onion addresses, but those addresses are no longer supported by the latest Tor client code, and MUST NOT be used once this ZIP is deployed.

Clients SHOULD gossip valid, potentially routable addresses from all known networks, even if they are currently not connected to some of them. That could help multi-homed nodes and make it more difficult for an observer to tell which networks a node is connected to.

Clients MUST NOT gossip addresses from unknown networks, because they have no means to validate those addresses and so can be tricked to gossip invalid addresses.

Clients MUST reject messages that contain addresses that have a different length than specified in this table for a specific network ID, as these are meaningless.

Network address encodings

The IPV4 and IPV6 network IDs use addresses encoded in the usual way for binary IPv4 and IPv6 addresses in network byte order (big endian).

Tor v3 address encoding

According to the spec9, version 3 .onion addresses are encoded as follows:

onion_address = base32(PUBKEY || CHECKSUM || VERSION) + ".onion"
CHECKSUM = H(".onion checksum" || PUBKEY || VERSION)[:2]  // first 2 bytes

where:

  • PUBKEY is the 32-byte Ed25519 master pubkey of the onion service;
  • VERSION is a one-byte version field (default value 0x03);
  • ".onion" and ".onion checksum" are constant strings;
  • CHECKSUM is truncated to two bytes before inserting it in onion_address;
  • H() is the SHA3-256 cryptographic hash function.10

Tor v3 addresses MUST be sent with the TORV3 network ID, with the 32-byte PUBKEY part in the addr field. As VERSION will always be 0x03 in the case of v3 addresses, this is enough to reconstruct the onion address.

I2P address encoding

Like Tor, I2P naming uses a base32-encoded address format11.

I2P uses 52 characters (256 bits) to represent the full SHA-256 hash, followed by .b32.i2p. The base32 encoding does not include "=" padding characters.

I2P addresses MUST be sent with the I2P network ID, with the decoded SHA-256 hash as address field.

Cjdns address encoding

Cjdns addresses are simply IPv6 addresses in the fc00::/8 range 12. They MUST be sent with the CJDNS network ID. They are encoded in network byte order (big endian) as for the IPV6 network ID.

Deployment

Support for this specification is signalled by peer protocol version 170015 (on both Testnet and Mainnet). Note that this is the same peer protocol version that signals support for NU5 on Mainnet13.

Nodes that have not negotiated peer protocol version 170015 or higher on a given connection, MUST NOT send addrv2 messages on that connection.

A node that has negotiated peer protocol version 170015 or higher on a given connection, MAY still send addr messages on the connection, and MUST handle received addr messages as it would have done prior to this ZIP.

Rationale

This ZIP is closely based on BIP 15514, with the following changes:

  • Deployment: support for the addrv2 message is signalled by advertising a peer protocol version of 170015 or higher, not by sending a sendaddrv2 message. This is motivated by a desire to avoid an exponential explosion in the space of possible feature configurations in a given peer-to-peer connection. In Zcash, unlike Bitcoin, the space of such configurations is effectively constant no matter how many peer-to-peer protocol changes are made, because nodes that do not support a given peer protocol version will drop off the network over time if they do not support the latest Network Upgrade. The feature configuration for a given connection is also established at version negotiation, and cannot change after that point without reconnecting. Other peer-to-peer protocol changes ported from the Bitcoin peer-to-peer protocol, for example the MSG_WTX inv type defined in ZIP 23915, have taken the same approach to signalling.
  • No Network ID for Tor v2 onion addresses: the Tor network is expected to have removed support for these addresses in the timeframe for deployment of this ZIP.
  • Clients MUST, rather than SHOULD, reject addrv2 messages with more than 1,000 addresses. Making this a consistent requirement promotes interoperability.
  • Clients MUST NOT, rather than SHOULD NOT, gossip addresses from unknown networks.
  • Clients MUST, rather than SHOULD, reject messages that contain addresses that have a different length than specified for a known network ID, or a length greater than the 512-byte maximum for an unknown network ID.

Reference implementation

TBD.

Acknowledgements

This ZIP is closely based on BIP 15516, written by Wladimir J. van der Laan. Zancas Wilcox ported the implementation for Zcashd.

Acknowledgements for BIP 155:

  • Jonas Schnelli: change services field to CompactSize, to make the message more compact in the likely case instead of always using 8 bytes.
  • Gregory Maxwell: various suggestions regarding extensibility.

References


  1. RFC 2119: Key words for use in RFCs to Indicate Requirement Levels

  2. ZIP 200: Network Upgrade Mechanism

  3. Zcash Protocol Specification, Version 2020.2.14 [NU5 proposal]. Section 3.12 Mainnet and Testnet

  4. Tor Rendezvous Specification - Version 3

  5. Protocol documentation: addr. Bitcoin Wiki

  6. Protocol documentation: addr. Bitcoin Wiki

  7. Variable length integer. Bitcoin Wiki

  8. BIP 155: addrv2 message

  9. Tor Rendezvous Specification - Version 3

  10. NIST FIPS 202 - SHA-3 Standard: Permutation-Based Hash and Extendable-Output Functions

  11. I2P: Naming and address book

  12. Cjdns whitepaper: Pulling It All Together

  13. ZIP 252: Deployment of the NU5 Network Upgrade

  14. BIP 155: addrv2 message

  15. ZIP 239: Relay of Version 5 Transactions

  16. BIP 155: addrv2 message