From 3c7544af3d90dacd22166e6f0255c8710adc2a35 Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Fri, 6 May 2022 13:56:40 -0500 Subject: [PATCH 1/7] Add invalid large withdrawable epoch test --- .../test_process_registry_updates.py | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_registry_updates.py b/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_registry_updates.py index 6539dc92d..2aff866c2 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_registry_updates.py +++ b/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_registry_updates.py @@ -1,3 +1,5 @@ +import pytest + from eth2spec.test.helpers.deposits import mock_deposit from eth2spec.test.helpers.state import next_epoch, next_slots from eth2spec.test.helpers.constants import MINIMAL @@ -342,3 +344,27 @@ def test_activation_queue_activation_and_ejection__exceed_scaled_churn_limit(spe churn_limit = spec.get_validator_churn_limit(state) assert churn_limit > spec.config.MIN_PER_EPOCH_CHURN_LIMIT yield from run_test_activation_queue_activation_and_ejection(spec, state, churn_limit * 2) + + +@with_all_phases +@spec_state_test +def test_invalid_large_withdrawable_epoch(spec, state): + """ + This test forces a validator into a withdrawable epoch that overflows the + epoch (uint64) type. To do this we need two validators, one validator that + already has an exit epoch and another with a low effective balance. When + calculating the withdrawable epoch for the second validator, it will + use the greatest exit epoch of all of the validators. If the first + validator is given an exit epoch between + (FAR_FUTURE_EPOCH-MIN_VALIDATOR_WITHDRAWABILITY_DELAY+1) and + (FAR_FUTURE_EPOCH-1), it will cause an overflow. + """ + assert spec.is_active_validator(state.validators[0], spec.get_current_epoch(state)) + assert spec.is_active_validator(state.validators[1], spec.get_current_epoch(state)) + + state.validators[0].exit_epoch = spec.FAR_FUTURE_EPOCH - 1 + state.validators[1].effective_balance = spec.config.EJECTION_BALANCE + + with pytest.raises(ValueError): + yield from run_process_registry_updates(spec, state) + yield 'post', None From e2cbdb2b672e1b7a74a94e60e3218c7b79743e88 Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Mon, 9 May 2022 16:47:19 -0500 Subject: [PATCH 2/7] Move test case to new location --- .../test_process_registry_updates.py | 26 ------------------ .../test/phase0/helper_functions/test_misc.py | 27 +++++++++++++++++++ 2 files changed, 27 insertions(+), 26 deletions(-) create mode 100644 tests/core/pyspec/eth2spec/test/phase0/helper_functions/test_misc.py diff --git a/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_registry_updates.py b/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_registry_updates.py index 2aff866c2..6539dc92d 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_registry_updates.py +++ b/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_registry_updates.py @@ -1,5 +1,3 @@ -import pytest - from eth2spec.test.helpers.deposits import mock_deposit from eth2spec.test.helpers.state import next_epoch, next_slots from eth2spec.test.helpers.constants import MINIMAL @@ -344,27 +342,3 @@ def test_activation_queue_activation_and_ejection__exceed_scaled_churn_limit(spe churn_limit = spec.get_validator_churn_limit(state) assert churn_limit > spec.config.MIN_PER_EPOCH_CHURN_LIMIT yield from run_test_activation_queue_activation_and_ejection(spec, state, churn_limit * 2) - - -@with_all_phases -@spec_state_test -def test_invalid_large_withdrawable_epoch(spec, state): - """ - This test forces a validator into a withdrawable epoch that overflows the - epoch (uint64) type. To do this we need two validators, one validator that - already has an exit epoch and another with a low effective balance. When - calculating the withdrawable epoch for the second validator, it will - use the greatest exit epoch of all of the validators. If the first - validator is given an exit epoch between - (FAR_FUTURE_EPOCH-MIN_VALIDATOR_WITHDRAWABILITY_DELAY+1) and - (FAR_FUTURE_EPOCH-1), it will cause an overflow. - """ - assert spec.is_active_validator(state.validators[0], spec.get_current_epoch(state)) - assert spec.is_active_validator(state.validators[1], spec.get_current_epoch(state)) - - state.validators[0].exit_epoch = spec.FAR_FUTURE_EPOCH - 1 - state.validators[1].effective_balance = spec.config.EJECTION_BALANCE - - with pytest.raises(ValueError): - yield from run_process_registry_updates(spec, state) - yield 'post', None diff --git a/tests/core/pyspec/eth2spec/test/phase0/helper_functions/test_misc.py b/tests/core/pyspec/eth2spec/test/phase0/helper_functions/test_misc.py new file mode 100644 index 000000000..7fdc57e91 --- /dev/null +++ b/tests/core/pyspec/eth2spec/test/phase0/helper_functions/test_misc.py @@ -0,0 +1,27 @@ +import pytest + +from eth2spec.test.context import spec_state_test, with_all_phases + +@with_all_phases +@spec_state_test +def test_invalid_large_withdrawable_epoch(spec, state): + """ + This test forces a validator into a withdrawable epoch that overflows the + epoch (uint64) type. To do this we need two validators, one validator that + already has an exit epoch and another with a low effective balance. When + calculating the withdrawable epoch for the second validator, it will + use the greatest exit epoch of all of the validators. If the first + validator is given an exit epoch between + (FAR_FUTURE_EPOCH-MIN_VALIDATOR_WITHDRAWABILITY_DELAY+1) and + (FAR_FUTURE_EPOCH-1), it will cause an overflow. + """ + assert spec.is_active_validator(state.validators[0], spec.get_current_epoch(state)) + assert spec.is_active_validator(state.validators[1], spec.get_current_epoch(state)) + + state.validators[0].exit_epoch = spec.FAR_FUTURE_EPOCH - 1 + state.validators[1].effective_balance = spec.config.EJECTION_BALANCE + + yield 'pre', state + with pytest.raises(ValueError): + spec.initiate_validator_exit(state, 1) + yield 'post', None From ac7267c93873cca968aa7b6811fb53fb8b0407e9 Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Mon, 9 May 2022 16:50:43 -0500 Subject: [PATCH 3/7] Fix linter warnings again --- .../pyspec/eth2spec/test/phase0/helper_functions/test_misc.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/core/pyspec/eth2spec/test/phase0/helper_functions/test_misc.py b/tests/core/pyspec/eth2spec/test/phase0/helper_functions/test_misc.py index 7fdc57e91..88d7478f5 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/helper_functions/test_misc.py +++ b/tests/core/pyspec/eth2spec/test/phase0/helper_functions/test_misc.py @@ -2,6 +2,7 @@ import pytest from eth2spec.test.context import spec_state_test, with_all_phases + @with_all_phases @spec_state_test def test_invalid_large_withdrawable_epoch(spec, state): From 5868a53cf19e6520260cbeef85b8248791937ea8 Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Tue, 10 May 2022 10:48:51 -0500 Subject: [PATCH 4/7] Revert "Fix linter warnings again" This reverts commit ac7267c93873cca968aa7b6811fb53fb8b0407e9. --- .../pyspec/eth2spec/test/phase0/helper_functions/test_misc.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/core/pyspec/eth2spec/test/phase0/helper_functions/test_misc.py b/tests/core/pyspec/eth2spec/test/phase0/helper_functions/test_misc.py index 88d7478f5..7fdc57e91 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/helper_functions/test_misc.py +++ b/tests/core/pyspec/eth2spec/test/phase0/helper_functions/test_misc.py @@ -2,7 +2,6 @@ import pytest from eth2spec.test.context import spec_state_test, with_all_phases - @with_all_phases @spec_state_test def test_invalid_large_withdrawable_epoch(spec, state): From d1f01870767ba7554b89b429f5ec65eee6344a6b Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Tue, 10 May 2022 10:48:59 -0500 Subject: [PATCH 5/7] Revert "Move test case to new location" This reverts commit e2cbdb2b672e1b7a74a94e60e3218c7b79743e88. --- .../test_process_registry_updates.py | 26 ++++++++++++++++++ .../test/phase0/helper_functions/test_misc.py | 27 ------------------- 2 files changed, 26 insertions(+), 27 deletions(-) delete mode 100644 tests/core/pyspec/eth2spec/test/phase0/helper_functions/test_misc.py diff --git a/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_registry_updates.py b/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_registry_updates.py index 6539dc92d..2aff866c2 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_registry_updates.py +++ b/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_registry_updates.py @@ -1,3 +1,5 @@ +import pytest + from eth2spec.test.helpers.deposits import mock_deposit from eth2spec.test.helpers.state import next_epoch, next_slots from eth2spec.test.helpers.constants import MINIMAL @@ -342,3 +344,27 @@ def test_activation_queue_activation_and_ejection__exceed_scaled_churn_limit(spe churn_limit = spec.get_validator_churn_limit(state) assert churn_limit > spec.config.MIN_PER_EPOCH_CHURN_LIMIT yield from run_test_activation_queue_activation_and_ejection(spec, state, churn_limit * 2) + + +@with_all_phases +@spec_state_test +def test_invalid_large_withdrawable_epoch(spec, state): + """ + This test forces a validator into a withdrawable epoch that overflows the + epoch (uint64) type. To do this we need two validators, one validator that + already has an exit epoch and another with a low effective balance. When + calculating the withdrawable epoch for the second validator, it will + use the greatest exit epoch of all of the validators. If the first + validator is given an exit epoch between + (FAR_FUTURE_EPOCH-MIN_VALIDATOR_WITHDRAWABILITY_DELAY+1) and + (FAR_FUTURE_EPOCH-1), it will cause an overflow. + """ + assert spec.is_active_validator(state.validators[0], spec.get_current_epoch(state)) + assert spec.is_active_validator(state.validators[1], spec.get_current_epoch(state)) + + state.validators[0].exit_epoch = spec.FAR_FUTURE_EPOCH - 1 + state.validators[1].effective_balance = spec.config.EJECTION_BALANCE + + with pytest.raises(ValueError): + yield from run_process_registry_updates(spec, state) + yield 'post', None diff --git a/tests/core/pyspec/eth2spec/test/phase0/helper_functions/test_misc.py b/tests/core/pyspec/eth2spec/test/phase0/helper_functions/test_misc.py deleted file mode 100644 index 7fdc57e91..000000000 --- a/tests/core/pyspec/eth2spec/test/phase0/helper_functions/test_misc.py +++ /dev/null @@ -1,27 +0,0 @@ -import pytest - -from eth2spec.test.context import spec_state_test, with_all_phases - -@with_all_phases -@spec_state_test -def test_invalid_large_withdrawable_epoch(spec, state): - """ - This test forces a validator into a withdrawable epoch that overflows the - epoch (uint64) type. To do this we need two validators, one validator that - already has an exit epoch and another with a low effective balance. When - calculating the withdrawable epoch for the second validator, it will - use the greatest exit epoch of all of the validators. If the first - validator is given an exit epoch between - (FAR_FUTURE_EPOCH-MIN_VALIDATOR_WITHDRAWABILITY_DELAY+1) and - (FAR_FUTURE_EPOCH-1), it will cause an overflow. - """ - assert spec.is_active_validator(state.validators[0], spec.get_current_epoch(state)) - assert spec.is_active_validator(state.validators[1], spec.get_current_epoch(state)) - - state.validators[0].exit_epoch = spec.FAR_FUTURE_EPOCH - 1 - state.validators[1].effective_balance = spec.config.EJECTION_BALANCE - - yield 'pre', state - with pytest.raises(ValueError): - spec.initiate_validator_exit(state, 1) - yield 'post', None From 02090d94ab8c8eeba1d4b30d2fac440d9f378ca1 Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Tue, 10 May 2022 11:00:16 -0500 Subject: [PATCH 6/7] Remove pytest import --- .../epoch_processing/test_process_registry_updates.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_registry_updates.py b/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_registry_updates.py index 2aff866c2..9c6461fb4 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_registry_updates.py +++ b/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_registry_updates.py @@ -1,5 +1,3 @@ -import pytest - from eth2spec.test.helpers.deposits import mock_deposit from eth2spec.test.helpers.state import next_epoch, next_slots from eth2spec.test.helpers.constants import MINIMAL @@ -365,6 +363,10 @@ def test_invalid_large_withdrawable_epoch(spec, state): state.validators[0].exit_epoch = spec.FAR_FUTURE_EPOCH - 1 state.validators[1].effective_balance = spec.config.EJECTION_BALANCE - with pytest.raises(ValueError): + try: yield from run_process_registry_updates(spec, state) - yield 'post', None + except ValueError: + yield 'post', None + return + + raise AssertionError('expected ValueError') From 89e7a1073d37c2d027c40a0fa6f4cd982bf45234 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Tue, 10 May 2022 19:00:08 +0200 Subject: [PATCH 7/7] Add notes about invalid case to `epoch_processing` test format --- tests/formats/epoch_processing/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/formats/epoch_processing/README.md b/tests/formats/epoch_processing/README.md index 1032026a6..e0e6dc367 100644 --- a/tests/formats/epoch_processing/README.md +++ b/tests/formats/epoch_processing/README.md @@ -21,7 +21,7 @@ An SSZ-snappy encoded `BeaconState`, the state before running the epoch sub-tran ### `post.ssz_snappy` -An SSZ-snappy encoded `BeaconState`, the state after applying the epoch sub-transition. +An SSZ-snappy encoded `BeaconState`, the state after applying the epoch sub-transition. No value if the sub-transition processing is aborted. ## Condition