Skip to content

Commit

Permalink
Address ethereum/consensus-specs#627: fix off by one attestaton issue
Browse files Browse the repository at this point in the history
  • Loading branch information
hwwhww committed Feb 22, 2019
1 parent 8d4abeb commit 1bf5f44
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
Expand Down

0 comments on commit 1bf5f44

Please sign in to comment.