2019-05-16 13:06:41 +00:00
|
|
|
#![cfg(all(test, not(feature = "fake_crypto")))]
|
2019-08-30 05:49:06 +00:00
|
|
|
|
2021-07-09 06:15:32 +00:00
|
|
|
use crate::per_block_processing;
|
|
|
|
use crate::per_block_processing::errors::{
|
|
|
|
AttestationInvalid, AttesterSlashingInvalid, BlockOperationError, BlockProcessingError,
|
|
|
|
DepositInvalid, HeaderInvalid, IndexedAttestationInvalid, IntoWithIndex,
|
|
|
|
ProposerSlashingInvalid,
|
2019-11-12 05:09:33 +00:00
|
|
|
};
|
2021-07-09 06:15:32 +00:00
|
|
|
use crate::{per_block_processing::process_operations, BlockSignatureStrategy, VerifySignatures};
|
|
|
|
use beacon_chain::test_utils::{BeaconChainHarness, EphemeralHarnessType};
|
|
|
|
use lazy_static::lazy_static;
|
|
|
|
use ssz_types::Bitfield;
|
|
|
|
use test_utils::generate_deterministic_keypairs;
|
2019-05-16 13:06:41 +00:00
|
|
|
use types::*;
|
2019-04-10 04:42:31 +00:00
|
|
|
|
2021-07-09 06:15:32 +00:00
|
|
|
pub const MAX_VALIDATOR_COUNT: usize = 97;
|
2019-11-12 05:09:33 +00:00
|
|
|
pub const NUM_DEPOSITS: u64 = 1;
|
2020-04-01 11:03:03 +00:00
|
|
|
pub const VALIDATOR_COUNT: usize = 64;
|
2020-05-08 23:37:21 +00:00
|
|
|
pub const EPOCH_OFFSET: u64 = 4;
|
2019-11-12 05:09:33 +00:00
|
|
|
pub const NUM_ATTESTATIONS: u64 = 1;
|
2019-04-10 04:42:31 +00:00
|
|
|
|
2021-07-09 06:15:32 +00:00
|
|
|
lazy_static! {
|
|
|
|
/// A cached set of keys.
|
|
|
|
static ref KEYPAIRS: Vec<Keypair> = generate_deterministic_keypairs(MAX_VALIDATOR_COUNT);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_harness<E: EthSpec>(
|
|
|
|
epoch_offset: u64,
|
|
|
|
num_validators: usize,
|
|
|
|
) -> BeaconChainHarness<EphemeralHarnessType<E>> {
|
|
|
|
// Set the state and block to be in the last slot of the `epoch_offset`th epoch.
|
|
|
|
let last_slot_of_epoch =
|
|
|
|
(MainnetEthSpec::genesis_epoch() + epoch_offset).end_slot(E::slots_per_epoch());
|
2021-10-14 02:58:10 +00:00
|
|
|
let harness = BeaconChainHarness::builder(E::default())
|
|
|
|
.default_spec()
|
|
|
|
.keypairs(KEYPAIRS[0..num_validators].to_vec())
|
|
|
|
.fresh_ephemeral_store()
|
|
|
|
.build();
|
2021-07-09 06:15:32 +00:00
|
|
|
let state = harness.get_current_state();
|
|
|
|
if last_slot_of_epoch > Slot::new(0) {
|
|
|
|
harness.add_attested_blocks_at_slots(
|
|
|
|
state,
|
|
|
|
Hash256::zero(),
|
|
|
|
(1..last_slot_of_epoch.as_u64())
|
|
|
|
.map(Slot::new)
|
|
|
|
.collect::<Vec<_>>()
|
|
|
|
.as_slice(),
|
|
|
|
(0..num_validators).collect::<Vec<_>>().as_slice(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
harness
|
|
|
|
}
|
2020-02-10 23:19:36 +00:00
|
|
|
|
2019-04-10 04:42:31 +00:00
|
|
|
#[test]
|
2019-04-15 00:38:13 +00:00
|
|
|
fn valid_block_ok() {
|
2019-06-08 12:49:04 +00:00
|
|
|
let spec = MainnetEthSpec::default_spec();
|
2021-07-09 06:15:32 +00:00
|
|
|
let harness = get_harness::<MainnetEthSpec>(EPOCH_OFFSET, VALIDATOR_COUNT);
|
|
|
|
let state = harness.get_current_state();
|
|
|
|
|
|
|
|
let slot = state.slot();
|
|
|
|
let (block, mut state) = harness.make_block_return_pre_state(state, slot + Slot::new(1));
|
2019-04-10 11:56:31 +00:00
|
|
|
|
2019-08-29 01:34:25 +00:00
|
|
|
let result = per_block_processing(
|
|
|
|
&mut state,
|
|
|
|
&block,
|
|
|
|
None,
|
|
|
|
BlockSignatureStrategy::VerifyIndividual,
|
|
|
|
&spec,
|
|
|
|
);
|
2019-04-15 00:38:13 +00:00
|
|
|
|
2021-07-09 06:15:32 +00:00
|
|
|
assert!(result.is_ok());
|
2019-04-10 11:56:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2019-04-15 00:38:13 +00:00
|
|
|
fn invalid_block_header_state_slot() {
|
2019-06-08 12:49:04 +00:00
|
|
|
let spec = MainnetEthSpec::default_spec();
|
2021-07-09 06:15:32 +00:00
|
|
|
let harness = get_harness::<MainnetEthSpec>(EPOCH_OFFSET, VALIDATOR_COUNT);
|
2019-04-10 11:56:31 +00:00
|
|
|
|
2021-07-09 06:15:32 +00:00
|
|
|
let state = harness.get_current_state();
|
|
|
|
let slot = state.slot() + Slot::new(1);
|
|
|
|
|
|
|
|
let (signed_block, mut state) = harness.make_block_return_pre_state(state, slot);
|
|
|
|
let (mut block, signature) = signed_block.deconstruct();
|
|
|
|
*block.slot_mut() = slot + Slot::new(1);
|
2019-04-10 11:56:31 +00:00
|
|
|
|
2019-08-29 01:34:25 +00:00
|
|
|
let result = per_block_processing(
|
|
|
|
&mut state,
|
2021-07-09 06:15:32 +00:00
|
|
|
&SignedBeaconBlock::from_block(block, signature),
|
2019-08-29 01:34:25 +00:00
|
|
|
None,
|
|
|
|
BlockSignatureStrategy::VerifyIndividual,
|
|
|
|
&spec,
|
|
|
|
);
|
2019-04-10 11:56:31 +00:00
|
|
|
|
2019-04-15 00:38:13 +00:00
|
|
|
assert_eq!(
|
|
|
|
result,
|
2019-08-29 01:34:25 +00:00
|
|
|
Err(BlockProcessingError::HeaderInvalid {
|
|
|
|
reason: HeaderInvalid::StateSlotMismatch
|
|
|
|
})
|
2019-04-15 00:38:13 +00:00
|
|
|
);
|
2019-04-10 11:56:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2019-04-15 00:38:13 +00:00
|
|
|
fn invalid_parent_block_root() {
|
2019-06-08 12:49:04 +00:00
|
|
|
let spec = MainnetEthSpec::default_spec();
|
2021-07-09 06:15:32 +00:00
|
|
|
let harness = get_harness::<MainnetEthSpec>(EPOCH_OFFSET, VALIDATOR_COUNT);
|
|
|
|
|
|
|
|
let state = harness.get_current_state();
|
|
|
|
let slot = state.slot();
|
|
|
|
|
|
|
|
let (signed_block, mut state) = harness.make_block_return_pre_state(state, slot + Slot::new(1));
|
|
|
|
let (mut block, signature) = signed_block.deconstruct();
|
|
|
|
*block.parent_root_mut() = Hash256::from([0xAA; 32]);
|
2019-05-16 13:06:41 +00:00
|
|
|
|
2019-08-29 01:34:25 +00:00
|
|
|
let result = per_block_processing(
|
|
|
|
&mut state,
|
2021-07-09 06:15:32 +00:00
|
|
|
&SignedBeaconBlock::from_block(block, signature),
|
2019-08-29 01:34:25 +00:00
|
|
|
None,
|
|
|
|
BlockSignatureStrategy::VerifyIndividual,
|
|
|
|
&spec,
|
|
|
|
);
|
2019-05-16 13:06:41 +00:00
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
result,
|
2019-08-29 01:34:25 +00:00
|
|
|
Err(BlockProcessingError::HeaderInvalid {
|
|
|
|
reason: HeaderInvalid::ParentBlockRootMismatch {
|
2021-07-09 06:15:32 +00:00
|
|
|
state: state.latest_block_header().canonical_root(),
|
|
|
|
block: Hash256::from([0xAA; 32])
|
2019-05-16 13:06:41 +00:00
|
|
|
}
|
2019-08-29 01:34:25 +00:00
|
|
|
})
|
2019-05-16 13:06:41 +00:00
|
|
|
);
|
2019-04-10 11:56:31 +00:00
|
|
|
}
|
|
|
|
|
2019-04-15 00:38:13 +00:00
|
|
|
#[test]
|
|
|
|
fn invalid_block_signature() {
|
2019-06-08 12:49:04 +00:00
|
|
|
let spec = MainnetEthSpec::default_spec();
|
2021-07-09 06:15:32 +00:00
|
|
|
let harness = get_harness::<MainnetEthSpec>(EPOCH_OFFSET, VALIDATOR_COUNT);
|
|
|
|
|
|
|
|
let state = harness.get_current_state();
|
|
|
|
let slot = state.slot();
|
|
|
|
let (signed_block, mut state) = harness.make_block_return_pre_state(state, slot + Slot::new(1));
|
|
|
|
let (block, _) = signed_block.deconstruct();
|
2019-04-15 00:38:13 +00:00
|
|
|
|
2019-08-29 01:34:25 +00:00
|
|
|
let result = per_block_processing(
|
|
|
|
&mut state,
|
2021-07-09 06:15:32 +00:00
|
|
|
&SignedBeaconBlock::from_block(block, Signature::empty()),
|
2019-08-29 01:34:25 +00:00
|
|
|
None,
|
|
|
|
BlockSignatureStrategy::VerifyIndividual,
|
|
|
|
&spec,
|
|
|
|
);
|
2019-04-15 00:38:13 +00:00
|
|
|
|
|
|
|
// should get a BadSignature error
|
|
|
|
assert_eq!(
|
|
|
|
result,
|
2019-08-29 01:34:25 +00:00
|
|
|
Err(BlockProcessingError::HeaderInvalid {
|
|
|
|
reason: HeaderInvalid::ProposalSignatureInvalid
|
|
|
|
})
|
2019-04-15 00:38:13 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-04-17 21:00:40 +00:00
|
|
|
#[test]
|
|
|
|
fn invalid_randao_reveal_signature() {
|
2019-06-08 12:49:04 +00:00
|
|
|
let spec = MainnetEthSpec::default_spec();
|
2021-07-09 06:15:32 +00:00
|
|
|
let harness = get_harness::<MainnetEthSpec>(EPOCH_OFFSET, VALIDATOR_COUNT);
|
|
|
|
|
|
|
|
let state = harness.get_current_state();
|
|
|
|
let slot = state.slot();
|
2019-04-17 21:00:40 +00:00
|
|
|
|
2021-07-09 06:15:32 +00:00
|
|
|
let (signed_block, mut state) = harness.make_block_with_modifier(state, slot + 1, |block| {
|
|
|
|
*block.body_mut().randao_reveal_mut() = Signature::empty();
|
|
|
|
});
|
2019-05-20 06:47:44 +00:00
|
|
|
|
2019-08-29 01:34:25 +00:00
|
|
|
let result = per_block_processing(
|
|
|
|
&mut state,
|
2021-07-09 06:15:32 +00:00
|
|
|
&signed_block,
|
2019-08-29 01:34:25 +00:00
|
|
|
None,
|
|
|
|
BlockSignatureStrategy::VerifyIndividual,
|
|
|
|
&spec,
|
|
|
|
);
|
2019-04-17 21:00:40 +00:00
|
|
|
|
|
|
|
// should get a BadRandaoSignature error
|
2019-08-29 01:34:25 +00:00
|
|
|
assert_eq!(result, Err(BlockProcessingError::RandaoSignatureInvalid));
|
2019-04-17 21:00:40 +00:00
|
|
|
}
|
|
|
|
|
2019-11-12 05:09:33 +00:00
|
|
|
#[test]
|
|
|
|
fn valid_4_deposits() {
|
|
|
|
let spec = MainnetEthSpec::default_spec();
|
2021-07-09 06:15:32 +00:00
|
|
|
let harness = get_harness::<MainnetEthSpec>(EPOCH_OFFSET, VALIDATOR_COUNT);
|
|
|
|
let mut state = harness.get_current_state();
|
2019-11-12 05:09:33 +00:00
|
|
|
|
2021-12-03 04:44:30 +00:00
|
|
|
let (deposits, state) = harness.make_deposits(&mut state, 4, None, None);
|
2021-07-09 06:15:32 +00:00
|
|
|
let deposits = VariableList::from(deposits);
|
2019-11-12 05:09:33 +00:00
|
|
|
|
2021-07-09 06:15:32 +00:00
|
|
|
let mut head_block = harness.chain.head_beacon_block().unwrap().deconstruct().0;
|
|
|
|
*head_block.to_mut().body_mut().deposits_mut() = deposits;
|
|
|
|
|
2021-12-03 04:44:30 +00:00
|
|
|
let result = process_operations::process_deposits(state, head_block.body().deposits(), &spec);
|
2019-11-12 05:09:33 +00:00
|
|
|
|
|
|
|
// Expecting Ok because these are valid deposits.
|
|
|
|
assert_eq!(result, Ok(()));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn invalid_deposit_deposit_count_too_big() {
|
|
|
|
let spec = MainnetEthSpec::default_spec();
|
2021-07-09 06:15:32 +00:00
|
|
|
let harness = get_harness::<MainnetEthSpec>(EPOCH_OFFSET, VALIDATOR_COUNT);
|
|
|
|
let mut state = harness.get_current_state();
|
2019-11-12 05:09:33 +00:00
|
|
|
|
2021-12-03 04:44:30 +00:00
|
|
|
let (deposits, state) = harness.make_deposits(&mut state, 1, None, None);
|
2021-07-09 06:15:32 +00:00
|
|
|
let deposits = VariableList::from(deposits);
|
2019-11-12 05:09:33 +00:00
|
|
|
|
2021-07-09 06:15:32 +00:00
|
|
|
let mut head_block = harness.chain.head_beacon_block().unwrap().deconstruct().0;
|
|
|
|
*head_block.to_mut().body_mut().deposits_mut() = deposits;
|
2019-11-12 05:09:33 +00:00
|
|
|
|
2021-07-09 06:15:32 +00:00
|
|
|
let big_deposit_count = NUM_DEPOSITS + 1;
|
|
|
|
state.eth1_data_mut().deposit_count = big_deposit_count;
|
2021-12-03 04:44:30 +00:00
|
|
|
let result = process_operations::process_deposits(state, head_block.body().deposits(), &spec);
|
2019-11-12 05:09:33 +00:00
|
|
|
|
|
|
|
// Expecting DepositCountInvalid because we incremented the deposit_count
|
|
|
|
assert_eq!(
|
|
|
|
result,
|
|
|
|
Err(BlockProcessingError::DepositCountInvalid {
|
|
|
|
expected: big_deposit_count as usize,
|
|
|
|
found: 1
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn invalid_deposit_count_too_small() {
|
|
|
|
let spec = MainnetEthSpec::default_spec();
|
2021-07-09 06:15:32 +00:00
|
|
|
let harness = get_harness::<MainnetEthSpec>(EPOCH_OFFSET, VALIDATOR_COUNT);
|
|
|
|
let mut state = harness.get_current_state();
|
2019-11-12 05:09:33 +00:00
|
|
|
|
2021-12-03 04:44:30 +00:00
|
|
|
let (deposits, state) = harness.make_deposits(&mut state, 1, None, None);
|
2021-07-09 06:15:32 +00:00
|
|
|
let deposits = VariableList::from(deposits);
|
2019-11-12 05:09:33 +00:00
|
|
|
|
2021-07-09 06:15:32 +00:00
|
|
|
let mut head_block = harness.chain.head_beacon_block().unwrap().deconstruct().0;
|
|
|
|
*head_block.to_mut().body_mut().deposits_mut() = deposits;
|
2019-11-12 05:09:33 +00:00
|
|
|
|
2021-07-09 06:15:32 +00:00
|
|
|
let small_deposit_count = NUM_DEPOSITS - 1;
|
|
|
|
state.eth1_data_mut().deposit_count = small_deposit_count;
|
2021-12-03 04:44:30 +00:00
|
|
|
let result = process_operations::process_deposits(state, head_block.body().deposits(), &spec);
|
2019-11-12 05:09:33 +00:00
|
|
|
|
|
|
|
// Expecting DepositCountInvalid because we decremented the deposit_count
|
|
|
|
assert_eq!(
|
|
|
|
result,
|
|
|
|
Err(BlockProcessingError::DepositCountInvalid {
|
|
|
|
expected: small_deposit_count as usize,
|
|
|
|
found: 1
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn invalid_deposit_bad_merkle_proof() {
|
|
|
|
let spec = MainnetEthSpec::default_spec();
|
2021-07-09 06:15:32 +00:00
|
|
|
let harness = get_harness::<MainnetEthSpec>(EPOCH_OFFSET, VALIDATOR_COUNT);
|
|
|
|
let mut state = harness.get_current_state();
|
2019-11-12 05:09:33 +00:00
|
|
|
|
2021-12-03 04:44:30 +00:00
|
|
|
let (deposits, state) = harness.make_deposits(&mut state, 1, None, None);
|
2021-07-09 06:15:32 +00:00
|
|
|
let deposits = VariableList::from(deposits);
|
2019-11-12 05:09:33 +00:00
|
|
|
|
2021-07-09 06:15:32 +00:00
|
|
|
let mut head_block = harness.chain.head_beacon_block().unwrap().deconstruct().0;
|
|
|
|
*head_block.to_mut().body_mut().deposits_mut() = deposits;
|
|
|
|
let bad_index = state.eth1_deposit_index() as usize;
|
2019-11-12 05:09:33 +00:00
|
|
|
|
|
|
|
// Manually offsetting deposit count and index to trigger bad merkle proof
|
2021-07-09 06:15:32 +00:00
|
|
|
state.eth1_data_mut().deposit_count += 1;
|
|
|
|
*state.eth1_deposit_index_mut() += 1;
|
2021-12-03 04:44:30 +00:00
|
|
|
let result = process_operations::process_deposits(state, head_block.body().deposits(), &spec);
|
2019-11-12 05:09:33 +00:00
|
|
|
|
|
|
|
// Expecting BadMerkleProof because the proofs were created with different indices
|
|
|
|
assert_eq!(
|
|
|
|
result,
|
|
|
|
Err(BlockProcessingError::DepositInvalid {
|
|
|
|
index: bad_index,
|
|
|
|
reason: DepositInvalid::BadMerkleProof
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn invalid_deposit_wrong_sig() {
|
|
|
|
let spec = MainnetEthSpec::default_spec();
|
2021-07-09 06:15:32 +00:00
|
|
|
let harness = get_harness::<MainnetEthSpec>(EPOCH_OFFSET, VALIDATOR_COUNT);
|
|
|
|
let mut state = harness.get_current_state();
|
2019-11-12 05:09:33 +00:00
|
|
|
|
2021-12-03 04:44:30 +00:00
|
|
|
let (deposits, state) =
|
2021-07-09 06:15:32 +00:00
|
|
|
harness.make_deposits(&mut state, 1, None, Some(SignatureBytes::empty()));
|
|
|
|
let deposits = VariableList::from(deposits);
|
2019-11-12 05:09:33 +00:00
|
|
|
|
2021-07-09 06:15:32 +00:00
|
|
|
let mut head_block = harness.chain.head_beacon_block().unwrap().deconstruct().0;
|
|
|
|
*head_block.to_mut().body_mut().deposits_mut() = deposits;
|
2019-11-12 05:09:33 +00:00
|
|
|
|
2021-12-03 04:44:30 +00:00
|
|
|
let result = process_operations::process_deposits(state, head_block.body().deposits(), &spec);
|
2019-11-12 05:09:33 +00:00
|
|
|
// Expecting Ok(()) even though the block signature does not correspond to the correct public key
|
|
|
|
assert_eq!(result, Ok(()));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn invalid_deposit_invalid_pub_key() {
|
|
|
|
let spec = MainnetEthSpec::default_spec();
|
2021-07-09 06:15:32 +00:00
|
|
|
let harness = get_harness::<MainnetEthSpec>(EPOCH_OFFSET, VALIDATOR_COUNT);
|
|
|
|
let mut state = harness.get_current_state();
|
2019-11-12 05:09:33 +00:00
|
|
|
|
2021-12-03 04:44:30 +00:00
|
|
|
let (deposits, state) =
|
2021-07-09 06:15:32 +00:00
|
|
|
harness.make_deposits(&mut state, 1, Some(PublicKeyBytes::empty()), None);
|
|
|
|
let deposits = VariableList::from(deposits);
|
2019-11-12 05:09:33 +00:00
|
|
|
|
2021-07-09 06:15:32 +00:00
|
|
|
let mut head_block = harness.chain.head_beacon_block().unwrap().deconstruct().0;
|
|
|
|
*head_block.to_mut().body_mut().deposits_mut() = deposits;
|
2019-11-12 05:09:33 +00:00
|
|
|
|
2021-12-03 04:44:30 +00:00
|
|
|
let result = process_operations::process_deposits(state, head_block.body().deposits(), &spec);
|
2019-11-12 05:09:33 +00:00
|
|
|
|
2021-07-09 06:15:32 +00:00
|
|
|
// Expecting Ok(()) even though we passed in invalid publickeybytes in the public key field of the deposit data.
|
2019-11-12 05:09:33 +00:00
|
|
|
assert_eq!(result, Ok(()));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-05-08 23:37:21 +00:00
|
|
|
fn invalid_attestation_no_committee_for_index() {
|
2019-11-12 05:09:33 +00:00
|
|
|
let spec = MainnetEthSpec::default_spec();
|
2021-07-09 06:15:32 +00:00
|
|
|
let harness = get_harness::<MainnetEthSpec>(EPOCH_OFFSET, VALIDATOR_COUNT);
|
2019-11-12 05:09:33 +00:00
|
|
|
|
2021-07-09 06:15:32 +00:00
|
|
|
let mut state = harness.get_current_state();
|
|
|
|
let mut head_block = harness.chain.head_beacon_block().unwrap().deconstruct().0;
|
|
|
|
head_block.to_mut().body_mut().attestations_mut()[0]
|
|
|
|
.data
|
|
|
|
.index += 1;
|
|
|
|
let result = process_operations::process_attestations(
|
2019-11-12 05:09:33 +00:00
|
|
|
&mut state,
|
2021-07-09 06:15:32 +00:00
|
|
|
head_block.body(),
|
2021-07-23 00:23:53 +00:00
|
|
|
head_block.proposer_index(),
|
2021-07-09 06:15:32 +00:00
|
|
|
VerifySignatures::True,
|
2019-11-12 05:09:33 +00:00
|
|
|
&spec,
|
|
|
|
);
|
|
|
|
|
2020-05-08 23:37:21 +00:00
|
|
|
// Expecting NoCommitee because we manually set the attestation's index to be invalid
|
2019-11-12 05:09:33 +00:00
|
|
|
assert_eq!(
|
|
|
|
result,
|
2020-05-08 23:37:21 +00:00
|
|
|
Err(BlockProcessingError::AttestationInvalid {
|
|
|
|
index: 0,
|
|
|
|
reason: AttestationInvalid::BadCommitteeIndex
|
|
|
|
})
|
2019-11-12 05:09:33 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn invalid_attestation_wrong_justified_checkpoint() {
|
|
|
|
let spec = MainnetEthSpec::default_spec();
|
2021-07-09 06:15:32 +00:00
|
|
|
let harness = get_harness::<MainnetEthSpec>(EPOCH_OFFSET, VALIDATOR_COUNT);
|
2019-11-12 05:09:33 +00:00
|
|
|
|
2021-07-09 06:15:32 +00:00
|
|
|
let mut state = harness.get_current_state();
|
|
|
|
let mut head_block = harness.chain.head_beacon_block().unwrap().deconstruct().0;
|
|
|
|
let old_justified_checkpoint = head_block.body().attestations()[0].data.source;
|
|
|
|
let mut new_justified_checkpoint = old_justified_checkpoint;
|
|
|
|
new_justified_checkpoint.epoch += Epoch::new(1);
|
|
|
|
head_block.to_mut().body_mut().attestations_mut()[0]
|
|
|
|
.data
|
|
|
|
.source = new_justified_checkpoint;
|
|
|
|
|
|
|
|
let result = process_operations::process_attestations(
|
2019-11-12 05:09:33 +00:00
|
|
|
&mut state,
|
2021-07-09 06:15:32 +00:00
|
|
|
head_block.body(),
|
2021-07-23 00:23:53 +00:00
|
|
|
head_block.proposer_index(),
|
2021-07-09 06:15:32 +00:00
|
|
|
VerifySignatures::True,
|
2019-11-12 05:09:33 +00:00
|
|
|
&spec,
|
|
|
|
);
|
|
|
|
|
|
|
|
// Expecting WrongJustifiedCheckpoint because we manually set the
|
|
|
|
// source field of the AttestationData object to be invalid
|
|
|
|
assert_eq!(
|
|
|
|
result,
|
|
|
|
Err(BlockProcessingError::AttestationInvalid {
|
|
|
|
index: 0,
|
|
|
|
reason: AttestationInvalid::WrongJustifiedCheckpoint {
|
2021-07-09 06:15:32 +00:00
|
|
|
state: old_justified_checkpoint,
|
|
|
|
attestation: new_justified_checkpoint,
|
2019-11-12 05:09:33 +00:00
|
|
|
is_current: true,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn invalid_attestation_bad_aggregation_bitfield_len() {
|
|
|
|
let spec = MainnetEthSpec::default_spec();
|
2021-07-09 06:15:32 +00:00
|
|
|
let harness = get_harness::<MainnetEthSpec>(EPOCH_OFFSET, VALIDATOR_COUNT);
|
2019-11-12 05:09:33 +00:00
|
|
|
|
2021-07-09 06:15:32 +00:00
|
|
|
let mut state = harness.get_current_state();
|
|
|
|
let mut head_block = harness.chain.head_beacon_block().unwrap().deconstruct().0;
|
|
|
|
head_block.to_mut().body_mut().attestations_mut()[0].aggregation_bits =
|
|
|
|
Bitfield::with_capacity(spec.target_committee_size).unwrap();
|
|
|
|
|
|
|
|
let result = process_operations::process_attestations(
|
2019-11-12 05:09:33 +00:00
|
|
|
&mut state,
|
2021-07-09 06:15:32 +00:00
|
|
|
head_block.body(),
|
2021-07-23 00:23:53 +00:00
|
|
|
head_block.proposer_index(),
|
2021-07-09 06:15:32 +00:00
|
|
|
VerifySignatures::True,
|
2019-11-12 05:09:33 +00:00
|
|
|
&spec,
|
|
|
|
);
|
|
|
|
|
|
|
|
// Expecting InvalidBitfield because the size of the aggregation_bitfield is bigger than the commitee size.
|
|
|
|
assert_eq!(
|
|
|
|
result,
|
|
|
|
Err(BlockProcessingError::BeaconStateError(
|
|
|
|
BeaconStateError::InvalidBitfield
|
|
|
|
))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn invalid_attestation_bad_signature() {
|
|
|
|
let spec = MainnetEthSpec::default_spec();
|
2021-07-09 06:15:32 +00:00
|
|
|
let harness = get_harness::<MainnetEthSpec>(EPOCH_OFFSET, 97); // minimal number of required validators for this test
|
|
|
|
|
|
|
|
let mut state = harness.get_current_state();
|
|
|
|
let mut head_block = harness.chain.head_beacon_block().unwrap().deconstruct().0;
|
|
|
|
head_block.to_mut().body_mut().attestations_mut()[0].signature = AggregateSignature::empty();
|
|
|
|
|
|
|
|
let result = process_operations::process_attestations(
|
2019-11-12 05:09:33 +00:00
|
|
|
&mut state,
|
2021-07-09 06:15:32 +00:00
|
|
|
head_block.body(),
|
2021-07-23 00:23:53 +00:00
|
|
|
head_block.proposer_index(),
|
2021-07-09 06:15:32 +00:00
|
|
|
VerifySignatures::True,
|
2019-11-12 05:09:33 +00:00
|
|
|
&spec,
|
|
|
|
);
|
|
|
|
// Expecting BadSignature because we're signing with invalid secret_keys
|
|
|
|
assert_eq!(
|
|
|
|
result,
|
|
|
|
Err(BlockProcessingError::AttestationInvalid {
|
|
|
|
index: 0,
|
|
|
|
reason: AttestationInvalid::BadIndexedAttestation(
|
|
|
|
IndexedAttestationInvalid::BadSignature
|
|
|
|
)
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn invalid_attestation_included_too_early() {
|
|
|
|
let spec = MainnetEthSpec::default_spec();
|
2021-07-09 06:15:32 +00:00
|
|
|
let harness = get_harness::<MainnetEthSpec>(EPOCH_OFFSET, VALIDATOR_COUNT);
|
2019-11-12 05:09:33 +00:00
|
|
|
|
2021-07-09 06:15:32 +00:00
|
|
|
let mut state = harness.get_current_state();
|
|
|
|
let mut head_block = harness.chain.head_beacon_block().unwrap().deconstruct().0;
|
|
|
|
let new_attesation_slot = head_block.body().attestations()[0].data.slot
|
|
|
|
+ Slot::new(MainnetEthSpec::slots_per_epoch());
|
|
|
|
head_block.to_mut().body_mut().attestations_mut()[0]
|
|
|
|
.data
|
|
|
|
.slot = new_attesation_slot;
|
|
|
|
|
|
|
|
let result = process_operations::process_attestations(
|
2019-11-12 05:09:33 +00:00
|
|
|
&mut state,
|
2021-07-09 06:15:32 +00:00
|
|
|
head_block.body(),
|
2021-07-23 00:23:53 +00:00
|
|
|
head_block.proposer_index(),
|
2021-07-09 06:15:32 +00:00
|
|
|
VerifySignatures::True,
|
2019-11-12 05:09:33 +00:00
|
|
|
&spec,
|
|
|
|
);
|
|
|
|
|
|
|
|
// Expecting IncludedTooEarly because the shard included in the crosslink is bigger than expected
|
|
|
|
assert_eq!(
|
|
|
|
result,
|
|
|
|
Err(BlockProcessingError::AttestationInvalid {
|
|
|
|
index: 0,
|
|
|
|
reason: AttestationInvalid::IncludedTooEarly {
|
2021-07-09 06:15:32 +00:00
|
|
|
state: state.slot(),
|
2019-11-12 05:09:33 +00:00
|
|
|
delay: spec.min_attestation_inclusion_delay,
|
2021-07-09 06:15:32 +00:00
|
|
|
attestation: new_attesation_slot,
|
2019-11-12 05:09:33 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn invalid_attestation_included_too_late() {
|
|
|
|
let spec = MainnetEthSpec::default_spec();
|
2019-11-21 00:47:30 +00:00
|
|
|
// note to maintainer: might need to increase validator count if we get NoCommittee
|
2021-07-09 06:15:32 +00:00
|
|
|
let harness = get_harness::<MainnetEthSpec>(EPOCH_OFFSET, VALIDATOR_COUNT);
|
2019-11-12 05:09:33 +00:00
|
|
|
|
2021-07-09 06:15:32 +00:00
|
|
|
let mut state = harness.get_current_state();
|
|
|
|
let mut head_block = harness.chain.head_beacon_block().unwrap().deconstruct().0;
|
|
|
|
let new_attesation_slot = head_block.body().attestations()[0].data.slot
|
|
|
|
- Slot::new(MainnetEthSpec::slots_per_epoch());
|
|
|
|
head_block.to_mut().body_mut().attestations_mut()[0]
|
|
|
|
.data
|
|
|
|
.slot = new_attesation_slot;
|
|
|
|
|
|
|
|
let result = process_operations::process_attestations(
|
2019-11-12 05:09:33 +00:00
|
|
|
&mut state,
|
2021-07-09 06:15:32 +00:00
|
|
|
head_block.body(),
|
2021-07-23 00:23:53 +00:00
|
|
|
head_block.proposer_index(),
|
2021-07-09 06:15:32 +00:00
|
|
|
VerifySignatures::True,
|
2019-11-12 05:09:33 +00:00
|
|
|
&spec,
|
|
|
|
);
|
2019-11-21 00:47:30 +00:00
|
|
|
assert_eq!(
|
|
|
|
result,
|
|
|
|
Err(BlockProcessingError::AttestationInvalid {
|
|
|
|
index: 0,
|
|
|
|
reason: AttestationInvalid::IncludedTooLate {
|
2021-07-09 06:15:32 +00:00
|
|
|
state: state.slot(),
|
|
|
|
attestation: new_attesation_slot,
|
2019-11-21 00:47:30 +00:00
|
|
|
}
|
|
|
|
})
|
2019-11-12 05:09:33 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-02-10 23:19:36 +00:00
|
|
|
fn invalid_attestation_target_epoch_slot_mismatch() {
|
2019-11-12 05:09:33 +00:00
|
|
|
let spec = MainnetEthSpec::default_spec();
|
2019-11-21 00:47:30 +00:00
|
|
|
// note to maintainer: might need to increase validator count if we get NoCommittee
|
2021-07-09 06:15:32 +00:00
|
|
|
let harness = get_harness::<MainnetEthSpec>(EPOCH_OFFSET, VALIDATOR_COUNT);
|
2019-11-12 05:09:33 +00:00
|
|
|
|
2021-07-09 06:15:32 +00:00
|
|
|
let mut state = harness.get_current_state();
|
|
|
|
let mut head_block = harness.chain.head_beacon_block().unwrap().deconstruct().0;
|
|
|
|
head_block.to_mut().body_mut().attestations_mut()[0]
|
|
|
|
.data
|
|
|
|
.target
|
|
|
|
.epoch += Epoch::new(1);
|
|
|
|
|
|
|
|
let result = process_operations::process_attestations(
|
2019-11-12 05:09:33 +00:00
|
|
|
&mut state,
|
2021-07-09 06:15:32 +00:00
|
|
|
head_block.body(),
|
2021-07-23 00:23:53 +00:00
|
|
|
head_block.proposer_index(),
|
2021-07-09 06:15:32 +00:00
|
|
|
VerifySignatures::True,
|
2019-11-12 05:09:33 +00:00
|
|
|
&spec,
|
|
|
|
);
|
2020-02-10 23:19:36 +00:00
|
|
|
assert_eq!(
|
|
|
|
result,
|
|
|
|
Err(BlockProcessingError::AttestationInvalid {
|
|
|
|
index: 0,
|
|
|
|
reason: AttestationInvalid::TargetEpochSlotMismatch {
|
2021-07-09 06:15:32 +00:00
|
|
|
target_epoch: Epoch::new(EPOCH_OFFSET + 1),
|
|
|
|
slot_epoch: Epoch::new(EPOCH_OFFSET),
|
2020-02-10 23:19:36 +00:00
|
|
|
}
|
|
|
|
})
|
2019-11-12 05:09:33 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn valid_insert_attester_slashing() {
|
|
|
|
let spec = MainnetEthSpec::default_spec();
|
2021-07-09 06:15:32 +00:00
|
|
|
let harness = get_harness::<MainnetEthSpec>(EPOCH_OFFSET, VALIDATOR_COUNT);
|
2019-11-12 05:09:33 +00:00
|
|
|
|
2021-07-09 06:15:32 +00:00
|
|
|
let attester_slashing = harness.make_attester_slashing(vec![1, 2]);
|
|
|
|
|
|
|
|
let mut state = harness.get_current_state();
|
|
|
|
let result = process_operations::process_attester_slashings(
|
2019-11-12 05:09:33 +00:00
|
|
|
&mut state,
|
2021-07-09 06:15:32 +00:00
|
|
|
&[attester_slashing],
|
|
|
|
VerifySignatures::True,
|
2019-11-12 05:09:33 +00:00
|
|
|
&spec,
|
|
|
|
);
|
|
|
|
|
|
|
|
// Expecting Ok(()) because attester slashing is valid
|
|
|
|
assert_eq!(result, Ok(()));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn invalid_attester_slashing_not_slashable() {
|
|
|
|
let spec = MainnetEthSpec::default_spec();
|
2021-07-09 06:15:32 +00:00
|
|
|
let harness = get_harness::<MainnetEthSpec>(EPOCH_OFFSET, VALIDATOR_COUNT);
|
|
|
|
|
|
|
|
let mut attester_slashing = harness.make_attester_slashing(vec![1, 2]);
|
|
|
|
attester_slashing.attestation_1 = attester_slashing.attestation_2.clone();
|
|
|
|
|
|
|
|
let mut state = harness.get_current_state();
|
|
|
|
let result = process_operations::process_attester_slashings(
|
2019-11-12 05:09:33 +00:00
|
|
|
&mut state,
|
2021-07-09 06:15:32 +00:00
|
|
|
&[attester_slashing],
|
|
|
|
VerifySignatures::True,
|
2019-11-12 05:09:33 +00:00
|
|
|
&spec,
|
|
|
|
);
|
|
|
|
|
|
|
|
// Expecting NotSlashable because the two attestations are the same
|
|
|
|
assert_eq!(
|
|
|
|
result,
|
|
|
|
Err(BlockProcessingError::AttesterSlashingInvalid {
|
|
|
|
index: 0,
|
|
|
|
reason: AttesterSlashingInvalid::NotSlashable
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn invalid_attester_slashing_1_invalid() {
|
|
|
|
let spec = MainnetEthSpec::default_spec();
|
2021-07-09 06:15:32 +00:00
|
|
|
let harness = get_harness::<MainnetEthSpec>(EPOCH_OFFSET, VALIDATOR_COUNT);
|
2019-11-12 05:09:33 +00:00
|
|
|
|
2021-07-09 06:15:32 +00:00
|
|
|
let mut attester_slashing = harness.make_attester_slashing(vec![1, 2]);
|
|
|
|
attester_slashing.attestation_1.attesting_indices = VariableList::from(vec![2, 1]);
|
|
|
|
|
|
|
|
let mut state = harness.get_current_state();
|
|
|
|
let result = process_operations::process_attester_slashings(
|
2019-11-12 05:09:33 +00:00
|
|
|
&mut state,
|
2021-07-09 06:15:32 +00:00
|
|
|
&[attester_slashing],
|
|
|
|
VerifySignatures::True,
|
2019-11-12 05:09:33 +00:00
|
|
|
&spec,
|
|
|
|
);
|
|
|
|
|
2019-11-21 00:47:30 +00:00
|
|
|
assert_eq!(
|
|
|
|
result,
|
2020-05-08 23:37:21 +00:00
|
|
|
Err(
|
|
|
|
BlockOperationError::Invalid(AttesterSlashingInvalid::IndexedAttestation1Invalid(
|
|
|
|
BlockOperationError::Invalid(
|
|
|
|
IndexedAttestationInvalid::BadValidatorIndicesOrdering(0)
|
|
|
|
)
|
|
|
|
))
|
|
|
|
.into_with_index(0)
|
|
|
|
)
|
2019-11-12 05:09:33 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn invalid_attester_slashing_2_invalid() {
|
|
|
|
let spec = MainnetEthSpec::default_spec();
|
2021-07-09 06:15:32 +00:00
|
|
|
let harness = get_harness::<MainnetEthSpec>(EPOCH_OFFSET, VALIDATOR_COUNT);
|
2019-11-12 05:09:33 +00:00
|
|
|
|
2021-07-09 06:15:32 +00:00
|
|
|
let mut attester_slashing = harness.make_attester_slashing(vec![1, 2]);
|
|
|
|
attester_slashing.attestation_2.attesting_indices = VariableList::from(vec![2, 1]);
|
|
|
|
|
|
|
|
let mut state = harness.get_current_state();
|
|
|
|
let result = process_operations::process_attester_slashings(
|
2019-11-12 05:09:33 +00:00
|
|
|
&mut state,
|
2021-07-09 06:15:32 +00:00
|
|
|
&[attester_slashing],
|
|
|
|
VerifySignatures::True,
|
2019-11-12 05:09:33 +00:00
|
|
|
&spec,
|
|
|
|
);
|
|
|
|
|
2019-11-21 00:47:30 +00:00
|
|
|
assert_eq!(
|
|
|
|
result,
|
2020-05-08 23:37:21 +00:00
|
|
|
Err(
|
|
|
|
BlockOperationError::Invalid(AttesterSlashingInvalid::IndexedAttestation2Invalid(
|
|
|
|
BlockOperationError::Invalid(
|
|
|
|
IndexedAttestationInvalid::BadValidatorIndicesOrdering(0)
|
|
|
|
)
|
|
|
|
))
|
|
|
|
.into_with_index(0)
|
|
|
|
)
|
2019-11-12 05:09:33 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn valid_insert_proposer_slashing() {
|
|
|
|
let spec = MainnetEthSpec::default_spec();
|
2021-07-09 06:15:32 +00:00
|
|
|
let harness = get_harness::<MainnetEthSpec>(EPOCH_OFFSET, VALIDATOR_COUNT);
|
|
|
|
let proposer_slashing = harness.make_proposer_slashing(1);
|
|
|
|
let mut state = harness.get_current_state();
|
|
|
|
let result = process_operations::process_proposer_slashings(
|
2019-11-12 05:09:33 +00:00
|
|
|
&mut state,
|
2021-07-09 06:15:32 +00:00
|
|
|
&[proposer_slashing],
|
|
|
|
VerifySignatures::True,
|
2019-11-12 05:09:33 +00:00
|
|
|
&spec,
|
|
|
|
);
|
2021-07-09 06:15:32 +00:00
|
|
|
// Expecting Ok(_) because we inserted a valid proposer slashing
|
|
|
|
assert!(result.is_ok());
|
2019-11-12 05:09:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn invalid_proposer_slashing_proposals_identical() {
|
|
|
|
let spec = MainnetEthSpec::default_spec();
|
2021-07-09 06:15:32 +00:00
|
|
|
let harness = get_harness::<MainnetEthSpec>(EPOCH_OFFSET, VALIDATOR_COUNT);
|
2019-11-12 05:09:33 +00:00
|
|
|
|
2021-07-09 06:15:32 +00:00
|
|
|
let mut proposer_slashing = harness.make_proposer_slashing(1);
|
|
|
|
proposer_slashing.signed_header_1.message = proposer_slashing.signed_header_2.message.clone();
|
|
|
|
|
|
|
|
let mut state = harness.get_current_state();
|
|
|
|
let result = process_operations::process_proposer_slashings(
|
2019-11-12 05:09:33 +00:00
|
|
|
&mut state,
|
2021-07-09 06:15:32 +00:00
|
|
|
&[proposer_slashing],
|
|
|
|
VerifySignatures::True,
|
2019-11-12 05:09:33 +00:00
|
|
|
&spec,
|
|
|
|
);
|
2021-07-09 06:15:32 +00:00
|
|
|
|
2019-11-12 05:09:33 +00:00
|
|
|
// Expecting ProposalsIdentical because we the two headers are identical
|
|
|
|
assert_eq!(
|
|
|
|
result,
|
|
|
|
Err(BlockProcessingError::ProposerSlashingInvalid {
|
|
|
|
index: 0,
|
|
|
|
reason: ProposerSlashingInvalid::ProposalsIdentical
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn invalid_proposer_slashing_proposer_unknown() {
|
|
|
|
let spec = MainnetEthSpec::default_spec();
|
2021-07-09 06:15:32 +00:00
|
|
|
let harness = get_harness::<MainnetEthSpec>(EPOCH_OFFSET, VALIDATOR_COUNT);
|
2019-11-12 05:09:33 +00:00
|
|
|
|
2021-07-09 06:15:32 +00:00
|
|
|
let mut proposer_slashing = harness.make_proposer_slashing(1);
|
|
|
|
proposer_slashing.signed_header_1.message.proposer_index = 3_141_592;
|
|
|
|
proposer_slashing.signed_header_2.message.proposer_index = 3_141_592;
|
|
|
|
|
|
|
|
let mut state = harness.get_current_state();
|
|
|
|
let result = process_operations::process_proposer_slashings(
|
2019-11-12 05:09:33 +00:00
|
|
|
&mut state,
|
2021-07-09 06:15:32 +00:00
|
|
|
&[proposer_slashing],
|
|
|
|
VerifySignatures::True,
|
2019-11-12 05:09:33 +00:00
|
|
|
&spec,
|
|
|
|
);
|
|
|
|
|
|
|
|
// Expecting ProposerUnknown because validator_index is unknown
|
|
|
|
assert_eq!(
|
|
|
|
result,
|
|
|
|
Err(BlockProcessingError::ProposerSlashingInvalid {
|
|
|
|
index: 0,
|
|
|
|
reason: ProposerSlashingInvalid::ProposerUnknown(3_141_592)
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-07-09 06:15:32 +00:00
|
|
|
fn invalid_proposer_slashing_duplicate_slashing() {
|
2019-11-12 05:09:33 +00:00
|
|
|
let spec = MainnetEthSpec::default_spec();
|
2021-07-09 06:15:32 +00:00
|
|
|
let harness = get_harness::<MainnetEthSpec>(EPOCH_OFFSET, VALIDATOR_COUNT);
|
2019-11-12 05:09:33 +00:00
|
|
|
|
2021-07-09 06:15:32 +00:00
|
|
|
let proposer_slashing = harness.make_proposer_slashing(1);
|
|
|
|
let mut state = harness.get_current_state();
|
|
|
|
let result_1 = process_operations::process_proposer_slashings(
|
2019-11-12 05:09:33 +00:00
|
|
|
&mut state,
|
2021-07-09 06:15:32 +00:00
|
|
|
&[proposer_slashing.clone()],
|
|
|
|
VerifySignatures::False,
|
2019-11-12 05:09:33 +00:00
|
|
|
&spec,
|
|
|
|
);
|
2021-07-09 06:15:32 +00:00
|
|
|
assert!(result_1.is_ok());
|
2019-11-12 05:09:33 +00:00
|
|
|
|
2021-07-09 06:15:32 +00:00
|
|
|
let result_2 = process_operations::process_proposer_slashings(
|
2020-04-30 05:21:43 +00:00
|
|
|
&mut state,
|
2021-07-09 06:15:32 +00:00
|
|
|
&[proposer_slashing],
|
|
|
|
VerifySignatures::False,
|
2020-04-30 05:21:43 +00:00
|
|
|
&spec,
|
|
|
|
);
|
2021-07-09 06:15:32 +00:00
|
|
|
// Expecting ProposerNotSlashable because we've already slashed the validator
|
2020-04-30 05:21:43 +00:00
|
|
|
assert_eq!(
|
2021-07-09 06:15:32 +00:00
|
|
|
result_2,
|
2020-04-30 05:21:43 +00:00
|
|
|
Err(BlockProcessingError::ProposerSlashingInvalid {
|
2021-07-09 06:15:32 +00:00
|
|
|
index: 0,
|
|
|
|
reason: ProposerSlashingInvalid::ProposerNotSlashable(1)
|
2020-04-30 05:21:43 +00:00
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-11-12 05:09:33 +00:00
|
|
|
#[test]
|
|
|
|
fn invalid_bad_proposal_1_signature() {
|
|
|
|
let spec = MainnetEthSpec::default_spec();
|
2021-07-09 06:15:32 +00:00
|
|
|
let harness = get_harness::<MainnetEthSpec>(EPOCH_OFFSET, VALIDATOR_COUNT);
|
|
|
|
let mut proposer_slashing = harness.make_proposer_slashing(1);
|
|
|
|
proposer_slashing.signed_header_1.signature = Signature::empty();
|
|
|
|
let mut state = harness.get_current_state();
|
|
|
|
let result = process_operations::process_proposer_slashings(
|
2019-11-12 05:09:33 +00:00
|
|
|
&mut state,
|
2021-07-09 06:15:32 +00:00
|
|
|
&[proposer_slashing],
|
|
|
|
VerifySignatures::True,
|
2019-11-12 05:09:33 +00:00
|
|
|
&spec,
|
|
|
|
);
|
|
|
|
|
|
|
|
// Expecting BadProposal1Signature because signature of proposal 1 is invalid
|
|
|
|
assert_eq!(
|
|
|
|
result,
|
|
|
|
Err(BlockProcessingError::ProposerSlashingInvalid {
|
|
|
|
index: 0,
|
|
|
|
reason: ProposerSlashingInvalid::BadProposal1Signature
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn invalid_bad_proposal_2_signature() {
|
|
|
|
let spec = MainnetEthSpec::default_spec();
|
2021-07-09 06:15:32 +00:00
|
|
|
let harness = get_harness::<MainnetEthSpec>(EPOCH_OFFSET, VALIDATOR_COUNT);
|
|
|
|
let mut proposer_slashing = harness.make_proposer_slashing(1);
|
|
|
|
proposer_slashing.signed_header_2.signature = Signature::empty();
|
|
|
|
let mut state = harness.get_current_state();
|
|
|
|
let result = process_operations::process_proposer_slashings(
|
2019-11-12 05:09:33 +00:00
|
|
|
&mut state,
|
2021-07-09 06:15:32 +00:00
|
|
|
&[proposer_slashing],
|
|
|
|
VerifySignatures::True,
|
2019-11-12 05:09:33 +00:00
|
|
|
&spec,
|
|
|
|
);
|
|
|
|
|
|
|
|
// Expecting BadProposal2Signature because signature of proposal 2 is invalid
|
|
|
|
assert_eq!(
|
|
|
|
result,
|
|
|
|
Err(BlockProcessingError::ProposerSlashingInvalid {
|
|
|
|
index: 0,
|
|
|
|
reason: ProposerSlashingInvalid::BadProposal2Signature
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn invalid_proposer_slashing_proposal_epoch_mismatch() {
|
|
|
|
let spec = MainnetEthSpec::default_spec();
|
2021-07-09 06:15:32 +00:00
|
|
|
let harness = get_harness::<MainnetEthSpec>(EPOCH_OFFSET, VALIDATOR_COUNT);
|
|
|
|
let mut proposer_slashing = harness.make_proposer_slashing(1);
|
|
|
|
proposer_slashing.signed_header_1.message.slot = Slot::new(0);
|
|
|
|
proposer_slashing.signed_header_2.message.slot = Slot::new(128);
|
|
|
|
let mut state = harness.get_current_state();
|
|
|
|
let result = process_operations::process_proposer_slashings(
|
2019-11-12 05:09:33 +00:00
|
|
|
&mut state,
|
2021-07-09 06:15:32 +00:00
|
|
|
&[proposer_slashing],
|
|
|
|
VerifySignatures::False,
|
2019-11-12 05:09:33 +00:00
|
|
|
&spec,
|
|
|
|
);
|
|
|
|
|
|
|
|
// Expecting ProposalEpochMismatch because the two epochs are different
|
|
|
|
assert_eq!(
|
|
|
|
result,
|
|
|
|
Err(BlockProcessingError::ProposerSlashingInvalid {
|
|
|
|
index: 0,
|
2019-11-21 00:47:30 +00:00
|
|
|
reason: ProposerSlashingInvalid::ProposalSlotMismatch(
|
2021-01-19 00:34:28 +00:00
|
|
|
Slot::from(0_u64),
|
2021-01-28 23:31:06 +00:00
|
|
|
Slot::from(128_u64)
|
2019-11-12 05:09:33 +00:00
|
|
|
)
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|