This commit is contained in:
dapplion 2024-03-27 01:35:36 +09:00
parent 23ad85e8bf
commit e6aaa9d44d
13 changed files with 289 additions and 225 deletions

View File

@ -792,7 +792,8 @@ def apply_deposit(state: BeaconState,
else:
# Increase balance by deposit amount
index = ValidatorIndex(validator_pubkeys.index(pubkey))
state.pending_balance_deposits.append(PendingBalanceDeposit(index=index, amount=amount)) # [Modified in EIP-7251]
state.pending_balance_deposits.append(
PendingBalanceDeposit(index=index, amount=amount)) # [Modified in EIP-7251]
# Check if valid deposit switch to compounding credentials
if (
is_compounding_withdrawal_credential(withdrawal_credentials)
@ -810,14 +811,14 @@ def is_valid_deposit_signature(pubkey: BLSPubkey,
withdrawal_credentials: Bytes32,
amount: uint64,
signature: BLSSignature) -> None:
deposit_message = DepositMessage(
pubkey=pubkey,
withdrawal_credentials=withdrawal_credentials,
amount=amount,
)
domain = compute_domain(DOMAIN_DEPOSIT) # Fork-agnostic domain since deposits are valid across forks
signing_root = compute_signing_root(deposit_message, domain)
return bls.Verify(pubkey, signing_root, signature)
deposit_message = DepositMessage(
pubkey=pubkey,
withdrawal_credentials=withdrawal_credentials,
amount=amount,
)
domain = compute_domain(DOMAIN_DEPOSIT) # Fork-agnostic domain since deposits are valid across forks
signing_root = compute_signing_root(deposit_message, domain)
return bls.Verify(pubkey, signing_root, signature)
```
###### Modified `add_validator_to_registry`

View File

@ -130,9 +130,9 @@ def upgrade_to_eip7251(pre: deneb.BeaconState) -> BeaconState:
# Ensure early adopters of compounding credentials go through the activation churn
queue_excess_active_balance(post)
for index, validator in enumerate(state.validators):
for index, validator in enumerate(post.validators):
if has_compounding_withdrawal_credential(validator):
queue_excess_active_balance(state, index)
queue_excess_active_balance(post, index)
return post
```

View File

@ -135,18 +135,20 @@ def scaled_churn_balances_exceed_activation_churn_limit(spec: Spec):
num_validators = spec.config.CHURN_LIMIT_QUOTIENT * (spec.config.MAX_PER_EPOCH_ACTIVATION_CHURN_LIMIT + 2)
return [spec.MAX_EFFECTIVE_BALANCE] * num_validators
def scaled_churn_balances_exceed_activation_exit_churn_limit(spec: Spec):
"""
Helper method to create enough validators to scale the churn limit.
(The number of validators is double the amount need for the max activation/exit churn limit)
Usage: `@with_custom_state(balances_fn=scaled_churn_balances_exceed_activation_churn_limit, ...)`
"""
num_validators = 2 * spec.config.CHURN_LIMIT_QUOTIENT * spec.config.MAX_PER_EPOCH_ACTIVATION_EXIT_CHURN_LIMIT // spec.MIN_ACTIVATION_BALANCE
num_validators = (
2 * spec.config.CHURN_LIMIT_QUOTIENT
* spec.config.MAX_PER_EPOCH_ACTIVATION_EXIT_CHURN_LIMIT
// spec.MIN_ACTIVATION_BALANCE)
return [spec.MIN_ACTIVATION_BALANCE] * num_validators
with_state = with_custom_state(default_balances, default_activation_threshold)

View File

@ -2,7 +2,7 @@ from eth2spec.test.helpers.constants import MINIMAL
from eth2spec.test.context import (
spec_state_test,
with_eip7251_and_later,
with_presets,
with_presets,
always_bls,
spec_test, single_phase,
with_custom_state,
@ -23,9 +23,11 @@ from eth2spec.test.helpers.withdrawals import (
# * CONSOLIDATION TESTS *
# ***********************
@with_eip7251_and_later
@with_presets([MINIMAL], "need sufficient consolidation churn limit")
@with_custom_state(balances_fn=scaled_churn_balances_exceed_activation_exit_churn_limit, threshold_fn=default_activation_threshold)
@with_custom_state(
balances_fn=scaled_churn_balances_exceed_activation_exit_churn_limit, threshold_fn=default_activation_threshold)
@spec_test
@single_phase
def test_basic_consolidation(spec, state):
@ -44,20 +46,25 @@ def test_basic_consolidation(spec, state):
set_eth1_withdrawal_credential_with_balance(spec, state, source_index)
set_eth1_withdrawal_credential_with_balance(spec, state, target_index)
signed_consolidation = sign_consolidation(spec, state,
spec.Consolidation(epoch=current_epoch, source_index=source_index, target_index=target_index),
source_privkey, target_privkey)
signed_consolidation = sign_consolidation(spec, state,
spec.Consolidation(
epoch=current_epoch,
source_index=source_index,
target_index=target_index),
source_privkey, target_privkey)
yield from run_consolidation_processing(spec, state, signed_consolidation)
expected_exit_epoch = spec.compute_activation_exit_epoch(current_epoch)
# Check consolidation churn is decremented correctly
assert state.consolidation_balance_to_consume == consolidation_churn_limit - spec.MIN_ACTIVATION_BALANCE
assert state.consolidation_balance_to_consume == consolidation_churn_limit - spec.MIN_ACTIVATION_BALANCE
# Check exit epoch
assert state.validators[0].exit_epoch == expected_exit_epoch
@with_eip7251_and_later
@with_presets([MINIMAL], "need sufficient consolidation churn limit")
@with_custom_state(balances_fn=scaled_churn_balances_exceed_activation_exit_churn_limit, threshold_fn=default_activation_threshold)
@with_custom_state(
balances_fn=scaled_churn_balances_exceed_activation_exit_churn_limit, threshold_fn=default_activation_threshold)
@spec_test
@single_phase
def test_basic_consolidation_with_compounding_credential(spec, state):
@ -75,20 +82,25 @@ def test_basic_consolidation_with_compounding_credential(spec, state):
set_compounding_withdrawal_credential(spec, state, source_index)
set_compounding_withdrawal_credential(spec, state, target_index)
signed_consolidation = sign_consolidation(spec, state,
spec.Consolidation(epoch=current_epoch, source_index=source_index, target_index=target_index),
source_privkey, target_privkey)
signed_consolidation = sign_consolidation(spec, state,
spec.Consolidation(
epoch=current_epoch,
source_index=source_index,
target_index=target_index),
source_privkey, target_privkey)
yield from run_consolidation_processing(spec, state, signed_consolidation)
expected_exit_epoch = spec.compute_activation_exit_epoch(current_epoch)
# Check consolidation churn is decremented correctly
assert state.consolidation_balance_to_consume == consolidation_churn_limit - spec.MIN_ACTIVATION_BALANCE
assert state.consolidation_balance_to_consume == consolidation_churn_limit - spec.MIN_ACTIVATION_BALANCE
# Check exit epoch
assert state.validators[0].exit_epoch == expected_exit_epoch
@with_eip7251_and_later
@with_presets([MINIMAL], "need sufficient consolidation churn limit")
@with_custom_state(balances_fn=scaled_churn_balances_exceed_activation_exit_churn_limit, threshold_fn=default_activation_threshold)
@with_custom_state(
balances_fn=scaled_churn_balances_exceed_activation_exit_churn_limit, threshold_fn=default_activation_threshold)
@spec_test
@single_phase
def test_consolidation_churn_limit_balance(spec, state):
@ -109,9 +121,12 @@ def test_consolidation_churn_limit_balance(spec, state):
set_compounding_withdrawal_credential(spec, state, source_index)
set_compounding_withdrawal_credential(spec, state, target_index)
signed_consolidation = sign_consolidation(spec, state,
spec.Consolidation(epoch=current_epoch, source_index=source_index, target_index=target_index),
source_privkey, target_privkey)
signed_consolidation = sign_consolidation(spec, state,
spec.Consolidation(
epoch=current_epoch,
source_index=source_index,
target_index=target_index),
source_privkey, target_privkey)
yield from run_consolidation_processing(spec, state, signed_consolidation)
expected_exit_epoch = spec.compute_activation_exit_epoch(current_epoch)
@ -120,9 +135,11 @@ def test_consolidation_churn_limit_balance(spec, state):
# Check exit epoch
assert state.validators[0].exit_epoch == expected_exit_epoch
@with_eip7251_and_later
@with_presets([MINIMAL], "need sufficient consolidation churn limit")
@with_custom_state(balances_fn=scaled_churn_balances_exceed_activation_exit_churn_limit, threshold_fn=default_activation_threshold)
@with_custom_state(
balances_fn=scaled_churn_balances_exceed_activation_exit_churn_limit, threshold_fn=default_activation_threshold)
@spec_test
@single_phase
def test_consolidation_balance_larger_than_churn_limit(spec, state):
@ -143,9 +160,12 @@ def test_consolidation_balance_larger_than_churn_limit(spec, state):
set_compounding_withdrawal_credential(spec, state, source_index)
set_compounding_withdrawal_credential(spec, state, target_index)
signed_consolidation = sign_consolidation(spec, state,
spec.Consolidation(epoch=current_epoch, source_index=source_index, target_index=target_index),
source_privkey, target_privkey)
signed_consolidation = sign_consolidation(spec, state,
spec.Consolidation(
epoch=current_epoch,
source_index=source_index,
target_index=target_index),
source_privkey, target_privkey)
yield from run_consolidation_processing(spec, state, signed_consolidation)
expected_exit_epoch = spec.compute_activation_exit_epoch(current_epoch) + 1
@ -157,7 +177,8 @@ def test_consolidation_balance_larger_than_churn_limit(spec, state):
@with_eip7251_and_later
@with_presets([MINIMAL], "need sufficient consolidation churn limit")
@with_custom_state(balances_fn=scaled_churn_balances_exceed_activation_exit_churn_limit, threshold_fn=default_activation_threshold)
@with_custom_state(
balances_fn=scaled_churn_balances_exceed_activation_exit_churn_limit, threshold_fn=default_activation_threshold)
@spec_test
@single_phase
def test_consolidation_balance_twice_the_churn_limit(spec, state):
@ -179,9 +200,12 @@ def test_consolidation_balance_twice_the_churn_limit(spec, state):
# Set source balance higher than consolidation churn limit
state.balances[source_index] = 2 * consolidation_churn_limit
signed_consolidation = sign_consolidation(spec, state,
spec.Consolidation(epoch=current_epoch, source_index=source_index, target_index=target_index),
source_privkey, target_privkey)
signed_consolidation = sign_consolidation(spec, state,
spec.Consolidation(
epoch=current_epoch,
source_index=source_index,
target_index=target_index),
source_privkey, target_privkey)
yield from run_consolidation_processing(spec, state, signed_consolidation)
# when exiting a multiple of the churn limit greater than 1, an extra exit epoch is added
@ -191,10 +215,10 @@ def test_consolidation_balance_twice_the_churn_limit(spec, state):
assert state.consolidation_balance_to_consume == consolidation_churn_limit
@with_eip7251_and_later
@with_presets([MINIMAL], "need sufficient consolidation churn limit")
@with_custom_state(balances_fn=scaled_churn_balances_exceed_activation_exit_churn_limit, threshold_fn=default_activation_threshold)
@with_custom_state(
balances_fn=scaled_churn_balances_exceed_activation_exit_churn_limit, threshold_fn=default_activation_threshold)
@spec_test
@single_phase
def test_multiple_consolidations_below_churn(spec, state):
@ -207,17 +231,20 @@ def test_multiple_consolidations_below_churn(spec, state):
yield "pre", state
# Prepare a bunch of consolidations, based on the current state
consolidations = []
for i in range(3):
source_index = 2*i
target_index = 2*i + 1
for i in range(3):
source_index = 2 * i
target_index = 2 * i + 1
source_privkey = pubkey_to_privkey[state.validators[source_index].pubkey]
target_privkey = pubkey_to_privkey[state.validators[target_index].pubkey]
# Set source and target withdrawal credentials to the same eth1 credential
set_eth1_withdrawal_credential_with_balance(spec, state, source_index)
set_eth1_withdrawal_credential_with_balance(spec, state, target_index)
signed_consolidation = sign_consolidation(spec, state,
spec.Consolidation(epoch=current_epoch, source_index=source_index, target_index=target_index),
source_privkey, target_privkey)
signed_consolidation = sign_consolidation(spec, state,
spec.Consolidation(
epoch=current_epoch,
source_index=source_index,
target_index=target_index),
source_privkey, target_privkey)
consolidations.append(signed_consolidation)
# Now run all the consolidations
@ -225,19 +252,20 @@ def test_multiple_consolidations_below_churn(spec, state):
# the function yields data, but we are just interested in running it here, ignore yields.
for _ in run_consolidation_processing(spec, state, consolidation):
continue
yield "post", state
expected_exit_epoch = spec.compute_activation_exit_epoch(current_epoch)
assert state.earliest_consolidation_epoch == expected_exit_epoch
assert state.consolidation_balance_to_consume == consolidation_churn_limit - 3*spec.MIN_ACTIVATION_BALANCE
assert state.consolidation_balance_to_consume == consolidation_churn_limit - 3 * spec.MIN_ACTIVATION_BALANCE
for i in range(3):
assert state.validators[2*i].exit_epoch == expected_exit_epoch
assert state.validators[2 * i].exit_epoch == expected_exit_epoch
@with_eip7251_and_later
@with_presets([MINIMAL], "need sufficient consolidation churn limit")
@with_custom_state(balances_fn=scaled_churn_balances_exceed_activation_exit_churn_limit, threshold_fn=default_activation_threshold)
@with_custom_state(
balances_fn=scaled_churn_balances_exceed_activation_exit_churn_limit, threshold_fn=default_activation_threshold)
@spec_test
@single_phase
def test_multiple_consolidations_equal_churn(spec, state):
@ -250,17 +278,20 @@ def test_multiple_consolidations_equal_churn(spec, state):
yield "pre", state
# Prepare a bunch of consolidations, based on the current state
consolidations = []
for i in range(4):
source_index = 2*i
target_index = 2*i + 1
for i in range(4):
source_index = 2 * i
target_index = 2 * i + 1
source_privkey = pubkey_to_privkey[state.validators[source_index].pubkey]
target_privkey = pubkey_to_privkey[state.validators[target_index].pubkey]
# Set source and target withdrawal credentials to the same eth1 credential
set_eth1_withdrawal_credential_with_balance(spec, state, source_index)
set_eth1_withdrawal_credential_with_balance(spec, state, target_index)
signed_consolidation = sign_consolidation(spec, state,
spec.Consolidation(epoch=current_epoch, source_index=source_index, target_index=target_index),
source_privkey, target_privkey)
signed_consolidation = sign_consolidation(spec, state,
spec.Consolidation(
epoch=current_epoch,
source_index=source_index,
target_index=target_index),
source_privkey, target_privkey)
consolidations.append(signed_consolidation)
# Now run all the consolidations
@ -268,19 +299,20 @@ def test_multiple_consolidations_equal_churn(spec, state):
# the function yields data, but we are just interested in running it here, ignore yields.
for _ in run_consolidation_processing(spec, state, consolidation):
continue
yield "post", state
expected_exit_epoch = spec.compute_activation_exit_epoch(current_epoch)
assert state.earliest_consolidation_epoch == expected_exit_epoch
assert state.consolidation_balance_to_consume == 0
for i in range(4):
assert state.validators[2*i].exit_epoch == expected_exit_epoch
assert state.validators[2 * i].exit_epoch == expected_exit_epoch
@with_eip7251_and_later
@with_presets([MINIMAL], "need sufficient consolidation churn limit")
@with_custom_state(balances_fn=scaled_churn_balances_exceed_activation_exit_churn_limit, threshold_fn=default_activation_threshold)
@with_custom_state(
balances_fn=scaled_churn_balances_exceed_activation_exit_churn_limit, threshold_fn=default_activation_threshold)
@spec_test
@single_phase
def test_multiple_consolidations_above_churn(spec, state):
@ -292,17 +324,20 @@ def test_multiple_consolidations_above_churn(spec, state):
# Prepare a bunch of consolidations, based on the current state
consolidations = []
for i in range(4):
source_index = 2*i
target_index = 2*i + 1
for i in range(4):
source_index = 2 * i
target_index = 2 * i + 1
source_privkey = pubkey_to_privkey[state.validators[source_index].pubkey]
target_privkey = pubkey_to_privkey[state.validators[target_index].pubkey]
# Set source and target withdrawal credentials to the same eth1 credential
set_eth1_withdrawal_credential_with_balance(spec, state, source_index)
set_eth1_withdrawal_credential_with_balance(spec, state, target_index)
signed_consolidation = sign_consolidation(spec, state,
spec.Consolidation(epoch=current_epoch, source_index=source_index, target_index=target_index),
source_privkey, target_privkey)
signed_consolidation = sign_consolidation(spec, state,
spec.Consolidation(
epoch=current_epoch,
source_index=source_index,
target_index=target_index),
source_privkey, target_privkey)
consolidations.append(signed_consolidation)
# Now run all the consolidations
@ -321,24 +356,28 @@ def test_multiple_consolidations_above_churn(spec, state):
set_eth1_withdrawal_credential_with_balance(spec, state, source_index)
set_eth1_withdrawal_credential_with_balance(spec, state, target_index)
signed_consolidation = sign_consolidation(spec, state,
spec.Consolidation(epoch=current_epoch, source_index=source_index, target_index=target_index),
source_privkey, target_privkey)
signed_consolidation = sign_consolidation(spec, state,
spec.Consolidation(
epoch=current_epoch,
source_index=source_index,
target_index=target_index),
source_privkey, target_privkey)
# This is the interesting part of the test: on a pre-state with full consolidation queue,
# when processing an additional consolidation, it results in an exit in a later epoch
yield from run_consolidation_processing(spec, state, signed_consolidation)
expected_exit_epoch = spec.compute_activation_exit_epoch(current_epoch)
assert state.earliest_consolidation_epoch == expected_exit_epoch + 1
assert state.consolidation_balance_to_consume == consolidation_churn_limit - spec.MIN_ACTIVATION_BALANCE
assert state.consolidation_balance_to_consume == consolidation_churn_limit - spec.MIN_ACTIVATION_BALANCE
assert state.validators[source_index].exit_epoch == expected_exit_epoch + 1
for i in range(4):
assert state.validators[2*i].exit_epoch == expected_exit_epoch
assert state.validators[2 * i].exit_epoch == expected_exit_epoch
@with_eip7251_and_later
@with_presets([MINIMAL], "need sufficient consolidation churn limit")
@with_custom_state(balances_fn=scaled_churn_balances_exceed_activation_exit_churn_limit, threshold_fn=default_activation_threshold)
@with_custom_state(
balances_fn=scaled_churn_balances_exceed_activation_exit_churn_limit, threshold_fn=default_activation_threshold)
@spec_test
@single_phase
def test_multiple_consolidations_equal_twice_churn(spec, state):
@ -351,17 +390,20 @@ def test_multiple_consolidations_equal_twice_churn(spec, state):
yield "pre", state
# Prepare a bunch of consolidations, based on the current state
consolidations = []
for i in range(8):
source_index = 2*i
target_index = 2*i + 1
for i in range(8):
source_index = 2 * i
target_index = 2 * i + 1
source_privkey = pubkey_to_privkey[state.validators[source_index].pubkey]
target_privkey = pubkey_to_privkey[state.validators[target_index].pubkey]
# Set source and target withdrawal credentials to the same eth1 credential
set_eth1_withdrawal_credential_with_balance(spec, state, source_index)
set_eth1_withdrawal_credential_with_balance(spec, state, target_index)
signed_consolidation = sign_consolidation(spec, state,
spec.Consolidation(epoch=current_epoch, source_index=source_index, target_index=target_index),
source_privkey, target_privkey)
signed_consolidation = sign_consolidation(spec, state,
spec.Consolidation(
epoch=current_epoch,
source_index=source_index,
target_index=target_index),
source_privkey, target_privkey)
consolidations.append(signed_consolidation)
# Now run all the consolidations
@ -369,19 +411,19 @@ def test_multiple_consolidations_equal_twice_churn(spec, state):
# the function yields data, but we are just interested in running it here, ignore yields.
for _ in run_consolidation_processing(spec, state, consolidation):
continue
yield "post", state
first_exit_epoch = spec.compute_activation_exit_epoch(current_epoch)
assert state.consolidation_balance_to_consume == 0
assert state.earliest_consolidation_epoch == first_exit_epoch + 1
for i in range(4):
assert state.validators[2*i].exit_epoch == first_exit_epoch
for i in range(4,8):
assert state.validators[2*i].exit_epoch == first_exit_epoch + 1
assert state.validators[2 * i].exit_epoch == first_exit_epoch
for i in range(4, 8):
assert state.validators[2 * i].exit_epoch == first_exit_epoch + 1
## Failing tests
# Failing tests
@with_eip7251_and_later
@spec_state_test
@ -393,24 +435,30 @@ def test_invalid_source_equals_target(spec, state):
# Set withdrawal credentials to eth1
set_eth1_withdrawal_credential_with_balance(spec, state, validator_index)
signed_consolidation = sign_consolidation(spec, state,
spec.Consolidation(epoch=current_epoch, source_index=validator_index, target_index=validator_index),
validator_privkey, validator_privkey)
signed_consolidation = sign_consolidation(spec, state,
spec.Consolidation(
epoch=current_epoch,
source_index=validator_index,
target_index=validator_index),
validator_privkey, validator_privkey)
yield from run_consolidation_processing(spec, state, signed_consolidation, valid=False)
@with_eip7251_and_later
@spec_state_test
def test_invalid_exceed_pending_consolidations_limit(spec, state):
state.pending_consolidations = [spec.PendingConsolidation(source_index = 0,target_index = 1)] * spec.PENDING_CONSOLIDATIONS_LIMIT
state.pending_consolidations = (
[spec.PendingConsolidation(source_index=0, target_index=1)] * spec.PENDING_CONSOLIDATIONS_LIMIT
)
current_epoch = spec.get_current_epoch(state)
source_privkey = pubkey_to_privkey[state.validators[0].pubkey]
target_privkey = pubkey_to_privkey[state.validators[1].pubkey]
# Set source and target withdrawal credentials to the same eth1 credential
set_eth1_withdrawal_credential_with_balance(spec, state, 0)
set_eth1_withdrawal_credential_with_balance(spec, state, 1)
signed_consolidation = sign_consolidation(spec, state,
spec.Consolidation(epoch=current_epoch, source_index=0, target_index=1),
source_privkey, target_privkey)
signed_consolidation = sign_consolidation(spec, state,
spec.Consolidation(epoch=current_epoch, source_index=0, target_index=1),
source_privkey, target_privkey)
yield from run_consolidation_processing(spec, state, signed_consolidation, valid=False)
@ -422,9 +470,9 @@ def test_invalid_exited_source(spec, state):
target_privkey = pubkey_to_privkey[state.validators[1].pubkey]
set_eth1_withdrawal_credential_with_balance(spec, state, 0)
set_eth1_withdrawal_credential_with_balance(spec, state, 1)
signed_consolidation = sign_consolidation(spec, state,
spec.Consolidation(epoch=current_epoch, source_index=0, target_index=1),
source_privkey, target_privkey)
signed_consolidation = sign_consolidation(spec, state,
spec.Consolidation(epoch=current_epoch, source_index=0, target_index=1),
source_privkey, target_privkey)
# exit source
spec.initiate_validator_exit(state, 0)
yield from run_consolidation_processing(spec, state, signed_consolidation, valid=False)
@ -439,13 +487,17 @@ def test_invalid_exited_target(spec, state):
# Set source and target withdrawal credentials to the same eth1 credential
set_eth1_withdrawal_credential_with_balance(spec, state, 0)
set_eth1_withdrawal_credential_with_balance(spec, state, 1)
signed_consolidation = sign_consolidation(spec, state,
spec.Consolidation(epoch=current_epoch, source_index=0, target_index=1),
source_privkey, target_privkey)
signed_consolidation = sign_consolidation(spec, state,
spec.Consolidation(
epoch=current_epoch,
source_index=0,
target_index=1),
source_privkey, target_privkey)
# exit target
spec.initiate_validator_exit(state, 1)
yield from run_consolidation_processing(spec, state, signed_consolidation, valid=False)
@with_eip7251_and_later
@spec_state_test
def test_invalid_inactive_source(spec, state):
@ -454,9 +506,12 @@ def test_invalid_inactive_source(spec, state):
target_privkey = pubkey_to_privkey[state.validators[1].pubkey]
set_eth1_withdrawal_credential_with_balance(spec, state, 0)
set_eth1_withdrawal_credential_with_balance(spec, state, 1)
signed_consolidation = sign_consolidation(spec, state,
spec.Consolidation(epoch=current_epoch, source_index=0, target_index=1),
source_privkey, target_privkey)
signed_consolidation = sign_consolidation(spec, state,
spec.Consolidation(
epoch=current_epoch,
source_index=0,
target_index=1),
source_privkey, target_privkey)
# set source validator as not yet activated
state.validators[0].activation_epoch = spec.FAR_FUTURE_EPOCH
yield from run_consolidation_processing(spec, state, signed_consolidation, valid=False)
@ -471,9 +526,12 @@ def test_invalid_inactive_target(spec, state):
# Set source and target withdrawal credentials to the same eth1 credential
set_eth1_withdrawal_credential_with_balance(spec, state, 0)
set_eth1_withdrawal_credential_with_balance(spec, state, 1)
signed_consolidation = sign_consolidation(spec, state,
spec.Consolidation(epoch=current_epoch, source_index=0, target_index=1),
source_privkey, target_privkey)
signed_consolidation = sign_consolidation(spec, state,
spec.Consolidation(
epoch=current_epoch,
source_index=0,
target_index=1),
source_privkey, target_privkey)
# set target validator as not yet activated
state.validators[1].activation_epoch = spec.FAR_FUTURE_EPOCH
yield from run_consolidation_processing(spec, state, signed_consolidation, valid=False)
@ -485,23 +543,30 @@ def test_invalid_no_execution_withdrawal_credential(spec, state):
current_epoch = spec.get_current_epoch(state)
source_privkey = pubkey_to_privkey[state.validators[0].pubkey]
target_privkey = pubkey_to_privkey[state.validators[1].pubkey]
signed_consolidation = sign_consolidation(spec, state,
spec.Consolidation(epoch=current_epoch, source_index=0, target_index=1),
source_privkey, target_privkey)
signed_consolidation = sign_consolidation(spec, state,
spec.Consolidation(
epoch=current_epoch,
source_index=0,
target_index=1),
source_privkey, target_privkey)
yield from run_consolidation_processing(spec, state, signed_consolidation, valid=False)
@with_eip7251_and_later
@spec_state_test
def test_invalid_different_credentials(spec, state):
current_epoch = spec.get_current_epoch(state)
source_privkey = pubkey_to_privkey[state.validators[0].pubkey]
target_privkey = pubkey_to_privkey[state.validators[1].pubkey]
signed_consolidation = sign_consolidation(spec, state,
spec.Consolidation(epoch=current_epoch, source_index=0, target_index=1),
source_privkey, target_privkey)
signed_consolidation = sign_consolidation(spec, state,
spec.Consolidation(
epoch=current_epoch,
source_index=0,
target_index=1),
source_privkey, target_privkey)
# Set source and target withdrawal credentials to different eth1 credentials
set_eth1_withdrawal_credential_with_balance(spec, state, 0)
set_eth1_withdrawal_credential_with_balance(spec, state, 1, address=b'\x10'*20)
set_eth1_withdrawal_credential_with_balance(spec, state, 1, address=b'\x10' * 20)
yield from run_consolidation_processing(spec, state, signed_consolidation, valid=False)
@ -515,13 +580,17 @@ def test_invalid_source_signature(spec, state):
# Set source and target withdrawal credentials to the same eth1 credential
set_eth1_withdrawal_credential_with_balance(spec, state, 0)
set_eth1_withdrawal_credential_with_balance(spec, state, 1)
signed_consolidation = sign_consolidation(spec, state,
spec.Consolidation(epoch=current_epoch, source_index=0, target_index=1),
source_privkey, target_privkey)
signed_consolidation = sign_consolidation(spec, state,
spec.Consolidation(
epoch=current_epoch,
source_index=0,
target_index=1),
source_privkey, target_privkey)
# Change the pubkey of the source validator, invalidating its signature
state.validators[0].pubkey = state.validators[1].pubkey
yield from run_consolidation_processing(spec, state, signed_consolidation, valid=False)
@with_eip7251_and_later
@spec_state_test
@always_bls
@ -532,13 +601,17 @@ def test_invalid_target_signature(spec, state):
# Set source and target withdrawal credentials to the same eth1 credential
set_eth1_withdrawal_credential_with_balance(spec, state, 0)
set_eth1_withdrawal_credential_with_balance(spec, state, 1)
signed_consolidation = sign_consolidation(spec, state,
spec.Consolidation(epoch=current_epoch, source_index=0, target_index=1),
source_privkey, target_privkey)
signed_consolidation = sign_consolidation(spec, state,
spec.Consolidation(
epoch=current_epoch,
source_index=0,
target_index=1),
source_privkey, target_privkey)
# Change the pubkey of the target validator, invalidating its signature
state.validators[1].pubkey = state.validators[2].pubkey
yield from run_consolidation_processing(spec, state, signed_consolidation, valid=False)
@with_eip7251_and_later
@spec_state_test
def test_invalid_before_specified_epoch(spec, state):
@ -549,7 +622,10 @@ def test_invalid_before_specified_epoch(spec, state):
set_eth1_withdrawal_credential_with_balance(spec, state, 0)
set_eth1_withdrawal_credential_with_balance(spec, state, 1)
# set epoch=current_epoch + 1, so it's too early to process it
signed_consolidation = sign_consolidation(spec, state,
spec.Consolidation(epoch=current_epoch+1, source_index=0, target_index=1),
source_privkey, target_privkey)
yield from run_consolidation_processing(spec, state, signed_consolidation, valid=False)
signed_consolidation = sign_consolidation(spec, state,
spec.Consolidation(
epoch=current_epoch + 1,
source_index=0,
target_index=1),
source_privkey, target_privkey)
yield from run_consolidation_processing(spec, state, signed_consolidation, valid=False)

View File

@ -13,6 +13,7 @@ from eth2spec.test.context import (
always_bls,
)
@with_eip7251_and_later
@spec_state_test
def test_new_deposit_under_min_activation_balance(spec, state):
@ -24,6 +25,7 @@ def test_new_deposit_under_min_activation_balance(spec, state):
yield from run_deposit_processing_eip7251(spec, state, deposit, validator_index)
@with_eip7251_and_later
@spec_state_test
def test_new_deposit_min(spec, state):
@ -33,6 +35,7 @@ def test_new_deposit_min(spec, state):
deposit = prepare_state_and_deposit(spec, state, validator_index, amount, signed=True)
yield from run_deposit_processing_eip7251(spec, state, deposit, validator_index)
@with_eip7251_and_later
@spec_state_test
def test_new_deposit_between_min_and_max(spec, state):
@ -64,8 +67,6 @@ def test_new_deposit_over_max(spec, state):
yield from run_deposit_processing_eip7251(spec, state, deposit, validator_index)
# @with_eip7251_and_later
# @spec_state_test
# def test_top_up__max_effective_balance(spec, state):
@ -80,7 +81,7 @@ def test_new_deposit_over_max(spec, state):
# assert state.balances[validator_index] == spec.MAX_EFFECTIVE_BALANCE_EIP7251 + amount
# assert state.validators[validator_index].effective_balance == spec.MAX_EFFECTIVE_BALANCE_EIP7251
@with_eip7251_and_later
@spec_state_test
@always_bls

View File

@ -2,30 +2,22 @@ from eth2spec.test.context import (
spec_state_test,
expect_assertion_error,
with_eip7251_and_later,
with_presets,
with_presets,
)
from eth2spec.test.helpers.constants import MINIMAL
from eth2spec.test.helpers.state import (
next_epoch,
next_slot,
get_validator_index_by_pubkey,
)
from eth2spec.test.helpers.withdrawals import (
prepare_expected_withdrawals,
set_eth1_withdrawal_credential_with_balance,
set_validator_fully_withdrawable,
set_validator_partially_withdrawable,
)
from eth2spec.test.context import expect_assertion_error
from eth2spec.test.helpers.state import get_validator_index_by_pubkey
from eth2spec.test.helpers.withdrawals import set_eth1_withdrawal_credential_with_balance
# Only failing test from capella process_withdrawals is
# test_success_excess_balance_but_no_max_effective_balance
## Only failing test from capella process_withdrawals is
## test_success_excess_balance_but_no_max_effective_balance
#### Modified tests from 7002. Just testing EL-triggered exits, not partial withdrawals
# Modified tests from 7002. Just testing EL-triggered exits, not partial withdrawals
@with_eip7251_and_later
@spec_state_test
@ -41,7 +33,7 @@ def test_basic_exit(spec, state):
execution_layer_withdraw_request = spec.ExecutionLayerWithdrawRequest(
source_address=address,
validator_pubkey=validator_pubkey,
amount = 0,
amount=0,
)
yield from run_execution_layer_withdraw_request_processing(spec, state, execution_layer_withdraw_request)
@ -65,7 +57,9 @@ def test_incorrect_source_address(spec, state):
amount=0,
)
yield from run_execution_layer_withdraw_request_processing(spec, state, execution_layer_withdraw_request, success=False)
yield from run_execution_layer_withdraw_request_processing(
spec, state, execution_layer_withdraw_request, success=False
)
@with_eip7251_and_later
@ -90,7 +84,9 @@ def test_incorrect_withdrawal_credential_prefix(spec, state):
amount=0,
)
yield from run_execution_layer_withdraw_request_processing(spec, state, execution_layer_withdraw_request, success=False)
yield from run_execution_layer_withdraw_request_processing(
spec, state, execution_layer_withdraw_request, success=False
)
@with_eip7251_and_later
@ -112,7 +108,9 @@ def test_on_exit_initiated_validator(spec, state):
amount=0,
)
yield from run_execution_layer_withdraw_request_processing(spec, state, execution_layer_withdraw_request, success=False)
yield from run_execution_layer_withdraw_request_processing(
spec, state, execution_layer_withdraw_request, success=False
)
@with_eip7251_and_later
@ -133,12 +131,12 @@ def test_activation_epoch_less_than_shard_committee_period(spec, state):
state.validators[validator_index].activation_epoch + spec.config.SHARD_COMMITTEE_PERIOD
)
yield from run_execution_layer_withdraw_request_processing(spec, state, execution_layer_withdraw_request, success=False)
yield from run_execution_layer_withdraw_request_processing(
spec, state, execution_layer_withdraw_request, success=False
)
## Partial withdrawals tests
# Partial withdrawals tests
@with_eip7251_and_later
@spec_state_test
@ -153,21 +151,23 @@ def test_partial_withdrawal_queue_full(spec, state):
execution_layer_withdraw_request = spec.ExecutionLayerWithdrawRequest(
source_address=address,
validator_pubkey=validator_pubkey,
amount = 10**9,
amount=10 ** 9,
)
partial_withdrawal = spec.PartialWithdrawal(index=0,amount=1,withdrawable_epoch=current_epoch)
partial_withdrawal = spec.PartialWithdrawal(index=0, amount=1, withdrawable_epoch=current_epoch)
state.pending_partial_withdrawals = [partial_withdrawal] * spec.PENDING_PARTIAL_WITHDRAWALS_LIMIT
yield from run_execution_layer_withdraw_request_processing(spec, state, execution_layer_withdraw_request, success=False)
yield from run_execution_layer_withdraw_request_processing(
spec, state, execution_layer_withdraw_request, success=False
)
#
# Run processing
#
def run_execution_layer_withdraw_request_processing(spec, state, execution_layer_withdraw_request, valid=True, success=True):
def run_execution_layer_withdraw_request_processing(
spec, state, execution_layer_withdraw_request, valid=True, success=True
):
"""
Run ``process_execution_layer_withdraw_request``, yielding:
- pre-state ('pre')
@ -182,7 +182,8 @@ def run_execution_layer_withdraw_request_processing(spec, state, execution_layer
yield 'execution_layer_withdraw_request', execution_layer_withdraw_request
if not valid:
expect_assertion_error(lambda: spec.process_execution_layer_withdraw_request(state, execution_layer_withdraw_request))
expect_assertion_error(
lambda: spec.process_execution_layer_withdraw_request(state, execution_layer_withdraw_request))
yield 'post', None
return
@ -207,6 +208,6 @@ def run_execution_layer_withdraw_request_processing(spec, state, execution_layer
post_length = len(state.pending_partial_withdrawals)
assert post_length == len(pre_pending_partial_withdrawals) + 1
assert post_length < spec.PENDING_PARTIAL_WITHDRAWALS_LIMIT
assert state.pending_partial_withdrawals[post_length-1].validator_index == validator_index
assert state.pending_partial_withdrawals[post_length - 1].validator_index == validator_index
else:
assert state.pending_partial_withdrawals == pre_pending_partial_withdrawals

View File

@ -2,7 +2,7 @@ from eth2spec.test.helpers.constants import (MINIMAL, MAINNET)
from eth2spec.test.context import (
spec_state_test,
with_eip7251_and_later,
with_presets,
with_presets,
always_bls,
spec_test, single_phase,
with_custom_state,
@ -17,6 +17,7 @@ from eth2spec.test.helpers.voluntary_exits import (
# * EXIT QUEUE TESTS *
# ********************
@with_eip7251_and_later
@spec_state_test
def test_min_balance_exit(spec, state):
@ -32,7 +33,7 @@ def test_min_balance_exit(spec, state):
yield "post", state
# Check exit queue churn is set
assert state.exit_balance_to_consume == churn_limit - spec.MIN_ACTIVATION_BALANCE
assert state.exit_balance_to_consume == churn_limit - spec.MIN_ACTIVATION_BALANCE
# Check exit epoch
assert state.validators[0].exit_epoch == expected_exit_epoch
@ -54,11 +55,12 @@ def test_min_balance_exits_up_to_churn(spec, state):
spec.initiate_validator_exit(state, validator_index)
yield f"post{i}", state
# Check exit queue churn is set
assert state.exit_balance_to_consume == churn_limit - single_validator_balance * (i + 1)
assert state.exit_balance_to_consume == churn_limit - single_validator_balance * (i + 1)
# Check exit epoch
assert state.validators[validator_index].exit_epoch == expected_exit_epoch
yield "post", state
@with_eip7251_and_later
@spec_state_test
def test_min_balance_exits_above_churn(spec, state):
@ -75,7 +77,7 @@ def test_min_balance_exits_above_churn(spec, state):
validator_index = i
spec.initiate_validator_exit(state, validator_index)
# Check exit queue churn is set
assert state.exit_balance_to_consume == churn_limit - single_validator_balance * (i + 1)
assert state.exit_balance_to_consume == churn_limit - single_validator_balance * (i + 1)
# Check exit epoch
assert state.validators[validator_index].exit_epoch == expected_exit_epoch
@ -94,12 +96,11 @@ def test_min_balance_exits_above_churn(spec, state):
assert state.exit_balance_to_consume == churn_limit - single_validator_balance
# @with_eip7251_and_later
# @spec_state_test
# def test_exit_balance_to_consume_large_validator(spec, state):
# # Set 0th validator effective balance to 2048 ETH
# state.validators[0].effective_balance = spec.MAX_EFFECTIVE_BALANCE_EIP7251
# state.validators[0].effective_balance = spec.MAX_EFFECTIVE_BALANCE_EIP7251
# churn_limit = spec.get_validator_churn_limit(state)
# expected_exit_epoch = spec.compute_activation_exit_epoch(spec.get_current_epoch(state))
# expected_exit_epoch += spec.MAX_EFFECTIVE_BALANCE_EIP7251 // churn_limit
@ -154,18 +155,20 @@ def test_exit_with_balance_equal_to_churn_limit(spec, state):
yield 'post', state
# Validator consumes churn limit fully in the current epoch
assert state.validators[validator_index].exit_epoch == spec.compute_activation_exit_epoch(spec.get_current_epoch(state))
assert (state.validators[validator_index].exit_epoch ==
spec.compute_activation_exit_epoch(spec.get_current_epoch(state)))
# Check exit_balance_to_consume
assert state.exit_balance_to_consume == 0
# Check earliest_exit_epoch
assert state.earliest_exit_epoch == state.validators[validator_index].exit_epoch
@with_eip7251_and_later
@spec_state_test
@with_presets([MAINNET], "With CHURN_LIMIT_QUOTIENT=32, can't change validator balance without changing churn_limit")
def test_exit_churn_limit_balance_existing_churn_(spec, state):
cl = spec.get_activation_exit_churn_limit(state)
# set exit epoch to the first available one and set exit balance to consume to full churn limit
state.earliest_exit_epoch = spec.compute_activation_exit_epoch(spec.get_current_epoch(state))
state.exit_balance_to_consume = cl
@ -187,7 +190,7 @@ def test_exit_churn_limit_balance_existing_churn_(spec, state):
assert state.validators[validator_index].exit_epoch == expected_exit_epoch
# Check balance consumed in exit epoch is the remainder 1 ETH
assert state.exit_balance_to_consume == cl - 1000000000
# check earliest exit epoch
# check earliest exit epoch
assert expected_exit_epoch == state.earliest_exit_epoch
@ -203,9 +206,8 @@ def test_multi_epoch_exit_existing_churn(spec, state):
# consume some churn in exit epoch
state.exit_balance_to_consume -= 1000000000
# Set 0th validator effective balance to 2x the churn limit
state.validators[0].effective_balance = 2*cl
state.validators[0].effective_balance = 2 * cl
yield 'pre', state
# Two extra epochs will be necessary
@ -218,11 +220,11 @@ def test_multi_epoch_exit_existing_churn(spec, state):
assert state.validators[validator_index].exit_epoch == expected_exit_epoch
# Check balance consumed in exit epoch is the remainder 1 ETH
assert state.exit_balance_to_consume == cl - 1000000000
# check earliest exit epoch
# check earliest exit epoch
assert expected_exit_epoch == state.earliest_exit_epoch
### Repurposed from phase0 voluntary exit tests, should disable the phase0 ones
# Repurposed from phase0 voluntary exit tests, should disable the phase0 ones
def run_test_success_exit_queue(spec, state):
# move state forward SHARD_COMMITTEE_PERIOD epochs to allow for exit
@ -267,8 +269,8 @@ def run_test_success_exit_queue(spec, state):
state.validators[index].exit_epoch + 1
)
assert state.earliest_exit_epoch == state.validators[validator_index].exit_epoch
consumed_churn = spec.MIN_ACTIVATION_BALANCE * (max_exits+1)
assert state.exit_balance_to_consume == churn_limit - (consumed_churn % churn_limit)
consumed_churn = spec.MIN_ACTIVATION_BALANCE * (max_exits + 1)
assert state.exit_balance_to_consume == churn_limit - (consumed_churn % churn_limit)
@with_eip7251_and_later
@ -276,6 +278,7 @@ def run_test_success_exit_queue(spec, state):
def test_success_exit_queue__min_churn(spec, state):
yield from run_test_success_exit_queue(spec, state)
@with_eip7251_and_later
@with_presets([MINIMAL],
reason="mainnet config leads to larger validator set than limit of public/private keys pre-generated")
@ -289,8 +292,7 @@ def test_success_exit_queue__scaled_churn(spec, state):
yield from run_test_success_exit_queue(spec, state)
#### After here no modifications were made, can just leave them in phase0 as is
# After here no modifications were made, can just leave them in phase0 as is
@with_eip7251_and_later
@spec_state_test
@ -327,11 +329,6 @@ def test_invalid_incorrect_signature(spec, state):
yield from run_voluntary_exit_processing(spec, state, signed_voluntary_exit, valid=False)
@with_eip7251_and_later
@spec_state_test
def test_default_exit_epoch_subsequent_exit(spec, state):

View File

@ -2,9 +2,9 @@ from eth2spec.test.helpers.epoch_processing import run_epoch_processing_with
from eth2spec.test.context import (
spec_state_test,
with_eip7251_and_later,
with_presets,
)
@with_eip7251_and_later
@spec_state_test
def test_pending_deposit_min_activation_balance(spec, state):
@ -13,11 +13,12 @@ def test_pending_deposit_min_activation_balance(spec, state):
state.pending_balance_deposits.append(spec.PendingBalanceDeposit(index=index, amount=amount))
pre_balance = state.balances[index]
yield from run_epoch_processing_with(spec, state, 'process_pending_balance_deposits')
assert state.balances[index] == pre_balance + amount
# No leftover deposit balance to consume when there are no deposits left to process
assert state.balances[index] == pre_balance + amount
# No leftover deposit balance to consume when there are no deposits left to process
assert state.deposit_balance_to_consume == 0
assert state.pending_balance_deposits == []
@with_eip7251_and_later
@spec_state_test
def test_pending_deposit_balance_equal_churn(spec, state):
@ -30,6 +31,7 @@ def test_pending_deposit_balance_equal_churn(spec, state):
assert state.deposit_balance_to_consume == 0
assert state.pending_balance_deposits == []
@with_eip7251_and_later
@spec_state_test
def test_pending_deposit_balance_above_churn(spec, state):
@ -45,22 +47,24 @@ def test_pending_deposit_balance_above_churn(spec, state):
# deposit is still in the queue
assert state.pending_balance_deposits == [spec.PendingBalanceDeposit(index=index, amount=amount)]
@with_eip7251_and_later
@spec_state_test
def test_pending_deposit_preexisting_churn(spec, state):
index = 0
amount = 10**9 + 1
state.deposit_balance_to_consume = 2*amount
amount = 10 ** 9 + 1
state.deposit_balance_to_consume = 2 * amount
state.pending_balance_deposits.append(spec.PendingBalanceDeposit(index=index, amount=amount))
pre_balance = state.balances[index]
yield from run_epoch_processing_with(spec, state, 'process_pending_balance_deposits')
# balance was deposited correctly
assert state.balances[index] == pre_balance + amount
# No leftover deposit balance to consume when there are no deposits left to process
# No leftover deposit balance to consume when there are no deposits left to process
assert state.deposit_balance_to_consume == 0
# queue emptied
assert state.pending_balance_deposits == []
@with_eip7251_and_later
@spec_state_test
def test_multiple_pending_deposits_below_churn(spec, state):
@ -69,29 +73,27 @@ def test_multiple_pending_deposits_below_churn(spec, state):
state.pending_balance_deposits.append(spec.PendingBalanceDeposit(index=1, amount=amount))
pre_balances = state.balances
yield from run_epoch_processing_with(spec, state, 'process_pending_balance_deposits')
for i in [0,1]:
assert state.balances[i] == pre_balances[i] + amount
# No leftover deposit balance to consume when there are no deposits left to process
for i in [0, 1]:
assert state.balances[i] == pre_balances[i] + amount
# No leftover deposit balance to consume when there are no deposits left to process
assert state.deposit_balance_to_consume == 0
assert state.pending_balance_deposits == []
@with_eip7251_and_later
@spec_state_test
def test_multiple_pending_deposits_above_churn(spec, state):
# set third deposit to be over the churn
amount = (spec.get_activation_exit_churn_limit(state) // 3) + 1
for i in [0,1,2]:
for i in [0, 1, 2]:
state.pending_balance_deposits.append(spec.PendingBalanceDeposit(index=i, amount=amount))
pre_balances = state.balances
yield from run_epoch_processing_with(spec, state, 'process_pending_balance_deposits')
# First two deposits are processed, third is not because above churn
for i in [0,1]:
assert state.balances[i] == pre_balances[i] + amount
for i in [0, 1]:
assert state.balances[i] == pre_balances[i] + amount
assert state.balances[2] == pre_balances[2]
# Only first two subtract from the deposit balance to consume
assert state.deposit_balance_to_consume == spec.get_activation_exit_churn_limit(state) - 2*amount
assert state.deposit_balance_to_consume == spec.get_activation_exit_churn_limit(state) - 2 * amount
# third deposit is still in the queue
assert state.pending_balance_deposits == [spec.PendingBalanceDeposit(index=2, amount=amount)]

View File

@ -1,29 +1,14 @@
from eth2spec.test.helpers.constants import MINIMAL
from eth2spec.test.helpers.epoch_processing import run_epoch_processing_with
from eth2spec.test.helpers.state import next_epoch
from eth2spec.test.context import (
spec_state_test,
with_eip7251_and_later,
with_presets,
spec_test, single_phase,
with_custom_state,
scaled_churn_balances_exceed_activation_exit_churn_limit,
default_activation_threshold,
)
from eth2spec.test.helpers.keys import pubkey_to_privkey
from eth2spec.test.helpers.consolidations import (
run_consolidation_processing,
sign_consolidation,
)
from eth2spec.test.helpers.withdrawals import (
set_eth1_withdrawal_credential_with_balance,
set_compounding_withdrawal_credential,
)
# ***********************
# * CONSOLIDATION TESTS *
# ***********************
@with_eip7251_and_later
@spec_state_test
def test_basic_pending_consolidation(spec, state):
@ -31,7 +16,7 @@ def test_basic_pending_consolidation(spec, state):
source_index = spec.get_active_validator_indices(state, current_epoch)[0]
target_index = spec.get_active_validator_indices(state, current_epoch)[1]
# append pending consolidation
state.pending_consolidations.append(spec.PendingConsolidation(source_index=source_index,target_index=target_index))
state.pending_consolidations.append(spec.PendingConsolidation(source_index=source_index, target_index=target_index))
# Set withdrawable epoch to current epoch to allow processing
state.validators[source_index].withdrawable_epoch = spec.get_current_epoch(state)
yield from run_epoch_processing_with(spec, state, "process_pending_consolidations")
@ -39,7 +24,6 @@ def test_basic_pending_consolidation(spec, state):
assert state.balances[target_index] == 2 * spec.MIN_ACTIVATION_BALANCE
assert state.balances[source_index] == 0
@with_eip7251_and_later
@spec_state_test
@ -50,8 +34,12 @@ def test_skip_consolidation_when_source_slashed(spec, state):
source1_index = spec.get_active_validator_indices(state, current_epoch)[2]
target1_index = spec.get_active_validator_indices(state, current_epoch)[3]
# append pending consolidation
state.pending_consolidations.append(spec.PendingConsolidation(source_index=source0_index,target_index=target0_index))
state.pending_consolidations.append(spec.PendingConsolidation(source_index=source1_index,target_index=target1_index))
state.pending_consolidations.append(
spec.PendingConsolidation(source_index=source0_index, target_index=target0_index)
)
state.pending_consolidations.append(
spec.PendingConsolidation(source_index=source1_index, target_index=target1_index)
)
# Set withdrawable epoch of sources to current epoch to allow processing
state.validators[source0_index].withdrawable_epoch = spec.get_current_epoch(state)
@ -67,5 +55,3 @@ def test_skip_consolidation_when_source_slashed(spec, state):
# second pending consolidation should be processed: first one is skipped and doesn't block the queue
assert state.balances[target1_index] == 2 * spec.MIN_ACTIVATION_BALANCE
assert state.balances[source1_index] == 0

View File

@ -1,4 +1,3 @@
from random import Random
from eth2spec.utils import bls
from eth2spec.test.context import expect_assertion_error
from eth2spec.test.helpers.keys import privkeys
@ -11,10 +10,12 @@ def prepare_signed_consolidations(spec, state, index_pairs, fork_version=None):
source_index=source_index,
target_index=target_index,
)
return sign_consolidation(spec, state, consolidation, privkeys[source_index], privkeys[target_index], fork_version=fork_version)
return sign_consolidation(spec, state, consolidation, privkeys[source_index], privkeys[target_index],
fork_version=fork_version)
return [create_signed_consolidation(source_index, target_index) for (source_index, target_index) in index_pairs]
def sign_consolidation(spec, state, consolidation, source_privkey, target_privkey, fork_version=None):
domain = spec.compute_domain(spec.DOMAIN_CONSOLIDATION, genesis_validators_root=state.genesis_validators_root)
signing_root = spec.compute_signing_root(consolidation, domain)
@ -23,6 +24,7 @@ def sign_consolidation(spec, state, consolidation, source_privkey, target_privke
signature=bls.Aggregate([bls.Sign(source_privkey, signing_root), bls.Sign(target_privkey, signing_root)])
)
def run_consolidation_processing(spec, state, signed_consolidation, valid=True):
"""
Run ``process_consolidation``, yielding:
@ -43,7 +45,6 @@ def run_consolidation_processing(spec, state, signed_consolidation, valid=True):
yield 'post', None
return
pre_exit_epoch = source_validator.exit_epoch
spec.process_consolidation(state, signed_consolidation)
@ -54,8 +55,7 @@ def run_consolidation_processing(spec, state, signed_consolidation, valid=True):
assert pre_exit_epoch == spec.FAR_FUTURE_EPOCH
assert state.validators[signed_consolidation.message.source_index].exit_epoch < spec.FAR_FUTURE_EPOCH
assert state.validators[signed_consolidation.message.source_index].exit_epoch == state.earliest_consolidation_epoch
assert state.pending_consolidations[len(state.pending_consolidations)-1] == spec.PendingConsolidation(
source_index = signed_consolidation.message.source_index,
target_index = signed_consolidation.message.target_index
)
assert state.pending_consolidations[len(state.pending_consolidations) - 1] == spec.PendingConsolidation(
source_index=signed_consolidation.message.source_index,
target_index=signed_consolidation.message.target_index
)

View File

@ -395,7 +395,7 @@ def run_deposit_receipt_processing_with_specific_fork_version(
# ********************
# * EIP7251 *
# ********************
def run_deposit_processing_eip7251(spec, state, deposit, validator_index, valid=True, effective=True):
"""
@ -413,7 +413,7 @@ def run_deposit_processing_eip7251(spec, state, deposit, validator_index, valid=
# is a top-up
if validator_index < pre_validator_count:
is_top_up = True
pre_balance = get_balance(state, validator_index)
pre_balance = get_balance(state, validator_index)
pre_effective_balance = state.validators[validator_index].effective_balance
yield 'pre', state

View File

@ -157,5 +157,3 @@ def create_genesis_state(spec, validator_balances, activation_threshold):
state.pending_partial_withdrawals = []
return state

View File

@ -58,7 +58,7 @@ def prepare_expected_withdrawals(spec, state,
def set_compounding_withdrawal_credential(spec, state, index, address=None):
if address is None:
address = b'\x11' * 20
address = b'\x11' * 20
validator = state.validators[index]
validator.withdrawal_credentials = spec.COMPOUNDING_WITHDRAWAL_PREFIX + b'\x00' * 11 + address
validator.withdrawal_credentials = spec.COMPOUNDING_WITHDRAWAL_PREFIX + b'\x00' * 11 + address