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

eip7685: Pass execution_requests_hash to is_valid_block_hash #3950

Closed
wants to merge 10 commits into from
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
jtraglia marked this conversation as resolved.
Show resolved Hide resolved
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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would still prefer to pass execution_requests here, and if anything handle the serialization step in the engine API, rather than the consensus specs

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s not about serialization, the exact encoding is currently a part of the protocol and would have to be done even if there was other communication channel than engine API. Serialization of this array to JSON is happening in the engine API client

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