mirror of
https://github.com/sigp/lighthouse.git
synced 2026-07-04 21:34:36 +00:00
Update to v0.9.1
This commit is contained in:
@@ -4,7 +4,7 @@ default:
|
|||||||
image: 'sigp/lighthouse:latest'
|
image: 'sigp/lighthouse:latest'
|
||||||
cache:
|
cache:
|
||||||
paths:
|
paths:
|
||||||
- tests/ef_tests/*-v0.9.0.tar.gz
|
- tests/ef_tests/*-v0.9.1.tar.gz
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- test
|
- test
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ use std::sync::Arc;
|
|||||||
use store::MemoryStore;
|
use store::MemoryStore;
|
||||||
use tree_hash::{SignedRoot, TreeHash};
|
use tree_hash::{SignedRoot, TreeHash};
|
||||||
use types::{
|
use types::{
|
||||||
AggregateSignature, Attestation, AttestationDataAndCustodyBit, BeaconBlock, BeaconState,
|
AggregateSignature, Attestation, BeaconBlock, BeaconState, BitList, ChainSpec, Domain, EthSpec,
|
||||||
BitList, ChainSpec, Domain, EthSpec, Hash256, Keypair, SecretKey, Signature, Slot,
|
Hash256, Keypair, SecretKey, Signature, Slot,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub use types::test_utils::generate_deterministic_keypairs;
|
pub use types::test_utils::generate_deterministic_keypairs;
|
||||||
@@ -321,15 +321,9 @@ where
|
|||||||
aggregation_bits
|
aggregation_bits
|
||||||
.set(i, true)
|
.set(i, true)
|
||||||
.expect("should be able to set aggregation bits");
|
.expect("should be able to set aggregation bits");
|
||||||
let custody_bits = BitList::with_capacity(committee_size)
|
|
||||||
.expect("should make custody bits");
|
|
||||||
|
|
||||||
let signature = {
|
let signature = {
|
||||||
let message = AttestationDataAndCustodyBit {
|
let message = data.tree_hash_root();
|
||||||
data: data.clone(),
|
|
||||||
custody_bit: false,
|
|
||||||
}
|
|
||||||
.tree_hash_root();
|
|
||||||
|
|
||||||
let domain = spec.get_domain(
|
let domain = spec.get_domain(
|
||||||
data.target.epoch,
|
data.target.epoch,
|
||||||
@@ -350,7 +344,6 @@ where
|
|||||||
let attestation = Attestation {
|
let attestation = Attestation {
|
||||||
aggregation_bits,
|
aggregation_bits,
|
||||||
data,
|
data,
|
||||||
custody_bits,
|
|
||||||
signature,
|
signature,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -347,8 +347,6 @@ pub fn get_new_attestation<T: BeaconChainTypes + 'static>(req: Request<Body>) ->
|
|||||||
let attestation: Attestation<T::EthSpec> = Attestation {
|
let attestation: Attestation<T::EthSpec> = Attestation {
|
||||||
aggregation_bits,
|
aggregation_bits,
|
||||||
data: attestation_data,
|
data: attestation_data,
|
||||||
custody_bits: BitList::with_capacity(val_duty.committee_len)
|
|
||||||
.expect("Should be able to create an empty BitList for the custody bits."),
|
|
||||||
signature: AggregateSignature::new(),
|
signature: AggregateSignature::new(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use types::*;
|
|||||||
|
|
||||||
/// Returns validator indices which participated in the attestation, sorted by increasing index.
|
/// Returns validator indices which participated in the attestation, sorted by increasing index.
|
||||||
///
|
///
|
||||||
/// Spec v0.9.0
|
/// Spec v0.9.1
|
||||||
pub fn get_attesting_indices<T: EthSpec>(
|
pub fn get_attesting_indices<T: EthSpec>(
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
attestation_data: &AttestationData,
|
attestation_data: &AttestationData,
|
||||||
|
|||||||
@@ -6,117 +6,19 @@ type Result<T> = std::result::Result<T, BlockOperationError<Invalid>>;
|
|||||||
|
|
||||||
/// Convert `attestation` to (almost) indexed-verifiable form.
|
/// Convert `attestation` to (almost) indexed-verifiable form.
|
||||||
///
|
///
|
||||||
/// Spec v0.9.0
|
/// Spec v0.9.1
|
||||||
pub fn get_indexed_attestation<T: EthSpec>(
|
pub fn get_indexed_attestation<T: EthSpec>(
|
||||||
state: &BeaconState<T>,
|
state: &BeaconState<T>,
|
||||||
attestation: &Attestation<T>,
|
attestation: &Attestation<T>,
|
||||||
) -> Result<IndexedAttestation<T>> {
|
) -> Result<IndexedAttestation<T>> {
|
||||||
// Note: we rely on both calls to `get_attesting_indices` to check the bitfield lengths
|
|
||||||
// against the committee length
|
|
||||||
let attesting_indices =
|
let attesting_indices =
|
||||||
get_attesting_indices(state, &attestation.data, &attestation.aggregation_bits)?;
|
get_attesting_indices(state, &attestation.data, &attestation.aggregation_bits)?;
|
||||||
|
|
||||||
let custody_bit_1_indices =
|
|
||||||
get_attesting_indices(state, &attestation.data, &attestation.custody_bits)?;
|
|
||||||
|
|
||||||
verify!(
|
|
||||||
custody_bit_1_indices.is_subset(&attesting_indices),
|
|
||||||
Invalid::CustodyBitfieldNotSubset
|
|
||||||
);
|
|
||||||
|
|
||||||
let custody_bit_0_indices = &attesting_indices - &custody_bit_1_indices;
|
|
||||||
|
|
||||||
Ok(IndexedAttestation {
|
Ok(IndexedAttestation {
|
||||||
custody_bit_0_indices: VariableList::new(
|
attesting_indices: VariableList::new(
|
||||||
custody_bit_0_indices
|
attesting_indices.into_iter().map(|x| x as u64).collect(),
|
||||||
.into_iter()
|
|
||||||
.map(|x| x as u64)
|
|
||||||
.collect(),
|
|
||||||
)?,
|
|
||||||
custody_bit_1_indices: VariableList::new(
|
|
||||||
custody_bit_1_indices
|
|
||||||
.into_iter()
|
|
||||||
.map(|x| x as u64)
|
|
||||||
.collect(),
|
|
||||||
)?,
|
)?,
|
||||||
data: attestation.data.clone(),
|
data: attestation.data.clone(),
|
||||||
signature: attestation.signature.clone(),
|
signature: attestation.signature.clone(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod test {
|
|
||||||
use super::*;
|
|
||||||
use itertools::{Either, Itertools};
|
|
||||||
use types::test_utils::*;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn custody_bitfield_indexing() {
|
|
||||||
let validator_count = 128;
|
|
||||||
let spec = MinimalEthSpec::default_spec();
|
|
||||||
let state_builder =
|
|
||||||
TestingBeaconStateBuilder::<MinimalEthSpec>::from_default_keypairs_file_if_exists(
|
|
||||||
validator_count,
|
|
||||||
&spec,
|
|
||||||
);
|
|
||||||
let (mut state, keypairs) = state_builder.build();
|
|
||||||
state.build_all_caches(&spec).unwrap();
|
|
||||||
state.slot += 1;
|
|
||||||
|
|
||||||
let index = 0;
|
|
||||||
let bc = state.get_beacon_committee(Slot::new(0), index).unwrap();
|
|
||||||
|
|
||||||
// Make a third of the validators sign with custody bit 0, a third with custody bit 1
|
|
||||||
// and a third not sign at all.
|
|
||||||
assert!(
|
|
||||||
bc.committee.len() >= 4,
|
|
||||||
"need at least 4 validators per committee for this test to work"
|
|
||||||
);
|
|
||||||
let (mut bit_0_indices, mut bit_1_indices): (Vec<_>, Vec<_>) = bc
|
|
||||||
.committee
|
|
||||||
.iter()
|
|
||||||
.enumerate()
|
|
||||||
.filter(|(i, _)| i % 3 != 0)
|
|
||||||
.partition_map(|(i, index)| {
|
|
||||||
if i % 3 == 1 {
|
|
||||||
Either::Left(*index)
|
|
||||||
} else {
|
|
||||||
Either::Right(*index)
|
|
||||||
}
|
|
||||||
});
|
|
||||||
assert!(!bit_0_indices.is_empty());
|
|
||||||
assert!(!bit_1_indices.is_empty());
|
|
||||||
|
|
||||||
let bit_0_keys = bit_0_indices
|
|
||||||
.iter()
|
|
||||||
.map(|validator_index| &keypairs[*validator_index].sk)
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
let bit_1_keys = bit_1_indices
|
|
||||||
.iter()
|
|
||||||
.map(|validator_index| &keypairs[*validator_index].sk)
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
|
|
||||||
let mut attestation_builder =
|
|
||||||
TestingAttestationBuilder::new(&state, &bc.committee, bc.slot, index);
|
|
||||||
attestation_builder
|
|
||||||
.sign(&bit_0_indices, &bit_0_keys, &state.fork, &spec, false)
|
|
||||||
.sign(&bit_1_indices, &bit_1_keys, &state.fork, &spec, true);
|
|
||||||
let attestation = attestation_builder.build();
|
|
||||||
|
|
||||||
let indexed_attestation = get_indexed_attestation(&state, &attestation).unwrap();
|
|
||||||
|
|
||||||
bit_0_indices.sort();
|
|
||||||
bit_1_indices.sort();
|
|
||||||
|
|
||||||
assert!(indexed_attestation
|
|
||||||
.custody_bit_0_indices
|
|
||||||
.iter()
|
|
||||||
.copied()
|
|
||||||
.eq(bit_0_indices.iter().map(|idx| *idx as u64)));
|
|
||||||
assert!(indexed_attestation
|
|
||||||
.custody_bit_1_indices
|
|
||||||
.iter()
|
|
||||||
.copied()
|
|
||||||
.eq(bit_1_indices.iter().map(|idx| *idx as u64)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
use super::errors::{BlockOperationError, IndexedAttestationInvalid as Invalid};
|
use super::errors::{BlockOperationError, IndexedAttestationInvalid as Invalid};
|
||||||
use super::signature_sets::indexed_attestation_signature_set;
|
use super::signature_sets::indexed_attestation_signature_set;
|
||||||
use crate::VerifySignatures;
|
use crate::VerifySignatures;
|
||||||
use std::collections::HashSet;
|
|
||||||
use std::iter::FromIterator;
|
|
||||||
use types::*;
|
use types::*;
|
||||||
|
|
||||||
type Result<T> = std::result::Result<T, BlockOperationError<Invalid>>;
|
type Result<T> = std::result::Result<T, BlockOperationError<Invalid>>;
|
||||||
@@ -20,28 +18,15 @@ pub fn is_valid_indexed_attestation<T: EthSpec>(
|
|||||||
verify_signatures: VerifySignatures,
|
verify_signatures: VerifySignatures,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let bit_0_indices = &indexed_attestation.custody_bit_0_indices;
|
let indices = &indexed_attestation.attesting_indices;
|
||||||
let bit_1_indices = &indexed_attestation.custody_bit_1_indices;
|
|
||||||
|
|
||||||
// Verify no index has custody bit equal to 1 [to be removed in phase 1]
|
|
||||||
verify!(bit_1_indices.is_empty(), Invalid::CustodyBitfieldHasSetBits);
|
|
||||||
|
|
||||||
// Verify max number of indices
|
// Verify max number of indices
|
||||||
let total_indices = bit_0_indices.len() + bit_1_indices.len();
|
|
||||||
verify!(
|
verify!(
|
||||||
total_indices <= T::MaxValidatorsPerCommittee::to_usize(),
|
indices.len() <= T::MaxValidatorsPerCommittee::to_usize(),
|
||||||
Invalid::MaxIndicesExceed(T::MaxValidatorsPerCommittee::to_usize(), total_indices)
|
Invalid::MaxIndicesExceed(T::MaxValidatorsPerCommittee::to_usize(), indices.len())
|
||||||
);
|
);
|
||||||
|
|
||||||
// Verify index sets are disjoint
|
// Check that indices are sorted
|
||||||
let custody_bit_intersection: HashSet<&u64> =
|
|
||||||
&HashSet::from_iter(bit_0_indices.iter()) & &HashSet::from_iter(bit_1_indices.iter());
|
|
||||||
verify!(
|
|
||||||
custody_bit_intersection.is_empty(),
|
|
||||||
Invalid::CustodyBitValidatorsIntersect
|
|
||||||
);
|
|
||||||
|
|
||||||
// Check that both vectors of indices are sorted
|
|
||||||
let check_sorted = |list: &[u64]| -> Result<()> {
|
let check_sorted = |list: &[u64]| -> Result<()> {
|
||||||
list.windows(2).enumerate().try_for_each(|(i, pair)| {
|
list.windows(2).enumerate().try_for_each(|(i, pair)| {
|
||||||
if pair[0] >= pair[1] {
|
if pair[0] >= pair[1] {
|
||||||
@@ -52,8 +37,7 @@ pub fn is_valid_indexed_attestation<T: EthSpec>(
|
|||||||
})?;
|
})?;
|
||||||
Ok(())
|
Ok(())
|
||||||
};
|
};
|
||||||
check_sorted(&bit_0_indices)?;
|
check_sorted(indices)?;
|
||||||
check_sorted(&bit_1_indices)?;
|
|
||||||
|
|
||||||
if verify_signatures.is_true() {
|
if verify_signatures.is_true() {
|
||||||
verify!(
|
verify!(
|
||||||
|
|||||||
@@ -2,13 +2,13 @@
|
|||||||
//! validated individually, or alongside in others in a potentially cheaper bulk operation.
|
//! validated individually, or alongside in others in a potentially cheaper bulk operation.
|
||||||
//!
|
//!
|
||||||
//! This module exposes one function to extract each type of `SignatureSet` from a `BeaconBlock`.
|
//! This module exposes one function to extract each type of `SignatureSet` from a `BeaconBlock`.
|
||||||
use bls::SignatureSet;
|
use bls::{SignatureSet, SignedMessage};
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
use tree_hash::{SignedRoot, TreeHash};
|
use tree_hash::{SignedRoot, TreeHash};
|
||||||
use types::{
|
use types::{
|
||||||
AggregateSignature, AttestationDataAndCustodyBit, AttesterSlashing, BeaconBlock,
|
AggregateSignature, AttesterSlashing, BeaconBlock, BeaconBlockHeader, BeaconState,
|
||||||
BeaconBlockHeader, BeaconState, BeaconStateError, ChainSpec, Deposit, Domain, EthSpec, Fork,
|
BeaconStateError, ChainSpec, Deposit, Domain, EthSpec, Fork, Hash256, IndexedAttestation,
|
||||||
Hash256, IndexedAttestation, ProposerSlashing, PublicKey, Signature, VoluntaryExit,
|
ProposerSlashing, PublicKey, Signature, VoluntaryExit,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub type Result<T> = std::result::Result<T, Error>;
|
pub type Result<T> = std::result::Result<T, Error>;
|
||||||
@@ -138,16 +138,12 @@ pub fn indexed_attestation_signature_set<'a, 'b, T: EthSpec>(
|
|||||||
indexed_attestation: &'b IndexedAttestation<T>,
|
indexed_attestation: &'b IndexedAttestation<T>,
|
||||||
spec: &'a ChainSpec,
|
spec: &'a ChainSpec,
|
||||||
) -> Result<SignatureSet<'a>> {
|
) -> Result<SignatureSet<'a>> {
|
||||||
let message_0 = AttestationDataAndCustodyBit {
|
let message = indexed_attestation.data.tree_hash_root();
|
||||||
data: indexed_attestation.data.clone(),
|
|
||||||
custody_bit: false,
|
let signed_message = SignedMessage::new(
|
||||||
}
|
get_pubkeys(state, &indexed_attestation.attesting_indices)?,
|
||||||
.tree_hash_root();
|
message,
|
||||||
let message_1 = AttestationDataAndCustodyBit {
|
);
|
||||||
data: indexed_attestation.data.clone(),
|
|
||||||
custody_bit: true,
|
|
||||||
}
|
|
||||||
.tree_hash_root();
|
|
||||||
|
|
||||||
let domain = spec.get_domain(
|
let domain = spec.get_domain(
|
||||||
indexed_attestation.data.target.epoch,
|
indexed_attestation.data.target.epoch,
|
||||||
@@ -155,14 +151,7 @@ pub fn indexed_attestation_signature_set<'a, 'b, T: EthSpec>(
|
|||||||
&state.fork,
|
&state.fork,
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(SignatureSet::dual(
|
Ok(SignatureSet::new(signature, vec![signed_message], domain))
|
||||||
signature,
|
|
||||||
message_0,
|
|
||||||
get_pubkeys(state, &indexed_attestation.custody_bit_0_indices)?,
|
|
||||||
message_1,
|
|
||||||
get_pubkeys(state, &indexed_attestation.custody_bit_1_indices)?,
|
|
||||||
domain,
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the signature set for the given `attester_slashing` and corresponding `pubkeys`.
|
/// Returns the signature set for the given `attester_slashing` and corresponding `pubkeys`.
|
||||||
|
|||||||
@@ -71,15 +71,13 @@ where
|
|||||||
let attestation_2 = &attester_slashing.attestation_2;
|
let attestation_2 = &attester_slashing.attestation_2;
|
||||||
|
|
||||||
let attesting_indices_1 = attestation_1
|
let attesting_indices_1 = attestation_1
|
||||||
.custody_bit_0_indices
|
.attesting_indices
|
||||||
.iter()
|
.iter()
|
||||||
.chain(&attestation_1.custody_bit_1_indices)
|
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect::<BTreeSet<_>>();
|
.collect::<BTreeSet<_>>();
|
||||||
let attesting_indices_2 = attestation_2
|
let attesting_indices_2 = attestation_2
|
||||||
.custody_bit_0_indices
|
.attesting_indices
|
||||||
.iter()
|
.iter()
|
||||||
.chain(&attestation_2.custody_bit_1_indices)
|
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect::<BTreeSet<_>>();
|
.collect::<BTreeSet<_>>();
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ use tree_hash_derive::{SignedRoot, TreeHash};
|
|||||||
|
|
||||||
/// Details an attestation that can be slashable.
|
/// Details an attestation that can be slashable.
|
||||||
///
|
///
|
||||||
/// Spec v0.9.0
|
/// Spec v0.9.1
|
||||||
#[derive(
|
#[derive(
|
||||||
Debug,
|
Debug,
|
||||||
Clone,
|
Clone,
|
||||||
@@ -26,7 +26,6 @@ use tree_hash_derive::{SignedRoot, TreeHash};
|
|||||||
pub struct Attestation<T: EthSpec> {
|
pub struct Attestation<T: EthSpec> {
|
||||||
pub aggregation_bits: BitList<T::MaxValidatorsPerCommittee>,
|
pub aggregation_bits: BitList<T::MaxValidatorsPerCommittee>,
|
||||||
pub data: AttestationData,
|
pub data: AttestationData,
|
||||||
pub custody_bits: BitList<T::MaxValidatorsPerCommittee>,
|
|
||||||
#[signed_root(skip_hashing)]
|
#[signed_root(skip_hashing)]
|
||||||
pub signature: AggregateSignature,
|
pub signature: AggregateSignature,
|
||||||
}
|
}
|
||||||
@@ -47,7 +46,6 @@ impl<T: EthSpec> Attestation<T> {
|
|||||||
debug_assert!(self.signers_disjoint_from(other));
|
debug_assert!(self.signers_disjoint_from(other));
|
||||||
|
|
||||||
self.aggregation_bits = self.aggregation_bits.union(&other.aggregation_bits);
|
self.aggregation_bits = self.aggregation_bits.union(&other.aggregation_bits);
|
||||||
self.custody_bits = self.custody_bits.union(&other.custody_bits);
|
|
||||||
self.signature.add_aggregate(&other.signature);
|
self.signature.add_aggregate(&other.signature);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
use super::AttestationData;
|
|
||||||
use crate::test_utils::TestRandom;
|
|
||||||
use serde_derive::{Deserialize, Serialize};
|
|
||||||
use ssz_derive::{Decode, Encode};
|
|
||||||
use test_random_derive::TestRandom;
|
|
||||||
use tree_hash_derive::TreeHash;
|
|
||||||
|
|
||||||
/// Used for pairing an attestation with a proof-of-custody.
|
|
||||||
///
|
|
||||||
/// Spec v0.9.0
|
|
||||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Encode, Decode, TreeHash, TestRandom)]
|
|
||||||
pub struct AttestationDataAndCustodyBit {
|
|
||||||
pub data: AttestationData,
|
|
||||||
pub custody_bit: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod test {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
ssz_tests!(AttestationDataAndCustodyBit);
|
|
||||||
}
|
|
||||||
@@ -9,7 +9,7 @@ use tree_hash_derive::{SignedRoot, TreeHash};
|
|||||||
///
|
///
|
||||||
/// To be included in an `AttesterSlashing`.
|
/// To be included in an `AttesterSlashing`.
|
||||||
///
|
///
|
||||||
/// Spec v0.9.0
|
/// Spec v0.9.1
|
||||||
#[derive(
|
#[derive(
|
||||||
Debug,
|
Debug,
|
||||||
PartialEq,
|
PartialEq,
|
||||||
@@ -25,8 +25,7 @@ use tree_hash_derive::{SignedRoot, TreeHash};
|
|||||||
#[serde(bound = "T: EthSpec")]
|
#[serde(bound = "T: EthSpec")]
|
||||||
pub struct IndexedAttestation<T: EthSpec> {
|
pub struct IndexedAttestation<T: EthSpec> {
|
||||||
/// Lists validator registry indices, not committee indices.
|
/// Lists validator registry indices, not committee indices.
|
||||||
pub custody_bit_0_indices: VariableList<u64, T::MaxValidatorsPerCommittee>,
|
pub attesting_indices: VariableList<u64, T::MaxValidatorsPerCommittee>,
|
||||||
pub custody_bit_1_indices: VariableList<u64, T::MaxValidatorsPerCommittee>,
|
|
||||||
pub data: AttestationData,
|
pub data: AttestationData,
|
||||||
#[signed_root(skip_hashing)]
|
#[signed_root(skip_hashing)]
|
||||||
pub signature: AggregateSignature,
|
pub signature: AggregateSignature,
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ pub mod test_utils;
|
|||||||
|
|
||||||
pub mod attestation;
|
pub mod attestation;
|
||||||
pub mod attestation_data;
|
pub mod attestation_data;
|
||||||
pub mod attestation_data_and_custody_bit;
|
|
||||||
pub mod attestation_duty;
|
pub mod attestation_duty;
|
||||||
pub mod attester_slashing;
|
pub mod attester_slashing;
|
||||||
pub mod beacon_block;
|
pub mod beacon_block;
|
||||||
@@ -42,7 +41,6 @@ use ethereum_types::{H160, H256};
|
|||||||
|
|
||||||
pub use crate::attestation::Attestation;
|
pub use crate::attestation::Attestation;
|
||||||
pub use crate::attestation_data::AttestationData;
|
pub use crate::attestation_data::AttestationData;
|
||||||
pub use crate::attestation_data_and_custody_bit::AttestationDataAndCustodyBit;
|
|
||||||
pub use crate::attestation_duty::AttestationDuty;
|
pub use crate::attestation_duty::AttestationDuty;
|
||||||
pub use crate::attester_slashing::AttesterSlashing;
|
pub use crate::attester_slashing::AttesterSlashing;
|
||||||
pub use crate::beacon_block::BeaconBlock;
|
pub use crate::beacon_block::BeaconBlock;
|
||||||
|
|||||||
@@ -16,17 +16,14 @@ impl<T: EthSpec> TestingAttestationBuilder<T> {
|
|||||||
let data_builder = TestingAttestationDataBuilder::new(state, index, slot);
|
let data_builder = TestingAttestationDataBuilder::new(state, index, slot);
|
||||||
|
|
||||||
let mut aggregation_bits = BitList::with_capacity(committee.len()).unwrap();
|
let mut aggregation_bits = BitList::with_capacity(committee.len()).unwrap();
|
||||||
let mut custody_bits = BitList::with_capacity(committee.len()).unwrap();
|
|
||||||
|
|
||||||
for (i, _) in committee.iter().enumerate() {
|
for (i, _) in committee.iter().enumerate() {
|
||||||
custody_bits.set(i, false).unwrap();
|
|
||||||
aggregation_bits.set(i, false).unwrap();
|
aggregation_bits.set(i, false).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
let attestation = Attestation {
|
let attestation = Attestation {
|
||||||
aggregation_bits,
|
aggregation_bits,
|
||||||
data: data_builder.build(),
|
data: data_builder.build(),
|
||||||
custody_bits,
|
|
||||||
signature: AggregateSignature::new(),
|
signature: AggregateSignature::new(),
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -46,7 +43,6 @@ impl<T: EthSpec> TestingAttestationBuilder<T> {
|
|||||||
secret_keys: &[&SecretKey],
|
secret_keys: &[&SecretKey],
|
||||||
fork: &Fork,
|
fork: &Fork,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
custody_bit: bool,
|
|
||||||
) -> &mut Self {
|
) -> &mut Self {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
signing_validators.len(),
|
signing_validators.len(),
|
||||||
@@ -66,18 +62,7 @@ impl<T: EthSpec> TestingAttestationBuilder<T> {
|
|||||||
.set(committee_index, true)
|
.set(committee_index, true)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
if custody_bit {
|
let message = self.attestation.data.tree_hash_root();
|
||||||
self.attestation
|
|
||||||
.custody_bits
|
|
||||||
.set(committee_index, true)
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
let message = AttestationDataAndCustodyBit {
|
|
||||||
data: self.attestation.data.clone(),
|
|
||||||
custody_bit,
|
|
||||||
}
|
|
||||||
.tree_hash_root();
|
|
||||||
|
|
||||||
let domain = spec.get_domain(
|
let domain = spec.get_domain(
|
||||||
self.attestation.data.target.epoch,
|
self.attestation.data.target.epoch,
|
||||||
|
|||||||
@@ -50,26 +50,19 @@ impl TestingAttesterSlashingBuilder {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let mut attestation_1 = IndexedAttestation {
|
let mut attestation_1 = IndexedAttestation {
|
||||||
custody_bit_0_indices: validator_indices.to_vec().into(),
|
attesting_indices: validator_indices.to_vec().into(),
|
||||||
custody_bit_1_indices: VariableList::empty(),
|
|
||||||
data: data_1,
|
data: data_1,
|
||||||
signature: AggregateSignature::new(),
|
signature: AggregateSignature::new(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut attestation_2 = IndexedAttestation {
|
let mut attestation_2 = IndexedAttestation {
|
||||||
custody_bit_0_indices: validator_indices.to_vec().into(),
|
attesting_indices: validator_indices.to_vec().into(),
|
||||||
custody_bit_1_indices: VariableList::empty(),
|
|
||||||
data: data_2,
|
data: data_2,
|
||||||
signature: AggregateSignature::new(),
|
signature: AggregateSignature::new(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let add_signatures = |attestation: &mut IndexedAttestation<T>| {
|
let add_signatures = |attestation: &mut IndexedAttestation<T>| {
|
||||||
// All validators sign with a `false` custody bit.
|
let message = attestation.data.tree_hash_root();
|
||||||
let attestation_data_and_custody_bit = AttestationDataAndCustodyBit {
|
|
||||||
data: attestation.data.clone(),
|
|
||||||
custody_bit: false,
|
|
||||||
};
|
|
||||||
let message = attestation_data_and_custody_bit.tree_hash_root();
|
|
||||||
|
|
||||||
for validator_index in validator_indices {
|
for validator_index in validator_indices {
|
||||||
let signature = signer(
|
let signature = signer(
|
||||||
|
|||||||
@@ -181,13 +181,7 @@ impl<T: EthSpec> TestingBeaconBlockBuilder<T> {
|
|||||||
.iter()
|
.iter()
|
||||||
.map(|validator_index| secret_keys[*validator_index])
|
.map(|validator_index| secret_keys[*validator_index])
|
||||||
.collect();
|
.collect();
|
||||||
builder.sign(
|
builder.sign(signing_validators, &signing_secret_keys, &state.fork, spec);
|
||||||
signing_validators,
|
|
||||||
&signing_secret_keys,
|
|
||||||
&state.fork,
|
|
||||||
spec,
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
|
|
||||||
builder.build()
|
builder.build()
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Bump the test tag here and in .gitlab-ci.yml and CI will take care of updating the cached tarballs
|
# Bump the test tag here and in .gitlab-ci.yml and CI will take care of updating the cached tarballs
|
||||||
TESTS_TAG := v0.9.0
|
TESTS_TAG := v0.9.1
|
||||||
TESTS = general minimal mainnet
|
TESTS = general minimal mainnet
|
||||||
TARBALLS = $(patsubst %,%-$(TESTS_TAG).tar.gz,$(TESTS))
|
TARBALLS = $(patsubst %,%-$(TESTS_TAG).tar.gz,$(TESTS))
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ type_name!(MainnetEthSpec, "mainnet");
|
|||||||
|
|
||||||
type_name_generic!(Attestation);
|
type_name_generic!(Attestation);
|
||||||
type_name!(AttestationData);
|
type_name!(AttestationData);
|
||||||
type_name!(AttestationDataAndCustodyBit);
|
|
||||||
type_name_generic!(AttesterSlashing);
|
type_name_generic!(AttesterSlashing);
|
||||||
type_name_generic!(BeaconBlock);
|
type_name_generic!(BeaconBlock);
|
||||||
type_name_generic!(BeaconBlockBody);
|
type_name_generic!(BeaconBlockBody);
|
||||||
|
|||||||
@@ -133,10 +133,6 @@ mod ssz_static {
|
|||||||
|
|
||||||
ssz_static_test!(attestation, Attestation<_>, SR);
|
ssz_static_test!(attestation, Attestation<_>, SR);
|
||||||
ssz_static_test!(attestation_data, AttestationData);
|
ssz_static_test!(attestation_data, AttestationData);
|
||||||
ssz_static_test!(
|
|
||||||
attestation_data_and_custody_bit,
|
|
||||||
AttestationDataAndCustodyBit
|
|
||||||
);
|
|
||||||
ssz_static_test!(attester_slashing, AttesterSlashing<_>);
|
ssz_static_test!(attester_slashing, AttesterSlashing<_>);
|
||||||
ssz_static_test!(beacon_block, BeaconBlock<_>, SR);
|
ssz_static_test!(beacon_block, BeaconBlock<_>, SR);
|
||||||
ssz_static_test!(beacon_block_body, BeaconBlockBody<_>);
|
ssz_static_test!(beacon_block_body, BeaconBlockBody<_>);
|
||||||
@@ -180,7 +176,7 @@ fn epoch_processing_justification_and_finalization() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn epoch_processing_rewards_and_penalties() {
|
fn epoch_processing_rewards_and_penalties() {
|
||||||
EpochProcessingHandler::<MinimalEthSpec, RewardsAndPenalties>::run();
|
EpochProcessingHandler::<MinimalEthSpec, RewardsAndPenalties>::run();
|
||||||
EpochProcessingHandler::<MainnetEthSpec, RewardsAndPenalties>::run();
|
// Note: there are no reward and penalty tests for mainnet yet
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -10,10 +10,7 @@ use beacon_node_attestation::BeaconNodeAttestation;
|
|||||||
use core::marker::PhantomData;
|
use core::marker::PhantomData;
|
||||||
use slog::{error, info, warn};
|
use slog::{error, info, warn};
|
||||||
use tree_hash::TreeHash;
|
use tree_hash::TreeHash;
|
||||||
use types::{
|
use types::{AggregateSignature, Attestation, AttestationData, AttestationDuty, BitList};
|
||||||
AggregateSignature, Attestation, AttestationData, AttestationDataAndCustodyBit,
|
|
||||||
AttestationDuty, BitList,
|
|
||||||
};
|
|
||||||
|
|
||||||
//TODO: Group these errors at a crate level
|
//TODO: Group these errors at a crate level
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
@@ -129,11 +126,7 @@ impl<'a, B: BeaconNodeAttestation, S: Signer, E: EthSpec> AttestationProducer<'a
|
|||||||
|
|
||||||
// build the aggregate signature
|
// build the aggregate signature
|
||||||
let aggregate_signature = {
|
let aggregate_signature = {
|
||||||
let message = AttestationDataAndCustodyBit {
|
let message = attestation.tree_hash_root();
|
||||||
data: attestation.clone(),
|
|
||||||
custody_bit: false,
|
|
||||||
}
|
|
||||||
.tree_hash_root();
|
|
||||||
|
|
||||||
let sig = self.signer.sign_message(&message, domain)?;
|
let sig = self.signer.sign_message(&message, domain)?;
|
||||||
|
|
||||||
@@ -143,13 +136,11 @@ impl<'a, B: BeaconNodeAttestation, S: Signer, E: EthSpec> AttestationProducer<'a
|
|||||||
};
|
};
|
||||||
|
|
||||||
let mut aggregation_bits = BitList::with_capacity(duties.committee_len).ok()?;
|
let mut aggregation_bits = BitList::with_capacity(duties.committee_len).ok()?;
|
||||||
let custody_bits = BitList::with_capacity(duties.committee_len).ok()?;
|
|
||||||
aggregation_bits.set(duties.committee_position, true).ok()?;
|
aggregation_bits.set(duties.committee_position, true).ok()?;
|
||||||
|
|
||||||
Some(Attestation {
|
Some(Attestation {
|
||||||
aggregation_bits,
|
aggregation_bits,
|
||||||
data: attestation,
|
data: attestation,
|
||||||
custody_bits,
|
|
||||||
signature: aggregate_signature,
|
signature: aggregate_signature,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user