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
5 changes: 3 additions & 2 deletions pysetup/spec_builders/electra.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +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
'''

@classmethod
Expand All @@ -28,7 +29,6 @@ class NoopExecutionEngine(ExecutionEngine):

def notify_new_payload(self: ExecutionEngine,
execution_payload: ExecutionPayload,
execution_requests: ExecutionRequests,
parent_beacon_block_root: Root) -> bool:
return True

Expand All @@ -45,7 +45,8 @@ def get_payload(self: ExecutionEngine, payload_id: PayloadId) -> GetPayloadRespo

def is_valid_block_hash(self: ExecutionEngine,
execution_payload: ExecutionPayload,
parent_beacon_block_root: Root) -> bool:
parent_beacon_block_root: Root,
execution_requests_list: list[bytes]) -> bool:
return True

def is_valid_versioned_hashes(self: ExecutionEngine, new_payload_request: NewPayloadRequest) -> bool:
Expand Down
48 changes: 32 additions & 16 deletions specs/electra/beacon-chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,14 @@
- [Request data](#request-data)
- [Modified `NewPayloadRequest`](#modified-newpayloadrequest)
- [Engine APIs](#engine-apis)
- [Modified `notify_new_payload`](#modified-notify_new_payload)
- [Modified `is_valid_block_hash`](#modified-is_valid_block_hash)
- [Modified `verify_and_notify_new_payload`](#modified-verify_and_notify_new_payload)
- [Block processing](#block-processing)
- [Withdrawals](#withdrawals)
- [Modified `get_expected_withdrawals`](#modified-get_expected_withdrawals)
- [Modified `process_withdrawals`](#modified-process_withdrawals)
- [Execution payload](#execution-payload)
- [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 @@ -935,18 +936,17 @@ class NewPayloadRequest(object):

#### Engine APIs

##### Modified `notify_new_payload`
##### Modified `is_valid_block_hash`

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

```python
def notify_new_payload(self: ExecutionEngine,
execution_payload: ExecutionPayload,
execution_requests: ExecutionRequests,
parent_beacon_block_root: Root) -> bool:
def is_valid_block_hash(self: ExecutionEngine,
execution_payload: ExecutionPayload,
parent_beacon_block_root: Root,
execution_requests_list: list[bytes]) -> bool:
"""
Return ``True`` if and only if ``execution_payload`` and ``execution_requests``
are valid with respect to ``self.execution_state``.
Return ``True`` if and only if ``execution_payload.block_hash`` is computed correctly.
"""
...
```
Expand All @@ -963,19 +963,22 @@ def verify_and_notify_new_payload(self: ExecutionEngine,
Return ``True`` if and only if ``new_payload_request`` is valid with respect to ``self.execution_state``.
"""
execution_payload = new_payload_request.execution_payload
execution_requests = new_payload_request.execution_requests # [New in Electra]
parent_beacon_block_root = new_payload_request.parent_beacon_block_root
jtraglia marked this conversation as resolved.
Show resolved Hide resolved

if not self.is_valid_block_hash(execution_payload, parent_beacon_block_root):
# [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_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):
return False

# [Modified in Electra]
if not self.notify_new_payload(
execution_payload,
execution_requests,
execution_payload,
parent_beacon_block_root):
return False

Expand Down Expand Up @@ -1090,6 +1093,19 @@ def process_withdrawals(state: BeaconState, payload: ExecutionPayload) -> None:

#### Execution payload

##### New `get_execution_requests_list`

*Note*: Encodes execution layer requests as it is 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)

return [deposit_bytes, withdrawal_bytes, consolidation_bytes]
```

##### Modified `process_execution_payload`

*Note*: The function `process_execution_payload` is modified to pass `execution_requests` into `execution_engine.verify_and_notify_new_payload` (via the updated `NewPayloadRequest`).
Expand All @@ -1111,9 +1127,9 @@ def process_execution_payload(state: BeaconState, body: BeaconBlockBody, executi
assert execution_engine.verify_and_notify_new_payload(
NewPayloadRequest(
execution_payload=payload,
execution_requests=body.execution_requests, # [New in Electra]
versioned_hashes=versioned_hashes,
parent_beacon_block_root=state.latest_block_header.parent_root,
execution_requests=body.execution_requests, # [New in Electra]
)
)
# Cache execution payload header
Expand Down