From 64f609af180d8096312d2d7cb0c09cf53048b113 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Wed, 11 Jan 2023 00:23:19 +0800 Subject: [PATCH 1/4] Add a test case from staking-deposit-cli --- .../test_process_bls_to_execution_change.py | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/capella/block_processing/test_process_bls_to_execution_change.py b/tests/core/pyspec/eth2spec/test/capella/block_processing/test_process_bls_to_execution_change.py index ab7e14d56..996285add 100644 --- a/tests/core/pyspec/eth2spec/test/capella/block_processing/test_process_bls_to_execution_change.py +++ b/tests/core/pyspec/eth2spec/test/capella/block_processing/test_process_bls_to_execution_change.py @@ -1,7 +1,14 @@ from eth2spec.test.helpers.keys import pubkeys from eth2spec.test.helpers.bls_to_execution_changes import get_signed_address_change - -from eth2spec.test.context import spec_state_test, expect_assertion_error, with_capella_and_later, always_bls +from eth2spec.test.helpers.constants import CAPELLA, MAINNET +from eth2spec.test.context import ( + always_bls, + expect_assertion_error, + spec_state_test, + with_capella_and_later, + with_presets, + with_phases, +) def run_bls_to_execution_change_processing(spec, state, signed_address_change, valid=True): @@ -208,3 +215,30 @@ def test_invalid_genesis_validators_root(spec, state): signed_address_change = get_signed_address_change(spec, state, genesis_validators_root=b'\x99' * 32) yield from run_bls_to_execution_change_processing(spec, state, signed_address_change, valid=False) + + +@with_phases([CAPELLA]) +@with_presets([MAINNET], reason="use mainnet fork version") +@spec_state_test +@always_bls +def test_valid_signature_from_staking_deposit_cli(spec, state): + validator_index = 1 + from_bls_pubkey = bytes.fromhex('86248e64705987236ec3c41f6a81d96f98e7b85e842a1d71405b216fa75a9917512f3c94c85779a9729c927ea2aa9ed1') # noqa: E501 + to_execution_address = bytes.fromhex('3434343434343434343434343434343434343434') + signature = bytes.fromhex('b9611626f18632086b6e05e161b1cb1f686ca0e920d12a2d7430e230e336d96b381099d1fda198949b727830088d70eb039e30ea213908a34a1d0d81b0c4c8fd23f38475f36c45ff98dd0906874387183d7583c60ad7bd1744a41ea68b5dfcb2') # noqa: E501 + + # Use mainnet `genesis_validators_root` + state.genesis_validators_root = bytes.fromhex('4b363db94e286120d76eb905340fdd4e54bfe9f06bf33ff6cf5ad27f511bfe95') + state.validators[1].withdrawal_credentials = spec.BLS_WITHDRAWAL_PREFIX + spec.hash(from_bls_pubkey)[1:] + + address_change = spec.BLSToExecutionChange( + validator_index=validator_index, + from_bls_pubkey=from_bls_pubkey, + to_execution_address=to_execution_address, + ) + signed_address_change = spec.SignedBLSToExecutionChange( + message=address_change, + signature=signature, + ) + + yield from run_bls_to_execution_change_processing(spec, state, signed_address_change) From 75def3c88e410c9f062dc8b33200ff81eb06f2b7 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Thu, 12 Jan 2023 02:51:48 +0800 Subject: [PATCH 2/4] PR feedback from @ralexstokes Co-authored-by: Alex Stokes --- .../block_processing/test_process_bls_to_execution_change.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/core/pyspec/eth2spec/test/capella/block_processing/test_process_bls_to_execution_change.py b/tests/core/pyspec/eth2spec/test/capella/block_processing/test_process_bls_to_execution_change.py index 996285add..afc6469db 100644 --- a/tests/core/pyspec/eth2spec/test/capella/block_processing/test_process_bls_to_execution_change.py +++ b/tests/core/pyspec/eth2spec/test/capella/block_processing/test_process_bls_to_execution_change.py @@ -229,7 +229,7 @@ def test_valid_signature_from_staking_deposit_cli(spec, state): # Use mainnet `genesis_validators_root` state.genesis_validators_root = bytes.fromhex('4b363db94e286120d76eb905340fdd4e54bfe9f06bf33ff6cf5ad27f511bfe95') - state.validators[1].withdrawal_credentials = spec.BLS_WITHDRAWAL_PREFIX + spec.hash(from_bls_pubkey)[1:] + state.validators[validator_index].withdrawal_credentials = spec.BLS_WITHDRAWAL_PREFIX + spec.hash(from_bls_pubkey)[1:] address_change = spec.BLSToExecutionChange( validator_index=validator_index, From 9b3f8881b48a9dde25e025e21055fe0fff5a63e8 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Thu, 12 Jan 2023 21:57:05 +0800 Subject: [PATCH 3/4] Fix lint --- .../block_processing/test_process_bls_to_execution_change.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/core/pyspec/eth2spec/test/capella/block_processing/test_process_bls_to_execution_change.py b/tests/core/pyspec/eth2spec/test/capella/block_processing/test_process_bls_to_execution_change.py index afc6469db..c96e1f9ac 100644 --- a/tests/core/pyspec/eth2spec/test/capella/block_processing/test_process_bls_to_execution_change.py +++ b/tests/core/pyspec/eth2spec/test/capella/block_processing/test_process_bls_to_execution_change.py @@ -229,7 +229,8 @@ def test_valid_signature_from_staking_deposit_cli(spec, state): # Use mainnet `genesis_validators_root` state.genesis_validators_root = bytes.fromhex('4b363db94e286120d76eb905340fdd4e54bfe9f06bf33ff6cf5ad27f511bfe95') - state.validators[validator_index].withdrawal_credentials = spec.BLS_WITHDRAWAL_PREFIX + spec.hash(from_bls_pubkey)[1:] + validator = state.validators[validator_index] + validator.withdrawal_credentials = spec.BLS_WITHDRAWAL_PREFIX + spec.hash(from_bls_pubkey)[1:] address_change = spec.BLSToExecutionChange( validator_index=validator_index, From a5273905efc76fcfbbece33429bbd6dcb430e976 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Fri, 13 Jan 2023 23:34:59 +0800 Subject: [PATCH 4/4] Update signature value due to #3206 --- .../block_processing/test_process_bls_to_execution_change.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/core/pyspec/eth2spec/test/capella/block_processing/test_process_bls_to_execution_change.py b/tests/core/pyspec/eth2spec/test/capella/block_processing/test_process_bls_to_execution_change.py index c96e1f9ac..f222744f0 100644 --- a/tests/core/pyspec/eth2spec/test/capella/block_processing/test_process_bls_to_execution_change.py +++ b/tests/core/pyspec/eth2spec/test/capella/block_processing/test_process_bls_to_execution_change.py @@ -225,7 +225,7 @@ def test_valid_signature_from_staking_deposit_cli(spec, state): validator_index = 1 from_bls_pubkey = bytes.fromhex('86248e64705987236ec3c41f6a81d96f98e7b85e842a1d71405b216fa75a9917512f3c94c85779a9729c927ea2aa9ed1') # noqa: E501 to_execution_address = bytes.fromhex('3434343434343434343434343434343434343434') - signature = bytes.fromhex('b9611626f18632086b6e05e161b1cb1f686ca0e920d12a2d7430e230e336d96b381099d1fda198949b727830088d70eb039e30ea213908a34a1d0d81b0c4c8fd23f38475f36c45ff98dd0906874387183d7583c60ad7bd1744a41ea68b5dfcb2') # noqa: E501 + signature = bytes.fromhex('8cf4219884b326a04f6664b680cd9a99ad70b5280745af1147477aa9f8b4a2b2b38b8688c6a74a06f275ad4e14c5c0c70e2ed37a15ece5bf7c0724a376ad4c03c79e14dd9f633a3d54abc1ce4e73bec3524a789ab9a69d4d06686a8a67c9e4dc') # noqa: E501 # Use mainnet `genesis_validators_root` state.genesis_validators_root = bytes.fromhex('4b363db94e286120d76eb905340fdd4e54bfe9f06bf33ff6cf5ad27f511bfe95')