From fabb42a162a44178f837136b70bbec488d69063b Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Wed, 22 May 2019 13:03:51 +1000 Subject: [PATCH] Update various v0.5.1 tags, delete old file --- .../src/attestation_data_and_custody_bit.rs | 27 +++++++------- .../src/beacon_state/beacon_state_types.rs | 16 ++++----- eth2/types/src/deposit_data.rs | 31 +--------------- eth2/types/src/eth1_data_vote.rs | 36 ------------------- eth2/types/src/historical_batch.rs | 2 +- eth2/types/src/relative_epoch.rs | 2 +- 6 files changed, 23 insertions(+), 91 deletions(-) delete mode 100644 eth2/types/src/eth1_data_vote.rs diff --git a/eth2/types/src/attestation_data_and_custody_bit.rs b/eth2/types/src/attestation_data_and_custody_bit.rs index f1437cb549..2e952bf27b 100644 --- a/eth2/types/src/attestation_data_and_custody_bit.rs +++ b/eth2/types/src/attestation_data_and_custody_bit.rs @@ -1,29 +1,30 @@ use super::AttestationData; use crate::test_utils::TestRandom; - -use rand::RngCore; use serde_derive::Serialize; use ssz_derive::{Decode, Encode}; +use test_random_derive::TestRandom; use tree_hash_derive::{CachedTreeHash, TreeHash}; /// Used for pairing an attestation with a proof-of-custody. /// -/// Spec v0.5.1 -#[derive(Debug, Clone, PartialEq, Default, Serialize, Encode, Decode, TreeHash, CachedTreeHash)] +/// Spec v0.6.1 +#[derive( + Debug, + Clone, + PartialEq, + Default, + Serialize, + Encode, + Decode, + TreeHash, + CachedTreeHash, + TestRandom, +)] pub struct AttestationDataAndCustodyBit { pub data: AttestationData, pub custody_bit: bool, } -impl TestRandom for AttestationDataAndCustodyBit { - fn random_for_test(rng: &mut impl RngCore) -> Self { - Self { - data: <_>::random_for_test(rng), - custody_bit: <_>::random_for_test(rng), - } - } -} - #[cfg(test)] mod test { use super::*; diff --git a/eth2/types/src/beacon_state/beacon_state_types.rs b/eth2/types/src/beacon_state/beacon_state_types.rs index 07eda2435b..b5ab937259 100644 --- a/eth2/types/src/beacon_state/beacon_state_types.rs +++ b/eth2/types/src/beacon_state/beacon_state_types.rs @@ -56,35 +56,35 @@ pub trait EthSpec: /// Returns the `SHARD_COUNT` constant for this specification. /// - /// Spec v0.5.1 + /// Spec v0.6.1 fn shard_count() -> usize { Self::ShardCount::to_usize() } /// Returns the `SLOTS_PER_HISTORICAL_ROOT` constant for this specification. /// - /// Spec v0.5.1 + /// Spec v0.6.1 fn slots_per_historical_root() -> usize { Self::SlotsPerHistoricalRoot::to_usize() } /// Returns the `LATEST_RANDAO_MIXES_LENGTH` constant for this specification. /// - /// Spec v0.5.1 + /// Spec v0.6.1 fn latest_randao_mixes_length() -> usize { Self::LatestRandaoMixesLength::to_usize() } /// Returns the `LATEST_ACTIVE_INDEX_ROOTS` constant for this specification. /// - /// Spec v0.5.1 + /// Spec v0.6.1 fn latest_active_index_roots() -> usize { Self::LatestActiveIndexRootsLength::to_usize() } /// Returns the `LATEST_SLASHED_EXIT_LENGTH` constant for this specification. /// - /// Spec v0.5.1 + /// Spec v0.6.1 fn latest_slashed_exit_length() -> usize { Self::LatestSlashedExitLength::to_usize() } @@ -92,7 +92,7 @@ pub trait EthSpec: /// Ethereum Foundation specifications. /// -/// Spec v0.5.1 +/// Spec v0.6.1 #[derive(Clone, PartialEq, Debug, Default, Serialize, Deserialize)] pub struct FoundationEthSpec; @@ -111,8 +111,6 @@ impl EthSpec for FoundationEthSpec { pub type FoundationBeaconState = BeaconState; /// Ethereum Foundation specifications, modified to be suitable for < 1000 validators. -/// -/// Spec v0.5.1 #[derive(Clone, PartialEq, Debug, Default, Serialize, Deserialize)] pub struct FewValidatorsEthSpec; @@ -131,8 +129,6 @@ impl EthSpec for FewValidatorsEthSpec { pub type FewValidatorsBeaconState = BeaconState; /// Specifications suitable for a small-scale (< 1000 validators) lighthouse testnet. -/// -/// Spec v0.5.1 #[derive(Clone, PartialEq, Debug, Default, Serialize, Deserialize)] pub struct LighthouseTestnetEthSpec; diff --git a/eth2/types/src/deposit_data.rs b/eth2/types/src/deposit_data.rs index d00bb69e2c..274fa68a41 100644 --- a/eth2/types/src/deposit_data.rs +++ b/eth2/types/src/deposit_data.rs @@ -35,7 +35,7 @@ pub struct DepositData { impl DepositData { /// Generate the signature for a given DepositData details. /// - /// Spec v0.5.1 + /// Spec v0.6.1 pub fn create_signature( &self, secret_key: &SecretKey, @@ -48,16 +48,6 @@ impl DepositData { Signature::new(msg.as_slice(), domain, secret_key) } - - /// Verify that proof-of-possession is valid. - /// - /// Spec v0.5.1 - pub fn validate_signature(&self, epoch: Epoch, fork: &Fork, spec: &ChainSpec) -> bool { - let msg = self.signed_root(); - let domain = spec.get_domain(epoch, Domain::Deposit, fork); - - self.signature.verify(&msg, domain, &self.pubkey) - } } #[cfg(test)] @@ -66,23 +56,4 @@ mod tests { ssz_tests!(DepositData); cached_tree_hash_tests!(DepositData); - - #[test] - fn can_create_and_validate() { - let spec = ChainSpec::foundation(); - let fork = Fork::genesis(&spec); - let keypair = Keypair::random(); - let epoch = Epoch::new(0); - - let mut deposit_input = DepositData { - pubkey: keypair.pk.clone(), - amount: 0, - withdrawal_credentials: Hash256::zero(), - signature: Signature::empty_signature(), - }; - - deposit_input.signature = deposit_input.create_signature(&keypair.sk, epoch, &fork, &spec); - - assert!(deposit_input.validate_signature(epoch, &fork, &spec)); - } } diff --git a/eth2/types/src/eth1_data_vote.rs b/eth2/types/src/eth1_data_vote.rs deleted file mode 100644 index 27cb0be78d..0000000000 --- a/eth2/types/src/eth1_data_vote.rs +++ /dev/null @@ -1,36 +0,0 @@ -use super::Eth1Data; -use crate::test_utils::TestRandom; - -use serde_derive::{Deserialize, Serialize}; -use ssz_derive::{Decode, Encode}; -use test_random_derive::TestRandom; -use tree_hash_derive::{CachedTreeHash, TreeHash}; - -/// A summation of votes for some `Eth1Data`. -/// -/// Spec v0.5.1 -#[derive( - Debug, - PartialEq, - Clone, - Default, - Serialize, - Deserialize, - Encode, - Decode, - TreeHash, - CachedTreeHash, - TestRandom, -)] -pub struct Eth1DataVote { - pub eth1_data: Eth1Data, - pub vote_count: u64, -} - -#[cfg(test)] -mod tests { - use super::*; - - ssz_tests!(Eth1DataVote); - cached_tree_hash_tests!(Eth1DataVote); -} diff --git a/eth2/types/src/historical_batch.rs b/eth2/types/src/historical_batch.rs index d808382216..3480508dc7 100644 --- a/eth2/types/src/historical_batch.rs +++ b/eth2/types/src/historical_batch.rs @@ -9,7 +9,7 @@ use tree_hash_derive::{CachedTreeHash, TreeHash}; /// Historical block and state roots. /// -/// Spec v0.5.1 +/// Spec v0.6.1 #[derive( Debug, Clone, diff --git a/eth2/types/src/relative_epoch.rs b/eth2/types/src/relative_epoch.rs index 58e3427cc8..3178701e8f 100644 --- a/eth2/types/src/relative_epoch.rs +++ b/eth2/types/src/relative_epoch.rs @@ -9,7 +9,7 @@ pub enum Error { /// Defines the epochs relative to some epoch. Most useful when referring to the committees prior /// to and following some epoch. /// -/// Spec v0.5.1 +/// Spec v0.6.1 #[derive(Debug, PartialEq, Clone, Copy)] pub enum RelativeEpoch { /// The prior epoch.