From 3011727214a70ce8ddb0158dfbf3769d718f7d11 Mon Sep 17 00:00:00 2001 From: Lucas Saldanha Date: Thu, 10 Oct 2024 12:25:18 +1300 Subject: [PATCH 01/14] Updated validator spec with rules for including execution requests in the beacon block body --- specs/electra/validator.md | 50 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/specs/electra/validator.md b/specs/electra/validator.md index f589e963c5..e6f0906d83 100644 --- a/specs/electra/validator.md +++ b/specs/electra/validator.md @@ -38,6 +38,19 @@ All behaviors and definitions defined in this document, and documents it extends 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. Please see related Beacon Chain doc before continuing and use them as a reference throughout. +## Helpers + +### Modified `GetPayloadResponse` + +```python +@dataclass +class GetPayloadResponse(object): + execution_payload: ExecutionPayload + block_value: uint256 + blobs_bundle: BlobsBundle + execution_requests: list[bytes] # [New in Electra] +``` + ## Containers ### Modified Containers @@ -59,6 +72,24 @@ class SignedAggregateAndProof(Container): signature: BLSSignature ``` +## Protocol + +### `ExecutionEngine` + +#### Modified `get_payload` + +Given the `payload_id`, `get_payload` returns the most recent version of the execution payload that +has been built since the corresponding call to `notify_forkchoice_updated` method. + +```python +def get_payload(self: ExecutionEngine, payload_id: PayloadId) -> GetPayloadResponse: + """ + Return ExecutionPayload, uint256, BlobsBundle and list[bytes] objects. + """ + # pylint: disable=unused-argument + ... +``` + ## Block proposal ### Constructing the `BeaconBlockBody` @@ -148,6 +179,25 @@ def prepare_execution_payload(state: BeaconState, ) ``` +#### Execution Requests + +*[New in Electra]* + +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 +in [EIP-7685](https://eips.ethereum.org/EIPS/eip-7685). The index of each element in the array determines the type of request. +2. Set `block.body.execution_requests = get_execution_requests(execution_requests)`, where: + +```python +def get_execution_requests(execution_requests: list[bytes]) -> ExecutionRequests: + requests = ExecutionRequests() + + requests.deposits = deserialize(execution_requests[0], DepositRequest) + requests.withdrawals = deserialize(execution_requests[0], WithdrawalRequest) + requests.consolidations = deserialize(execution_requests[0], ConsolidationRequest) + + return requests +``` + ## Attesting ### Construct attestation From 1a2ff476d9c30497df1d872c3257049761343c99 Mon Sep 17 00:00:00 2001 From: Lucas Saldanha Date: Thu, 10 Oct 2024 12:42:59 +1300 Subject: [PATCH 02/14] Fix indexes --- specs/electra/validator.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/specs/electra/validator.md b/specs/electra/validator.md index e6f0906d83..02de8727e7 100644 --- a/specs/electra/validator.md +++ b/specs/electra/validator.md @@ -192,8 +192,8 @@ def get_execution_requests(execution_requests: list[bytes]) -> ExecutionRequests requests = ExecutionRequests() requests.deposits = deserialize(execution_requests[0], DepositRequest) - requests.withdrawals = deserialize(execution_requests[0], WithdrawalRequest) - requests.consolidations = deserialize(execution_requests[0], ConsolidationRequest) + requests.withdrawals = deserialize(execution_requests[1], WithdrawalRequest) + requests.consolidations = deserialize(execution_requests[2], ConsolidationRequest) return requests ``` From a3153a53ca12d6054a5f9c3ffebcab284e27b442 Mon Sep 17 00:00:00 2001 From: Lucas Saldanha Date: Thu, 10 Oct 2024 17:27:19 +1300 Subject: [PATCH 03/14] Add deserialize fn --- pysetup/spec_builders/electra.py | 2 +- specs/electra/validator.md | 10 ++++------ tests/core/pyspec/eth2spec/utils/ssz/ssz_impl.py | 2 ++ 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pysetup/spec_builders/electra.py b/pysetup/spec_builders/electra.py index 48082249b6..d08dd40248 100644 --- a/pysetup/spec_builders/electra.py +++ b/pysetup/spec_builders/electra.py @@ -10,7 +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 +from eth2spec.utils.ssz.ssz_impl import serialize, deserialize ''' @classmethod diff --git a/specs/electra/validator.md b/specs/electra/validator.md index 02de8727e7..1c715668ca 100644 --- a/specs/electra/validator.md +++ b/specs/electra/validator.md @@ -189,13 +189,11 @@ in [EIP-7685](https://eips.ethereum.org/EIPS/eip-7685). The index of each elemen ```python def get_execution_requests(execution_requests: list[bytes]) -> ExecutionRequests: - requests = ExecutionRequests() + deposits = deserialize(DepositRequest, execution_requests[0]) + withdrawals = deserialize(WithdrawalRequest, execution_requests[1]) + consolidations = deserialize(ConsolidationRequest, execution_requests[2]) - requests.deposits = deserialize(execution_requests[0], DepositRequest) - requests.withdrawals = deserialize(execution_requests[1], WithdrawalRequest) - requests.consolidations = deserialize(execution_requests[2], ConsolidationRequest) - - return requests + return ExecutionRequests(deposits, withdrawals, consolidations) ``` ## Attesting diff --git a/tests/core/pyspec/eth2spec/utils/ssz/ssz_impl.py b/tests/core/pyspec/eth2spec/utils/ssz/ssz_impl.py index 65808038ea..52164f593c 100644 --- a/tests/core/pyspec/eth2spec/utils/ssz/ssz_impl.py +++ b/tests/core/pyspec/eth2spec/utils/ssz/ssz_impl.py @@ -8,6 +8,8 @@ def serialize(obj: View) -> bytes: return obj.encode_bytes() +def deserialize(cls: View, data: bytes) -> object: + return cls.decode_bytes(data) def hash_tree_root(obj: View) -> Bytes32: return Bytes32(obj.get_backing().merkle_root()) From 5eb77c2655a4528ec3aa13548e94a5b577a6ef44 Mon Sep 17 00:00:00 2001 From: Lucas Saldanha Date: Thu, 10 Oct 2024 17:33:00 +1300 Subject: [PATCH 04/14] fix deserialize typing --- specs/electra/validator.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/specs/electra/validator.md b/specs/electra/validator.md index 1c715668ca..a2577f0343 100644 --- a/specs/electra/validator.md +++ b/specs/electra/validator.md @@ -189,9 +189,9 @@ in [EIP-7685](https://eips.ethereum.org/EIPS/eip-7685). The index of each elemen ```python def get_execution_requests(execution_requests: list[bytes]) -> ExecutionRequests: - deposits = deserialize(DepositRequest, execution_requests[0]) - withdrawals = deserialize(WithdrawalRequest, execution_requests[1]) - consolidations = deserialize(ConsolidationRequest, execution_requests[2]) + deposits = deserialize(List[DepositRequest, MAX_DEPOSIT_REQUESTS_PER_PAYLOAD], execution_requests[0]) + withdrawals = deserialize(List[WithdrawalRequest, MAX_WITHDRAWAL_REQUESTS_PER_PAYLOAD], execution_requests[1]) + consolidations = deserialize(List[ConsolidationRequest, MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD], execution_requests[2]) return ExecutionRequests(deposits, withdrawals, consolidations) ``` From cd51168bdfd7ae0bc1773ba20119c2e4b92d4d58 Mon Sep 17 00:00:00 2001 From: Lucas Saldanha Date: Thu, 10 Oct 2024 17:36:36 +1300 Subject: [PATCH 05/14] fix toc --- specs/electra/validator.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/specs/electra/validator.md b/specs/electra/validator.md index a2577f0343..b35ec2cbc5 100644 --- a/specs/electra/validator.md +++ b/specs/electra/validator.md @@ -8,16 +8,22 @@ - [Introduction](#introduction) - [Prerequisites](#prerequisites) +- [Helpers](#helpers) + - [Modified `GetPayloadResponse`](#modified-getpayloadresponse) - [Containers](#containers) - [Modified Containers](#modified-containers) - [`AggregateAndProof`](#aggregateandproof) - [`SignedAggregateAndProof`](#signedaggregateandproof) +- [Protocol](#protocol) + - [`ExecutionEngine`](#executionengine) + - [Modified `get_payload`](#modified-get_payload) - [Block proposal](#block-proposal) - [Constructing the `BeaconBlockBody`](#constructing-the-beaconblockbody) - [Attester slashings](#attester-slashings) - [Attestations](#attestations) - [Deposits](#deposits) - [Execution payload](#execution-payload) + - [Execution Requests](#execution-requests) - [Attesting](#attesting) - [Construct attestation](#construct-attestation) - [Attestation aggregation](#attestation-aggregation) From 16e6085a3c007af23577d827f2b5aaa02dd08dc8 Mon Sep 17 00:00:00 2001 From: Lucas Saldanha Date: Thu, 10 Oct 2024 18:06:57 +1300 Subject: [PATCH 06/14] Change list -> List --- specs/electra/validator.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/electra/validator.md b/specs/electra/validator.md index b35ec2cbc5..520862ed47 100644 --- a/specs/electra/validator.md +++ b/specs/electra/validator.md @@ -194,7 +194,7 @@ in [EIP-7685](https://eips.ethereum.org/EIPS/eip-7685). The index of each elemen 2. Set `block.body.execution_requests = get_execution_requests(execution_requests)`, where: ```python -def get_execution_requests(execution_requests: list[bytes]) -> ExecutionRequests: +def get_execution_requests(execution_requests: List[bytes]) -> ExecutionRequests: deposits = deserialize(List[DepositRequest, MAX_DEPOSIT_REQUESTS_PER_PAYLOAD], execution_requests[0]) withdrawals = deserialize(List[WithdrawalRequest, MAX_WITHDRAWAL_REQUESTS_PER_PAYLOAD], execution_requests[1]) consolidations = deserialize(List[ConsolidationRequest, MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD], execution_requests[2]) From bc3ee13797c0c9f976784e8a2fc66ff7f66bd46b Mon Sep 17 00:00:00 2001 From: Lucas Saldanha Date: Thu, 10 Oct 2024 19:22:40 +1300 Subject: [PATCH 07/14] Yet another change list -> List --- specs/electra/validator.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/specs/electra/validator.md b/specs/electra/validator.md index 520862ed47..016383c448 100644 --- a/specs/electra/validator.md +++ b/specs/electra/validator.md @@ -54,7 +54,7 @@ class GetPayloadResponse(object): execution_payload: ExecutionPayload block_value: uint256 blobs_bundle: BlobsBundle - execution_requests: list[bytes] # [New in Electra] + execution_requests: List[bytes] # [New in Electra] ``` ## Containers @@ -90,7 +90,7 @@ has been built since the corresponding call to `notify_forkchoice_updated` metho ```python def get_payload(self: ExecutionEngine, payload_id: PayloadId) -> GetPayloadResponse: """ - Return ExecutionPayload, uint256, BlobsBundle and list[bytes] objects. + Return ExecutionPayload, uint256, BlobsBundle and List[bytes] objects. """ # pylint: disable=unused-argument ... From 2a163adda29e411b8a52a51fd7004b9392b6a974 Mon Sep 17 00:00:00 2001 From: Lucas Saldanha Date: Thu, 10 Oct 2024 19:30:10 +1300 Subject: [PATCH 08/14] Fix lint errors --- specs/electra/validator.md | 3 ++- tests/core/pyspec/eth2spec/utils/ssz/ssz_impl.py | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/specs/electra/validator.md b/specs/electra/validator.md index 016383c448..169d3cdf5a 100644 --- a/specs/electra/validator.md +++ b/specs/electra/validator.md @@ -197,7 +197,8 @@ in [EIP-7685](https://eips.ethereum.org/EIPS/eip-7685). The index of each elemen def get_execution_requests(execution_requests: List[bytes]) -> ExecutionRequests: deposits = deserialize(List[DepositRequest, MAX_DEPOSIT_REQUESTS_PER_PAYLOAD], execution_requests[0]) withdrawals = deserialize(List[WithdrawalRequest, MAX_WITHDRAWAL_REQUESTS_PER_PAYLOAD], execution_requests[1]) - consolidations = deserialize(List[ConsolidationRequest, MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD], execution_requests[2]) + consolidations = deserialize(List[ConsolidationRequest, MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD], + execution_requests[2]) return ExecutionRequests(deposits, withdrawals, consolidations) ``` diff --git a/tests/core/pyspec/eth2spec/utils/ssz/ssz_impl.py b/tests/core/pyspec/eth2spec/utils/ssz/ssz_impl.py index 52164f593c..1edeb05d29 100644 --- a/tests/core/pyspec/eth2spec/utils/ssz/ssz_impl.py +++ b/tests/core/pyspec/eth2spec/utils/ssz/ssz_impl.py @@ -8,9 +8,11 @@ def serialize(obj: View) -> bytes: return obj.encode_bytes() + def deserialize(cls: View, data: bytes) -> object: return cls.decode_bytes(data) + def hash_tree_root(obj: View) -> Bytes32: return Bytes32(obj.get_backing().merkle_root()) From 04a40d2afbbce741c13f72feb98433879d2db291 Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Thu, 10 Oct 2024 08:39:06 -0500 Subject: [PATCH 09/14] Use Sequence for serialized execution requests --- specs/electra/beacon-chain.md | 6 +++--- specs/electra/validator.md | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/specs/electra/beacon-chain.md b/specs/electra/beacon-chain.md index 7c6d9fe1fa..8dca8efa4e 100644 --- a/specs/electra/beacon-chain.md +++ b/specs/electra/beacon-chain.md @@ -992,9 +992,9 @@ class NewPayloadRequest(object): def notify_new_payload(self: ExecutionEngine, execution_payload: ExecutionPayload, parent_beacon_block_root: Root, - execution_requests_list: list[bytes]) -> bool: + execution_requests_list: Sequence[bytes]) -> bool: """ - Return ``True`` if and only if ``execution_payload`` and ``execution_requests`` + Return ``True`` if and only if ``execution_payload`` and ``execution_requests`` are valid with respect to ``self.execution_state``. """ ... @@ -1145,7 +1145,7 @@ def process_withdrawals(state: BeaconState, payload: ExecutionPayload) -> None: *Note*: Encodes execution requests as defined by [EIP-7685](https://eips.ethereum.org/EIPS/eip-7685). ```python -def get_execution_requests_list(execution_requests: ExecutionRequests) -> list[bytes]: +def get_execution_requests_list(execution_requests: ExecutionRequests) -> Sequence[bytes]: deposit_bytes = serialize(execution_requests.deposits) withdrawal_bytes = serialize(execution_requests.withdrawals) consolidation_bytes = serialize(execution_requests.consolidations) diff --git a/specs/electra/validator.md b/specs/electra/validator.md index 169d3cdf5a..fe9c143d02 100644 --- a/specs/electra/validator.md +++ b/specs/electra/validator.md @@ -54,7 +54,7 @@ class GetPayloadResponse(object): execution_payload: ExecutionPayload block_value: uint256 blobs_bundle: BlobsBundle - execution_requests: List[bytes] # [New in Electra] + execution_requests: Sequence[bytes] # [New in Electra] ``` ## Containers @@ -90,7 +90,7 @@ has been built since the corresponding call to `notify_forkchoice_updated` metho ```python def get_payload(self: ExecutionEngine, payload_id: PayloadId) -> GetPayloadResponse: """ - Return ExecutionPayload, uint256, BlobsBundle and List[bytes] objects. + Return ExecutionPayload, uint256, BlobsBundle and Sequence[bytes] objects. """ # pylint: disable=unused-argument ... @@ -194,10 +194,10 @@ in [EIP-7685](https://eips.ethereum.org/EIPS/eip-7685). The index of each elemen 2. Set `block.body.execution_requests = get_execution_requests(execution_requests)`, where: ```python -def get_execution_requests(execution_requests: List[bytes]) -> ExecutionRequests: +def get_execution_requests(execution_requests: Sequence[bytes]) -> ExecutionRequests: deposits = deserialize(List[DepositRequest, MAX_DEPOSIT_REQUESTS_PER_PAYLOAD], execution_requests[0]) withdrawals = deserialize(List[WithdrawalRequest, MAX_WITHDRAWAL_REQUESTS_PER_PAYLOAD], execution_requests[1]) - consolidations = deserialize(List[ConsolidationRequest, MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD], + consolidations = deserialize(List[ConsolidationRequest, MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD], execution_requests[2]) return ExecutionRequests(deposits, withdrawals, consolidations) From 5e9d27dc3232ed93bdd2d66e653edbed8bde5fee Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Thu, 10 Oct 2024 08:45:10 -0500 Subject: [PATCH 10/14] Use Sequence in NoopExecutionEngine too --- pysetup/spec_builders/electra.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pysetup/spec_builders/electra.py b/pysetup/spec_builders/electra.py index d08dd40248..23237dce91 100644 --- a/pysetup/spec_builders/electra.py +++ b/pysetup/spec_builders/electra.py @@ -30,7 +30,7 @@ class NoopExecutionEngine(ExecutionEngine): def notify_new_payload(self: ExecutionEngine, execution_payload: ExecutionPayload, parent_beacon_block_root: Root, - execution_requests_list: list[bytes]) -> bool: + execution_requests_list: Sequence[bytes]) -> bool: return True def notify_forkchoice_updated(self: ExecutionEngine, From 0ecc87164b0b09f9659800ab45214408d00f8028 Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Thu, 10 Oct 2024 09:43:50 -0500 Subject: [PATCH 11/14] Update deserialize() definition --- tests/core/pyspec/eth2spec/utils/ssz/ssz_impl.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/core/pyspec/eth2spec/utils/ssz/ssz_impl.py b/tests/core/pyspec/eth2spec/utils/ssz/ssz_impl.py index 1edeb05d29..a76cf80f90 100644 --- a/tests/core/pyspec/eth2spec/utils/ssz/ssz_impl.py +++ b/tests/core/pyspec/eth2spec/utils/ssz/ssz_impl.py @@ -1,7 +1,7 @@ from typing import TypeVar from remerkleable.basic import uint -from remerkleable.core import View +from remerkleable.core import Type, View from remerkleable.byte_arrays import Bytes32 @@ -9,8 +9,8 @@ def serialize(obj: View) -> bytes: return obj.encode_bytes() -def deserialize(cls: View, data: bytes) -> object: - return cls.decode_bytes(data) +def deserialize(typ: Type[View], data: bytes) -> View: + return typ.decode_bytes(data) def hash_tree_root(obj: View) -> Bytes32: From f9ae4c5501b7f1ddbcbca01c507f5e69dcf83a2c Mon Sep 17 00:00:00 2001 From: Justin Traglia <95511699+jtraglia@users.noreply.github.com> Date: Thu, 10 Oct 2024 13:29:12 -0500 Subject: [PATCH 12/14] Clarify execution requests return Co-authored-by: Alex Stokes --- specs/electra/validator.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/electra/validator.md b/specs/electra/validator.md index fe9c143d02..29293d301c 100644 --- a/specs/electra/validator.md +++ b/specs/electra/validator.md @@ -90,7 +90,7 @@ has been built since the corresponding call to `notify_forkchoice_updated` metho ```python def get_payload(self: ExecutionEngine, payload_id: PayloadId) -> GetPayloadResponse: """ - Return ExecutionPayload, uint256, BlobsBundle and Sequence[bytes] objects. + Return ExecutionPayload, uint256, BlobsBundle and execution requests (as Sequence[bytes]) objects. """ # pylint: disable=unused-argument ... From 83c04b8469c6a9f930795313914353f4db9f6817 Mon Sep 17 00:00:00 2001 From: Justin Traglia <95511699+jtraglia@users.noreply.github.com> Date: Thu, 10 Oct 2024 13:29:27 -0500 Subject: [PATCH 13/14] Capitalize SSZ Co-authored-by: Alex Stokes --- specs/electra/validator.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/electra/validator.md b/specs/electra/validator.md index 29293d301c..4622ff4805 100644 --- a/specs/electra/validator.md +++ b/specs/electra/validator.md @@ -189,7 +189,7 @@ def prepare_execution_payload(state: BeaconState, *[New in Electra]* -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 +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 in [EIP-7685](https://eips.ethereum.org/EIPS/eip-7685). The index of each element in the array determines the type of request. 2. Set `block.body.execution_requests = get_execution_requests(execution_requests)`, where: From 6416a562abb6085b87889e9c202cd3d2cb7d2b39 Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Thu, 10 Oct 2024 13:41:02 -0500 Subject: [PATCH 14/14] Add ssz_{de,}serialize aliases --- pysetup/spec_builders/electra.py | 2 +- specs/electra/beacon-chain.md | 6 +++--- specs/electra/validator.md | 8 ++++---- tests/core/pyspec/eth2spec/utils/ssz/ssz_impl.py | 12 ++++++++++-- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/pysetup/spec_builders/electra.py b/pysetup/spec_builders/electra.py index 23237dce91..6746d9aada 100644 --- a/pysetup/spec_builders/electra.py +++ b/pysetup/spec_builders/electra.py @@ -10,7 +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, deserialize +from eth2spec.utils.ssz.ssz_impl import ssz_serialize, ssz_deserialize ''' @classmethod diff --git a/specs/electra/beacon-chain.md b/specs/electra/beacon-chain.md index 8dca8efa4e..aff2167cfc 100644 --- a/specs/electra/beacon-chain.md +++ b/specs/electra/beacon-chain.md @@ -1146,9 +1146,9 @@ def process_withdrawals(state: BeaconState, payload: ExecutionPayload) -> None: ```python def get_execution_requests_list(execution_requests: ExecutionRequests) -> Sequence[bytes]: - deposit_bytes = serialize(execution_requests.deposits) - withdrawal_bytes = serialize(execution_requests.withdrawals) - consolidation_bytes = serialize(execution_requests.consolidations) + deposit_bytes = ssz_serialize(execution_requests.deposits) + withdrawal_bytes = ssz_serialize(execution_requests.withdrawals) + consolidation_bytes = ssz_serialize(execution_requests.consolidations) return [deposit_bytes, withdrawal_bytes, consolidation_bytes] ``` diff --git a/specs/electra/validator.md b/specs/electra/validator.md index 4622ff4805..ae8d53c8f0 100644 --- a/specs/electra/validator.md +++ b/specs/electra/validator.md @@ -195,10 +195,10 @@ in [EIP-7685](https://eips.ethereum.org/EIPS/eip-7685). The index of each elemen ```python def get_execution_requests(execution_requests: Sequence[bytes]) -> ExecutionRequests: - deposits = deserialize(List[DepositRequest, MAX_DEPOSIT_REQUESTS_PER_PAYLOAD], execution_requests[0]) - withdrawals = deserialize(List[WithdrawalRequest, MAX_WITHDRAWAL_REQUESTS_PER_PAYLOAD], execution_requests[1]) - consolidations = deserialize(List[ConsolidationRequest, MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD], - execution_requests[2]) + deposits = ssz_deserialize(List[DepositRequest, MAX_DEPOSIT_REQUESTS_PER_PAYLOAD], execution_requests[0]) + withdrawals = ssz_deserialize(List[WithdrawalRequest, MAX_WITHDRAWAL_REQUESTS_PER_PAYLOAD], execution_requests[1]) + consolidations = ssz_deserialize(List[ConsolidationRequest, MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD], + execution_requests[2]) return ExecutionRequests(deposits, withdrawals, consolidations) ``` diff --git a/tests/core/pyspec/eth2spec/utils/ssz/ssz_impl.py b/tests/core/pyspec/eth2spec/utils/ssz/ssz_impl.py index a76cf80f90..645cbff775 100644 --- a/tests/core/pyspec/eth2spec/utils/ssz/ssz_impl.py +++ b/tests/core/pyspec/eth2spec/utils/ssz/ssz_impl.py @@ -5,14 +5,22 @@ from remerkleable.byte_arrays import Bytes32 -def serialize(obj: View) -> bytes: +def ssz_serialize(obj: View) -> bytes: return obj.encode_bytes() -def deserialize(typ: Type[View], data: bytes) -> View: +def serialize(obj: View) -> bytes: + return ssz_serialize(obj) + + +def ssz_deserialize(typ: Type[View], data: bytes) -> View: return typ.decode_bytes(data) +def deserialize(typ: Type[View], data: bytes) -> View: + return ssz_deserialize(typ, data) + + def hash_tree_root(obj: View) -> Bytes32: return Bytes32(obj.get_backing().merkle_root())