diff --git a/specs/_features/eip7002/beacon-chain.md b/specs/_features/eip7002/beacon-chain.md index ca592af5c..57a1b1b82 100644 --- a/specs/_features/eip7002/beacon-chain.md +++ b/specs/_features/eip7002/beacon-chain.md @@ -53,7 +53,7 @@ This mechanism relies on the changes proposed by [EIP-7002](http://eips.ethereum ```python class ExecutionLayerExit(Container): source_address: ExecutionAddress - validator_index: ValidatorIndex + validator_pubkey: BLSPubkey ``` ### Extended Containers @@ -238,7 +238,9 @@ def process_operations(state: BeaconState, body: BeaconBlockBody) -> None: ```python def process_execution_layer_exit(state: BeaconState, execution_layer_exit: ExecutionLayerExit) -> None: - validator = state.validators[execution_layer_exit.validator_index] + validator_pubkeys = [v.pubkey for v in state.validators] + validator_index = ValidatorIndex(validator_pubkeys.index(execution_layer_exit.validator_pubkey)) + validator = state.validators[validator_index] # Verify withdrawal credentials is_correct_source_address = ( @@ -258,7 +260,7 @@ def process_execution_layer_exit(state: BeaconState, execution_layer_exit: Execu return # Initiate exit - initiate_validator_exit(state, execution_layer_exit.validator_index) + initiate_validator_exit(state, validator_index) ``` ## Testing diff --git a/tests/core/pyspec/eth2spec/test/eip7002/block_processing/test_process_execution_layer_exit.py b/tests/core/pyspec/eth2spec/test/eip7002/block_processing/test_process_execution_layer_exit.py index 74f05dd5f..a7adce945 100644 --- a/tests/core/pyspec/eth2spec/test/eip7002/block_processing/test_process_execution_layer_exit.py +++ b/tests/core/pyspec/eth2spec/test/eip7002/block_processing/test_process_execution_layer_exit.py @@ -11,11 +11,12 @@ def test_basic_exit(spec, state): current_epoch = spec.get_current_epoch(state) validator_index = spec.get_active_validator_indices(state, current_epoch)[0] + validator_pubkey = state.validators[validator_index].pubkey address = b'\x22' * 20 set_eth1_withdrawal_credential_with_balance(spec, state, validator_index, address=address) execution_layer_exit = spec.ExecutionLayerExit( source_address=address, - validator_index=validator_index, + validator_pubkey=validator_pubkey, ) yield from run_execution_layer_exit_processing(spec, state, execution_layer_exit) @@ -29,12 +30,13 @@ def test_incorrect_source_address(spec, state): current_epoch = spec.get_current_epoch(state) validator_index = spec.get_active_validator_indices(state, current_epoch)[0] + validator_pubkey = state.validators[validator_index].pubkey address = b'\x22' * 20 incorrect_address = b'\x33' * 20 set_eth1_withdrawal_credential_with_balance(spec, state, validator_index, address=address) execution_layer_exit = spec.ExecutionLayerExit( source_address=incorrect_address, - validator_index=validator_index, + validator_pubkey=validator_pubkey, ) yield from run_execution_layer_exit_processing(spec, state, execution_layer_exit, success=False) diff --git a/tests/core/pyspec/eth2spec/test/eip7002/sanity/test_blocks.py b/tests/core/pyspec/eth2spec/test/eip7002/sanity/test_blocks.py index 6d0b753f0..5998c9495 100644 --- a/tests/core/pyspec/eth2spec/test/eip7002/sanity/test_blocks.py +++ b/tests/core/pyspec/eth2spec/test/eip7002/sanity/test_blocks.py @@ -24,11 +24,12 @@ def test_basic_exit(spec, state): current_epoch = spec.get_current_epoch(state) validator_index = spec.get_active_validator_indices(state, current_epoch)[0] + validator_pubkey = state.validators[validator_index].pubkey address = b'\x22' * 20 set_eth1_withdrawal_credential_with_balance(spec, state, validator_index, address=address) execution_layer_exit = spec.ExecutionLayerExit( source_address=address, - validator_index=validator_index, + validator_pubkey=validator_pubkey, ) yield 'pre', state diff --git a/tests/core/pyspec/eth2spec/test/helpers/execution_layer_exits.py b/tests/core/pyspec/eth2spec/test/helpers/execution_layer_exits.py index f6f7328ae..1a23f068d 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/execution_layer_exits.py +++ b/tests/core/pyspec/eth2spec/test/helpers/execution_layer_exits.py @@ -1,4 +1,5 @@ from eth2spec.test.context import expect_assertion_error +from eth2spec.test.helpers.state import get_validator_index_by_pubkey # @@ -14,7 +15,7 @@ def run_execution_layer_exit_processing(spec, state, execution_layer_exit, valid - post-state ('post'). If ``valid == False``, run expecting ``AssertionError`` """ - validator_index = execution_layer_exit.validator_index + validator_index = get_validator_index_by_pubkey(state, execution_layer_exit.validator_pubkey) yield 'pre', state yield 'execution_layer_exit', execution_layer_exit diff --git a/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py b/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py index 31125dfc3..482d82c86 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py +++ b/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py @@ -141,8 +141,8 @@ def get_exit_rlp(exit): exit_rlp = [ # source_address (Binary(20, 20), exit.source_address), - # validator_index - (big_endian_int, exit.validator_index), + # validator_pubkey + (Binary(48, 48), exit.validator_pubkey), ] sedes = List([schema for schema, _ in exit_rlp]) diff --git a/tests/core/pyspec/eth2spec/test/helpers/state.py b/tests/core/pyspec/eth2spec/test/helpers/state.py index 0dc17b00f..1e64bd4db 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/state.py +++ b/tests/core/pyspec/eth2spec/test/helpers/state.py @@ -166,3 +166,8 @@ def has_active_balance_differential(spec, state): active_balance = spec.get_total_active_balance(state) total_balance = spec.get_total_balance(state, set(range(len(state.validators)))) return active_balance // spec.EFFECTIVE_BALANCE_INCREMENT != total_balance // spec.EFFECTIVE_BALANCE_INCREMENT + + +def get_validator_index_by_pubkey(state, pubkey): + index = next((i for i, validator in enumerate(state.validators) if validator.pubkey == pubkey), None) + return index