assorted consensus spec URL updates to v1.3.0-rc.5 (#4768)

This commit is contained in:
tersec 2023-03-27 14:41:22 +00:00 committed by GitHub
parent 29c77948cb
commit 9d2fdc2e26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 53 additions and 49 deletions

View File

@ -26,7 +26,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.3.0-rc.4/specs/phase0/fork-choice.md#fork-choice ## https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/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

@ -25,7 +25,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.3.0-rc.3/specs/phase0/beacon-chain.md#get_committee_count_per_slot # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/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))
@ -51,7 +51,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.3.0-rc.3/specs/phase0/beacon-chain.md#get_beacon_committee # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/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] =

View File

@ -408,7 +408,7 @@ template toGaugeValue(x: Quantity): int64 =
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.3.0-rc.2/specs/phase0/validator.md#get_eth1_data # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/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

View File

@ -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.3.0-rc.3/specs/phase0/beacon-chain.md#compute_start_slot_at_epoch # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/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.3.0-rc.3/specs/phase0/beacon-chain.md#get_previous_epoch # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/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

@ -150,14 +150,14 @@ func get_slashing_penalty*(state: ForkyBeaconState,
else: else:
{.fatal: "invalid BeaconState type".} {.fatal: "invalid BeaconState type".}
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/phase0/beacon-chain.md#slash_validator # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/phase0/beacon-chain.md#slash_validator
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/altair/beacon-chain.md#modified-slash_validator # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/altair/beacon-chain.md#modified-slash_validator
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/bellatrix/beacon-chain.md#modified-slash_validator # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/bellatrix/beacon-chain.md#modified-slash_validator
func get_whistleblower_reward*(validator_effective_balance: Gwei): Gwei = func get_whistleblower_reward*(validator_effective_balance: Gwei): Gwei =
validator_effective_balance div WHISTLEBLOWER_REWARD_QUOTIENT validator_effective_balance div WHISTLEBLOWER_REWARD_QUOTIENT
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/phase0/beacon-chain.md#slash_validator # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/phase0/beacon-chain.md#slash_validator
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/altair/beacon-chain.md#modified-slash_validator # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/altair/beacon-chain.md#modified-slash_validator
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/bellatrix/beacon-chain.md#modified-slash_validator # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/bellatrix/beacon-chain.md#modified-slash_validator
func get_proposer_reward(state: ForkyBeaconState, whistleblower_reward: Gwei): Gwei = func get_proposer_reward(state: ForkyBeaconState, whistleblower_reward: Gwei): Gwei =
when state is phase0.BeaconState: when state is phase0.BeaconState:
@ -169,7 +169,7 @@ func get_proposer_reward(state: ForkyBeaconState, whistleblower_reward: Gwei): G
{.fatal: "invalid BeaconState type".} {.fatal: "invalid BeaconState type".}
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/phase0/beacon-chain.md#slash_validator # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/phase0/beacon-chain.md#slash_validator
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/altair/beacon-chain.md#modified-slash_validator # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/altair/beacon-chain.md#modified-slash_validator
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/bellatrix/beacon-chain.md#modified-slash_validator # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/bellatrix/beacon-chain.md#modified-slash_validator
proc slash_validator*( proc slash_validator*(
cfg: RuntimeConfig, state: var ForkyBeaconState, cfg: RuntimeConfig, state: var ForkyBeaconState,
@ -331,7 +331,7 @@ func is_eligible_for_activation_queue*(validator: Validator): bool =
validator.activation_eligibility_epoch == FAR_FUTURE_EPOCH and validator.activation_eligibility_epoch == FAR_FUTURE_EPOCH and
validator.effective_balance == MAX_EFFECTIVE_BALANCE validator.effective_balance == MAX_EFFECTIVE_BALANCE
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/phase0/beacon-chain.md#is_eligible_for_activation # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/phase0/beacon-chain.md#is_eligible_for_activation
func is_eligible_for_activation*( func is_eligible_for_activation*(
state: ForkyBeaconState, validator: Validator): bool = state: ForkyBeaconState, validator: Validator): bool =
## Check if ``validator`` is eligible for activation. ## Check if ``validator`` is eligible for activation.
@ -522,7 +522,7 @@ func get_attestation_participation_flag_indices(
# TODO these duplicate some stuff in state_transition_epoch which uses TotalBalances # TODO these duplicate some stuff in state_transition_epoch which uses TotalBalances
# better to centralize around that if feasible # better to centralize around that if feasible
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/phase0/beacon-chain.md#get_total_active_balance # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/phase0/beacon-chain.md#get_total_active_balance
func get_total_active_balance*(state: ForkyBeaconState, cache: var StateCache): Gwei = func get_total_active_balance*(state: ForkyBeaconState, cache: var StateCache): Gwei =
## Return the combined effective balance of the active validators. ## Return the combined effective balance of the active validators.
# Note: ``get_total_balance`` returns ``EFFECTIVE_BALANCE_INCREMENT`` Gwei # Note: ``get_total_balance`` returns ``EFFECTIVE_BALANCE_INCREMENT`` Gwei

View File

@ -95,7 +95,7 @@ export
# API # API
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/phase0/beacon-chain.md#bls-signatures # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/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
@ -216,7 +216,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.3.0-rc.3/specs/phase0/beacon-chain.md#bls-signatures # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/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

@ -57,7 +57,7 @@ const
TIMELY_TARGET_FLAG_INDEX* = 1 TIMELY_TARGET_FLAG_INDEX* = 1
TIMELY_HEAD_FLAG_INDEX* = 2 TIMELY_HEAD_FLAG_INDEX* = 2
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/altair/beacon-chain.md#inactivity-penalties # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/altair/beacon-chain.md#inactivity-penalties
INACTIVITY_SCORE_BIAS* = 4 INACTIVITY_SCORE_BIAS* = 4
INACTIVITY_SCORE_RECOVERY_RATE* = 16 INACTIVITY_SCORE_RECOVERY_RATE* = 16
@ -80,7 +80,7 @@ type
## effectively making the cost of clearing the cache higher than the typical ## effectively making the cost of clearing the cache higher than the typical
## gains ## gains
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/altair/beacon-chain.md#syncaggregate # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/altair/beacon-chain.md#syncaggregate
SyncAggregate* = object SyncAggregate* = object
sync_committee_bits*: BitArray[SYNC_COMMITTEE_SIZE] sync_committee_bits*: BitArray[SYNC_COMMITTEE_SIZE]
sync_committee_signature*: ValidatorSig sync_committee_signature*: ValidatorSig
@ -204,7 +204,7 @@ type
# Slot at which the aggregate signature was created (untrusted) # Slot at which the aggregate signature was created (untrusted)
signature_slot*: Slot signature_slot*: Slot
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/altair/light-client/sync-protocol.md#lightclientoptimisticupdate # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/altair/light-client/sync-protocol.md#lightclientoptimisticupdate
LightClientOptimisticUpdate* = object LightClientOptimisticUpdate* = object
# Header attested to by the sync committee # Header attested to by the sync committee
attested_header*: LightClientHeader attested_header*: LightClientHeader
@ -230,7 +230,7 @@ type
LightClientBootstrap | LightClientBootstrap |
SomeLightClientUpdate SomeLightClientUpdate
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/altair/light-client/sync-protocol.md#lightclientstore # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/altair/light-client/sync-protocol.md#lightclientstore
LightClientStore* = object LightClientStore* = object
finalized_header*: LightClientHeader finalized_header*: LightClientHeader
## Header that is finalized ## Header that is finalized
@ -338,7 +338,7 @@ type
data*: BeaconState data*: BeaconState
root*: Eth2Digest # hash_tree_root(data) root*: Eth2Digest # hash_tree_root(data)
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/phase0/beacon-chain.md#beaconblock # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/phase0/beacon-chain.md#beaconblock
BeaconBlock* = object BeaconBlock* = object
## For each slot, a proposer is chosen from the validator pool to propose ## For each slot, a proposer is chosen from the validator pool to propose
## a new block. Once the block as been proposed, it is transmitted to ## a new block. Once the block as been proposed, it is transmitted to

View File

@ -260,7 +260,7 @@ type
data*: DepositData data*: DepositData
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/phase0/beacon-chain.md#depositmessage # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/phase0/beacon-chain.md#depositmessage
DepositMessage* = object DepositMessage* = object
pubkey*: ValidatorPubKey pubkey*: ValidatorPubKey
withdrawal_credentials*: Eth2Digest withdrawal_credentials*: Eth2Digest
@ -339,7 +339,7 @@ type
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.3.0-rc.3/specs/phase0/beacon-chain.md#fork # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/phase0/beacon-chain.md#fork
Fork* = object Fork* = object
previous_version*: Version previous_version*: Version
current_version*: Version current_version*: Version
@ -415,7 +415,7 @@ type
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.3.0-rc.3/specs/phase0/beacon-chain.md#validator # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/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

View File

@ -90,7 +90,7 @@ type
ExecutePayload* = proc( ExecutePayload* = proc(
execution_payload: ExecutionPayload): bool {.gcsafe, raises: [Defect].} execution_payload: ExecutionPayload): bool {.gcsafe, raises: [Defect].}
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/bellatrix/fork-choice.md#powblock # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/bellatrix/fork-choice.md#powblock
PowBlock* = object PowBlock* = object
block_hash*: Eth2Digest block_hash*: Eth2Digest
parent_hash*: Eth2Digest parent_hash*: Eth2Digest

View File

@ -51,7 +51,7 @@ type
from_bls_pubkey*: ValidatorPubKey from_bls_pubkey*: ValidatorPubKey
to_execution_address*: ExecutionAddress to_execution_address*: ExecutionAddress
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.2/specs/capella/beacon-chain.md#signedblstoexecutionchange # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/capella/beacon-chain.md#signedblstoexecutionchange
SignedBLSToExecutionChange* = object SignedBLSToExecutionChange* = object
message*: BLSToExecutionChange message*: BLSToExecutionChange
signature*: ValidatorSig signature*: ValidatorSig
@ -347,7 +347,7 @@ type
state_root*: Eth2Digest state_root*: Eth2Digest
body*: TrustedBeaconBlockBody body*: TrustedBeaconBlockBody
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.2/specs/capella/beacon-chain.md#beaconblockbody # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/capella/beacon-chain.md#beaconblockbody
BeaconBlockBody* = object BeaconBlockBody* = object
randao_reveal*: ValidatorSig randao_reveal*: ValidatorSig
eth1_data*: Eth1Data eth1_data*: Eth1Data

View File

@ -29,7 +29,7 @@ from ../../vendor/nim-kzg4844/kzg4844 import KZGCommitment, KZGProof
export json_serialization, base, kzg4844 export json_serialization, base, kzg4844
const const
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/deneb/polynomial-commitments.md#constants # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/deneb/polynomial-commitments.md#constants
BYTES_PER_FIELD_ELEMENT = 32 BYTES_PER_FIELD_ELEMENT = 32
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/deneb/beacon-chain.md#blob # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/deneb/beacon-chain.md#blob
@ -76,7 +76,7 @@ type
message*: BlobSidecar message*: BlobSidecar
signature*: ValidatorSig signature*: ValidatorSig
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/deneb/p2p-interface.md#blobidentifier # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/deneb/p2p-interface.md#blobidentifier
BlobIdentifier* = object BlobIdentifier* = object
block_root*: Eth2Digest block_root*: Eth2Digest
index*: BlobIndex index*: BlobIndex

View File

@ -166,7 +166,7 @@ type
state_root*: Eth2Digest state_root*: Eth2Digest
body*: TrustedBeaconBlockBody body*: TrustedBeaconBlockBody
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/phase0/beacon-chain.md#beaconblockbody # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/phase0/beacon-chain.md#beaconblockbody
BeaconBlockBody* = object BeaconBlockBody* = object
randao_reveal*: ValidatorSig randao_reveal*: ValidatorSig
eth1_data*: Eth1Data eth1_data*: Eth1Data

View File

@ -400,7 +400,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.3.0-rc.3/specs/phase0/beacon-chain.md#constants # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/phase0/beacon-chain.md#constants
# GENESIS_SLOT # GENESIS_SLOT
# GENESIS_EPOCH # GENESIS_EPOCH
# FAR_FUTURE_EPOCH # FAR_FUTURE_EPOCH

View File

@ -131,7 +131,7 @@ func uint_to_bytes*(x: uint32): array[4, byte] = toBytesLE(x)
func uint_to_bytes*(x: uint16): array[2, byte] = toBytesLE(x) func uint_to_bytes*(x: uint16): array[2, byte] = toBytesLE(x)
func uint_to_bytes*(x: uint8): array[1, byte] = toBytesLE(x) func uint_to_bytes*(x: uint8): array[1, byte] = toBytesLE(x)
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/phase0/beacon-chain.md#compute_domain # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/phase0/beacon-chain.md#compute_domain
func compute_domain*( func compute_domain*(
domain_type: DomainType, domain_type: DomainType,
fork_version: Version, fork_version: Version,

View File

@ -6,7 +6,11 @@
# 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.3.0-rc.3/specs/phase0/beacon-chain.md#block-processing # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/phase0/beacon-chain.md#block-processing
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/altair/beacon-chain.md#block-processing
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/bellatrix/beacon-chain.md#block-processing
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/capella/beacon-chain.md#block-processing
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/deneb/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 +38,7 @@ from ./datatypes/capella import
export extras, phase0, altair export extras, phase0, altair
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/phase0/beacon-chain.md#block-header # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/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] =
@ -76,7 +80,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.3.0-rc.3/specs/phase0/beacon-chain.md#randao # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/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] =
@ -99,7 +103,7 @@ proc process_randao(
return err("process_randao: invalid epoch signature") return err("process_randao: invalid epoch signature")
# Mix it in # Mix in RANDAO reveal
let let
mix = get_randao_mix(state, epoch) mix = get_randao_mix(state, epoch)
rr = eth2digest(body.randao_reveal.toRaw()).data rr = eth2digest(body.randao_reveal.toRaw()).data
@ -127,7 +131,7 @@ func is_slashable_validator(validator: Validator, epoch: Epoch): bool =
(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.3.0-rc.3/specs/phase0/beacon-chain.md#proposer-slashings # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/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):
@ -186,7 +190,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.3.0-rc.3/specs/phase0/beacon-chain.md#is_slashable_attestation_data # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/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
@ -768,7 +772,7 @@ proc validate_blobs*(expected_kzg_commitments: seq[KZGCommitment],
ok() ok()
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/deneb/fork-choice.md#is_data_available # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/deneb/fork-choice.md#is_data_available
func is_data_available( func is_data_available(
slot: Slot, beacon_block_root: Eth2Digest, slot: Slot, beacon_block_root: Eth2Digest,
blob_kzg_commitments: seq[deneb.KZGCommitment]): bool = blob_kzg_commitments: seq[deneb.KZGCommitment]): bool =

View File

@ -950,14 +950,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.3.0-rc.3/specs/phase0/beacon-chain.md#slashings-balances-updates # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/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.3.0-rc.3/specs/phase0/beacon-chain.md#randao-mixes-updates # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/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)
@ -975,7 +975,7 @@ func compute_historical_root*(state: var ForkyBeaconState): Eth2Digest =
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.3.0-rc.3/specs/phase0/beacon-chain.md#historical-roots-updates # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/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
@ -1018,7 +1018,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.3.0-rc.3/specs/altair/beacon-chain.md#inactivity-scores # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/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 | state: var (altair.BeaconState | bellatrix.BeaconState |
@ -1204,10 +1204,10 @@ proc process_epoch*(
process_inactivity_updates(cfg, state, info) process_inactivity_updates(cfg, state, info)
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/phase0/beacon-chain.md#process_rewards_and_penalties # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/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.3.0-rc.3/specs/phase0/beacon-chain.md#registry-updates # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/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.3.0-rc.5/specs/phase0/beacon-chain.md#slashings # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/specs/phase0/beacon-chain.md#slashings

View File

@ -152,13 +152,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.3.0-rc.3/specs/phase0/beacon-chain.md#get_active_validator_indices # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/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.3.0-rc.4/specs/phase0/beacon-chain.md#get_committee_count_per_slot # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/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,
@ -229,7 +229,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.3.0-rc.4/specs/phase0/beacon-chain.md#get_beacon_committee # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/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) =
@ -292,7 +292,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.3.0-rc.3/specs/phase0/beacon-chain.md#compute_shuffled_index # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/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``).
@ -354,7 +354,7 @@ func compute_proposer_index(state: ForkyBeaconState,
return Opt.some(candidate_index) return Opt.some(candidate_index)
i += 1 i += 1
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/phase0/beacon-chain.md#get_beacon_proposer_index # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/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):
Opt[ValidatorIndex] = Opt[ValidatorIndex] =
@ -403,7 +403,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.3.0-rc.4/specs/phase0/validator.md#aggregation-selection # https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.5/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)