Skip to content

Commit

Permalink
Send execution_requests to EE as a list of byte sequences
Browse files Browse the repository at this point in the history
  • Loading branch information
mkalinin committed Oct 3, 2024
1 parent 21fdd85 commit 601631f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 26 deletions.
2 changes: 1 addition & 1 deletion pysetup/spec_builders/electra.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def get_payload(self: ExecutionEngine, payload_id: PayloadId) -> GetPayloadRespo
def is_valid_block_hash(self: ExecutionEngine,
execution_payload: ExecutionPayload,
parent_beacon_block_root: Root,
execution_requests_hash: Hash32) -> bool:
execution_requests_list: list[bytes]) -> bool:
return True
def is_valid_versioned_hashes(self: ExecutionEngine, new_payload_request: NewPayloadRequest) -> bool:
Expand Down
2 changes: 1 addition & 1 deletion specs/_features/eip7732/beacon-chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ def process_execution_payload(state: BeaconState,
execution_payload=payload,
versioned_hashes=versioned_hashes,
parent_beacon_block_root=state.latest_block_header.parent_root,
execution_requests_hash=compute_execution_requests_hash(requests),
execution_requests=requests,
)
)

Expand Down
39 changes: 15 additions & 24 deletions specs/electra/beacon-chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
- [Constants](#constants)
- [Misc](#misc)
- [Withdrawal prefixes](#withdrawal-prefixes)
- [Execution layer triggered requests](#execution-layer-triggered-requests)
- [Preset](#preset)
- [Gwei values](#gwei-values)
- [Rewards and penalties](#rewards-and-penalties)
Expand Down Expand Up @@ -85,7 +84,7 @@
- [Modified `get_expected_withdrawals`](#modified-get_expected_withdrawals)
- [Modified `process_withdrawals`](#modified-process_withdrawals)
- [Execution payload](#execution-payload)
- [New `compute_execution_requests_hash`](#new-compute_execution_requests_hash)
- [New `get_execution_requests_list`](#new-get_execution_requests_list)
- [Modified `process_execution_payload`](#modified-process_execution_payload)
- [Operations](#operations)
- [Modified `process_operations`](#modified-process_operations)
Expand Down Expand Up @@ -136,14 +135,6 @@ The following values are (non-configurable) constants used throughout the specif
| - | - |
| `COMPOUNDING_WITHDRAWAL_PREFIX` | `Bytes1('0x02')` |

### Execution layer triggered requests

| Name | Value |
| - | - |
| `DEPOSIT_REQUEST_TYPE` | `Bytes1('0x00')` |
| `WITHDRAWAL_REQUEST_TYPE` | `Bytes1('0x01')` |
| `CONSOLIDATION_REQUEST_TYPE` | `Bytes1('0x02')` |

## Preset

### Gwei values
Expand Down Expand Up @@ -940,20 +931,20 @@ class NewPayloadRequest(object):
execution_payload: ExecutionPayload
versioned_hashes: Sequence[VersionedHash]
parent_beacon_block_root: Root
execution_requests_hash: Hash32 # [New in Electra:EIP7685]
execution_requests: ExecutionRequests # [New in Electra]
```

#### Engine APIs

##### Modified `is_valid_block_hash`

*Note*: The function `is_valid_block_hash` is modified to include the additional `execution_requests_hash` parameter for EIP-7685.
*Note*: The function `is_valid_block_hash` is modified to include the additional `execution_requests_list` parameter for EIP-7685.

```python
def is_valid_block_hash(self: ExecutionEngine,
execution_payload: ExecutionPayload,
parent_beacon_block_root: Root,
execution_requests_hash: Hash32) -> bool:
execution_requests_list: list[bytes]) -> bool:
"""
Return ``True`` if and only if ``execution_payload.block_hash`` is computed correctly.
"""
Expand All @@ -973,13 +964,14 @@ def verify_and_notify_new_payload(self: ExecutionEngine,
"""
execution_payload = new_payload_request.execution_payload
parent_beacon_block_root = new_payload_request.parent_beacon_block_root
execution_requests_hash = new_payload_request.execution_requests_hash # [New in Electra]
# [New in Electra]
execution_requests_list = get_execution_requests_list(new_payload_request.execution_requests)

# [Modified in Electra:EIP7685]
if not self.is_valid_block_hash(
execution_payload,
parent_beacon_block_root,
execution_requests_hash):
execution_requests_list):
return False

if not self.is_valid_versioned_hashes(new_payload_request):
Expand Down Expand Up @@ -1101,18 +1093,17 @@ def process_withdrawals(state: BeaconState, payload: ExecutionPayload) -> None:

#### Execution payload

##### New `compute_execution_requests_hash`
##### New `get_execution_requests_list`

*Note*: Computes commitment to the execution layer triggered requests data.
The computation algorithm is defined by [EIP-7685](https://eips.ethereum.org/EIPS/eip-7685).
*Note*: Encodes execution layer requests as it is defined by [EIP-7685](https://eips.ethereum.org/EIPS/eip-7685).

```python
def compute_execution_requests_hash(execution_requests: ExecutionRequests) -> Hash32:
deposit_bytes = DEPOSIT_REQUEST_TYPE + serialize(execution_requests.deposits)
withdrawal_bytes = WITHDRAWAL_REQUEST_TYPE + serialize(execution_requests.withdrawals)
consolidation_bytes = CONSOLIDATION_REQUEST_TYPE + serialize(execution_requests.consolidations)
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)

return hash(deposit_bytes + withdrawal_bytes + consolidation_bytes)
return [deposit_bytes, withdrawal_bytes, consolidation_bytes]
```

##### Modified `process_execution_payload`
Expand All @@ -1138,7 +1129,7 @@ def process_execution_payload(state: BeaconState, body: BeaconBlockBody, executi
execution_payload=payload,
versioned_hashes=versioned_hashes,
parent_beacon_block_root=state.latest_block_header.parent_root,
execution_requests_hash=compute_execution_requests_hash(body.execution_requests), # [New in Electra]
execution_requests=body.execution_requests, # [New in Electra]
)
)
# Cache execution payload header
Expand Down

0 comments on commit 601631f

Please sign in to comment.