From 745b4dd3db14a4d0ae48d9bfb36f43e7f007f23a Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Mon, 7 Oct 2024 07:24:13 -0500 Subject: [PATCH 1/7] Move yield pre-state after state setup --- .../test/electra/sanity/blocks/test_blocks.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/electra/sanity/blocks/test_blocks.py b/tests/core/pyspec/eth2spec/test/electra/sanity/blocks/test_blocks.py index 0bb8f32d46..c3d2284610 100644 --- a/tests/core/pyspec/eth2spec/test/electra/sanity/blocks/test_blocks.py +++ b/tests/core/pyspec/eth2spec/test/electra/sanity/blocks/test_blocks.py @@ -28,13 +28,13 @@ def test_basic_el_withdrawal_request(spec, state): # move state forward SHARD_COMMITTEE_PERIOD epochs to allow for exit state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH - yield 'pre', state - validator_index = 0 address = b'\x22' * 20 set_eth1_withdrawal_credential_with_balance(spec, state, validator_index, address=address) assert state.validators[validator_index].exit_epoch == spec.FAR_FUTURE_EPOCH + yield 'pre', state + validator_pubkey = state.validators[validator_index].pubkey withdrawal_request = spec.WithdrawalRequest( source_address=address, @@ -57,10 +57,11 @@ def test_basic_btec_and_el_withdrawal_request_in_same_block(spec, state): # move state forward SHARD_COMMITTEE_PERIOD epochs to allow for exit state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH - yield 'pre', state validator_index = 0 assert state.validators[validator_index].exit_epoch == spec.FAR_FUTURE_EPOCH + yield 'pre', state + block = build_empty_block_for_next_slot(spec, state) address = b'\x22' * 20 @@ -99,11 +100,11 @@ def test_basic_btec_before_el_withdrawal_request(spec, state): # move state forward SHARD_COMMITTEE_PERIOD epochs to allow for exit state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH - yield 'pre', state - validator_index = 0 assert state.validators[validator_index].exit_epoch == spec.FAR_FUTURE_EPOCH + yield 'pre', state + # block_1 contains a BTEC operation of the given validator address = b'\x22' * 20 signed_address_change = get_signed_address_change( @@ -146,13 +147,13 @@ def test_cl_exit_and_el_withdrawal_request_in_same_block(spec, state): # move state forward SHARD_COMMITTEE_PERIOD epochs to allow for exit state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH - yield 'pre', state - validator_index = 0 address = b'\x22' * 20 set_eth1_withdrawal_credential_with_balance(spec, state, validator_index, address=address) assert state.validators[validator_index].exit_epoch == spec.FAR_FUTURE_EPOCH + yield 'pre', state + # CL-Exit signed_voluntary_exits = prepare_signed_exits(spec, state, indices=[validator_index]) # EL-Exit From 8d7613821cb259ba879178d07b4e71a0cb1c10a4 Mon Sep 17 00:00:00 2001 From: Justin Traglia <95511699+jtraglia@users.noreply.github.com> Date: Mon, 7 Oct 2024 19:30:29 -0500 Subject: [PATCH 2/7] Bump version to 1.5.0-alpha.8 --- tests/core/pyspec/eth2spec/VERSION.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/core/pyspec/eth2spec/VERSION.txt b/tests/core/pyspec/eth2spec/VERSION.txt index d1cdd9f1e4..93244d44a1 100644 --- a/tests/core/pyspec/eth2spec/VERSION.txt +++ b/tests/core/pyspec/eth2spec/VERSION.txt @@ -1 +1 @@ -1.5.0-alpha.7 +1.5.0-alpha.8 From 7df8ab7f4a454c2b32386e885d7af50000ad96f1 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Tue, 8 Oct 2024 14:35:09 +0800 Subject: [PATCH 3/7] Add Electra `test_process_withdrawals` path to testgen --- tests/generators/operations/main.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/generators/operations/main.py b/tests/generators/operations/main.py index 51cd507066..ae66843f61 100644 --- a/tests/generators/operations/main.py +++ b/tests/generators/operations/main.py @@ -49,6 +49,7 @@ 'deposit_request', 'voluntary_exit', 'withdrawal_request', + 'withdrawals', ]} electra_mods = combine_mods(_new_electra_mods, deneb_mods) From a624d4cd9376da2b89ac4ad69dd3e30db2ad0bec Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Tue, 8 Oct 2024 11:08:11 -0500 Subject: [PATCH 4/7] Move execution_requests after parent_beacon_block_root --- pysetup/spec_builders/electra.py | 4 ++-- specs/electra/beacon-chain.md | 13 ++++++------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/pysetup/spec_builders/electra.py b/pysetup/spec_builders/electra.py index 2ab1f5ecfb..4c7ef7e9ed 100644 --- a/pysetup/spec_builders/electra.py +++ b/pysetup/spec_builders/electra.py @@ -28,8 +28,8 @@ class NoopExecutionEngine(ExecutionEngine): 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: ExecutionRequests) -> bool: return True def notify_forkchoice_updated(self: ExecutionEngine, diff --git a/specs/electra/beacon-chain.md b/specs/electra/beacon-chain.md index c231e718e7..0e6c3a3754 100644 --- a/specs/electra/beacon-chain.md +++ b/specs/electra/beacon-chain.md @@ -990,8 +990,8 @@ class NewPayloadRequest(object): ```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: ExecutionRequests) -> bool: """ Return ``True`` if and only if ``execution_payload`` and ``execution_requests`` are valid with respect to ``self.execution_state``. @@ -1011,8 +1011,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 = new_payload_request.execution_requests # [New in Electra] parent_beacon_block_root = new_payload_request.parent_beacon_block_root + execution_requests = new_payload_request.execution_requests # [New in Electra] if not self.is_valid_block_hash(execution_payload, parent_beacon_block_root): return False @@ -1022,9 +1022,8 @@ 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): + parent_beacon_block_root, + execution_requests): return False return True @@ -1160,9 +1159,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 From a44071a9a522915a8640013943d5f5e05cd5b5dd Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Tue, 8 Oct 2024 12:19:13 -0500 Subject: [PATCH 5/7] Pass execution requests to Engine API as a list of bytes --- pysetup/spec_builders/electra.py | 3 ++- specs/electra/beacon-chain.md | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/pysetup/spec_builders/electra.py b/pysetup/spec_builders/electra.py index 2ab1f5ecfb..a374b7384c 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 @@ -28,7 +29,7 @@ class NoopExecutionEngine(ExecutionEngine): def notify_new_payload(self: ExecutionEngine, execution_payload: ExecutionPayload, - execution_requests: ExecutionRequests, + execution_requests_list: list[bytes], parent_beacon_block_root: Root) -> bool: return True diff --git a/specs/electra/beacon-chain.md b/specs/electra/beacon-chain.md index c231e718e7..6c679afcc8 100644 --- a/specs/electra/beacon-chain.md +++ b/specs/electra/beacon-chain.md @@ -990,7 +990,7 @@ class NewPayloadRequest(object): ```python def notify_new_payload(self: ExecutionEngine, execution_payload: ExecutionPayload, - execution_requests: ExecutionRequests, + execution_requests_list: list[bytes], parent_beacon_block_root: Root) -> bool: """ Return ``True`` if and only if ``execution_payload`` and ``execution_requests`` @@ -1011,7 +1011,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_list = get_execution_requests_list(new_payload_request.execution_requests) # [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): @@ -1023,7 +1023,7 @@ def verify_and_notify_new_payload(self: ExecutionEngine, # [Modified in Electra] if not self.notify_new_payload( execution_payload, - execution_requests, + execution_requests_list, parent_beacon_block_root): return False @@ -1139,6 +1139,19 @@ def process_withdrawals(state: BeaconState, payload: ExecutionPayload) -> None: #### Execution payload +##### New `get_execution_requests_list` + +*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]: + 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`). From c9ea712389f04c26f0a7b3b0a46bd66b4d3f6497 Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Tue, 8 Oct 2024 12:27:50 -0500 Subject: [PATCH 6/7] Fix table of contents --- specs/electra/beacon-chain.md | 1 + 1 file changed, 1 insertion(+) diff --git a/specs/electra/beacon-chain.md b/specs/electra/beacon-chain.md index 6c679afcc8..23a602da29 100644 --- a/specs/electra/beacon-chain.md +++ b/specs/electra/beacon-chain.md @@ -84,6 +84,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) - [Modified `process_execution_payload`](#modified-process_execution_payload) - [Operations](#operations) - [Modified `process_operations`](#modified-process_operations) From d40c797acca54d921045633a88ffa42d2db37dc5 Mon Sep 17 00:00:00 2001 From: Justin Traglia <95511699+jtraglia@users.noreply.github.com> Date: Tue, 8 Oct 2024 13:16:17 -0500 Subject: [PATCH 7/7] Re-add `execution_payload` to `notify_new_payload` call --- specs/electra/beacon-chain.md | 1 + 1 file changed, 1 insertion(+) diff --git a/specs/electra/beacon-chain.md b/specs/electra/beacon-chain.md index 0e6c3a3754..1629f45776 100644 --- a/specs/electra/beacon-chain.md +++ b/specs/electra/beacon-chain.md @@ -1022,6 +1022,7 @@ def verify_and_notify_new_payload(self: ExecutionEngine, # [Modified in Electra] if not self.notify_new_payload( + execution_payload, parent_beacon_block_root, execution_requests): return False