Skip to content

Commit

Permalink
Merge pull request #3976 from lucassaldanha/update-validator-electra
Browse files Browse the repository at this point in the history
Updated validator spec with rules for including execution requests in the beacon block body
  • Loading branch information
jtraglia authored Oct 11, 2024
2 parents 6bbe3ae + 6416a56 commit a2e16c8
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 10 deletions.
4 changes: 2 additions & 2 deletions pysetup/spec_builders/electra.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ElectraSpecBuilder(BaseSpecBuilder):
def imports(cls, preset_name: str):
return f'''
from eth2spec.deneb import {preset_name} as deneb
from eth2spec.utils.ssz.ssz_impl import serialize
from eth2spec.utils.ssz.ssz_impl import ssz_serialize, ssz_deserialize
'''

@classmethod
Expand All @@ -30,7 +30,7 @@ class NoopExecutionEngine(ExecutionEngine):
def notify_new_payload(self: ExecutionEngine,
execution_payload: ExecutionPayload,
parent_beacon_block_root: Root,
execution_requests_list: list[bytes]) -> bool:
execution_requests_list: Sequence[bytes]) -> bool:
return True
def notify_forkchoice_updated(self: ExecutionEngine,
Expand Down
12 changes: 6 additions & 6 deletions specs/electra/beacon-chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -992,9 +992,9 @@ class NewPayloadRequest(object):
def notify_new_payload(self: ExecutionEngine,
execution_payload: ExecutionPayload,
parent_beacon_block_root: Root,
execution_requests_list: list[bytes]) -> bool:
execution_requests_list: Sequence[bytes]) -> bool:
"""
Return ``True`` if and only if ``execution_payload`` and ``execution_requests``
Return ``True`` if and only if ``execution_payload`` and ``execution_requests``
are valid with respect to ``self.execution_state``.
"""
...
Expand Down Expand Up @@ -1145,10 +1145,10 @@ def process_withdrawals(state: BeaconState, payload: ExecutionPayload) -> None:
*Note*: Encodes execution requests as defined by [EIP-7685](https://eips.ethereum.org/EIPS/eip-7685).

```python
def get_execution_requests_list(execution_requests: ExecutionRequests) -> list[bytes]:
deposit_bytes = serialize(execution_requests.deposits)
withdrawal_bytes = serialize(execution_requests.withdrawals)
consolidation_bytes = serialize(execution_requests.consolidations)
def get_execution_requests_list(execution_requests: ExecutionRequests) -> Sequence[bytes]:
deposit_bytes = ssz_serialize(execution_requests.deposits)
withdrawal_bytes = ssz_serialize(execution_requests.withdrawals)
consolidation_bytes = ssz_serialize(execution_requests.consolidations)

return [deposit_bytes, withdrawal_bytes, consolidation_bytes]
```
Expand Down
55 changes: 55 additions & 0 deletions specs/electra/validator.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,22 @@

- [Introduction](#introduction)
- [Prerequisites](#prerequisites)
- [Helpers](#helpers)
- [Modified `GetPayloadResponse`](#modified-getpayloadresponse)
- [Containers](#containers)
- [Modified Containers](#modified-containers)
- [`AggregateAndProof`](#aggregateandproof)
- [`SignedAggregateAndProof`](#signedaggregateandproof)
- [Protocol](#protocol)
- [`ExecutionEngine`](#executionengine)
- [Modified `get_payload`](#modified-get_payload)
- [Block proposal](#block-proposal)
- [Constructing the `BeaconBlockBody`](#constructing-the-beaconblockbody)
- [Attester slashings](#attester-slashings)
- [Attestations](#attestations)
- [Deposits](#deposits)
- [Execution payload](#execution-payload)
- [Execution Requests](#execution-requests)
- [Attesting](#attesting)
- [Construct attestation](#construct-attestation)
- [Attestation aggregation](#attestation-aggregation)
Expand All @@ -38,6 +44,19 @@ All behaviors and definitions defined in this document, and documents it extends
All terminology, constants, functions, and protocol mechanics defined in the updated Beacon Chain doc of [Electra](./beacon-chain.md) are requisite for this document and used throughout.
Please see related Beacon Chain doc before continuing and use them as a reference throughout.

## Helpers

### Modified `GetPayloadResponse`

```python
@dataclass
class GetPayloadResponse(object):
execution_payload: ExecutionPayload
block_value: uint256
blobs_bundle: BlobsBundle
execution_requests: Sequence[bytes] # [New in Electra]
```

## Containers

### Modified Containers
Expand All @@ -59,6 +78,24 @@ class SignedAggregateAndProof(Container):
signature: BLSSignature
```

## Protocol

### `ExecutionEngine`

#### Modified `get_payload`

Given the `payload_id`, `get_payload` returns the most recent version of the execution payload that
has been built since the corresponding call to `notify_forkchoice_updated` method.

```python
def get_payload(self: ExecutionEngine, payload_id: PayloadId) -> GetPayloadResponse:
"""
Return ExecutionPayload, uint256, BlobsBundle and execution requests (as Sequence[bytes]) objects.
"""
# pylint: disable=unused-argument
...
```

## Block proposal

### Constructing the `BeaconBlockBody`
Expand Down Expand Up @@ -148,6 +185,24 @@ def prepare_execution_payload(state: BeaconState,
)
```

#### Execution Requests

*[New in Electra]*

1. The execution payload is obtained from the execution engine as defined above using `payload_id`. The response also includes a `execution_requests` entry containing a list of bytes. Each element on the list corresponds to one SSZ list of requests as defined
in [EIP-7685](https://eips.ethereum.org/EIPS/eip-7685). The index of each element in the array determines the type of request.
2. Set `block.body.execution_requests = get_execution_requests(execution_requests)`, where:

```python
def get_execution_requests(execution_requests: Sequence[bytes]) -> ExecutionRequests:
deposits = ssz_deserialize(List[DepositRequest, MAX_DEPOSIT_REQUESTS_PER_PAYLOAD], execution_requests[0])
withdrawals = ssz_deserialize(List[WithdrawalRequest, MAX_WITHDRAWAL_REQUESTS_PER_PAYLOAD], execution_requests[1])
consolidations = ssz_deserialize(List[ConsolidationRequest, MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD],
execution_requests[2])

return ExecutionRequests(deposits, withdrawals, consolidations)
```

## Attesting

### Construct attestation
Expand Down
16 changes: 14 additions & 2 deletions tests/core/pyspec/eth2spec/utils/ssz/ssz_impl.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
from typing import TypeVar

from remerkleable.basic import uint
from remerkleable.core import View
from remerkleable.core import Type, View
from remerkleable.byte_arrays import Bytes32


def serialize(obj: View) -> bytes:
def ssz_serialize(obj: View) -> bytes:
return obj.encode_bytes()


def serialize(obj: View) -> bytes:
return ssz_serialize(obj)


def ssz_deserialize(typ: Type[View], data: bytes) -> View:
return typ.decode_bytes(data)


def deserialize(typ: Type[View], data: bytes) -> View:
return ssz_deserialize(typ, data)


def hash_tree_root(obj: View) -> Bytes32:
return Bytes32(obj.get_backing().merkle_root())

Expand Down

0 comments on commit a2e16c8

Please sign in to comment.