Skip to content

Commit

Permalink
rename _INDEX generalized index constants to _GINDEX
Browse files Browse the repository at this point in the history
Rename constants for consistency with upcoming spec adjustment:

- ethereum/consensus-specs#3537
  • Loading branch information
etan-status committed Nov 9, 2023
1 parent 4399361 commit 19e2fc9
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -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)

Expand Down
14 changes: 7 additions & 7 deletions beacon_chain/spec/datatypes/altair.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions beacon_chain/spec/datatypes/capella.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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* =
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions beacon_chain/spec/datatypes/deneb.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions beacon_chain/spec/forks_light_client.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions beacon_chain/spec/light_client_sync.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 19e2fc9

Please sign in to comment.