From dfd99ec94336b784d71845421ac2c15288f8cef1 Mon Sep 17 00:00:00 2001 From: tersec Date: Mon, 22 Mar 2021 14:44:45 +0000 Subject: [PATCH] Altair (HF1/v1.1.0) minimal and mainnet presets/constants (#2444) * Altair mainnet & minimal presets * std/math not used --- beacon_chain/spec/datatypes/base.nim | 7 ++- beacon_chain/spec/preset_values.nim | 2 + beacon_chain/spec/presets.nim | 8 +++- beacon_chain/spec/presets/altair/mainnet.nim | 50 ++++++++++++++++++++ beacon_chain/spec/presets/altair/minimal.nim | 50 ++++++++++++++++++++ 5 files changed, 115 insertions(+), 2 deletions(-) create mode 100644 beacon_chain/spec/presets/altair/mainnet.nim create mode 100644 beacon_chain/spec/presets/altair/minimal.nim diff --git a/beacon_chain/spec/datatypes/base.nim b/beacon_chain/spec/datatypes/base.nim index aa24becb7..63a5ca39c 100644 --- a/beacon_chain/spec/datatypes/base.nim +++ b/beacon_chain/spec/datatypes/base.nim @@ -114,8 +114,8 @@ template maxSize*(n: int) {.pragma.} type # Domains # --------------------------------------------------------------- - # https://github.com/ethereum/eth2.0-specs/blob/v1.0.1/specs/phase0/beacon-chain.md#domain-types DomainType* = enum + # https://github.com/ethereum/eth2.0-specs/blob/v1.0.1/specs/phase0/beacon-chain.md#domain-types DOMAIN_BEACON_PROPOSER = 0 DOMAIN_BEACON_ATTESTER = 1 DOMAIN_RANDAO = 2 @@ -124,6 +124,11 @@ type DOMAIN_SELECTION_PROOF = 5 DOMAIN_AGGREGATE_AND_PROOF = 6 + # https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.1/configs/mainnet/altair.yaml#L31 + # Needs to be in same enum definition and is safe regardless of whether one + # only accesses phase 0 definitions + DOMAIN_SYNC_COMMITTEE = 7 + # https://github.com/ethereum/eth2.0-specs/blob/v1.0.1/specs/phase0/beacon-chain.md#custom-types Domain* = array[32, byte] diff --git a/beacon_chain/spec/preset_values.nim b/beacon_chain/spec/preset_values.nim index e04d1dc66..d004d05b9 100644 --- a/beacon_chain/spec/preset_values.nim +++ b/beacon_chain/spec/preset_values.nim @@ -1,5 +1,6 @@ type PresetValue* {.pure.} = enum + ALTAIR_FORK_VERSION BASE_REWARD_FACTOR BLS_WITHDRAWAL_PREFIX CHURN_LIMIT_QUOTIENT @@ -12,6 +13,7 @@ type DOMAIN_DEPOSIT DOMAIN_RANDAO DOMAIN_SELECTION_PROOF + DOMAIN_SYNC_COMMITTEE DOMAIN_VOLUNTARY_EXIT EFFECTIVE_BALANCE_INCREMENT EJECTION_BALANCE diff --git a/beacon_chain/spec/presets.nim b/beacon_chain/spec/presets.nim index 1642dc73c..711920fcd 100644 --- a/beacon_chain/spec/presets.nim +++ b/beacon_chain/spec/presets.nim @@ -1,5 +1,5 @@ # beacon_chain -# Copyright (c) 2018-2020 Status Research & Development GmbH +# Copyright (c) 2018-2021 Status Research & Development GmbH # Licensed and distributed under either of # * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). @@ -22,6 +22,7 @@ type RuntimePreset* = object GENESIS_FORK_VERSION*: Version + ALTAIR_FORK_VERSION*: Version GENESIS_DELAY*: uint64 MIN_GENESIS_ACTIVE_VALIDATOR_COUNT*: uint64 MIN_GENESIS_TIME*: uint64 @@ -40,6 +41,7 @@ const MIN_GENESIS_ACTIVE_VALIDATOR_COUNT, MIN_GENESIS_TIME, GENESIS_FORK_VERSION, + ALTAIR_FORK_VERSION, GENESIS_DELAY, ETH1_FOLLOW_DISTANCE, } @@ -60,10 +62,12 @@ const DOMAIN_VOLUNTARY_EXIT, DOMAIN_SELECTION_PROOF, DOMAIN_AGGREGATE_AND_PROOF, + DOMAIN_SYNC_COMMITTEE, CONFIG_NAME } presetValueTypes* = { + ALTAIR_FORK_VERSION: "Version", BLS_WITHDRAWAL_PREFIX: "byte", GENESIS_FORK_VERSION: "Version", }.toTable @@ -133,6 +137,7 @@ const mainnetRuntimePreset* = RuntimePreset( MIN_GENESIS_ACTIVE_VALIDATOR_COUNT: 16384, MIN_GENESIS_TIME: 1606824000, # Dec 1, 2020, 12pm UTC GENESIS_FORK_VERSION: Version [byte 0, 0, 0, 0], + ALTAIR_FORK_VERSION: Version [byte 1, 0, 0, 0], GENESIS_DELAY: 604800, ETH1_FOLLOW_DISTANCE: 2048) @@ -141,6 +146,7 @@ const MIN_GENESIS_ACTIVE_VALIDATOR_COUNT: 64, MIN_GENESIS_TIME: 1606824000, # Dec 1, 2020, 12pm UTC GENESIS_FORK_VERSION: Version [byte 0, 0, 0, 1], + ALTAIR_FORK_VERSION: Version [byte 1, 0, 0, 0], GENESIS_DELAY: 300, ETH1_FOLLOW_DISTANCE: 16) diff --git a/beacon_chain/spec/presets/altair/mainnet.nim b/beacon_chain/spec/presets/altair/mainnet.nim new file mode 100644 index 000000000..7744f1725 --- /dev/null +++ b/beacon_chain/spec/presets/altair/mainnet.nim @@ -0,0 +1,50 @@ +# beacon_chain +# Copyright (c) 2021 Status Research & Development GmbH +# Licensed and distributed under either of +# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). +# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). +# at your option. This file may not be copied, modified, or distributed except according to those terms. + +# This file contains constants that are part of the spec and thus subject to +# serialization and spec updates. + +const + # Updated penalty values + # --------------------------------------------------------------- + # https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.1/configs/mainnet/altair.yaml#L5 + CONFIG_NAME* = "mainnet" + + INACTIVITY_PENALTY_QUOTIENT_ALTAIR* = 50331648 ##\ + ## 3 * 2**24 (= 50,331,648) + + MIN_SLASHING_PENALTY_QUOTIENT_ALTAIR* = 64 + PROPORTIONAL_SLASHING_MULTIPLIER_ALTAIR* = 2 + + # Misc + # --------------------------------------------------------------- + # https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.1/configs/mainnet/altair.yaml#L15 + SYNC_COMMITTEE_SIZE* = 1024 + SYNC_SUBCOMMITTEE_SIZE* = 64 + INACTIVITY_SCORE_BIAS* = 4 + + # Time parameters + # --------------------------------------------------------------- + # https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.1/configs/mainnet/altair.yaml#L25 + EPOCHS_PER_SYNC_COMMITTEE_PERIOD* = 256 + + # Signature domains (DOMAIN_SYNC_COMMITTEE) in spec/datatypes/base + + # Fork + # --------------------------------------------------------------- + # https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.1/configs/mainnet/altair.yaml#L36 + + # ALTAIR_FORK_VERSION is a runtime preset + + ALTAIR_FORK_SLOT* = 0 # TBD + + # Sync protocol + # --------------------------------------------------------------- + # https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.1/configs/mainnet/altair.yaml#L43 + MIN_SYNC_COMMITTEE_PARTICIPANTS* = 1 + MAX_VALID_LIGHT_CLIENT_UPDATES* = 8192 + LIGHT_CLIENT_UPDATE_TIMEOUT* = 8192 diff --git a/beacon_chain/spec/presets/altair/minimal.nim b/beacon_chain/spec/presets/altair/minimal.nim new file mode 100644 index 000000000..61b94e3dd --- /dev/null +++ b/beacon_chain/spec/presets/altair/minimal.nim @@ -0,0 +1,50 @@ +# beacon_chain +# Copyright (c) 2021 Status Research & Development GmbH +# Licensed and distributed under either of +# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). +# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). +# at your option. This file may not be copied, modified, or distributed except according to those terms. + +# This file contains constants that are part of the spec and thus subject to +# serialization and spec updates. + +const + # Updated penalty values + # --------------------------------------------------------------- + # https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.1/configs/minimal/altair.yaml#L5 + CONFIG_NAME* = "minimal" + + INACTIVITY_PENALTY_QUOTIENT_ALTAIR* = 50331648 ##\ + ## 3 * 2**24 (= 50,331,648) + + MIN_SLASHING_PENALTY_QUOTIENT_ALTAIR* = 64 + PROPORTIONAL_SLASHING_MULTIPLIER_ALTAIR* = 2 + + # Misc + # --------------------------------------------------------------- + # https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.1/configs/minimal/altair.yaml#L15 + SYNC_COMMITTEE_SIZE* = 32 + SYNC_SUBCOMMITTEE_SIZE* = 16 + INACTIVITY_SCORE_BIAS* = 4 + + # Time parameters + # --------------------------------------------------------------- + # https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.1/configs/minimal/altair.yaml#L25 + EPOCHS_PER_SYNC_COMMITTEE_PERIOD* = 8 + + # Signature domains (DOMAIN_SYNC_COMMITTEE) in spec/datatypes/base + + # Fork + # --------------------------------------------------------------- + # https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.1/configs/minimal/altair.yaml#L36 + + # ALTAIR_FORK_VERSION is a runtime preset + + ALTAIR_FORK_SLOT* = 0 # TBD + + # Sync protocol + # --------------------------------------------------------------- + # https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.1/configs/minimal/altair.yaml#L43 + MIN_SYNC_COMMITTEE_PARTICIPANTS* = 1 + MAX_VALID_LIGHT_CLIENT_UPDATES* = 32 + LIGHT_CLIENT_UPDATE_TIMEOUT* = 32