|
| 1 | +--- |
| 2 | +tags: spec |
| 3 | +--- |
| 4 | + |
| 5 | +# MEV-Geth v0.1 specification |
| 6 | + |
| 7 | +## Simple Summary |
| 8 | + |
| 9 | +Defines the construction and usage of MEV bundles by the miners. Provides specification for custom implementation of required node changes so that MEV bundles can be used correctly. |
| 10 | + |
| 11 | +## Abstract |
| 12 | + |
| 13 | +`MevBundles` are stored by the node and the best bundle is added to the block in front of other transactions. `MevBundles` are sorted by their `adjusted gas price`. |
| 14 | + |
| 15 | +## Motivation |
| 16 | + |
| 17 | +We believe that without the adoption of neutral, public, open-source infrastructure for permissionless MEV extraction, MEV risks becoming an insiders' game. We commit as an organisation to releasing reference implementations for participation in fair, ethical, and politically neutral MEV extraction. |
| 18 | + |
| 19 | +## Specification |
| 20 | + |
| 21 | +The key words `MUST`, `MUST NOT`, `REQUIRED`, `SHALL`, `SHALL NOT`, `SHOULD`, `SHOULD NOT`, `RECOMMENDED`, `MAY`, and `OPTIONAL` in this document are to be interpreted as described in [RFC-2119](https://www.ietf.org/rfc/rfc2119.txt). |
| 22 | + |
| 23 | +### Definitions |
| 24 | + |
| 25 | +#### `Bundle` |
| 26 | +A set of transactions that `MUST` be executed together and `MUST` be executed at the beginning of the block. |
| 27 | + |
| 28 | +#### `Unit of work` |
| 29 | +A `transaction`, a `bundle` or a `block`. |
| 30 | + |
| 31 | +#### `Subunit` |
| 32 | +A discernible `unit of work` that is a part of a bigger `unit of work`. A `transaction` is a `subunit` of a `bundle` or a `block`. A `bundle` is a `subunit` of a `block`. |
| 33 | + |
| 34 | +#### `Total gas used` |
| 35 | +A sum of gas units used by each transaction from the `unit of work`. |
| 36 | + |
| 37 | +#### `Average gas price` |
| 38 | +Sum of (`gas price` * `total gas used`) of all `subunits` divided by the `total gas used` of the unit. |
| 39 | + |
| 40 | +#### `Direct coinbase payment` |
| 41 | +A value of a transaction with a recipient set to be the same as the `coinbase` address. |
| 42 | + |
| 43 | +#### `Contract coinbase payment` |
| 44 | +A payment from a smart contract to the `coinbase` address. |
| 45 | + |
| 46 | +#### `Profit` |
| 47 | +A difference between the balance of the `coinbase` account at the end and at the beginning of the execution of a `unit of work`. We can measure a `transaction profit`, a `bundle profit`, and a `block profit`. |
| 48 | + |
| 49 | +Balance of the `coinbase` account changes in the following way |
| 50 | +|Unit of work|Balance Change| |
| 51 | +|-|-| |
| 52 | +|Transaction| `average gas price` * `total gas used` + `direct coinbase payment` + `contract coinbase payment` | |
| 53 | +|Bundle | `average gas price` * `total gas used` + `direct coinbase payment` + `contract coinbase payment` | |
| 54 | +|Block | `block reward` + `average gas price` * `total gas used` + `direct coinbase payment` + `contract coinbase payment` | |
| 55 | + |
| 56 | +#### `Adjusted gas price` |
| 57 | +`Unit of work` `profit` divided by the `total gas used` by the `unit of work`. |
| 58 | + |
| 59 | +#### `MevBundle` |
| 60 | +An object with four properties: |
| 61 | + |
| 62 | +|Property| Type|Description| |
| 63 | +|-|-|-| |
| 64 | +|`transactions`|`Array<RLP(SignedTransaction)>`|A list of transactions in the bundle. Each transaction is signed and RLP-encoded.| |
| 65 | +|`blockNumber`|`uint64`|The exact block number at which the bundle can be executed| |
| 66 | +|`minTimestamp`|`uint64`|Minimum block timestamp (inclusive) at which the bundle can be executed| |
| 67 | +|`maxTimestamp`|`uint64`|Maximum block timestamp (inclusive) at which the bundle can be executed| |
| 68 | + |
| 69 | +### Bundle construction |
| 70 | + |
| 71 | +Bundle `SHOULD` contain transactions with nonces that are following the current nonces of the signing addresses or other transactions preceding them in the same bundle. |
| 72 | + |
| 73 | +A bundle `MUST` contain at least one transaction. There is no upper limit for the number of transactions in the bundle, however bundles that exceed the block gas limit will always be rejected. |
| 74 | + |
| 75 | +A bundle `MAY` include a `direct coinbase payment` or a `contract coinbase payment`. Bundles that do not contain such payments may lose comparison when their `profit` is compared with other bundles. |
| 76 | + |
| 77 | +The `maxTimestamp` value `MUST` be greater or equal the `minTimestamp` value. |
| 78 | + |
| 79 | +### Accepting bundles from the network |
| 80 | + |
| 81 | +Node `MUST` provide a way of exposing a JSON RPC endpoint accepting `eth_sendBundle` calls (specified [here](MEV_spec_RPC_v0_1.md)). Such endpoint `SHOULD` only be accepting calls from `MEV-relay` but there is no requirement to restrict it through the node source code as it can be done on the infrastructure level. |
| 82 | + |
| 83 | +### Bundle eligibility |
| 84 | + |
| 85 | +Any bundle that is correctly constructed `MUST` have a `blockNumber` field set which specifies in which block it can be included. If the node has already progressed to a later block number then such bundle `MAY` be removed from memory. |
| 86 | + |
| 87 | +Any bundle that is correctly constructed `MAY` have a `minTimestamp` and/or a `maxTimestamp` field set. Default values for both of these fields are `0` and the meaning of `0` is that any block timestamp value is accepted. When these values are not `0`, then `block.timestamp` is compared with them. If the current `block.timestamp` is greater than the `maxTimestamp` then the bundle `MUST NOT` be included in the block and `MAY` be removed from memory. If the `block.timestamp` is less than `minTimestamp` then the bundle `MUST NOT` be included in the block and `SHOULD NOT` be removed from memory (it awaits future blocks). |
| 88 | + |
| 89 | +### Block construction |
| 90 | + |
| 91 | +A block `MUST` either contain one bundle or no bundles. When a bundle is included it `MUST` be the bundle with the highest `adjusted gas price` among eligible bundles. The node `SHOULD` be able to compare a `block profit` in cases when a bundle is included (MEV block) and when no bundles are included (regular block) and choose a block with the highest `profit`. |
| 92 | + |
| 93 | +A block with a bundle `MUST` place the bundle at the beginning of the block and `MUST NOT` insert any transactions between the bundle transactions. |
| 94 | + |
| 95 | +### Bundle eviction |
| 96 | + |
| 97 | +Node `SHOULD` be able to limit the number of bundles kept in memory and apply an algorithm for selecting bundles to be evicted when too many eligible bundles have been received. |
| 98 | + |
| 99 | +## Rationale |
| 100 | + |
| 101 | +### At most one MevBundle gets included in the block |
| 102 | + |
| 103 | +There are two reasons for which multiple bundles in a block may cause problems: |
| 104 | + |
| 105 | +- two bundles may affect each other's `profit` and so the bundle creator may not be willing to accept a possibility of not being added in the front of the block |
| 106 | +- simulating multiple bundle combinations may be very straining for the node infrastructure and introduce excessive latency into the block creation process |
| 107 | + |
| 108 | +Both of these problems may be addressed in the future versions. |
| 109 | + |
| 110 | +## Each bundle needs a blockNumber |
| 111 | + |
| 112 | +This allows specifying bundles to be included in the future blocks (e.g. just after some smart contracts change their state). This cannot be used to ensure a specific parent block / hash. |
| 113 | + |
| 114 | +## Backwards Compatibility |
| 115 | + |
| 116 | +This change is not affecting consensus and is fully backwards compatible. |
| 117 | + |
| 118 | +## Security Considerations |
| 119 | + |
| 120 | +`MevBundles` that are awaiting future blocks must be stored by the miner's node and it is important to ensure that there is a mechanism to ensure that the storage is limits are not exceeded (whether they are store in memory or persisted). |
0 commit comments