Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rebase EIP-4844 on Capella #3052

Merged
merged 25 commits into from
Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
242e1b7
Rebase Capella on EIP-4844
Inphi Oct 20, 2022
f6f2474
Update specs/eip4844/beacon-chain.md
Inphi Oct 20, 2022
2ac57c7
Fix py setup
Inphi Oct 24, 2022
0488c0c
remove unchanged epoch processing section
Inphi Oct 24, 2022
459310f
Fix test_process_execution_payload
Inphi Oct 24, 2022
6d270cd
Add CAPELLA_FORK_EPOCH overrides
Inphi Oct 24, 2022
ca538f5
Update specs/eip4844/beacon-chain.md
Inphi Oct 25, 2022
3172095
Make pyspec disable withdrawal-functions in EIP4844
hwwhww Oct 26, 2022
e460005
Add tests for no-op functions
hwwhww Oct 26, 2022
60187e5
Add `test_process_withdrawals` no-op test
hwwhww Oct 26, 2022
95ee291
Merge branch 'dev' into pr3052
hwwhww Nov 7, 2022
e3e73a8
Add Capella fork version
Inphi Nov 8, 2022
a59dd37
Merge remote-tracking branch 'origin/dev' into inphi/eip4844-rebase
Inphi Nov 10, 2022
a04f06b
Fix merge conflict
Inphi Nov 10, 2022
bed1df0
Remove withdrawal_queue from BeaconState upgrade
Inphi Nov 10, 2022
2fbb1ed
fix test_process_withdrawals
Inphi Nov 10, 2022
fcafdc1
remove eip4844 partial/full withdrawwals tests
Inphi Nov 10, 2022
67ba28c
remove eip4844 epoch_processing package
Inphi Nov 10, 2022
104cba0
replace get_blobs_and_kzg_commitments
Inphi Nov 11, 2022
6327ffa
rename excess_blobs
Inphi Nov 11, 2022
cd1e113
excess_data_gas uint256
Inphi Nov 11, 2022
3df1371
Merge remote-tracking branch 'origin/dev' into inphi/eip4844-rebase
Inphi Nov 11, 2022
3714446
Fix merge conflict
Inphi Nov 11, 2022
f1d4c90
Merge branch 'dev' into pr3052
hwwhww Nov 17, 2022
ee0e2a0
Merge branch 'dev' into pr3052
hwwhww Nov 17, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,14 +582,14 @@ def imports(cls, preset_name: str):
#
# EIP4844SpecBuilder
#
class EIP4844SpecBuilder(BellatrixSpecBuilder):
class EIP4844SpecBuilder(CapellaSpecBuilder):
fork: str = EIP4844

@classmethod
def imports(cls, preset_name: str):
return super().imports(preset_name) + f'''
from eth2spec.utils import kzg
from eth2spec.bellatrix import {preset_name} as bellatrix
from eth2spec.capella import {preset_name} as capella
from eth2spec.utils.ssz.ssz_impl import serialize as ssz_serialize
'''

Expand Down Expand Up @@ -967,7 +967,7 @@ def finalize_options(self):
specs/bellatrix/p2p-interface.md
sync/optimistic.md
"""
if self.spec_fork == CAPELLA:
if self.spec_fork in (CAPELLA, EIP4844):
self.md_doc_paths += """
specs/capella/beacon-chain.md
specs/capella/fork.md
Expand Down
20 changes: 18 additions & 2 deletions specs/eip4844/beacon-chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@
- [`process_execution_payload`](#process_execution_payload)
- [Blob KZG commitments](#blob-kzg-commitments)
- [Testing](#testing)
- [Disabling Withdrawals](#disabling-withdrawals)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->
<!-- /TOC -->

## Introduction

This upgrade adds blobs to the beacon chain as part of EIP-4844.
This upgrade adds blobs to the beacon chain as part of EIP-4844. This is an extension of the Capella upgrade.

## Custom types

Expand Down Expand Up @@ -97,6 +98,7 @@ class BeaconBlockBody(Container):
sync_aggregate: SyncAggregate
# Execution
execution_payload: ExecutionPayload
bls_to_execution_changes: List[SignedBLSToExecutionChange, MAX_BLS_TO_EXECUTION_CHANGES]
djrtwo marked this conversation as resolved.
Show resolved Hide resolved
blob_kzg_commitments: List[KZGCommitment, MAX_BLOBS_PER_BLOCK] # [New in EIP-4844]
```

Expand All @@ -121,6 +123,7 @@ class ExecutionPayload(Container):
# Extra payload fields
block_hash: Hash32 # Hash of execution block
transactions: List[Transaction, MAX_TRANSACTIONS_PER_PAYLOAD]
withdrawals: List[Withdrawal, MAX_WITHDRAWALS_PER_PAYLOAD]
```

#### `ExecutionPayloadHeader`
Expand All @@ -144,6 +147,7 @@ class ExecutionPayloadHeader(Container):
# Extra payload fields
djrtwo marked this conversation as resolved.
Show resolved Hide resolved
block_hash: Hash32 # Hash of execution block
transactions_root: Root
withdrawals_root: Root
```

## Helper functions
Expand Down Expand Up @@ -198,7 +202,8 @@ def verify_kzg_commitments_against_transactions(transactions: Sequence[Transacti
def process_block(state: BeaconState, block: BeaconBlock) -> None:
process_block_header(state, block)
if is_execution_enabled(state, block.body):
process_execution_payload(state, block.body.execution_payload, EXECUTION_ENGINE)
process_withdrawals(state, block.body.execution_payload)
process_execution_payload(state, block.body.execution_payload, EXECUTION_ENGINE) # [Modified in EIP-4844]
process_randao(state, block.body)
process_eth1_data(state, block.body)
process_operations(state, block.body)
Expand All @@ -221,6 +226,7 @@ def process_execution_payload(state: BeaconState, payload: ExecutionPayload, exe
assert payload.timestamp == compute_timestamp_at_slot(state, state.slot)
# Verify the execution payload is valid
assert execution_engine.notify_new_payload(payload)

# Cache execution payload header
state.latest_execution_payload_header = ExecutionPayloadHeader(
parent_hash=payload.parent_hash,
Expand All @@ -238,6 +244,7 @@ def process_execution_payload(state: BeaconState, payload: ExecutionPayload, exe
excess_blobs=payload.excess_blobs, # [New in EIP-4844]
block_hash=payload.block_hash,
transactions_root=hash_tree_root(payload.transactions),
withdrawals_root=hash_tree_root(payload.withdrawals),
)
```

Expand Down Expand Up @@ -303,3 +310,12 @@ def initialize_beacon_state_from_eth1(eth1_block_hash: Hash32,

return state
```

### Disabling Withdrawals
During testing we avoid Capella-specific updates the state transition. We do this by replacing the following functions with a no-op implementation:
Inphi marked this conversation as resolved.
Show resolved Hide resolved
- `process_full_withdrawals`
- `process_partial_withdrawals`
- `process_withdrawals`
- `process_bls_to_execution_change`

The `get_expected_withdrawals` function is also modified to return an empty withdrawals list. As such, the PayloadAttributes used to update forkchoice does not contain withdrawals.
13 changes: 9 additions & 4 deletions specs/eip4844/fork.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ def compute_fork_version(epoch: Epoch) -> Version:
"""
if epoch >= EIP4844_FORK_EPOCH:
return EIP4844_FORK_VERSION
if epoch >= CAPELLA_FORK_EPOCH:
return CAPELLA_FORK_VERSION
if epoch >= BELLATRIX_FORK_EPOCH:
return BELLATRIX_FORK_VERSION
if epoch >= ALTAIR_FORK_EPOCH:
Expand All @@ -62,12 +64,11 @@ Note that for the pure EIP-4844 networks, we don't apply `upgrade_to_eip4844` si

### Upgrading the state

Since the `eip4844.BeaconState` format is equal to the `bellatrix.BeaconState` format, we only have to update `BeaconState.fork`.
Since the `eip4844.BeaconState` format is equal to the `capella.BeaconState` format, we only have to update `BeaconState.fork`.

```python
def upgrade_to_eip4844(pre: bellatrix.BeaconState) -> BeaconState:
# TODO: if Capella gets scheduled, add sync it with Capella.BeaconState
epoch = bellatrix.get_current_epoch(pre)
def upgrade_to_eip4844(pre: capella.BeaconState) -> BeaconState:
epoch = capella.get_current_epoch(pre)
post = BeaconState(
# Versioning
genesis_time=pre.genesis_time,
Expand Down Expand Up @@ -109,6 +110,10 @@ def upgrade_to_eip4844(pre: bellatrix.BeaconState) -> BeaconState:
next_sync_committee=pre.next_sync_committee,
# Execution-layer
latest_execution_payload_header=pre.latest_execution_payload_header,
# Withdrawals
withdrawal_queue=pre.withdrawal_queue,
next_withdrawal_index=pre.next_withdrawal_index,
next_partial_withdrawal_validator_index=pre.next_partial_withdrawal_validator_index,
)

return post
Expand Down
2 changes: 1 addition & 1 deletion specs/eip4844/p2p-interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Some gossip meshes are upgraded in the fork of EIP4844 to support upgraded types
Topics follow the same specification as in prior upgrades.
All topics remain stable except the beacon block topic which is updated with the modified type.

The specification around the creation, validation, and dissemination of messages has not changed from the Bellatrix document unless explicitly noted here.
The specification around the creation, validation, and dissemination of messages has not changed from the Capella document unless explicitly noted here.

The derivation of the `message-id` remains stable.

Expand Down
15 changes: 13 additions & 2 deletions specs/eip4844/validator.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
- [`BlobsAndCommitments`](#blobsandcommitments)
- [`PolynomialAndCommitment`](#polynomialandcommitment)
- [Helpers](#helpers)
- [Protocols](#protocols)
- [`ExecutionEngine`](#executionengine)
- [`get_payload`](#get_payload)
- [`is_data_available`](#is_data_available)
- [`hash_to_bls_field`](#hash_to_bls_field)
- [`compute_powers`](#compute_powers)
Expand All @@ -37,7 +40,7 @@ This document represents the changes to be made in the code of an "honest valida

## Prerequisites

This document is an extension of the [Bellatrix -- Honest Validator](../bellatrix/validator.md) guide.
This document is an extension of the [Capella -- Honest Validator](../capella/validator.md) guide.
All behaviors and definitions defined in this document, and documents it extends, carry over unless explicitly noted or overridden.

All terminology, constants, functions, and protocol mechanics defined in the updated [Beacon Chain doc of EIP4844](./beacon-chain.md) are requisite for this document and used throughout.
Expand Down Expand Up @@ -70,6 +73,14 @@ class PolynomialAndCommitment(Container):

## Helpers

## Protocols

### `ExecutionEngine`

#### `get_payload`

`get_payload` returns the upgraded EIP-4844 `ExecutionPayload` type.

### `is_data_available`

The implementation of `is_data_available` is meant to change with later sharding upgrades.
Expand Down Expand Up @@ -200,7 +211,7 @@ Namely, the blob handling and the addition of `BlobsSidecar`.

##### Blob KZG commitments

1. After retrieving the execution payload from the execution engine as specified in Bellatrix,
1. After retrieving the execution payload from the execution engine as specified in Capella,
use the `payload_id` to retrieve `blobs` and `blob_kzg_commitments` via `get_blobs_and_kzg_commitments(payload_id)`.
2. Validate `blobs` and `blob_kzg_commitments`:

Expand Down
5 changes: 3 additions & 2 deletions tests/core/pyspec/eth2spec/test/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
PHASE0, ALTAIR, BELLATRIX, CAPELLA, EIP4844, SHARDING,
MINIMAL, MAINNET,
ALL_PHASES, FORKS_BEFORE_ALTAIR, FORKS_BEFORE_BELLATRIX,
ALL_FORK_UPGRADES,
FORKS_BEFORE_CAPELLA, ALL_FORK_UPGRADES,
)
from .helpers.typing import SpecForkName, PresetBaseName
from .helpers.genesis import create_genesis_state
Expand Down Expand Up @@ -305,6 +305,7 @@ def config_fork_epoch_overrides(spec, state):
elif _check_current_version(spec, state, EIP4844):
overrides['ALTAIR_FORK_EPOCH'] = spec.GENESIS_EPOCH
overrides['BELLATRIX_FORK_EPOCH'] = spec.GENESIS_EPOCH
overrides['CAPELLA_FORK_EPOCH'] = spec.GENESIS_EPOCH
overrides['EIP4844_FORK_EPOCH'] = spec.GENESIS_EPOCH
elif _check_current_version(spec, state, SHARDING):
overrides['ALTAIR_FORK_EPOCH'] = spec.GENESIS_EPOCH
Expand Down Expand Up @@ -596,7 +597,7 @@ def is_post_bellatrix(spec):


def is_post_capella(spec):
return spec.fork == CAPELLA
return spec.fork not in FORKS_BEFORE_CAPELLA


def is_post_eip4844(spec):
Expand Down