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:
parent
e8daca4c80
commit
90010ced55
@ -29,6 +29,7 @@ use super::signature_verification::{
|
|||||||
#[derive(Debug,PartialEq)]
|
#[derive(Debug,PartialEq)]
|
||||||
pub enum AttestationValidationError {
|
pub enum AttestationValidationError {
|
||||||
ParentSlotTooHigh,
|
ParentSlotTooHigh,
|
||||||
|
ParentSlotTooLow,
|
||||||
BlockSlotTooHigh,
|
BlockSlotTooHigh,
|
||||||
BlockSlotTooLow,
|
BlockSlotTooLow,
|
||||||
JustifiedSlotIncorrect,
|
JustifiedSlotIncorrect,
|
||||||
@ -94,11 +95,11 @@ impl<T> AttestationValidationContext<T>
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* The slot of this attestation must not be more than cycle_length + 1 distance
|
* 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)) {
|
.saturating_sub(u64::from(self.cycle_length).saturating_add(1)) {
|
||||||
return Err(AttestationValidationError::BlockSlotTooLow);
|
return Err(AttestationValidationError::ParentSlotTooLow);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -42,6 +42,15 @@ fn test_attestation_validation_invalid_parent_slot_too_high() {
|
|||||||
assert_eq!(result, Err(AttestationValidationError::ParentSlotTooHigh));
|
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]
|
#[test]
|
||||||
fn test_attestation_validation_invalid_block_slot_too_high() {
|
fn test_attestation_validation_invalid_block_slot_too_high() {
|
||||||
let mut rig = generic_rig();
|
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() {
|
fn test_attestation_validation_invalid_block_slot_too_low() {
|
||||||
let mut rig = generic_rig();
|
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);
|
let result = rig.context.validate_attestation(&rig.attestation);
|
||||||
assert_eq!(result, Err(AttestationValidationError::BlockSlotTooLow));
|
assert_eq!(result, Err(AttestationValidationError::BlockSlotTooLow));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user