initial automated v1.2.0 -> v1.3.0-alpha.0 consensus spec URL update (#4296)

This commit is contained in:
tersec 2022-11-08 02:37:28 +00:00 committed by GitHub
parent 229b58b002
commit 909c095e64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
51 changed files with 261 additions and 261 deletions

View File

@ -15,7 +15,7 @@ import
./spec/[eth2_ssz_serialization, eth2_merkleization] ./spec/[eth2_ssz_serialization, eth2_merkleization]
type type
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#beaconstate # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#beaconstate
# Memory-representation-equivalent to a phase0 BeaconState for in-place SSZ reading and writing # Memory-representation-equivalent to a phase0 BeaconState for in-place SSZ reading and writing
Phase0BeaconStateNoImmutableValidators* = object Phase0BeaconStateNoImmutableValidators* = object
# Versioning # Versioning
@ -66,7 +66,7 @@ type
current_justified_checkpoint*: Checkpoint current_justified_checkpoint*: Checkpoint
finalized_checkpoint*: Checkpoint finalized_checkpoint*: Checkpoint
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/beacon-chain.md#beaconstate # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/beacon-chain.md#beaconstate
# Memory-representation-equivalent to an Altair BeaconState for in-place SSZ # Memory-representation-equivalent to an Altair BeaconState for in-place SSZ
# reading and writing # reading and writing
AltairBeaconStateNoImmutableValidators* = object AltairBeaconStateNoImmutableValidators* = object

View File

@ -29,7 +29,7 @@ type
## which blocks are valid - in particular, blocks are not valid if they ## which blocks are valid - in particular, blocks are not valid if they
## come from the future as seen from the local clock. ## come from the future as seen from the local clock.
## ##
## https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/fork-choice.md#fork-choice ## https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/fork-choice.md#fork-choice
## ##
# TODO consider NTP and network-adjusted timestamps as outlined here: # TODO consider NTP and network-adjusted timestamps as outlined here:
# https://ethresear.ch/t/network-adjusted-timestamps/4187 # https://ethresear.ch/t/network-adjusted-timestamps/4187

View File

@ -7,9 +7,9 @@ to specs:
- blocks: https://github.com/ethereum/consensus-specs/blob/v1.1.10/specs/phase0/p2p-interface.md#beacon_block - blocks: https://github.com/ethereum/consensus-specs/blob/v1.1.10/specs/phase0/p2p-interface.md#beacon_block
- aggregate attestations: https://github.com/ethereum/consensus-specs/blob/v1.1.10/specs/phase0/p2p-interface.md#beacon_aggregate_and_proof - aggregate attestations: https://github.com/ethereum/consensus-specs/blob/v1.1.10/specs/phase0/p2p-interface.md#beacon_aggregate_and_proof
- unaggregated attestation: https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/p2p-interface.md#beacon_attestation_subnet_id - unaggregated attestation: https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/p2p-interface.md#beacon_attestation_subnet_id
- voluntary exits: https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/p2p-interface.md#voluntary_exit - voluntary exits: https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/p2p-interface.md#voluntary_exit
- Attester slashings: https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/p2p-interface.md#attester_slashing - Attester slashings: https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/p2p-interface.md#attester_slashing
- Proposer slashings: https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/p2p-interface.md#proposer_slashing - Proposer slashings: https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/p2p-interface.md#proposer_slashing
After "gossip validation" the consensus objects can be rebroadcasted as they are optimistically good, however for internal processing further verification is needed. After "gossip validation" the consensus objects can be rebroadcasted as they are optimistically good, however for internal processing further verification is needed.
For blocks, this means verifying state transition and all contained cryptographic signatures (instead of just the proposer signature). For blocks, this means verifying state transition and all contained cryptographic signatures (instead of just the proposer signature).

View File

@ -564,7 +564,7 @@ proc getAttestationsForBlock*(pool: var AttestationPool,
cache: var StateCache): seq[Attestation] = cache: var StateCache): seq[Attestation] =
## Retrieve attestations that may be added to a new block at the slot of the ## Retrieve attestations that may be added to a new block at the slot of the
## given state ## given state
## https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/validator.md#attestations ## https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/validator.md#attestations
let newBlockSlot = state.data.slot.uint64 let newBlockSlot = state.data.slot.uint64
if newBlockSlot < MIN_ATTESTATION_INCLUSION_DELAY: if newBlockSlot < MIN_ATTESTATION_INCLUSION_DELAY:
@ -785,7 +785,7 @@ proc getBeaconHead*(
finalizedExecutionPayloadHash = finalizedExecutionPayloadHash =
pool.dag.loadExecutionBlockRoot(pool.dag.finalizedHead.blck) pool.dag.loadExecutionBlockRoot(pool.dag.finalizedHead.blck)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/fork_choice/safe-block.md#get_safe_execution_payload_hash # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/fork_choice/safe-block.md#get_safe_execution_payload_hash
safeBlockRoot = pool.forkChoice.get_safe_beacon_block_root() safeBlockRoot = pool.forkChoice.get_safe_beacon_block_root()
safeBlock = pool.dag.getBlockRef(safeBlockRoot) safeBlock = pool.dag.getBlockRef(safeBlockRoot)
safeExecutionPayloadHash = safeExecutionPayloadHash =

View File

@ -129,7 +129,7 @@ func link*(parent, child: BlockRef) =
func get_ancestor*(blck: BlockRef, slot: Slot, func get_ancestor*(blck: BlockRef, slot: Slot,
maxDepth = 100'i64 * 365 * 24 * 60 * 60 div SECONDS_PER_SLOT.int): maxDepth = 100'i64 * 365 * 24 * 60 * 60 div SECONDS_PER_SLOT.int):
BlockRef = BlockRef =
## https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/fork-choice.md#get_ancestor ## https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/fork-choice.md#get_ancestor
## Return the most recent block as of the time at `slot` that not more recent ## Return the most recent block as of the time at `slot` that not more recent
## than `blck` itself ## than `blck` itself
if isNil(blck): return nil if isNil(blck): return nil

View File

@ -240,7 +240,7 @@ type
## committee messages will be rejected ## committee messages will be rejected
optimisticRoots*: HashSet[Eth2Digest] optimisticRoots*: HashSet[Eth2Digest]
## https://github.com/ethereum/consensus-specs/blob/v1.2.0/sync/optimistic.md#helpers ## https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/sync/optimistic.md#helpers
EpochKey* = object EpochKey* = object
## The epoch key fully determines the shuffling for proposers and ## The epoch key fully determines the shuffling for proposers and

View File

@ -28,7 +28,7 @@ logScope: topics = "spec_cache"
func count_active_validators*(shufflingRef: ShufflingRef): uint64 = func count_active_validators*(shufflingRef: ShufflingRef): uint64 =
shufflingRef.shuffled_active_validator_indices.lenu64 shufflingRef.shuffled_active_validator_indices.lenu64
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#get_committee_count_per_slot # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#get_committee_count_per_slot
func get_committee_count_per_slot*(shufflingRef: ShufflingRef): uint64 = func get_committee_count_per_slot*(shufflingRef: ShufflingRef): uint64 =
get_committee_count_per_slot(count_active_validators(shufflingRef)) get_committee_count_per_slot(count_active_validators(shufflingRef))
@ -41,7 +41,7 @@ func get_committee_index*(shufflingRef: ShufflingRef, index: uint64):
Result[CommitteeIndex, cstring] = Result[CommitteeIndex, cstring] =
check_attestation_index(index, get_committee_count_per_slot(shufflingRef)) check_attestation_index(index, get_committee_count_per_slot(shufflingRef))
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#get_beacon_committee # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#get_beacon_committee
iterator get_beacon_committee*( iterator get_beacon_committee*(
shufflingRef: ShufflingRef, slot: Slot, committee_index: CommitteeIndex): shufflingRef: ShufflingRef, slot: Slot, committee_index: CommitteeIndex):
(int, ValidatorIndex) = (int, ValidatorIndex) =
@ -54,7 +54,7 @@ iterator get_beacon_committee*(
committees_per_slot * SLOTS_PER_EPOCH committees_per_slot * SLOTS_PER_EPOCH
): yield (index_in_committee, idx) ): yield (index_in_committee, idx)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#get_beacon_committee # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#get_beacon_committee
func get_beacon_committee*( func get_beacon_committee*(
shufflingRef: ShufflingRef, slot: Slot, committee_index: CommitteeIndex): shufflingRef: ShufflingRef, slot: Slot, committee_index: CommitteeIndex):
seq[ValidatorIndex] = seq[ValidatorIndex] =
@ -67,7 +67,7 @@ func get_beacon_committee*(
committees_per_slot * SLOTS_PER_EPOCH committees_per_slot * SLOTS_PER_EPOCH
) )
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#get_beacon_committee # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#get_beacon_committee
func get_beacon_committee_len*( func get_beacon_committee_len*(
shufflingRef: ShufflingRef, slot: Slot, committee_index: CommitteeIndex): uint64 = shufflingRef: ShufflingRef, slot: Slot, committee_index: CommitteeIndex): uint64 =
## Return the number of members in the beacon committee at ``slot`` for ``index``. ## Return the number of members in the beacon committee at ``slot`` for ``index``.
@ -79,7 +79,7 @@ func get_beacon_committee_len*(
committees_per_slot * SLOTS_PER_EPOCH committees_per_slot * SLOTS_PER_EPOCH
) )
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#get_attesting_indices # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#get_attesting_indices
iterator get_attesting_indices*(shufflingRef: ShufflingRef, iterator get_attesting_indices*(shufflingRef: ShufflingRef,
slot: Slot, slot: Slot,
committee_index: CommitteeIndex, committee_index: CommitteeIndex,
@ -158,7 +158,7 @@ func get_attesting_indices_one*(shufflingRef: ShufflingRef,
res = some(validator_index) res = some(validator_index)
res res
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#get_attesting_indices # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#get_attesting_indices
func get_attesting_indices*(shufflingRef: ShufflingRef, func get_attesting_indices*(shufflingRef: ShufflingRef,
slot: Slot, slot: Slot,
committee_index: CommitteeIndex, committee_index: CommitteeIndex,
@ -184,7 +184,7 @@ func makeAttestationData*(
doAssert current_epoch == epochRef.epoch doAssert current_epoch == epochRef.epoch
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/validator.md#attestation-data # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/validator.md#attestation-data
AttestationData( AttestationData(
slot: slot, slot: slot,
index: committee_index.asUInt64, index: committee_index.asUInt64,
@ -194,7 +194,7 @@ func makeAttestationData*(
epoch: current_epoch, epoch: current_epoch,
root: epoch_boundary_block.blck.root)) root: epoch_boundary_block.blck.root))
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/validator.md#validator-assignments # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/validator.md#validator-assignments
iterator get_committee_assignments*( iterator get_committee_assignments*(
shufflingRef: ShufflingRef, validator_indices: HashSet[ValidatorIndex]): shufflingRef: ShufflingRef, validator_indices: HashSet[ValidatorIndex]):
tuple[committee_index: CommitteeIndex, tuple[committee_index: CommitteeIndex,

View File

@ -296,11 +296,11 @@ template toGaugeValue(x: Quantity): int64 =
# doAssert SECONDS_PER_ETH1_BLOCK * cfg.ETH1_FOLLOW_DISTANCE < GENESIS_DELAY, # doAssert SECONDS_PER_ETH1_BLOCK * cfg.ETH1_FOLLOW_DISTANCE < GENESIS_DELAY,
# "Invalid configuration: GENESIS_DELAY is set too low" # "Invalid configuration: GENESIS_DELAY is set too low"
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/validator.md#get_eth1_data # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/validator.md#get_eth1_data
func compute_time_at_slot(genesis_time: uint64, slot: Slot): uint64 = func compute_time_at_slot(genesis_time: uint64, slot: Slot): uint64 =
genesis_time + slot * SECONDS_PER_SLOT genesis_time + slot * SECONDS_PER_SLOT
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/validator.md#get_eth1_data # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/validator.md#get_eth1_data
func voting_period_start_time(state: ForkedHashedBeaconState): uint64 = func voting_period_start_time(state: ForkedHashedBeaconState): uint64 =
let eth1_voting_period_start_slot = let eth1_voting_period_start_slot =
getStateField(state, slot) - getStateField(state, slot) mod getStateField(state, slot) - getStateField(state, slot) mod
@ -308,7 +308,7 @@ func voting_period_start_time(state: ForkedHashedBeaconState): uint64 =
compute_time_at_slot( compute_time_at_slot(
getStateField(state, genesis_time), eth1_voting_period_start_slot) getStateField(state, genesis_time), eth1_voting_period_start_slot)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/validator.md#get_eth1_data # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/validator.md#get_eth1_data
func is_candidate_block(cfg: RuntimeConfig, func is_candidate_block(cfg: RuntimeConfig,
blk: Eth1Block, blk: Eth1Block,
period_start: uint64): bool = period_start: uint64): bool =
@ -859,7 +859,7 @@ template trackFinalizedState*(m: Eth1Monitor,
finalizedStateDepositIndex: uint64): bool = finalizedStateDepositIndex: uint64): bool =
trackFinalizedState(m.depositsChain, finalizedEth1Data, finalizedStateDepositIndex) trackFinalizedState(m.depositsChain, finalizedEth1Data, finalizedStateDepositIndex)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/validator.md#get_eth1_data # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/validator.md#get_eth1_data
proc getBlockProposalData*(chain: var Eth1Chain, proc getBlockProposalData*(chain: var Eth1Chain,
state: ForkedHashedBeaconState, state: ForkedHashedBeaconState,
finalizedEth1Data: Eth1Data, finalizedEth1Data: Eth1Data,

View File

@ -10,7 +10,7 @@ when (NimMajor, NimMinor) < (1, 4):
else: else:
{.push raises: [].} {.push raises: [].}
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/tests/core/pyspec/eth2spec/utils/merkle_minimal.py # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/tests/core/pyspec/eth2spec/utils/merkle_minimal.py
# Merkle tree helpers # Merkle tree helpers
# --------------------------------------------------------------- # ---------------------------------------------------------------

View File

@ -86,7 +86,7 @@ func extend[T](s: var seq[T], minLen: int) =
if s.len < minLen: if s.len < minLen:
s.setLen(minLen) s.setLen(minLen)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/fork-choice.md#should_update_justified_checkpoint # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/fork-choice.md#should_update_justified_checkpoint
func should_update_justified_checkpoint( func should_update_justified_checkpoint(
self: var Checkpoints, dag: ChainDAGRef, self: var Checkpoints, dag: ChainDAGRef,
new_justified_checkpoint: Checkpoint): FcResult[bool] = new_justified_checkpoint: Checkpoint): FcResult[bool] =
@ -140,7 +140,7 @@ proc update_justified(
self.update_justified(dag, blck, justified.epoch) self.update_justified(dag, blck, justified.epoch)
ok() ok()
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/fork-choice.md#on_block # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/fork-choice.md#on_block
proc update_checkpoints( proc update_checkpoints(
self: var Checkpoints, dag: ChainDAGRef, self: var Checkpoints, dag: ChainDAGRef,
checkpoints: FinalityCheckpoints): FcResult[void] = checkpoints: FinalityCheckpoints): FcResult[void] =
@ -163,7 +163,7 @@ proc update_checkpoints(
ok() ok()
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/fork-choice.md#on_tick # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/fork-choice.md#on_tick
proc on_tick( proc on_tick(
self: var ForkChoice, dag: ChainDAGRef, time: BeaconTime): FcResult[void] = self: var ForkChoice, dag: ChainDAGRef, time: BeaconTime): FcResult[void] =
## Must be called at least once per slot. ## Must be called at least once per slot.
@ -292,7 +292,7 @@ proc on_attestation*(
block_root: beacon_block_root)) block_root: beacon_block_root))
ok() ok()
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/fork-choice.md#on_attester_slashing # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/fork-choice.md#on_attester_slashing
func process_equivocation*( func process_equivocation*(
self: var ForkChoice, self: var ForkChoice,
validator_index: ValidatorIndex validator_index: ValidatorIndex
@ -308,7 +308,7 @@ func process_equivocation*(
trace "Integrating equivocation in fork choice", trace "Integrating equivocation in fork choice",
validator_index validator_index
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/fork-choice.md#on_block # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/fork-choice.md#on_block
func process_block*(self: var ForkChoiceBackend, func process_block*(self: var ForkChoiceBackend,
block_root: Eth2Digest, block_root: Eth2Digest,
parent_root: Eth2Digest, parent_root: Eth2Digest,
@ -421,7 +421,7 @@ proc get_head*(self: var ForkChoice,
self.checkpoints.justified.balances, self.checkpoints.justified.balances,
self.checkpoints.proposer_boost_root) self.checkpoints.proposer_boost_root)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/fork_choice/safe-block.md#get_safe_beacon_block_root # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/fork_choice/safe-block.md#get_safe_beacon_block_root
func get_safe_beacon_block_root*(self: ForkChoice): Eth2Digest = func get_safe_beacon_block_root*(self: ForkChoice): Eth2Digest =
# Use most recent justified block as a stopgap # Use most recent justified block as a stopgap
self.checkpoints.justified.checkpoint.root self.checkpoints.justified.checkpoint.root

View File

@ -533,7 +533,7 @@ func nodeLeadsToViableHead(self: ProtoArray, node: ProtoNode): FcResult[bool] =
func nodeIsViableForHead(self: ProtoArray, node: ProtoNode): bool = func nodeIsViableForHead(self: ProtoArray, node: ProtoNode): bool =
## This is the equivalent of `filter_block_tree` function in eth2 spec ## This is the equivalent of `filter_block_tree` function in eth2 spec
## https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/fork-choice.md#filter_block_tree ## https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/fork-choice.md#filter_block_tree
if node.invalid: if node.invalid:
return false return false

View File

@ -12,9 +12,9 @@ Gossip validation is different from consensus verification in particular for blo
- Blocks: https://github.com/ethereum/consensus-specs/blob/v1.1.10/specs/phase0/p2p-interface.md#beacon_block - Blocks: https://github.com/ethereum/consensus-specs/blob/v1.1.10/specs/phase0/p2p-interface.md#beacon_block
- Attestations (aggregated): https://github.com/ethereum/consensus-specs/blob/v1.1.10/specs/phase0/p2p-interface.md#beacon_aggregate_and_proof - Attestations (aggregated): https://github.com/ethereum/consensus-specs/blob/v1.1.10/specs/phase0/p2p-interface.md#beacon_aggregate_and_proof
- Attestations (unaggregated): https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/p2p-interface.md#attestation-subnets - Attestations (unaggregated): https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/p2p-interface.md#attestation-subnets
- Voluntary exits: https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/p2p-interface.md#voluntary_exit - Voluntary exits: https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/p2p-interface.md#voluntary_exit
- Proposer slashings: https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/p2p-interface.md#proposer_slashing - Proposer slashings: https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/p2p-interface.md#proposer_slashing
- Attester slashing: https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/p2p-interface.md#attester_slashing - Attester slashing: https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/p2p-interface.md#attester_slashing
There are multiple consumers of validated consensus objects: There are multiple consumers of validated consensus objects:
- a `ValidationResult.Accept` output triggers rebroadcasting in libp2p - a `ValidationResult.Accept` output triggers rebroadcasting in libp2p

View File

@ -596,7 +596,7 @@ proc processBlock(
# - MUST NOT optimistically import the block. # - MUST NOT optimistically import the block.
# - MUST NOT apply the block to the fork choice store. # - MUST NOT apply the block to the fork choice store.
# - MAY queue the block for later processing. # - MAY queue the block for later processing.
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/sync/optimistic.md#execution-engine-errors # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/sync/optimistic.md#execution-engine-errors
await sleepAsync(chronos.seconds(1)) await sleepAsync(chronos.seconds(1))
self[].addBlock( self[].addBlock(
entry.src, entry.blck, entry.resfut, entry.validationDur) entry.src, entry.blck, entry.resfut, entry.validationDur)

View File

@ -566,7 +566,7 @@ proc processSignedContributionAndProof*(
err(v.error()) err(v.error())
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/light-client/sync-protocol.md#process_light_client_finality_update # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/light-client/sync-protocol.md#process_light_client_finality_update
proc processLightClientFinalityUpdate*( proc processLightClientFinalityUpdate*(
self: var Eth2Processor, src: MsgSource, self: var Eth2Processor, src: MsgSource,
finality_update: altair.LightClientFinalityUpdate finality_update: altair.LightClientFinalityUpdate
@ -577,7 +577,7 @@ proc processLightClientFinalityUpdate*(
self.lightClientPool[], self.dag, finality_update, wallTime) self.lightClientPool[], self.dag, finality_update, wallTime)
v v
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/light-client/sync-protocol.md#process_light_client_optimistic_update # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/light-client/sync-protocol.md#process_light_client_optimistic_update
proc processLightClientOptimisticUpdate*( proc processLightClientOptimisticUpdate*(
self: var Eth2Processor, src: MsgSource, self: var Eth2Processor, src: MsgSource,
optimistic_update: altair.LightClientOptimisticUpdate optimistic_update: altair.LightClientOptimisticUpdate

View File

@ -94,7 +94,7 @@ func check_propagation_slot_range(
let let
pastSlot = (wallTime - MAXIMUM_GOSSIP_CLOCK_DISPARITY).toSlot() pastSlot = (wallTime - MAXIMUM_GOSSIP_CLOCK_DISPARITY).toSlot()
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/p2p-interface.md#configuration # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/p2p-interface.md#configuration
# The spec value of ATTESTATION_PROPAGATION_SLOT_RANGE is 32, but it can # The spec value of ATTESTATION_PROPAGATION_SLOT_RANGE is 32, but it can
# retransmit attestations on the cusp of being out of spec, and which by # retransmit attestations on the cusp of being out of spec, and which by
# the time they reach their destination might be out of spec. # the time they reach their destination might be out of spec.
@ -180,7 +180,7 @@ template validateBeaconBlockBellatrix(
parent: BlockRef): untyped = parent: BlockRef): untyped =
discard discard
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/bellatrix/p2p-interface.md#beacon_block # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/bellatrix/p2p-interface.md#beacon_block
template validateBeaconBlockBellatrix( template validateBeaconBlockBellatrix(
signed_beacon_block: bellatrix.SignedBeaconBlock, signed_beacon_block: bellatrix.SignedBeaconBlock,
parent: BlockRef): untyped = parent: BlockRef): untyped =
@ -221,7 +221,7 @@ template validateBeaconBlockBellatrix(
# `ACCEPTED` or `SYNCING` from the EL to get this far. # `ACCEPTED` or `SYNCING` from the EL to get this far.
# https://github.com/ethereum/consensus-specs/blob/v1.1.9/specs/phase0/p2p-interface.md#beacon_block # https://github.com/ethereum/consensus-specs/blob/v1.1.9/specs/phase0/p2p-interface.md#beacon_block
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/bellatrix/p2p-interface.md#beacon_block # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/bellatrix/p2p-interface.md#beacon_block
proc validateBeaconBlock*( proc validateBeaconBlock*(
dag: ChainDAGRef, quarantine: ref Quarantine, dag: ChainDAGRef, quarantine: ref Quarantine,
signed_beacon_block: phase0.SignedBeaconBlock | altair.SignedBeaconBlock | signed_beacon_block: phase0.SignedBeaconBlock | altair.SignedBeaconBlock |
@ -249,7 +249,7 @@ proc validateBeaconBlock*(
# proposer for the slot, signed_beacon_block.message.slot. # proposer for the slot, signed_beacon_block.message.slot.
# #
# While this condition is similar to the proposer slashing condition at # While this condition is similar to the proposer slashing condition at
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/validator.md#proposer-slashing # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/validator.md#proposer-slashing
# it's not identical, and this check does not address slashing: # it's not identical, and this check does not address slashing:
# #
# (1) The beacon blocks must be conflicting, i.e. different, for the same # (1) The beacon blocks must be conflicting, i.e. different, for the same
@ -300,7 +300,7 @@ proc validateBeaconBlock*(
if signed_beacon_block.message.parent_root in quarantine[].unviable: if signed_beacon_block.message.parent_root in quarantine[].unviable:
quarantine[].addUnviable(signed_beacon_block.root) quarantine[].addUnviable(signed_beacon_block.root)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/bellatrix/p2p-interface.md#beacon_block # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/bellatrix/p2p-interface.md#beacon_block
# `is_execution_enabled(state, block.body)` check, but unlike in # `is_execution_enabled(state, block.body)` check, but unlike in
# validateBeaconBlockBellatrix() don't have parent BlockRef. # validateBeaconBlockBellatrix() don't have parent BlockRef.
if signed_beacon_block.message.is_execution_block or if signed_beacon_block.message.is_execution_block or
@ -764,7 +764,7 @@ proc validateAggregate*(
return ok((attesting_indices, sig)) return ok((attesting_indices, sig))
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/p2p-interface.md#attester_slashing # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/p2p-interface.md#attester_slashing
proc validateAttesterSlashing*( proc validateAttesterSlashing*(
pool: ExitPool, attester_slashing: AttesterSlashing): pool: ExitPool, attester_slashing: AttesterSlashing):
Result[void, ValidationError] = Result[void, ValidationError] =
@ -787,7 +787,7 @@ proc validateAttesterSlashing*(
ok() ok()
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/p2p-interface.md#proposer_slashing # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/p2p-interface.md#proposer_slashing
proc validateProposerSlashing*( proc validateProposerSlashing*(
pool: ExitPool, proposer_slashing: ProposerSlashing): pool: ExitPool, proposer_slashing: ProposerSlashing):
Result[void, ValidationError] = Result[void, ValidationError] =
@ -840,7 +840,7 @@ proc validateVoluntaryExit*(
ok() ok()
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/p2p-interface.md#sync_committee_subnet_id # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/p2p-interface.md#sync_committee_subnet_id
proc validateSyncCommitteeMessage*( proc validateSyncCommitteeMessage*(
dag: ChainDAGRef, dag: ChainDAGRef,
batchCrypto: ref BatchCrypto, batchCrypto: ref BatchCrypto,
@ -1045,7 +1045,7 @@ proc validateContribution*(
return ok((sig, participants)) return ok((sig, participants))
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/light-client/p2p-interface.md#light_client_finality_update # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/light-client/p2p-interface.md#light_client_finality_update
proc validateLightClientFinalityUpdate*( proc validateLightClientFinalityUpdate*(
pool: var LightClientPool, dag: ChainDAGRef, pool: var LightClientPool, dag: ChainDAGRef,
finality_update: altair.LightClientFinalityUpdate, finality_update: altair.LightClientFinalityUpdate,
@ -1073,7 +1073,7 @@ proc validateLightClientFinalityUpdate*(
pool.latestForwardedFinalitySlot = finalized_slot pool.latestForwardedFinalitySlot = finalized_slot
ok() ok()
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/light-client/p2p-interface.md#light_client_optimistic_update # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/light-client/p2p-interface.md#light_client_optimistic_update
proc validateLightClientOptimisticUpdate*( proc validateLightClientOptimisticUpdate*(
pool: var LightClientPool, dag: ChainDAGRef, pool: var LightClientPool, dag: ChainDAGRef,
optimistic_update: altair.LightClientOptimisticUpdate, optimistic_update: altair.LightClientOptimisticUpdate,

View File

@ -431,7 +431,7 @@ func toValidationError(
# `attested_header.slot` was already forwarded on the network. # `attested_header.slot` was already forwarded on the network.
errIgnore($r.error) errIgnore($r.error)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/light-client/sync-protocol.md#process_light_client_finality_update # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/light-client/sync-protocol.md#process_light_client_finality_update
proc processLightClientFinalityUpdate*( proc processLightClientFinalityUpdate*(
self: var LightClientProcessor, src: MsgSource, self: var LightClientProcessor, src: MsgSource,
finality_update: altair.LightClientFinalityUpdate finality_update: altair.LightClientFinalityUpdate
@ -444,7 +444,7 @@ proc processLightClientFinalityUpdate*(
self.latestFinalityUpdate = finality_update.toOptimistic self.latestFinalityUpdate = finality_update.toOptimistic
v v
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/light-client/sync-protocol.md#process_light_client_finality_update # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/light-client/sync-protocol.md#process_light_client_finality_update
proc processLightClientOptimisticUpdate*( proc processLightClientOptimisticUpdate*(
self: var LightClientProcessor, src: MsgSource, self: var LightClientProcessor, src: MsgSource,
optimistic_update: altair.LightClientOptimisticUpdate optimistic_update: altair.LightClientOptimisticUpdate

View File

@ -174,7 +174,7 @@ type
MounterProc* = proc(network: Eth2Node) {.gcsafe, raises: [Defect, CatchableError].} MounterProc* = proc(network: Eth2Node) {.gcsafe, raises: [Defect, CatchableError].}
MessageContentPrinter* = proc(msg: pointer): string {.gcsafe, raises: [Defect].} MessageContentPrinter* = proc(msg: pointer): string {.gcsafe, raises: [Defect].}
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/p2p-interface.md#goodbye # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/p2p-interface.md#goodbye
DisconnectionReason* = enum DisconnectionReason* = enum
# might see other values on the wire! # might see other values on the wire!
ClientShutDown = 1 ClientShutDown = 1
@ -2230,8 +2230,8 @@ proc getPersistentNetKeys*(
func gossipId( func gossipId(
data: openArray[byte], phase0Prefix, topic: string): seq[byte] = data: openArray[byte], phase0Prefix, topic: string): seq[byte] =
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/p2p-interface.md#topics-and-messages # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/p2p-interface.md#topics-and-messages
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/p2p-interface.md#topics-and-messages # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/p2p-interface.md#topics-and-messages
const const
MESSAGE_DOMAIN_INVALID_SNAPPY = [0x00'u8, 0x00, 0x00, 0x00] MESSAGE_DOMAIN_INVALID_SNAPPY = [0x00'u8, 0x00, 0x00, 0x00]
MESSAGE_DOMAIN_VALID_SNAPPY = [0x01'u8, 0x00, 0x00, 0x00] MESSAGE_DOMAIN_VALID_SNAPPY = [0x01'u8, 0x00, 0x00, 0x00]
@ -2496,7 +2496,7 @@ proc broadcast(node: Eth2Node, topic: string, msg: auto):
proc subscribeAttestationSubnets*( proc subscribeAttestationSubnets*(
node: Eth2Node, subnets: AttnetBits, forkDigest: ForkDigest) = node: Eth2Node, subnets: AttnetBits, forkDigest: ForkDigest) =
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/p2p-interface.md#attestations-and-aggregation # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/p2p-interface.md#attestations-and-aggregation
# Nimbus won't score attestation subnets for now, we just rely on block and # Nimbus won't score attestation subnets for now, we just rely on block and
# aggregate which are more stable and reliable # aggregate which are more stable and reliable
@ -2507,7 +2507,7 @@ proc subscribeAttestationSubnets*(
proc unsubscribeAttestationSubnets*( proc unsubscribeAttestationSubnets*(
node: Eth2Node, subnets: AttnetBits, forkDigest: ForkDigest) = node: Eth2Node, subnets: AttnetBits, forkDigest: ForkDigest) =
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/p2p-interface.md#attestations-and-aggregation # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/p2p-interface.md#attestations-and-aggregation
# Nimbus won't score attestation subnets for now; we just rely on block and # Nimbus won't score attestation subnets for now; we just rely on block and
# aggregate which are more stable and reliable # aggregate which are more stable and reliable
@ -2516,15 +2516,15 @@ proc unsubscribeAttestationSubnets*(
node.unsubscribe(getAttestationTopic(forkDigest, SubnetId(subnet_id))) node.unsubscribe(getAttestationTopic(forkDigest, SubnetId(subnet_id)))
proc updateStabilitySubnetMetadata*(node: Eth2Node, attnets: AttnetBits) = proc updateStabilitySubnetMetadata*(node: Eth2Node, attnets: AttnetBits) =
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/p2p-interface.md#metadata # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/p2p-interface.md#metadata
if node.metadata.attnets == attnets: if node.metadata.attnets == attnets:
return return
node.metadata.seq_number += 1 node.metadata.seq_number += 1
node.metadata.attnets = attnets node.metadata.attnets = attnets
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/validator.md#phase-0-attestation-subnet-stability # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/validator.md#phase-0-attestation-subnet-stability
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/p2p-interface.md#attestation-subnet-bitfield # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/p2p-interface.md#attestation-subnet-bitfield
let res = node.discovery.updateRecord({ let res = node.discovery.updateRecord({
enrAttestationSubnetsField: SSZ.encode(node.metadata.attnets) enrAttestationSubnetsField: SSZ.encode(node.metadata.attnets)
}) })
@ -2577,7 +2577,7 @@ proc broadcastAttestation*(
node: Eth2Node, subnet_id: SubnetId, attestation: Attestation): node: Eth2Node, subnet_id: SubnetId, attestation: Attestation):
Future[SendResult] = Future[SendResult] =
# Regardless of the contents of the attestation, # Regardless of the contents of the attestation,
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/p2p-interface.md#transitioning-the-gossip # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/p2p-interface.md#transitioning-the-gossip
# implies that pre-fork, messages using post-fork digests might be # implies that pre-fork, messages using post-fork digests might be
# ignored, whilst post-fork, there is effectively a seen_ttl-based # ignored, whilst post-fork, there is effectively a seen_ttl-based
# timer unsubscription point that means no new pre-fork-forkdigest # timer unsubscription point that means no new pre-fork-forkdigest

View File

@ -22,7 +22,7 @@ proc installConfigApiHandlers*(router: var RestRouter, node: BeaconNode) =
cachedConfigSpec = cachedConfigSpec =
RestApiResponse.prepareJsonResponse( RestApiResponse.prepareJsonResponse(
( (
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/presets/mainnet/phase0.yaml # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/presets/mainnet/phase0.yaml
MAX_COMMITTEES_PER_SLOT: MAX_COMMITTEES_PER_SLOT:
Base10.toString(MAX_COMMITTEES_PER_SLOT), Base10.toString(MAX_COMMITTEES_PER_SLOT),
TARGET_COMMITTEE_SIZE: TARGET_COMMITTEE_SIZE:
@ -90,7 +90,7 @@ proc installConfigApiHandlers*(router: var RestRouter, node: BeaconNode) =
MAX_VOLUNTARY_EXITS: MAX_VOLUNTARY_EXITS:
Base10.toString(MAX_VOLUNTARY_EXITS), Base10.toString(MAX_VOLUNTARY_EXITS),
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/presets/mainnet/altair.yaml # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/presets/mainnet/altair.yaml
INACTIVITY_PENALTY_QUOTIENT_ALTAIR: INACTIVITY_PENALTY_QUOTIENT_ALTAIR:
Base10.toString(INACTIVITY_PENALTY_QUOTIENT_ALTAIR), Base10.toString(INACTIVITY_PENALTY_QUOTIENT_ALTAIR),
MIN_SLASHING_PENALTY_QUOTIENT_ALTAIR: MIN_SLASHING_PENALTY_QUOTIENT_ALTAIR:
@ -106,7 +106,7 @@ proc installConfigApiHandlers*(router: var RestRouter, node: BeaconNode) =
UPDATE_TIMEOUT: UPDATE_TIMEOUT:
Base10.toString(UPDATE_TIMEOUT), Base10.toString(UPDATE_TIMEOUT),
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/presets/mainnet/bellatrix.yaml # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/presets/mainnet/bellatrix.yaml
INACTIVITY_PENALTY_QUOTIENT_BELLATRIX: INACTIVITY_PENALTY_QUOTIENT_BELLATRIX:
Base10.toString(INACTIVITY_PENALTY_QUOTIENT_BELLATRIX), Base10.toString(INACTIVITY_PENALTY_QUOTIENT_BELLATRIX),
MIN_SLASHING_PENALTY_QUOTIENT_BELLATRIX: MIN_SLASHING_PENALTY_QUOTIENT_BELLATRIX:
@ -186,7 +186,7 @@ proc installConfigApiHandlers*(router: var RestRouter, node: BeaconNode) =
DEPOSIT_CONTRACT_ADDRESS: DEPOSIT_CONTRACT_ADDRESS:
$cfg.DEPOSIT_CONTRACT_ADDRESS, $cfg.DEPOSIT_CONTRACT_ADDRESS,
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#constants # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#constants
# GENESIS_SLOT # GENESIS_SLOT
# GENESIS_EPOCH # GENESIS_EPOCH
# FAR_FUTURE_EPOCH # FAR_FUTURE_EPOCH
@ -213,7 +213,7 @@ proc installConfigApiHandlers*(router: var RestRouter, node: BeaconNode) =
DOMAIN_AGGREGATE_AND_PROOF: DOMAIN_AGGREGATE_AND_PROOF:
to0xHex(DOMAIN_AGGREGATE_AND_PROOF.data), to0xHex(DOMAIN_AGGREGATE_AND_PROOF.data),
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/beacon-chain.md#constants # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/beacon-chain.md#constants
TIMELY_SOURCE_FLAG_INDEX: TIMELY_SOURCE_FLAG_INDEX:
to0xHex([byte(TIMELY_SOURCE_FLAG_INDEX)]), to0xHex([byte(TIMELY_SOURCE_FLAG_INDEX)]),
TIMELY_TARGET_FLAG_INDEX: TIMELY_TARGET_FLAG_INDEX:
@ -240,7 +240,7 @@ proc installConfigApiHandlers*(router: var RestRouter, node: BeaconNode) =
to0xHex(DOMAIN_CONTRIBUTION_AND_PROOF.data), to0xHex(DOMAIN_CONTRIBUTION_AND_PROOF.data),
# PARTICIPATION_FLAG_WEIGHTS # PARTICIPATION_FLAG_WEIGHTS
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/validator.md#constants # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/validator.md#constants
TARGET_AGGREGATORS_PER_COMMITTEE: TARGET_AGGREGATORS_PER_COMMITTEE:
Base10.toString(TARGET_AGGREGATORS_PER_COMMITTEE), Base10.toString(TARGET_AGGREGATORS_PER_COMMITTEE),
RANDOM_SUBNETS_PER_VALIDATOR: RANDOM_SUBNETS_PER_VALIDATOR:

View File

@ -46,7 +46,7 @@ const
GENESIS_SLOT* = Slot(0) GENESIS_SLOT* = Slot(0)
GENESIS_EPOCH* = Epoch(0) # compute_epoch_at_slot(GENESIS_SLOT) GENESIS_EPOCH* = Epoch(0) # compute_epoch_at_slot(GENESIS_SLOT)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/fork-choice.md#constant # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/fork-choice.md#constant
INTERVALS_PER_SLOT* = 3 INTERVALS_PER_SLOT* = 3
FAR_FUTURE_BEACON_TIME* = BeaconTime(ns_since_genesis: int64.high()) FAR_FUTURE_BEACON_TIME* = BeaconTime(ns_since_genesis: int64.high())
@ -134,10 +134,10 @@ template `+`*(a: TimeDiff, b: Duration): TimeDiff =
const const
# Offsets from the start of the slot to when the corresponding message should # Offsets from the start of the slot to when the corresponding message should
# be sent # be sent
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/validator.md#attesting # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/validator.md#attesting
attestationSlotOffset* = TimeDiff(nanoseconds: attestationSlotOffset* = TimeDiff(nanoseconds:
NANOSECONDS_PER_SLOT.int64 div INTERVALS_PER_SLOT) NANOSECONDS_PER_SLOT.int64 div INTERVALS_PER_SLOT)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/validator.md#broadcast-aggregate # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/validator.md#broadcast-aggregate
aggregateSlotOffset* = TimeDiff(nanoseconds: aggregateSlotOffset* = TimeDiff(nanoseconds:
NANOSECONDS_PER_SLOT.int64 * 2 div INTERVALS_PER_SLOT) NANOSECONDS_PER_SLOT.int64 * 2 div INTERVALS_PER_SLOT)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/validator.md#prepare-sync-committee-message # https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/validator.md#prepare-sync-committee-message
@ -146,10 +146,10 @@ const
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/validator.md#broadcast-sync-committee-contribution # https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/validator.md#broadcast-sync-committee-contribution
syncContributionSlotOffset* = TimeDiff(nanoseconds: syncContributionSlotOffset* = TimeDiff(nanoseconds:
NANOSECONDS_PER_SLOT.int64 * 2 div INTERVALS_PER_SLOT) NANOSECONDS_PER_SLOT.int64 * 2 div INTERVALS_PER_SLOT)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/light-client/p2p-interface.md#sync-committee # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/light-client/p2p-interface.md#sync-committee
lightClientFinalityUpdateSlotOffset* = TimeDiff(nanoseconds: lightClientFinalityUpdateSlotOffset* = TimeDiff(nanoseconds:
NANOSECONDS_PER_SLOT.int64 div INTERVALS_PER_SLOT) NANOSECONDS_PER_SLOT.int64 div INTERVALS_PER_SLOT)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/light-client/p2p-interface.md#sync-committee # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/light-client/p2p-interface.md#sync-committee
lightClientOptimisticUpdateSlotOffset* = TimeDiff(nanoseconds: lightClientOptimisticUpdateSlotOffset* = TimeDiff(nanoseconds:
NANOSECONDS_PER_SLOT.int64 div INTERVALS_PER_SLOT) NANOSECONDS_PER_SLOT.int64 div INTERVALS_PER_SLOT)
@ -183,13 +183,13 @@ func slotOrZero*(time: BeaconTime): Slot =
if exSlot.afterGenesis: exSlot.slot if exSlot.afterGenesis: exSlot.slot
else: Slot(0) else: Slot(0)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#compute_epoch_at_slot # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#compute_epoch_at_slot
func epoch*(slot: Slot): Epoch = # aka compute_epoch_at_slot func epoch*(slot: Slot): Epoch = # aka compute_epoch_at_slot
## Return the epoch number at ``slot``. ## Return the epoch number at ``slot``.
if slot == FAR_FUTURE_SLOT: FAR_FUTURE_EPOCH if slot == FAR_FUTURE_SLOT: FAR_FUTURE_EPOCH
else: Epoch(slot div SLOTS_PER_EPOCH) else: Epoch(slot div SLOTS_PER_EPOCH)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/fork-choice.md#compute_slots_since_epoch_start # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/fork-choice.md#compute_slots_since_epoch_start
func since_epoch_start*(slot: Slot): uint64 = # aka compute_slots_since_epoch_start func since_epoch_start*(slot: Slot): uint64 = # aka compute_slots_since_epoch_start
## How many slots since the beginning of the epoch (`[0..SLOTS_PER_EPOCH-1]`) ## How many slots since the beginning of the epoch (`[0..SLOTS_PER_EPOCH-1]`)
(slot mod SLOTS_PER_EPOCH) (slot mod SLOTS_PER_EPOCH)
@ -197,14 +197,14 @@ func since_epoch_start*(slot: Slot): uint64 = # aka compute_slots_since_epoch_st
template is_epoch*(slot: Slot): bool = template is_epoch*(slot: Slot): bool =
slot.since_epoch_start == 0 slot.since_epoch_start == 0
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#compute_start_slot_at_epoch # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#compute_start_slot_at_epoch
func start_slot*(epoch: Epoch): Slot = # aka compute_start_slot_at_epoch func start_slot*(epoch: Epoch): Slot = # aka compute_start_slot_at_epoch
## Return the start slot of ``epoch``. ## Return the start slot of ``epoch``.
const maxEpoch = Epoch(FAR_FUTURE_SLOT div SLOTS_PER_EPOCH) const maxEpoch = Epoch(FAR_FUTURE_SLOT div SLOTS_PER_EPOCH)
if epoch >= maxEpoch: FAR_FUTURE_SLOT if epoch >= maxEpoch: FAR_FUTURE_SLOT
else: Slot(epoch * SLOTS_PER_EPOCH) else: Slot(epoch * SLOTS_PER_EPOCH)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#get_previous_epoch # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#get_previous_epoch
func get_previous_epoch*(current_epoch: Epoch): Epoch = func get_previous_epoch*(current_epoch: Epoch): Epoch =
## Return the previous epoch (unless the current epoch is ``GENESIS_EPOCH``). ## Return the previous epoch (unless the current epoch is ``GENESIS_EPOCH``).
if current_epoch == GENESIS_EPOCH: if current_epoch == GENESIS_EPOCH:

View File

@ -96,7 +96,7 @@ export
# API # API
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#bls-signatures # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#bls-signatures
func toPubKey*(privkey: ValidatorPrivKey): CookedPubKey = func toPubKey*(privkey: ValidatorPrivKey): CookedPubKey =
## Derive a public key from a private key ## Derive a public key from a private key
@ -204,7 +204,7 @@ func finish*(agg: AggregateSignature): CookedSig {.inline.} =
sig.finish(agg) sig.finish(agg)
CookedSig(sig) CookedSig(sig)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#bls-signatures # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#bls-signatures
func blsVerify*( func blsVerify*(
pubkey: CookedPubKey, message: openArray[byte], pubkey: CookedPubKey, message: openArray[byte],
signature: CookedSig): bool = signature: CookedSig): bool =
@ -217,7 +217,7 @@ func blsVerify*(
## to enforce correct usage. ## to enforce correct usage.
PublicKey(pubkey).verify(message, blscurve.Signature(signature)) PublicKey(pubkey).verify(message, blscurve.Signature(signature))
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#bls-signatures # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#bls-signatures
proc blsVerify*( proc blsVerify*(
pubkey: ValidatorPubKey, message: openArray[byte], pubkey: ValidatorPubKey, message: openArray[byte],
signature: CookedSig): bool = signature: CookedSig): bool =

View File

@ -85,7 +85,7 @@ const
ZERO_HASH* = Eth2Digest() ZERO_HASH* = Eth2Digest()
MAX_GRAFFITI_SIZE* = 32 MAX_GRAFFITI_SIZE* = 32
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/p2p-interface.md#configuration # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/p2p-interface.md#configuration
MAXIMUM_GOSSIP_CLOCK_DISPARITY* = 500.millis MAXIMUM_GOSSIP_CLOCK_DISPARITY* = 500.millis
SLOTS_PER_ETH1_VOTING_PERIOD* = SLOTS_PER_ETH1_VOTING_PERIOD* =
@ -129,7 +129,7 @@ template maxSize*(n: int) {.pragma.}
# - broke the compiler in SSZ and nim-serialization # - broke the compiler in SSZ and nim-serialization
type type
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#custom-types # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#custom-types
Eth2Domain* = array[32, byte] Eth2Domain* = array[32, byte]
ValidatorIndex* = distinct uint32 ValidatorIndex* = distinct uint32
@ -176,7 +176,7 @@ type
# SSZ / hashing purposes # SSZ / hashing purposes
JustificationBits* = distinct uint8 JustificationBits* = distinct uint8
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#proposerslashing # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#proposerslashing
ProposerSlashing* = object ProposerSlashing* = object
signed_header_1*: SignedBeaconBlockHeader signed_header_1*: SignedBeaconBlockHeader
signed_header_2*: SignedBeaconBlockHeader signed_header_2*: SignedBeaconBlockHeader
@ -188,7 +188,7 @@ type
signed_header_1*: TrustedSignedBeaconBlockHeader signed_header_1*: TrustedSignedBeaconBlockHeader
signed_header_2*: TrustedSignedBeaconBlockHeader signed_header_2*: TrustedSignedBeaconBlockHeader
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#attesterslashing # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#attesterslashing
AttesterSlashing* = object AttesterSlashing* = object
attestation_1*: IndexedAttestation attestation_1*: IndexedAttestation
attestation_2*: IndexedAttestation attestation_2*: IndexedAttestation
@ -200,7 +200,7 @@ type
attestation_1*: TrustedIndexedAttestation attestation_1*: TrustedIndexedAttestation
attestation_2*: TrustedIndexedAttestation attestation_2*: TrustedIndexedAttestation
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#indexedattestation # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#indexedattestation
IndexedAttestation* = object IndexedAttestation* = object
attesting_indices*: List[uint64, Limit MAX_VALIDATORS_PER_COMMITTEE] attesting_indices*: List[uint64, Limit MAX_VALIDATORS_PER_COMMITTEE]
data*: AttestationData data*: AttestationData
@ -216,7 +216,7 @@ type
CommitteeValidatorsBits* = BitList[Limit MAX_VALIDATORS_PER_COMMITTEE] CommitteeValidatorsBits* = BitList[Limit MAX_VALIDATORS_PER_COMMITTEE]
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#attestation # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#attestation
Attestation* = object Attestation* = object
aggregation_bits*: CommitteeValidatorsBits aggregation_bits*: CommitteeValidatorsBits
data*: AttestationData data*: AttestationData
@ -232,17 +232,17 @@ type
ForkDigest* = distinct array[4, byte] ForkDigest* = distinct array[4, byte]
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#forkdata # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#forkdata
ForkData* = object ForkData* = object
current_version*: Version current_version*: Version
genesis_validators_root*: Eth2Digest genesis_validators_root*: Eth2Digest
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#checkpoint # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#checkpoint
Checkpoint* = object Checkpoint* = object
epoch*: Epoch epoch*: Epoch
root*: Eth2Digest root*: Eth2Digest
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#AttestationData # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#AttestationData
AttestationData* = object AttestationData* = object
slot*: Slot slot*: Slot
@ -255,20 +255,20 @@ type
source*: Checkpoint source*: Checkpoint
target*: Checkpoint target*: Checkpoint
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#deposit # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#deposit
Deposit* = object Deposit* = object
proof*: array[DEPOSIT_CONTRACT_TREE_DEPTH + 1, Eth2Digest] proof*: array[DEPOSIT_CONTRACT_TREE_DEPTH + 1, Eth2Digest]
## Merkle path to deposit root ## Merkle path to deposit root
data*: DepositData data*: DepositData
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#depositmessage # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#depositmessage
DepositMessage* = object DepositMessage* = object
pubkey*: ValidatorPubKey pubkey*: ValidatorPubKey
withdrawal_credentials*: Eth2Digest withdrawal_credentials*: Eth2Digest
amount*: Gwei amount*: Gwei
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#depositdata # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#depositdata
DepositData* = object DepositData* = object
pubkey*: ValidatorPubKey pubkey*: ValidatorPubKey
withdrawal_credentials*: Eth2Digest withdrawal_credentials*: Eth2Digest
@ -277,7 +277,7 @@ type
# if the deposit should be added or not during processing # if the deposit should be added or not during processing
signature*: ValidatorSig # Signing over DepositMessage signature*: ValidatorSig # Signing over DepositMessage
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#voluntaryexit # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#voluntaryexit
VoluntaryExit* = object VoluntaryExit* = object
epoch*: Epoch epoch*: Epoch
## Earliest epoch when voluntary exit can be processed ## Earliest epoch when voluntary exit can be processed
@ -305,7 +305,7 @@ type
pubkey*: CookedPubKey pubkey*: CookedPubKey
withdrawal_credentials*: Eth2Digest withdrawal_credentials*: Eth2Digest
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#validator # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#validator
Validator* = object Validator* = object
pubkey*: ValidatorPubKey pubkey*: ValidatorPubKey
@ -327,7 +327,7 @@ type
withdrawable_epoch*: Epoch withdrawable_epoch*: Epoch
## When validator can withdraw or transfer funds ## When validator can withdraw or transfer funds
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#pendingattestation # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#pendingattestation
PendingAttestation* = object PendingAttestation* = object
aggregation_bits*: CommitteeValidatorsBits aggregation_bits*: CommitteeValidatorsBits
data*: AttestationData data*: AttestationData
@ -336,12 +336,12 @@ type
proposer_index*: uint64 # `ValidatorIndex` after validation proposer_index*: uint64 # `ValidatorIndex` after validation
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#historicalbatch # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#historicalbatch
HistoricalBatch* = object HistoricalBatch* = object
block_roots* : array[SLOTS_PER_HISTORICAL_ROOT, Eth2Digest] block_roots* : array[SLOTS_PER_HISTORICAL_ROOT, Eth2Digest]
state_roots* : array[SLOTS_PER_HISTORICAL_ROOT, Eth2Digest] state_roots* : array[SLOTS_PER_HISTORICAL_ROOT, Eth2Digest]
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#fork # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#fork
Fork* = object Fork* = object
previous_version*: Version previous_version*: Version
current_version*: Version current_version*: Version
@ -349,13 +349,13 @@ type
epoch*: Epoch epoch*: Epoch
## Epoch of latest fork ## Epoch of latest fork
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#eth1data # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#eth1data
Eth1Data* = object Eth1Data* = object
deposit_root*: Eth2Digest deposit_root*: Eth2Digest
deposit_count*: uint64 deposit_count*: uint64
block_hash*: Eth2Digest block_hash*: Eth2Digest
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#signedvoluntaryexit # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#signedvoluntaryexit
SignedVoluntaryExit* = object SignedVoluntaryExit* = object
message*: VoluntaryExit message*: VoluntaryExit
signature*: ValidatorSig signature*: ValidatorSig
@ -364,7 +364,7 @@ type
message*: VoluntaryExit message*: VoluntaryExit
signature*: TrustedSig signature*: TrustedSig
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#beaconblockheader # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#beaconblockheader
BeaconBlockHeader* = object BeaconBlockHeader* = object
slot*: Slot slot*: Slot
proposer_index*: uint64 # `ValidatorIndex` after validation proposer_index*: uint64 # `ValidatorIndex` after validation
@ -372,14 +372,14 @@ type
state_root*: Eth2Digest state_root*: Eth2Digest
body_root*: Eth2Digest body_root*: Eth2Digest
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#signingdata # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#signingdata
SigningData* = object SigningData* = object
object_root*: Eth2Digest object_root*: Eth2Digest
domain*: Eth2Domain domain*: Eth2Domain
GraffitiBytes* = distinct array[MAX_GRAFFITI_SIZE, byte] GraffitiBytes* = distinct array[MAX_GRAFFITI_SIZE, byte]
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#signedbeaconblockheader # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#signedbeaconblockheader
SignedBeaconBlockHeader* = object SignedBeaconBlockHeader* = object
message*: BeaconBlockHeader message*: BeaconBlockHeader
signature*: ValidatorSig signature*: ValidatorSig
@ -388,13 +388,13 @@ type
message*: BeaconBlockHeader message*: BeaconBlockHeader
signature*: TrustedSig signature*: TrustedSig
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/validator.md#aggregateandproof # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/validator.md#aggregateandproof
AggregateAndProof* = object AggregateAndProof* = object
aggregator_index*: uint64 # `ValidatorIndex` after validation aggregator_index*: uint64 # `ValidatorIndex` after validation
aggregate*: Attestation aggregate*: Attestation
selection_proof*: ValidatorSig selection_proof*: ValidatorSig
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/validator.md#signedaggregateandproof # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/validator.md#signedaggregateandproof
SignedAggregateAndProof* = object SignedAggregateAndProof* = object
message*: AggregateAndProof message*: AggregateAndProof
signature*: ValidatorSig signature*: ValidatorSig
@ -411,12 +411,12 @@ type
sync_committees*: Table[SyncCommitteePeriod, SyncCommitteeCache] sync_committees*: Table[SyncCommitteePeriod, SyncCommitteeCache]
# This matches the mutable state of the Solidity deposit contract # This matches the mutable state of the Solidity deposit contract
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/solidity_deposit_contract/deposit_contract.sol # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/solidity_deposit_contract/deposit_contract.sol
DepositContractState* = object DepositContractState* = object
branch*: array[DEPOSIT_CONTRACT_TREE_DEPTH, Eth2Digest] branch*: array[DEPOSIT_CONTRACT_TREE_DEPTH, Eth2Digest]
deposit_count*: array[32, byte] # Uint256 deposit_count*: array[32, byte] # Uint256
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#validator # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#validator
ValidatorStatus* = object ValidatorStatus* = object
# This is a validator without the expensive, immutable, append-only parts # This is a validator without the expensive, immutable, append-only parts
# serialized. They're represented in memory to allow in-place SSZ reading # serialized. They're represented in memory to allow in-place SSZ reading
@ -442,7 +442,7 @@ type
withdrawable_epoch*: Epoch withdrawable_epoch*: Epoch
## When validator can withdraw or transfer funds ## When validator can withdraw or transfer funds
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/p2p-interface.md#eth2-field # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/p2p-interface.md#eth2-field
ENRForkID* = object ENRForkID* = object
fork_digest*: ForkDigest fork_digest*: ForkDigest
next_fork_version*: Version next_fork_version*: Version

View File

@ -21,7 +21,7 @@ const
FAR_FUTURE_EPOCH* = Epoch(not 0'u64) FAR_FUTURE_EPOCH* = Epoch(not 0'u64)
FAR_FUTURE_PERIOD* = SyncCommitteePeriod(not 0'u64) FAR_FUTURE_PERIOD* = SyncCommitteePeriod(not 0'u64)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#domain-types # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#domain-types
DOMAIN_BEACON_PROPOSER* = DomainType([byte 0x00, 0x00, 0x00, 0x00]) DOMAIN_BEACON_PROPOSER* = DomainType([byte 0x00, 0x00, 0x00, 0x00])
DOMAIN_BEACON_ATTESTER* = DomainType([byte 0x01, 0x00, 0x00, 0x00]) DOMAIN_BEACON_ATTESTER* = DomainType([byte 0x01, 0x00, 0x00, 0x00])
DOMAIN_RANDAO* = DomainType([byte 0x02, 0x00, 0x00, 0x00]) DOMAIN_RANDAO* = DomainType([byte 0x02, 0x00, 0x00, 0x00])
@ -31,7 +31,7 @@ const
DOMAIN_AGGREGATE_AND_PROOF* = DomainType([byte 0x06, 0x00, 0x00, 0x00]) DOMAIN_AGGREGATE_AND_PROOF* = DomainType([byte 0x06, 0x00, 0x00, 0x00])
DOMAIN_APPLICATION_MASK* = DomainType([byte 0x00, 0x00, 0x00, 0x01]) DOMAIN_APPLICATION_MASK* = DomainType([byte 0x00, 0x00, 0x00, 0x01])
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/beacon-chain.md#domain-types # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/beacon-chain.md#domain-types
DOMAIN_SYNC_COMMITTEE* = DomainType([byte 0x07, 0x00, 0x00, 0x00]) DOMAIN_SYNC_COMMITTEE* = DomainType([byte 0x07, 0x00, 0x00, 0x00])
DOMAIN_SYNC_COMMITTEE_SELECTION_PROOF* = DomainType([byte 0x08, 0x00, 0x00, 0x00]) DOMAIN_SYNC_COMMITTEE_SELECTION_PROOF* = DomainType([byte 0x08, 0x00, 0x00, 0x00])
DOMAIN_CONTRIBUTION_AND_PROOF* = DomainType([byte 0x09, 0x00, 0x00, 0x00]) DOMAIN_CONTRIBUTION_AND_PROOF* = DomainType([byte 0x09, 0x00, 0x00, 0x00])
@ -42,8 +42,8 @@ const
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/bellatrix/beacon-chain.md#transition-settings # https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/bellatrix/beacon-chain.md#transition-settings
TERMINAL_BLOCK_HASH_ACTIVATION_EPOCH* = FAR_FUTURE_EPOCH TERMINAL_BLOCK_HASH_ACTIVATION_EPOCH* = FAR_FUTURE_EPOCH
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/fork-choice.md#configuration # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/fork-choice.md#configuration
PROPOSER_SCORE_BOOST*: uint64 = 40 PROPOSER_SCORE_BOOST*: uint64 = 40
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/validator.md#misc # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/validator.md#misc
ATTESTATION_SUBNET_COUNT*: uint64 = 64 ATTESTATION_SUBNET_COUNT*: uint64 = 64

View File

@ -7,7 +7,7 @@
# Serenity hash function / digest # Serenity hash function / digest
# #
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#hash # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#hash
# #
# In Phase 0 the beacon chain is deployed with SHA256 (SHA2-256). # In Phase 0 the beacon chain is deployed with SHA256 (SHA2-256).
# Note that is is different from Keccak256 (often mistakenly called SHA3-256) # Note that is is different from Keccak256 (often mistakenly called SHA3-256)

View File

@ -268,7 +268,7 @@ type
of BeaconBlockFork.Capella: cappellaBody*: capella.BeaconBlockBody of BeaconBlockFork.Capella: cappellaBody*: capella.BeaconBlockBody
RestSpec* = object RestSpec* = object
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/presets/mainnet/phase0.yaml # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/presets/mainnet/phase0.yaml
MAX_COMMITTEES_PER_SLOT*: uint64 MAX_COMMITTEES_PER_SLOT*: uint64
TARGET_COMMITTEE_SIZE*: uint64 TARGET_COMMITTEE_SIZE*: uint64
MAX_VALIDATORS_PER_COMMITTEE*: uint64 MAX_VALIDATORS_PER_COMMITTEE*: uint64
@ -303,7 +303,7 @@ type
MAX_DEPOSITS*: uint64 MAX_DEPOSITS*: uint64
MAX_VOLUNTARY_EXITS*: uint64 MAX_VOLUNTARY_EXITS*: uint64
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/presets/mainnet/altair.yaml # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/presets/mainnet/altair.yaml
INACTIVITY_PENALTY_QUOTIENT_ALTAIR*: uint64 INACTIVITY_PENALTY_QUOTIENT_ALTAIR*: uint64
MIN_SLASHING_PENALTY_QUOTIENT_ALTAIR*: uint64 MIN_SLASHING_PENALTY_QUOTIENT_ALTAIR*: uint64
PROPORTIONAL_SLASHING_MULTIPLIER_ALTAIR*: uint64 PROPORTIONAL_SLASHING_MULTIPLIER_ALTAIR*: uint64
@ -312,7 +312,7 @@ type
MIN_SYNC_COMMITTEE_PARTICIPANTS*: uint64 MIN_SYNC_COMMITTEE_PARTICIPANTS*: uint64
UPDATE_TIMEOUT*: uint64 UPDATE_TIMEOUT*: uint64
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/presets/mainnet/bellatrix.yaml # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/presets/mainnet/bellatrix.yaml
INACTIVITY_PENALTY_QUOTIENT_BELLATRIX*: uint64 INACTIVITY_PENALTY_QUOTIENT_BELLATRIX*: uint64
MIN_SLASHING_PENALTY_QUOTIENT_BELLATRIX*: uint64 MIN_SLASHING_PENALTY_QUOTIENT_BELLATRIX*: uint64
PROPORTIONAL_SLASHING_MULTIPLIER_BELLATRIX*: uint64 PROPORTIONAL_SLASHING_MULTIPLIER_BELLATRIX*: uint64
@ -354,7 +354,7 @@ type
DEPOSIT_NETWORK_ID*: uint64 DEPOSIT_NETWORK_ID*: uint64
DEPOSIT_CONTRACT_ADDRESS*: Eth1Address DEPOSIT_CONTRACT_ADDRESS*: Eth1Address
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#constants # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#constants
# GENESIS_SLOT # GENESIS_SLOT
# GENESIS_EPOCH # GENESIS_EPOCH
# FAR_FUTURE_EPOCH # FAR_FUTURE_EPOCH
@ -372,7 +372,7 @@ type
DOMAIN_SELECTION_PROOF*: DomainType DOMAIN_SELECTION_PROOF*: DomainType
DOMAIN_AGGREGATE_AND_PROOF*: DomainType DOMAIN_AGGREGATE_AND_PROOF*: DomainType
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/beacon-chain.md#constants # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/beacon-chain.md#constants
TIMELY_SOURCE_FLAG_INDEX*: byte TIMELY_SOURCE_FLAG_INDEX*: byte
TIMELY_TARGET_FLAG_INDEX*: byte TIMELY_TARGET_FLAG_INDEX*: byte
TIMELY_HEAD_FLAG_INDEX*: byte TIMELY_HEAD_FLAG_INDEX*: byte
@ -387,7 +387,7 @@ type
DOMAIN_CONTRIBUTION_AND_PROOF*: DomainType DOMAIN_CONTRIBUTION_AND_PROOF*: DomainType
# PARTICIPATION_FLAG_WEIGHTS # PARTICIPATION_FLAG_WEIGHTS
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/validator.md#constants # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/validator.md#constants
TARGET_AGGREGATORS_PER_COMMITTEE*: uint64 TARGET_AGGREGATORS_PER_COMMITTEE*: uint64
RANDOM_SUBNETS_PER_VALIDATOR*: uint64 RANDOM_SUBNETS_PER_VALIDATOR*: uint64
EPOCHS_PER_RANDOM_SUBNET_SUBSCRIPTION*: uint64 EPOCHS_PER_RANDOM_SUBNET_SUBSCRIPTION*: uint64

View File

@ -758,7 +758,7 @@ func toBeaconBlockFork*(fork: BeaconStateFork): BeaconBlockFork =
of BeaconStateFork.Bellatrix: BeaconBlockFork.Bellatrix of BeaconStateFork.Bellatrix: BeaconBlockFork.Bellatrix
of BeaconStateFork.Capella: BeaconBlockFork.Capella of BeaconStateFork.Capella: BeaconBlockFork.Capella
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#compute_fork_data_root # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#compute_fork_data_root
func compute_fork_data_root*(current_version: Version, func compute_fork_data_root*(current_version: Version,
genesis_validators_root: Eth2Digest): Eth2Digest = genesis_validators_root: Eth2Digest): Eth2Digest =
## Return the 32-byte fork data root for the ``current_version`` and ## Return the 32-byte fork data root for the ``current_version`` and
@ -770,7 +770,7 @@ func compute_fork_data_root*(current_version: Version,
genesis_validators_root: genesis_validators_root genesis_validators_root: genesis_validators_root
)) ))
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#compute_fork_digest # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#compute_fork_digest
func compute_fork_digest*(current_version: Version, func compute_fork_digest*(current_version: Version,
genesis_validators_root: Eth2Digest): ForkDigest = genesis_validators_root: Eth2Digest): ForkDigest =
## Return the 4-byte fork digest for the ``current_version`` and ## Return the 4-byte fork digest for the ``current_version`` and

View File

@ -1001,7 +1001,7 @@ proc createWallet*(kdfKind: KdfKind,
crypto: crypto, crypto: crypto,
nextAccount: nextAccount.get(0)) nextAccount: nextAccount.get(0))
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/validator.md#bls_withdrawal_prefix # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/validator.md#bls_withdrawal_prefix
func makeWithdrawalCredentials*(k: ValidatorPubKey): Eth2Digest = func makeWithdrawalCredentials*(k: ValidatorPubKey): Eth2Digest =
var bytes = eth2digest(k.toRaw()) var bytes = eth2digest(k.toRaw())
bytes.data[0] = BLS_WITHDRAWAL_PREFIX.uint8 bytes.data[0] = BLS_WITHDRAWAL_PREFIX.uint8

View File

@ -18,7 +18,7 @@ import
from ../consensus_object_pools/block_pools_types import BlockError from ../consensus_object_pools/block_pools_types import BlockError
export block_pools_types.BlockError export block_pools_types.BlockError
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/light-client/sync-protocol.md#initialize_light_client_store # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/light-client/sync-protocol.md#initialize_light_client_store
func initialize_light_client_store*( func initialize_light_client_store*(
trusted_block_root: Eth2Digest, trusted_block_root: Eth2Digest,
bootstrap: altair.LightClientBootstrap bootstrap: altair.LightClientBootstrap
@ -39,7 +39,7 @@ func initialize_light_client_store*(
current_sync_committee: bootstrap.current_sync_committee, current_sync_committee: bootstrap.current_sync_committee,
optimistic_header: bootstrap.header)) optimistic_header: bootstrap.header))
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/light-client/sync-protocol.md#validate_light_client_update # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/light-client/sync-protocol.md#validate_light_client_update
proc validate_light_client_update*( proc validate_light_client_update*(
store: LightClientStore, store: LightClientStore,
update: SomeLightClientUpdate, update: SomeLightClientUpdate,
@ -148,7 +148,7 @@ proc validate_light_client_update*(
ok() ok()
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/light-client/sync-protocol.md#apply_light_client_update # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/light-client/sync-protocol.md#apply_light_client_update
func apply_light_client_update( func apply_light_client_update(
store: var LightClientStore, store: var LightClientStore,
update: SomeLightClientUpdate): bool = update: SomeLightClientUpdate): bool =
@ -179,7 +179,7 @@ func apply_light_client_update(
didProgress = true didProgress = true
didProgress didProgress
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/light-client/sync-protocol.md#process_light_client_store_force_update # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/light-client/sync-protocol.md#process_light_client_store_force_update
type type
ForceUpdateResult* = enum ForceUpdateResult* = enum
NoUpdate, NoUpdate,

View File

@ -17,7 +17,7 @@ import
export base export base
const const
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/p2p-interface.md#topics-and-messages # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/p2p-interface.md#topics-and-messages
topicBeaconBlocksSuffix* = "beacon_block/ssz_snappy" topicBeaconBlocksSuffix* = "beacon_block/ssz_snappy"
topicVoluntaryExitsSuffix* = "voluntary_exit/ssz_snappy" topicVoluntaryExitsSuffix* = "voluntary_exit/ssz_snappy"
topicProposerSlashingsSuffix* = "proposer_slashing/ssz_snappy" topicProposerSlashingsSuffix* = "proposer_slashing/ssz_snappy"
@ -30,7 +30,7 @@ const
TTFB_TIMEOUT* = 5.seconds TTFB_TIMEOUT* = 5.seconds
RESP_TIMEOUT* = 10.seconds RESP_TIMEOUT* = 10.seconds
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/bellatrix/p2p-interface.md#configuration # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/bellatrix/p2p-interface.md#configuration
GOSSIP_MAX_SIZE_BELLATRIX* = 10 * 1024 * 1024 # bytes GOSSIP_MAX_SIZE_BELLATRIX* = 10 * 1024 * 1024 # bytes
MAX_CHUNK_SIZE_BELLATRIX* = 10 * 1024 * 1024 # bytes MAX_CHUNK_SIZE_BELLATRIX* = 10 * 1024 * 1024 # bytes
@ -63,7 +63,7 @@ func getAttesterSlashingsTopic*(forkDigest: ForkDigest): string =
func getAggregateAndProofsTopic*(forkDigest: ForkDigest): string = func getAggregateAndProofsTopic*(forkDigest: ForkDigest): string =
eth2Prefix(forkDigest) & topicAggregateAndProofsSuffix eth2Prefix(forkDigest) & topicAggregateAndProofsSuffix
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/validator.md#broadcast-attestation # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/validator.md#broadcast-attestation
func compute_subnet_for_attestation*( func compute_subnet_for_attestation*(
committees_per_slot: uint64, slot: Slot, committee_index: CommitteeIndex): committees_per_slot: uint64, slot: Slot, committee_index: CommitteeIndex):
SubnetId = SubnetId =
@ -79,29 +79,29 @@ func compute_subnet_for_attestation*(
(committees_since_epoch_start + committee_index.asUInt64) mod (committees_since_epoch_start + committee_index.asUInt64) mod
ATTESTATION_SUBNET_COUNT) ATTESTATION_SUBNET_COUNT)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/validator.md#broadcast-attestation # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/validator.md#broadcast-attestation
func getAttestationTopic*(forkDigest: ForkDigest, func getAttestationTopic*(forkDigest: ForkDigest,
subnetId: SubnetId): string = subnetId: SubnetId): string =
## For subscribing and unsubscribing to/from a subnet. ## For subscribing and unsubscribing to/from a subnet.
eth2Prefix(forkDigest) & "beacon_attestation_" & $(subnetId) & "/ssz_snappy" eth2Prefix(forkDigest) & "beacon_attestation_" & $(subnetId) & "/ssz_snappy"
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/p2p-interface.md#topics-and-messages # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/p2p-interface.md#topics-and-messages
func getSyncCommitteeTopic*(forkDigest: ForkDigest, func getSyncCommitteeTopic*(forkDigest: ForkDigest,
subcommitteeIdx: SyncSubcommitteeIndex): string = subcommitteeIdx: SyncSubcommitteeIndex): string =
## For subscribing and unsubscribing to/from a subnet. ## For subscribing and unsubscribing to/from a subnet.
eth2Prefix(forkDigest) & "sync_committee_" & $subcommitteeIdx & "/ssz_snappy" eth2Prefix(forkDigest) & "sync_committee_" & $subcommitteeIdx & "/ssz_snappy"
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/p2p-interface.md#topics-and-messages # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/p2p-interface.md#topics-and-messages
func getSyncCommitteeContributionAndProofTopic*(forkDigest: ForkDigest): string = func getSyncCommitteeContributionAndProofTopic*(forkDigest: ForkDigest): string =
## For subscribing and unsubscribing to/from a subnet. ## For subscribing and unsubscribing to/from a subnet.
eth2Prefix(forkDigest) & "sync_committee_contribution_and_proof/ssz_snappy" eth2Prefix(forkDigest) & "sync_committee_contribution_and_proof/ssz_snappy"
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/light-client/p2p-interface.md#light_client_finality_update # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/light-client/p2p-interface.md#light_client_finality_update
func getLightClientFinalityUpdateTopic*(forkDigest: ForkDigest): string = func getLightClientFinalityUpdateTopic*(forkDigest: ForkDigest): string =
## For broadcasting or obtaining the latest `LightClientFinalityUpdate`. ## For broadcasting or obtaining the latest `LightClientFinalityUpdate`.
eth2Prefix(forkDigest) & "light_client_finality_update/ssz_snappy" eth2Prefix(forkDigest) & "light_client_finality_update/ssz_snappy"
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/light-client/p2p-interface.md#light_client_optimistic_update # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/light-client/p2p-interface.md#light_client_optimistic_update
func getLightClientOptimisticUpdateTopic*(forkDigest: ForkDigest): string = func getLightClientOptimisticUpdateTopic*(forkDigest: ForkDigest): string =
## For broadcasting or obtaining the latest `LightClientOptimisticUpdate`. ## For broadcasting or obtaining the latest `LightClientOptimisticUpdate`.
eth2Prefix(forkDigest) & "light_client_optimistic_update/ssz_snappy" eth2Prefix(forkDigest) & "light_client_optimistic_update/ssz_snappy"
@ -138,7 +138,7 @@ func getDiscoveryForkID*(cfg: RuntimeConfig,
next_fork_version: current_fork_version, next_fork_version: current_fork_version,
next_fork_epoch: FAR_FUTURE_EPOCH) next_fork_epoch: FAR_FUTURE_EPOCH)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/p2p-interface.md#transitioning-the-gossip # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/p2p-interface.md#transitioning-the-gossip
type GossipState* = set[BeaconStateFork] type GossipState* = set[BeaconStateFork]
func getTargetGossipState*( func getTargetGossipState*(
epoch, ALTAIR_FORK_EPOCH, BELLATRIX_FORK_EPOCH: Epoch, isBehind: bool): epoch, ALTAIR_FORK_EPOCH, BELLATRIX_FORK_EPOCH: Epoch, isBehind: bool):

View File

@ -20,7 +20,7 @@ export constants
export stint, ethtypes.toHex, ethtypes.`==` export stint, ethtypes.toHex, ethtypes.`==`
const const
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#withdrawal-prefixes # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#withdrawal-prefixes
BLS_WITHDRAWAL_PREFIX*: byte = 0 BLS_WITHDRAWAL_PREFIX*: byte = 0
ETH1_ADDRESS_WITHDRAWAL_PREFIX*: byte = 1 ETH1_ADDRESS_WITHDRAWAL_PREFIX*: byte = 1
@ -510,7 +510,7 @@ template name*(cfg: RuntimeConfig): string =
else: else:
const_preset const_preset
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/p2p-interface.md#configuration # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/p2p-interface.md#configuration
func MIN_EPOCHS_FOR_BLOCK_REQUESTS*(cfg: RuntimeConfig): uint64 = func MIN_EPOCHS_FOR_BLOCK_REQUESTS*(cfg: RuntimeConfig): uint64 =
cfg.MIN_VALIDATOR_WITHDRAWABILITY_DELAY + cfg.CHURN_LIMIT_QUOTIENT div 2 cfg.MIN_VALIDATOR_WITHDRAWABILITY_DELAY + cfg.CHURN_LIMIT_QUOTIENT div 2

View File

@ -1,5 +1,5 @@
# Mainnet preset - Altair # Mainnet preset - Altair
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/presets/mainnet/altair.yaml # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/presets/mainnet/altair.yaml
const const
# Updated penalty values # Updated penalty values
# --------------------------------------------------------------- # ---------------------------------------------------------------

View File

@ -1,5 +1,5 @@
# Mainnet preset - Bellatrix # Mainnet preset - Bellatrix
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/presets/mainnet/bellatrix.yaml # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/presets/mainnet/bellatrix.yaml
const const
# Updated penalty values # Updated penalty values
# --------------------------------------------------------------- # ---------------------------------------------------------------

View File

@ -1,5 +1,5 @@
# Mainnet preset - Phase0 # Mainnet preset - Phase0
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/presets/mainnet/phase0.yaml # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/presets/mainnet/phase0.yaml
const const
# #

View File

@ -1,5 +1,5 @@
# Minimal preset - Altair # Minimal preset - Altair
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/presets/minimal/altair.yaml # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/presets/minimal/altair.yaml
const const
# Updated penalty values # Updated penalty values
# --------------------------------------------------------------- # ---------------------------------------------------------------

View File

@ -1,5 +1,5 @@
# Minimal preset - Bellatrix # Minimal preset - Bellatrix
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/presets/minimal/bellatrix.yaml # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/presets/minimal/bellatrix.yaml
const const
# Updated penalty values # Updated penalty values
# --------------------------------------------------------------- # ---------------------------------------------------------------

View File

@ -1,5 +1,5 @@
# Minimal preset - Phase0 # Minimal preset - Phase0
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/presets/minimal/phase0.yaml # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/presets/minimal/phase0.yaml
const const
# #

View File

@ -48,7 +48,7 @@ func compute_slot_signing_root*(
fork, DOMAIN_SELECTION_PROOF, epoch, genesis_validators_root) fork, DOMAIN_SELECTION_PROOF, epoch, genesis_validators_root)
compute_signing_root(slot, domain) compute_signing_root(slot, domain)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/validator.md#aggregation-selection # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/validator.md#aggregation-selection
func get_slot_signature*( func get_slot_signature*(
fork: Fork, genesis_validators_root: Eth2Digest, slot: Slot, fork: Fork, genesis_validators_root: Eth2Digest, slot: Slot,
privkey: ValidatorPrivKey): CookedSig = privkey: ValidatorPrivKey): CookedSig =
@ -72,7 +72,7 @@ func compute_epoch_signing_root*(
let domain = get_domain(fork, DOMAIN_RANDAO, epoch, genesis_validators_root) let domain = get_domain(fork, DOMAIN_RANDAO, epoch, genesis_validators_root)
compute_signing_root(epoch, domain) compute_signing_root(epoch, domain)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/validator.md#randao-reveal # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/validator.md#randao-reveal
func get_epoch_signature*( func get_epoch_signature*(
fork: Fork, genesis_validators_root: Eth2Digest, epoch: Epoch, fork: Fork, genesis_validators_root: Eth2Digest, epoch: Epoch,
privkey: ValidatorPrivKey): CookedSig = privkey: ValidatorPrivKey): CookedSig =
@ -101,7 +101,7 @@ func compute_block_signing_root*(
fork, DOMAIN_BEACON_PROPOSER, epoch, genesis_validators_root) fork, DOMAIN_BEACON_PROPOSER, epoch, genesis_validators_root)
compute_signing_root(blck, domain) compute_signing_root(blck, domain)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/validator.md#signature # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/validator.md#signature
func get_block_signature*( func get_block_signature*(
fork: Fork, genesis_validators_root: Eth2Digest, slot: Slot, fork: Fork, genesis_validators_root: Eth2Digest, slot: Slot,
root: Eth2Digest, privkey: ValidatorPrivKey): CookedSig = root: Eth2Digest, privkey: ValidatorPrivKey): CookedSig =
@ -130,7 +130,7 @@ func compute_aggregate_and_proof_signing_root*(
fork, DOMAIN_AGGREGATE_AND_PROOF, epoch, genesis_validators_root) fork, DOMAIN_AGGREGATE_AND_PROOF, epoch, genesis_validators_root)
compute_signing_root(aggregate_and_proof, domain) compute_signing_root(aggregate_and_proof, domain)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/validator.md#broadcast-aggregate # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/validator.md#broadcast-aggregate
func get_aggregate_and_proof_signature*(fork: Fork, genesis_validators_root: Eth2Digest, func get_aggregate_and_proof_signature*(fork: Fork, genesis_validators_root: Eth2Digest,
aggregate_and_proof: AggregateAndProof, aggregate_and_proof: AggregateAndProof,
privkey: ValidatorPrivKey): CookedSig = privkey: ValidatorPrivKey): CookedSig =
@ -158,7 +158,7 @@ func compute_attestation_signing_root*(
fork, DOMAIN_BEACON_ATTESTER, epoch, genesis_validators_root) fork, DOMAIN_BEACON_ATTESTER, epoch, genesis_validators_root)
compute_signing_root(attestation_data, domain) compute_signing_root(attestation_data, domain)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/validator.md#aggregate-signature # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/validator.md#aggregate-signature
func get_attestation_signature*( func get_attestation_signature*(
fork: Fork, genesis_validators_root: Eth2Digest, fork: Fork, genesis_validators_root: Eth2Digest,
attestation_data: AttestationData, attestation_data: AttestationData,
@ -186,7 +186,7 @@ func compute_deposit_signing_root*(
domain = compute_domain(DOMAIN_DEPOSIT, version) domain = compute_domain(DOMAIN_DEPOSIT, version)
compute_signing_root(deposit_message, domain) compute_signing_root(deposit_message, domain)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#deposits # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#deposits
func get_deposit_signature*(preset: RuntimeConfig, func get_deposit_signature*(preset: RuntimeConfig,
deposit: DepositData, deposit: DepositData,
privkey: ValidatorPrivKey): CookedSig = privkey: ValidatorPrivKey): CookedSig =

View File

@ -77,7 +77,7 @@ proc aggregateAttesters(
# Aggregation spec requires non-empty collection # Aggregation spec requires non-empty collection
# - https://tools.ietf.org/html/draft-irtf-cfrg-bls-signature-04 # - https://tools.ietf.org/html/draft-irtf-cfrg-bls-signature-04
# Eth2 spec requires at least one attesting index in attestation # Eth2 spec requires at least one attesting index in attestation
# - https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#is_valid_indexed_attestation # - https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#is_valid_indexed_attestation
return err("aggregateAttesters: no attesting indices") return err("aggregateAttesters: no attesting indices")
let let
@ -106,7 +106,7 @@ proc aggregateAttesters(
# Aggregation spec requires non-empty collection # Aggregation spec requires non-empty collection
# - https://tools.ietf.org/html/draft-irtf-cfrg-bls-signature-04 # - https://tools.ietf.org/html/draft-irtf-cfrg-bls-signature-04
# Eth2 spec requires at least one attesting index in attestation # Eth2 spec requires at least one attesting index in attestation
# - https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#is_valid_indexed_attestation # - https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#is_valid_indexed_attestation
return err("aggregateAttesters: no attesting indices") return err("aggregateAttesters: no attesting indices")
var attestersAgg{.noinit.}: AggregatePublicKey var attestersAgg{.noinit.}: AggregatePublicKey

View File

@ -6,7 +6,7 @@
# at your option. This file may not be copied, modified, or distributed except according to those terms. # at your option. This file may not be copied, modified, or distributed except according to those terms.
# State transition, as described in # State transition, as described in
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#beacon-chain-state-transition-function # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#beacon-chain-state-transition-function
# #
# The entry point is `state_transition` which is at the bottom of the file! # The entry point is `state_transition` which is at the bottom of the file!
# #
@ -54,7 +54,7 @@ import
export results, extras, phase0, altair, bellatrix export results, extras, phase0, altair, bellatrix
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#beacon-chain-state-transition-function # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#beacon-chain-state-transition-function
proc verify_block_signature( proc verify_block_signature(
state: ForkyBeaconState, signed_block: SomeForkySignedBeaconBlock): state: ForkyBeaconState, signed_block: SomeForkySignedBeaconBlock):
Result[void, cstring] = Result[void, cstring] =
@ -71,7 +71,7 @@ proc verify_block_signature(
ok() ok()
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#beacon-chain-state-transition-function # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#beacon-chain-state-transition-function
func verifyStateRoot( func verifyStateRoot(
state: ForkyBeaconState, blck: ForkyBeaconBlock | ForkySigVerifiedBeaconBlock): state: ForkyBeaconState, blck: ForkyBeaconBlock | ForkySigVerifiedBeaconBlock):
Result[void, cstring] = Result[void, cstring] =
@ -100,7 +100,7 @@ func noRollback*() =
# Hashed-state transition functions # Hashed-state transition functions
# --------------------------------------------------------------- # ---------------------------------------------------------------
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#beacon-chain-state-transition-function # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#beacon-chain-state-transition-function
func process_slot*( func process_slot*(
state: var ForkyBeaconState, pre_state_root: Eth2Digest) = state: var ForkyBeaconState, pre_state_root: Eth2Digest) =
# `process_slot` is the first stage of per-slot processing - it is run for # `process_slot` is the first stage of per-slot processing - it is run for
@ -125,7 +125,7 @@ func clear_epoch_from_cache(cache: var StateCache, epoch: Epoch) =
for slot in epoch.slots(): for slot in epoch.slots():
cache.beacon_proposer_indices.del slot cache.beacon_proposer_indices.del slot
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#beacon-chain-state-transition-function # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#beacon-chain-state-transition-function
proc advance_slot( proc advance_slot(
cfg: RuntimeConfig, cfg: RuntimeConfig,
state: var ForkyBeaconState, previous_slot_state_root: Eth2Digest, state: var ForkyBeaconState, previous_slot_state_root: Eth2Digest,
@ -295,7 +295,7 @@ proc state_transition*(
state_transition_block( state_transition_block(
cfg, state, signedBlock, cache, flags, rollback) cfg, state, signedBlock, cache, flags, rollback)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/validator.md#preparing-for-a-beaconblock # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/validator.md#preparing-for-a-beaconblock
template partialBeaconBlock( template partialBeaconBlock(
cfg: RuntimeConfig, cfg: RuntimeConfig,
state: var phase0.HashedBeaconState, state: var phase0.HashedBeaconState,

View File

@ -6,7 +6,7 @@
# at your option. This file may not be copied, modified, or distributed except according to those terms. # at your option. This file may not be copied, modified, or distributed except according to those terms.
# State transition - block processing, as described in # State transition - block processing, as described in
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#block-processing # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#block-processing
# #
# The entry point is `process_block` which is at the bottom of this file. # The entry point is `process_block` which is at the bottom of this file.
# #
@ -34,7 +34,7 @@ from ./datatypes/capella import
export extras, phase0, altair export extras, phase0, altair
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#block-header # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#block-header
func process_block_header*( func process_block_header*(
state: var ForkyBeaconState, blck: SomeForkyBeaconBlock, flags: UpdateFlags, state: var ForkyBeaconState, blck: SomeForkyBeaconBlock, flags: UpdateFlags,
cache: var StateCache): Result[void, cstring] = cache: var StateCache): Result[void, cstring] =
@ -77,7 +77,7 @@ func `xor`[T: array](a, b: T): T =
for i in 0..<result.len: for i in 0..<result.len:
result[i] = a[i] xor b[i] result[i] = a[i] xor b[i]
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#randao # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#randao
proc process_randao( proc process_randao(
state: var ForkyBeaconState, body: SomeForkyBeaconBlockBody, flags: UpdateFlags, state: var ForkyBeaconState, body: SomeForkyBeaconBlockBody, flags: UpdateFlags,
cache: var StateCache): Result[void, cstring] = cache: var StateCache): Result[void, cstring] =
@ -118,7 +118,7 @@ proc process_randao(
ok() ok()
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#eth1-data # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#eth1-data
func process_eth1_data(state: var ForkyBeaconState, body: SomeForkyBeaconBlockBody): Result[void, cstring]= func process_eth1_data(state: var ForkyBeaconState, body: SomeForkyBeaconBlockBody): Result[void, cstring]=
if not state.eth1_data_votes.add body.eth1_data: if not state.eth1_data_votes.add body.eth1_data:
# Count is reset in process_final_updates, so this should never happen # Count is reset in process_final_updates, so this should never happen
@ -129,14 +129,14 @@ func process_eth1_data(state: var ForkyBeaconState, body: SomeForkyBeaconBlockBo
state.eth1_data = body.eth1_data state.eth1_data = body.eth1_data
ok() ok()
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#is_slashable_validator # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#is_slashable_validator
func is_slashable_validator(validator: Validator, epoch: Epoch): bool = func is_slashable_validator(validator: Validator, epoch: Epoch): bool =
# Check if ``validator`` is slashable. # Check if ``validator`` is slashable.
(not validator.slashed) and (not validator.slashed) and
(validator.activation_epoch <= epoch) and (validator.activation_epoch <= epoch) and
(epoch < validator.withdrawable_epoch) (epoch < validator.withdrawable_epoch)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#proposer-slashings # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#proposer-slashings
proc check_proposer_slashing*( proc check_proposer_slashing*(
state: ForkyBeaconState, proposer_slashing: SomeProposerSlashing, state: ForkyBeaconState, proposer_slashing: SomeProposerSlashing,
flags: UpdateFlags): flags: UpdateFlags):
@ -185,7 +185,7 @@ proc check_proposer_slashing*(
withState(state): withState(state):
check_proposer_slashing(forkyState.data, proposer_slashing, flags) check_proposer_slashing(forkyState.data, proposer_slashing, flags)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#proposer-slashings # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#proposer-slashings
proc process_proposer_slashing*( proc process_proposer_slashing*(
cfg: RuntimeConfig, state: var ForkyBeaconState, cfg: RuntimeConfig, state: var ForkyBeaconState,
proposer_slashing: SomeProposerSlashing, flags: UpdateFlags, proposer_slashing: SomeProposerSlashing, flags: UpdateFlags,
@ -195,7 +195,7 @@ proc process_proposer_slashing*(
? slash_validator(cfg, state, proposer_index, cache) ? slash_validator(cfg, state, proposer_index, cache)
ok() ok()
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#is_slashable_attestation_data # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#is_slashable_attestation_data
func is_slashable_attestation_data( func is_slashable_attestation_data(
data_1: AttestationData, data_2: AttestationData): bool = data_1: AttestationData, data_2: AttestationData): bool =
## Check if ``data_1`` and ``data_2`` are slashable according to Casper FFG ## Check if ``data_1`` and ``data_2`` are slashable according to Casper FFG
@ -207,7 +207,7 @@ func is_slashable_attestation_data(
(data_1.source.epoch < data_2.source.epoch and (data_1.source.epoch < data_2.source.epoch and
data_2.target.epoch < data_1.target.epoch) data_2.target.epoch < data_1.target.epoch)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#attester-slashings # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#attester-slashings
proc check_attester_slashing*( proc check_attester_slashing*(
state: ForkyBeaconState, state: ForkyBeaconState,
attester_slashing: SomeAttesterSlashing, attester_slashing: SomeAttesterSlashing,
@ -249,7 +249,7 @@ proc check_attester_slashing*(
withState(state): withState(state):
check_attester_slashing(forkyState.data, attester_slashing, flags) check_attester_slashing(forkyState.data, attester_slashing, flags)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#attester-slashings # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#attester-slashings
proc process_attester_slashing*( proc process_attester_slashing*(
cfg: RuntimeConfig, cfg: RuntimeConfig,
state: var ForkyBeaconState, state: var ForkyBeaconState,
@ -332,7 +332,7 @@ proc process_deposit*(cfg: RuntimeConfig,
ok() ok()
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#voluntary-exits # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#voluntary-exits
proc check_voluntary_exit*( proc check_voluntary_exit*(
cfg: RuntimeConfig, cfg: RuntimeConfig,
state: ForkyBeaconState, state: ForkyBeaconState,
@ -381,7 +381,7 @@ proc check_voluntary_exit*(
withState(state): withState(state):
check_voluntary_exit(cfg, forkyState.data, signed_voluntary_exit, flags) check_voluntary_exit(cfg, forkyState.data, signed_voluntary_exit, flags)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#voluntary-exits # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#voluntary-exits
proc process_voluntary_exit*( proc process_voluntary_exit*(
cfg: RuntimeConfig, cfg: RuntimeConfig,
state: var ForkyBeaconState, state: var ForkyBeaconState,
@ -463,7 +463,7 @@ proc process_operations(cfg: RuntimeConfig,
ok() ok()
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/beacon-chain.md#sync-committee-processing # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/beacon-chain.md#sync-committee-processing
func get_participant_reward*(total_active_balance: Gwei): Gwei = func get_participant_reward*(total_active_balance: Gwei): Gwei =
let let
total_active_increments = total_active_increments =
@ -478,7 +478,7 @@ func get_participant_reward*(total_active_balance: Gwei): Gwei =
func get_proposer_reward*(participant_reward: Gwei): Gwei = func get_proposer_reward*(participant_reward: Gwei): Gwei =
participant_reward * PROPOSER_WEIGHT div (WEIGHT_DENOMINATOR - PROPOSER_WEIGHT) participant_reward * PROPOSER_WEIGHT div (WEIGHT_DENOMINATOR - PROPOSER_WEIGHT)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/beacon-chain.md#sync-committee-processing # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/beacon-chain.md#sync-committee-processing
proc process_sync_aggregate*( proc process_sync_aggregate*(
state: var (altair.BeaconState | bellatrix.BeaconState | capella.BeaconState), state: var (altair.BeaconState | bellatrix.BeaconState | capella.BeaconState),
sync_aggregate: SomeSyncAggregate, total_active_balance: Gwei, sync_aggregate: SomeSyncAggregate, total_active_balance: Gwei,
@ -642,7 +642,7 @@ func process_withdrawals*(
ok() ok()
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#block-processing # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#block-processing
# TODO workaround for https://github.com/nim-lang/Nim/issues/18095 # TODO workaround for https://github.com/nim-lang/Nim/issues/18095
# copy of datatypes/phase0.nim # copy of datatypes/phase0.nim
type SomePhase0Block = type SomePhase0Block =
@ -662,7 +662,7 @@ proc process_block*(
ok() ok()
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/beacon-chain.md#block-processing # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/beacon-chain.md#block-processing
# TODO workaround for https://github.com/nim-lang/Nim/issues/18095 # TODO workaround for https://github.com/nim-lang/Nim/issues/18095
# copy of datatypes/altair.nim # copy of datatypes/altair.nim
type SomeAltairBlock = type SomeAltairBlock =

View File

@ -6,8 +6,8 @@
# at your option. This file may not be copied, modified, or distributed except according to those terms. # at your option. This file may not be copied, modified, or distributed except according to those terms.
# State transition - epoch processing, as described in # State transition - epoch processing, as described in
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#epoch-processing and # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#epoch-processing and
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/beacon-chain.md#epoch-processing # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/beacon-chain.md#epoch-processing
# #
# The entry point is `process_epoch`, which is at the bottom of this file. # The entry point is `process_epoch`, which is at the bottom of this file.
# #
@ -40,7 +40,7 @@ export extras, phase0, altair
logScope: topics = "consens" logScope: topics = "consens"
# Accessors that implement the max condition in `get_total_balance`: # Accessors that implement the max condition in `get_total_balance`:
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#get_total_balance # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#get_total_balance
template current_epoch*(v: TotalBalances): Gwei = template current_epoch*(v: TotalBalances): Gwei =
max(EFFECTIVE_BALANCE_INCREMENT, v.current_epoch_raw) max(EFFECTIVE_BALANCE_INCREMENT, v.current_epoch_raw)
template previous_epoch*(v: TotalBalances): Gwei = template previous_epoch*(v: TotalBalances): Gwei =
@ -155,7 +155,7 @@ func process_attestations*(
if v.flags.contains RewardFlags.isPreviousEpochHeadAttester: if v.flags.contains RewardFlags.isPreviousEpochHeadAttester:
info.balances.previous_epoch_head_attesters_raw += validator_balance info.balances.previous_epoch_head_attesters_raw += validator_balance
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#helpers # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#helpers
# get_eligible_validator_indices # get_eligible_validator_indices
func is_eligible_validator*(validator: RewardStatus): bool = func is_eligible_validator*(validator: RewardStatus): bool =
validator.flags.contains(RewardFlags.isActiveInPreviousEpoch) or validator.flags.contains(RewardFlags.isActiveInPreviousEpoch) or
@ -172,8 +172,8 @@ func is_eligible_validator*(validator: ParticipationInfo): bool =
# Spec # Spec
# -------------------------------------------------------- # --------------------------------------------------------
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/beacon-chain.md#get_unslashed_participating_indices # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/beacon-chain.md#get_unslashed_participating_indices
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#get_total_balance # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#get_total_balance
func get_unslashed_participating_balances*( func get_unslashed_participating_balances*(
state: altair.BeaconState | bellatrix.BeaconState | capella.BeaconState state: altair.BeaconState | bellatrix.BeaconState | capella.BeaconState
): UnslashedParticipatingBalances = ): UnslashedParticipatingBalances =
@ -240,7 +240,7 @@ func is_unslashed_participating_index(
has_flag(epoch_participation[].item(validator_index), flag_index) and has_flag(epoch_participation[].item(validator_index), flag_index) and
not state.validators[validator_index].slashed not state.validators[validator_index].slashed
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#justification-and-finalization # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#justification-and-finalization
type FinalityState = object type FinalityState = object
slot: Slot slot: Slot
current_epoch_ancestor_root: Eth2Digest current_epoch_ancestor_root: Eth2Digest
@ -308,7 +308,7 @@ proc weigh_justification_and_finalization(
## state.justification_bits[1:] = state.justification_bits[:-1] ## state.justification_bits[1:] = state.justification_bits[:-1]
## state.justification_bits[0] = 0b0 ## state.justification_bits[0] = 0b0
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#misc # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#misc
const JUSTIFICATION_BITS_LENGTH = 4 const JUSTIFICATION_BITS_LENGTH = 4
state.justification_bits = JustificationBits( state.justification_bits = JustificationBits(
@ -384,7 +384,7 @@ proc weigh_justification_and_finalization(
current_epoch = current_epoch, current_epoch = current_epoch,
checkpoint = shortLog(state.finalized_checkpoint) checkpoint = shortLog(state.finalized_checkpoint)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#justification-and-finalization # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#justification-and-finalization
proc process_justification_and_finalization*( proc process_justification_and_finalization*(
state: var phase0.BeaconState, state: var phase0.BeaconState,
balances: TotalBalances, flags: UpdateFlags = {}) = balances: TotalBalances, flags: UpdateFlags = {}) =
@ -420,7 +420,7 @@ proc compute_unrealized_finality*(
justified: finalityState.current_justified_checkpoint, justified: finalityState.current_justified_checkpoint,
finalized: finalityState.finalized_checkpoint) finalized: finalityState.finalized_checkpoint)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/beacon-chain.md#justification-and-finalization # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/beacon-chain.md#justification-and-finalization
proc process_justification_and_finalization*( proc process_justification_and_finalization*(
state: var (altair.BeaconState | bellatrix.BeaconState | capella.BeaconState), state: var (altair.BeaconState | bellatrix.BeaconState | capella.BeaconState),
balances: UnslashedParticipatingBalances, balances: UnslashedParticipatingBalances,
@ -454,7 +454,7 @@ proc compute_unrealized_finality*(
justified: finalityState.current_justified_checkpoint, justified: finalityState.current_justified_checkpoint,
finalized: finalityState.finalized_checkpoint) finalized: finalityState.finalized_checkpoint)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#helpers # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#helpers
func get_base_reward_sqrt*(state: phase0.BeaconState, index: ValidatorIndex, func get_base_reward_sqrt*(state: phase0.BeaconState, index: ValidatorIndex,
total_balance_sqrt: auto): Gwei = total_balance_sqrt: auto): Gwei =
# Spec function recalculates total_balance every time, which creates an # Spec function recalculates total_balance every time, which creates an
@ -502,7 +502,7 @@ func get_attestation_component_delta(is_unslashed_attester: bool,
else: else:
RewardDelta(penalties: base_reward) RewardDelta(penalties: base_reward)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#components-of-attestation-deltas # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#components-of-attestation-deltas
func get_source_delta*(validator: RewardStatus, func get_source_delta*(validator: RewardStatus,
base_reward: uint64, base_reward: uint64,
balances: TotalBalances, balances: TotalBalances,
@ -580,7 +580,7 @@ func get_inactivity_penalty_delta*(validator: RewardStatus,
delta delta
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#get_attestation_deltas # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#get_attestation_deltas
func get_attestation_deltas(state: phase0.BeaconState, info: var phase0.EpochInfo) = func get_attestation_deltas(state: phase0.BeaconState, info: var phase0.EpochInfo) =
## Update rewards with attestation reward/penalty deltas for each validator. ## Update rewards with attestation reward/penalty deltas for each validator.
@ -624,7 +624,7 @@ func get_attestation_deltas(state: phase0.BeaconState, info: var phase0.EpochInf
info.validators[proposer_index].delta.add( info.validators[proposer_index].delta.add(
proposer_delta.get()[1]) proposer_delta.get()[1])
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/beacon-chain.md#get_base_reward # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/beacon-chain.md#get_base_reward
func get_base_reward_increment*( func get_base_reward_increment*(
state: altair.BeaconState | bellatrix.BeaconState | capella.BeaconState, state: altair.BeaconState | bellatrix.BeaconState | capella.BeaconState,
index: ValidatorIndex, base_reward_per_increment: Gwei): Gwei = index: ValidatorIndex, base_reward_per_increment: Gwei): Gwei =
@ -634,7 +634,7 @@ func get_base_reward_increment*(
state.validators[index].effective_balance div EFFECTIVE_BALANCE_INCREMENT state.validators[index].effective_balance div EFFECTIVE_BALANCE_INCREMENT
increments * base_reward_per_increment increments * base_reward_per_increment
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/beacon-chain.md#get_flag_index_deltas # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/beacon-chain.md#get_flag_index_deltas
func get_flag_index_reward*( func get_flag_index_reward*(
state: altair.BeaconState | bellatrix.BeaconState | capella.BeaconState, state: altair.BeaconState | bellatrix.BeaconState | capella.BeaconState,
base_reward: Gwei, active_increments: Gwei, base_reward: Gwei, active_increments: Gwei,
@ -647,16 +647,16 @@ func get_flag_index_reward*(
else: else:
0.Gwei 0.Gwei
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/beacon-chain.md#get_flag_index_deltas # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/beacon-chain.md#get_flag_index_deltas
func get_unslashed_participating_increment*( func get_unslashed_participating_increment*(
info: altair.EpochInfo | bellatrix.BeaconState, flag_index: int): Gwei = info: altair.EpochInfo | bellatrix.BeaconState, flag_index: int): Gwei =
info.balances.previous_epoch[flag_index] div EFFECTIVE_BALANCE_INCREMENT info.balances.previous_epoch[flag_index] div EFFECTIVE_BALANCE_INCREMENT
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/beacon-chain.md#get_flag_index_deltas # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/beacon-chain.md#get_flag_index_deltas
func get_active_increments*(info: altair.EpochInfo | bellatrix.BeaconState): Gwei = func get_active_increments*(info: altair.EpochInfo | bellatrix.BeaconState): Gwei =
info.balances.current_epoch div EFFECTIVE_BALANCE_INCREMENT info.balances.current_epoch div EFFECTIVE_BALANCE_INCREMENT
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/beacon-chain.md#get_flag_index_deltas # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/beacon-chain.md#get_flag_index_deltas
iterator get_flag_index_deltas*( iterator get_flag_index_deltas*(
state: altair.BeaconState | bellatrix.BeaconState | capella.BeaconState, state: altair.BeaconState | bellatrix.BeaconState | capella.BeaconState,
flag_index: int, base_reward_per_increment: Gwei, flag_index: int, base_reward_per_increment: Gwei,
@ -700,7 +700,7 @@ iterator get_flag_index_deltas*(
else: else:
(vidx, RewardDelta(rewards: 0.Gwei, penalties: 0.Gwei)) (vidx, RewardDelta(rewards: 0.Gwei, penalties: 0.Gwei))
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/beacon-chain.md#modified-get_inactivity_penalty_deltas # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/beacon-chain.md#modified-get_inactivity_penalty_deltas
iterator get_inactivity_penalty_deltas*( iterator get_inactivity_penalty_deltas*(
cfg: RuntimeConfig, state: altair.BeaconState, info: altair.EpochInfo): cfg: RuntimeConfig, state: altair.BeaconState, info: altair.EpochInfo):
(ValidatorIndex, Gwei) = (ValidatorIndex, Gwei) =
@ -745,7 +745,7 @@ iterator get_inactivity_penalty_deltas*(
state.inactivity_scores[vidx] state.inactivity_scores[vidx]
yield (vidx, Gwei(penalty_numerator div penalty_denominator)) yield (vidx, Gwei(penalty_numerator div penalty_denominator))
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#rewards-and-penalties-1 # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#rewards-and-penalties-1
func process_rewards_and_penalties*( func process_rewards_and_penalties*(
state: var phase0.BeaconState, info: var phase0.EpochInfo) = state: var phase0.BeaconState, info: var phase0.EpochInfo) =
# No rewards are applied at the end of `GENESIS_EPOCH` because rewards are # No rewards are applied at the end of `GENESIS_EPOCH` because rewards are
@ -768,7 +768,7 @@ func process_rewards_and_penalties*(
decrease_balance(balance, v.delta.penalties) decrease_balance(balance, v.delta.penalties)
state.balances.asSeq()[idx] = balance state.balances.asSeq()[idx] = balance
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/beacon-chain.md#rewards-and-penalties # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/beacon-chain.md#rewards-and-penalties
func process_rewards_and_penalties*( func process_rewards_and_penalties*(
cfg: RuntimeConfig, state: var (altair.BeaconState | bellatrix.BeaconState | capella.BeaconState), cfg: RuntimeConfig, state: var (altair.BeaconState | bellatrix.BeaconState | capella.BeaconState),
info: var altair.EpochInfo) info: var altair.EpochInfo)
@ -803,7 +803,7 @@ func process_rewards_and_penalties*(
decrease_balance(balance, info.validators[vidx].delta.penalties) decrease_balance(balance, info.validators[vidx].delta.penalties)
state.balances.asSeq()[vidx] = balance state.balances.asSeq()[vidx] = balance
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#registry-updates # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#registry-updates
func process_registry_updates*( func process_registry_updates*(
cfg: RuntimeConfig, state: var ForkyBeaconState, cache: var StateCache): cfg: RuntimeConfig, state: var ForkyBeaconState, cache: var StateCache):
Result[void, cstring] = Result[void, cstring] =
@ -856,8 +856,8 @@ func process_registry_updates*(
ok() ok()
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#slashings # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#slashings
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/beacon-chain.md#slashings # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/beacon-chain.md#slashings
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/bellatrix/beacon-chain.md#slashings # https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/bellatrix/beacon-chain.md#slashings
func get_adjusted_total_slashing_balance*( func get_adjusted_total_slashing_balance*(
state: ForkyBeaconState, total_balance: Gwei): Gwei = state: ForkyBeaconState, total_balance: Gwei): Gwei =
@ -876,15 +876,15 @@ func get_adjusted_total_slashing_balance*(
{.fatal: "process_slashings: incorrect BeaconState type".} {.fatal: "process_slashings: incorrect BeaconState type".}
min(sum(state.slashings.data) * multiplier, total_balance) min(sum(state.slashings.data) * multiplier, total_balance)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#slashings # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#slashings
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/beacon-chain.md#slashings # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/beacon-chain.md#slashings
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/bellatrix/beacon-chain.md#slashings # https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/bellatrix/beacon-chain.md#slashings
func slashing_penalty_applies*(validator: Validator, epoch: Epoch): bool = func slashing_penalty_applies*(validator: Validator, epoch: Epoch): bool =
validator.slashed and validator.slashed and
epoch + EPOCHS_PER_SLASHINGS_VECTOR div 2 == validator.withdrawable_epoch epoch + EPOCHS_PER_SLASHINGS_VECTOR div 2 == validator.withdrawable_epoch
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#slashings # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#slashings
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/beacon-chain.md#slashings # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/beacon-chain.md#slashings
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/bellatrix/beacon-chain.md#slashings # https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/bellatrix/beacon-chain.md#slashings
func get_slashing_penalty*(validator: Validator, func get_slashing_penalty*(validator: Validator,
adjusted_total_slashing_balance, adjusted_total_slashing_balance,
@ -895,8 +895,8 @@ func get_slashing_penalty*(validator: Validator,
adjusted_total_slashing_balance adjusted_total_slashing_balance
penalty_numerator div total_balance * increment penalty_numerator div total_balance * increment
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#slashings # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#slashings
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/beacon-chain.md#slashings # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/beacon-chain.md#slashings
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/bellatrix/beacon-chain.md#slashings # https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/bellatrix/beacon-chain.md#slashings
func process_slashings*(state: var ForkyBeaconState, total_balance: Gwei) = func process_slashings*(state: var ForkyBeaconState, total_balance: Gwei) =
let let
@ -911,7 +911,7 @@ func process_slashings*(state: var ForkyBeaconState, total_balance: Gwei) =
validator[], adjusted_total_slashing_balance, total_balance) validator[], adjusted_total_slashing_balance, total_balance)
decrease_balance(state, vidx, penalty) decrease_balance(state, vidx, penalty)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#eth1-data-votes-updates # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#eth1-data-votes-updates
func process_eth1_data_reset*(state: var ForkyBeaconState) = func process_eth1_data_reset*(state: var ForkyBeaconState) =
let next_epoch = get_current_epoch(state) + 1 let next_epoch = get_current_epoch(state) + 1
@ -919,7 +919,7 @@ func process_eth1_data_reset*(state: var ForkyBeaconState) =
if next_epoch mod EPOCHS_PER_ETH1_VOTING_PERIOD == 0: if next_epoch mod EPOCHS_PER_ETH1_VOTING_PERIOD == 0:
state.eth1_data_votes = default(type state.eth1_data_votes) state.eth1_data_votes = default(type state.eth1_data_votes)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#effective-balances-updates # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#effective-balances-updates
func process_effective_balance_updates*(state: var ForkyBeaconState) = func process_effective_balance_updates*(state: var ForkyBeaconState) =
# Update effective balances with hysteresis # Update effective balances with hysteresis
for vidx in state.validators.vindices: for vidx in state.validators.vindices:
@ -941,14 +941,14 @@ func process_effective_balance_updates*(state: var ForkyBeaconState) =
if new_effective_balance != effective_balance: if new_effective_balance != effective_balance:
state.validators.mitem(vidx).effective_balance = new_effective_balance state.validators.mitem(vidx).effective_balance = new_effective_balance
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#slashings-balances-updates # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#slashings-balances-updates
func process_slashings_reset*(state: var ForkyBeaconState) = func process_slashings_reset*(state: var ForkyBeaconState) =
let next_epoch = get_current_epoch(state) + 1 let next_epoch = get_current_epoch(state) + 1
# Reset slashings # Reset slashings
state.slashings[int(next_epoch mod EPOCHS_PER_SLASHINGS_VECTOR)] = 0.Gwei state.slashings[int(next_epoch mod EPOCHS_PER_SLASHINGS_VECTOR)] = 0.Gwei
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#randao-mixes-updates # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#randao-mixes-updates
func process_randao_mixes_reset*(state: var ForkyBeaconState) = func process_randao_mixes_reset*(state: var ForkyBeaconState) =
let let
current_epoch = get_current_epoch(state) current_epoch = get_current_epoch(state)
@ -961,12 +961,12 @@ func process_randao_mixes_reset*(state: var ForkyBeaconState) =
func compute_historical_root*(state: var ForkyBeaconState): Eth2Digest = func compute_historical_root*(state: var ForkyBeaconState): Eth2Digest =
# Equivalent to hash_tree_root(foo: HistoricalBatch), but without using # Equivalent to hash_tree_root(foo: HistoricalBatch), but without using
# significant additional stack or heap. # significant additional stack or heap.
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#historicalbatch # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#historicalbatch
# In response to https://github.com/status-im/nimbus-eth2/issues/921 # In response to https://github.com/status-im/nimbus-eth2/issues/921
hash_tree_root([ hash_tree_root([
hash_tree_root(state.block_roots), hash_tree_root(state.state_roots)]) hash_tree_root(state.block_roots), hash_tree_root(state.state_roots)])
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#historical-roots-updates # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#historical-roots-updates
func process_historical_roots_update*(state: var ForkyBeaconState) = func process_historical_roots_update*(state: var ForkyBeaconState) =
## Set historical root accumulator ## Set historical root accumulator
let next_epoch = get_current_epoch(state) + 1 let next_epoch = get_current_epoch(state) + 1
@ -974,19 +974,19 @@ func process_historical_roots_update*(state: var ForkyBeaconState) =
if next_epoch mod (SLOTS_PER_HISTORICAL_ROOT div SLOTS_PER_EPOCH) == 0: if next_epoch mod (SLOTS_PER_HISTORICAL_ROOT div SLOTS_PER_EPOCH) == 0:
# Equivalent to hash_tree_root(foo: HistoricalBatch), but without using # Equivalent to hash_tree_root(foo: HistoricalBatch), but without using
# significant additional stack or heap. # significant additional stack or heap.
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#historicalbatch # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#historicalbatch
# In response to https://github.com/status-im/nimbus-eth2/issues/921 # In response to https://github.com/status-im/nimbus-eth2/issues/921
if not state.historical_roots.add state.compute_historical_root(): if not state.historical_roots.add state.compute_historical_root():
raiseAssert "no more room for historical roots, so long and thanks for the fish!" raiseAssert "no more room for historical roots, so long and thanks for the fish!"
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#participation-records-rotation # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#participation-records-rotation
func process_participation_record_updates*(state: var phase0.BeaconState) = func process_participation_record_updates*(state: var phase0.BeaconState) =
# Rotate current/previous epoch attestations - using swap avoids copying all # Rotate current/previous epoch attestations - using swap avoids copying all
# elements using a slow genericSeqAssign # elements using a slow genericSeqAssign
state.previous_epoch_attestations.clear() state.previous_epoch_attestations.clear()
swap(state.previous_epoch_attestations, state.current_epoch_attestations) swap(state.previous_epoch_attestations, state.current_epoch_attestations)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/beacon-chain.md#participation-flags-updates # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/beacon-chain.md#participation-flags-updates
func process_participation_flag_updates*( func process_participation_flag_updates*(
state: var (altair.BeaconState | bellatrix.BeaconState | capella.BeaconState)) = state: var (altair.BeaconState | bellatrix.BeaconState | capella.BeaconState)) =
state.previous_epoch_participation = state.current_epoch_participation state.previous_epoch_participation = state.current_epoch_participation
@ -1001,7 +1001,7 @@ func process_participation_flag_updates*(
state.current_epoch_participation.asHashList.resetCache() state.current_epoch_participation.asHashList.resetCache()
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/beacon-chain.md#sync-committee-updates # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/beacon-chain.md#sync-committee-updates
func process_sync_committee_updates*( func process_sync_committee_updates*(
state: var (altair.BeaconState | bellatrix.BeaconState | capella.BeaconState)) = state: var (altair.BeaconState | bellatrix.BeaconState | capella.BeaconState)) =
let next_epoch = get_current_epoch(state) + 1 let next_epoch = get_current_epoch(state) + 1
@ -1009,7 +1009,7 @@ func process_sync_committee_updates*(
state.current_sync_committee = state.next_sync_committee state.current_sync_committee = state.next_sync_committee
state.next_sync_committee = get_next_sync_committee(state) state.next_sync_committee = get_next_sync_committee(state)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/beacon-chain.md#inactivity-scores # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/beacon-chain.md#inactivity-scores
func process_inactivity_updates*( func process_inactivity_updates*(
cfg: RuntimeConfig, cfg: RuntimeConfig,
state: var (altair.BeaconState | bellatrix.BeaconState | capella.BeaconState), state: var (altair.BeaconState | bellatrix.BeaconState | capella.BeaconState),
@ -1122,7 +1122,7 @@ func process_partial_withdrawals*(state: var capella.BeaconState) =
state.next_partial_withdrawal_validator_index = validator_index state.next_partial_withdrawal_validator_index = validator_index
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#epoch-processing # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#epoch-processing
proc process_epoch*( proc process_epoch*(
cfg: RuntimeConfig, state: var phase0.BeaconState, flags: UpdateFlags, cfg: RuntimeConfig, state: var phase0.BeaconState, flags: UpdateFlags,
cache: var StateCache, info: var phase0.EpochInfo): Result[void, cstring] = cache: var StateCache, info: var phase0.EpochInfo): Result[void, cstring] =
@ -1179,7 +1179,7 @@ func init*(
state: altair.BeaconState | bellatrix.BeaconState | capella.BeaconState): T = state: altair.BeaconState | bellatrix.BeaconState | capella.BeaconState): T =
init(result, state) init(result, state)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/beacon-chain.md#epoch-processing # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/beacon-chain.md#epoch-processing
proc process_epoch*( proc process_epoch*(
cfg: RuntimeConfig, state: var (altair.BeaconState | bellatrix.BeaconState), cfg: RuntimeConfig, state: var (altair.BeaconState | bellatrix.BeaconState),
flags: UpdateFlags, cache: var StateCache, info: var altair.EpochInfo): flags: UpdateFlags, cache: var StateCache, info: var altair.EpochInfo):
@ -1190,7 +1190,7 @@ proc process_epoch*(
info.init(state) info.init(state)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#justification-and-finalization # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#justification-and-finalization
process_justification_and_finalization(state, info.balances, flags) process_justification_and_finalization(state, info.balances, flags)
# state.slot hasn't been incremented yet. # state.slot hasn't been incremented yet.
@ -1205,13 +1205,13 @@ proc process_epoch*(
process_inactivity_updates(cfg, state, info) # [New in Altair] process_inactivity_updates(cfg, state, info) # [New in Altair]
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#process_rewards_and_penalties # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#process_rewards_and_penalties
process_rewards_and_penalties(cfg, state, info) process_rewards_and_penalties(cfg, state, info)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#registry-updates # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#registry-updates
? process_registry_updates(cfg, state, cache) ? process_registry_updates(cfg, state, cache)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#slashings # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#slashings
process_slashings(state, info.balances.current_epoch) process_slashings(state, info.balances.current_epoch)
process_eth1_data_reset(state) process_eth1_data_reset(state)
@ -1235,7 +1235,7 @@ proc process_epoch*(
info.init(state) info.init(state)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#justification-and-finalization # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#justification-and-finalization
process_justification_and_finalization(state, info.balances, flags) process_justification_and_finalization(state, info.balances, flags)
# state.slot hasn't been incremented yet. # state.slot hasn't been incremented yet.
@ -1250,13 +1250,13 @@ proc process_epoch*(
process_inactivity_updates(cfg, state, info) # [New in Altair] process_inactivity_updates(cfg, state, info) # [New in Altair]
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#process_rewards_and_penalties # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#process_rewards_and_penalties
process_rewards_and_penalties(cfg, state, info) process_rewards_and_penalties(cfg, state, info)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#registry-updates # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#registry-updates
? process_registry_updates(cfg, state, cache) ? process_registry_updates(cfg, state, cache)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#slashings # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#slashings
process_slashings(state, info.balances.current_epoch) process_slashings(state, info.balances.current_epoch)
process_eth1_data_reset(state) process_eth1_data_reset(state)

View File

@ -25,8 +25,8 @@ const
PIVOT_VIEW_SIZE = SEED_SIZE + ROUND_SIZE PIVOT_VIEW_SIZE = SEED_SIZE + ROUND_SIZE
TOTAL_SIZE = PIVOT_VIEW_SIZE + POSITION_WINDOW_SIZE TOTAL_SIZE = PIVOT_VIEW_SIZE + POSITION_WINDOW_SIZE
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#compute_shuffled_index # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#compute_shuffled_index
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#compute_committee # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#compute_committee
# Port of https://github.com/protolambda/zrnt/blob/master/eth2/beacon/shuffle.go # Port of https://github.com/protolambda/zrnt/blob/master/eth2/beacon/shuffle.go
# Shuffles or unshuffles, depending on the `dir` (true for shuffling, false for unshuffling # Shuffles or unshuffles, depending on the `dir` (true for shuffling, false for unshuffling
func shuffle_list*(input: var seq[ValidatorIndex], seed: Eth2Digest) = func shuffle_list*(input: var seq[ValidatorIndex], seed: Eth2Digest) =
@ -156,13 +156,13 @@ func get_shuffled_active_validator_indices*(
withState(state): withState(state):
cache.get_shuffled_active_validator_indices(forkyState.data, epoch) cache.get_shuffled_active_validator_indices(forkyState.data, epoch)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#get_active_validator_indices # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#get_active_validator_indices
func count_active_validators*(state: ForkyBeaconState, func count_active_validators*(state: ForkyBeaconState,
epoch: Epoch, epoch: Epoch,
cache: var StateCache): uint64 = cache: var StateCache): uint64 =
cache.get_shuffled_active_validator_indices(state, epoch).lenu64 cache.get_shuffled_active_validator_indices(state, epoch).lenu64
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#get_committee_count_per_slot # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#get_committee_count_per_slot
func get_committee_count_per_slot*(num_active_validators: uint64): uint64 = func get_committee_count_per_slot*(num_active_validators: uint64): uint64 =
clamp( clamp(
num_active_validators div SLOTS_PER_EPOCH div TARGET_COMMITTEE_SIZE, num_active_validators div SLOTS_PER_EPOCH div TARGET_COMMITTEE_SIZE,
@ -187,7 +187,7 @@ iterator get_committee_indices*(committee_count_per_slot: uint64): CommitteeInde
let committee_index = CommitteeIndex.init(idx).expect("value clamped") let committee_index = CommitteeIndex.init(idx).expect("value clamped")
yield committee_index yield committee_index
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#compute_committee # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#compute_committee
func compute_committee_slice*( func compute_committee_slice*(
active_validators, index, count: uint64): Slice[int] = active_validators, index, count: uint64): Slice[int] =
doAssert active_validators <= ValidatorIndex.high.uint64 doAssert active_validators <= ValidatorIndex.high.uint64
@ -233,7 +233,7 @@ func compute_committee_len*(
(slice.b - slice.a + 1).uint64 (slice.b - slice.a + 1).uint64
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#get_beacon_committee # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#get_beacon_committee
iterator get_beacon_committee*( iterator get_beacon_committee*(
state: ForkyBeaconState, slot: Slot, index: CommitteeIndex, state: ForkyBeaconState, slot: Slot, index: CommitteeIndex,
cache: var StateCache): (int, ValidatorIndex) = cache: var StateCache): (int, ValidatorIndex) =
@ -273,7 +273,7 @@ func get_beacon_committee*(
withState(state): withState(state):
get_beacon_committee(forkyState.data, slot, index, cache) get_beacon_committee(forkyState.data, slot, index, cache)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#get_beacon_committee # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#get_beacon_committee
func get_beacon_committee_len*( func get_beacon_committee_len*(
state: ForkyBeaconState, slot: Slot, index: CommitteeIndex, state: ForkyBeaconState, slot: Slot, index: CommitteeIndex,
cache: var StateCache): uint64 = cache: var StateCache): uint64 =
@ -296,7 +296,7 @@ func get_beacon_committee_len*(
withState(state): withState(state):
get_beacon_committee_len(forkyState.data, slot, index, cache) get_beacon_committee_len(forkyState.data, slot, index, cache)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#compute_shuffled_index # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#compute_shuffled_index
func compute_shuffled_index*( func compute_shuffled_index*(
index: uint64, index_count: uint64, seed: Eth2Digest): uint64 = index: uint64, index_count: uint64, seed: Eth2Digest): uint64 =
## Return the shuffled index corresponding to ``seed`` (and ``index_count``). ## Return the shuffled index corresponding to ``seed`` (and ``index_count``).
@ -331,7 +331,7 @@ func compute_shuffled_index*(
cur_idx_permuted cur_idx_permuted
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#compute_proposer_index # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#compute_proposer_index
func compute_proposer_index(state: ForkyBeaconState, func compute_proposer_index(state: ForkyBeaconState,
indices: seq[ValidatorIndex], seed: Eth2Digest): Option[ValidatorIndex] = indices: seq[ValidatorIndex], seed: Eth2Digest): Option[ValidatorIndex] =
## Return from ``indices`` a random index sampled by effective balance. ## Return from ``indices`` a random index sampled by effective balance.
@ -358,7 +358,7 @@ func compute_proposer_index(state: ForkyBeaconState,
return some(candidate_index) return some(candidate_index)
i += 1 i += 1
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#get_beacon_proposer_index # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#get_beacon_proposer_index
func get_beacon_proposer_index*( func get_beacon_proposer_index*(
state: ForkyBeaconState, cache: var StateCache, slot: Slot): state: ForkyBeaconState, cache: var StateCache, slot: Slot):
Option[ValidatorIndex] = Option[ValidatorIndex] =
@ -396,7 +396,7 @@ func get_beacon_proposer_index*(
return res return res
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#get_beacon_proposer_index # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#get_beacon_proposer_index
func get_beacon_proposer_index*(state: ForkyBeaconState, cache: var StateCache): func get_beacon_proposer_index*(state: ForkyBeaconState, cache: var StateCache):
Option[ValidatorIndex] = Option[ValidatorIndex] =
get_beacon_proposer_index(state, cache, state.slot) get_beacon_proposer_index(state, cache, state.slot)
@ -407,7 +407,7 @@ func get_beacon_proposer_index*(state: ForkedHashedBeaconState,
withState(state): withState(state):
get_beacon_proposer_index(forkyState.data, cache, slot) get_beacon_proposer_index(forkyState.data, cache, slot)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/validator.md#aggregation-selection # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/validator.md#aggregation-selection
func is_aggregator*(committee_len: uint64, slot_signature: ValidatorSig): bool = func is_aggregator*(committee_len: uint64, slot_signature: ValidatorSig): bool =
let let
modulo = max(1'u64, committee_len div TARGET_AGGREGATORS_PER_COMMITTEE) modulo = max(1'u64, committee_len div TARGET_AGGREGATORS_PER_COMMITTEE)

View File

@ -29,7 +29,7 @@ func compute_weak_subjectivity_period(
SAFETY_DECAY * validator_count div (2 * 100 * cfg.MIN_PER_EPOCH_CHURN_LIMIT) SAFETY_DECAY * validator_count div (2 * 100 * cfg.MIN_PER_EPOCH_CHURN_LIMIT)
return weak_subjectivity_period return weak_subjectivity_period
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/weak-subjectivity.md#checking-for-stale-weak-subjectivity-checkpoint # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/weak-subjectivity.md#checking-for-stale-weak-subjectivity-checkpoint
func is_within_weak_subjectivity_period*(cfg: RuntimeConfig, current_slot: Slot, func is_within_weak_subjectivity_period*(cfg: RuntimeConfig, current_slot: Slot,
ws_state: ForkedHashedBeaconState, ws_state: ForkedHashedBeaconState,
ws_checkpoint: Checkpoint): bool = ws_checkpoint: Checkpoint): bool =

View File

@ -116,7 +116,7 @@ proc isGossipSupported*(
else: else:
period <= finalizedPeriod period <= finalizedPeriod
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/light-client/p2p-interface.md#getlightclientbootstrap # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/light-client/p2p-interface.md#getlightclientbootstrap
proc doRequest( proc doRequest(
e: typedesc[Bootstrap], e: typedesc[Bootstrap],
peer: Peer, peer: Peer,
@ -125,7 +125,7 @@ proc doRequest(
raises: [Defect, IOError].} = raises: [Defect, IOError].} =
peer.lightClientBootstrap(blockRoot) peer.lightClientBootstrap(blockRoot)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/light-client/p2p-interface.md#lightclientupdatesbyrange # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/light-client/p2p-interface.md#lightclientupdatesbyrange
type LightClientUpdatesByRangeResponse = type LightClientUpdatesByRangeResponse =
NetRes[List[altair.LightClientUpdate, MAX_REQUEST_LIGHT_CLIENT_UPDATES]] NetRes[List[altair.LightClientUpdate, MAX_REQUEST_LIGHT_CLIENT_UPDATES]]
proc doRequest( proc doRequest(
@ -166,7 +166,7 @@ proc doRequest(
inc expectedPeriod inc expectedPeriod
return response return response
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/light-client/p2p-interface.md#getlightclientfinalityupdate # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/light-client/p2p-interface.md#getlightclientfinalityupdate
proc doRequest( proc doRequest(
e: typedesc[FinalityUpdate], e: typedesc[FinalityUpdate],
peer: Peer peer: Peer
@ -174,7 +174,7 @@ proc doRequest(
raises: [Defect, IOError].} = raises: [Defect, IOError].} =
peer.lightClientFinalityUpdate() peer.lightClientFinalityUpdate()
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/light-client/p2p-interface.md#getlightclientoptimisticupdate # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/light-client/p2p-interface.md#getlightclientoptimisticupdate
proc doRequest( proc doRequest(
e: typedesc[OptimisticUpdate], e: typedesc[OptimisticUpdate],
peer: Peer peer: Peer
@ -388,7 +388,7 @@ func fetchTime(
jitterDelay = chronos.seconds(self.rng[].rand(jitterSeconds).int64) jitterDelay = chronos.seconds(self.rng[].rand(jitterSeconds).int64)
return wallTime + minDelay + jitterDelay return wallTime + minDelay + jitterDelay
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/light-client/light-client.md#light-client-sync-process # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/light-client/light-client.md#light-client-sync-process
proc loop(self: LightClientManager) {.async.} = proc loop(self: LightClientManager) {.async.} =
var nextFetchTime = self.getBeaconTime() var nextFetchTime = self.getBeaconTime()
while true: while true:

View File

@ -29,7 +29,7 @@ const
blockResponseCost = allowedOpsPerSecondCost(64) # Allow syncing ~64 blocks/sec (minus request costs) blockResponseCost = allowedOpsPerSecondCost(64) # Allow syncing ~64 blocks/sec (minus request costs)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/light-client/p2p-interface.md#configuration # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/light-client/p2p-interface.md#configuration
MAX_REQUEST_LIGHT_CLIENT_UPDATES* = 128 MAX_REQUEST_LIGHT_CLIENT_UPDATES* = 128
lightClientBootstrapResponseCost = allowedOpsPerSecondCost(1) lightClientBootstrapResponseCost = allowedOpsPerSecondCost(1)
## Only one bootstrap per peer should ever be needed - no need to allow more ## Only one bootstrap per peer should ever be needed - no need to allow more
@ -293,7 +293,7 @@ p2pProtocol BeaconSync(version = 1,
if startSlot.epoch >= dag.cfg.ALTAIR_FORK_EPOCH: if startSlot.epoch >= dag.cfg.ALTAIR_FORK_EPOCH:
# "Clients MAY limit the number of blocks in the response." # "Clients MAY limit the number of blocks in the response."
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/p2p-interface.md#beaconblocksbyrange # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/p2p-interface.md#beaconblocksbyrange
debug "Block range v1 request for post-altair range", debug "Block range v1 request for post-altair range",
peer, startSlot, reqCount, reqStep peer, startSlot, reqCount, reqStep
return return
@ -379,7 +379,7 @@ p2pProtocol BeaconSync(version = 1,
if blockRef.slot.epoch >= dag.cfg.ALTAIR_FORK_EPOCH: if blockRef.slot.epoch >= dag.cfg.ALTAIR_FORK_EPOCH:
# Skipping this block should be fine because the spec says: # Skipping this block should be fine because the spec says:
# "Clients MAY limit the number of blocks in the response." # "Clients MAY limit the number of blocks in the response."
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/p2p-interface.md#beaconblocksbyroot # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/p2p-interface.md#beaconblocksbyroot
# #
# Also, our response would be indistinguishable from a node # Also, our response would be indistinguishable from a node
# that have been synced exactly to the altair transition slot. # that have been synced exactly to the altair transition slot.
@ -534,7 +534,7 @@ p2pProtocol BeaconSync(version = 1,
debug "Block root request done", debug "Block root request done",
peer, roots = blockRoots.len, count, found peer, roots = blockRoots.len, count, found
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/light-client/p2p-interface.md#getlightclientbootstrap # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/light-client/p2p-interface.md#getlightclientbootstrap
proc lightClientBootstrap( proc lightClientBootstrap(
peer: Peer, peer: Peer,
blockRoot: Eth2Digest, blockRoot: Eth2Digest,
@ -560,7 +560,7 @@ p2pProtocol BeaconSync(version = 1,
debug "LC bootstrap request done", peer, blockRoot debug "LC bootstrap request done", peer, blockRoot
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/light-client/p2p-interface.md#lightclientupdatesbyrange # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/light-client/p2p-interface.md#lightclientupdatesbyrange
proc lightClientUpdatesByRange( proc lightClientUpdatesByRange(
peer: Peer, peer: Peer,
startPeriod: SyncCommitteePeriod, startPeriod: SyncCommitteePeriod,
@ -600,7 +600,7 @@ p2pProtocol BeaconSync(version = 1,
debug "LC updates by range request done", peer, startPeriod, count, found debug "LC updates by range request done", peer, startPeriod, count, found
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/light-client/p2p-interface.md#getlightclientfinalityupdate # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/light-client/p2p-interface.md#getlightclientfinalityupdate
proc lightClientFinalityUpdate( proc lightClientFinalityUpdate(
peer: Peer, peer: Peer,
response: SingleChunkResponse[altair.LightClientFinalityUpdate]) response: SingleChunkResponse[altair.LightClientFinalityUpdate])
@ -626,7 +626,7 @@ p2pProtocol BeaconSync(version = 1,
debug "LC finality update request done", peer debug "LC finality update request done", peer
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/light-client/p2p-interface.md#getlightclientoptimisticupdate # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/light-client/p2p-interface.md#getlightclientoptimisticupdate
proc lightClientOptimisticUpdate( proc lightClientOptimisticUpdate(
peer: Peer, peer: Peer,
response: SingleChunkResponse[altair.LightClientOptimisticUpdate]) response: SingleChunkResponse[altair.LightClientOptimisticUpdate])

View File

@ -36,7 +36,7 @@ import
# - https://notes.ethereum.org/@djrtwo/Bkn3zpwxB#Validator-responsibilities # - https://notes.ethereum.org/@djrtwo/Bkn3zpwxB#Validator-responsibilities
# #
# Phase 0 spec - Honest Validator - how to avoid slashing # Phase 0 spec - Honest Validator - how to avoid slashing
# - https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/validator.md#how-to-avoid-slashing # - https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/validator.md#how-to-avoid-slashing
# #
# In-depth reading on slashing conditions # In-depth reading on slashing conditions
# #
@ -58,7 +58,7 @@ import
# 2. An attester can get slashed for signing # 2. An attester can get slashed for signing
# two attestations that together violate # two attestations that together violate
# the Casper FFG slashing conditions. # the Casper FFG slashing conditions.
# - https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/validator.md#ffg-vote # - https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/validator.md#ffg-vote
# The "source" is the current_justified_epoch # The "source" is the current_justified_epoch
# The "target" is the current_epoch # The "target" is the current_epoch
# #

View File

@ -268,7 +268,7 @@ proc signData(v: AttachedValidator,
else: else:
v.signWithDistributedKey(request) v.signWithDistributedKey(request)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/validator.md#signature # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/validator.md#signature
proc getBlockSignature*(v: AttachedValidator, fork: Fork, proc getBlockSignature*(v: AttachedValidator, fork: Fork,
genesis_validators_root: Eth2Digest, slot: Slot, genesis_validators_root: Eth2Digest, slot: Slot,
block_root: Eth2Digest, block_root: Eth2Digest,
@ -312,7 +312,7 @@ proc getBlockSignature*(v: AttachedValidator, fork: Fork,
fork, genesis_validators_root, web3SignerBlock) fork, genesis_validators_root, web3SignerBlock)
await v.signData(request) await v.signData(request)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/validator.md#aggregate-signature # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/validator.md#aggregate-signature
proc getAttestationSignature*(v: AttachedValidator, fork: Fork, proc getAttestationSignature*(v: AttachedValidator, fork: Fork,
genesis_validators_root: Eth2Digest, genesis_validators_root: Eth2Digest,
data: AttestationData data: AttestationData
@ -328,7 +328,7 @@ proc getAttestationSignature*(v: AttachedValidator, fork: Fork,
let request = Web3SignerRequest.init(fork, genesis_validators_root, data) let request = Web3SignerRequest.init(fork, genesis_validators_root, data)
await v.signData(request) await v.signData(request)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/validator.md#broadcast-aggregate # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/validator.md#broadcast-aggregate
proc getAggregateAndProofSignature*(v: AttachedValidator, proc getAggregateAndProofSignature*(v: AttachedValidator,
fork: Fork, fork: Fork,
genesis_validators_root: Eth2Digest, genesis_validators_root: Eth2Digest,
@ -414,7 +414,7 @@ proc getContributionAndProofSignature*(v: AttachedValidator, fork: Fork,
fork, genesis_validators_root, contribution_and_proof) fork, genesis_validators_root, contribution_and_proof)
await v.signData(request) await v.signData(request)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/validator.md#randao-reveal # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/validator.md#randao-reveal
proc getEpochSignature*(v: AttachedValidator, fork: Fork, proc getEpochSignature*(v: AttachedValidator, fork: Fork,
genesis_validators_root: Eth2Digest, epoch: Epoch genesis_validators_root: Eth2Digest, epoch: Epoch
): Future[SignatureResult] {.async.} = ): Future[SignatureResult] {.async.} =
@ -429,7 +429,7 @@ proc getEpochSignature*(v: AttachedValidator, fork: Fork,
fork, genesis_validators_root, epoch) fork, genesis_validators_root, epoch)
await v.signData(request) await v.signData(request)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/validator.md#aggregation-selection # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/validator.md#aggregation-selection
proc getSlotSignature*(v: AttachedValidator, fork: Fork, proc getSlotSignature*(v: AttachedValidator, fork: Fork,
genesis_validators_root: Eth2Digest, slot: Slot genesis_validators_root: Eth2Digest, slot: Slot
): Future[SignatureResult] {.async.} = ): Future[SignatureResult] {.async.} =

View File

@ -9,7 +9,7 @@ It is important to distinguish attestation `validation` from attestation `verifi
- Aggregated: https://github.com/ethereum/consensus-specs/blob/v1.1.10/specs/phase0/p2p-interface.md#beacon_aggregate_and_proof - Aggregated: https://github.com/ethereum/consensus-specs/blob/v1.1.10/specs/phase0/p2p-interface.md#beacon_aggregate_and_proof
- Unaggregated: https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/p2p-interface.md#beacon_attestation_subnet_id - Unaggregated: https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/p2p-interface.md#beacon_attestation_subnet_id
- Attestation `verification` is defined in the consensus specs. Verified attestations can affect fork choice and may be included in a block. - Attestation `verification` is defined in the consensus specs. Verified attestations can affect fork choice and may be included in a block.
- https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#attestations - https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#attestations
From the specs it seems like gossip attestation `validation` is a superset of consensus attestation `verification`. From the specs it seems like gossip attestation `validation` is a superset of consensus attestation `verification`.

View File

@ -9,7 +9,7 @@ Important distinction:
https://github.com/ethereum/consensus-specs/blob/v1.1.10/specs/phase0/p2p-interface.md#beacon_block. https://github.com/ethereum/consensus-specs/blob/v1.1.10/specs/phase0/p2p-interface.md#beacon_block.
A validated block can be forwarded on gossipsub. A validated block can be forwarded on gossipsub.
- and we distinguish `verification` which is defined in consensus specs: - and we distinguish `verification` which is defined in consensus specs:
https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#block-processing https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#block-processing
A block needs to be verified to enter fork choice, the DAG and the BeaconChainDB A block needs to be verified to enter fork choice, the DAG and the BeaconChainDB
In particular in terms of costly checks validating a block only requires checking: In particular in terms of costly checks validating a block only requires checking:

View File

@ -22,7 +22,7 @@ import
# Test utilities # Test utilities
../../testutil, ../../testblockutil ../../testutil, ../../testblockutil
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/tests/core/pyspec/eth2spec/test/helpers/sync_committee.py#L27-L44 # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/tests/core/pyspec/eth2spec/test/helpers/sync_committee.py#L27-L44
proc compute_aggregate_sync_committee_signature( proc compute_aggregate_sync_committee_signature(
cfg: RuntimeConfig, cfg: RuntimeConfig,
forked: ForkedHashedBeaconState, forked: ForkedHashedBeaconState,
@ -53,7 +53,7 @@ proc compute_aggregate_sync_committee_signature(
aggregateSig.aggregate(signature) aggregateSig.aggregate(signature)
aggregateSig.finish.toValidatorSig aggregateSig.finish.toValidatorSig
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/tests/core/pyspec/eth2spec/test/helpers/light_client.py#L32-L62 # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/tests/core/pyspec/eth2spec/test/helpers/light_client.py#L32-L62
proc get_sync_aggregate( proc get_sync_aggregate(
cfg: RuntimeConfig, cfg: RuntimeConfig,
forked: ForkedHashedBeaconState, forked: ForkedHashedBeaconState,
@ -137,7 +137,7 @@ let full_sync_committee_bits = block:
res.bytes.fill(byte.high) res.bytes.fill(byte.high)
res res
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/tests/core/pyspec/eth2spec/test/helpers/light_client.py#L20-L29 # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/tests/core/pyspec/eth2spec/test/helpers/light_client.py#L20-L29
func initialize_light_client_store(state: auto): LightClientStore = func initialize_light_client_store(state: auto): LightClientStore =
LightClientStore( LightClientStore(
finalized_header: BeaconBlockHeader(), finalized_header: BeaconBlockHeader(),
@ -157,7 +157,7 @@ suite "EF - Altair - Unittests - Light client - Sync protocol" & preset():
res res
genesisState = newClone(initGenesisState(cfg = cfg)) genesisState = newClone(initGenesisState(cfg = cfg))
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/tests/core/pyspec/eth2spec/test/altair/unittests/light_client/test_sync_protocol.py#L23-L60 # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/tests/core/pyspec/eth2spec/test/altair/unittests/light_client/test_sync_protocol.py#L23-L60
test "test_process_light_client_update_not_timeout": test "test_process_light_client_update_not_timeout":
let forked = assignClone(genesisState[]) let forked = assignClone(genesisState[])
template state(): auto = forked[].altairData.data template state(): auto = forked[].altairData.data
@ -203,7 +203,7 @@ suite "EF - Altair - Unittests - Light client - Sync protocol" & preset():
store.optimistic_header == update.attested_header store.optimistic_header == update.attested_header
store.current_max_active_participants > 0 store.current_max_active_participants > 0
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/tests/core/pyspec/eth2spec/test/altair/unittests/light_client/test_sync_protocol.py#L63-L104 # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/tests/core/pyspec/eth2spec/test/altair/unittests/light_client/test_sync_protocol.py#L63-L104
test "test_process_light_client_update_at_period_boundary": test "test_process_light_client_update_at_period_boundary":
var forked = assignClone(genesisState[]) var forked = assignClone(genesisState[])
template state(): auto = forked[].altairData.data template state(): auto = forked[].altairData.data
@ -256,7 +256,7 @@ suite "EF - Altair - Unittests - Light client - Sync protocol" & preset():
store.optimistic_header == update.attested_header store.optimistic_header == update.attested_header
store.current_max_active_participants > 0 store.current_max_active_participants > 0
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/tests/core/pyspec/eth2spec/test/altair/unittests/light_client/test_sync_protocol.py#L107-L149 # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/tests/core/pyspec/eth2spec/test/altair/unittests/light_client/test_sync_protocol.py#L107-L149
test "process_light_client_update_timeout": test "process_light_client_update_timeout":
let forked = assignClone(genesisState[]) let forked = assignClone(genesisState[])
template state(): auto = forked[].altairData.data template state(): auto = forked[].altairData.data
@ -312,7 +312,7 @@ suite "EF - Altair - Unittests - Light client - Sync protocol" & preset():
store.optimistic_header == update.attested_header store.optimistic_header == update.attested_header
store.current_max_active_participants > 0 store.current_max_active_participants > 0
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/tests/core/pyspec/eth2spec/test/altair/unittests/light_client/test_sync_protocol.py#L152-L201 # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/tests/core/pyspec/eth2spec/test/altair/unittests/light_client/test_sync_protocol.py#L152-L201
test "process_light_client_update_finality_updated": test "process_light_client_update_finality_updated":
let forked = assignClone(genesisState[]) let forked = assignClone(genesisState[])
template state(): auto = forked[].altairData.data template state(): auto = forked[].altairData.data

View File

@ -69,7 +69,7 @@ type
rewards*: List[uint64, Limit VALIDATOR_REGISTRY_LIMIT] rewards*: List[uint64, Limit VALIDATOR_REGISTRY_LIMIT]
penalties*: List[uint64, Limit VALIDATOR_REGISTRY_LIMIT] penalties*: List[uint64, Limit VALIDATOR_REGISTRY_LIMIT]
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/validator.md#eth1block # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/validator.md#eth1block
Eth1Block* = object Eth1Block* = object
timestamp*: uint64 timestamp*: uint64
deposit_root*: Eth2Digest deposit_root*: Eth2Digest

View File

@ -7,7 +7,7 @@
# process_deposit (beaconstate.nim) # process_deposit (beaconstate.nim)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#deposits # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#deposits
# --------------------------------------------------------------- # ---------------------------------------------------------------
{.used.} {.used.}