Skip to content

Commit a2e16c8

Browse files
authored
Merge pull request #3976 from lucassaldanha/update-validator-electra
Updated validator spec with rules for including execution requests in the beacon block body
2 parents 6bbe3ae + 6416a56 commit a2e16c8

File tree

4 files changed

+77
-10
lines changed

4 files changed

+77
-10
lines changed

pysetup/spec_builders/electra.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class ElectraSpecBuilder(BaseSpecBuilder):
1010
def imports(cls, preset_name: str):
1111
return f'''
1212
from eth2spec.deneb import {preset_name} as deneb
13-
from eth2spec.utils.ssz.ssz_impl import serialize
13+
from eth2spec.utils.ssz.ssz_impl import ssz_serialize, ssz_deserialize
1414
'''
1515

1616
@classmethod
@@ -30,7 +30,7 @@ class NoopExecutionEngine(ExecutionEngine):
3030
def notify_new_payload(self: ExecutionEngine,
3131
execution_payload: ExecutionPayload,
3232
parent_beacon_block_root: Root,
33-
execution_requests_list: list[bytes]) -> bool:
33+
execution_requests_list: Sequence[bytes]) -> bool:
3434
return True
3535
3636
def notify_forkchoice_updated(self: ExecutionEngine,

specs/electra/beacon-chain.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -992,9 +992,9 @@ class NewPayloadRequest(object):
992992
def notify_new_payload(self: ExecutionEngine,
993993
execution_payload: ExecutionPayload,
994994
parent_beacon_block_root: Root,
995-
execution_requests_list: list[bytes]) -> bool:
995+
execution_requests_list: Sequence[bytes]) -> bool:
996996
"""
997-
Return ``True`` if and only if ``execution_payload`` and ``execution_requests``
997+
Return ``True`` if and only if ``execution_payload`` and ``execution_requests``
998998
are valid with respect to ``self.execution_state``.
999999
"""
10001000
...
@@ -1145,10 +1145,10 @@ def process_withdrawals(state: BeaconState, payload: ExecutionPayload) -> None:
11451145
*Note*: Encodes execution requests as defined by [EIP-7685](https://eips.ethereum.org/EIPS/eip-7685).
11461146

11471147
```python
1148-
def get_execution_requests_list(execution_requests: ExecutionRequests) -> list[bytes]:
1149-
deposit_bytes = serialize(execution_requests.deposits)
1150-
withdrawal_bytes = serialize(execution_requests.withdrawals)
1151-
consolidation_bytes = serialize(execution_requests.consolidations)
1148+
def get_execution_requests_list(execution_requests: ExecutionRequests) -> Sequence[bytes]:
1149+
deposit_bytes = ssz_serialize(execution_requests.deposits)
1150+
withdrawal_bytes = ssz_serialize(execution_requests.withdrawals)
1151+
consolidation_bytes = ssz_serialize(execution_requests.consolidations)
11521152

11531153
return [deposit_bytes, withdrawal_bytes, consolidation_bytes]
11541154
```

specs/electra/validator.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,22 @@
88

99
- [Introduction](#introduction)
1010
- [Prerequisites](#prerequisites)
11+
- [Helpers](#helpers)
12+
- [Modified `GetPayloadResponse`](#modified-getpayloadresponse)
1113
- [Containers](#containers)
1214
- [Modified Containers](#modified-containers)
1315
- [`AggregateAndProof`](#aggregateandproof)
1416
- [`SignedAggregateAndProof`](#signedaggregateandproof)
17+
- [Protocol](#protocol)
18+
- [`ExecutionEngine`](#executionengine)
19+
- [Modified `get_payload`](#modified-get_payload)
1520
- [Block proposal](#block-proposal)
1621
- [Constructing the `BeaconBlockBody`](#constructing-the-beaconblockbody)
1722
- [Attester slashings](#attester-slashings)
1823
- [Attestations](#attestations)
1924
- [Deposits](#deposits)
2025
- [Execution payload](#execution-payload)
26+
- [Execution Requests](#execution-requests)
2127
- [Attesting](#attesting)
2228
- [Construct attestation](#construct-attestation)
2329
- [Attestation aggregation](#attestation-aggregation)
@@ -38,6 +44,19 @@ All behaviors and definitions defined in this document, and documents it extends
3844
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.
3945
Please see related Beacon Chain doc before continuing and use them as a reference throughout.
4046

47+
## Helpers
48+
49+
### Modified `GetPayloadResponse`
50+
51+
```python
52+
@dataclass
53+
class GetPayloadResponse(object):
54+
execution_payload: ExecutionPayload
55+
block_value: uint256
56+
blobs_bundle: BlobsBundle
57+
execution_requests: Sequence[bytes] # [New in Electra]
58+
```
59+
4160
## Containers
4261

4362
### Modified Containers
@@ -59,6 +78,24 @@ class SignedAggregateAndProof(Container):
5978
signature: BLSSignature
6079
```
6180

81+
## Protocol
82+
83+
### `ExecutionEngine`
84+
85+
#### Modified `get_payload`
86+
87+
Given the `payload_id`, `get_payload` returns the most recent version of the execution payload that
88+
has been built since the corresponding call to `notify_forkchoice_updated` method.
89+
90+
```python
91+
def get_payload(self: ExecutionEngine, payload_id: PayloadId) -> GetPayloadResponse:
92+
"""
93+
Return ExecutionPayload, uint256, BlobsBundle and execution requests (as Sequence[bytes]) objects.
94+
"""
95+
# pylint: disable=unused-argument
96+
...
97+
```
98+
6299
## Block proposal
63100

64101
### Constructing the `BeaconBlockBody`
@@ -148,6 +185,24 @@ def prepare_execution_payload(state: BeaconState,
148185
)
149186
```
150187

188+
#### Execution Requests
189+
190+
*[New in Electra]*
191+
192+
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
193+
in [EIP-7685](https://eips.ethereum.org/EIPS/eip-7685). The index of each element in the array determines the type of request.
194+
2. Set `block.body.execution_requests = get_execution_requests(execution_requests)`, where:
195+
196+
```python
197+
def get_execution_requests(execution_requests: Sequence[bytes]) -> ExecutionRequests:
198+
deposits = ssz_deserialize(List[DepositRequest, MAX_DEPOSIT_REQUESTS_PER_PAYLOAD], execution_requests[0])
199+
withdrawals = ssz_deserialize(List[WithdrawalRequest, MAX_WITHDRAWAL_REQUESTS_PER_PAYLOAD], execution_requests[1])
200+
consolidations = ssz_deserialize(List[ConsolidationRequest, MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD],
201+
execution_requests[2])
202+
203+
return ExecutionRequests(deposits, withdrawals, consolidations)
204+
```
205+
151206
## Attesting
152207

153208
### Construct attestation

tests/core/pyspec/eth2spec/utils/ssz/ssz_impl.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
from typing import TypeVar
22

33
from remerkleable.basic import uint
4-
from remerkleable.core import View
4+
from remerkleable.core import Type, View
55
from remerkleable.byte_arrays import Bytes32
66

77

8-
def serialize(obj: View) -> bytes:
8+
def ssz_serialize(obj: View) -> bytes:
99
return obj.encode_bytes()
1010

1111

12+
def serialize(obj: View) -> bytes:
13+
return ssz_serialize(obj)
14+
15+
16+
def ssz_deserialize(typ: Type[View], data: bytes) -> View:
17+
return typ.decode_bytes(data)
18+
19+
20+
def deserialize(typ: Type[View], data: bytes) -> View:
21+
return ssz_deserialize(typ, data)
22+
23+
1224
def hash_tree_root(obj: View) -> Bytes32:
1325
return Bytes32(obj.get_backing().merkle_root())
1426

0 commit comments

Comments
 (0)