Fix big in attestation validation

There was no check that the attestation is within an appropriate
distance from its parent block.
This commit is contained in:
Paul Hauner 2018-10-13 09:39:10 +11:00
parent e8daca4c80
commit 90010ced55
No known key found for this signature in database
GPG Key ID: 303E4494BB28068C
2 changed files with 14 additions and 4 deletions

View File

@ -29,6 +29,7 @@ use super::signature_verification::{
#[derive(Debug,PartialEq)]
pub enum AttestationValidationError {
ParentSlotTooHigh,
ParentSlotTooLow,
BlockSlotTooHigh,
BlockSlotTooLow,
JustifiedSlotIncorrect,
@ -94,11 +95,11 @@ impl<T> AttestationValidationContext<T>
/*
* The slot of this attestation must not be more than cycle_length + 1 distance
* from the block that contained it.
* from the parent_slot of block that contained it.
*/
if a.slot < self.block_slot
if a.slot < self.parent_block_slot
.saturating_sub(u64::from(self.cycle_length).saturating_add(1)) {
return Err(AttestationValidationError::BlockSlotTooLow);
return Err(AttestationValidationError::ParentSlotTooLow);
}
/*

View File

@ -42,6 +42,15 @@ fn test_attestation_validation_invalid_parent_slot_too_high() {
assert_eq!(result, Err(AttestationValidationError::ParentSlotTooHigh));
}
#[test]
fn test_attestation_validation_invalid_parent_slot_too_low() {
let mut rig = generic_rig();
rig.attestation.slot = rig.context.parent_block_slot - u64::from(rig.context.cycle_length) - 2;
let result = rig.context.validate_attestation(&rig.attestation);
assert_eq!(result, Err(AttestationValidationError::ParentSlotTooLow));
}
#[test]
fn test_attestation_validation_invalid_block_slot_too_high() {
let mut rig = generic_rig();
@ -56,7 +65,7 @@ fn test_attestation_validation_invalid_block_slot_too_high() {
fn test_attestation_validation_invalid_block_slot_too_low() {
let mut rig = generic_rig();
rig.attestation.slot = rig.context.block_slot - u64::from(rig.context.cycle_length) - 2;
rig.context.block_slot = rig.context.block_slot + u64::from(rig.context.cycle_length);
let result = rig.context.validate_attestation(&rig.attestation);
assert_eq!(result, Err(AttestationValidationError::BlockSlotTooLow));
}