mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-10 20:22:02 +00:00
invalid block signature test
This commit is contained in:
@@ -1,39 +1,72 @@
|
||||
#![cfg(test)]
|
||||
use crate::per_block_processing;
|
||||
use super::block_processing_builder::BlockProcessingBuilder;
|
||||
use super::errors::*;
|
||||
use types::*;
|
||||
use crate::per_block_processing;
|
||||
use ssz::SignedRoot;
|
||||
use types::{ChainSpec, Domain, Keypair, Signature, Slot};
|
||||
|
||||
pub const VALIDATOR_COUNT: usize = 10;
|
||||
|
||||
#[test]
|
||||
fn runs_without_error() {
|
||||
fn valid_block_ok() {
|
||||
let spec = ChainSpec::foundation();
|
||||
let (block, mut state) = get_block_state(&spec);
|
||||
let builder = get_builder(&spec);
|
||||
let (block, mut state) = builder.build(&spec);
|
||||
|
||||
per_block_processing(&mut state, &block, &spec).unwrap();
|
||||
let result = per_block_processing(&mut state, &block, &spec);
|
||||
|
||||
assert_eq!(result, Ok(()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn process_block_header_invalid_state_slot() {
|
||||
fn invalid_block_header_state_slot() {
|
||||
let spec = ChainSpec::foundation();
|
||||
let (mut block, mut state) = get_block_state(&spec);
|
||||
let builder = get_builder(&spec);
|
||||
let (mut block, mut state) = builder.build(&spec);
|
||||
|
||||
state.slot = Slot::new(133713);
|
||||
block.slot = Slot::new(424242);
|
||||
|
||||
let result = per_block_processing(&mut state, &block, &spec);
|
||||
|
||||
assert_eq!(result, Err(BlockProcessingError::Invalid(BlockInvalid::StateSlotMismatch)));
|
||||
assert_eq!(
|
||||
result,
|
||||
Err(BlockProcessingError::Invalid(
|
||||
BlockInvalid::StateSlotMismatch
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn process_block_header_invalid_parent_block_root() {
|
||||
fn invalid_parent_block_root() {
|
||||
// this will be changed in spec 0.5.1 to use signed root
|
||||
}
|
||||
|
||||
fn get_block_state(spec: &ChainSpec) -> (BeaconBlock, BeaconState) {
|
||||
#[test]
|
||||
fn invalid_block_signature() {
|
||||
let spec = ChainSpec::foundation();
|
||||
let builder = get_builder(&spec);
|
||||
let (mut block, mut state) = builder.build(&spec);
|
||||
|
||||
// sign the block with a keypair that is not the expected proposer
|
||||
let keypair = Keypair::random();
|
||||
let message = block.signed_root();
|
||||
let epoch = block.slot.epoch(spec.slots_per_epoch);
|
||||
let domain = spec.get_domain(epoch, Domain::BeaconBlock, &state.fork);
|
||||
block.signature = Signature::new(&message, domain, &keypair.sk);
|
||||
|
||||
// process block with invalid block signature
|
||||
let result = per_block_processing(&mut state, &block, &spec);
|
||||
|
||||
// should get a BadSignature error
|
||||
assert_eq!(
|
||||
result,
|
||||
Err(BlockProcessingError::Invalid(BlockInvalid::BadSignature))
|
||||
);
|
||||
}
|
||||
|
||||
fn get_builder(spec: &ChainSpec) -> (BlockProcessingBuilder) {
|
||||
let mut builder = BlockProcessingBuilder::new(VALIDATOR_COUNT, &spec);
|
||||
|
||||
// Set the state and block to be in the last slot of the 4th epoch.
|
||||
@@ -41,92 +74,5 @@ fn get_block_state(spec: &ChainSpec) -> (BeaconBlock, BeaconState) {
|
||||
builder.set_slot(last_slot_of_epoch, &spec);
|
||||
builder.build_caches(&spec);
|
||||
|
||||
let (block, state) = builder.build(&spec);
|
||||
|
||||
(block, state)
|
||||
(builder)
|
||||
}
|
||||
|
||||
// verify_block_signature
|
||||
// Invalid::BadSignature
|
||||
|
||||
// process_randao
|
||||
// Invalid::BadRandaoSignature
|
||||
|
||||
// process_proposer_slashings
|
||||
// Invalid::MaxProposerSlashingsExceeded
|
||||
// verify_proposer_slashing
|
||||
// Invalid::ProposerUnknown
|
||||
// Invalid::ProposalSlotMismatch
|
||||
// Invalid::ProposalsIdentical
|
||||
// Invalid::ProposerAlreadySlashed
|
||||
// Invalid::ProposerAlreadyWithdrawn
|
||||
// Invalid::BadProposal1Signature
|
||||
// Invalid::BadProposal2Signature
|
||||
|
||||
// process_attester_slashings
|
||||
// Invalid::MaxAttesterSlashingsExceed
|
||||
// verify_attester_slashing
|
||||
// Invalid::AttestationDataIdentical
|
||||
// Invalid::NotSlashable
|
||||
// Invalid::SlashableAttestation1Invalid
|
||||
// Invalid::SlashableAttestation2Invalid
|
||||
|
||||
// process_attestations
|
||||
// Invalid::MaxAttestationsExceeded
|
||||
// validate_attestation
|
||||
// Invalid::PreGenesis
|
||||
// Invalid::IncludedTooLate
|
||||
// Invalid::IncludedTooEarly
|
||||
// Invalid::BadPreviousCrosslink
|
||||
// Invalid::AggregationBitfieldIsEmpty
|
||||
// Invalid::CustodyBitfieldHasSetBits
|
||||
// Invalid::NoCommitteeForShard
|
||||
// Invalid::BadCustodyBitfieldLength
|
||||
// Invalid::BadAggregationBitfieldLength
|
||||
// Invalid::ShardBlockRootNotZero
|
||||
// verify_justified_epoch_and_root
|
||||
// Invalid::WrongJustifiedEpoch (current)
|
||||
// Invalid::WrongJustifiedRoot (current)
|
||||
// Invalid::WrongJustifiedEpoch (previous)
|
||||
// Invalid::WrongJustifiedRoot (previous)
|
||||
// verify_attestation_signature
|
||||
// Invalid::BadAggregationBitfieldLength
|
||||
// Invalid::BadCustodyBitfieldLength
|
||||
// BeaconStateError::UnknownValidator
|
||||
// Invalid::BadSignature
|
||||
|
||||
// process_deposits
|
||||
// Invalid::MaxDepositsExceeded
|
||||
// verify_deposit
|
||||
// Invalid::BadProofOfPossession
|
||||
// Invalid::BadMerkleProof
|
||||
// verify_deposit_index
|
||||
// Invalid::BadIndex
|
||||
|
||||
// process_exits
|
||||
// Invalid::MaxExitsExceeded
|
||||
// verify_exit
|
||||
// Invalid::ValidatorUnknown
|
||||
// Invalid::AlreadyExited
|
||||
// Invalid::AlreadyInitiatedExited
|
||||
// Invalid::FutureEpoch
|
||||
// Invalid::TooYoungToLeave
|
||||
// Invalid::BadSignature
|
||||
|
||||
// process_transfers
|
||||
// Invalid::MaxTransfersExceed
|
||||
// verify_transfer
|
||||
// Invalid::FromValidatorUnknown
|
||||
// Invalid::FeeOverflow
|
||||
// Invalid::FromBalanceInsufficient (amount)
|
||||
// Invalid::FromBalanceInsufficient (fee)
|
||||
// Invalid::InvalidResultingFromBalance
|
||||
// Invalid::TransferSlotInPast
|
||||
// Invalid::StateSlotMismatch
|
||||
// Invalid::FromValidatorUnknown (???)
|
||||
// Invalid::FromValidatorIneligableForTransfer
|
||||
// Invalid::WithdrawalCredentialsMismatch
|
||||
// Invalid::BadSignature
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user