Create unique errors for att. parent hashes
This commit is contained in:
parent
890aaf7335
commit
30bf97539c
@ -1,5 +1,12 @@
|
|||||||
use super::Hash256;
|
use super::Hash256;
|
||||||
use super::ParameterError;
|
|
||||||
|
pub enum ParentHashesError {
|
||||||
|
BadCurrentHashes,
|
||||||
|
BadObliqueHashes,
|
||||||
|
SlotTooHigh,
|
||||||
|
SlotTooLow,
|
||||||
|
IntWrapping,
|
||||||
|
}
|
||||||
|
|
||||||
/// This function is used to select the hashes used in
|
/// This function is used to select the hashes used in
|
||||||
/// the signing of an AttestationRecord.
|
/// the signing of an AttestationRecord.
|
||||||
@ -18,23 +25,20 @@ pub fn attestation_parent_hashes(
|
|||||||
attestation_slot: u64,
|
attestation_slot: u64,
|
||||||
current_hashes: &[Hash256],
|
current_hashes: &[Hash256],
|
||||||
oblique_hashes: &[Hash256])
|
oblique_hashes: &[Hash256])
|
||||||
-> Result<Vec<Hash256>, ParameterError>
|
-> Result<Vec<Hash256>, ParentHashesError>
|
||||||
{
|
{
|
||||||
// This cast places a limit on cycle_length. If you change it, check math
|
// This cast places a limit on cycle_length. If you change it, check math
|
||||||
// for overflow.
|
// for overflow.
|
||||||
let cycle_length: u64 = u64::from(cycle_length);
|
let cycle_length: u64 = u64::from(cycle_length);
|
||||||
|
|
||||||
if current_hashes.len() as u64 != (cycle_length * 2) {
|
if current_hashes.len() as u64 != (cycle_length * 2) {
|
||||||
return Err(ParameterError::InvalidInput(String::from(
|
return Err(ParentHashesError::BadCurrentHashes);
|
||||||
"current_hashes.len() must equal cycle_length * 2")));
|
|
||||||
}
|
|
||||||
if attestation_slot >= block_slot {
|
|
||||||
return Err(ParameterError::InvalidInput(String::from(
|
|
||||||
"attestation_slot must be less than block_slot")));
|
|
||||||
}
|
}
|
||||||
if oblique_hashes.len() as u64 > cycle_length {
|
if oblique_hashes.len() as u64 > cycle_length {
|
||||||
return Err(ParameterError::InvalidInput(String::from(
|
return Err(ParentHashesError::BadObliqueHashes);
|
||||||
"oblique_hashes.len() must be <= cycle_length * 2")));
|
}
|
||||||
|
if attestation_slot >= block_slot {
|
||||||
|
return Err(ParentHashesError::SlotTooHigh);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -44,8 +48,7 @@ pub fn attestation_parent_hashes(
|
|||||||
let attestation_distance = block_slot - attestation_slot;
|
let attestation_distance = block_slot - attestation_slot;
|
||||||
|
|
||||||
if attestation_distance > cycle_length {
|
if attestation_distance > cycle_length {
|
||||||
return Err(ParameterError::InvalidInput(String::from(
|
return Err(ParentHashesError::SlotTooLow);
|
||||||
"attestation_slot must be withing one cycle of block_slot")));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -63,7 +66,7 @@ pub fn attestation_parent_hashes(
|
|||||||
*/
|
*/
|
||||||
let end = start.checked_add(cycle_length)
|
let end = start.checked_add(cycle_length)
|
||||||
.and_then(|x| x.checked_sub(oblique_hashes.len() as u64))
|
.and_then(|x| x.checked_sub(oblique_hashes.len() as u64))
|
||||||
.ok_or(ParameterError::IntWrapping)?;
|
.ok_or(ParentHashesError::IntWrapping)?;
|
||||||
|
|
||||||
|
|
||||||
let mut hashes = Vec::new();
|
let mut hashes = Vec::new();
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
use super::utils::types::Hash256;
|
use super::utils::types::Hash256;
|
||||||
use super::utils::errors::ParameterError;
|
|
||||||
|
|
||||||
mod attestation_parent_hashes;
|
pub mod attestation_parent_hashes;
|
||||||
mod shuffling;
|
mod shuffling;
|
||||||
|
|
||||||
pub use self::attestation_parent_hashes::attestation_parent_hashes;
|
|
||||||
pub use self::shuffling::shuffle;
|
pub use self::shuffling::shuffle;
|
||||||
|
@ -1,14 +1,5 @@
|
|||||||
// Collection of custom errors
|
// Collection of custom errors
|
||||||
|
|
||||||
#[derive(Debug,PartialEq)]
|
|
||||||
pub enum AttestationValidationError {
|
|
||||||
SlotTooHigh,
|
|
||||||
SlotTooLow(String),
|
|
||||||
IncorrectBitField,
|
|
||||||
NonZeroTrailingBits,
|
|
||||||
AggregateSignatureFail
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug,PartialEq)]
|
#[derive(Debug,PartialEq)]
|
||||||
pub enum ParameterError {
|
pub enum ParameterError {
|
||||||
IntWrapping,
|
IntWrapping,
|
||||||
|
Loading…
Reference in New Issue
Block a user