From d9031d97dcd1c5742b5c31e2f59a4f18f726abb2 Mon Sep 17 00:00:00 2001 From: Etan Kissling Date: Thu, 9 Nov 2023 13:54:44 +0100 Subject: [PATCH] rename `_INDEX` generalized index constants to `_GINDEX` (#5583) Rename constants for consistency with upcoming spec adjustment: - https://github.com/ethereum/consensus-specs/pull/3537 --- .../blockchain_dag_light_client.nim | 14 +++++++------- beacon_chain/spec/datatypes/altair.nim | 14 +++++++------- beacon_chain/spec/datatypes/capella.nim | 8 ++++---- beacon_chain/spec/datatypes/deneb.nim | 6 +++--- beacon_chain/spec/forks_light_client.nim | 6 +++--- beacon_chain/spec/light_client_sync.nim | 12 ++++++------ .../test_fixture_light_client_sync_protocol.nim | 4 ++-- 7 files changed, 32 insertions(+), 32 deletions(-) diff --git a/beacon_chain/consensus_object_pools/blockchain_dag_light_client.nim b/beacon_chain/consensus_object_pools/blockchain_dag_light_client.nim index b605f3e4ec..e917f246d9 100644 --- a/beacon_chain/consensus_object_pools/blockchain_dag_light_client.nim +++ b/beacon_chain/consensus_object_pools/blockchain_dag_light_client.nim @@ -222,7 +222,7 @@ proc initLightClientBootstrapForPeriod( forkyBlck.toLightClientHeader(lcDataFork)) dag.lcDataStore.db.putCurrentSyncCommitteeBranch( bid.slot, forkyState.data.build_proof( - altair.CURRENT_SYNC_COMMITTEE_INDEX).get) + altair.CURRENT_SYNC_COMMITTEE_GINDEX).get) else: raiseAssert "Unreachable" res @@ -371,10 +371,10 @@ proc initLightClientUpdateForPeriod( attested_header: forkyBlck.toLightClientHeader(lcDataFork), next_sync_committee: forkyState.data.next_sync_committee, next_sync_committee_branch: - forkyState.data.build_proof(altair.NEXT_SYNC_COMMITTEE_INDEX).get, + forkyState.data.build_proof(altair.NEXT_SYNC_COMMITTEE_GINDEX).get, finality_branch: if finalizedBid.slot != FAR_FUTURE_SLOT: - forkyState.data.build_proof(altair.FINALIZED_ROOT_INDEX).get + forkyState.data.build_proof(altair.FINALIZED_ROOT_GINDEX).get else: default(FinalityBranch))) else: raiseAssert "Unreachable" @@ -442,13 +442,13 @@ proc cacheLightClientData( ## block and state. let cachedData = CachedLightClientData( current_sync_committee_branch: - state.data.build_proof(altair.CURRENT_SYNC_COMMITTEE_INDEX).get, + state.data.build_proof(altair.CURRENT_SYNC_COMMITTEE_GINDEX).get, next_sync_committee_branch: - state.data.build_proof(altair.NEXT_SYNC_COMMITTEE_INDEX).get, + state.data.build_proof(altair.NEXT_SYNC_COMMITTEE_GINDEX).get, finalized_slot: state.data.finalized_checkpoint.epoch.start_slot, finality_branch: - state.data.build_proof(altair.FINALIZED_ROOT_INDEX).get) + state.data.build_proof(altair.FINALIZED_ROOT_GINDEX).get) if dag.lcDataStore.cache.data.hasKeyOrPut(bid, cachedData): doAssert false, "Redundant `cacheLightClientData` call" @@ -956,7 +956,7 @@ proc getLightClientBootstrap( dag.lcDataStore.db.putHeader(header) dag.lcDataStore.db.putCurrentSyncCommitteeBranch( slot, forkyState.data.build_proof( - altair.CURRENT_SYNC_COMMITTEE_INDEX).get) + altair.CURRENT_SYNC_COMMITTEE_GINDEX).get) else: raiseAssert "Unreachable" do: return default(ForkedLightClientBootstrap) diff --git a/beacon_chain/spec/datatypes/altair.nim b/beacon_chain/spec/datatypes/altair.nim index a32c9ae39e..3a7aaf1709 100644 --- a/beacon_chain/spec/datatypes/altair.nim +++ b/beacon_chain/spec/datatypes/altair.nim @@ -59,11 +59,11 @@ const # All of these indices are rooted in `BeaconState`. # The first member (`genesis_time`) is 32, subsequent members +1 each. # If there are ever more than 32 members in `BeaconState`, indices change! - # `FINALIZED_ROOT_INDEX` is one layer deeper, i.e., `52 * 2 + 1`. + # `FINALIZED_ROOT_GINDEX` is one layer deeper, i.e., `52 * 2 + 1`. # https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.3/ssz/merkle-proofs.md - FINALIZED_ROOT_INDEX* = 105.GeneralizedIndex # `finalized_checkpoint` > `root` - CURRENT_SYNC_COMMITTEE_INDEX* = 54.GeneralizedIndex # `current_sync_committee` - NEXT_SYNC_COMMITTEE_INDEX* = 55.GeneralizedIndex # `next_sync_committee` + FINALIZED_ROOT_GINDEX* = 105.GeneralizedIndex # finalized_checkpoint > root + CURRENT_SYNC_COMMITTEE_GINDEX* = 54.GeneralizedIndex # current_sync_committee + NEXT_SYNC_COMMITTEE_GINDEX* = 55.GeneralizedIndex # next_sync_committee # https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.4/specs/altair/beacon-chain.md#inactivity-penalties INACTIVITY_SCORE_BIAS* = 4 @@ -157,13 +157,13 @@ type ### Modified/overloaded FinalityBranch* = - array[log2trunc(FINALIZED_ROOT_INDEX), Eth2Digest] + array[log2trunc(FINALIZED_ROOT_GINDEX), Eth2Digest] CurrentSyncCommitteeBranch* = - array[log2trunc(CURRENT_SYNC_COMMITTEE_INDEX), Eth2Digest] + array[log2trunc(CURRENT_SYNC_COMMITTEE_GINDEX), Eth2Digest] NextSyncCommitteeBranch* = - array[log2trunc(NEXT_SYNC_COMMITTEE_INDEX), Eth2Digest] + array[log2trunc(NEXT_SYNC_COMMITTEE_GINDEX), Eth2Digest] # https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.4/specs/altair/light-client/sync-protocol.md#lightclientheader LightClientHeader* = object diff --git a/beacon_chain/spec/datatypes/capella.nim b/beacon_chain/spec/datatypes/capella.nim index cbfd1461d1..83c89ac99e 100644 --- a/beacon_chain/spec/datatypes/capella.nim +++ b/beacon_chain/spec/datatypes/capella.nim @@ -32,7 +32,7 @@ const # The first member (`randao_reveal`) is 16, subsequent members +1 each. # If there are ever more than 16 members in `BeaconBlockBody`, indices change! # https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.3/ssz/merkle-proofs.md - EXECUTION_PAYLOAD_INDEX* = 25.GeneralizedIndex # `execution_payload` + EXECUTION_PAYLOAD_GINDEX* = 25.GeneralizedIndex # execution_payload type SignedBLSToExecutionChangeList* = @@ -120,7 +120,7 @@ type execution_payload: ExecutionPayload): bool {.gcsafe, raises: [].} ExecutionBranch* = - array[log2trunc(EXECUTION_PAYLOAD_INDEX), Eth2Digest] + array[log2trunc(EXECUTION_PAYLOAD_GINDEX), Eth2Digest] # https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.4/specs/capella/light-client/sync-protocol.md#modified-lightclientheader LightClientHeader* = object @@ -673,8 +673,8 @@ func is_valid_light_client_header*( is_valid_merkle_branch( get_lc_execution_root(header, cfg), header.execution_branch, - log2trunc(EXECUTION_PAYLOAD_INDEX), - get_subtree_index(EXECUTION_PAYLOAD_INDEX), + log2trunc(EXECUTION_PAYLOAD_GINDEX), + get_subtree_index(EXECUTION_PAYLOAD_GINDEX), header.beacon.body_root) # https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.4/specs/capella/light-client/fork.md#upgrading-light-client-data diff --git a/beacon_chain/spec/datatypes/deneb.nim b/beacon_chain/spec/datatypes/deneb.nim index 1fc0b946a0..a89cf0a30e 100644 --- a/beacon_chain/spec/datatypes/deneb.nim +++ b/beacon_chain/spec/datatypes/deneb.nim @@ -574,7 +574,7 @@ func kzg_commitment_inclusion_proof_gindex*( # If there are ever more than 16 members in `BeaconBlockBody`, indices change! # https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.4/ssz/merkle-proofs.md const - # `blob_kzg_commitments` + # blob_kzg_commitments BLOB_KZG_COMMITMENTS_GINDEX = 27.GeneralizedIndex # List + 0 = items, + 1 = len @@ -639,8 +639,8 @@ func is_valid_light_client_header*( is_valid_merkle_branch( get_lc_execution_root(header, cfg), header.execution_branch, - log2trunc(EXECUTION_PAYLOAD_INDEX), - get_subtree_index(EXECUTION_PAYLOAD_INDEX), + log2trunc(EXECUTION_PAYLOAD_GINDEX), + get_subtree_index(EXECUTION_PAYLOAD_GINDEX), header.beacon.body_root) # https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.4/specs/deneb/light-client/fork.md#upgrading-light-client-data diff --git a/beacon_chain/spec/forks_light_client.nim b/beacon_chain/spec/forks_light_client.nim index 863ad09295..090e54a2d3 100644 --- a/beacon_chain/spec/forks_light_client.nim +++ b/beacon_chain/spec/forks_light_client.nim @@ -878,7 +878,7 @@ func toCapellaLightClientHeader( transactions_root: hash_tree_root(payload.transactions), withdrawals_root: hash_tree_root(payload.withdrawals)), execution_branch: blck.message.body.build_proof( - capella.EXECUTION_PAYLOAD_INDEX).get) + capella.EXECUTION_PAYLOAD_GINDEX).get) # https://github.com/ethereum/consensus-specs/blob/v1.4.0-alpha.0/specs/deneb/light-client/full-node.md#modified-block_to_light_client_header func toDenebLightClientHeader( @@ -920,7 +920,7 @@ func toDenebLightClientHeader( transactions_root: hash_tree_root(payload.transactions), withdrawals_root: hash_tree_root(payload.withdrawals)), execution_branch: blck.message.body.build_proof( - capella.EXECUTION_PAYLOAD_INDEX).get) + capella.EXECUTION_PAYLOAD_GINDEX).get) func toDenebLightClientHeader( blck: # `SomeSignedBeaconBlock` doesn't work here (Nim 1.6) @@ -947,7 +947,7 @@ func toDenebLightClientHeader( withdrawals_root: hash_tree_root(payload.withdrawals), excess_blob_gas: payload.excess_blob_gas), execution_branch: blck.message.body.build_proof( - capella.EXECUTION_PAYLOAD_INDEX).get) + capella.EXECUTION_PAYLOAD_GINDEX).get) func toLightClientHeader*( blck: # `SomeSignedBeaconBlock` doesn't work here (Nim 1.6) diff --git a/beacon_chain/spec/light_client_sync.nim b/beacon_chain/spec/light_client_sync.nim index a7282cea9a..0c7b16e537 100644 --- a/beacon_chain/spec/light_client_sync.nim +++ b/beacon_chain/spec/light_client_sync.nim @@ -32,8 +32,8 @@ func initialize_light_client_store*( if not is_valid_merkle_branch( hash_tree_root(bootstrap.current_sync_committee), bootstrap.current_sync_committee_branch, - log2trunc(altair.CURRENT_SYNC_COMMITTEE_INDEX), - get_subtree_index(altair.CURRENT_SYNC_COMMITTEE_INDEX), + log2trunc(altair.CURRENT_SYNC_COMMITTEE_GINDEX), + get_subtree_index(altair.CURRENT_SYNC_COMMITTEE_GINDEX), bootstrap.header.beacon.state_root): return ResultType.err(VerifierError.Invalid) @@ -111,8 +111,8 @@ proc validate_light_client_update*( if not is_valid_merkle_branch( finalized_root, update.finality_branch, - log2trunc(altair.FINALIZED_ROOT_INDEX), - get_subtree_index(altair.FINALIZED_ROOT_INDEX), + log2trunc(altair.FINALIZED_ROOT_GINDEX), + get_subtree_index(altair.FINALIZED_ROOT_GINDEX), update.attested_header.beacon.state_root): return err(VerifierError.Invalid) @@ -130,8 +130,8 @@ proc validate_light_client_update*( if not is_valid_merkle_branch( hash_tree_root(update.next_sync_committee), update.next_sync_committee_branch, - log2trunc(altair.NEXT_SYNC_COMMITTEE_INDEX), - get_subtree_index(altair.NEXT_SYNC_COMMITTEE_INDEX), + log2trunc(altair.NEXT_SYNC_COMMITTEE_GINDEX), + get_subtree_index(altair.NEXT_SYNC_COMMITTEE_GINDEX), update.attested_header.beacon.state_root): return err(VerifierError.Invalid) diff --git a/tests/consensus_spec/altair/test_fixture_light_client_sync_protocol.nim b/tests/consensus_spec/altair/test_fixture_light_client_sync_protocol.nim index 9be0520874..b99400da91 100644 --- a/tests/consensus_spec/altair/test_fixture_light_client_sync_protocol.nim +++ b/tests/consensus_spec/altair/test_fixture_light_client_sync_protocol.nim @@ -288,7 +288,7 @@ proc runTest(storeDataFork: static LightClientDataFork) = template next_sync_committee(): auto = state.next_sync_committee let next_sync_committee_branch = - state.build_proof(altair.NEXT_SYNC_COMMITTEE_INDEX).get + state.build_proof(altair.NEXT_SYNC_COMMITTEE_GINDEX).get # Finality is unchanged finality_header = default(storeDataFork.LightClientHeader) @@ -358,7 +358,7 @@ proc runTest(storeDataFork: static LightClientDataFork) = finalized_header.beacon.hash_tree_root() == state.finalized_checkpoint.root let - finality_branch = state.build_proof(altair.FINALIZED_ROOT_INDEX).get + finality_branch = state.build_proof(altair.FINALIZED_ROOT_GINDEX).get update = storeDataFork.LightClientUpdate( attested_header: attested_header,