Add individual processing for ef tests (#745)
* Add Individual signature verification for ef tests * Add clone state to avoid errors in ef tests * Add state verification for VerifyIndividual in ef tests * Add Clone derive for errors * Update comments
This commit is contained in:
parent
95cc5dd22f
commit
8e1e6838d2
@ -7,7 +7,7 @@ use types::*;
|
|||||||
/// Any of the `...Error` variants indicate that at some point during block (and block operation)
|
/// Any of the `...Error` variants indicate that at some point during block (and block operation)
|
||||||
/// verification, there was an error. There is no indication as to _where_ that error happened
|
/// verification, there was an error. There is no indication as to _where_ that error happened
|
||||||
/// (e.g., when processing attestations instead of when processing deposits).
|
/// (e.g., when processing attestations instead of when processing deposits).
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
pub enum BlockProcessingError {
|
pub enum BlockProcessingError {
|
||||||
RandaoSignatureInvalid,
|
RandaoSignatureInvalid,
|
||||||
BulkSignatureVerificationFailed,
|
BulkSignatureVerificationFailed,
|
||||||
@ -122,7 +122,7 @@ pub type AttestationValidationError = BlockOperationError<AttestationInvalid>;
|
|||||||
pub type DepositValidationError = BlockOperationError<DepositInvalid>;
|
pub type DepositValidationError = BlockOperationError<DepositInvalid>;
|
||||||
pub type ExitValidationError = BlockOperationError<ExitInvalid>;
|
pub type ExitValidationError = BlockOperationError<ExitInvalid>;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
pub enum BlockOperationError<T> {
|
pub enum BlockOperationError<T> {
|
||||||
Invalid(T),
|
Invalid(T),
|
||||||
BeaconStateError(BeaconStateError),
|
BeaconStateError(BeaconStateError),
|
||||||
@ -153,7 +153,7 @@ impl<T> From<ssz_types::Error> for BlockOperationError<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
pub enum HeaderInvalid {
|
pub enum HeaderInvalid {
|
||||||
ProposalSignatureInvalid,
|
ProposalSignatureInvalid,
|
||||||
StateSlotMismatch,
|
StateSlotMismatch,
|
||||||
@ -161,7 +161,7 @@ pub enum HeaderInvalid {
|
|||||||
ProposerSlashed(usize),
|
ProposerSlashed(usize),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
pub enum ProposerSlashingInvalid {
|
pub enum ProposerSlashingInvalid {
|
||||||
/// The proposer index is not a known validator.
|
/// The proposer index is not a known validator.
|
||||||
ProposerUnknown(u64),
|
ProposerUnknown(u64),
|
||||||
@ -179,7 +179,7 @@ pub enum ProposerSlashingInvalid {
|
|||||||
BadProposal2Signature,
|
BadProposal2Signature,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
pub enum AttesterSlashingInvalid {
|
pub enum AttesterSlashingInvalid {
|
||||||
/// The attestations were not in conflict.
|
/// The attestations were not in conflict.
|
||||||
NotSlashable,
|
NotSlashable,
|
||||||
@ -196,7 +196,7 @@ pub enum AttesterSlashingInvalid {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Describes why an object is invalid.
|
/// Describes why an object is invalid.
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
pub enum AttestationInvalid {
|
pub enum AttestationInvalid {
|
||||||
/// Commmittee index exceeds number of committees in that slot.
|
/// Commmittee index exceeds number of committees in that slot.
|
||||||
BadCommitteeIndex,
|
BadCommitteeIndex,
|
||||||
@ -251,7 +251,7 @@ impl From<BlockOperationError<IndexedAttestationInvalid>>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
pub enum IndexedAttestationInvalid {
|
pub enum IndexedAttestationInvalid {
|
||||||
/// The number of indices exceeds the global maximum.
|
/// The number of indices exceeds the global maximum.
|
||||||
///
|
///
|
||||||
@ -270,7 +270,7 @@ pub enum IndexedAttestationInvalid {
|
|||||||
SignatureSetError(SignatureSetError),
|
SignatureSetError(SignatureSetError),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
pub enum DepositInvalid {
|
pub enum DepositInvalid {
|
||||||
/// The signature (proof-of-possession) does not match the given pubkey.
|
/// The signature (proof-of-possession) does not match the given pubkey.
|
||||||
BadSignature,
|
BadSignature,
|
||||||
@ -281,7 +281,7 @@ pub enum DepositInvalid {
|
|||||||
BadMerkleProof,
|
BadMerkleProof,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
pub enum ExitInvalid {
|
pub enum ExitInvalid {
|
||||||
/// The specified validator is not active.
|
/// The specified validator is not active.
|
||||||
NotActive(u64),
|
NotActive(u64),
|
||||||
|
@ -14,7 +14,7 @@ use types::{
|
|||||||
|
|
||||||
pub type Result<T> = std::result::Result<T, Error>;
|
pub type Result<T> = std::result::Result<T, Error>;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
/// Signature verification failed. The block is invalid.
|
/// Signature verification failed. The block is invalid.
|
||||||
SignatureInvalid,
|
SignatureInvalid,
|
||||||
|
@ -28,7 +28,7 @@ mod tests;
|
|||||||
pub const CACHED_EPOCHS: usize = 3;
|
pub const CACHED_EPOCHS: usize = 3;
|
||||||
const MAX_RANDOM_BYTE: u64 = (1 << 8) - 1;
|
const MAX_RANDOM_BYTE: u64 = (1 << 8) - 1;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
EpochOutOfBounds,
|
EpochOutOfBounds,
|
||||||
SlotOutOfBounds,
|
SlotOutOfBounds,
|
||||||
|
@ -10,7 +10,7 @@ pub use crate::multi_cache::MultiTreeHashCache;
|
|||||||
use ethereum_types::H256 as Hash256;
|
use ethereum_types::H256 as Hash256;
|
||||||
use tree_hash::TreeHash;
|
use tree_hash::TreeHash;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
/// Attempting to provide more than 2^depth leaves to a Merkle tree is disallowed.
|
/// Attempting to provide more than 2^depth leaves to a Merkle tree is disallowed.
|
||||||
TooManyLeaves,
|
TooManyLeaves,
|
||||||
|
@ -53,7 +53,7 @@ pub mod length {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returned when an item encounters an error.
|
/// Returned when an item encounters an error.
|
||||||
#[derive(PartialEq, Debug)]
|
#[derive(PartialEq, Debug, Clone)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
OutOfBounds {
|
OutOfBounds {
|
||||||
i: usize,
|
i: usize,
|
||||||
|
@ -61,41 +61,65 @@ impl<E: EthSpec> Case for SanityBlocks<E> {
|
|||||||
fn result(&self, _case_index: usize) -> Result<(), Error> {
|
fn result(&self, _case_index: usize) -> Result<(), Error> {
|
||||||
self.metadata.bls_setting.unwrap_or_default().check()?;
|
self.metadata.bls_setting.unwrap_or_default().check()?;
|
||||||
|
|
||||||
let mut state = self.pre.clone();
|
let mut bulk_state = self.pre.clone();
|
||||||
let mut expected = self.post.clone();
|
let mut expected = self.post.clone();
|
||||||
let spec = &E::default_spec();
|
let spec = &E::default_spec();
|
||||||
|
|
||||||
// Processing requires the epoch cache.
|
// Processing requires the epoch cache.
|
||||||
state.build_all_caches(spec).unwrap();
|
bulk_state.build_all_caches(spec).unwrap();
|
||||||
|
|
||||||
let mut result = self
|
// Spawning a second state to call the VerifyIndiviual strategy to avoid bitrot.
|
||||||
|
// See https://github.com/sigp/lighthouse/issues/742.
|
||||||
|
let mut indiv_state = bulk_state.clone();
|
||||||
|
|
||||||
|
let result = self
|
||||||
.blocks
|
.blocks
|
||||||
.iter()
|
.iter()
|
||||||
.try_for_each(|block| {
|
.try_for_each(|block| {
|
||||||
while state.slot < block.slot {
|
while bulk_state.slot < block.slot {
|
||||||
per_slot_processing(&mut state, None, spec).unwrap();
|
per_slot_processing(&mut bulk_state, None, spec).unwrap();
|
||||||
|
per_slot_processing(&mut indiv_state, None, spec).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
state
|
bulk_state
|
||||||
|
.build_committee_cache(RelativeEpoch::Current, spec)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
indiv_state
|
||||||
.build_committee_cache(RelativeEpoch::Current, spec)
|
.build_committee_cache(RelativeEpoch::Current, spec)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
per_block_processing(
|
per_block_processing(
|
||||||
&mut state,
|
&mut indiv_state,
|
||||||
|
block,
|
||||||
|
None,
|
||||||
|
BlockSignatureStrategy::VerifyIndividual,
|
||||||
|
spec,
|
||||||
|
)?;
|
||||||
|
|
||||||
|
per_block_processing(
|
||||||
|
&mut bulk_state,
|
||||||
block,
|
block,
|
||||||
None,
|
None,
|
||||||
BlockSignatureStrategy::VerifyBulk,
|
BlockSignatureStrategy::VerifyBulk,
|
||||||
spec,
|
spec,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
if block.state_root == state.canonical_root() {
|
if block.state_root == bulk_state.canonical_root()
|
||||||
|
&& block.state_root == indiv_state.canonical_root()
|
||||||
|
{
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
Err(BlockProcessingError::StateRootMismatch)
|
Err(BlockProcessingError::StateRootMismatch)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.map(|_| state);
|
.map(|_| (bulk_state, indiv_state));
|
||||||
|
|
||||||
compare_beacon_state_results_without_caches(&mut result, &mut expected)
|
let (mut bulk_result, mut indiv_result) = match result {
|
||||||
|
Err(e) => (Err(e.clone()), Err(e)),
|
||||||
|
Ok(res) => (Ok(res.0), Ok(res.1)),
|
||||||
|
};
|
||||||
|
compare_beacon_state_results_without_caches(&mut indiv_result, &mut expected)?;
|
||||||
|
compare_beacon_state_results_without_caches(&mut bulk_result, &mut expected)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user