Consensus updates for v0.12 (#1228)

* Update state processing for v0.12

* Fix EF test runners for v0.12

* Fix some tests

* Fix broken attestation verification test

* More test fixes

* Fix typo found in review
This commit is contained in:
Michael Sproul
2020-06-03 13:34:01 +10:00
parent 197adeff0b
commit fe03ff0f21
29 changed files with 359 additions and 323 deletions

View File

@@ -176,6 +176,10 @@ impl<T> From<ArithError> for BlockOperationError<T> {
pub enum HeaderInvalid {
ProposalSignatureInvalid,
StateSlotMismatch,
OlderThanLatestBlockHeader {
latest_block_header_slot: Slot,
block_slot: Slot,
},
ProposerIndexMismatch {
block_proposer_index: usize,
state_proposer_index: usize,
@@ -255,9 +259,6 @@ pub enum AttestationInvalid {
attestation: Checkpoint,
is_current: bool,
},
/// There are no set bits on the attestation -- an attestation must be signed by at least one
/// validator.
AggregationBitfieldIsEmpty,
/// The aggregation bitfield length is not the smallest possible size to represent the committee.
BadAggregationBitfieldLength {
committee_len: usize,
@@ -291,10 +292,8 @@ impl From<BlockOperationError<IndexedAttestationInvalid>>
#[derive(Debug, PartialEq, Clone)]
pub enum IndexedAttestationInvalid {
/// The number of indices exceeds the global maximum.
///
/// (max_indices, indices_given)
MaxIndicesExceed(usize, usize),
/// The number of indices is 0.
IndicesEmpty,
/// The validator indices were not in increasing order.
///
/// The error occurred between the given `index` and `index + 1`

View File

@@ -20,11 +20,8 @@ pub fn is_valid_indexed_attestation<T: EthSpec>(
) -> Result<()> {
let indices = &indexed_attestation.attesting_indices;
// Verify max number of indices
verify!(
indices.len() <= T::MaxValidatorsPerCommittee::to_usize(),
Invalid::MaxIndicesExceed(T::MaxValidatorsPerCommittee::to_usize(), indices.len())
);
// Verify that indices aren't empty
verify!(!indices.is_empty(), Invalid::IndicesEmpty);
// Check that indices are sorted and unique
let check_sorted = |list: &[u64]| -> Result<()> {

View File

@@ -11,7 +11,7 @@ use types::{
AggregateSignature, AttesterSlashing, BeaconBlock, BeaconState, BeaconStateError, ChainSpec,
DepositData, Domain, EthSpec, Fork, Hash256, IndexedAttestation, ProposerSlashing, PublicKey,
Signature, SignedAggregateAndProof, SignedBeaconBlock, SignedBeaconBlockHeader, SignedRoot,
SignedVoluntaryExit, SigningRoot,
SignedVoluntaryExit, SigningData,
};
pub type Result<T> = std::result::Result<T, Error>;
@@ -92,7 +92,7 @@ where
);
let message = if let Some(root) = block_root {
SigningRoot {
SigningData {
object_root: root,
domain,
}

View File

@@ -58,13 +58,6 @@ pub fn verify_attestation_for_state<T: EthSpec>(
) -> Result<()> {
let data = &attestation.data;
// This emptiness check is required *in addition* to the length check in `get_attesting_indices`
// because we can parse a bitfield and know its length, even if it has no bits set.
verify!(
!attestation.aggregation_bits.is_zero(),
Invalid::AggregationBitfieldIsEmpty
);
verify!(
data.index < state.get_committee_count_at_slot(data.slot)?,
Invalid::BadCommitteeIndex

View File

@@ -78,10 +78,10 @@ fn verify_exit_parametric<T: EthSpec>(
// Verify the validator has been active long enough.
verify!(
state.current_epoch() >= validator.activation_epoch + spec.persistent_committee_period,
state.current_epoch() >= validator.activation_epoch + spec.shard_committee_period,
ExitInvalid::TooYoungToExit {
current_epoch: state.current_epoch(),
earliest_exit_epoch: validator.activation_epoch + spec.persistent_committee_period,
earliest_exit_epoch: validator.activation_epoch + spec.shard_committee_period,
}
);