|
| 1 | +# Ethereum Witness Protocol (wit) |
| 2 | + |
| 3 | +The `wit` protocol runs on top of [RLPx], facilitating the exchange of Ethereum state |
| 4 | +witnesses between peers. The protocol is an optional extension for peers supporting (or |
| 5 | +caring about) the state witnesses for Ethereum blocks. |
| 6 | + |
| 7 | +The current version is `wit/0`. |
| 8 | + |
| 9 | +### Overview |
| 10 | + |
| 11 | +The `wit` protocol is designed to assist clients in syncing up to the tip of the chain. |
| 12 | +Eventually, it also aspires to assist in stateless client operation. The `wit` protocol |
| 13 | +does not take part in chain maintenance (block and transaction propagation); and it is |
| 14 | +**meant to be run side-by-side with the `eth` protocol**, not standalone (e.g. chain |
| 15 | +progression is announced via `eth`). (like the `snap` protocol) |
| 16 | + |
| 17 | +Despite the name, version 0 will not provide actual witnesses. It will provide meta-data |
| 18 | +about the witness, which can be used to download the witness over the `eth` protocol. |
| 19 | + |
| 20 | +For now, the known use case is to assist [Beam Syncing] peers. By requesting witness |
| 21 | +metadata, these peers will keep up with the tip of the network and become fully-synced |
| 22 | +nodes faster. |
| 23 | + |
| 24 | +Using the `wit` protocol, peers ask each other for the list of trie node hashes read |
| 25 | +during the execution of a particular block. This includes the following data: |
| 26 | + |
| 27 | +- Storage nodes |
| 28 | +- Bytecodes |
| 29 | +- Account nodes |
| 30 | + - Read during EVM execution |
| 31 | + - Read during transaction validation |
| 32 | + - Read during block reward calculation |
| 33 | +- Nodes read when generating the final state root (i.e. sometimes deleting data requires a |
| 34 | + trie refactor that reads nearby trie nodes) |
| 35 | + |
| 36 | +The trie node hashes which are generated at the end of the block from existing data are |
| 37 | +*not* included. For example, the final state root hash is not included. |
| 38 | + |
| 39 | +## Relation to `eth` |
| 40 | + |
| 41 | +The `wit` protocol follows the same pattern as `snap`. It is a *dependent satellite* of |
| 42 | +`eth` (i.e. to run `wit`, you need to run `eth` too), not a fully standalone protocol. |
| 43 | +This is a deliberate design decision: |
| 44 | + |
| 45 | +- `wit` is meant to be a bootstrap aid for newly joining full nodes. By enforcing all |
| 46 | + `wit` peers to also speak `eth`, we can avoid non-full nodes from lingering attached to |
| 47 | + `wit` indefinitely. |
| 48 | +- `eth` already contains well established chain and fork negotiation mechanisms, as well |
| 49 | + as remote peer staleness detection during sync. By running both protocols side-by-side, |
| 50 | + `wit` can benefit of all these mechanisms without having to duplicate them. |
| 51 | + |
| 52 | +This *satellite* status may be changed later, but it's better to launch with a more |
| 53 | +restricted protocol first and then expand if need be vs. trying to withdraw depended-upon |
| 54 | +features. |
| 55 | + |
| 56 | +In order to follow the `wit` protocol, clients must generate witness metadata when |
| 57 | +executing blocks. For now, its primary purpose is also one specific sync method that might |
| 58 | +not be suitable for all clients. Keeping `wit` as a separate protocol permits every client |
| 59 | +to decide to pursue it or not, without hindering their capacity to participate in the |
| 60 | +`eth` protocol. |
| 61 | + |
| 62 | +## Accelerating Beam Sync |
| 63 | + |
| 64 | +At its most naive, Beam Sync needs to download any missing state one trie node at a time. |
| 65 | +According to a recent test, after Beam Syncing for 22 hours, the median block still |
| 66 | +required more than 300 new trie nodes. At an optimistic 100ms round-trip time, that means |
| 67 | +30 seconds per block of data download. This is where witness metadata can help |
| 68 | +tremendously. |
| 69 | + |
| 70 | +If a client can request the trie node hashes used by a block up front, those 300 trie |
| 71 | +nodes can likely be accessed in a fraction of a second. That's easily enough to keep |
| 72 | +synced with mainnet. |
| 73 | + |
| 74 | +Unfortunately, the list of trie node hashes cannot be verified before the block is |
| 75 | +imported. This would be a huge problem for a stateless client, which would be permanently |
| 76 | +at risk to a DoS attack where peers feed it a long list of incorrect hashes. But Beam |
| 77 | +Syncing clients are only vulnerable until they've finished downloading the full network |
| 78 | +state, so the payoff for such an attack is smaller. |
| 79 | + |
| 80 | +## Protocol Messages |
| 81 | + |
| 82 | +### RESERVED (0x00) |
| 83 | + |
| 84 | +This command is undefined, held in place for a possible future Status message. |
| 85 | + |
| 86 | +### GetBlockWitnessHashes (0x01) |
| 87 | + |
| 88 | +`[reqID: P, blockHash: B_32]` |
| 89 | + |
| 90 | +Requests a list of trie node hashes used by a given block. |
| 91 | + |
| 92 | +- `reqID`: Request ID to match up responses with |
| 93 | +- `blockHash`: Hash of the header to request the witness hashes for |
| 94 | + |
| 95 | +Notes: |
| 96 | + |
| 97 | +- Nodes **must** always respond to the query. |
| 98 | +- If the node does **not** have the trie hashes requested block, it **must** return an |
| 99 | + empty reply. |
| 100 | + |
| 101 | +### BlockWitnessHashes (0x02) |
| 102 | + |
| 103 | +`[reqID: P, witnessHashes: [trieNodeHash: B_32, ...]]` |
| 104 | + |
| 105 | +Returns a list of the trie node hashes that were read during execution and validation of |
| 106 | +the given block. |
| 107 | + |
| 108 | +- `reqID`: ID of the request this is a response for |
| 109 | +- `witnessHashes`: List of trie node hashes |
| 110 | + |
| 111 | +## Change Log |
| 112 | + |
| 113 | +### wit/0 (October 2020) |
| 114 | + |
| 115 | +Version 0 was the introduction of the witness protocol. |
| 116 | + |
| 117 | +[RLPx]: ../rlpx.md |
| 118 | +[Beam Syncing]: https://github.com/ethereum/stateless-ethereum-specs/blob/master/beam-sync-phase0.md |
0 commit comments