From cc9a5fe61e303da4be1b91219ae6bf6dd7e2a4fe Mon Sep 17 00:00:00 2001 From: terencechain Date: Wed, 17 Aug 2022 06:48:05 -0700 Subject: [PATCH 1/9] EIP4844: fix format --- specs/eip4844/p2p-interface.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/eip4844/p2p-interface.md b/specs/eip4844/p2p-interface.md index 9bd2061277..913bbd752a 100644 --- a/specs/eip4844/p2p-interface.md +++ b/specs/eip4844/p2p-interface.md @@ -104,7 +104,7 @@ The following validations MUST pass before forwarding the `signed_blobs_sidecar` Alias `sidecar = signed_blobs_sidecar.message`. - _[IGNORE]_ the `sidecar.beacon_block_slot` is for the current slot (with a `MAXIMUM_GOSSIP_CLOCK_DISPARITY` allowance) -- i.e. `sidecar.beacon_block_slot == current_slot`. - _[REJECT]_ the `sidecar.blobs` are all well formatted, i.e. the `BLSFieldElement` in valid range (`x < BLS_MODULUS`). -- _[REJECT]_ The KZG proof is a correctly encoded compressed BLS G1 Point -- i.e. `bls.KeyValidate(blobs_sidecar.kzg_aggregated_proof) +- _[REJECT]_ The KZG proof is a correctly encoded compressed BLS G1 Point -- i.e. `bls.KeyValidate(blobs_sidecar.kzg_aggregated_proof)` - _[REJECT]_ the beacon proposer signature, `signed_blobs_sidecar.signature`, is valid -- i.e. - Let `domain = get_domain(state, DOMAIN_BLOBS_SIDECAR, sidecar.beacon_block_slot // SLOTS_PER_EPOCH)` - Let `signing_root = compute_signing_root(sidecar, domain)` From cadb94aaaf380b9b68818f083de54322ffe6dfab Mon Sep 17 00:00:00 2001 From: 0xYYY <0xYYY@protonmail.com> Date: Wed, 17 Aug 2022 22:46:47 +0800 Subject: [PATCH 2/9] Update Bellatrix fork epoch in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 56267c0dbd..f3647eee04 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Features are researched and developed in parallel, and then consolidated into se | - | - | - | - | | 0 | **Phase0** |`0` | | | 1 | **Altair** | `74240` | | -| 2 | **Bellatrix**
(["The Merge"](https://ethereum.org/en/upgrades/merge/)) | TBD | | +| 2 | **Bellatrix**
(["The Merge"](https://ethereum.org/en/upgrades/merge/)) | `144896` | | ### In-development Specifications | Code Name or Topic | Specs | Notes | From d133dae4713585c6d61b932b44edff888838ec73 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Thu, 18 Aug 2022 22:08:44 +0800 Subject: [PATCH 3/9] Fix codespell errors (#2975) --- presets/minimal/phase0.yaml | 4 ++-- specs/phase0/p2p-interface.md | 2 +- tests/generators/random/generate.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/presets/minimal/phase0.yaml b/presets/minimal/phase0.yaml index c9c81325f1..2c6fbb3691 100644 --- a/presets/minimal/phase0.yaml +++ b/presets/minimal/phase0.yaml @@ -4,11 +4,11 @@ # --------------------------------------------------------------- # [customized] Just 4 committees for slot for testing purposes MAX_COMMITTEES_PER_SLOT: 4 -# [customized] unsecure, but fast +# [customized] insecure, but fast TARGET_COMMITTEE_SIZE: 4 # 2**11 (= 2,048) MAX_VALIDATORS_PER_COMMITTEE: 2048 -# [customized] Faster, but unsecure. +# [customized] Faster, but insecure. SHUFFLE_ROUND_COUNT: 10 # 4 HYSTERESIS_QUOTIENT: 4 diff --git a/specs/phase0/p2p-interface.md b/specs/phase0/p2p-interface.md index 34b0375e06..6277bee9fc 100644 --- a/specs/phase0/p2p-interface.md +++ b/specs/phase0/p2p-interface.md @@ -1327,7 +1327,7 @@ Requests are segregated by protocol ID to: 1. This has the benefit that clients can explicitly choose which RFCs to deploy without buying into all other RFCs that may be included in that top-level version. 2. Affording this level of granularity with a top-level protocol would imply creating as many variants - (e.g. /protocol/43-{a,b,c,d,...}) as the cartesian product of RFCs inflight, O(n^2). + (e.g. /protocol/43-{a,b,c,d,...}) as the cartesian product of RFCs in-flight, O(n^2). 7. Allow us to simplify the payload of requests. Request-id’s and method-ids no longer need to be sent. The encoding/request type and version can all be handled by the framework. diff --git a/tests/generators/random/generate.py b/tests/generators/random/generate.py index f96f05a754..f71595c02e 100644 --- a/tests/generators/random/generate.py +++ b/tests/generators/random/generate.py @@ -3,7 +3,7 @@ as the current test infra does not have a facility to dynamically generate tests that can be seen by ``pytest``. -This will likley change in future releases of the testing infra. +This will likely change in future releases of the testing infra. NOTE: To add additional scenarios, add test cases below in ``_generate_randomized_scenarios``. """ From b3ef9b2b3e8cc8dd6ff6a031113620a4c16f3608 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Thu, 18 Aug 2022 17:49:40 +0800 Subject: [PATCH 4/9] Add invalid fork version tests --- .../block_processing/test_process_deposit.py | 85 +++++++++++++++++++ .../test_process_voluntary_exit.py | 71 ++++++++++++++++ .../pyspec/eth2spec/test/helpers/deposits.py | 60 ++++++++++++- .../eth2spec/test/helpers/voluntary_exits.py | 49 ++++++++++- .../block_processing/test_process_deposit.py | 56 +----------- .../test_process_voluntary_exit.py | 35 ++------ 6 files changed, 269 insertions(+), 87 deletions(-) create mode 100644 tests/core/pyspec/eth2spec/test/bellatrix/block_processing/test_process_deposit.py create mode 100644 tests/core/pyspec/eth2spec/test/bellatrix/block_processing/test_process_voluntary_exit.py diff --git a/tests/core/pyspec/eth2spec/test/bellatrix/block_processing/test_process_deposit.py b/tests/core/pyspec/eth2spec/test/bellatrix/block_processing/test_process_deposit.py new file mode 100644 index 0000000000..c9ce186c52 --- /dev/null +++ b/tests/core/pyspec/eth2spec/test/bellatrix/block_processing/test_process_deposit.py @@ -0,0 +1,85 @@ +from eth2spec.test.context import ( + spec_state_test, + always_bls, + with_bellatrix_and_later, +) +from eth2spec.test.helpers.deposits import ( + deposit_from_context, + run_deposit_processing, +) +from eth2spec.test.helpers.keys import ( + privkeys, + pubkeys, +) +from eth2spec.utils import bls + + +def _run_deposit_processing_with_specific_fork_version( + spec, + state, + fork_version, + valid, + effective): + validator_index = len(state.validators) + amount = spec.MAX_EFFECTIVE_BALANCE + + pubkey = pubkeys[validator_index] + privkey = privkeys[validator_index] + withdrawal_credentials = spec.BLS_WITHDRAWAL_PREFIX + spec.hash(pubkey)[1:] + + deposit_message = spec.DepositMessage(pubkey=pubkey, withdrawal_credentials=withdrawal_credentials, amount=amount) + domain = spec.compute_domain(domain_type=spec.DOMAIN_DEPOSIT, fork_version=fork_version) + deposit_data = spec.DepositData( + pubkey=pubkey, withdrawal_credentials=withdrawal_credentials, amount=amount, + signature=bls.Sign(privkey, spec.compute_signing_root(deposit_message, domain)) + ) + deposit, root, _ = deposit_from_context(spec, [deposit_data], 0) + + state.eth1_deposit_index = 0 + state.eth1_data.deposit_root = root + state.eth1_data.deposit_count = 1 + + yield from run_deposit_processing(spec, state, deposit, validator_index, valid=valid, effective=effective) + + +@with_bellatrix_and_later +@spec_state_test +@always_bls +def test_deposit_with_previous_fork_version__valid_effective(spec, state): + assert state.fork.previous_version != state.fork.current_version + + yield from _run_deposit_processing_with_specific_fork_version( + spec, + state, + fork_version=state.fork.previous_version, + valid=True, + effective=False, + ) + + +@with_bellatrix_and_later +@spec_state_test +@always_bls +def test_deposit_with_genesis_fork_version__valid_ineffective(spec, state): + assert spec.config.GENESIS_FORK_VERSION not in (state.fork.previous_version, state.fork.current_version) + + yield from _run_deposit_processing_with_specific_fork_version( + spec, + state, + fork_version=spec.config.GENESIS_FORK_VERSION, + valid=True, + effective=True, + ) + + +@with_bellatrix_and_later +@spec_state_test +@always_bls +def test_deposit_with_bad_fork_version__valid_ineffective(spec, state): + yield from _run_deposit_processing_with_specific_fork_version( + spec, + state, + fork_version=spec.Version('0xAaBbCcDd'), + valid=True, + effective=False, + ) diff --git a/tests/core/pyspec/eth2spec/test/bellatrix/block_processing/test_process_voluntary_exit.py b/tests/core/pyspec/eth2spec/test/bellatrix/block_processing/test_process_voluntary_exit.py new file mode 100644 index 0000000000..efc4faf03c --- /dev/null +++ b/tests/core/pyspec/eth2spec/test/bellatrix/block_processing/test_process_voluntary_exit.py @@ -0,0 +1,71 @@ +from eth2spec.test.context import ( + spec_state_test, + always_bls, + with_bellatrix_and_later, +) +from eth2spec.test.helpers.keys import pubkey_to_privkey +from eth2spec.test.helpers.state import ( + next_epoch, +) +from eth2spec.test.helpers.voluntary_exits import ( + run_voluntary_exit_processing, + sign_voluntary_exit, +) + + +def _run_voluntary_exit_processing_with_specific_fork_version( + spec, + state, + fork_version, + valid): + next_epoch(spec, state) + state.fork.epoch = spec.get_current_epoch(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=0, + validator_index=validator_index, + ) + signed_voluntary_exit = sign_voluntary_exit( + spec, + state, + voluntary_exit, + privkey, + fork_version=fork_version, + ) + + yield from run_voluntary_exit_processing(spec, state, signed_voluntary_exit, valid=valid) + + +@with_bellatrix_and_later +@spec_state_test +@always_bls +def test_voluntary_exit_with_previous_fork_version__valid(spec, state): + assert state.fork.previous_version != state.fork.current_version + + yield from _run_voluntary_exit_processing_with_specific_fork_version( + spec, + state, + fork_version=state.fork.previous_version, + valid=True, + ) + + +@with_bellatrix_and_later +@spec_state_test +@always_bls +def test_voluntary_exit_with_genesis_fork_version__invalid(spec, state): + assert spec.config.GENESIS_FORK_VERSION not in (state.fork.previous_version, state.fork.current_version) + + yield from _run_voluntary_exit_processing_with_specific_fork_version( + spec, + state, + fork_version=spec.config.GENESIS_FORK_VERSION, + valid=False, + ) diff --git a/tests/core/pyspec/eth2spec/test/helpers/deposits.py b/tests/core/pyspec/eth2spec/test/helpers/deposits.py index 4e26215228..dae05c2ebe 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/deposits.py +++ b/tests/core/pyspec/eth2spec/test/helpers/deposits.py @@ -1,7 +1,11 @@ from random import Random -from eth2spec.test.context import is_post_altair +from eth2spec.test.context import ( + is_post_altair, + expect_assertion_error, +) from eth2spec.test.helpers.keys import pubkeys, privkeys +from eth2spec.test.helpers.state import get_balance from eth2spec.utils import bls from eth2spec.utils.merkle_minimal import calc_merkle_tree_from_leaves, get_merkle_proof from eth2spec.utils.ssz.ssz_impl import hash_tree_root @@ -160,3 +164,57 @@ def prepare_state_and_deposit(spec, state, validator_index, amount, withdrawal_c state.eth1_data.deposit_root = root state.eth1_data.deposit_count = len(deposit_data_list) return deposit + + +# +# Run processing +# + + +def run_deposit_processing(spec, state, deposit, validator_index, valid=True, effective=True): + """ + Run ``process_deposit``, yielding: + - pre-state ('pre') + - deposit ('deposit') + - post-state ('post'). + If ``valid == False``, run expecting ``AssertionError`` + """ + pre_validator_count = len(state.validators) + pre_balance = 0 + if validator_index < pre_validator_count: + pre_balance = get_balance(state, validator_index) + + yield 'pre', state + yield 'deposit', deposit + + if not valid: + expect_assertion_error(lambda: spec.process_deposit(state, deposit)) + yield 'post', None + return + + spec.process_deposit(state, deposit) + + yield 'post', state + + if not effective: + assert len(state.validators) == pre_validator_count + assert len(state.balances) == pre_validator_count + if validator_index < pre_validator_count: + assert get_balance(state, validator_index) == pre_balance + else: + if validator_index < pre_validator_count: + # top-up + assert len(state.validators) == pre_validator_count + assert len(state.balances) == pre_validator_count + else: + # new validator + assert len(state.validators) == pre_validator_count + 1 + assert len(state.balances) == pre_validator_count + 1 + assert get_balance(state, validator_index) == pre_balance + deposit.data.amount + + effective = min(spec.MAX_EFFECTIVE_BALANCE, + pre_balance + deposit.data.amount) + effective -= effective % spec.EFFECTIVE_BALANCE_INCREMENT + assert state.validators[validator_index].effective_balance == effective + + assert state.eth1_deposit_index == state.eth1_data.deposit_count diff --git a/tests/core/pyspec/eth2spec/test/helpers/voluntary_exits.py b/tests/core/pyspec/eth2spec/test/helpers/voluntary_exits.py index 55ea0b5b0f..cac101dff1 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/voluntary_exits.py +++ b/tests/core/pyspec/eth2spec/test/helpers/voluntary_exits.py @@ -1,10 +1,14 @@ from random import Random from eth2spec.utils import bls +from eth2spec.test.context import expect_assertion_error from eth2spec.test.helpers.keys import privkeys -def prepare_signed_exits(spec, state, indices): - domain = spec.get_domain(state, spec.DOMAIN_VOLUNTARY_EXIT) +def prepare_signed_exits(spec, state, indices, fork_version=None): + if fork_version is None: + domain = spec.get_domain(state, spec.DOMAIN_VOLUNTARY_EXIT) + else: + domain = spec.compute_domain(spec.DOMAIN_VOLUNTARY_EXIT, fork_version, state.genesis_validators_root) def create_signed_exit(index): exit = spec.VoluntaryExit( @@ -17,8 +21,12 @@ def create_signed_exit(index): return [create_signed_exit(index) for index in indices] -def sign_voluntary_exit(spec, state, voluntary_exit, privkey): - domain = spec.get_domain(state, spec.DOMAIN_VOLUNTARY_EXIT, voluntary_exit.epoch) +def sign_voluntary_exit(spec, state, voluntary_exit, privkey, fork_version=None): + if fork_version is None: + domain = spec.get_domain(state, spec.DOMAIN_VOLUNTARY_EXIT, voluntary_exit.epoch) + else: + domain = spec.compute_domain(spec.DOMAIN_VOLUNTARY_EXIT, fork_version, state.genesis_validators_root) + signing_root = spec.compute_signing_root(voluntary_exit, domain) return spec.SignedVoluntaryExit( message=voluntary_exit, @@ -49,3 +57,36 @@ def exit_validators(spec, state, validator_count, rng=None): for index in indices: spec.initiate_validator_exit(state, index) return indices + + +# +# Run processing +# + + +def run_voluntary_exit_processing(spec, state, signed_voluntary_exit, valid=True): + """ + Run ``process_voluntary_exit``, yielding: + - pre-state ('pre') + - voluntary_exit ('voluntary_exit') + - post-state ('post'). + If ``valid == False``, run expecting ``AssertionError`` + """ + validator_index = signed_voluntary_exit.message.validator_index + + yield 'pre', state + yield 'voluntary_exit', signed_voluntary_exit + + if not valid: + expect_assertion_error(lambda: spec.process_voluntary_exit(state, signed_voluntary_exit)) + yield 'post', None + return + + pre_exit_epoch = state.validators[validator_index].exit_epoch + + spec.process_voluntary_exit(state, signed_voluntary_exit) + + yield 'post', state + + assert pre_exit_epoch == spec.FAR_FUTURE_EPOCH + assert state.validators[validator_index].exit_epoch < spec.FAR_FUTURE_EPOCH diff --git a/tests/core/pyspec/eth2spec/test/phase0/block_processing/test_process_deposit.py b/tests/core/pyspec/eth2spec/test/phase0/block_processing/test_process_deposit.py index 36e76f46c8..df0bd2a17c 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/block_processing/test_process_deposit.py +++ b/tests/core/pyspec/eth2spec/test/phase0/block_processing/test_process_deposit.py @@ -1,63 +1,15 @@ -from eth2spec.test.context import spec_state_test, expect_assertion_error, always_bls, with_all_phases +from eth2spec.test.context import spec_state_test, always_bls, with_all_phases from eth2spec.test.helpers.deposits import ( build_deposit, + deposit_from_context, prepare_state_and_deposit, + run_deposit_processing, sign_deposit_data, - deposit_from_context) -from eth2spec.test.helpers.state import get_balance +) from eth2spec.test.helpers.keys import privkeys, pubkeys from eth2spec.utils import bls -def run_deposit_processing(spec, state, deposit, validator_index, valid=True, effective=True): - """ - Run ``process_deposit``, yielding: - - pre-state ('pre') - - deposit ('deposit') - - post-state ('post'). - If ``valid == False``, run expecting ``AssertionError`` - """ - pre_validator_count = len(state.validators) - pre_balance = 0 - if validator_index < pre_validator_count: - pre_balance = get_balance(state, validator_index) - - yield 'pre', state - yield 'deposit', deposit - - if not valid: - expect_assertion_error(lambda: spec.process_deposit(state, deposit)) - yield 'post', None - return - - spec.process_deposit(state, deposit) - - yield 'post', state - - if not effective: - assert len(state.validators) == pre_validator_count - assert len(state.balances) == pre_validator_count - if validator_index < pre_validator_count: - assert get_balance(state, validator_index) == pre_balance - else: - if validator_index < pre_validator_count: - # top-up - assert len(state.validators) == pre_validator_count - assert len(state.balances) == pre_validator_count - else: - # new validator - assert len(state.validators) == pre_validator_count + 1 - assert len(state.balances) == pre_validator_count + 1 - assert get_balance(state, validator_index) == pre_balance + deposit.data.amount - - effective = min(spec.MAX_EFFECTIVE_BALANCE, - pre_balance + deposit.data.amount) - effective -= effective % spec.EFFECTIVE_BALANCE_INCREMENT - assert state.validators[validator_index].effective_balance == effective - - assert state.eth1_deposit_index == state.eth1_data.deposit_count - - @with_all_phases @spec_state_test def test_new_deposit_under_max(spec, state): diff --git a/tests/core/pyspec/eth2spec/test/phase0/block_processing/test_process_voluntary_exit.py b/tests/core/pyspec/eth2spec/test/phase0/block_processing/test_process_voluntary_exit.py index 9e209f23e2..73602f14c3 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/block_processing/test_process_voluntary_exit.py +++ b/tests/core/pyspec/eth2spec/test/phase0/block_processing/test_process_voluntary_exit.py @@ -1,40 +1,15 @@ from eth2spec.test.helpers.constants import MINIMAL from eth2spec.test.context import ( - spec_state_test, expect_assertion_error, + spec_state_test, always_bls, with_all_phases, with_presets, spec_test, single_phase, with_custom_state, scaled_churn_balances, ) from eth2spec.test.helpers.keys import pubkey_to_privkey -from eth2spec.test.helpers.voluntary_exits import sign_voluntary_exit - - -def run_voluntary_exit_processing(spec, state, signed_voluntary_exit, valid=True): - """ - Run ``process_voluntary_exit``, yielding: - - pre-state ('pre') - - voluntary_exit ('voluntary_exit') - - post-state ('post'). - If ``valid == False``, run expecting ``AssertionError`` - """ - validator_index = signed_voluntary_exit.message.validator_index - - yield 'pre', state - yield 'voluntary_exit', signed_voluntary_exit - - if not valid: - expect_assertion_error(lambda: spec.process_voluntary_exit(state, signed_voluntary_exit)) - yield 'post', None - return - - pre_exit_epoch = state.validators[validator_index].exit_epoch - - spec.process_voluntary_exit(state, signed_voluntary_exit) - - yield 'post', state - - assert pre_exit_epoch == spec.FAR_FUTURE_EPOCH - assert state.validators[validator_index].exit_epoch < spec.FAR_FUTURE_EPOCH +from eth2spec.test.helpers.voluntary_exits import ( + run_voluntary_exit_processing, + sign_voluntary_exit, +) @with_all_phases From 806a6ad414fac594f3ecae095f9092732ea35612 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Fri, 19 Aug 2022 00:03:58 +0800 Subject: [PATCH 5/9] Apply suggestions from code review Co-authored-by: Danny Ryan --- .../test/bellatrix/block_processing/test_process_deposit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/core/pyspec/eth2spec/test/bellatrix/block_processing/test_process_deposit.py b/tests/core/pyspec/eth2spec/test/bellatrix/block_processing/test_process_deposit.py index c9ce186c52..eb975130c3 100644 --- a/tests/core/pyspec/eth2spec/test/bellatrix/block_processing/test_process_deposit.py +++ b/tests/core/pyspec/eth2spec/test/bellatrix/block_processing/test_process_deposit.py @@ -60,7 +60,7 @@ def test_deposit_with_previous_fork_version__valid_effective(spec, state): @with_bellatrix_and_later @spec_state_test @always_bls -def test_deposit_with_genesis_fork_version__valid_ineffective(spec, state): +def test_deposit_with_genesis_fork_version__valid_effective(spec, state): assert spec.config.GENESIS_FORK_VERSION not in (state.fork.previous_version, state.fork.current_version) yield from _run_deposit_processing_with_specific_fork_version( From 6c00b48dca454d1e327b1b81ae7c9493cacb8e60 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Fri, 19 Aug 2022 00:29:20 +0800 Subject: [PATCH 6/9] PR feedback from @djrtwo: add `is_before_fork_epoch` and more param combinations --- .../test_process_voluntary_exit.py | 74 +++++++++++++++++-- 1 file changed, 68 insertions(+), 6 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/bellatrix/block_processing/test_process_voluntary_exit.py b/tests/core/pyspec/eth2spec/test/bellatrix/block_processing/test_process_voluntary_exit.py index efc4faf03c..257247b162 100644 --- a/tests/core/pyspec/eth2spec/test/bellatrix/block_processing/test_process_voluntary_exit.py +++ b/tests/core/pyspec/eth2spec/test/bellatrix/block_processing/test_process_voluntary_exit.py @@ -13,14 +13,18 @@ ) -def _run_voluntary_exit_processing_with_specific_fork_version( +def _run_voluntary_exit_processing_test( spec, state, fork_version, + is_before_fork_epoch, valid): + # create a fork next_epoch(spec, state) state.fork.epoch = spec.get_current_epoch(state) + voluntary_exit_epoch = 0 if is_before_fork_epoch else state.fork.epoch + # move state forward SHARD_COMMITTEE_PERIOD epochs to allow for exit state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH @@ -29,7 +33,7 @@ def _run_voluntary_exit_processing_with_specific_fork_version( privkey = pubkey_to_privkey[state.validators[validator_index].pubkey] voluntary_exit = spec.VoluntaryExit( - epoch=0, + epoch=voluntary_exit_epoch, validator_index=validator_index, ) signed_voluntary_exit = sign_voluntary_exit( @@ -46,13 +50,40 @@ def _run_voluntary_exit_processing_with_specific_fork_version( @with_bellatrix_and_later @spec_state_test @always_bls -def test_voluntary_exit_with_previous_fork_version__valid(spec, state): +def test_voluntary_exit_with_current_fork_version_is_before_fork_epoch__invalid(spec, state): + yield from _run_voluntary_exit_processing_test( + spec, + state, + fork_version=state.fork.current_version, + is_before_fork_epoch=True, + valid=False, + ) + + +@with_bellatrix_and_later +@spec_state_test +@always_bls +def test_voluntary_exit_with_current_fork_version_not_is_before_fork_epoch__valid(spec, state): + yield from _run_voluntary_exit_processing_test( + spec, + state, + fork_version=state.fork.current_version, + is_before_fork_epoch=False, + valid=True, + ) + + +@with_bellatrix_and_later +@spec_state_test +@always_bls +def test_voluntary_exit_with_previous_fork_version_is_before_fork_epoch__valid(spec, state): assert state.fork.previous_version != state.fork.current_version - yield from _run_voluntary_exit_processing_with_specific_fork_version( + yield from _run_voluntary_exit_processing_test( spec, state, fork_version=state.fork.previous_version, + is_before_fork_epoch=True, valid=True, ) @@ -60,12 +91,43 @@ def test_voluntary_exit_with_previous_fork_version__valid(spec, state): @with_bellatrix_and_later @spec_state_test @always_bls -def test_voluntary_exit_with_genesis_fork_version__invalid(spec, state): +def test_voluntary_exit_with_previous_fork_version_not_is_before_fork_epoch__invalid(spec, state): + assert state.fork.previous_version != state.fork.current_version + + yield from _run_voluntary_exit_processing_test( + spec, + state, + fork_version=state.fork.previous_version, + is_before_fork_epoch=False, + valid=False, + ) + + +@with_bellatrix_and_later +@spec_state_test +@always_bls +def test_voluntary_exit_with_genesis_fork_version_is_before_fork_epoch__invalid(spec, state): + assert spec.config.GENESIS_FORK_VERSION not in (state.fork.previous_version, state.fork.current_version) + + yield from _run_voluntary_exit_processing_test( + spec, + state, + fork_version=spec.config.GENESIS_FORK_VERSION, + is_before_fork_epoch=True, + valid=False, + ) + + +@with_bellatrix_and_later +@spec_state_test +@always_bls +def test_voluntary_exit_with_genesis_fork_version_not_is_before_fork_epoch__invalid(spec, state): assert spec.config.GENESIS_FORK_VERSION not in (state.fork.previous_version, state.fork.current_version) - yield from _run_voluntary_exit_processing_with_specific_fork_version( + yield from _run_voluntary_exit_processing_test( spec, state, fork_version=spec.config.GENESIS_FORK_VERSION, + is_before_fork_epoch=False, valid=False, ) From bafb5870c11480a90203ea6b3421ab1e20ec6dd1 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Fri, 19 Aug 2022 01:20:53 +0800 Subject: [PATCH 7/9] Update tests/core/pyspec/eth2spec/test/bellatrix/block_processing/test_process_deposit.py Co-authored-by: Danny Ryan --- .../test/bellatrix/block_processing/test_process_deposit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/core/pyspec/eth2spec/test/bellatrix/block_processing/test_process_deposit.py b/tests/core/pyspec/eth2spec/test/bellatrix/block_processing/test_process_deposit.py index eb975130c3..b111fd9ffb 100644 --- a/tests/core/pyspec/eth2spec/test/bellatrix/block_processing/test_process_deposit.py +++ b/tests/core/pyspec/eth2spec/test/bellatrix/block_processing/test_process_deposit.py @@ -45,7 +45,7 @@ def _run_deposit_processing_with_specific_fork_version( @with_bellatrix_and_later @spec_state_test @always_bls -def test_deposit_with_previous_fork_version__valid_effective(spec, state): +def test_deposit_with_previous_fork_version__valid_ineffective(spec, state): assert state.fork.previous_version != state.fork.current_version yield from _run_deposit_processing_with_specific_fork_version( From efc4d45bbc4d1a89ce5020016fe1d2fb828a4fe3 Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Thu, 18 Aug 2022 11:35:39 -0600 Subject: [PATCH 8/9] bump VERSION.txt --- tests/core/pyspec/eth2spec/VERSION.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/core/pyspec/eth2spec/VERSION.txt b/tests/core/pyspec/eth2spec/VERSION.txt index e11954015f..3289940692 100644 --- a/tests/core/pyspec/eth2spec/VERSION.txt +++ b/tests/core/pyspec/eth2spec/VERSION.txt @@ -1 +1 @@ -1.2.0-rc.2 \ No newline at end of file +1.2.0-rc.3 \ No newline at end of file From 5db5b87e5ebf960c771d651323a47afed8226e7c Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Fri, 19 Aug 2022 01:52:34 +0800 Subject: [PATCH 9/9] Add bellatrix deposit and voluntary_exit tests --- tests/generators/operations/main.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/generators/operations/main.py b/tests/generators/operations/main.py index 37e7cf0947..2a634cd5b1 100644 --- a/tests/generators/operations/main.py +++ b/tests/generators/operations/main.py @@ -18,7 +18,9 @@ altair_mods = combine_mods(_new_altair_mods, phase_0_mods) _new_bellatrix_mods = {key: 'eth2spec.test.bellatrix.block_processing.test_process_' + key for key in [ + 'deposit', 'execution_payload', + 'voluntary_exit', ]} bellatrix_mods = combine_mods(_new_bellatrix_mods, altair_mods)