|
| 1 | +# The Verge -- The Beacon Chain |
| 2 | + |
| 3 | +## Table of contents |
| 4 | + |
| 5 | +<!-- TOC --> |
| 6 | +<!-- START doctoc generated TOC please keep comment here to allow auto update --> |
| 7 | +<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> |
| 8 | + |
| 9 | +- [Introduction](#introduction) |
| 10 | +- [Custom types](#custom-types) |
| 11 | +- [Preset](#preset) |
| 12 | + - [Execution](#execution) |
| 13 | +- [Containers](#containers) |
| 14 | + - [Extended containers](#extended-containers) |
| 15 | + - [`ExecutionPayload`](#executionpayload) |
| 16 | + - [`ExecutionPayloadHeader`](#executionpayloadheader) |
| 17 | + - [New containers](#new-containers) |
| 18 | + - [`SuffixStateDiff`](#suffixstatediff) |
| 19 | + - [`StemStateDiff`](#stemstatediff) |
| 20 | + - [`IPAProof`](#ipaproof) |
| 21 | + - [`VerkleProof`](#verkleproof) |
| 22 | + - [`ExecutionWitness`](#executionwitness) |
| 23 | +- [Beacon chain state transition function](#beacon-chain-state-transition-function) |
| 24 | + - [Execution engine](#execution-engine) |
| 25 | + - [`notify_new_payload`](#notify_new_payload) |
| 26 | + - [Block processing](#block-processing) |
| 27 | + - [Execution payload](#execution-payload) |
| 28 | + - [`process_execution_payload`](#process_execution_payload) |
| 29 | +- [Testing](#testing) |
| 30 | + |
| 31 | +<!-- END doctoc generated TOC please keep comment here to allow auto update --> |
| 32 | +<!-- /TOC --> |
| 33 | + |
| 34 | +## Introduction |
| 35 | + |
| 36 | +This upgrade adds transaction execution to the beacon chain as part of the Verge upgrade. |
| 37 | + |
| 38 | +## Custom types |
| 39 | + |
| 40 | +| Name | SSZ equivalent | Description | |
| 41 | +| - | - | - | |
| 42 | +| `StateDiff` | `List[StemStateDiff, MAX_STEMS]` | Only valid if list is sorted by stems | |
| 43 | +| `BandersnatchGroupElement` | `Bytes32` | | |
| 44 | +| `BandersnatchFieldElement` | `Bytes32` | | |
| 45 | +| `Stem` | `Bytes31` | | |
| 46 | + |
| 47 | +## Preset |
| 48 | + |
| 49 | +### Execution |
| 50 | + |
| 51 | +| Name | Value | |
| 52 | +| - | - | |
| 53 | +| `MAX_STEMS` | `2**16` | |
| 54 | +| `MAX_COMMITMENTS_PER_STEM` | `33` | |
| 55 | +| `VERKLE_WIDTH` | `256` | |
| 56 | +| `IPA_PROOF_DEPTH` | `8` | |
| 57 | + |
| 58 | +## Containers |
| 59 | + |
| 60 | +### Extended containers |
| 61 | + |
| 62 | +#### `ExecutionPayload` |
| 63 | + |
| 64 | +```python |
| 65 | +class ExecutionPayload(Container): |
| 66 | + # Execution block header fields |
| 67 | + parent_hash: Hash32 |
| 68 | + fee_recipient: ExecutionAddress # 'beneficiary' in the yellow paper |
| 69 | + state_root: Bytes32 |
| 70 | + receipts_root: Bytes32 |
| 71 | + logs_bloom: ByteVector[BYTES_PER_LOGS_BLOOM] |
| 72 | + prev_randao: Bytes32 # 'difficulty' in the yellow paper |
| 73 | + block_number: uint64 # 'number' in the yellow paper |
| 74 | + gas_limit: uint64 |
| 75 | + gas_used: uint64 |
| 76 | + timestamp: uint64 |
| 77 | + extra_data: ByteList[MAX_EXTRA_DATA_BYTES] |
| 78 | + base_fee_per_gas: uint256 |
| 79 | + block_hash: Hash32 # Hash of execution block |
| 80 | + # Extra payload field |
| 81 | + execution_witness: ExecutionWitness |
| 82 | + transactions: List[Transaction, MAX_TRANSACTIONS_PER_PAYLOAD] |
| 83 | +``` |
| 84 | + |
| 85 | +#### `ExecutionPayloadHeader` |
| 86 | + |
| 87 | +```python |
| 88 | +class ExecutionPayloadHeader(Container): |
| 89 | + # Execution block header fields |
| 90 | + parent_hash: Hash32 |
| 91 | + fee_recipient: ExecutionAddress |
| 92 | + state_root: Bytes32 |
| 93 | + receipts_root: Bytes32 |
| 94 | + logs_bloom: ByteVector[BYTES_PER_LOGS_BLOOM] |
| 95 | + prev_randao: Bytes32 |
| 96 | + block_number: uint64 |
| 97 | + gas_limit: uint64 |
| 98 | + gas_used: uint64 |
| 99 | + timestamp: uint64 |
| 100 | + extra_data: ByteList[MAX_EXTRA_DATA_BYTES] |
| 101 | + base_fee_per_gas: uint256 |
| 102 | + block_hash: Hash32 # Hash of execution block |
| 103 | + transactions_root: Root |
| 104 | + # Extra payload fields |
| 105 | + execution_witness: ExecutionWitness |
| 106 | +``` |
| 107 | + |
| 108 | +### New containers |
| 109 | + |
| 110 | +#### `SuffixStateDiff` |
| 111 | + |
| 112 | +```python |
| 113 | +class SuffixStateDiff(Container): |
| 114 | + suffix: Byte |
| 115 | + |
| 116 | + # Null means not currently present |
| 117 | + current_value: Union[Null, Bytes32] |
| 118 | + |
| 119 | + # Null means value not updated |
| 120 | + new_value: Union[Null, Bytes32] |
| 121 | +``` |
| 122 | + |
| 123 | +*Note*: on the Kaustinen testnet, `new_value` is ommitted from the container. |
| 124 | + |
| 125 | +#### `StemStateDiff` |
| 126 | + |
| 127 | +```python |
| 128 | +class StemStateDiff(Container): |
| 129 | + stem: Stem |
| 130 | + # Valid only if list is sorted by suffixes |
| 131 | + suffix_diffs: List[SuffixStateDiff, VERKLE_WIDTH] |
| 132 | +``` |
| 133 | + |
| 134 | +```python |
| 135 | +# Valid only if list is sorted by stems |
| 136 | +StateDiff = List[StemStateDiff, MAX_STEMS] |
| 137 | +``` |
| 138 | + |
| 139 | +#### `IPAProof` |
| 140 | + |
| 141 | +```python |
| 142 | +class IpaProof(Container): |
| 143 | + C_L = Vector[BandersnatchGroupElement, IPA_PROOF_DEPTH] |
| 144 | + C_R = Vector[BandersnatchGroupElement, IPA_PROOF_DEPTH] |
| 145 | + final_evaluation = BandersnatchFieldElement |
| 146 | +``` |
| 147 | + |
| 148 | +#### `VerkleProof` |
| 149 | + |
| 150 | +```python |
| 151 | +class VerkleProof(Container): |
| 152 | + other_stems: List[Bytes32, MAX_STEMS] |
| 153 | + depth_extension_present: List[uint8, MAX_STEMS] |
| 154 | + commitments_by_path: List[BandersnatchGroupElement, MAX_STEMS * MAX_COMMITMENTS_PER_STEM] |
| 155 | + D: BandersnatchGroupElement |
| 156 | + ipa_proof: IpaProof |
| 157 | +``` |
| 158 | + |
| 159 | +#### `ExecutionWitness` |
| 160 | + |
| 161 | +```python |
| 162 | +class ExecutionWitness(container): |
| 163 | + state_diff: StateDiff |
| 164 | + verkle_proof: VerkleProof |
| 165 | +``` |
| 166 | + |
| 167 | +## Beacon chain state transition function |
| 168 | + |
| 169 | +### Block processing |
| 170 | + |
| 171 | +#### Execution payload |
| 172 | + |
| 173 | +##### `process_execution_payload` |
| 174 | + |
| 175 | +```python |
| 176 | +def process_execution_payload(state: BeaconState, payload: ExecutionPayload, execution_engine: ExecutionEngine) -> None: |
| 177 | + # Verify consistency of the parent hash with respect to the previous execution payload header |
| 178 | + if is_merge_transition_complete(state): |
| 179 | + assert payload.parent_hash == state.latest_execution_payload_header.block_hash |
| 180 | + # Verify prev_randao |
| 181 | + assert payload.prev_randao == get_randao_mix(state, get_current_epoch(state)) |
| 182 | + # Verify timestamp |
| 183 | + assert payload.timestamp == compute_timestamp_at_slot(state, state.slot) |
| 184 | + # Verify the execution payload is valid |
| 185 | + assert execution_engine.notify_new_payload(payload) |
| 186 | + # Cache execution payload header |
| 187 | + state.latest_execution_payload_header = ExecutionPayloadHeader( |
| 188 | + parent_hash=payload.parent_hash, |
| 189 | + fee_recipient=payload.fee_recipient, |
| 190 | + state_root=payload.state_root, |
| 191 | + receipts_root=payload.receipts_root, |
| 192 | + logs_bloom=payload.logs_bloom, |
| 193 | + prev_randao=payload.prev_randao, |
| 194 | + block_number=payload.block_number, |
| 195 | + gas_limit=payload.gas_limit, |
| 196 | + gas_used=payload.gas_used, |
| 197 | + timestamp=payload.timestamp, |
| 198 | + extra_data=payload.extra_data, |
| 199 | + base_fee_per_gas=payload.base_fee_per_gas, |
| 200 | + block_hash=payload.block_hash, |
| 201 | + transactions_root=hash_tree_root(payload.transactions), |
| 202 | + execution_witness=payload.execution_witness, |
| 203 | + ) |
| 204 | +``` |
| 205 | + |
| 206 | +## Testing |
| 207 | + |
| 208 | +TBD |
0 commit comments