switch 3 modules in beacon_chain/spec/ from eip4844 to deneb (#4651)

This commit is contained in:
tersec 2023-02-22 14:10:00 +01:00 committed by GitHub
parent 1a0b2daa0a
commit 1dd07d5def
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 46 deletions

View File

@ -132,7 +132,7 @@ func initiate_validator_exit*(
ok()
from ./datatypes/eip4844 import BeaconState
from ./datatypes/deneb import BeaconState
# 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
@ -146,7 +146,7 @@ func get_slashing_penalty*(state: ForkyBeaconState,
elif state is altair.BeaconState:
validator_effective_balance div MIN_SLASHING_PENALTY_QUOTIENT_ALTAIR
elif state is bellatrix.BeaconState or state is capella.BeaconState or
state is eip4844.BeaconState:
state is deneb.BeaconState:
validator_effective_balance div MIN_SLASHING_PENALTY_QUOTIENT_BELLATRIX
else:
{.fatal: "invalid BeaconState type".}
@ -164,7 +164,7 @@ func get_proposer_reward(state: ForkyBeaconState, whistleblower_reward: Gwei): G
when state is phase0.BeaconState:
whistleblower_reward div PROPOSER_REWARD_QUOTIENT
elif state is altair.BeaconState or state is bellatrix.BeaconState or
state is capella.BeaconState or state is eip4844.BeaconState:
state is capella.BeaconState or state is deneb.BeaconState:
whistleblower_reward * PROPOSER_WEIGHT div WEIGHT_DENOMINATOR
else:
{.fatal: "invalid BeaconState type".}
@ -361,15 +361,15 @@ func get_initial_beacon_block*(state: bellatrix.HashedBeaconState):
bellatrix.TrustedSignedBeaconBlock(
message: message, root: hash_tree_root(message))
func get_initial_beacon_block*(state: eip4844.HashedBeaconState):
eip4844.TrustedSignedBeaconBlock =
func get_initial_beacon_block*(state: deneb.HashedBeaconState):
deneb.TrustedSignedBeaconBlock =
# The genesis block is implicitly trusted
let message = eip4844.TrustedBeaconBlock(
let message = deneb.TrustedBeaconBlock(
slot: state.data.slot,
state_root: state.root)
# parent_root, randao_reveal, eth1_data, signature, and body automatically
# initialized to default values.
eip4844.TrustedSignedBeaconBlock(
deneb.TrustedSignedBeaconBlock(
message: message, root: hash_tree_root(message))
# https://github.com/ethereum/consensus-specs/blob/v1.1.7/specs/merge/beacon-chain.md#testing
@ -593,7 +593,7 @@ func check_attestation_index*(
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/altair/beacon-chain.md#get_attestation_participation_flag_indices
func get_attestation_participation_flag_indices(
state: altair.BeaconState | bellatrix.BeaconState | capella.BeaconState |
eip4844.BeaconState,
deneb.BeaconState,
data: AttestationData, inclusion_delay: uint64): seq[int] =
## Return the flag indices that are satisfied by an attestation.
let justified_checkpoint =
@ -653,7 +653,7 @@ func get_base_reward_per_increment*(
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/altair/beacon-chain.md#get_base_reward
func get_base_reward(
state: altair.BeaconState | bellatrix.BeaconState | capella.BeaconState |
eip4844.BeaconState,
deneb.BeaconState,
index: ValidatorIndex, base_reward_per_increment: Gwei): Gwei =
## Return the base reward for the validator defined by ``index`` with respect
## to the current ``state``.
@ -698,7 +698,7 @@ proc check_attestation*(
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.2/specs/capella/beacon-chain.md#new-process_bls_to_execution_change
proc check_bls_to_execution_change*(
genesisFork: Fork, state: capella.BeaconState | eip4844.BeaconState,
genesisFork: Fork, state: capella.BeaconState | deneb.BeaconState,
signed_address_change: SignedBLSToExecutionChange, flags: UpdateFlags):
Result[void, cstring] =
let address_change = signed_address_change.message
@ -793,7 +793,7 @@ proc process_attestation*(
else:
addPendingAttestation(state.previous_epoch_attestations)
elif state is altair.BeaconState or state is bellatrix.BeaconState or
state is capella.BeaconState or state is eip4844.BeaconState:
state is capella.BeaconState or state is deneb.BeaconState:
doAssert base_reward_per_increment > 0.Gwei
if attestation.data.target.epoch == get_current_epoch(state):
updateParticipationFlags(state.current_epoch_participation)
@ -807,7 +807,7 @@ proc process_attestation*(
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/altair/beacon-chain.md#get_next_sync_committee_indices
func get_next_sync_committee_keys(
state: altair.BeaconState | bellatrix.BeaconState | capella.BeaconState |
eip4844.BeaconState):
deneb.BeaconState):
array[SYNC_COMMITTEE_SIZE, ValidatorPubKey] =
## Return the sequence of sync committee indices, with possible duplicates,
## for the next sync committee.
@ -867,7 +867,7 @@ func is_partially_withdrawable_validator(
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.2/specs/capella/beacon-chain.md#new-get_expected_withdrawals
func get_expected_withdrawals*(
state: capella.BeaconState | eip4844.BeaconState): seq[Withdrawal] =
state: capella.BeaconState | deneb.BeaconState): seq[Withdrawal] =
let
epoch = get_current_epoch(state)
num_validators = lenu64(state.validators)
@ -904,7 +904,7 @@ func get_expected_withdrawals*(
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/altair/beacon-chain.md#get_next_sync_committee
func get_next_sync_committee*(
state: altair.BeaconState | bellatrix.BeaconState | capella.BeaconState |
eip4844.BeaconState):
deneb.BeaconState):
SyncCommittee =
## Return the *next* sync committee for a given ``state``.
var res: SyncCommittee
@ -1145,10 +1145,10 @@ func upgrade_to_capella*(cfg: RuntimeConfig, pre: bellatrix.BeaconState):
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.0/specs/eip4844/fork.md#upgrading-the-state
func upgrade_to_eip4844*(cfg: RuntimeConfig, pre: capella.BeaconState):
ref eip4844.BeaconState =
ref deneb.BeaconState =
let
epoch = get_current_epoch(pre)
latest_execution_payload_header = eip4844.ExecutionPayloadHeader(
latest_execution_payload_header = deneb.ExecutionPayloadHeader(
parent_hash: pre.latest_execution_payload_header.parent_hash,
fee_recipient: pre.latest_execution_payload_header.fee_recipient,
state_root: pre.latest_execution_payload_header.state_root,
@ -1167,7 +1167,7 @@ func upgrade_to_eip4844*(cfg: RuntimeConfig, pre: capella.BeaconState):
withdrawals_root: pre.latest_execution_payload_header.withdrawals_root
)
(ref eip4844.BeaconState)(
(ref deneb.BeaconState)(
# Versioning
genesis_time: pre.genesis_time,
genesis_validators_root: pre.genesis_validators_root,
@ -1259,7 +1259,7 @@ func latest_block_root*(state: ForkedHashedBeaconState): Eth2Digest =
func get_sync_committee_cache*(
state: altair.BeaconState | bellatrix.BeaconState | capella.BeaconState |
eip4844.BeaconState,
deneb.BeaconState,
cache: var StateCache): SyncCommitteeCache =
let period = state.slot.sync_committee_period()

View File

@ -16,7 +16,7 @@ import
eth/eip1559, eth/common/[eth_types, eth_types_rlp],
eth/rlp, eth/trie/[db, hexary],
# Internal
./datatypes/[phase0, altair, bellatrix, capella, eip4844],
./datatypes/[phase0, altair, bellatrix, capella, deneb],
"."/[eth2_merkleization, forks, ssz_codec]
# TODO although eth2_merkleization already exports ssz_codec, *sometimes* code
@ -333,7 +333,7 @@ func contextEpoch*(update: SomeForkyLightClientUpdate): Epoch =
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/bellatrix/beacon-chain.md#is_merge_transition_complete
func is_merge_transition_complete*(
state: bellatrix.BeaconState | capella.BeaconState | eip4844.BeaconState): bool =
state: bellatrix.BeaconState | capella.BeaconState | deneb.BeaconState): bool =
const defaultExecutionPayloadHeader =
default(typeof(state.latest_execution_payload_header))
state.latest_execution_payload_header != defaultExecutionPayloadHeader
@ -349,26 +349,26 @@ func is_execution_block*(blck: SomeForkyBeaconBlock): bool =
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/bellatrix/beacon-chain.md#is_merge_transition_block
func is_merge_transition_block(
state: bellatrix.BeaconState | capella.BeaconState | eip4844.BeaconState,
state: bellatrix.BeaconState | capella.BeaconState | deneb.BeaconState,
body: bellatrix.BeaconBlockBody | bellatrix.TrustedBeaconBlockBody |
bellatrix.SigVerifiedBeaconBlockBody |
capella.BeaconBlockBody | capella.TrustedBeaconBlockBody |
capella.SigVerifiedBeaconBlockBody |
eip4844.BeaconBlockBody | eip4844.TrustedBeaconBlockBody |
eip4844.SigVerifiedBeaconBlockBody): bool =
deneb.BeaconBlockBody | deneb.TrustedBeaconBlockBody |
deneb.SigVerifiedBeaconBlockBody): bool =
const defaultExecutionPayload = default(typeof(body.execution_payload))
not is_merge_transition_complete(state) and
body.execution_payload != defaultExecutionPayload
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/bellatrix/beacon-chain.md#is_execution_enabled
func is_execution_enabled*(
state: bellatrix.BeaconState | capella.BeaconState | eip4844.BeaconState,
state: bellatrix.BeaconState | capella.BeaconState | deneb.BeaconState,
body: bellatrix.BeaconBlockBody | bellatrix.TrustedBeaconBlockBody |
bellatrix.SigVerifiedBeaconBlockBody |
capella.BeaconBlockBody | capella.TrustedBeaconBlockBody |
capella.SigVerifiedBeaconBlockBody |
eip4844.BeaconBlockBody | eip4844.TrustedBeaconBlockBody |
eip4844.SigVerifiedBeaconBlockBody): bool =
deneb.BeaconBlockBody | deneb.TrustedBeaconBlockBody |
deneb.SigVerifiedBeaconBlockBody): bool =
is_merge_transition_block(state, body) or is_merge_transition_complete(state)
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/bellatrix/beacon-chain.md#compute_timestamp_at_slot
@ -400,7 +400,7 @@ func toExecutionWithdrawal*(
# https://eips.ethereum.org/EIPS/eip-4895
proc computeWithdrawalsTrieRoot*(
payload: capella.ExecutionPayload | eip4844.ExecutionPayload): Hash256 =
payload: capella.ExecutionPayload | deneb.ExecutionPayload): Hash256 =
if payload.withdrawals.len == 0:
return EMPTY_ROOT_HASH

View File

@ -266,7 +266,7 @@ func findValidatorIndex*(state: ForkyBeaconState, pubkey: ValidatorPubKey):
if state.validators.asSeq[vidx].pubkey == pubkey:
return Opt[ValidatorIndex].ok(vidx)
from ./datatypes/eip4844 import
from ./datatypes/deneb import
BLOB_TX_TYPE, BeaconState, KZGCommitment, VersionedHash
proc process_deposit*(cfg: RuntimeConfig,
@ -308,7 +308,7 @@ proc process_deposit*(cfg: RuntimeConfig,
raiseAssert "adding validator succeeded, so should balances"
when state is altair.BeaconState or state is bellatrix.BeaconState or
state is capella.BeaconState or state is eip4844.BeaconState:
state is capella.BeaconState or state is deneb.BeaconState:
if not state.previous_epoch_participation.add(ParticipationFlags(0)):
return err("process_deposit: too many validators (previous_epoch_participation)")
if not state.current_epoch_participation.add(ParticipationFlags(0)):
@ -388,7 +388,7 @@ proc process_voluntary_exit*(
ok()
proc process_bls_to_execution_change*(
cfg: RuntimeConfig, state: var (capella.BeaconState | eip4844.BeaconState),
cfg: RuntimeConfig, state: var (capella.BeaconState | deneb.BeaconState),
signed_address_change: SignedBLSToExecutionChange): Result[void, cstring] =
? check_bls_to_execution_change(
cfg.genesisFork, state, signed_address_change, {})
@ -458,7 +458,7 @@ func get_proposer_reward*(participant_reward: Gwei): Gwei =
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.3/specs/altair/beacon-chain.md#sync-committee-processing
proc process_sync_aggregate*(
state: var (altair.BeaconState | bellatrix.BeaconState |
capella.BeaconState | eip4844.BeaconState),
capella.BeaconState | deneb.BeaconState),
sync_aggregate: SomeSyncAggregate, total_active_balance: Gwei,
cache: var StateCache):
Result[void, cstring] =
@ -597,8 +597,8 @@ proc process_execution_payload*(
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.2/specs/eip4844/beacon-chain.md#process_execution_payload
proc process_execution_payload*(
state: var eip4844.BeaconState, payload: eip4844.ExecutionPayload,
notify_new_payload: eip4844.ExecutePayload): Result[void, cstring] =
state: var deneb.BeaconState, payload: deneb.ExecutionPayload,
notify_new_payload: deneb.ExecutePayload): Result[void, cstring] =
## Verify consistency of the parent hash with respect to the previous
## execution payload header
if is_merge_transition_complete(state):
@ -619,7 +619,7 @@ proc process_execution_payload*(
return err("process_execution_payload: execution payload invalid")
# Cache execution payload header
state.latest_execution_payload_header = eip4844.ExecutionPayloadHeader(
state.latest_execution_payload_header = deneb.ExecutionPayloadHeader(
parent_hash: payload.parent_hash,
fee_recipient: payload.fee_recipient,
state_root: payload.state_root,
@ -641,8 +641,8 @@ proc process_execution_payload*(
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.2/specs/capella/beacon-chain.md#new-process_withdrawals
func process_withdrawals*(
state: var (capella.BeaconState | eip4844.BeaconState),
payload: capella.ExecutionPayload | eip4844.ExecutionPayload):
state: var (capella.BeaconState | deneb.BeaconState),
payload: capella.ExecutionPayload | deneb.ExecutionPayload):
Result[void, cstring] =
let expected_withdrawals = get_expected_withdrawals(state)
@ -712,7 +712,7 @@ func tx_peek_blob_versioned_hashes(opaque_tx: Transaction):
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.2/specs/eip4844/beacon-chain.md#kzg_commitment_to_versioned_hash
func kzg_commitment_to_versioned_hash(
kzg_commitment: eip4844.KZGCommitment): VersionedHash =
kzg_commitment: deneb.KZGCommitment): VersionedHash =
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.2/specs/eip4844/beacon-chain.md#blob
const VERSIONED_HASH_VERSION_KZG = 0x01'u8
@ -724,7 +724,7 @@ func kzg_commitment_to_versioned_hash(
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.2/specs/eip4844/beacon-chain.md#verify_kzg_commitments_against_transactions
func verify_kzg_commitments_against_transactions*(
transactions: seq[Transaction],
kzg_commitments: seq[eip4844.KZGCommitment]): bool =
kzg_commitments: seq[deneb.KZGCommitment]): bool =
var all_versioned_hashes: seq[VersionedHash]
for tx in transactions:
if tx[0] == BLOB_TX_TYPE:
@ -740,9 +740,9 @@ func verify_kzg_commitments_against_transactions*(
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.2/specs/eip4844/beacon-chain.md#blob-kzg-commitments
func process_blob_kzg_commitments(
state: var eip4844.BeaconState,
body: eip4844.BeaconBlockBody | eip4844.TrustedBeaconBlockBody |
eip4844.SigVerifiedBeaconBlockBody):
state: var deneb.BeaconState,
body: deneb.BeaconBlockBody | deneb.TrustedBeaconBlockBody |
deneb.SigVerifiedBeaconBlockBody):
Result[void, cstring] =
if verify_kzg_commitments_against_transactions(
body.execution_payload.transactions.asSeq,
@ -753,8 +753,8 @@ func process_blob_kzg_commitments(
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.2/specs/eip4844/beacon-chain.md#validate_blobs_sidecar
proc validate_blobs_sidecar*(slot: Slot, root: Eth2Digest,
expected_kzg_commitments: seq[eip4844.KZGCommitment],
blobs_sidecar: eip4844.BlobsSidecar):
expected_kzg_commitments: seq[deneb.KZGCommitment],
blobs_sidecar: deneb.BlobsSidecar):
Result[void, cstring] =
if slot != blobs_sidecar.beacon_block_slot:
return err("validate_blobs_sidecar: different slot in block and sidecar")
@ -774,7 +774,7 @@ proc validate_blobs_sidecar*(slot: Slot, root: Eth2Digest,
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-rc.2/specs/eip4844/fork-choice.md#is_data_available
func is_data_available(
slot: Slot, beacon_block_root: Eth2Digest,
blob_kzg_commitments: seq[eip4844.KZGCommitment]): bool =
blob_kzg_commitments: seq[deneb.KZGCommitment]): bool =
discard $eip4844ImplementationMissing & ": state_transition_block.nim:is_data_available"
true
@ -895,10 +895,10 @@ proc process_block*(
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.2/specs/eip4844/beacon-chain.md#block-processing
# TODO workaround for https://github.com/nim-lang/Nim/issues/18095
type SomeEIP4844Block =
eip4844.BeaconBlock | eip4844.SigVerifiedBeaconBlock | eip4844.TrustedBeaconBlock
deneb.BeaconBlock | deneb.SigVerifiedBeaconBlock | deneb.TrustedBeaconBlock
proc process_block*(
cfg: RuntimeConfig,
state: var eip4844.BeaconState, blck: SomeEIP4844Block,
state: var deneb.BeaconState, blck: SomeEIP4844Block,
flags: UpdateFlags, cache: var StateCache): Result[void, cstring]=
## When there's a new block, we need to verify that the block is sane and
## update the state accordingly - the state is left in an unknown state when