From df54470b13112ea853ea0b0bfb5f85d50fa0f413 Mon Sep 17 00:00:00 2001 From: tersec Date: Tue, 29 Nov 2022 08:12:25 +0000 Subject: [PATCH] verify `CAPELLA_FORK_EPOCH == FAR_FUTURE_EPOCH` for supported networks (#4369) --- .../sync_committee_msg_pool.nim | 2 +- beacon_chain/networking/network_metadata.nim | 1 + beacon_chain/rpc/rest_constants.nim | 20 ------------------- beacon_chain/spec/datatypes/altair.nim | 12 +++++------ beacon_chain/spec/datatypes/bellatrix.nim | 2 +- beacon_chain/spec/helpers.nim | 4 ++-- beacon_chain/spec/signatures.nim | 2 +- beacon_chain/spec/state_transition.nim | 2 +- beacon_chain/spec/state_transition_block.nim | 2 +- beacon_chain/spec/state_transition_epoch.nim | 4 ++-- 10 files changed, 16 insertions(+), 35 deletions(-) diff --git a/beacon_chain/consensus_object_pools/sync_committee_msg_pool.nim b/beacon_chain/consensus_object_pools/sync_committee_msg_pool.nim index 633ef6e22..63bcc6661 100644 --- a/beacon_chain/consensus_object_pools/sync_committee_msg_pool.nim +++ b/beacon_chain/consensus_object_pools/sync_committee_msg_pool.nim @@ -294,7 +294,7 @@ proc produceSyncAggregate*( proc isEpochLeadTime*( pool: SyncCommitteeMsgPool, epochsToSyncPeriod: uint64): bool = - # https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/validator.md#sync-committee-subnet-stability + # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/altair/validator.md#sync-committee-subnet-stability # This ensures a uniform distribution without requiring additional state: # (1/4) = 1/4, 4 slots out # (3/4) * (1/3) = 1/4, 3 slots out diff --git a/beacon_chain/networking/network_metadata.nim b/beacon_chain/networking/network_metadata.nim index f699133b0..48d9880a8 100644 --- a/beacon_chain/networking/network_metadata.nim +++ b/beacon_chain/networking/network_metadata.nim @@ -209,6 +209,7 @@ elif const_preset == "mainnet": for network in [ mainnetMetadata, praterMetadata, ropstenMetadata, sepoliaMetadata]: checkForkConsistency(network.cfg) + doAssert network.cfg.CAPELLA_FORK_EPOCH == FAR_FUTURE_EPOCH proc getMetadataForNetwork*( networkName: string): Eth2NetworkMetadata {.raises: [Defect, IOError].} = diff --git a/beacon_chain/rpc/rest_constants.nim b/beacon_chain/rpc/rest_constants.nim index 8799c4ff4..b7f9e512b 100644 --- a/beacon_chain/rpc/rest_constants.nim +++ b/beacon_chain/rpc/rest_constants.nim @@ -27,8 +27,6 @@ const "Beacon node is currently syncing and not serving request on that endpoint" BlockNotFoundError* = "Block header/data has not been found" - BlockProduceError = - "Could not produce the block" EmptyRequestBodyError* = "Empty request's body" InvalidBlockObjectError* = @@ -126,8 +124,6 @@ const "Validator index exceeds maximum supported number of validators" StateNotFoundError* = "Could not get requested state" - SlotNotFoundError = - "Slot number is too far away" SlotNotInNextWallSlotEpochError* = "Requested slot not in next wall-slot epoch" SlotFromThePastError* = @@ -138,8 +134,6 @@ const "Requested epoch is from incorrect fork" ProposerNotFoundError* = "Could not find proposer for the head and slot" - NoHeadForSlotError = - "Cound not find head for slot" EpochOverflowValueError* = "Requesting epoch for which slot would overflow" InvalidPeerStateValueError* = @@ -164,8 +158,6 @@ const "Missing `beacon_block_root` value" InvalidBeaconBlockRootValueError* = "Invalid `beacon_block_root` value" - EpochOutsideSyncCommitteePeriodError = - "Epoch is outside the sync committee period of the state" InvalidSyncCommitteeSignatureMessageError* = "Unable to decode sync committee message(s)" InvalidSyncCommitteeSubscriptionRequestError* = @@ -192,20 +184,8 @@ const "Could not add some keystores" InvalidKeystoreObjects* = "Invalid keystore objects found" - KeystoreAdditionSuccess = - "All keystores has been added" - KeystoreModificationFailure = - "Could not change keystore(s) state" - KeystoreModificationSuccess = - "Keystore(s) state was successfully modified" - KeystoreRemovalSuccess = - "Keystore(s) was successfully removed" - KeystoreRemovalFailure = - "Could not remove keystore(s)" InvalidValidatorPublicKey* = "Invalid validator's public key(s) found" - BadRequestFormatError = - "Bad request format" InvalidAuthorizationError* = "Invalid Authorization Header" PrunedStateError* = diff --git a/beacon_chain/spec/datatypes/altair.nim b/beacon_chain/spec/datatypes/altair.nim index be04f8c29..1871840e7 100644 --- a/beacon_chain/spec/datatypes/altair.nim +++ b/beacon_chain/spec/datatypes/altair.nim @@ -130,7 +130,7 @@ type signature*: ValidatorSig ## Signature by the validator(s) over the block root of `slot` - # https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/validator.md#contributionandproof + # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/altair/validator.md#contributionandproof ContributionAndProof* = object aggregator_index*: uint64 # `ValidatorIndex` after validation contribution*: SyncCommitteeContribution @@ -184,12 +184,12 @@ type signature_slot*: Slot ## Slot at which the aggregate signature was created (untrusted) - # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/light-client/sync-protocol.md#lightclientfinalityupdate + # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/altair/light-client/sync-protocol.md#lightclientfinalityupdate LightClientFinalityUpdate* = object - # The beacon block header that is attested to by the sync committee + # Header attested to by the sync committee attested_header*: BeaconBlockHeader - # The finalized beacon block header attested to by Merkle branch + # Finalized header corresponding to `attested_header.state_root` finalized_header*: BeaconBlockHeader finality_branch*: FinalityBranch @@ -198,9 +198,9 @@ type # Slot at which the aggregate signature was created (untrusted) signature_slot*: Slot - # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/light-client/sync-protocol.md#lightclientoptimisticupdate + # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/altair/light-client/sync-protocol.md#lightclientoptimisticupdate LightClientOptimisticUpdate* = object - # The beacon block header that is attested to by the sync committee + # Header attested to by the sync committee attested_header*: BeaconBlockHeader # Sync committee aggregate signature diff --git a/beacon_chain/spec/datatypes/bellatrix.nim b/beacon_chain/spec/datatypes/bellatrix.nim index 2f5d6e5e7..d8240d0d1 100644 --- a/beacon_chain/spec/datatypes/bellatrix.nim +++ b/beacon_chain/spec/datatypes/bellatrix.nim @@ -90,7 +90,7 @@ type parent_hash*: Eth2Digest total_difficulty*: Eth2Digest # uint256 - # https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/bellatrix/beacon-chain.md#beaconstate + # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/bellatrix/beacon-chain.md#beaconstate BeaconState* = object # Versioning genesis_time*: uint64 diff --git a/beacon_chain/spec/helpers.nim b/beacon_chain/spec/helpers.nim index 9716d5d37..f2a50edfe 100644 --- a/beacon_chain/spec/helpers.nim +++ b/beacon_chain/spec/helpers.nim @@ -220,7 +220,7 @@ template is_finality_update*(update: SomeLightClientUpdate): bool = template is_next_sync_committee_known*(store: LightClientStore): bool = not isZeroMemory(store.next_sync_committee) -# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/light-client/sync-protocol.md#get_safety_threshold +# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/altair/light-client/sync-protocol.md#get_safety_threshold func get_safety_threshold*(store: LightClientStore): uint64 = max( store.previous_max_active_participants, @@ -320,7 +320,7 @@ func contextEpoch*(bootstrap: altair.LightClientBootstrap): Epoch = func contextEpoch*(update: SomeLightClientUpdate): Epoch = update.attested_header.slot.epoch -# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/bellatrix/beacon-chain.md#is_merge_transition_complete +# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/bellatrix/beacon-chain.md#is_merge_transition_complete func is_merge_transition_complete*( state: bellatrix.BeaconState | capella.BeaconState): bool = const defaultExecutionPayloadHeader = diff --git a/beacon_chain/spec/signatures.nim b/beacon_chain/spec/signatures.nim index 620a4e004..9600b0b67 100644 --- a/beacon_chain/spec/signatures.nim +++ b/beacon_chain/spec/signatures.nim @@ -333,7 +333,7 @@ proc get_contribution_and_proof_signature*( blsSign(privkey, signing_root.data) -# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/validator.md#aggregation-selection +# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/altair/validator.md#aggregation-selection func is_sync_committee_aggregator*(signature: ValidatorSig): bool = let signatureDigest = eth2digest(signature.blob) diff --git a/beacon_chain/spec/state_transition.nim b/beacon_chain/spec/state_transition.nim index fd871c667..d955381b0 100644 --- a/beacon_chain/spec/state_transition.nim +++ b/beacon_chain/spec/state_transition.nim @@ -484,7 +484,7 @@ proc makeBeaconBlock*( forkyState.data.latest_execution_payload_header.transactions_root = transactions_root.get - # https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/bellatrix/beacon-chain.md#beaconblockbody + # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/bellatrix/beacon-chain.md#beaconblockbody # Effectively hash_tree_root(ExecutionPayload) with the beacon block # body, with the execution payload replaced by the execution payload # header. htr(payload) == htr(payload header), so substitute. diff --git a/beacon_chain/spec/state_transition_block.nim b/beacon_chain/spec/state_transition_block.nim index 5c0f2b5ff..e6c2c1c4e 100644 --- a/beacon_chain/spec/state_transition_block.nim +++ b/beacon_chain/spec/state_transition_block.nim @@ -430,7 +430,7 @@ proc process_bls_to_execution_change*( ok() # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/phase0/beacon-chain.md#operations -# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/capella/beacon-chain.md#modified-process_operations +# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/capella/beacon-chain.md#modified-process_operations proc process_operations(cfg: RuntimeConfig, state: var ForkyBeaconState, body: SomeForkyBeaconBlockBody, diff --git a/beacon_chain/spec/state_transition_epoch.nim b/beacon_chain/spec/state_transition_epoch.nim index 931a32076..c20077004 100644 --- a/beacon_chain/spec/state_transition_epoch.nim +++ b/beacon_chain/spec/state_transition_epoch.nim @@ -723,7 +723,7 @@ iterator get_inactivity_penalty_deltas*( state.inactivity_scores[vidx] yield (vidx, Gwei(penalty_numerator div penalty_denominator)) -# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/bellatrix/beacon-chain.md#modified-get_inactivity_penalty_deltas +# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/bellatrix/beacon-chain.md#modified-get_inactivity_penalty_deltas iterator get_inactivity_penalty_deltas*( cfg: RuntimeConfig, state: bellatrix.BeaconState | capella.BeaconState, info: altair.EpochInfo): (ValidatorIndex, Gwei) = @@ -879,7 +879,7 @@ func get_adjusted_total_slashing_balance*( # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/specs/phase0/beacon-chain.md#slashings # https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.1/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.3.0-alpha.1/specs/bellatrix/beacon-chain.md#slashings func slashing_penalty_applies*(validator: Validator, epoch: Epoch): bool = validator.slashed and epoch + EPOCHS_PER_SLASHINGS_VECTOR div 2 == validator.withdrawable_epoch