use digest::Digest;
use typenum::Unsigned;
use serde::{Serialize, Deserialize};
use crate::primitives::{H256, Uint, Signature, ValidatorId};
pub trait BLSConfig: Default + Clone + 'static {
fn verify(pubkey: &ValidatorId, message: &H256, signature: &Signature, domain: u64) -> bool;
fn aggregate_pubkeys(pubkeys: &[ValidatorId]) -> ValidatorId;
fn aggregate_signatures(signatures: &[Signature]) -> Signature;
fn verify_multiple(pubkeys: &[ValidatorId], messages: &[H256], signature: &Signature, domain: u64) -> bool;
}
#[derive(Default, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "std", derive(Debug))]
pub struct BLSNoVerification;
impl BLSConfig for BLSNoVerification {
fn verify(_pubkey: &ValidatorId, _message: &H256, _signature: &Signature, _domain: u64) -> bool {
true
}
fn aggregate_pubkeys(_pubkeys: &[ValidatorId]) -> ValidatorId {
ValidatorId::default()
}
fn aggregate_signatures(_signatures: &[Signature]) -> Signature {
Signature::default()
}
fn verify_multiple(_pubkeys: &[ValidatorId], _messages: &[H256], _signature: &Signature, _domain: u64) -> bool {
true
}
}
pub trait Config: Default + Clone + PartialEq + Eq + core::fmt::Debug + 'static {
type Digest: Digest<OutputSize=typenum::U32>;
type MaxValidatorsPerCommittee: Unsigned + core::fmt::Debug + Clone + Eq + PartialEq + Default;
type SlotsPerHistoricalRoot: Unsigned + core::fmt::Debug + Clone + Eq + PartialEq + Default;
type MaxProposerSlashings: Unsigned + core::fmt::Debug + Clone + Eq + PartialEq + Default;
type MaxAttesterSlashings: Unsigned + core::fmt::Debug + Clone + Eq + PartialEq + Default;
type MaxAttestations: Unsigned + core::fmt::Debug + Clone + Eq + PartialEq + Default;
type MaxDeposits: Unsigned + core::fmt::Debug + Clone + Eq + PartialEq + Default;
type MaxVoluntaryExits: Unsigned + core::fmt::Debug + Clone + Eq + PartialEq + Default;
type MaxTransfers: Unsigned + core::fmt::Debug + Clone + Eq + PartialEq + Default;
type HistoricalRootsLimit: Unsigned + core::fmt::Debug + Clone + Eq + PartialEq + Default;
type ShardCount: Unsigned + core::fmt::Debug + Clone + Eq + PartialEq + Default;
type SlotsPerEpoch: Unsigned + core::fmt::Debug + Clone + Eq + PartialEq + Default;
type SlotsPerEth1VotingPeriod: Unsigned + core::fmt::Debug + Clone + Eq + PartialEq + Default;
type ValidatorRegistryLimit: Unsigned + core::fmt::Debug + Clone + Eq + PartialEq + Default;
type EpochsPerHistoricalVector: Unsigned + core::fmt::Debug + Clone + Eq + PartialEq + Default;
type EpochsPerSlashingsVector: Unsigned + core::fmt::Debug + Clone + Eq + PartialEq + Default;
type MaxAttestationsPerEpoch: Unsigned + core::fmt::Debug + Clone + Eq + PartialEq + Default;
fn shard_count() -> Uint { Self::ShardCount::to_u64() }
fn target_committee_size() -> Uint;
fn max_validators_per_committee() -> Uint { Self::MaxValidatorsPerCommittee::to_u64() }
fn min_per_epoch_churn_limit() -> Uint;
fn churn_limit_quotient() -> Uint;
fn shuffle_round_count() -> Uint;
fn min_genesis_active_validator_count() -> Uint;
fn min_genesis_time() -> Uint;
fn min_deposit_amount() -> Uint;
fn max_effective_balance() -> Uint;
fn ejection_balance() -> Uint;
fn effective_balance_increment() -> Uint;
fn genesis_slot() -> Uint;
fn genesis_epoch() -> Uint;
fn bls_withdrawal_prefix_byte() -> u8;
fn min_attestation_inclusion_delay() -> Uint;
fn slots_per_epoch() -> Uint { Self::SlotsPerEpoch::to_u64() }
fn min_seed_lookahead() -> Uint;
fn activation_exit_delay() -> Uint;
fn slots_per_eth1_voting_period() -> Uint { Self::SlotsPerEth1VotingPeriod::to_u64() }
fn slots_per_historical_root() -> Uint { Self::SlotsPerHistoricalRoot::to_u64() }
fn min_validator_withdrawability_delay() -> Uint;
fn persistent_committee_period() -> Uint;
fn max_epochs_per_crosslink() -> Uint;
fn min_epochs_to_inactivity_penalty() -> Uint;
fn epochs_per_historical_vector() -> Uint { Self::EpochsPerHistoricalVector::to_u64() }
fn epochs_per_slashings_vector() -> Uint { Self::EpochsPerSlashingsVector::to_u64() }
fn historical_roots_limit() -> Uint { Self::HistoricalRootsLimit::to_u64() }
fn validator_registry_limit() -> Uint { Self::ValidatorRegistryLimit::to_u64() }
fn base_reward_factor() -> Uint;
fn whistleblower_reward_quotient() -> Uint;
fn proposer_reward_quotient() -> Uint;
fn inactivity_penalty_quotient() -> Uint;
fn min_slashing_penalty_quotient() -> Uint;
fn max_proposer_slashings() -> Uint { Self::MaxProposerSlashings::to_u64() }
fn max_attester_slashings() -> Uint { Self::MaxAttesterSlashings::to_u64() }
fn max_attestations() -> Uint { Self::MaxAttestations::to_u64() }
fn max_deposits() -> Uint { Self::MaxDeposits::to_u64() }
fn max_voluntary_exits() -> Uint { Self::MaxVoluntaryExits::to_u64() }
fn max_transfers() -> Uint { Self::MaxTransfers::to_u64() }
fn domain_beacon_proposer() -> Uint;
fn domain_randao() -> Uint;
fn domain_attestation() -> Uint;
fn domain_deposit() -> Uint;
fn domain_voluntary_exit() -> Uint;
fn domain_transfer() -> Uint;
fn hash<A: AsRef<[u8]>, I: IntoIterator<Item=A>>(
inputs: I
) -> H256 {
let mut digest = Self::Digest::new();
for input in inputs {
digest.input(input);
}
H256::from_slice(digest.result().as_slice())
}
}
#[derive(Default, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "std", derive(Debug))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "parity-codec", derive(parity_codec::Encode, parity_codec::Decode))]
pub struct MinimalConfig;
impl Config for MinimalConfig {
type Digest = sha2::Sha256;
type MaxValidatorsPerCommittee = typenum::U4096;
type SlotsPerHistoricalRoot = typenum::U64;
type MaxProposerSlashings = typenum::U16;
type MaxAttesterSlashings = typenum::U1;
type MaxAttestations = typenum::U128;
type MaxDeposits = typenum::U16;
type MaxVoluntaryExits = typenum::U16;
type MaxTransfers = typenum::U0;
type HistoricalRootsLimit = typenum::U16777216;
type ShardCount = typenum::U8;
type SlotsPerEpoch = typenum::U8;
type SlotsPerEth1VotingPeriod = typenum::U16;
type ValidatorRegistryLimit = typenum::U1099511627776;
type EpochsPerHistoricalVector = typenum::U64;
type EpochsPerSlashingsVector = typenum::U64;
type MaxAttestationsPerEpoch = typenum::Prod<Self::MaxAttestations, Self::SlotsPerEpoch>;
fn target_committee_size() -> Uint { 4 }
fn min_per_epoch_churn_limit() -> Uint { 4 }
fn churn_limit_quotient() -> Uint { 65536 }
fn shuffle_round_count() -> Uint { 10 }
fn min_genesis_active_validator_count() -> Uint { 64 }
fn min_genesis_time() -> Uint { 1578009600 }
fn min_deposit_amount() -> Uint { 1000000000 }
fn max_effective_balance() -> Uint { 32000000000 }
fn ejection_balance() -> Uint { 16000000000 }
fn effective_balance_increment() -> Uint { 1000000000 }
fn genesis_slot() -> Uint { 0 }
fn genesis_epoch() -> Uint { 0 }
fn bls_withdrawal_prefix_byte() -> u8 { 0x00 }
fn min_attestation_inclusion_delay() -> Uint { 1 }
fn min_seed_lookahead() -> Uint { 1 }
fn activation_exit_delay() -> Uint { 4 }
fn min_validator_withdrawability_delay() -> Uint { 256 }
fn persistent_committee_period() -> Uint { 2048 }
fn max_epochs_per_crosslink() -> Uint { 4 }
fn min_epochs_to_inactivity_penalty() -> Uint { 4 }
fn base_reward_factor() -> Uint { 64 }
fn whistleblower_reward_quotient() -> Uint { 512 }
fn proposer_reward_quotient() -> Uint { 8 }
fn inactivity_penalty_quotient() -> Uint { 33554432 }
fn min_slashing_penalty_quotient() -> Uint { 32 }
fn domain_beacon_proposer() -> Uint { 0 }
fn domain_randao() -> Uint { 1 }
fn domain_attestation() -> Uint { 2 }
fn domain_deposit() -> Uint { 3 }
fn domain_voluntary_exit() -> Uint { 4 }
fn domain_transfer() -> Uint { 5 }
}
#[derive(Default, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "std", derive(Debug))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "parity-codec", derive(parity_codec::Encode, parity_codec::Decode))]
pub struct MainnetConfig;
impl Config for MainnetConfig {
type Digest = sha2::Sha256;
type MaxValidatorsPerCommittee = typenum::U4096;
type SlotsPerHistoricalRoot = typenum::U8192;
type MaxProposerSlashings = typenum::U16;
type MaxAttesterSlashings = typenum::U1;
type MaxAttestations = typenum::U128;
type MaxDeposits = typenum::U16;
type MaxVoluntaryExits = typenum::U16;
type MaxTransfers = typenum::U0;
type HistoricalRootsLimit = typenum::U16777216;
type ShardCount = typenum::U1024;
type SlotsPerEpoch = typenum::U64;
type SlotsPerEth1VotingPeriod = typenum::U1024;
type ValidatorRegistryLimit = typenum::U1099511627776;
type EpochsPerHistoricalVector = typenum::U65536;
type EpochsPerSlashingsVector = typenum::U8192;
type MaxAttestationsPerEpoch = typenum::Prod<Self::MaxAttestations, Self::SlotsPerEpoch>;
fn target_committee_size() -> Uint { 128 }
fn min_per_epoch_churn_limit() -> Uint { 4 }
fn churn_limit_quotient() -> Uint { 65536 }
fn shuffle_round_count() -> Uint { 90 }
fn min_genesis_active_validator_count() -> Uint { 65536 }
fn min_genesis_time() -> Uint { 1578009600 }
fn min_deposit_amount() -> Uint { 1000000000 }
fn max_effective_balance() -> Uint { 32000000000 }
fn ejection_balance() -> Uint { 16000000000 }
fn effective_balance_increment() -> Uint { 1000000000 }
fn genesis_slot() -> Uint { 0 }
fn genesis_epoch() -> Uint { 0 }
fn bls_withdrawal_prefix_byte() -> u8 { 0x00 }
fn min_attestation_inclusion_delay() -> Uint { 1 }
fn min_seed_lookahead() -> Uint { 1 }
fn activation_exit_delay() -> Uint { 4 }
fn min_validator_withdrawability_delay() -> Uint { 256 }
fn persistent_committee_period() -> Uint { 2048 }
fn max_epochs_per_crosslink() -> Uint { 64 }
fn min_epochs_to_inactivity_penalty() -> Uint { 4 }
fn base_reward_factor() -> Uint { 64 }
fn whistleblower_reward_quotient() -> Uint { 512 }
fn proposer_reward_quotient() -> Uint { 8 }
fn inactivity_penalty_quotient() -> Uint { 33554432 }
fn min_slashing_penalty_quotient() -> Uint { 32 }
fn domain_beacon_proposer() -> Uint { 0 }
fn domain_randao() -> Uint { 1 }
fn domain_attestation() -> Uint { 2 }
fn domain_deposit() -> Uint { 3 }
fn domain_voluntary_exit() -> Uint { 4 }
fn domain_transfer() -> Uint { 5 }
}