add Altair domains and participation flags; clean up imports (#2462)
This commit is contained in:
parent
6b13cdce36
commit
8d7792e6e9
|
@ -1,5 +1,5 @@
|
||||||
# beacon_chain
|
# beacon_chain
|
||||||
# Copyright (c) 2018-2020 Status Research & Development GmbH
|
# Copyright (c) 2018-2021 Status Research & Development GmbH
|
||||||
# Licensed and distributed under either of
|
# Licensed and distributed under either of
|
||||||
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
# * 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).
|
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
||||||
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
import
|
import
|
||||||
# Standard library
|
# Standard library
|
||||||
std/[deques, strformat, sets, tables, hashes],
|
std/[strformat, sets, tables, hashes],
|
||||||
# Status libraries
|
# Status libraries
|
||||||
stew/[endians2, byteutils], chronicles,
|
stew/[endians2, byteutils], chronicles,
|
||||||
eth/keys,
|
eth/keys,
|
||||||
|
|
|
@ -45,7 +45,20 @@ const
|
||||||
TARGET_AGGREGATORS_PER_SYNC_SUBCOMMITTEE* = 4
|
TARGET_AGGREGATORS_PER_SYNC_SUBCOMMITTEE* = 4
|
||||||
SYNC_COMMITTEE_SUBNET_COUNT* = 8
|
SYNC_COMMITTEE_SUBNET_COUNT* = 8
|
||||||
|
|
||||||
|
let
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.2/specs/altair/beacon-chain.md#misc
|
||||||
|
# Cannot be computed at compile-time due to importc dependency
|
||||||
|
G2_POINT_AT_INFINITY* = ValidatorSig.fromRaw([
|
||||||
|
0xc0'u8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0])
|
||||||
|
|
||||||
type
|
type
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.2/specs/altair/beacon-chain.md#custom-types
|
||||||
|
ParticipationFlags* = distinct uint8
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.2/specs/altair/beacon-chain.md#syncaggregate
|
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.2/specs/altair/beacon-chain.md#syncaggregate
|
||||||
SyncAggregate* = object
|
SyncAggregate* = object
|
||||||
sync_committee_bits*: BitArray[SYNC_COMMITTEE_SIZE]
|
sync_committee_bits*: BitArray[SYNC_COMMITTEE_SIZE]
|
||||||
|
@ -110,7 +123,13 @@ type
|
||||||
subcommittee_index*: uint64
|
subcommittee_index*: uint64
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.2/specs/altair/beacon-chain.md#participation-flag-indices
|
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.2/specs/altair/beacon-chain.md#participation-flag-indices
|
||||||
ValidatorFlag* = enum
|
ParticipationFlag* = enum
|
||||||
TIMELY_HEAD_FLAG = 0
|
TIMELY_HEAD_FLAG_INDEX = 0
|
||||||
TIMELY_SOURCE_FLAG = 1
|
TIMELY_SOURCE_FLAG_INDEX = 1
|
||||||
TIMELY_TARGET_FLAG = 2
|
TIMELY_TARGET_FLAG_INDEX = 2
|
||||||
|
|
||||||
|
# TODO when https://github.com/nim-lang/Nim/issues/14440 lands in Status's Nim,
|
||||||
|
# switch proc {.noSideEffect.} to func.
|
||||||
|
proc `or`*(x, y: ParticipationFlags) : ParticipationFlags {.borrow, noSideEffect.}
|
||||||
|
proc `and`*(x, y: ParticipationFlags) : ParticipationFlags {.borrow, noSideEffect.}
|
||||||
|
proc `==`*(x, y: ParticipationFlags) : bool {.borrow, noSideEffect.}
|
||||||
|
|
|
@ -120,10 +120,12 @@ type
|
||||||
DOMAIN_SELECTION_PROOF = 5
|
DOMAIN_SELECTION_PROOF = 5
|
||||||
DOMAIN_AGGREGATE_AND_PROOF = 6
|
DOMAIN_AGGREGATE_AND_PROOF = 6
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.1/configs/mainnet/altair.yaml#L31
|
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.2/specs/altair/beacon-chain.md#domain-types
|
||||||
# Needs to be in same enum definition and is safe regardless of whether one
|
# Needs to be in same enum definition and is safe regardless of whether one
|
||||||
# only accesses phase 0 definitions
|
# only accesses phase 0 definitions
|
||||||
DOMAIN_SYNC_COMMITTEE = 7
|
DOMAIN_SYNC_COMMITTEE = 7
|
||||||
|
DOMAIN_SYNC_COMMITTEE_SELECTION_PROOF = 8
|
||||||
|
DOMAIN_CONTRIBUTION_AND_PROOF = 9
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v1.0.1/specs/phase0/beacon-chain.md#custom-types
|
# https://github.com/ethereum/eth2.0-specs/blob/v1.0.1/specs/phase0/beacon-chain.md#custom-types
|
||||||
Eth2Domain* = array[32, byte]
|
Eth2Domain* = array[32, byte]
|
||||||
|
|
|
@ -15,7 +15,7 @@ import
|
||||||
# Third-party
|
# Third-party
|
||||||
stew/endians2,
|
stew/endians2,
|
||||||
# Internal
|
# Internal
|
||||||
./datatypes, ./digest, ./crypto, ../ssz/merkleization
|
./datatypes/[phase0, altair], ./digest, ./crypto, ../ssz/merkleization
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v1.0.1/specs/phase0/beacon-chain.md#integer_squareroot
|
# https://github.com/ethereum/eth2.0-specs/blob/v1.0.1/specs/phase0/beacon-chain.md#integer_squareroot
|
||||||
func integer_squareroot*(n: SomeInteger): SomeInteger =
|
func integer_squareroot*(n: SomeInteger): SomeInteger =
|
||||||
|
@ -178,3 +178,21 @@ func get_seed*(state: BeaconState, epoch: Epoch, domain_type: DomainType): Eth2D
|
||||||
get_randao_mix(state, # Avoid underflow
|
get_randao_mix(state, # Avoid underflow
|
||||||
epoch + EPOCHS_PER_HISTORICAL_VECTOR - MIN_SEED_LOOKAHEAD - 1).data
|
epoch + EPOCHS_PER_HISTORICAL_VECTOR - MIN_SEED_LOOKAHEAD - 1).data
|
||||||
eth2digest(seed_input)
|
eth2digest(seed_input)
|
||||||
|
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.2/specs/altair/beacon-chain.md#get_flag_indices_and_weights
|
||||||
|
iterator get_flag_indices_and_weights*(): (ParticipationFlag, int) =
|
||||||
|
for item in [
|
||||||
|
(TIMELY_HEAD_FLAG_INDEX, TIMELY_HEAD_WEIGHT),
|
||||||
|
(TIMELY_SOURCE_FLAG_INDEX, TIMELY_SOURCE_WEIGHT),
|
||||||
|
(TIMELY_TARGET_FLAG_INDEX, TIMELY_TARGET_WEIGHT)]:
|
||||||
|
yield item
|
||||||
|
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.2/specs/altair/beacon-chain.md#add_flag
|
||||||
|
func add_flag*(flags: ParticipationFlags, flag_index: int): ParticipationFlags =
|
||||||
|
let flag = ParticipationFlags(1'u8 shl flag_index)
|
||||||
|
flags or flag
|
||||||
|
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.2/specs/altair/beacon-chain.md#has_flag
|
||||||
|
func has_flag*(flags: ParticipationFlags, flag_index: int): bool =
|
||||||
|
let flag = ParticipationFlags(1'u8 shl flag_index)
|
||||||
|
(flags and flag) == flag
|
||||||
|
|
|
@ -10,10 +10,12 @@ type
|
||||||
DOMAIN_AGGREGATE_AND_PROOF
|
DOMAIN_AGGREGATE_AND_PROOF
|
||||||
DOMAIN_BEACON_ATTESTER
|
DOMAIN_BEACON_ATTESTER
|
||||||
DOMAIN_BEACON_PROPOSER
|
DOMAIN_BEACON_PROPOSER
|
||||||
|
DOMAIN_CONTRIBUTION_AND_PROOF
|
||||||
DOMAIN_DEPOSIT
|
DOMAIN_DEPOSIT
|
||||||
DOMAIN_RANDAO
|
DOMAIN_RANDAO
|
||||||
DOMAIN_SELECTION_PROOF
|
DOMAIN_SELECTION_PROOF
|
||||||
DOMAIN_SYNC_COMMITTEE
|
DOMAIN_SYNC_COMMITTEE
|
||||||
|
DOMAIN_SYNC_COMMITTEE_SELECTION_PROOF
|
||||||
DOMAIN_VOLUNTARY_EXIT
|
DOMAIN_VOLUNTARY_EXIT
|
||||||
EFFECTIVE_BALANCE_INCREMENT
|
EFFECTIVE_BALANCE_INCREMENT
|
||||||
EJECTION_BALANCE
|
EJECTION_BALANCE
|
||||||
|
|
|
@ -63,6 +63,8 @@ const
|
||||||
DOMAIN_SELECTION_PROOF,
|
DOMAIN_SELECTION_PROOF,
|
||||||
DOMAIN_AGGREGATE_AND_PROOF,
|
DOMAIN_AGGREGATE_AND_PROOF,
|
||||||
DOMAIN_SYNC_COMMITTEE,
|
DOMAIN_SYNC_COMMITTEE,
|
||||||
|
DOMAIN_SYNC_COMMITTEE_SELECTION_PROOF,
|
||||||
|
DOMAIN_CONTRIBUTION_AND_PROOF,
|
||||||
CONFIG_NAME
|
CONFIG_NAME
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# beacon_chain
|
# beacon_chain
|
||||||
# Copyright (c) 2018-2020 Status Research & Development GmbH
|
# Copyright (c) 2018-2021 Status Research & Development GmbH
|
||||||
# Licensed and distributed under either of
|
# Licensed and distributed under either of
|
||||||
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
# * 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).
|
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
||||||
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
import
|
import
|
||||||
std/[typetraits, options],
|
std/[typetraits, options],
|
||||||
stew/[bitops2, endians2, objects],
|
stew/[endians2, objects],
|
||||||
../spec/[digest, datatypes], ./types, ./spec_types, ./merkleization
|
../spec/[digest, datatypes], ./types, ./spec_types, ./merkleization
|
||||||
|
|
||||||
template raiseIncorrectSize(T: type) =
|
template raiseIncorrectSize(T: type) =
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
import
|
import
|
||||||
std/[typetraits, options],
|
std/[typetraits, options],
|
||||||
stew/[bitops2, endians2, leb128, objects],
|
stew/[endians2, leb128, objects],
|
||||||
serialization, serialization/testing/tracing,
|
serialization, serialization/testing/tracing,
|
||||||
../spec/[digest, datatypes],
|
../spec/[digest, datatypes],
|
||||||
./bytes_reader, ./bitseqs, ./types, ./spec_types
|
./bytes_reader, ./bitseqs, ./types, ./spec_types
|
||||||
|
|
Loading…
Reference in New Issue