diff --git a/pysetup/spec_builders/altair.py b/pysetup/spec_builders/altair.py index abd9b56c4..aed5a8a1e 100644 --- a/pysetup/spec_builders/altair.py +++ b/pysetup/spec_builders/altair.py @@ -42,9 +42,9 @@ def compute_merkle_proof(object: SSZObject, @classmethod def hardcoded_ssz_dep_constants(cls) -> Dict[str, str]: return { - 'FINALIZED_ROOT_INDEX': 'GeneralizedIndex(105)', - 'CURRENT_SYNC_COMMITTEE_INDEX': 'GeneralizedIndex(54)', - 'NEXT_SYNC_COMMITTEE_INDEX': 'GeneralizedIndex(55)', + 'FINALIZED_ROOT_GINDEX': 'GeneralizedIndex(105)', + 'CURRENT_SYNC_COMMITTEE_GINDEX': 'GeneralizedIndex(54)', + 'NEXT_SYNC_COMMITTEE_GINDEX': 'GeneralizedIndex(55)', } @classmethod diff --git a/specs/altair/light-client/full-node.md b/specs/altair/light-client/full-node.md index 27651af01..fe92f052f 100644 --- a/specs/altair/light-client/full-node.md +++ b/specs/altair/light-client/full-node.md @@ -75,7 +75,7 @@ def create_light_client_bootstrap(state: BeaconState, return LightClientBootstrap( header=block_to_light_client_header(block), current_sync_committee=state.current_sync_committee, - current_sync_committee_branch=compute_merkle_proof(state, CURRENT_SYNC_COMMITTEE_INDEX), + current_sync_committee_branch=compute_merkle_proof(state, CURRENT_SYNC_COMMITTEE_GINDEX), ) ``` @@ -122,7 +122,7 @@ def create_light_client_update(state: BeaconState, # `next_sync_committee` is only useful if the message is signed by the current sync committee if update_attested_period == update_signature_period: update.next_sync_committee = attested_state.next_sync_committee - update.next_sync_committee_branch = compute_merkle_proof(attested_state, NEXT_SYNC_COMMITTEE_INDEX) + update.next_sync_committee_branch = compute_merkle_proof(attested_state, NEXT_SYNC_COMMITTEE_GINDEX) # Indicate finality whenever possible if finalized_block is not None: @@ -131,7 +131,7 @@ def create_light_client_update(state: BeaconState, assert hash_tree_root(update.finalized_header.beacon) == attested_state.finalized_checkpoint.root else: assert attested_state.finalized_checkpoint.root == Bytes32() - update.finality_branch = compute_merkle_proof(attested_state, FINALIZED_ROOT_INDEX) + update.finality_branch = compute_merkle_proof(attested_state, FINALIZED_ROOT_GINDEX) update.sync_aggregate = block.message.body.sync_aggregate update.signature_slot = block.message.slot diff --git a/specs/altair/light-client/sync-protocol.md b/specs/altair/light-client/sync-protocol.md index baef684c6..ef1f7605a 100644 --- a/specs/altair/light-client/sync-protocol.md +++ b/specs/altair/light-client/sync-protocol.md @@ -60,9 +60,9 @@ Additional documents describe how the light client sync protocol can be used: | Name | Value | | - | - | -| `FINALIZED_ROOT_INDEX` | `get_generalized_index(BeaconState, 'finalized_checkpoint', 'root')` (= 105) | -| `CURRENT_SYNC_COMMITTEE_INDEX` | `get_generalized_index(BeaconState, 'current_sync_committee')` (= 54) | -| `NEXT_SYNC_COMMITTEE_INDEX` | `get_generalized_index(BeaconState, 'next_sync_committee')` (= 55) | +| `FINALIZED_ROOT_GINDEX` | `get_generalized_index(BeaconState, 'finalized_checkpoint', 'root')` (= 105) | +| `CURRENT_SYNC_COMMITTEE_GINDEX` | `get_generalized_index(BeaconState, 'current_sync_committee')` (= 54) | +| `NEXT_SYNC_COMMITTEE_GINDEX` | `get_generalized_index(BeaconState, 'next_sync_committee')` (= 55) | ## Preset @@ -93,7 +93,7 @@ class LightClientBootstrap(Container): header: LightClientHeader # Current sync committee corresponding to `header.beacon.state_root` current_sync_committee: SyncCommittee - current_sync_committee_branch: Vector[Bytes32, floorlog2(CURRENT_SYNC_COMMITTEE_INDEX)] + current_sync_committee_branch: Vector[Bytes32, floorlog2(CURRENT_SYNC_COMMITTEE_GINDEX)] ``` ### `LightClientUpdate` @@ -104,10 +104,10 @@ class LightClientUpdate(Container): attested_header: LightClientHeader # Next sync committee corresponding to `attested_header.beacon.state_root` next_sync_committee: SyncCommittee - next_sync_committee_branch: Vector[Bytes32, floorlog2(NEXT_SYNC_COMMITTEE_INDEX)] + next_sync_committee_branch: Vector[Bytes32, floorlog2(NEXT_SYNC_COMMITTEE_GINDEX)] # Finalized header corresponding to `attested_header.beacon.state_root` finalized_header: LightClientHeader - finality_branch: Vector[Bytes32, floorlog2(FINALIZED_ROOT_INDEX)] + finality_branch: Vector[Bytes32, floorlog2(FINALIZED_ROOT_GINDEX)] # Sync committee aggregate signature sync_aggregate: SyncAggregate # Slot at which the aggregate signature was created (untrusted) @@ -122,7 +122,7 @@ class LightClientFinalityUpdate(Container): attested_header: LightClientHeader # Finalized header corresponding to `attested_header.beacon.state_root` finalized_header: LightClientHeader - finality_branch: Vector[Bytes32, floorlog2(FINALIZED_ROOT_INDEX)] + finality_branch: Vector[Bytes32, floorlog2(FINALIZED_ROOT_GINDEX)] # Sync committee aggregate signature sync_aggregate: SyncAggregate # Slot at which the aggregate signature was created (untrusted) @@ -174,14 +174,14 @@ def is_valid_light_client_header(header: LightClientHeader) -> bool: ```python def is_sync_committee_update(update: LightClientUpdate) -> bool: - return update.next_sync_committee_branch != [Bytes32() for _ in range(floorlog2(NEXT_SYNC_COMMITTEE_INDEX))] + return update.next_sync_committee_branch != [Bytes32() for _ in range(floorlog2(NEXT_SYNC_COMMITTEE_GINDEX))] ``` ### `is_finality_update` ```python def is_finality_update(update: LightClientUpdate) -> bool: - return update.finality_branch != [Bytes32() for _ in range(floorlog2(FINALIZED_ROOT_INDEX))] + return update.finality_branch != [Bytes32() for _ in range(floorlog2(FINALIZED_ROOT_GINDEX))] ``` ### `is_better_update` @@ -286,8 +286,8 @@ def initialize_light_client_store(trusted_block_root: Root, assert is_valid_merkle_branch( leaf=hash_tree_root(bootstrap.current_sync_committee), branch=bootstrap.current_sync_committee_branch, - depth=floorlog2(CURRENT_SYNC_COMMITTEE_INDEX), - index=get_subtree_index(CURRENT_SYNC_COMMITTEE_INDEX), + depth=floorlog2(CURRENT_SYNC_COMMITTEE_GINDEX), + index=get_subtree_index(CURRENT_SYNC_COMMITTEE_GINDEX), root=bootstrap.header.beacon.state_root, ) @@ -358,8 +358,8 @@ def validate_light_client_update(store: LightClientStore, assert is_valid_merkle_branch( leaf=finalized_root, branch=update.finality_branch, - depth=floorlog2(FINALIZED_ROOT_INDEX), - index=get_subtree_index(FINALIZED_ROOT_INDEX), + depth=floorlog2(FINALIZED_ROOT_GINDEX), + index=get_subtree_index(FINALIZED_ROOT_GINDEX), root=update.attested_header.beacon.state_root, ) @@ -373,8 +373,8 @@ def validate_light_client_update(store: LightClientStore, assert is_valid_merkle_branch( leaf=hash_tree_root(update.next_sync_committee), branch=update.next_sync_committee_branch, - depth=floorlog2(NEXT_SYNC_COMMITTEE_INDEX), - index=get_subtree_index(NEXT_SYNC_COMMITTEE_INDEX), + depth=floorlog2(NEXT_SYNC_COMMITTEE_GINDEX), + index=get_subtree_index(NEXT_SYNC_COMMITTEE_GINDEX), root=update.attested_header.beacon.state_root, ) @@ -493,7 +493,7 @@ def process_light_client_finality_update(store: LightClientStore, update = LightClientUpdate( attested_header=finality_update.attested_header, next_sync_committee=SyncCommittee(), - next_sync_committee_branch=[Bytes32() for _ in range(floorlog2(NEXT_SYNC_COMMITTEE_INDEX))], + next_sync_committee_branch=[Bytes32() for _ in range(floorlog2(NEXT_SYNC_COMMITTEE_GINDEX))], finalized_header=finality_update.finalized_header, finality_branch=finality_update.finality_branch, sync_aggregate=finality_update.sync_aggregate, @@ -512,9 +512,9 @@ def process_light_client_optimistic_update(store: LightClientStore, update = LightClientUpdate( attested_header=optimistic_update.attested_header, next_sync_committee=SyncCommittee(), - next_sync_committee_branch=[Bytes32() for _ in range(floorlog2(NEXT_SYNC_COMMITTEE_INDEX))], + next_sync_committee_branch=[Bytes32() for _ in range(floorlog2(NEXT_SYNC_COMMITTEE_GINDEX))], finalized_header=LightClientHeader(), - finality_branch=[Bytes32() for _ in range(floorlog2(FINALIZED_ROOT_INDEX))], + finality_branch=[Bytes32() for _ in range(floorlog2(FINALIZED_ROOT_GINDEX))], sync_aggregate=optimistic_update.sync_aggregate, signature_slot=optimistic_update.signature_slot, ) diff --git a/tests/core/pyspec/eth2spec/test/altair/light_client/test_single_merkle_proof.py b/tests/core/pyspec/eth2spec/test/altair/light_client/test_single_merkle_proof.py index 104d4774c..6418caafd 100644 --- a/tests/core/pyspec/eth2spec/test/altair/light_client/test_single_merkle_proof.py +++ b/tests/core/pyspec/eth2spec/test/altair/light_client/test_single_merkle_proof.py @@ -10,17 +10,17 @@ from eth2spec.test.context import ( @spec_state_test def test_current_sync_committee_merkle_proof(spec, state): yield "object", state - current_sync_committee_branch = spec.compute_merkle_proof(state, spec.CURRENT_SYNC_COMMITTEE_INDEX) + current_sync_committee_branch = spec.compute_merkle_proof(state, spec.CURRENT_SYNC_COMMITTEE_GINDEX) yield "proof", { "leaf": "0x" + state.current_sync_committee.hash_tree_root().hex(), - "leaf_index": spec.CURRENT_SYNC_COMMITTEE_INDEX, + "leaf_index": spec.CURRENT_SYNC_COMMITTEE_GINDEX, "branch": ['0x' + root.hex() for root in current_sync_committee_branch] } assert spec.is_valid_merkle_branch( leaf=state.current_sync_committee.hash_tree_root(), branch=current_sync_committee_branch, - depth=spec.floorlog2(spec.CURRENT_SYNC_COMMITTEE_INDEX), - index=spec.get_subtree_index(spec.CURRENT_SYNC_COMMITTEE_INDEX), + depth=spec.floorlog2(spec.CURRENT_SYNC_COMMITTEE_GINDEX), + index=spec.get_subtree_index(spec.CURRENT_SYNC_COMMITTEE_GINDEX), root=state.hash_tree_root(), ) @@ -30,17 +30,17 @@ def test_current_sync_committee_merkle_proof(spec, state): @spec_state_test def test_next_sync_committee_merkle_proof(spec, state): yield "object", state - next_sync_committee_branch = spec.compute_merkle_proof(state, spec.NEXT_SYNC_COMMITTEE_INDEX) + next_sync_committee_branch = spec.compute_merkle_proof(state, spec.NEXT_SYNC_COMMITTEE_GINDEX) yield "proof", { "leaf": "0x" + state.next_sync_committee.hash_tree_root().hex(), - "leaf_index": spec.NEXT_SYNC_COMMITTEE_INDEX, + "leaf_index": spec.NEXT_SYNC_COMMITTEE_GINDEX, "branch": ['0x' + root.hex() for root in next_sync_committee_branch] } assert spec.is_valid_merkle_branch( leaf=state.next_sync_committee.hash_tree_root(), branch=next_sync_committee_branch, - depth=spec.floorlog2(spec.NEXT_SYNC_COMMITTEE_INDEX), - index=spec.get_subtree_index(spec.NEXT_SYNC_COMMITTEE_INDEX), + depth=spec.floorlog2(spec.NEXT_SYNC_COMMITTEE_GINDEX), + index=spec.get_subtree_index(spec.NEXT_SYNC_COMMITTEE_GINDEX), root=state.hash_tree_root(), ) @@ -50,17 +50,17 @@ def test_next_sync_committee_merkle_proof(spec, state): @spec_state_test def test_finality_root_merkle_proof(spec, state): yield "object", state - finality_branch = spec.compute_merkle_proof(state, spec.FINALIZED_ROOT_INDEX) + finality_branch = spec.compute_merkle_proof(state, spec.FINALIZED_ROOT_GINDEX) yield "proof", { "leaf": "0x" + state.finalized_checkpoint.root.hex(), - "leaf_index": spec.FINALIZED_ROOT_INDEX, + "leaf_index": spec.FINALIZED_ROOT_GINDEX, "branch": ['0x' + root.hex() for root in finality_branch] } assert spec.is_valid_merkle_branch( leaf=state.finalized_checkpoint.root, branch=finality_branch, - depth=spec.floorlog2(spec.FINALIZED_ROOT_INDEX), - index=spec.get_subtree_index(spec.FINALIZED_ROOT_INDEX), + depth=spec.floorlog2(spec.FINALIZED_ROOT_GINDEX), + index=spec.get_subtree_index(spec.FINALIZED_ROOT_GINDEX), root=state.hash_tree_root(), ) diff --git a/tests/core/pyspec/eth2spec/test/altair/light_client/test_sync.py b/tests/core/pyspec/eth2spec/test/altair/light_client/test_sync.py index 4b7951985..067550fa9 100644 --- a/tests/core/pyspec/eth2spec/test/altair/light_client/test_sync.py +++ b/tests/core/pyspec/eth2spec/test/altair/light_client/test_sync.py @@ -164,7 +164,7 @@ def emit_update(test, spec, state, block, attested_state, attested_block, finali if not with_next: data.next_sync_committee = spec.SyncCommittee() data.next_sync_committee_branch = \ - [spec.Bytes32() for _ in range(spec.floorlog2(spec.NEXT_SYNC_COMMITTEE_INDEX))] + [spec.Bytes32() for _ in range(spec.floorlog2(spec.NEXT_SYNC_COMMITTEE_GINDEX))] current_slot = state.slot upgraded = upgrade_lc_update_to_new_spec(d_spec, test.s_spec, data) diff --git a/tests/core/pyspec/eth2spec/test/helpers/light_client.py b/tests/core/pyspec/eth2spec/test/helpers/light_client.py index d068d01f2..64bd7147c 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/light_client.py +++ b/tests/core/pyspec/eth2spec/test/helpers/light_client.py @@ -68,11 +68,11 @@ def create_update(spec, if with_next: update.next_sync_committee = attested_state.next_sync_committee - update.next_sync_committee_branch = spec.compute_merkle_proof(attested_state, spec.NEXT_SYNC_COMMITTEE_INDEX) + update.next_sync_committee_branch = spec.compute_merkle_proof(attested_state, spec.NEXT_SYNC_COMMITTEE_GINDEX) if with_finality: update.finalized_header = spec.block_to_light_client_header(finalized_block) - update.finality_branch = spec.compute_merkle_proof(attested_state, spec.FINALIZED_ROOT_INDEX) + update.finality_branch = spec.compute_merkle_proof(attested_state, spec.FINALIZED_ROOT_GINDEX) update.sync_aggregate, update.signature_slot = get_sync_aggregate( spec, attested_state, num_participants)