Always use `GENESIS_FORK_VERSION` to sign `BLSToExecutionChange` message

This commit is contained in:
Hsiao-Wei Wang 2023-01-12 23:10:22 +08:00
parent fc6bdade50
commit 730a7afe49
No known key found for this signature in database
GPG Key ID: AE3D6B174F971DE4
3 changed files with 17 additions and 11 deletions

View File

@ -472,7 +472,8 @@ def process_bls_to_execution_change(state: BeaconState,
assert validator.withdrawal_credentials[:1] == BLS_WITHDRAWAL_PREFIX
assert validator.withdrawal_credentials[1:] == hash(address_change.from_bls_pubkey)[1:]
domain = get_domain(state, DOMAIN_BLS_TO_EXECUTION_CHANGE)
# Fork-agnostic domain since address changes are valid across forks
domain = compute_domain(DOMAIN_BLS_TO_EXECUTION_CHANGE, genesis_validators_root=state.genesis_validators_root)
signing_root = compute_signing_root(address_change, domain)
assert bls.Verify(address_change.from_bls_pubkey, signing_root, signed_address_change.signature)

View File

@ -177,16 +177,21 @@ def test_invalid_bad_signature(spec, state):
@with_capella_and_later
@spec_state_test
@always_bls
def test_current_fork_version(spec, state):
"""
It should be identical to the `test_success` test case.
It is just for comparing with `test_invalid_previous_fork_version`.
"""
signed_address_change = get_signed_address_change(spec, state, fork_version=state.fork.current_version)
def test_genesis_fork_version(spec, state):
signed_address_change = get_signed_address_change(spec, state, fork_version=spec.config.GENESIS_FORK_VERSION)
yield from run_bls_to_execution_change_processing(spec, state, signed_address_change)
@with_capella_and_later
@spec_state_test
@always_bls
def test_invalid_current_fork_version(spec, state):
signed_address_change = get_signed_address_change(spec, state, fork_version=state.fork.current_version)
yield from run_bls_to_execution_change_processing(spec, state, signed_address_change, valid=False)
@with_capella_and_later
@spec_state_test
@always_bls

View File

@ -17,10 +17,10 @@ def get_signed_address_change(spec, state, validator_index=None, withdrawal_pubk
if to_execution_address is None:
to_execution_address = b'\x42' * 20
if fork_version is None:
domain = spec.get_domain(state, spec.DOMAIN_BLS_TO_EXECUTION_CHANGE)
else:
domain = spec.compute_domain(spec.DOMAIN_BLS_TO_EXECUTION_CHANGE, fork_version, state.genesis_validators_root)
domain = spec.compute_domain(
spec.DOMAIN_BLS_TO_EXECUTION_CHANGE,
fork_version=fork_version,
genesis_validators_root=state.genesis_validators_root)
address_change = spec.BLSToExecutionChange(
validator_index=validator_index,