Merge in EIP-7251 tests to Electra

This commit is contained in:
Alex Stokes 2024-04-15 19:45:40 -06:00
parent e1840a78a0
commit 034909ddb6
No known key found for this signature in database
28 changed files with 119 additions and 1700 deletions

View File

@ -168,19 +168,6 @@ jobs:
command: make citest fork=electra
- store_test_results:
path: tests/core/pyspec/test-reports
test-eip7251:
docker:
- image: circleci/python:3.9
working_directory: ~/specs-repo
steps:
- restore_cache:
key: v3-specs-repo-{{ .Branch }}-{{ .Revision }}
- restore_pyspec_cached_venv
- run:
name: Run py-tests
command: make citest fork=eip7251
- store_test_results:
path: tests/core/pyspec/test-reports
test-whisk:
docker:
- image: circleci/python:3.9
@ -330,9 +317,6 @@ workflows:
- test-electra:
requires:
- install_pyspec_test
- test-eip7251:
requires:
- install_pyspec_test
- test-whisk:
requires:
- install_pyspec_test

View File

@ -71,7 +71,7 @@ jobs:
needs: [preclear,lint,codespell,table_of_contents]
strategy:
matrix:
version: ["phase0", "altair", "bellatrix", "capella", "deneb", "electra", "eip7251", "whisk", "eip7594"]
version: ["phase0", "altair", "bellatrix", "capella", "deneb", "electra", "whisk", "eip7594"]
steps:
- name: Checkout this repo
uses: actions/checkout@v3.2.0

View File

@ -35,7 +35,7 @@ MARKDOWN_FILES = $(wildcard $(SPEC_DIR)/*/*.md) \
$(wildcard $(SPEC_DIR)/_features/*/*/*.md) \
$(wildcard $(SSZ_DIR)/*.md)
ALL_EXECUTABLE_SPEC_NAMES = phase0 altair bellatrix capella deneb electra eip7251 whisk
ALL_EXECUTABLE_SPEC_NAMES = phase0 altair bellatrix capella deneb electra whisk
# The parameters for commands. Use `foreach` to avoid listing specs again.
COVERAGE_SCOPE := $(foreach S,$(ALL_EXECUTABLE_SPEC_NAMES), --cov=eth2spec.$S.$(TEST_PRESET_TYPE))
PYLINT_SCOPE := $(foreach S,$(ALL_EXECUTABLE_SPEC_NAMES), ./eth2spec/$S)

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,7 @@ from eth2spec.test.context import (
spec_state_test,
with_capella_and_later,
)
from eth2spec.test.helpers.forks import is_post_eip7251
from eth2spec.test.helpers.forks import is_post_electra
from eth2spec.test.helpers.state import next_epoch_via_block
from eth2spec.test.helpers.deposits import (
prepare_state_and_deposit,
@ -31,7 +31,7 @@ def test_success_top_up_to_withdrawn_validator(spec, state):
yield from run_deposit_processing(spec, state, deposit, validator_index)
if is_post_eip7251(spec):
if is_post_electra(spec):
pending_balance_deposits_len = len(state.pending_balance_deposits)
pending_balance_deposit = state.pending_balance_deposits[pending_balance_deposits_len - 1]
assert pending_balance_deposit.amount == amount
@ -44,7 +44,7 @@ def test_success_top_up_to_withdrawn_validator(spec, state):
balance = state.balances[validator_index]
current_epoch = spec.get_current_epoch(state)
if is_post_eip7251(spec):
if is_post_electra(spec):
has_execution_withdrawal = spec.has_execution_withdrawal_credential(validator)
is_withdrawable = validator.withdrawable_epoch <= current_epoch
has_non_zero_balance = pending_balance_deposit.amount > 0

View File

@ -1,5 +1,5 @@
from eth2spec.test.helpers.constants import MINIMAL
from eth2spec.test.helpers.forks import is_post_eip7251
from eth2spec.test.helpers.forks import is_post_electra
from eth2spec.test.context import (
with_capella_and_later,
spec_state_test,
@ -359,7 +359,7 @@ def test_top_up_and_partial_withdrawable_validator(spec, state):
signed_block = state_transition_and_sign_block(spec, state, block)
# ensure we go through an epoch transition, to account for post-EIP-7251 behavior
# ensure we go through an epoch transition, to account for post-electra behavior
block_in_next_epoch = build_empty_block(spec, state, slot=state.slot + spec.SLOTS_PER_EPOCH)
signed_block_in_next_epoch = state_transition_and_sign_block(spec, state, block_in_next_epoch)
@ -402,7 +402,7 @@ def test_top_up_to_fully_withdrawn_validator(spec, state):
signed_block_1 = state_transition_and_sign_block(spec, state, block)
balance = state.balances[validator_index]
if is_post_eip7251(spec):
if is_post_electra(spec):
balance += state.pending_balance_deposits[0].amount
assert spec.is_fully_withdrawable_validator(

View File

@ -1,5 +1,5 @@
from eth2spec.test.helpers.keys import pubkeys
from eth2spec.test.helpers.forks import is_post_eip7251
from eth2spec.test.helpers.forks import is_post_electra
from eth2spec.test.helpers.constants import MINIMAL
from eth2spec.test.context import (
with_deneb_and_later,
@ -50,7 +50,7 @@ def run_test_activation_churn_limit(spec, state):
index = validator_count_0 + i
# NOTE: activations are gated different after EIP-7251
# all eligible validators have been activated
if index < validator_count_0 + churn_limit_0 or is_post_eip7251(spec):
if index < validator_count_0 + churn_limit_0 or is_post_electra(spec):
# The eligible validators within the activation churn limit should have been activated
assert state.validators[index].activation_epoch < spec.FAR_FUTURE_EPOCH
else:

View File

@ -1,441 +0,0 @@
from eth2spec.test.helpers.constants import (MINIMAL, MAINNET)
from eth2spec.test.context import (
spec_state_test,
with_electra_and_later,
with_presets,
always_bls,
spec_test, single_phase,
with_custom_state,
scaled_churn_balances_min_churn_limit,
)
from eth2spec.test.helpers.keys import pubkey_to_privkey
from eth2spec.test.helpers.voluntary_exits import (
run_voluntary_exit_processing,
sign_voluntary_exit,
)
# ********************
# * EXIT QUEUE TESTS *
# ********************
@with_electra_and_later
@spec_state_test
def test_min_balance_exit(spec, state):
# This state has 64 validators each with 32 ETH
expected_exit_epoch = spec.compute_activation_exit_epoch(spec.get_current_epoch(state))
churn_limit = spec.get_activation_exit_churn_limit(state)
# Set the balance to consume equal to churn limit
state.exit_balance_to_consume = churn_limit
yield "pre", state
# Exit validators, all which fit in the churn limit
spec.initiate_validator_exit(state, 0)
yield "post", state
# Check exit queue churn is set
assert state.exit_balance_to_consume == churn_limit - spec.MIN_ACTIVATION_BALANCE
# Check exit epoch
assert state.validators[0].exit_epoch == expected_exit_epoch
@with_electra_and_later
@spec_state_test
def test_min_balance_exits_up_to_churn(spec, state):
# This state has 64 validators each with 32 ETH
single_validator_balance = spec.MIN_ACTIVATION_BALANCE
expected_exit_epoch = spec.compute_activation_exit_epoch(spec.get_current_epoch(state))
churn_limit = spec.get_activation_exit_churn_limit(state)
# Set the balance to consume equal to churn limit
state.exit_balance_to_consume = churn_limit
yield "pre", state
# Exit validators, all which fit in the churn limit
for i in range(churn_limit // spec.MIN_ACTIVATION_BALANCE):
validator_index = i
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)
# Check exit epoch
assert state.validators[validator_index].exit_epoch == expected_exit_epoch
yield "post", state
@with_electra_and_later
@spec_state_test
def test_min_balance_exits_above_churn(spec, state):
# This state has 64 validators each with 32 ETH
single_validator_balance = spec.MIN_ACTIVATION_BALANCE
expected_exit_epoch = spec.compute_activation_exit_epoch(spec.get_current_epoch(state))
churn_limit = spec.get_activation_exit_churn_limit(state)
# Set the balance to consume equal to churn limit
state.exit_balance_to_consume = churn_limit
yield "pre", state
# Exit validators, all which fit in the churn limit
for i in range(churn_limit // spec.MIN_ACTIVATION_BALANCE):
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)
# Check exit epoch
assert state.validators[validator_index].exit_epoch == expected_exit_epoch
# Exit balance has been fully consumed
assert state.exit_balance_to_consume == 0
# Exit an additional validator, doesn't fit in the churn limit, so exit
# epoch is incremented
validator_index = churn_limit // spec.MIN_ACTIVATION_BALANCE
spec.initiate_validator_exit(state, validator_index)
yield "post", state
# Check exit epoch
assert state.validators[validator_index].exit_epoch == expected_exit_epoch + 1
# Check exit balance to consume is set
assert state.exit_balance_to_consume == churn_limit - single_validator_balance
# @with_electra_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_electra
# 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_electra // churn_limit
# validator_index = 0
# spec.initiate_validator_exit(state, validator_index)
# # Check exit epoch
# assert state.validators[validator_index].exit_epoch == expected_exit_epoch
# # Check exit_balance_to_consume
# assert state.exit_balance_to_consume == churn_limit - (spec.MAX_EFFECTIVE_BALANCE_electra % churn_limit)
# # Check earliest_exit_epoch
# assert state.earliest_exit_epoch == expected_exit_epoch
@with_electra_and_later
@spec_state_test
@with_presets([MAINNET], "With CHURN_LIMIT_QUOTIENT=32, can't change validator balance without changing churn_limit")
def test_max_balance_exit(spec, state):
churn_limit = spec.get_activation_exit_churn_limit(state)
assert churn_limit == spec.MIN_ACTIVATION_BALANCE * spec.config.MIN_PER_EPOCH_CHURN_LIMIT
# Set 0th validator effective balance to 2048 ETH
state.validators[0].effective_balance = spec.MAX_EFFECTIVE_BALANCE_electra
yield 'pre', state
expected_exit_epoch = spec.compute_activation_exit_epoch(spec.get_current_epoch(state))
# Validator consumes exit churn for 16 epochs, exits at the 17th one
expected_exit_epoch += (spec.MAX_EFFECTIVE_BALANCE_electra // churn_limit)
validator_index = 0
spec.initiate_validator_exit(state, validator_index)
yield 'post', state
# Check exit epoch
assert state.validators[validator_index].exit_epoch == expected_exit_epoch
# Check exit_balance_to_consume
assert state.exit_balance_to_consume == churn_limit
# Check earliest_exit_epoch
assert state.earliest_exit_epoch == expected_exit_epoch
@with_electra_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_with_balance_equal_to_churn_limit(spec, state):
churn_limit = spec.get_activation_exit_churn_limit(state)
# Set 0th validator effective balance to churn_limit
state.validators[0].effective_balance = churn_limit
yield 'pre', state
validator_index = 0
spec.initiate_validator_exit(state, validator_index)
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)))
# 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_electra_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
# consume some churn in exit epoch
state.exit_balance_to_consume -= 1000000000
# Set 0th validator effective balance to the churn limit
state.validators[0].effective_balance = cl
yield 'pre', state
# The existing 1 ETH churn will push an extra epoch
expected_exit_epoch = state.earliest_exit_epoch + 1
yield 'post', state
validator_index = 0
spec.initiate_validator_exit(state, validator_index)
# Check exit epoch
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
assert expected_exit_epoch == state.earliest_exit_epoch
@with_electra_and_later
@spec_state_test
@with_presets([MAINNET], "With CHURN_LIMIT_QUOTIENT=32, can't change validator balance without changing churn_limit")
def test_multi_epoch_exit_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
# 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
yield 'pre', state
# Two extra epochs will be necessary
expected_exit_epoch = spec.compute_activation_exit_epoch(spec.get_current_epoch(state)) + 2
validator_index = 0
spec.initiate_validator_exit(state, validator_index)
yield 'post', state
# Check exit epoch
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
assert expected_exit_epoch == state.earliest_exit_epoch
# 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
state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH
current_epoch = spec.get_current_epoch(state)
churn_limit = spec.get_activation_exit_churn_limit(state)
# exit `MAX_EXITS_PER_EPOCH`
max_exits = churn_limit // spec.MIN_ACTIVATION_BALANCE
initial_indices = spec.get_active_validator_indices(state, current_epoch)[:max_exits]
# Prepare a bunch of exits, based on the current state
exit_queue = []
for index in initial_indices:
privkey = pubkey_to_privkey[state.validators[index].pubkey]
signed_voluntary_exit = sign_voluntary_exit(
spec, state, spec.VoluntaryExit(epoch=current_epoch, validator_index=index), privkey)
exit_queue.append(signed_voluntary_exit)
# Now run all the exits
for voluntary_exit in exit_queue:
# the function yields data, but we are just interested in running it here, ignore yields.
for _ in run_voluntary_exit_processing(spec, state, voluntary_exit):
continue
# exit an additional validator
validator_index = spec.get_active_validator_indices(state, current_epoch)[-1]
privkey = pubkey_to_privkey[state.validators[validator_index].pubkey]
signed_voluntary_exit = sign_voluntary_exit(
spec, state, spec.VoluntaryExit(epoch=current_epoch, validator_index=validator_index), privkey)
# This is the interesting part of the test: on a pre-state with a full exit queue,
# when processing an additional exit, it results in an exit in a later epoch
yield from run_voluntary_exit_processing(spec, state, signed_voluntary_exit)
for index in initial_indices:
assert (
state.validators[validator_index].exit_epoch ==
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)
@with_electra_and_later
@spec_state_test
def test_success_exit_queue__min_churn(spec, state):
yield from run_test_success_exit_queue(spec, state)
@with_electra_and_later
@with_presets([MINIMAL],
reason="mainnet config leads to larger validator set than limit of public/private keys pre-generated")
@spec_test
@with_custom_state(balances_fn=scaled_churn_balances_min_churn_limit,
threshold_fn=lambda spec: spec.config.EJECTION_BALANCE)
@single_phase
def test_success_exit_queue__scaled_churn(spec, state):
churn_limit = spec.get_activation_exit_churn_limit(state)
assert churn_limit > spec.config.MIN_PER_EPOCH_CHURN_LIMIT
yield from run_test_success_exit_queue(spec, state)
# After here no modifications were made, can just leave them in phase0 as is
@with_electra_and_later
@spec_state_test
def test_basic(spec, state):
state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH
current_epoch = spec.get_current_epoch(state)
validator_index = spec.get_active_validator_indices(state, current_epoch)[0]
privkey = pubkey_to_privkey[state.validators[validator_index].pubkey]
signed_voluntary_exit = sign_voluntary_exit(
spec, state, spec.VoluntaryExit(epoch=current_epoch, validator_index=validator_index), privkey)
yield from run_voluntary_exit_processing(spec, state, signed_voluntary_exit)
assert state.validators[validator_index].exit_epoch == spec.compute_activation_exit_epoch(current_epoch)
@with_electra_and_later
@spec_state_test
@always_bls
def test_invalid_incorrect_signature(spec, state):
# move state forward SHARD_COMMITTEE_PERIOD epochs to allow for exit
state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH
current_epoch = spec.get_current_epoch(state)
validator_index = spec.get_active_validator_indices(state, current_epoch)[0]
voluntary_exit = spec.VoluntaryExit(
epoch=current_epoch,
validator_index=validator_index,
)
signed_voluntary_exit = sign_voluntary_exit(spec, state, voluntary_exit, 12345)
yield from run_voluntary_exit_processing(spec, state, signed_voluntary_exit, valid=False)
@with_electra_and_later
@spec_state_test
def test_default_exit_epoch_subsequent_exit(spec, state):
# move state forward SHARD_COMMITTEE_PERIOD epochs to allow for exit
state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH
current_epoch = spec.get_current_epoch(state)
validator_index = spec.get_active_validator_indices(state, current_epoch)[0]
privkey = pubkey_to_privkey[state.validators[validator_index].pubkey]
signed_voluntary_exit = sign_voluntary_exit(
spec, state, spec.VoluntaryExit(epoch=current_epoch, validator_index=validator_index), privkey)
# Exit one validator prior to this new one
exited_index = spec.get_active_validator_indices(state, current_epoch)[-1]
state.validators[exited_index].exit_epoch = current_epoch - 1
yield from run_voluntary_exit_processing(spec, state, signed_voluntary_exit)
assert state.validators[validator_index].exit_epoch == spec.compute_activation_exit_epoch(current_epoch)
@with_electra_and_later
@spec_state_test
def test_invalid_validator_exit_in_future(spec, state):
# move state forward SHARD_COMMITTEE_PERIOD epochs to allow for exit
state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH
current_epoch = spec.get_current_epoch(state)
validator_index = spec.get_active_validator_indices(state, current_epoch)[0]
privkey = pubkey_to_privkey[state.validators[validator_index].pubkey]
voluntary_exit = spec.VoluntaryExit(
epoch=current_epoch + 1,
validator_index=validator_index,
)
signed_voluntary_exit = sign_voluntary_exit(spec, state, voluntary_exit, privkey)
yield from run_voluntary_exit_processing(spec, state, signed_voluntary_exit, valid=False)
@with_electra_and_later
@spec_state_test
def test_invalid_validator_incorrect_validator_index(spec, state):
# move state forward SHARD_COMMITTEE_PERIOD epochs to allow for exit
state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH
current_epoch = spec.get_current_epoch(state)
validator_index = spec.get_active_validator_indices(state, current_epoch)[0]
privkey = pubkey_to_privkey[state.validators[validator_index].pubkey]
voluntary_exit = spec.VoluntaryExit(
epoch=current_epoch,
validator_index=len(state.validators),
)
signed_voluntary_exit = sign_voluntary_exit(spec, state, voluntary_exit, privkey)
yield from run_voluntary_exit_processing(spec, state, signed_voluntary_exit, valid=False)
@with_electra_and_later
@spec_state_test
def test_invalid_validator_not_active(spec, state):
current_epoch = spec.get_current_epoch(state)
validator_index = spec.get_active_validator_indices(state, current_epoch)[0]
privkey = pubkey_to_privkey[state.validators[validator_index].pubkey]
state.validators[validator_index].activation_epoch = spec.FAR_FUTURE_EPOCH
signed_voluntary_exit = sign_voluntary_exit(
spec, state, spec.VoluntaryExit(epoch=current_epoch, validator_index=validator_index), privkey)
yield from run_voluntary_exit_processing(spec, state, signed_voluntary_exit, valid=False)
@with_electra_and_later
@spec_state_test
def test_invalid_validator_already_exited(spec, state):
# move state forward SHARD_COMMITTEE_PERIOD epochs to allow validator able to exit
state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH
current_epoch = spec.get_current_epoch(state)
validator_index = spec.get_active_validator_indices(state, current_epoch)[0]
privkey = pubkey_to_privkey[state.validators[validator_index].pubkey]
# but validator already has exited
state.validators[validator_index].exit_epoch = current_epoch + 2
signed_voluntary_exit = sign_voluntary_exit(
spec, state, spec.VoluntaryExit(epoch=current_epoch, validator_index=validator_index), privkey)
yield from run_voluntary_exit_processing(spec, state, signed_voluntary_exit, valid=False)
@with_electra_and_later
@spec_state_test
def test_invalid_validator_not_active_long_enough(spec, state):
current_epoch = spec.get_current_epoch(state)
validator_index = spec.get_active_validator_indices(state, current_epoch)[0]
privkey = pubkey_to_privkey[state.validators[validator_index].pubkey]
signed_voluntary_exit = sign_voluntary_exit(
spec, state, spec.VoluntaryExit(epoch=current_epoch, validator_index=validator_index), privkey)
assert (
current_epoch - state.validators[validator_index].activation_epoch <
spec.config.SHARD_COMMITTEE_PERIOD
)
yield from run_voluntary_exit_processing(spec, state, signed_voluntary_exit, valid=False)

View File

@ -118,7 +118,7 @@ def test_basic_consolidation_in_new_consolidation_epoch(spec, state):
assert state.validators[0].exit_epoch == expected_exit_epoch
@with_eip7251_and_later
@with_electra_and_later
@with_presets([MINIMAL], "need sufficient consolidation churn limit")
@with_custom_state(
balances_fn=scaled_churn_balances_exceed_activation_exit_churn_limit,
@ -166,7 +166,7 @@ def test_basic_consolidation_with_preexisting_churn(spec, state):
assert state.validators[0].exit_epoch == expected_exit_epoch
@with_eip7251_and_later
@with_electra_and_later
@with_presets([MINIMAL], "need sufficient consolidation churn limit")
@with_custom_state(
balances_fn=scaled_churn_balances_exceed_activation_exit_churn_limit,
@ -218,7 +218,7 @@ def test_basic_consolidation_with_insufficient_preexisting_churn(spec, state):
assert state.validators[0].exit_epoch == expected_exit_epoch
@with_eip7251_and_later
@with_electra_and_later
@with_presets([MINIMAL], "need sufficient consolidation churn limit")
@with_custom_state(
balances_fn=scaled_churn_balances_exceed_activation_exit_churn_limit,
@ -701,7 +701,7 @@ def test_invalid_exceed_pending_consolidations_limit(spec, state):
)
@with_eip7251_and_later
@with_electra_and_later
@spec_state_test
def test_invalid_not_enough_consolidation_churn_available(spec, state):
state.validators = state.validators[0:2]

View File

@ -1,8 +1,8 @@
from eth2spec.test.helpers.deposits import (
build_deposit,
prepare_state_and_deposit,
run_deposit_processing_electra,
run_deposit_processing_electra_with_specific_fork_version,
run_deposit_processing,
run_deposit_processing_with_specific_fork_version,
sign_deposit_data,
)
from eth2spec.test.helpers.keys import privkeys, pubkeys
@ -23,7 +23,7 @@ def test_new_deposit_under_min_activation_balance(spec, state):
amount = spec.MIN_ACTIVATION_BALANCE - 1
deposit = prepare_state_and_deposit(spec, state, validator_index, amount, signed=True)
yield from run_deposit_processing_electra(spec, state, deposit, validator_index)
yield from run_deposit_processing(spec, state, deposit, validator_index)
@with_electra_and_later
@ -33,7 +33,7 @@ def test_new_deposit_min(spec, state):
validator_index = len(state.validators)
amount = spec.MIN_DEPOSIT_AMOUNT
deposit = prepare_state_and_deposit(spec, state, validator_index, amount, signed=True)
yield from run_deposit_processing_electra(spec, state, deposit, validator_index)
yield from run_deposit_processing(spec, state, deposit, validator_index)
@with_electra_and_later
@ -43,7 +43,7 @@ def test_new_deposit_between_min_and_max(spec, state):
validator_index = len(state.validators)
amount = spec.MAX_EFFECTIVE_BALANCE_electra // 2
deposit = prepare_state_and_deposit(spec, state, validator_index, amount, signed=True)
yield from run_deposit_processing_electra(spec, state, deposit, validator_index)
yield from run_deposit_processing(spec, state, deposit, validator_index)
@with_electra_and_later
@ -54,7 +54,7 @@ def test_new_deposit_max(spec, state):
# effective balance will be exactly the same as balance.
amount = spec.MAX_EFFECTIVE_BALANCE_electra
deposit = prepare_state_and_deposit(spec, state, validator_index, amount, signed=True)
yield from run_deposit_processing_electra(spec, state, deposit, validator_index)
yield from run_deposit_processing(spec, state, deposit, validator_index)
@with_electra_and_later
@ -64,7 +64,7 @@ def test_new_deposit_over_max(spec, state):
validator_index = len(state.validators)
amount = spec.MAX_EFFECTIVE_BALANCE_electra + 1
deposit = prepare_state_and_deposit(spec, state, validator_index, amount, signed=True)
yield from run_deposit_processing_electra(spec, state, deposit, validator_index)
yield from run_deposit_processing(spec, state, deposit, validator_index)
# @with_electra_and_later
@ -77,7 +77,7 @@ def test_new_deposit_over_max(spec, state):
# state.balances[validator_index] = spec.MAX_EFFECTIVE_BALANCE_electra
# state.validators[validator_index].effective_balance = spec.MAX_EFFECTIVE_BALANCE_electra
# yield from run_deposit_processing_electra(spec, state, deposit, validator_index)
# yield from run_deposit_processing(spec, state, deposit, validator_index)
# assert state.balances[validator_index] == spec.MAX_EFFECTIVE_BALANCE_electra + amount
# assert state.validators[validator_index].effective_balance == spec.MAX_EFFECTIVE_BALANCE_electra
@ -91,7 +91,7 @@ def test_correct_sig_but_forked_state(spec, state):
# deposits will always be valid, regardless of the current fork
state.fork.current_version = spec.Version('0x1234abcd')
deposit = prepare_state_and_deposit(spec, state, validator_index, amount, signed=True)
yield from run_deposit_processing_electra(spec, state, deposit, validator_index)
yield from run_deposit_processing(spec, state, deposit, validator_index)
@with_electra_and_later
@ -102,7 +102,7 @@ def test_incorrect_sig_new_deposit(spec, state):
validator_index = len(state.validators)
amount = spec.MIN_ACTIVATION_BALANCE
deposit = prepare_state_and_deposit(spec, state, validator_index, amount)
yield from run_deposit_processing_electra(spec, state, deposit, validator_index, effective=False)
yield from run_deposit_processing(spec, state, deposit, validator_index, effective=False)
@with_electra_and_later
@ -115,7 +115,7 @@ def test_top_up__max_effective_balance(spec, state):
state.balances[validator_index] = spec.MAX_EFFECTIVE_BALANCE
state.validators[validator_index].effective_balance = spec.MAX_EFFECTIVE_BALANCE
yield from run_deposit_processing_electra(spec, state, deposit, validator_index)
yield from run_deposit_processing(spec, state, deposit, validator_index)
assert state.validators[validator_index].effective_balance == spec.MAX_EFFECTIVE_BALANCE
@ -132,7 +132,7 @@ def test_top_up__less_effective_balance(spec, state):
state.balances[validator_index] = initial_balance
state.validators[validator_index].effective_balance = initial_effective_balance
yield from run_deposit_processing_electra(spec, state, deposit, validator_index)
yield from run_deposit_processing(spec, state, deposit, validator_index)
# unchanged effective balance
assert state.validators[validator_index].effective_balance == initial_effective_balance
@ -150,7 +150,7 @@ def test_top_up__zero_balance(spec, state):
state.balances[validator_index] = initial_balance
state.validators[validator_index].effective_balance = initial_effective_balance
yield from run_deposit_processing_electra(spec, state, deposit, validator_index)
yield from run_deposit_processing(spec, state, deposit, validator_index)
# unchanged effective balance
assert state.validators[validator_index].effective_balance == initial_effective_balance
@ -165,7 +165,7 @@ def test_incorrect_sig_top_up(spec, state):
deposit = prepare_state_and_deposit(spec, state, validator_index, amount)
# invalid signatures, in top-ups, are allowed!
yield from run_deposit_processing_electra(spec, state, deposit, validator_index)
yield from run_deposit_processing(spec, state, deposit, validator_index)
@with_electra_and_later
@ -183,7 +183,7 @@ def test_incorrect_withdrawal_credentials_top_up(spec, state):
)
# inconsistent withdrawal credentials, in top-ups, are allowed!
yield from run_deposit_processing_electra(spec, state, deposit, validator_index)
yield from run_deposit_processing(spec, state, deposit, validator_index)
@with_electra_and_later
@ -224,7 +224,7 @@ def test_invalid_wrong_deposit_for_deposit_count(spec, state):
state.eth1_data.deposit_root = root_2
state.eth1_data.deposit_count = deposit_count_1
yield from run_deposit_processing_electra(spec, state, deposit_2, index_2, valid=False)
yield from run_deposit_processing(spec, state, deposit_2, index_2, valid=False)
@with_electra_and_later
@ -239,7 +239,7 @@ def test_invalid_bad_merkle_proof(spec, state):
sign_deposit_data(spec, deposit.data, privkeys[validator_index])
yield from run_deposit_processing_electra(spec, state, deposit, validator_index, valid=False)
yield from run_deposit_processing(spec, state, deposit, validator_index, valid=False)
@with_electra_and_later
@ -253,7 +253,7 @@ def test_key_validate_invalid_subgroup(spec, state):
deposit = prepare_state_and_deposit(spec, state, validator_index, amount, pubkey=pubkey, signed=True)
yield from run_deposit_processing_electra(spec, state, deposit, validator_index)
yield from run_deposit_processing(spec, state, deposit, validator_index)
@with_electra_and_later
@ -269,14 +269,14 @@ def test_key_validate_invalid_decompression(spec, state):
deposit = prepare_state_and_deposit(spec, state, validator_index, amount, pubkey=pubkey, signed=True)
yield from run_deposit_processing_electra(spec, state, deposit, validator_index)
yield from run_deposit_processing(spec, state, deposit, validator_index)
@with_electra_and_later
@spec_state_test
@always_bls
def test_ineffective_deposit_with_bad_fork_version(spec, state):
yield from run_deposit_processing_electra_with_specific_fork_version(
yield from run_deposit_processing_with_specific_fork_version(
spec,
state,
fork_version=spec.Version('0xAaBbCcDd'),

View File

@ -44,7 +44,7 @@ def test_basic_exit(spec, state):
)
@with_eip7251_and_later
@with_electra_and_later
@spec_state_test
def test_basic_exit_with_compounding_credentials(spec, state):
# move state forward SHARD_COMMITTEE_PERIOD epochs to allow for exit
@ -66,7 +66,7 @@ def test_basic_exit_with_compounding_credentials(spec, state):
)
@with_eip7251_and_later
@with_electra_and_later
@spec_state_test
@with_presets([MINIMAL], "need full partial withdrawal queue")
def test_basic_exit_with_full_partial_withdrawal_queue(spec, state):
@ -243,7 +243,7 @@ def test_basic_partial_withdrawal_request(spec, state):
)
@with_eip7251_and_later
@with_electra_and_later
@spec_state_test
@with_presets([MINIMAL])
def test_basic_partial_withdrawal_request_higher_excess_balance(spec, state):
@ -275,7 +275,7 @@ def test_basic_partial_withdrawal_request_higher_excess_balance(spec, state):
)
@with_eip7251_and_later
@with_electra_and_later
@spec_state_test
@with_presets([MINIMAL])
def test_basic_partial_withdrawal_request_lower_than_excess_balance(spec, state):
@ -308,7 +308,7 @@ def test_basic_partial_withdrawal_request_lower_than_excess_balance(spec, state)
)
@with_eip7251_and_later
@with_electra_and_later
@spec_state_test
@with_presets([MINIMAL])
def test_partial_withdrawal_request_with_pending_withdrawals(spec, state):
@ -347,7 +347,7 @@ def test_partial_withdrawal_request_with_pending_withdrawals(spec, state):
)
@with_eip7251_and_later
@with_electra_and_later
@spec_state_test
@with_presets([MINIMAL])
def test_partial_withdrawal_request_with_pending_withdrawals_and_high_amount(
@ -378,7 +378,7 @@ def test_partial_withdrawal_request_with_pending_withdrawals_and_high_amount(
)
# Set balance so that the validator still has excess balance even with the pending withdrawals
state.balances[validator_index] = spec.MAX_EFFECTIVE_BALANCE_EIP7251
state.balances[validator_index] = spec.MAX_EFFECTIVE_BALANCE_ELECTRA
yield from run_execution_layer_withdraw_request_processing(
spec,
@ -387,7 +387,7 @@ def test_partial_withdrawal_request_with_pending_withdrawals_and_high_amount(
)
@with_eip7251_and_later
@with_electra_and_later
@spec_state_test
@with_presets([MINIMAL])
def test_partial_withdrawal_request_with_high_balance(spec, state):
@ -396,10 +396,10 @@ def test_partial_withdrawal_request_with_high_balance(spec, state):
validator_index = spec.get_active_validator_indices(state, current_epoch)[0]
validator_pubkey = state.validators[validator_index].pubkey
address = b"\x22" * 20
amount = spec.MAX_EFFECTIVE_BALANCE_EIP7251
state.balances[validator_index] = 3 * spec.MAX_EFFECTIVE_BALANCE_EIP7251
amount = spec.MAX_EFFECTIVE_BALANCE_ELECTRA
state.balances[validator_index] = 3 * spec.MAX_EFFECTIVE_BALANCE_ELECTRA
state.validators[validator_index].effective_balance = (
spec.MAX_EFFECTIVE_BALANCE_EIP7251
spec.MAX_EFFECTIVE_BALANCE_ELECTRA
)
set_compounding_withdrawal_credential(spec, state, validator_index, address=address)
@ -424,7 +424,7 @@ def test_partial_withdrawal_request_with_high_balance(spec, state):
assert state.earliest_exit_epoch == exit_epoch
@with_eip7251_and_later
@with_electra_and_later
@spec_state_test
@with_presets([MINIMAL])
def test_partial_withdrawal_request_with_high_amount(spec, state):
@ -457,7 +457,7 @@ def test_partial_withdrawal_request_with_high_amount(spec, state):
)
@with_eip7251_and_later
@with_electra_and_later
@spec_state_test
@with_presets([MINIMAL])
def test_partial_withdrawal_request_with_low_amount(spec, state):
@ -492,7 +492,7 @@ def test_partial_withdrawal_request_with_low_amount(spec, state):
# No-op partial withdrawal tests
@with_eip7251_and_later
@with_electra_and_later
@spec_state_test
@with_presets([MINIMAL], "need full partial withdrawal queue")
def test_partial_withdrawal_queue_full(spec, state):
@ -523,7 +523,7 @@ def test_partial_withdrawal_queue_full(spec, state):
)
@with_eip7251_and_later
@with_electra_and_later
@spec_state_test
def test_no_compounding_credentials(spec, state):
state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH
@ -552,7 +552,7 @@ def test_no_compounding_credentials(spec, state):
)
@with_eip7251_and_later
@with_electra_and_later
@spec_state_test
def test_no_excess_balance(spec, state):
state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH
@ -574,7 +574,7 @@ def test_no_excess_balance(spec, state):
)
@with_eip7251_and_later
@with_electra_and_later
@spec_state_test
def test_pending_withdrawals_consume_all_excess_balance(spec, state):
state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH
@ -604,7 +604,7 @@ def test_pending_withdrawals_consume_all_excess_balance(spec, state):
)
@with_eip7251_and_later
@with_electra_and_later
@spec_state_test
def test_insufficient_effective_balance(spec, state):
state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH
@ -633,7 +633,7 @@ def test_insufficient_effective_balance(spec, state):
)
@with_eip7251_and_later
@with_electra_and_later
@spec_state_test
def test_partial_withdrawal_incorrect_source_address(spec, state):
# move state forward SHARD_COMMITTEE_PERIOD epochs to allow for exit
@ -659,7 +659,7 @@ def test_partial_withdrawal_incorrect_source_address(spec, state):
)
@with_eip7251_and_later
@with_electra_and_later
@spec_state_test
def test_partial_withdrawal_incorrect_withdrawal_credential_prefix(spec, state):
# move state forward SHARD_COMMITTEE_PERIOD epochs to allow for exit
@ -688,7 +688,7 @@ def test_partial_withdrawal_incorrect_withdrawal_credential_prefix(spec, state):
)
@with_eip7251_and_later
@with_electra_and_later
@spec_state_test
def test_partial_withdrawal_on_exit_initiated_validator(spec, state):
# move state forward SHARD_COMMITTEE_PERIOD epochs to allow for exit
@ -714,7 +714,7 @@ def test_partial_withdrawal_on_exit_initiated_validator(spec, state):
)
@with_eip7251_and_later
@with_electra_and_later
@spec_state_test
def test_partial_withdrawal_activation_epoch_less_than_shard_committee_period(
spec, state

View File

@ -1,7 +1,7 @@
from eth2spec.test.helpers.constants import MAINNET
from eth2spec.test.context import (
spec_state_test,
with_eip7251_and_later,
with_electra_and_later,
with_presets,
)
from eth2spec.test.helpers.keys import pubkey_to_privkey
@ -15,7 +15,7 @@ from eth2spec.test.helpers.voluntary_exits import (
# ********************
@with_eip7251_and_later
@with_electra_and_later
@spec_state_test
def test_min_balance_exit(spec, state):
state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH
@ -51,7 +51,7 @@ def test_min_balance_exit(spec, state):
assert state.earliest_exit_epoch == expected_exit_epoch
@with_eip7251_and_later
@with_electra_and_later
@spec_state_test
def test_min_balance_exits_up_to_churn(spec, state):
state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH
@ -104,7 +104,7 @@ def test_min_balance_exits_up_to_churn(spec, state):
assert state.earliest_exit_epoch == expected_exit_epoch
@with_eip7251_and_later
@with_electra_and_later
@spec_state_test
def test_min_balance_exits_above_churn(spec, state):
state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH
@ -156,7 +156,7 @@ def test_min_balance_exits_above_churn(spec, state):
assert state.earliest_exit_epoch == expected_exit_epoch + 1
@with_eip7251_and_later
@with_electra_and_later
@spec_state_test
@with_presets(
[MAINNET],
@ -168,7 +168,7 @@ def test_max_balance_exit(spec, state):
churn_limit = spec.get_activation_exit_churn_limit(state)
validator_index = spec.get_active_validator_indices(state, current_epoch)[0]
# Set validator effective balance to 2048 ETH
to_exit = spec.MAX_EFFECTIVE_BALANCE_EIP7251
to_exit = spec.MAX_EFFECTIVE_BALANCE_ELECTRA
state.validators[validator_index].effective_balance = to_exit
privkey = pubkey_to_privkey[state.validators[validator_index].pubkey]
@ -200,7 +200,7 @@ def test_max_balance_exit(spec, state):
assert state.earliest_exit_epoch == expected_exit_epoch
@with_eip7251_and_later
@with_electra_and_later
@spec_state_test
@with_presets(
[MAINNET],
@ -241,7 +241,7 @@ def test_exit_with_balance_equal_to_churn_limit(spec, state):
assert state.earliest_exit_epoch == expected_exit_epoch
@with_eip7251_and_later
@with_electra_and_later
@spec_state_test
@with_presets(
[MAINNET],
@ -284,7 +284,7 @@ def test_exit_with_balance_multiple_of_churn_limit(spec, state):
assert state.earliest_exit_epoch == expected_exit_epoch
@with_eip7251_and_later
@with_electra_and_later
@spec_state_test
@with_presets(
[MAINNET],
@ -331,7 +331,7 @@ def test_exit_existing_churn_and_churn_limit_balance(spec, state):
assert state.earliest_exit_epoch == expected_exit_epoch
@with_eip7251_and_later
@with_electra_and_later
@spec_state_test
@with_presets(
[MAINNET],
@ -382,7 +382,7 @@ def test_exit_existing_churn_and_balance_multiple_of_churn_limit(spec, state):
assert state.earliest_exit_epoch == expected_exit_epoch
@with_eip7251_and_later
@with_electra_and_later
@spec_state_test
def test_invalid_validator_has_pending_withdrawal(spec, state):
# move state forward SHARD_COMMITTEE_PERIOD epochs to allow for exit

View File

@ -1,10 +1,10 @@
from eth2spec.test.context import spec_state_test, with_eip7251_and_later
from eth2spec.test.context import spec_state_test, with_electra_and_later
from eth2spec.test.phase0.epoch_processing.test_process_effective_balance_updates import (
run_test_effective_balance_hysteresis,
)
@with_eip7251_and_later
@with_electra_and_later
@spec_state_test
def test_effective_balance_hysteresis_with_compounding_credentials(spec, state):
run_test_effective_balance_hysteresis(

View File

@ -39,7 +39,7 @@ def test_basic_pending_consolidation(spec, state):
assert state.pending_consolidations == []
@with_eip7251_and_later
@with_electra_and_later
@spec_state_test
def test_consolidation_not_yet_withdrawable_validator(spec, state):
current_epoch = spec.get_current_epoch(state)
@ -128,7 +128,7 @@ def test_skip_consolidation_when_source_slashed(spec, state):
)
@with_eip7251_and_later
@with_electra_and_later
@spec_state_test
def test_all_consolidation_cases_together(spec, state):
current_epoch = spec.get_current_epoch(state)

View File

@ -1,7 +1,7 @@
from random import Random
from eth2spec.test.context import expect_assertion_error
from eth2spec.test.helpers.forks import is_post_altair, is_post_eip7251
from eth2spec.test.helpers.forks import is_post_altair, is_post_electra
from eth2spec.test.helpers.keys import pubkeys, privkeys
from eth2spec.test.helpers.state import get_balance
from eth2spec.utils import bls
@ -242,7 +242,7 @@ def run_deposit_processing(spec, state, deposit, validator_index, valid=True, ef
pre_balance = get_balance(state, validator_index)
pre_effective_balance = state.validators[validator_index].effective_balance
if is_post_eip7251(spec):
if is_post_electra(spec):
pre_pending_deposits = len(state.pending_balance_deposits)
yield 'pre', state
@ -271,7 +271,7 @@ def run_deposit_processing(spec, state, deposit, validator_index, valid=True, ef
# new validator is added
assert len(state.validators) == pre_validator_count + 1
assert len(state.balances) == pre_validator_count + 1
if not is_post_eip7251(spec):
if not is_post_electra(spec):
if is_top_up:
# Top-ups do not change effective balance
assert state.validators[validator_index].effective_balance == pre_effective_balance
@ -281,7 +281,7 @@ def run_deposit_processing(spec, state, deposit, validator_index, valid=True, ef
assert state.validators[validator_index].effective_balance == effective_balance
assert get_balance(state, validator_index) == pre_balance + deposit.data.amount
else:
# no balance or effective balance changes on deposit processing post eip7251
# no balance or effective balance changes on deposit processing post electra
assert get_balance(state, validator_index) == pre_balance
assert state.validators[validator_index].effective_balance == pre_effective_balance
# new correct balance deposit queued up

View File

@ -7,28 +7,28 @@ from eth2spec.test.helpers.state import get_validator_index_by_pubkey
#
def run_execution_layer_exit_processing(spec, state, execution_layer_exit, valid=True, success=True):
def run_execution_layer_withdrawal_request_processing(spec, state, withdrawal_request, valid=True, success=True):
"""
Run ``process_execution_layer_exit``, yielding:
Run ``process_execution_layer_withdrawal_request``, yielding:
- pre-state ('pre')
- execution_layer_exit ('execution_layer_exit')
- withdrawal_request ('withdrawal_request')
- post-state ('post').
If ``valid == False``, run expecting ``AssertionError``
If ``success == False``, it doesn't initiate exit successfully
"""
validator_index = get_validator_index_by_pubkey(state, execution_layer_exit.validator_pubkey)
validator_index = get_validator_index_by_pubkey(state, withdrawal_request.validator_pubkey)
yield 'pre', state
yield 'execution_layer_exit', execution_layer_exit
yield 'withdrawal_request', withdrawal_request
if not valid:
expect_assertion_error(lambda: spec.process_execution_layer_exit(state, execution_layer_exit))
expect_assertion_error(lambda: spec.process_withdrawal_request(state, withdrawal_request))
yield 'post', None
return
pre_exit_epoch = state.validators[validator_index].exit_epoch
spec.process_execution_layer_exit(state, execution_layer_exit)
spec.process_withdrawal_request(state, withdrawal_request)
yield 'post', state

View File

@ -36,7 +36,7 @@ def get_execution_payload_header(spec, execution_payload):
payload_header.excess_blob_gas = execution_payload.excess_blob_gas
if is_post_electra(spec):
payload_header.deposit_receipts_root = spec.hash_tree_root(execution_payload.deposit_receipts)
payload_header.exits_root = spec.hash_tree_root(execution_payload.exits)
payload_header.withdrawal_requests_root = spec.hash_tree_root(execution_payload.withdrawal_requests)
return payload_header
@ -59,7 +59,7 @@ def compute_el_header_block_hash(spec,
transactions_trie_root,
withdrawals_trie_root=None,
deposit_receipts_trie_root=None,
exits_trie_root=None):
withdrawal_requests_root=None):
"""
Computes the RLP execution block hash described by an `ExecutionPayloadHeader`.
"""
@ -108,8 +108,8 @@ def compute_el_header_block_hash(spec,
# deposit_receipts_root
assert deposit_receipts_trie_root is not None
execution_payload_header_rlp.append((Binary(32, 32), deposit_receipts_trie_root))
# exits_trie_root
execution_payload_header_rlp.append((Binary(32, 32), exits_trie_root))
# withdrawal requests root
execution_payload_header_rlp.append((Binary(32, 32), withdrawal_requests_root))
sedes = List([schema for schema, _ in execution_payload_header_rlp])
values = [value for _, value in execution_payload_header_rlp]
@ -137,16 +137,16 @@ def get_withdrawal_rlp(withdrawal):
# https://eips.ethereum.org/EIPS/eip-7002
def get_exit_rlp(exit):
exit_rlp = [
def get_withdrawal_request_rlp(withdrawal_request):
withdrawal_request_rlp = [
# source_address
(Binary(20, 20), exit.source_address),
(Binary(20, 20), withdrawal_request.source_address),
# validator_pubkey
(Binary(48, 48), exit.validator_pubkey),
(Binary(48, 48), withdrawal_request.validator_pubkey),
]
sedes = List([schema for schema, _ in exit_rlp])
values = [value for _, value in exit_rlp]
sedes = List([schema for schema, _ in withdrawal_request_rlp])
values = [value for _, value in withdrawal_request_rlp]
return encode(values, sedes)
@ -174,7 +174,7 @@ def compute_el_block_hash(spec, payload):
withdrawals_trie_root = None
deposit_receipts_trie_root = None
exits_trie_root = None
withdrawal_requests_root = None
if is_post_capella(spec):
withdrawals_encoded = [get_withdrawal_rlp(withdrawal) for withdrawal in payload.withdrawals]
@ -182,8 +182,8 @@ def compute_el_block_hash(spec, payload):
if is_post_electra(spec):
deposit_receipts_encoded = [get_deposit_receipt_rlp(spec, receipt) for receipt in payload.deposit_receipts]
deposit_receipts_trie_root = compute_trie_root_from_indexed_data(deposit_receipts_encoded)
exits_encoded = [get_exit_rlp(exit) for exit in payload.exits]
exits_trie_root = compute_trie_root_from_indexed_data(exits_encoded)
withdrawal_requests_encoded = [get_withdrawal_request_rlp(request) for request in payload.withdrawal_requests]
withdrawal_requests_root = compute_trie_root_from_indexed_data(withdrawal_requests_encoded)
payload_header = get_execution_payload_header(spec, payload)
@ -193,7 +193,7 @@ def compute_el_block_hash(spec, payload):
transactions_trie_root,
withdrawals_trie_root,
deposit_receipts_trie_root,
exits_trie_root,
withdrawal_requests_root,
)

View File

@ -1,5 +1,5 @@
from eth2spec.test.helpers.block_header import sign_block_header
from eth2spec.test.helpers.forks import is_post_altair, is_post_bellatrix, is_post_eip7251
from eth2spec.test.helpers.forks import is_post_altair, is_post_bellatrix, is_post_electra
from eth2spec.test.helpers.keys import pubkey_to_privkey
from eth2spec.test.helpers.state import get_balance
from eth2spec.test.helpers.sync_committee import (
@ -9,8 +9,8 @@ from eth2spec.test.helpers.sync_committee import (
def get_min_slashing_penalty_quotient(spec):
if is_post_eip7251(spec):
return spec.MIN_SLASHING_PENALTY_QUOTIENT_EIP7251
if is_post_electra(spec):
return spec.MIN_SLASHING_PENALTY_QUOTIENT_ELECTRA
elif is_post_bellatrix(spec):
return spec.MIN_SLASHING_PENALTY_QUOTIENT_BELLATRIX
elif is_post_altair(spec):
@ -20,8 +20,8 @@ def get_min_slashing_penalty_quotient(spec):
def get_whistleblower_reward_quotient(spec):
if is_post_eip7251(spec):
return spec.WHISTLEBLOWER_REWARD_QUOTIENT_EIP7251
if is_post_electra(spec):
return spec.WHISTLEBLOWER_REWARD_QUOTIENT_ELECTRA
else:
return spec.WHISTLEBLOWER_REWARD_QUOTIENT

View File

@ -1,9 +1,9 @@
import random
from eth2spec.test.helpers.forks import is_post_eip7251
from eth2spec.test.helpers.forks import is_post_electra
def get_expected_withdrawals(spec, state):
if is_post_eip7251(spec):
if is_post_electra(spec):
withdrawals, _ = spec.get_expected_withdrawals(state)
return withdrawals
else:

View File

@ -7,7 +7,7 @@ from eth2spec.test.helpers.deposits import (
sign_deposit_data,
)
from eth2spec.test.helpers.keys import privkeys, pubkeys
from eth2spec.test.helpers.forks import is_post_eip7251
from eth2spec.test.helpers.forks import is_post_electra
@with_all_phases
@ -124,7 +124,7 @@ def test_top_up__max_effective_balance(spec, state):
yield from run_deposit_processing(spec, state, deposit, validator_index)
if not is_post_eip7251(spec):
if not is_post_electra(spec):
assert state.balances[validator_index] == spec.MAX_EFFECTIVE_BALANCE + amount
assert state.validators[validator_index].effective_balance == spec.MAX_EFFECTIVE_BALANCE
@ -143,7 +143,7 @@ def test_top_up__less_effective_balance(spec, state):
yield from run_deposit_processing(spec, state, deposit, validator_index)
if not is_post_eip7251(spec):
if not is_post_electra(spec):
assert state.balances[validator_index] == initial_balance + amount
# unchanged effective balance
assert state.validators[validator_index].effective_balance == initial_effective_balance
@ -163,7 +163,7 @@ def test_top_up__zero_balance(spec, state):
yield from run_deposit_processing(spec, state, deposit, validator_index)
if not is_post_eip7251(spec):
if not is_post_electra(spec):
assert state.balances[validator_index] == initial_balance + amount
# unchanged effective balance
assert state.validators[validator_index].effective_balance == initial_effective_balance

View File

@ -3,7 +3,7 @@ from eth2spec.test.helpers.epoch_processing import run_epoch_processing_to
from eth2spec.test.helpers.withdrawals import (
set_compounding_withdrawal_credential,
)
from eth2spec.test.helpers.forks import is_post_eip7251
from eth2spec.test.helpers.forks import is_post_electra
@with_all_phases
@ -13,12 +13,12 @@ def test_effective_balance_hysteresis(spec, state):
def run_test_effective_balance_hysteresis(spec, state, with_compounding_credentials=False):
assert is_post_eip7251(spec) or not with_compounding_credentials
assert is_post_electra(spec) or not with_compounding_credentials
# Prepare state up to the final-updates.
# Then overwrite the balances, we only want to focus to be on the hysteresis based changes.
run_epoch_processing_to(spec, state, 'process_effective_balance_updates')
# Set some edge cases for balances
max = spec.MAX_EFFECTIVE_BALANCE_EIP_7251 if with_compounding_credentials else spec.MIN_ACTIVATION_BALANCE
max = spec.MAX_EFFECTIVE_BALANCE_ELECTRA if with_compounding_credentials else spec.MIN_ACTIVATION_BALANCE
min = spec.config.EJECTION_BALANCE
inc = spec.EFFECTIVE_BALANCE_INCREMENT
div = spec.HYSTERESIS_QUOTIENT

View File

@ -1,6 +1,6 @@
from eth2spec.test.helpers.deposits import mock_deposit
from eth2spec.test.helpers.state import next_epoch, next_slots
from eth2spec.test.helpers.forks import is_post_eip7251
from eth2spec.test.helpers.forks import is_post_electra
from eth2spec.test.helpers.constants import MINIMAL
from eth2spec.test.context import (
spec_test, spec_state_test,
@ -106,7 +106,7 @@ def test_activation_queue_sorting(spec, state):
yield from run_process_registry_updates(spec, state)
if is_post_eip7251(spec):
if is_post_electra(spec):
# NOTE: EIP-7521 changed how activations are gated
# given the prefix setup here, all validators should be activated
activation_epochs = [state.validators[i].activation_epoch for i in range(mock_activations)]
@ -150,7 +150,7 @@ def run_test_activation_queue_efficiency(spec, state):
for i in range(mock_activations):
# NOTE: EIP-7251 changes how activations are gated
# given the prefix setup here, all validators are eligible for activation
if i < churn_limit_0 or is_post_eip7251(spec):
if i < churn_limit_0 or is_post_electra(spec):
assert state.validators[i].activation_epoch < spec.FAR_FUTURE_EPOCH
else:
assert state.validators[i].activation_epoch == spec.FAR_FUTURE_EPOCH
@ -214,7 +214,7 @@ def run_test_ejection_past_churn_limit(spec, state):
yield from run_process_registry_updates(spec, state)
if is_post_eip7251(spec):
if is_post_electra(spec):
per_epoch_churn = spec.get_activation_exit_churn_limit(state)
def map_index_to_exit_epoch(i):
@ -311,7 +311,7 @@ def run_test_activation_queue_activation_and_ejection(spec, state, num_per_statu
assert validator.activation_eligibility_epoch != spec.FAR_FUTURE_EPOCH
# NOTE: activations are gated differently after EIP-7251
# all eligible validators were activated, regardless of churn limit
if not is_post_eip7251(spec):
if not is_post_electra(spec):
assert validator.activation_epoch == spec.FAR_FUTURE_EPOCH
# all ejection balance validators ejected for a future epoch
@ -394,7 +394,7 @@ def test_invalid_large_withdrawable_epoch(spec, state):
state.validators[0].exit_epoch = exit_epoch
state.validators[1].effective_balance = spec.config.EJECTION_BALANCE
if is_post_eip7251(spec):
if is_post_electra(spec):
state.earliest_exit_epoch = exit_epoch
try:

View File

@ -34,7 +34,7 @@ from eth2spec.test.helpers.constants import PHASE0, MINIMAL
from eth2spec.test.helpers.forks import (
is_post_altair,
is_post_bellatrix,
is_post_eip7251,
is_post_electra,
is_post_capella,
)
from eth2spec.test.context import (
@ -744,7 +744,7 @@ def test_deposit_in_block(spec, state):
yield 'blocks', [signed_block]
yield 'post', state
if is_post_eip7251(spec):
if is_post_electra(spec):
balance = state.pending_balance_deposits[0].amount
else:
balance = get_balance(state, validator_index)
@ -815,7 +815,7 @@ def test_deposit_top_up(spec, state):
)
balance = get_balance(state, validator_index)
if is_post_eip7251(spec):
if is_post_electra(spec):
balance += state.pending_balance_deposits[0].amount
assert balance == (