diff --git a/tests/core/pyspec/eth2spec/test/capella/sanity/test_blocks.py b/tests/core/pyspec/eth2spec/test/capella/sanity/test_blocks.py index 0e910ed76..490253bef 100644 --- a/tests/core/pyspec/eth2spec/test/capella/sanity/test_blocks.py +++ b/tests/core/pyspec/eth2spec/test/capella/sanity/test_blocks.py @@ -79,7 +79,7 @@ def test_success_exit_and_bls_change(spec, state): @with_phases([CAPELLA]) @spec_state_test -def test_fail_double_bls_changes_same_block(spec, state): +def test_invalid_double_bls_changes_same_block(spec, state): index = 0 signed_address_change = get_signed_address_change(spec, state, validator_index=index) yield 'pre', state @@ -96,6 +96,30 @@ def test_fail_double_bls_changes_same_block(spec, state): yield 'post', None +@with_phases([CAPELLA]) +@spec_state_test +def test_invalid_two_bls_changes_of_different_addresses_same_validator_same_block(spec, state): + index = 0 + + signed_address_change_1 = get_signed_address_change(spec, state, validator_index=index, + to_execution_address=b'\x12' * 20) + signed_address_change_2 = get_signed_address_change(spec, state, validator_index=index, + to_execution_address=b'\x34' * 20) + assert signed_address_change_1 != signed_address_change_2 + + yield 'pre', state + + block = build_empty_block_for_next_slot(spec, state) + + block.body.bls_to_execution_changes.append(signed_address_change_1) + block.body.bls_to_execution_changes.append(signed_address_change_2) + + signed_block = state_transition_and_sign_block(spec, state, block, expect_fail=True) + + yield 'blocks', [signed_block] + yield 'post', None + + # # Withdrawals # diff --git a/tests/core/pyspec/eth2spec/test/helpers/bls_to_execution_changes.py b/tests/core/pyspec/eth2spec/test/helpers/bls_to_execution_changes.py index 61c84b515..446fa9710 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/bls_to_execution_changes.py +++ b/tests/core/pyspec/eth2spec/test/helpers/bls_to_execution_changes.py @@ -2,7 +2,7 @@ from eth2spec.utils import bls from eth2spec.test.helpers.keys import pubkeys, privkeys, pubkey_to_privkey -def get_signed_address_change(spec, state, validator_index=None, withdrawal_pubkey=None): +def get_signed_address_change(spec, state, validator_index=None, withdrawal_pubkey=None, to_execution_address=None): if validator_index is None: validator_index = 0 @@ -13,11 +13,14 @@ def get_signed_address_change(spec, state, validator_index=None, withdrawal_pubk else: withdrawal_privkey = pubkey_to_privkey[withdrawal_pubkey] + if to_execution_address is None: + to_execution_address = b'\x42' * 20 + domain = spec.get_domain(state, spec.DOMAIN_BLS_TO_EXECUTION_CHANGE) address_change = spec.BLSToExecutionChange( validator_index=validator_index, from_bls_pubkey=withdrawal_pubkey, - to_execution_address=b'\x42' * 20, + to_execution_address=to_execution_address, ) signing_root = spec.compute_signing_root(address_change, domain)