|
| 1 | +# EIP-7549 -- Fork Logic |
| 2 | + |
| 3 | +**Notice**: This document is a work-in-progress for researchers and implementers. |
| 4 | + |
| 5 | +## Table of contents |
| 6 | + |
| 7 | +<!-- START doctoc generated TOC please keep comment here to allow auto update --> |
| 8 | +<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> |
| 9 | + |
| 10 | +- [Introduction](#introduction) |
| 11 | +- [Configuration](#configuration) |
| 12 | +- [Helper functions](#helper-functions) |
| 13 | + - [Misc](#misc) |
| 14 | + - [Modified `compute_fork_version`](#modified-compute_fork_version) |
| 15 | +- [Fork to EIP-7549](#fork-to-eip-7549) |
| 16 | + - [Fork trigger](#fork-trigger) |
| 17 | + - [Upgrading the state](#upgrading-the-state) |
| 18 | + |
| 19 | +<!-- END doctoc generated TOC please keep comment here to allow auto update --> |
| 20 | + |
| 21 | +## Introduction |
| 22 | + |
| 23 | +This document describes the process of EIP-7549 upgrade. |
| 24 | + |
| 25 | +## Configuration |
| 26 | + |
| 27 | +Warning: this configuration is not definitive. |
| 28 | + |
| 29 | +| Name | Value | |
| 30 | +| - | - | |
| 31 | +| `EIP7549_FORK_VERSION` | `Version('0x06000000')` | |
| 32 | +| `EIP7549_FORK_EPOCH` | `Epoch(18446744073709551615)` **TBD** | |
| 33 | + |
| 34 | +## Helper functions |
| 35 | + |
| 36 | +### Misc |
| 37 | + |
| 38 | +#### Modified `compute_fork_version` |
| 39 | + |
| 40 | +```python |
| 41 | +def compute_fork_version(epoch: Epoch) -> Version: |
| 42 | + """ |
| 43 | + Return the fork version at the given ``epoch``. |
| 44 | + """ |
| 45 | + if epoch >= EIP7549_FORK_EPOCH: |
| 46 | + return EIP7549_FORK_VERSION |
| 47 | + if epoch >= DENEB_FORK_EPOCH: |
| 48 | + return DENEB_FORK_VERSION |
| 49 | + if epoch >= CAPELLA_FORK_EPOCH: |
| 50 | + return CAPELLA_FORK_VERSION |
| 51 | + if epoch >= BELLATRIX_FORK_EPOCH: |
| 52 | + return BELLATRIX_FORK_VERSION |
| 53 | + if epoch >= ALTAIR_FORK_EPOCH: |
| 54 | + return ALTAIR_FORK_VERSION |
| 55 | + return GENESIS_FORK_VERSION |
| 56 | +``` |
| 57 | + |
| 58 | +## Fork to EIP-7549 |
| 59 | + |
| 60 | +### Fork trigger |
| 61 | + |
| 62 | +TBD. This fork is defined for testing purposes, the EIP may be combined with other consensus-layer upgrade. |
| 63 | +For now, we assume the condition will be triggered at epoch `EIP7549_FORK_EPOCH`. |
| 64 | + |
| 65 | +Note that for the pure EIP-7549 networks, we don't apply `upgrade_to_eip7549` since it starts with EIP-7549 version logic. |
| 66 | + |
| 67 | +### Upgrading the state |
| 68 | + |
| 69 | +If `state.slot % SLOTS_PER_EPOCH == 0` and `compute_epoch_at_slot(state.slot) == EIP7549_FORK_EPOCH`, |
| 70 | +an irregular state change is made to upgrade to EIP-7549. |
| 71 | + |
| 72 | +```python |
| 73 | +def upgrade_to_eip7549(pre: capella.BeaconState) -> BeaconState: |
| 74 | + epoch = capella.get_current_epoch(pre) |
| 75 | + latest_execution_payload_header = ExecutionPayloadHeader( |
| 76 | + parent_hash=pre.latest_execution_payload_header.parent_hash, |
| 77 | + fee_recipient=pre.latest_execution_payload_header.fee_recipient, |
| 78 | + state_root=pre.latest_execution_payload_header.state_root, |
| 79 | + receipts_root=pre.latest_execution_payload_header.receipts_root, |
| 80 | + logs_bloom=pre.latest_execution_payload_header.logs_bloom, |
| 81 | + prev_randao=pre.latest_execution_payload_header.prev_randao, |
| 82 | + block_number=pre.latest_execution_payload_header.block_number, |
| 83 | + gas_limit=pre.latest_execution_payload_header.gas_limit, |
| 84 | + gas_used=pre.latest_execution_payload_header.gas_used, |
| 85 | + timestamp=pre.latest_execution_payload_header.timestamp, |
| 86 | + extra_data=pre.latest_execution_payload_header.extra_data, |
| 87 | + base_fee_per_gas=pre.latest_execution_payload_header.base_fee_per_gas, |
| 88 | + block_hash=pre.latest_execution_payload_header.block_hash, |
| 89 | + transactions_root=pre.latest_execution_payload_header.transactions_root, |
| 90 | + withdrawals_root=pre.latest_execution_payload_header.withdrawals_root, |
| 91 | + ) |
| 92 | + post = BeaconState( |
| 93 | + # Versioning |
| 94 | + genesis_time=pre.genesis_time, |
| 95 | + genesis_validators_root=pre.genesis_validators_root, |
| 96 | + slot=pre.slot, |
| 97 | + fork=Fork( |
| 98 | + previous_version=pre.fork.current_version, |
| 99 | + current_version=EIP7549_FORK_VERSION, # [Modified in EIP-7549] |
| 100 | + epoch=epoch, |
| 101 | + ), |
| 102 | + # History |
| 103 | + latest_block_header=pre.latest_block_header, |
| 104 | + block_roots=pre.block_roots, |
| 105 | + state_roots=pre.state_roots, |
| 106 | + historical_roots=pre.historical_roots, |
| 107 | + # Eth1 |
| 108 | + eth1_data=pre.eth1_data, |
| 109 | + eth1_data_votes=pre.eth1_data_votes, |
| 110 | + eth1_deposit_index=pre.eth1_deposit_index, |
| 111 | + # Registry |
| 112 | + validators=pre.validators, |
| 113 | + balances=pre.balances, |
| 114 | + # Randomness |
| 115 | + randao_mixes=pre.randao_mixes, |
| 116 | + # Slashings |
| 117 | + slashings=pre.slashings, |
| 118 | + # Participation |
| 119 | + previous_epoch_participation=pre.previous_epoch_participation, |
| 120 | + current_epoch_participation=pre.current_epoch_participation, |
| 121 | + # Finality |
| 122 | + justification_bits=pre.justification_bits, |
| 123 | + previous_justified_checkpoint=pre.previous_justified_checkpoint, |
| 124 | + current_justified_checkpoint=pre.current_justified_checkpoint, |
| 125 | + finalized_checkpoint=pre.finalized_checkpoint, |
| 126 | + # Inactivity |
| 127 | + inactivity_scores=pre.inactivity_scores, |
| 128 | + # Sync |
| 129 | + current_sync_committee=pre.current_sync_committee, |
| 130 | + next_sync_committee=pre.next_sync_committee, |
| 131 | + # Execution-layer |
| 132 | + latest_execution_payload_header=latest_execution_payload_header, |
| 133 | + # Withdrawals |
| 134 | + next_withdrawal_index=pre.next_withdrawal_index, |
| 135 | + next_withdrawal_validator_index=pre.next_withdrawal_validator_index, |
| 136 | + # Deep history valid from Capella onwards |
| 137 | + historical_summaries=pre.historical_summaries, |
| 138 | + ) |
| 139 | + |
| 140 | + return post |
| 141 | +``` |
0 commit comments