mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-17 11:52:42 +00:00
Merge remote-tracking branch 'origin/unstable' into tree-states
This commit is contained in:
@@ -302,7 +302,7 @@ where
|
||||
|
||||
/// Include the signature of the block's sync aggregate (if it exists) for verification.
|
||||
pub fn include_sync_aggregate(&mut self, block: &'a SignedBeaconBlock<T>) -> Result<()> {
|
||||
if let Some(sync_aggregate) = block.message().body().sync_aggregate() {
|
||||
if let Ok(sync_aggregate) = block.message().body().sync_aggregate() {
|
||||
if let Some(signature_set) = sync_aggregate_signature_set(
|
||||
&self.decompressor,
|
||||
sync_aggregate,
|
||||
|
||||
@@ -57,6 +57,19 @@ pub enum BlockProcessingError {
|
||||
ArithError(ArithError),
|
||||
InconsistentBlockFork(InconsistentFork),
|
||||
InconsistentStateFork(InconsistentFork),
|
||||
ExecutionHashChainIncontiguous {
|
||||
expected: Hash256,
|
||||
found: Hash256,
|
||||
},
|
||||
ExecutionRandaoMismatch {
|
||||
expected: Hash256,
|
||||
found: Hash256,
|
||||
},
|
||||
ExecutionInvalidTimestamp {
|
||||
expected: u64,
|
||||
found: u64,
|
||||
},
|
||||
ExecutionInvalid,
|
||||
#[cfg(feature = "milhouse")]
|
||||
MilhouseError(milhouse::Error),
|
||||
}
|
||||
|
||||
@@ -228,7 +228,7 @@ pub fn process_attestations<'a, T: EthSpec>(
|
||||
BeaconBlockBodyRef::Base(_) => {
|
||||
base::process_attestations(state, block_body.attestations(), verify_signatures, spec)?;
|
||||
}
|
||||
BeaconBlockBodyRef::Altair(_) => {
|
||||
BeaconBlockBodyRef::Altair(_) | BeaconBlockBodyRef::Merge(_) => {
|
||||
altair::process_attestations(
|
||||
state,
|
||||
block_body.attestations(),
|
||||
@@ -353,15 +353,15 @@ pub fn process_deposit<T: EthSpec>(
|
||||
state.validators_mut().push(validator)?;
|
||||
state.balances_mut().push(deposit.data.amount)?;
|
||||
|
||||
// Altair-specific initializations.
|
||||
if let BeaconState::Altair(altair_state) = state {
|
||||
altair_state
|
||||
.previous_epoch_participation
|
||||
.push(ParticipationFlags::default())?;
|
||||
altair_state
|
||||
.current_epoch_participation
|
||||
.push(ParticipationFlags::default())?;
|
||||
altair_state.inactivity_scores.push(0)?;
|
||||
// Altair or later initializations.
|
||||
if let Ok(previous_epoch_participation) = state.previous_epoch_participation_mut() {
|
||||
previous_epoch_participation.push(ParticipationFlags::default())?;
|
||||
}
|
||||
if let Ok(current_epoch_participation) = state.current_epoch_participation_mut() {
|
||||
current_epoch_participation.push(ParticipationFlags::default())?;
|
||||
}
|
||||
if let Ok(inactivity_scores) = state.inactivity_scores_mut() {
|
||||
inactivity_scores.push(0)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,10 @@ use crate::per_block_processing::errors::{
|
||||
DepositInvalid, HeaderInvalid, IndexedAttestationInvalid, IntoWithIndex,
|
||||
ProposerSlashingInvalid,
|
||||
};
|
||||
use crate::{per_block_processing::process_operations, BlockSignatureStrategy, VerifySignatures};
|
||||
use crate::{
|
||||
per_block_processing::process_operations, BlockSignatureStrategy, VerifyBlockRoot,
|
||||
VerifySignatures,
|
||||
};
|
||||
use beacon_chain::test_utils::{BeaconChainHarness, EphemeralHarnessType};
|
||||
use lazy_static::lazy_static;
|
||||
use ssz_types::Bitfield;
|
||||
@@ -65,6 +68,7 @@ fn valid_block_ok() {
|
||||
&block,
|
||||
None,
|
||||
BlockSignatureStrategy::VerifyIndividual,
|
||||
VerifyBlockRoot::True,
|
||||
&spec,
|
||||
);
|
||||
|
||||
@@ -88,6 +92,7 @@ fn invalid_block_header_state_slot() {
|
||||
&SignedBeaconBlock::from_block(block, signature),
|
||||
None,
|
||||
BlockSignatureStrategy::VerifyIndividual,
|
||||
VerifyBlockRoot::True,
|
||||
&spec,
|
||||
);
|
||||
|
||||
@@ -116,6 +121,7 @@ fn invalid_parent_block_root() {
|
||||
&SignedBeaconBlock::from_block(block, signature),
|
||||
None,
|
||||
BlockSignatureStrategy::VerifyIndividual,
|
||||
VerifyBlockRoot::True,
|
||||
&spec,
|
||||
);
|
||||
|
||||
@@ -145,6 +151,7 @@ fn invalid_block_signature() {
|
||||
&SignedBeaconBlock::from_block(block, Signature::empty()),
|
||||
None,
|
||||
BlockSignatureStrategy::VerifyIndividual,
|
||||
VerifyBlockRoot::True,
|
||||
&spec,
|
||||
);
|
||||
|
||||
@@ -174,6 +181,7 @@ fn invalid_randao_reveal_signature() {
|
||||
&signed_block,
|
||||
None,
|
||||
BlockSignatureStrategy::VerifyIndividual,
|
||||
VerifyBlockRoot::True,
|
||||
&spec,
|
||||
);
|
||||
|
||||
@@ -187,14 +195,13 @@ fn valid_4_deposits() {
|
||||
let harness = get_harness::<MainnetEthSpec>(EPOCH_OFFSET, VALIDATOR_COUNT);
|
||||
let mut state = harness.get_current_state();
|
||||
|
||||
let (deposits, mut state) = harness.make_deposits(&mut state, 4, None, None);
|
||||
let (deposits, state) = harness.make_deposits(&mut state, 4, None, None);
|
||||
let deposits = VariableList::from(deposits);
|
||||
|
||||
let mut head_block = harness.chain.head_beacon_block().unwrap().deconstruct().0;
|
||||
*head_block.to_mut().body_mut().deposits_mut() = deposits;
|
||||
|
||||
let result =
|
||||
process_operations::process_deposits(&mut state, head_block.body().deposits(), &spec);
|
||||
let result = process_operations::process_deposits(state, head_block.body().deposits(), &spec);
|
||||
|
||||
// Expecting Ok because these are valid deposits.
|
||||
assert_eq!(result, Ok(()));
|
||||
@@ -206,7 +213,7 @@ fn invalid_deposit_deposit_count_too_big() {
|
||||
let harness = get_harness::<MainnetEthSpec>(EPOCH_OFFSET, VALIDATOR_COUNT);
|
||||
let mut state = harness.get_current_state();
|
||||
|
||||
let (deposits, mut state) = harness.make_deposits(&mut state, 1, None, None);
|
||||
let (deposits, state) = harness.make_deposits(&mut state, 1, None, None);
|
||||
let deposits = VariableList::from(deposits);
|
||||
|
||||
let mut head_block = harness.chain.head_beacon_block().unwrap().deconstruct().0;
|
||||
@@ -214,8 +221,7 @@ fn invalid_deposit_deposit_count_too_big() {
|
||||
|
||||
let big_deposit_count = NUM_DEPOSITS + 1;
|
||||
state.eth1_data_mut().deposit_count = big_deposit_count;
|
||||
let result =
|
||||
process_operations::process_deposits(&mut state, head_block.body().deposits(), &spec);
|
||||
let result = process_operations::process_deposits(state, head_block.body().deposits(), &spec);
|
||||
|
||||
// Expecting DepositCountInvalid because we incremented the deposit_count
|
||||
assert_eq!(
|
||||
@@ -233,7 +239,7 @@ fn invalid_deposit_count_too_small() {
|
||||
let harness = get_harness::<MainnetEthSpec>(EPOCH_OFFSET, VALIDATOR_COUNT);
|
||||
let mut state = harness.get_current_state();
|
||||
|
||||
let (deposits, mut state) = harness.make_deposits(&mut state, 1, None, None);
|
||||
let (deposits, state) = harness.make_deposits(&mut state, 1, None, None);
|
||||
let deposits = VariableList::from(deposits);
|
||||
|
||||
let mut head_block = harness.chain.head_beacon_block().unwrap().deconstruct().0;
|
||||
@@ -241,8 +247,7 @@ fn invalid_deposit_count_too_small() {
|
||||
|
||||
let small_deposit_count = NUM_DEPOSITS - 1;
|
||||
state.eth1_data_mut().deposit_count = small_deposit_count;
|
||||
let result =
|
||||
process_operations::process_deposits(&mut state, head_block.body().deposits(), &spec);
|
||||
let result = process_operations::process_deposits(state, head_block.body().deposits(), &spec);
|
||||
|
||||
// Expecting DepositCountInvalid because we decremented the deposit_count
|
||||
assert_eq!(
|
||||
@@ -260,7 +265,7 @@ fn invalid_deposit_bad_merkle_proof() {
|
||||
let harness = get_harness::<MainnetEthSpec>(EPOCH_OFFSET, VALIDATOR_COUNT);
|
||||
let mut state = harness.get_current_state();
|
||||
|
||||
let (deposits, mut state) = harness.make_deposits(&mut state, 1, None, None);
|
||||
let (deposits, state) = harness.make_deposits(&mut state, 1, None, None);
|
||||
let deposits = VariableList::from(deposits);
|
||||
|
||||
let mut head_block = harness.chain.head_beacon_block().unwrap().deconstruct().0;
|
||||
@@ -270,8 +275,7 @@ fn invalid_deposit_bad_merkle_proof() {
|
||||
// Manually offsetting deposit count and index to trigger bad merkle proof
|
||||
state.eth1_data_mut().deposit_count += 1;
|
||||
*state.eth1_deposit_index_mut() += 1;
|
||||
let result =
|
||||
process_operations::process_deposits(&mut state, head_block.body().deposits(), &spec);
|
||||
let result = process_operations::process_deposits(state, head_block.body().deposits(), &spec);
|
||||
|
||||
// Expecting BadMerkleProof because the proofs were created with different indices
|
||||
assert_eq!(
|
||||
@@ -289,15 +293,14 @@ fn invalid_deposit_wrong_sig() {
|
||||
let harness = get_harness::<MainnetEthSpec>(EPOCH_OFFSET, VALIDATOR_COUNT);
|
||||
let mut state = harness.get_current_state();
|
||||
|
||||
let (deposits, mut state) =
|
||||
let (deposits, state) =
|
||||
harness.make_deposits(&mut state, 1, None, Some(SignatureBytes::empty()));
|
||||
let deposits = VariableList::from(deposits);
|
||||
|
||||
let mut head_block = harness.chain.head_beacon_block().unwrap().deconstruct().0;
|
||||
*head_block.to_mut().body_mut().deposits_mut() = deposits;
|
||||
|
||||
let result =
|
||||
process_operations::process_deposits(&mut state, head_block.body().deposits(), &spec);
|
||||
let result = process_operations::process_deposits(state, head_block.body().deposits(), &spec);
|
||||
// Expecting Ok(()) even though the block signature does not correspond to the correct public key
|
||||
assert_eq!(result, Ok(()));
|
||||
}
|
||||
@@ -308,15 +311,14 @@ fn invalid_deposit_invalid_pub_key() {
|
||||
let harness = get_harness::<MainnetEthSpec>(EPOCH_OFFSET, VALIDATOR_COUNT);
|
||||
let mut state = harness.get_current_state();
|
||||
|
||||
let (deposits, mut state) =
|
||||
let (deposits, state) =
|
||||
harness.make_deposits(&mut state, 1, Some(PublicKeyBytes::empty()), None);
|
||||
let deposits = VariableList::from(deposits);
|
||||
|
||||
let mut head_block = harness.chain.head_beacon_block().unwrap().deconstruct().0;
|
||||
*head_block.to_mut().body_mut().deposits_mut() = deposits;
|
||||
|
||||
let result =
|
||||
process_operations::process_deposits(&mut state, head_block.body().deposits(), &spec);
|
||||
let result = process_operations::process_deposits(state, head_block.body().deposits(), &spec);
|
||||
|
||||
// Expecting Ok(()) even though we passed in invalid publickeybytes in the public key field of the deposit data.
|
||||
assert_eq!(result, Ok(()));
|
||||
|
||||
Reference in New Issue
Block a user