EIP-778 · Final · Networking · 2017-11-23
EIP-778: Ethereum Node Records (ENR)
Ethereum Node Records (ENR) are a signed, versioned, extensible key/value format for a node's identity and network addresses, now used by discovery on both execution and consensus clients.
What problem does it solve?
Ethereum nodes find each other through a discovery protocol. The original Node Discovery v4 could relay only a fixed set of facts about a node: its secp256k1 public key, one IP address and two ports. There was no room for IPv6 alongside IPv4, other transports, other key types, or hints about which network or fork a node follows. A peer also had no good way to tell which of two announcements for the same node was newer.
ENR defines a flexible, signed node record that any channel can carry: a discovery protocol, DNS, a devp2p subprotocol and so on. Anyone holding the record can verify it, and it can be updated with clear ordering.
How it works
A record contains:
signature, made over the record's contentsseq, a 64-bit sequence number that the node increments each time it republishes a changed record- key/value pairs, sorted by key and unique
Predefined keys:
| Key | Value |
|---|---|
id |
Identity scheme name, e.g. "v4" (the only required key) |
secp256k1 |
Compressed public key, 33 bytes |
ip / ip6 |
IPv4 (4 bytes) / IPv6 (16 bytes) address |
tcp / udp |
Ports, big-endian integers |
tcp6 / udp6 |
IPv6-specific ports; if absent, tcp / udp apply to both |
Anyone can add other keys. Clients keep keys they do not understand.
Encoding. The canonical form is the RLP list [signature, seq, k, v, ...], at most 300 bytes. The text form is enr: followed by URL-safe base64 of the RLP, without padding.
The "v4" identity scheme. Sign keccak256(rlp([seq, k, v, ...])) with secp256k1 and store the 64-byte r || s signature, with no recovery id. To verify, check the signature against the secp256k1 key in the record. The node ID is the keccak256 hash of the uncompressed public key.
Sample code
The spec's test vector, a record for 127.0.0.1 with UDP port 30303 and seq = 1:
enr:-IS4QHCYrYZbAKWCBRlAy5zzaDZXJBGkcnh4MHcBFZntXNFrdvJjX04jRzjzCBOonrkTfj499SZuOh8R33Ls8RRcy5wBgmlkgnY0gmlwhH8AAAGJc2VjcDI1NmsxoQPKY0yuDUmstAHYpMa2_oxVtw0RW_QAdpzBQA8yWM0xOIN1ZHCCdl8
Decoded RLP structure:
[
7098ad86...5ccb9c, # 64-byte signature
01, # seq
"id", "v4",
"ip", 7f000001,
"secp256k1", 03ca634c...58cd3138,
"udp", 765f # 30303
]
Building and signing a record (pseudocode):
pairs = sorted({"id": b"v4", "secp256k1": pubkey33, "ip": ip4, "udp": port}.items())
content = [seq] + [x for kv in pairs for x in kv]
sig = secp256k1_sign(keccak256(rlp(content)), privkey)[:64] # r || s
record = rlp([sig] + content)
assert len(record) <= 300
text = "enr:" + base64url_nopad(record)
Things to know
- Node Discovery v4 gained ENR support through EIP-868. EIP-1459 distributes node lists as ENRs over DNS.
- Discovery v5 is built around ENRs. Consensus-layer clients use them for peer discovery and add their own keys for fork and subnet information.
- New keys need no coordination. New identity schemes do, because peers must be able to verify the signature.
- Always increase
seqwhen anything in the record changes. Peers keep the record with the highestseq.