From 1bf5f44cfee25dfa32ce1b68bb23e05a4b71a9e4 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Fri, 22 Feb 2019 15:31:18 +0800 Subject: [PATCH] Address ethereum/eth2.0-specs#627: fix off by one attestaton issue --- .../forks/serenity/block_validation.py | 2 +- .../test_serenity_block_attestation_validation.py | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/eth2/beacon/state_machines/forks/serenity/block_validation.py b/eth2/beacon/state_machines/forks/serenity/block_validation.py index 6cd18fc51b..9e62c965e2 100644 --- a/eth2/beacon/state_machines/forks/serenity/block_validation.py +++ b/eth2/beacon/state_machines/forks/serenity/block_validation.py @@ -320,7 +320,7 @@ def validate_attestation_justified_epoch(attestation_data: AttestationData, Validate ``justified_epoch`` field of ``attestation_data``. Raise ``ValidationError`` if it's invalid. """ - if attestation_data.slot >= get_epoch_start_slot(current_epoch, slots_per_epoch): + if slot_to_epoch(attestation_data.slot + 1, slots_per_epoch) >= current_epoch: if attestation_data.justified_epoch != justified_epoch: raise ValidationError( "Attestation ``slot`` is after recent epoch transition but attestation" diff --git a/tests/eth2/beacon/state_machines/forks/test_serenity_block_attestation_validation.py b/tests/eth2/beacon/state_machines/forks/test_serenity_block_attestation_validation.py index 7ad86003f2..0362b29a43 100644 --- a/tests/eth2/beacon/state_machines/forks/test_serenity_block_attestation_validation.py +++ b/tests/eth2/beacon/state_machines/forks/test_serenity_block_attestation_validation.py @@ -90,13 +90,12 @@ def test_validate_attestation_slot(sample_attestation_data_params, 'is_valid,' ), [ - (13, 1, 2, 0, 1, 5, True), - (13, 0, 2, 0, 1, 5, False), # targeting previous_justified_epoch, should be targeting justified_epoch # noqa: E501 - (13, 4, 2, 0, 1, 5, False), # targeting future epoch, should be targeting justified_epoch - (29, 1, 3, 1, 2, 10, True), - (29, 2, 3, 1, 2, 10, False), # targeting justified_epoch, should be targeting previous_justified_epoch # noqa: E501 - (29, 3, 3, 1, 2, 10, False), # targeting future epoch, should be targeting previous_justified_epoch # noqa: E501 - (10, 1, 1, 1, 1, 10, True), + # slot_to_epoch(attestation_data.slot + 1, slots_per_epoch) >= current_epoch + (23, 2, 3, 1, 2, 8, True), # attestation_data.justified_epoch == justified_epoch + (23, 1, 3, 1, 2, 8, False), # attestation_data.justified_epoch != justified_epoch + # slot_to_epoch(attestation_data.slot + 1, slots_per_epoch) < current_epoch + (22, 1, 3, 1, 2, 8, True), # attestation_data.justified_epoch == previous_justified_epoch + (22, 2, 3, 1, 2, 8, False), # attestation_data.justified_epoch != previous_justified_epoch ] ) def test_validate_attestation_justified_epoch( @@ -114,6 +113,7 @@ def test_validate_attestation_justified_epoch( ) if is_valid: + # slot_to_epoch(attestation_data.slot + 1, slots_per_epoch) >= current_epoch validate_attestation_justified_epoch( attestation_data, current_epoch,