From 5c03f7b06c3a230f6a7a9ed90da5c5daa9e6ccf5 Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Tue, 7 May 2019 13:29:14 +1000 Subject: [PATCH] spec: update chain spec for v0.6.1 --- eth2/types/src/attestation_data.rs | 4 +- eth2/types/src/beacon_block.rs | 6 +- eth2/types/src/chain_spec.rs | 95 +++++++++---------- .../testing_attestation_data_builder.rs | 6 +- .../testing_attester_slashing_builder.rs | 6 +- .../testing_beacon_block_builder.rs | 2 +- .../testing_proposer_slashing_builder.rs | 4 +- .../testing_voluntary_exit_builder.rs | 2 +- eth2/types/src/validator.rs | 6 +- 9 files changed, 59 insertions(+), 72 deletions(-) diff --git a/eth2/types/src/attestation_data.rs b/eth2/types/src/attestation_data.rs index 63b94fd703..d09217ef99 100644 --- a/eth2/types/src/attestation_data.rs +++ b/eth2/types/src/attestation_data.rs @@ -1,5 +1,5 @@ use crate::test_utils::TestRandom; -use crate::{Crosslink, Epoch, Hash256, Slot}; +use crate::{Epoch, Hash256, Slot}; use rand::RngCore; use serde_derive::{Deserialize, Serialize}; use ssz_derive::{Decode, Encode}; @@ -37,7 +37,7 @@ pub struct AttestationData { // Crosslink Vote pub shard: u64, - pub previous_crosslink_root: Crosslink, + pub previous_crosslink_root: Hash256, pub crosslink_data_root: Hash256, } diff --git a/eth2/types/src/beacon_block.rs b/eth2/types/src/beacon_block.rs index 1265a48643..ff75fbb641 100644 --- a/eth2/types/src/beacon_block.rs +++ b/eth2/types/src/beacon_block.rs @@ -43,7 +43,7 @@ impl BeaconBlock { previous_block_root: spec.zero_hash, state_root: spec.zero_hash, body: BeaconBlockBody { - randao_reveal: spec.empty_signature.clone(), + randao_reveal: Signature::empty_signature(), eth1_data: Eth1Data { deposit_root: spec.zero_hash, block_hash: spec.zero_hash, @@ -56,7 +56,7 @@ impl BeaconBlock { voluntary_exits: vec![], transfers: vec![], }, - signature: spec.empty_signature.clone(), + signature: Signature::empty_signature(), } } @@ -91,7 +91,7 @@ impl BeaconBlock { pub fn temporary_block_header(&self, spec: &ChainSpec) -> BeaconBlockHeader { BeaconBlockHeader { state_root: spec.zero_hash, - signature: spec.empty_signature.clone(), + signature: Signature::empty_signature(), ..self.block_header() } } diff --git a/eth2/types/src/chain_spec.rs b/eth2/types/src/chain_spec.rs index f3c92b42cf..c219c05ee9 100644 --- a/eth2/types/src/chain_spec.rs +++ b/eth2/types/src/chain_spec.rs @@ -1,26 +1,23 @@ use crate::*; -use bls::Signature; use int_to_bytes::int_to_bytes4; use serde_derive::Deserialize; use test_utils::u8_from_hex_str; -const GWEI: u64 = 1_000_000_000; - /// Each of the BLS signature domains. /// -/// Spec v0.5.1 +/// Spec v0.6.1 pub enum Domain { - BeaconBlock, + BeaconProposer, Randao, Attestation, Deposit, - Exit, + VoluntaryExit, Transfer, } /// Holds all the "constants" for a BeaconChain. /// -/// Spec v0.5.1 +/// Spec v0.6.1 #[derive(PartialEq, Debug, Clone, Deserialize)] #[serde(default)] pub struct ChainSpec { @@ -29,35 +26,32 @@ pub struct ChainSpec { */ pub shard_count: u64, pub target_committee_size: u64, - pub max_balance_churn_quotient: u64, - pub max_indices_per_slashable_vote: usize, - pub max_exit_dequeues_per_epoch: u64, + pub max_indices_per_attestation: u64, + pub min_per_epoch_churn_limit: u64, + pub churn_limit_quotient: u64, + pub base_rewards_per_epoch: u64, pub shuffle_round_count: u8, /* * Deposit contract */ - pub deposit_contract_address: Address, pub deposit_contract_tree_depth: u64, /* * Gwei values */ pub min_deposit_amount: u64, - pub max_deposit_amount: u64, - pub fork_choice_balance_increment: u64, + pub max_effective_balance: u64, pub ejection_balance: u64, + pub effective_balance_increment: u64, /* * Initial Values */ - pub genesis_fork_version: u32, pub genesis_slot: Slot, pub genesis_epoch: Epoch, - pub genesis_start_shard: u64, pub far_future_epoch: Epoch, pub zero_hash: Hash256, - pub empty_signature: Signature, #[serde(deserialize_with = "u8_from_hex_str")] pub bls_withdrawal_prefix_byte: u8, @@ -69,10 +63,12 @@ pub struct ChainSpec { pub slots_per_epoch: u64, pub min_seed_lookahead: Epoch, pub activation_exit_delay: u64, - pub epochs_per_eth1_voting_period: u64, + pub slots_per_eth1_voting_period: u64, pub slots_per_historical_root: usize, pub min_validator_withdrawability_delay: Epoch, pub persistent_committee_period: u64, + pub max_crosslink_epochs: u64, + pub min_epochs_to_inactivity_penalty: u64, /* * State list lengths @@ -85,10 +81,10 @@ pub struct ChainSpec { * Reward and penalty quotients */ pub base_reward_quotient: u64, - pub whistleblower_reward_quotient: u64, - pub attestation_inclusion_reward_quotient: u64, + pub whistleblowing_reward_quotient: u64, + pub proposer_reward_quotient: u64, pub inactivity_penalty_quotient: u64, - pub min_penalty_quotient: u64, + pub min_slashing_penalty_quotient: u64, /* * Max operations per block @@ -108,11 +104,11 @@ pub struct ChainSpec { * * Use `ChainSpec::get_domain(..)` to access these values. */ - domain_beacon_block: u32, + domain_beacon_proposer: u32, domain_randao: u32, domain_attestation: u32, domain_deposit: u32, - domain_exit: u32, + domain_voluntary_exit: u32, domain_transfer: u32, /* @@ -139,14 +135,14 @@ impl ChainSpec { /// Get the domain number that represents the fork meta and signature domain. /// - /// Spec v0.5.1 + /// Spec v0.6.1 pub fn get_domain(&self, epoch: Epoch, domain: Domain, fork: &Fork) -> u64 { let domain_constant = match domain { - Domain::BeaconBlock => self.domain_beacon_block, + Domain::BeaconProposer => self.domain_beacon_proposer, Domain::Randao => self.domain_randao, Domain::Attestation => self.domain_attestation, Domain::Deposit => self.domain_deposit, - Domain::Exit => self.domain_exit, + Domain::VoluntaryExit => self.domain_voluntary_exit, Domain::Transfer => self.domain_transfer, }; @@ -161,47 +157,40 @@ impl ChainSpec { /// Returns a `ChainSpec` compatible with the Ethereum Foundation specification. /// - /// Spec v0.5.1 + /// Spec v0.6.1 pub fn foundation() -> Self { - let genesis_slot = Slot::new(2_u64.pow(32)); - let slots_per_epoch = 64; - let genesis_epoch = genesis_slot.epoch(slots_per_epoch); - Self { /* * Misc */ shard_count: 1_024, target_committee_size: 128, - max_balance_churn_quotient: 32, - max_indices_per_slashable_vote: 4_096, - max_exit_dequeues_per_epoch: 4, + max_indices_per_attestation: 4096, + min_per_epoch_churn_limit: 4, + churn_limit_quotient: 65_536, + base_rewards_per_epoch: 5, shuffle_round_count: 90, /* * Deposit contract */ - deposit_contract_address: Address::zero(), deposit_contract_tree_depth: 32, /* * Gwei values */ - min_deposit_amount: u64::pow(2, 0) * GWEI, - max_deposit_amount: u64::pow(2, 5) * GWEI, - fork_choice_balance_increment: u64::pow(2, 0) * GWEI, - ejection_balance: u64::pow(2, 4) * GWEI, + min_deposit_amount: u64::pow(2, 0) * u64::pow(10, 9), + max_effective_balance: u64::pow(2, 5) * u64::pow(10, 9), + ejection_balance: u64::pow(2, 4) * u64::pow(10, 9), + effective_balance_increment: u64::pow(2, 0) * u64::pow(10, 9), /* * Initial Values */ - genesis_fork_version: 0, - genesis_slot, - genesis_epoch, - genesis_start_shard: 0, + genesis_slot: Slot::new(0), + genesis_epoch: Epoch::new(0), far_future_epoch: Epoch::new(u64::max_value()), zero_hash: Hash256::zero(), - empty_signature: Signature::empty_signature(), bls_withdrawal_prefix_byte: 0, /* @@ -209,13 +198,15 @@ impl ChainSpec { */ seconds_per_slot: 6, min_attestation_inclusion_delay: 4, - slots_per_epoch, + slots_per_epoch: 64, min_seed_lookahead: Epoch::new(1), activation_exit_delay: 4, - epochs_per_eth1_voting_period: 16, + slots_per_eth1_voting_period: 1_024, slots_per_historical_root: 8_192, min_validator_withdrawability_delay: Epoch::new(256), persistent_committee_period: 2_048, + max_crosslink_epochs: 64, + min_epochs_to_inactivity_penalty: 4, /* * State list lengths @@ -228,10 +219,10 @@ impl ChainSpec { * Reward and penalty quotients */ base_reward_quotient: 32, - whistleblower_reward_quotient: 512, - attestation_inclusion_reward_quotient: 8, - inactivity_penalty_quotient: 16_777_216, - min_penalty_quotient: 32, + whistleblowing_reward_quotient: 512, + proposer_reward_quotient: 8, + inactivity_penalty_quotient: 33_554_432, + min_slashing_penalty_quotient: 32, /* * Max operations per block @@ -241,16 +232,16 @@ impl ChainSpec { max_attestations: 128, max_deposits: 16, max_voluntary_exits: 16, - max_transfers: 16, + max_transfers: 0, /* * Signature domains */ - domain_beacon_block: 0, + domain_beacon_proposer: 0, domain_randao: 1, domain_attestation: 2, domain_deposit: 3, - domain_exit: 4, + domain_voluntary_exit: 4, domain_transfer: 5, /* diff --git a/eth2/types/src/test_utils/testing_attestation_data_builder.rs b/eth2/types/src/test_utils/testing_attestation_data_builder.rs index 146485fc0e..9fde5202c8 100644 --- a/eth2/types/src/test_utils/testing_attestation_data_builder.rs +++ b/eth2/types/src/test_utils/testing_attestation_data_builder.rs @@ -49,11 +49,7 @@ impl TestingAttestationDataBuilder { // Crosslink vote shard, - previous_crosslink_root: Crosslink { - epoch: slot.epoch(spec.slots_per_epoch), - previous_crosslink_root: spec.zero_hash, - crosslink_data_root: spec.zero_hash, - }, + previous_crosslink_root: spec.zero_hash, crosslink_data_root: spec.zero_hash, }; diff --git a/eth2/types/src/test_utils/testing_attester_slashing_builder.rs b/eth2/types/src/test_utils/testing_attester_slashing_builder.rs index bd5aea2a47..91615d258c 100644 --- a/eth2/types/src/test_utils/testing_attester_slashing_builder.rs +++ b/eth2/types/src/test_utils/testing_attester_slashing_builder.rs @@ -34,11 +34,7 @@ impl TestingAttesterSlashingBuilder { source_root: hash_1, target_root: hash_1, shard, - previous_crosslink_root: Crosslink { - epoch, - previous_crosslink_root: hash_1, - crosslink_data_root: hash_1, - }, + previous_crosslink_root: hash_1, crosslink_data_root: hash_1, }; diff --git a/eth2/types/src/test_utils/testing_beacon_block_builder.rs b/eth2/types/src/test_utils/testing_beacon_block_builder.rs index 549c00ac08..88e667efdd 100644 --- a/eth2/types/src/test_utils/testing_beacon_block_builder.rs +++ b/eth2/types/src/test_utils/testing_beacon_block_builder.rs @@ -34,7 +34,7 @@ impl TestingBeaconBlockBuilder { pub fn sign(&mut self, sk: &SecretKey, fork: &Fork, spec: &ChainSpec) { let message = self.block.signed_root(); let epoch = self.block.slot.epoch(spec.slots_per_epoch); - let domain = spec.get_domain(epoch, Domain::BeaconBlock, fork); + let domain = spec.get_domain(epoch, Domain::BeaconProposer, fork); self.block.signature = Signature::new(&message, domain, sk); } diff --git a/eth2/types/src/test_utils/testing_proposer_slashing_builder.rs b/eth2/types/src/test_utils/testing_proposer_slashing_builder.rs index 03c257b2d2..458082de2d 100644 --- a/eth2/types/src/test_utils/testing_proposer_slashing_builder.rs +++ b/eth2/types/src/test_utils/testing_proposer_slashing_builder.rs @@ -41,13 +41,13 @@ impl TestingProposerSlashingBuilder { header_1.signature = { let message = header_1.signed_root(); let epoch = slot.epoch(spec.slots_per_epoch); - signer(proposer_index, &message[..], epoch, Domain::BeaconBlock) + signer(proposer_index, &message[..], epoch, Domain::BeaconProposer) }; header_2.signature = { let message = header_2.signed_root(); let epoch = slot.epoch(spec.slots_per_epoch); - signer(proposer_index, &message[..], epoch, Domain::BeaconBlock) + signer(proposer_index, &message[..], epoch, Domain::BeaconProposer) }; ProposerSlashing { diff --git a/eth2/types/src/test_utils/testing_voluntary_exit_builder.rs b/eth2/types/src/test_utils/testing_voluntary_exit_builder.rs index 8583bc4517..58e8e750d2 100644 --- a/eth2/types/src/test_utils/testing_voluntary_exit_builder.rs +++ b/eth2/types/src/test_utils/testing_voluntary_exit_builder.rs @@ -25,7 +25,7 @@ impl TestingVoluntaryExitBuilder { /// The signing secret key must match that of the exiting validator. pub fn sign(&mut self, secret_key: &SecretKey, fork: &Fork, spec: &ChainSpec) { let message = self.exit.signed_root(); - let domain = spec.get_domain(self.exit.epoch, Domain::Exit, fork); + let domain = spec.get_domain(self.exit.epoch, Domain::VoluntaryExit, fork); self.exit.signature = Signature::new(&message, domain, secret_key); } diff --git a/eth2/types/src/validator.rs b/eth2/types/src/validator.rs index 5b369427c2..2731901917 100644 --- a/eth2/types/src/validator.rs +++ b/eth2/types/src/validator.rs @@ -37,6 +37,11 @@ impl Validator { self.activation_epoch <= epoch && epoch < self.exit_epoch } + /// Returns `true` if the validator is slashable at some epoch. + pub fn is_slashable_at(&self, epoch: Epoch) -> bool { + !self.slashed && self.activation_epoch <= epoch && epoch < self.withdrawable_epoch + } + /// Returns `true` if the validator is considered exited at some epoch. pub fn is_exited_at(&self, epoch: Epoch) -> bool { self.exit_epoch <= epoch @@ -77,7 +82,6 @@ mod tests { assert_eq!(v.is_active_at(epoch), false); assert_eq!(v.is_exited_at(epoch), false); assert_eq!(v.is_withdrawable_at(epoch), false); - assert_eq!(v.initiated_exit, false); assert_eq!(v.slashed, false); }