From 8f2cb7c8a7196df5aaf982171cf64afd542f1623 Mon Sep 17 00:00:00 2001 From: Mikhail Kalinin Date: Mon, 30 Sep 2024 17:25:25 +0400 Subject: [PATCH 1/9] Pass execution_requests_hash to notify_new_payload --- pysetup/spec_builders/electra.py | 1 + specs/electra/beacon-chain.md | 42 +++++++++++++++++++++++++------- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/pysetup/spec_builders/electra.py b/pysetup/spec_builders/electra.py index 2ab1f5ecfb..365b085741 100644 --- a/pysetup/spec_builders/electra.py +++ b/pysetup/spec_builders/electra.py @@ -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 diff --git a/specs/electra/beacon-chain.md b/specs/electra/beacon-chain.md index dbf84d8de8..6e3b8daf31 100644 --- a/specs/electra/beacon-chain.md +++ b/specs/electra/beacon-chain.md @@ -12,6 +12,7 @@ - [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) @@ -84,6 +85,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) - [Modified `process_execution_payload`](#modified-process_execution_payload) - [Operations](#operations) - [Modified `process_operations`](#modified-process_operations) @@ -134,6 +136,14 @@ 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 @@ -930,20 +940,20 @@ class NewPayloadRequest(object): execution_payload: ExecutionPayload versioned_hashes: Sequence[VersionedHash] parent_beacon_block_root: Root - execution_requests: ExecutionRequests # [New in Electra] + execution_requests_hash: Hash32 # [New in Electra] ``` #### Engine APIs ##### Modified `notify_new_payload` -*Note*: The function `notify_new_payload` is modified to include the additional `execution_requests` parameter in Electra. +*Note*: The function `notify_new_payload` is modified to include the additional `execution_requests_hash` parameter in Electra. ```python def notify_new_payload(self: ExecutionEngine, execution_payload: ExecutionPayload, - execution_requests: ExecutionRequests, - parent_beacon_block_root: Root) -> bool: + parent_beacon_block_root: Root, + execution_requests_hash: execution_requests_hash) -> bool: """ Return ``True`` if and only if ``execution_payload`` and ``execution_requests`` are valid with respect to ``self.execution_state``. @@ -963,7 +973,7 @@ 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] + execution_requests_hash = new_payload_request.execution_requests_hash # [New in Electra] parent_beacon_block_root = new_payload_request.parent_beacon_block_root if not self.is_valid_block_hash(execution_payload, parent_beacon_block_root): @@ -974,9 +984,9 @@ def verify_and_notify_new_payload(self: ExecutionEngine, # [Modified in Electra] if not self.notify_new_payload( - execution_payload, - execution_requests, - parent_beacon_block_root): + execution_payload, + parent_beacon_block_root, + execution_requests_hash): return False return True @@ -1090,6 +1100,20 @@ def process_withdrawals(state: BeaconState, payload: ExecutionPayload) -> None: #### Execution payload +##### New `compute_execution_requests_hash` + +*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). + +```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) + + return hash(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`). @@ -1111,9 +1135,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_hash=compute_execution_requests_hash(execution_requests), # [New in Electra] ) ) # Cache execution payload header From a00d1fd0340899756d60008d53a0cc6170b39eaa Mon Sep 17 00:00:00 2001 From: Mikhail Kalinin Date: Tue, 1 Oct 2024 11:07:55 +0400 Subject: [PATCH 2/9] Apply suggestions by @ralexstokes Co-authored-by: Alex Stokes --- specs/electra/beacon-chain.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/electra/beacon-chain.md b/specs/electra/beacon-chain.md index 6e3b8daf31..07c4e6bb48 100644 --- a/specs/electra/beacon-chain.md +++ b/specs/electra/beacon-chain.md @@ -1137,7 +1137,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(execution_requests), # [New in Electra] + execution_requests_hash=compute_execution_requests_hash(body.execution_requests), # [New in Electra] ) ) # Cache execution payload header From 69b7be50e95e11927f0cd8ccd30820505eb64361 Mon Sep 17 00:00:00 2001 From: Mikhail Kalinin Date: Tue, 1 Oct 2024 11:28:57 +0400 Subject: [PATCH 3/9] Fix expression order in verify_and_notify_new_payload --- specs/electra/beacon-chain.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/electra/beacon-chain.md b/specs/electra/beacon-chain.md index 07c4e6bb48..d6ff242048 100644 --- a/specs/electra/beacon-chain.md +++ b/specs/electra/beacon-chain.md @@ -973,8 +973,8 @@ 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_hash = new_payload_request.execution_requests_hash # [New in Electra] parent_beacon_block_root = new_payload_request.parent_beacon_block_root + execution_requests_hash = new_payload_request.execution_requests_hash # [New in Electra] if not self.is_valid_block_hash(execution_payload, parent_beacon_block_root): return False From 21fdd8598c5db162b2ae4f2ffd1d85a524c87442 Mon Sep 17 00:00:00 2001 From: Mikhail Kalinin Date: Tue, 1 Oct 2024 12:09:53 +0400 Subject: [PATCH 4/9] Pass execution_requests_hash only to is_valid_block_hash --- pysetup/spec_builders/electra.py | 4 ++-- specs/_features/eip7732/beacon-chain.md | 2 +- specs/electra/beacon-chain.md | 29 +++++++++++++------------ 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/pysetup/spec_builders/electra.py b/pysetup/spec_builders/electra.py index 365b085741..859cf6d4ec 100644 --- a/pysetup/spec_builders/electra.py +++ b/pysetup/spec_builders/electra.py @@ -29,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 @@ -46,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_hash: Hash32) -> bool: return True def is_valid_versioned_hashes(self: ExecutionEngine, new_payload_request: NewPayloadRequest) -> bool: diff --git a/specs/_features/eip7732/beacon-chain.md b/specs/_features/eip7732/beacon-chain.md index ec38d41674..127b46a640 100644 --- a/specs/_features/eip7732/beacon-chain.md +++ b/specs/_features/eip7732/beacon-chain.md @@ -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=requests, + execution_requests_hash=compute_execution_requests_hash(requests), ) ) diff --git a/specs/electra/beacon-chain.md b/specs/electra/beacon-chain.md index d6ff242048..29995708d8 100644 --- a/specs/electra/beacon-chain.md +++ b/specs/electra/beacon-chain.md @@ -78,7 +78,7 @@ - [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) @@ -940,23 +940,22 @@ class NewPayloadRequest(object): execution_payload: ExecutionPayload versioned_hashes: Sequence[VersionedHash] parent_beacon_block_root: Root - execution_requests_hash: Hash32 # [New in Electra] + execution_requests_hash: Hash32 # [New in Electra:EIP7685] ``` #### 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_hash` parameter in Electra. +*Note*: The function `is_valid_block_hash` is modified to include the additional `execution_requests_hash` parameter for EIP-7685. ```python -def notify_new_payload(self: ExecutionEngine, - execution_payload: ExecutionPayload, - parent_beacon_block_root: Root, - execution_requests_hash: execution_requests_hash) -> bool: +def is_valid_block_hash(self: ExecutionEngine, + execution_payload: ExecutionPayload, + parent_beacon_block_root: Root, + execution_requests_hash: Hash32) -> 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. """ ... ``` @@ -976,17 +975,19 @@ def verify_and_notify_new_payload(self: ExecutionEngine, parent_beacon_block_root = new_payload_request.parent_beacon_block_root execution_requests_hash = new_payload_request.execution_requests_hash # [New in Electra] - if not self.is_valid_block_hash(execution_payload, parent_beacon_block_root): + # [Modified in Electra:EIP7685] + if not self.is_valid_block_hash( + execution_payload, + parent_beacon_block_root, + execution_requests_hash): 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, - parent_beacon_block_root, - execution_requests_hash): + parent_beacon_block_root): return False return True From 601631fa898caf5d68cccf0b4b608ad06835d1b9 Mon Sep 17 00:00:00 2001 From: Mikhail Kalinin Date: Thu, 3 Oct 2024 17:39:41 +0400 Subject: [PATCH 5/9] Send execution_requests to EE as a list of byte sequences --- pysetup/spec_builders/electra.py | 2 +- specs/_features/eip7732/beacon-chain.md | 2 +- specs/electra/beacon-chain.md | 39 ++++++++++--------------- 3 files changed, 17 insertions(+), 26 deletions(-) diff --git a/pysetup/spec_builders/electra.py b/pysetup/spec_builders/electra.py index 859cf6d4ec..1307312dff 100644 --- a/pysetup/spec_builders/electra.py +++ b/pysetup/spec_builders/electra.py @@ -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: diff --git a/specs/_features/eip7732/beacon-chain.md b/specs/_features/eip7732/beacon-chain.md index 127b46a640..ec38d41674 100644 --- a/specs/_features/eip7732/beacon-chain.md +++ b/specs/_features/eip7732/beacon-chain.md @@ -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, ) ) diff --git a/specs/electra/beacon-chain.md b/specs/electra/beacon-chain.md index 29995708d8..497487169d 100644 --- a/specs/electra/beacon-chain.md +++ b/specs/electra/beacon-chain.md @@ -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) @@ -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) @@ -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 @@ -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. """ @@ -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): @@ -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` @@ -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 From 6f4cc2b44f86be348a5ca68be5d33b14e69f712a Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Mon, 7 Oct 2024 11:13:32 -0500 Subject: [PATCH 6/9] Revert "Send execution_requests to EE as a list of byte sequences" This reverts commit 601631fa898caf5d68cccf0b4b608ad06835d1b9. --- pysetup/spec_builders/electra.py | 2 +- specs/_features/eip7732/beacon-chain.md | 2 +- specs/electra/beacon-chain.md | 39 +++++++++++++++---------- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/pysetup/spec_builders/electra.py b/pysetup/spec_builders/electra.py index 1307312dff..859cf6d4ec 100644 --- a/pysetup/spec_builders/electra.py +++ b/pysetup/spec_builders/electra.py @@ -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_list: list[bytes]) -> bool: + execution_requests_hash: Hash32) -> bool: return True def is_valid_versioned_hashes(self: ExecutionEngine, new_payload_request: NewPayloadRequest) -> bool: diff --git a/specs/_features/eip7732/beacon-chain.md b/specs/_features/eip7732/beacon-chain.md index ec38d41674..127b46a640 100644 --- a/specs/_features/eip7732/beacon-chain.md +++ b/specs/_features/eip7732/beacon-chain.md @@ -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=requests, + execution_requests_hash=compute_execution_requests_hash(requests), ) ) diff --git a/specs/electra/beacon-chain.md b/specs/electra/beacon-chain.md index 497487169d..29995708d8 100644 --- a/specs/electra/beacon-chain.md +++ b/specs/electra/beacon-chain.md @@ -12,6 +12,7 @@ - [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) @@ -84,7 +85,7 @@ - [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) + - [New `compute_execution_requests_hash`](#new-compute_execution_requests_hash) - [Modified `process_execution_payload`](#modified-process_execution_payload) - [Operations](#operations) - [Modified `process_operations`](#modified-process_operations) @@ -135,6 +136,14 @@ 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 @@ -931,20 +940,20 @@ class NewPayloadRequest(object): execution_payload: ExecutionPayload versioned_hashes: Sequence[VersionedHash] parent_beacon_block_root: Root - execution_requests: ExecutionRequests # [New in Electra] + execution_requests_hash: Hash32 # [New in Electra:EIP7685] ``` #### Engine APIs ##### Modified `is_valid_block_hash` -*Note*: The function `is_valid_block_hash` is modified to include the additional `execution_requests_list` parameter for EIP-7685. +*Note*: The function `is_valid_block_hash` is modified to include the additional `execution_requests_hash` parameter for EIP-7685. ```python def is_valid_block_hash(self: ExecutionEngine, execution_payload: ExecutionPayload, parent_beacon_block_root: Root, - execution_requests_list: list[bytes]) -> bool: + execution_requests_hash: Hash32) -> bool: """ Return ``True`` if and only if ``execution_payload.block_hash`` is computed correctly. """ @@ -964,14 +973,13 @@ 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 - # [New in Electra] - execution_requests_list = get_execution_requests_list(new_payload_request.execution_requests) + execution_requests_hash = new_payload_request.execution_requests_hash # [New in Electra] # [Modified in Electra:EIP7685] if not self.is_valid_block_hash( execution_payload, parent_beacon_block_root, - execution_requests_list): + execution_requests_hash): return False if not self.is_valid_versioned_hashes(new_payload_request): @@ -1093,17 +1101,18 @@ def process_withdrawals(state: BeaconState, payload: ExecutionPayload) -> None: #### Execution payload -##### New `get_execution_requests_list` +##### New `compute_execution_requests_hash` -*Note*: Encodes execution layer requests as it is defined by [EIP-7685](https://eips.ethereum.org/EIPS/eip-7685). +*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). ```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 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) - return [deposit_bytes, withdrawal_bytes, consolidation_bytes] + return hash(deposit_bytes + withdrawal_bytes + consolidation_bytes) ``` ##### Modified `process_execution_payload` @@ -1129,7 +1138,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=body.execution_requests, # [New in Electra] + execution_requests_hash=compute_execution_requests_hash(body.execution_requests), # [New in Electra] ) ) # Cache execution payload header From ca62ad1b888bd4bcf01e10848e5566d77d108e3b Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Mon, 7 Oct 2024 18:13:40 -0500 Subject: [PATCH 7/9] Fix hash computation --- specs/electra/beacon-chain.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/specs/electra/beacon-chain.md b/specs/electra/beacon-chain.md index 29995708d8..a3deb06f82 100644 --- a/specs/electra/beacon-chain.md +++ b/specs/electra/beacon-chain.md @@ -1108,11 +1108,11 @@ The computation algorithm is defined by [EIP-7685](https://eips.ethereum.org/EIP ```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) - - return hash(deposit_bytes + withdrawal_bytes + consolidation_bytes) + deposit_requests = DEPOSIT_REQUEST_TYPE + serialize(execution_requests.deposits) + withdrawal_requests = WITHDRAWAL_REQUEST_TYPE + serialize(execution_requests.withdrawals) + consolidation_requests = CONSOLIDATION_REQUEST_TYPE + serialize(execution_requests.consolidations) + + return hash(hash(deposit_requests) + hash(withdrawal_requests) + hash(consolidation_requests)) ``` ##### Modified `process_execution_payload` From 3e3eec607c5e933468b97ad4e53998e084f3ea23 Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Mon, 7 Oct 2024 18:14:27 -0500 Subject: [PATCH 8/9] Delete trailing whitespace --- specs/electra/beacon-chain.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/electra/beacon-chain.md b/specs/electra/beacon-chain.md index a3deb06f82..5861aabe6b 100644 --- a/specs/electra/beacon-chain.md +++ b/specs/electra/beacon-chain.md @@ -1111,7 +1111,7 @@ def compute_execution_requests_hash(execution_requests: ExecutionRequests) -> Ha deposit_requests = DEPOSIT_REQUEST_TYPE + serialize(execution_requests.deposits) withdrawal_requests = WITHDRAWAL_REQUEST_TYPE + serialize(execution_requests.withdrawals) consolidation_requests = CONSOLIDATION_REQUEST_TYPE + serialize(execution_requests.consolidations) - + return hash(hash(deposit_requests) + hash(withdrawal_requests) + hash(consolidation_requests)) ``` From 04b2a555a4777c2bd73e31bdf35eee3e14ac36e9 Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Mon, 7 Oct 2024 19:21:21 -0500 Subject: [PATCH 9/9] Compute requests hash in verify_and_notify_new_payload --- specs/_features/eip7732/beacon-chain.md | 2 +- specs/electra/beacon-chain.md | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/specs/_features/eip7732/beacon-chain.md b/specs/_features/eip7732/beacon-chain.md index 3810f2fd49..30651cedbe 100644 --- a/specs/_features/eip7732/beacon-chain.md +++ b/specs/_features/eip7732/beacon-chain.md @@ -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, ) ) diff --git a/specs/electra/beacon-chain.md b/specs/electra/beacon-chain.md index 4a6ab9eb33..9dfd3ec4a4 100644 --- a/specs/electra/beacon-chain.md +++ b/specs/electra/beacon-chain.md @@ -988,7 +988,7 @@ 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:EIP7685] ``` #### Engine APIs @@ -1021,7 +1021,8 @@ 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_hash = compute_execution_requests_hash(new_payload_request.execution_requests) # [Modified in Electra:EIP7685] if not self.is_valid_block_hash( @@ -1187,7 +1188,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