Skip to content

Commit 868a600

Browse files
authored
Merge pull request #3537 from etan-status/lc-gindexname
Rename `_INDEX` generalized index constants to `_GINDEX`
2 parents 1509b22 + d9e53cb commit 868a600

File tree

6 files changed

+39
-39
lines changed

6 files changed

+39
-39
lines changed

pysetup/spec_builders/altair.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ def compute_merkle_proof(object: SSZObject,
4242
@classmethod
4343
def hardcoded_ssz_dep_constants(cls) -> Dict[str, str]:
4444
return {
45-
'FINALIZED_ROOT_INDEX': 'GeneralizedIndex(105)',
46-
'CURRENT_SYNC_COMMITTEE_INDEX': 'GeneralizedIndex(54)',
47-
'NEXT_SYNC_COMMITTEE_INDEX': 'GeneralizedIndex(55)',
45+
'FINALIZED_ROOT_GINDEX': 'GeneralizedIndex(105)',
46+
'CURRENT_SYNC_COMMITTEE_GINDEX': 'GeneralizedIndex(54)',
47+
'NEXT_SYNC_COMMITTEE_GINDEX': 'GeneralizedIndex(55)',
4848
}
4949

5050
@classmethod

specs/altair/light-client/full-node.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def create_light_client_bootstrap(state: BeaconState,
7575
return LightClientBootstrap(
7676
header=block_to_light_client_header(block),
7777
current_sync_committee=state.current_sync_committee,
78-
current_sync_committee_branch=compute_merkle_proof(state, CURRENT_SYNC_COMMITTEE_INDEX),
78+
current_sync_committee_branch=compute_merkle_proof(state, CURRENT_SYNC_COMMITTEE_GINDEX),
7979
)
8080
```
8181

@@ -122,7 +122,7 @@ def create_light_client_update(state: BeaconState,
122122
# `next_sync_committee` is only useful if the message is signed by the current sync committee
123123
if update_attested_period == update_signature_period:
124124
update.next_sync_committee = attested_state.next_sync_committee
125-
update.next_sync_committee_branch = compute_merkle_proof(attested_state, NEXT_SYNC_COMMITTEE_INDEX)
125+
update.next_sync_committee_branch = compute_merkle_proof(attested_state, NEXT_SYNC_COMMITTEE_GINDEX)
126126

127127
# Indicate finality whenever possible
128128
if finalized_block is not None:
@@ -131,7 +131,7 @@ def create_light_client_update(state: BeaconState,
131131
assert hash_tree_root(update.finalized_header.beacon) == attested_state.finalized_checkpoint.root
132132
else:
133133
assert attested_state.finalized_checkpoint.root == Bytes32()
134-
update.finality_branch = compute_merkle_proof(attested_state, FINALIZED_ROOT_INDEX)
134+
update.finality_branch = compute_merkle_proof(attested_state, FINALIZED_ROOT_GINDEX)
135135

136136
update.sync_aggregate = block.message.body.sync_aggregate
137137
update.signature_slot = block.message.slot

specs/altair/light-client/sync-protocol.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ Additional documents describe how the light client sync protocol can be used:
6060

6161
| Name | Value |
6262
| - | - |
63-
| `FINALIZED_ROOT_INDEX` | `get_generalized_index(BeaconState, 'finalized_checkpoint', 'root')` (= 105) |
64-
| `CURRENT_SYNC_COMMITTEE_INDEX` | `get_generalized_index(BeaconState, 'current_sync_committee')` (= 54) |
65-
| `NEXT_SYNC_COMMITTEE_INDEX` | `get_generalized_index(BeaconState, 'next_sync_committee')` (= 55) |
63+
| `FINALIZED_ROOT_GINDEX` | `get_generalized_index(BeaconState, 'finalized_checkpoint', 'root')` (= 105) |
64+
| `CURRENT_SYNC_COMMITTEE_GINDEX` | `get_generalized_index(BeaconState, 'current_sync_committee')` (= 54) |
65+
| `NEXT_SYNC_COMMITTEE_GINDEX` | `get_generalized_index(BeaconState, 'next_sync_committee')` (= 55) |
6666

6767
## Preset
6868

@@ -93,7 +93,7 @@ class LightClientBootstrap(Container):
9393
header: LightClientHeader
9494
# Current sync committee corresponding to `header.beacon.state_root`
9595
current_sync_committee: SyncCommittee
96-
current_sync_committee_branch: Vector[Bytes32, floorlog2(CURRENT_SYNC_COMMITTEE_INDEX)]
96+
current_sync_committee_branch: Vector[Bytes32, floorlog2(CURRENT_SYNC_COMMITTEE_GINDEX)]
9797
```
9898

9999
### `LightClientUpdate`
@@ -104,10 +104,10 @@ class LightClientUpdate(Container):
104104
attested_header: LightClientHeader
105105
# Next sync committee corresponding to `attested_header.beacon.state_root`
106106
next_sync_committee: SyncCommittee
107-
next_sync_committee_branch: Vector[Bytes32, floorlog2(NEXT_SYNC_COMMITTEE_INDEX)]
107+
next_sync_committee_branch: Vector[Bytes32, floorlog2(NEXT_SYNC_COMMITTEE_GINDEX)]
108108
# Finalized header corresponding to `attested_header.beacon.state_root`
109109
finalized_header: LightClientHeader
110-
finality_branch: Vector[Bytes32, floorlog2(FINALIZED_ROOT_INDEX)]
110+
finality_branch: Vector[Bytes32, floorlog2(FINALIZED_ROOT_GINDEX)]
111111
# Sync committee aggregate signature
112112
sync_aggregate: SyncAggregate
113113
# Slot at which the aggregate signature was created (untrusted)
@@ -122,7 +122,7 @@ class LightClientFinalityUpdate(Container):
122122
attested_header: LightClientHeader
123123
# Finalized header corresponding to `attested_header.beacon.state_root`
124124
finalized_header: LightClientHeader
125-
finality_branch: Vector[Bytes32, floorlog2(FINALIZED_ROOT_INDEX)]
125+
finality_branch: Vector[Bytes32, floorlog2(FINALIZED_ROOT_GINDEX)]
126126
# Sync committee aggregate signature
127127
sync_aggregate: SyncAggregate
128128
# Slot at which the aggregate signature was created (untrusted)
@@ -174,14 +174,14 @@ def is_valid_light_client_header(header: LightClientHeader) -> bool:
174174

175175
```python
176176
def is_sync_committee_update(update: LightClientUpdate) -> bool:
177-
return update.next_sync_committee_branch != [Bytes32() for _ in range(floorlog2(NEXT_SYNC_COMMITTEE_INDEX))]
177+
return update.next_sync_committee_branch != [Bytes32() for _ in range(floorlog2(NEXT_SYNC_COMMITTEE_GINDEX))]
178178
```
179179

180180
### `is_finality_update`
181181

182182
```python
183183
def is_finality_update(update: LightClientUpdate) -> bool:
184-
return update.finality_branch != [Bytes32() for _ in range(floorlog2(FINALIZED_ROOT_INDEX))]
184+
return update.finality_branch != [Bytes32() for _ in range(floorlog2(FINALIZED_ROOT_GINDEX))]
185185
```
186186

187187
### `is_better_update`
@@ -286,8 +286,8 @@ def initialize_light_client_store(trusted_block_root: Root,
286286
assert is_valid_merkle_branch(
287287
leaf=hash_tree_root(bootstrap.current_sync_committee),
288288
branch=bootstrap.current_sync_committee_branch,
289-
depth=floorlog2(CURRENT_SYNC_COMMITTEE_INDEX),
290-
index=get_subtree_index(CURRENT_SYNC_COMMITTEE_INDEX),
289+
depth=floorlog2(CURRENT_SYNC_COMMITTEE_GINDEX),
290+
index=get_subtree_index(CURRENT_SYNC_COMMITTEE_GINDEX),
291291
root=bootstrap.header.beacon.state_root,
292292
)
293293

@@ -358,8 +358,8 @@ def validate_light_client_update(store: LightClientStore,
358358
assert is_valid_merkle_branch(
359359
leaf=finalized_root,
360360
branch=update.finality_branch,
361-
depth=floorlog2(FINALIZED_ROOT_INDEX),
362-
index=get_subtree_index(FINALIZED_ROOT_INDEX),
361+
depth=floorlog2(FINALIZED_ROOT_GINDEX),
362+
index=get_subtree_index(FINALIZED_ROOT_GINDEX),
363363
root=update.attested_header.beacon.state_root,
364364
)
365365

@@ -373,8 +373,8 @@ def validate_light_client_update(store: LightClientStore,
373373
assert is_valid_merkle_branch(
374374
leaf=hash_tree_root(update.next_sync_committee),
375375
branch=update.next_sync_committee_branch,
376-
depth=floorlog2(NEXT_SYNC_COMMITTEE_INDEX),
377-
index=get_subtree_index(NEXT_SYNC_COMMITTEE_INDEX),
376+
depth=floorlog2(NEXT_SYNC_COMMITTEE_GINDEX),
377+
index=get_subtree_index(NEXT_SYNC_COMMITTEE_GINDEX),
378378
root=update.attested_header.beacon.state_root,
379379
)
380380

@@ -493,7 +493,7 @@ def process_light_client_finality_update(store: LightClientStore,
493493
update = LightClientUpdate(
494494
attested_header=finality_update.attested_header,
495495
next_sync_committee=SyncCommittee(),
496-
next_sync_committee_branch=[Bytes32() for _ in range(floorlog2(NEXT_SYNC_COMMITTEE_INDEX))],
496+
next_sync_committee_branch=[Bytes32() for _ in range(floorlog2(NEXT_SYNC_COMMITTEE_GINDEX))],
497497
finalized_header=finality_update.finalized_header,
498498
finality_branch=finality_update.finality_branch,
499499
sync_aggregate=finality_update.sync_aggregate,
@@ -512,9 +512,9 @@ def process_light_client_optimistic_update(store: LightClientStore,
512512
update = LightClientUpdate(
513513
attested_header=optimistic_update.attested_header,
514514
next_sync_committee=SyncCommittee(),
515-
next_sync_committee_branch=[Bytes32() for _ in range(floorlog2(NEXT_SYNC_COMMITTEE_INDEX))],
515+
next_sync_committee_branch=[Bytes32() for _ in range(floorlog2(NEXT_SYNC_COMMITTEE_GINDEX))],
516516
finalized_header=LightClientHeader(),
517-
finality_branch=[Bytes32() for _ in range(floorlog2(FINALIZED_ROOT_INDEX))],
517+
finality_branch=[Bytes32() for _ in range(floorlog2(FINALIZED_ROOT_GINDEX))],
518518
sync_aggregate=optimistic_update.sync_aggregate,
519519
signature_slot=optimistic_update.signature_slot,
520520
)

tests/core/pyspec/eth2spec/test/altair/light_client/test_single_merkle_proof.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010
@spec_state_test
1111
def test_current_sync_committee_merkle_proof(spec, state):
1212
yield "object", state
13-
current_sync_committee_branch = spec.compute_merkle_proof(state, spec.CURRENT_SYNC_COMMITTEE_INDEX)
13+
current_sync_committee_branch = spec.compute_merkle_proof(state, spec.CURRENT_SYNC_COMMITTEE_GINDEX)
1414
yield "proof", {
1515
"leaf": "0x" + state.current_sync_committee.hash_tree_root().hex(),
16-
"leaf_index": spec.CURRENT_SYNC_COMMITTEE_INDEX,
16+
"leaf_index": spec.CURRENT_SYNC_COMMITTEE_GINDEX,
1717
"branch": ['0x' + root.hex() for root in current_sync_committee_branch]
1818
}
1919
assert spec.is_valid_merkle_branch(
2020
leaf=state.current_sync_committee.hash_tree_root(),
2121
branch=current_sync_committee_branch,
22-
depth=spec.floorlog2(spec.CURRENT_SYNC_COMMITTEE_INDEX),
23-
index=spec.get_subtree_index(spec.CURRENT_SYNC_COMMITTEE_INDEX),
22+
depth=spec.floorlog2(spec.CURRENT_SYNC_COMMITTEE_GINDEX),
23+
index=spec.get_subtree_index(spec.CURRENT_SYNC_COMMITTEE_GINDEX),
2424
root=state.hash_tree_root(),
2525
)
2626

@@ -30,17 +30,17 @@ def test_current_sync_committee_merkle_proof(spec, state):
3030
@spec_state_test
3131
def test_next_sync_committee_merkle_proof(spec, state):
3232
yield "object", state
33-
next_sync_committee_branch = spec.compute_merkle_proof(state, spec.NEXT_SYNC_COMMITTEE_INDEX)
33+
next_sync_committee_branch = spec.compute_merkle_proof(state, spec.NEXT_SYNC_COMMITTEE_GINDEX)
3434
yield "proof", {
3535
"leaf": "0x" + state.next_sync_committee.hash_tree_root().hex(),
36-
"leaf_index": spec.NEXT_SYNC_COMMITTEE_INDEX,
36+
"leaf_index": spec.NEXT_SYNC_COMMITTEE_GINDEX,
3737
"branch": ['0x' + root.hex() for root in next_sync_committee_branch]
3838
}
3939
assert spec.is_valid_merkle_branch(
4040
leaf=state.next_sync_committee.hash_tree_root(),
4141
branch=next_sync_committee_branch,
42-
depth=spec.floorlog2(spec.NEXT_SYNC_COMMITTEE_INDEX),
43-
index=spec.get_subtree_index(spec.NEXT_SYNC_COMMITTEE_INDEX),
42+
depth=spec.floorlog2(spec.NEXT_SYNC_COMMITTEE_GINDEX),
43+
index=spec.get_subtree_index(spec.NEXT_SYNC_COMMITTEE_GINDEX),
4444
root=state.hash_tree_root(),
4545
)
4646

@@ -50,17 +50,17 @@ def test_next_sync_committee_merkle_proof(spec, state):
5050
@spec_state_test
5151
def test_finality_root_merkle_proof(spec, state):
5252
yield "object", state
53-
finality_branch = spec.compute_merkle_proof(state, spec.FINALIZED_ROOT_INDEX)
53+
finality_branch = spec.compute_merkle_proof(state, spec.FINALIZED_ROOT_GINDEX)
5454
yield "proof", {
5555
"leaf": "0x" + state.finalized_checkpoint.root.hex(),
56-
"leaf_index": spec.FINALIZED_ROOT_INDEX,
56+
"leaf_index": spec.FINALIZED_ROOT_GINDEX,
5757
"branch": ['0x' + root.hex() for root in finality_branch]
5858
}
5959

6060
assert spec.is_valid_merkle_branch(
6161
leaf=state.finalized_checkpoint.root,
6262
branch=finality_branch,
63-
depth=spec.floorlog2(spec.FINALIZED_ROOT_INDEX),
64-
index=spec.get_subtree_index(spec.FINALIZED_ROOT_INDEX),
63+
depth=spec.floorlog2(spec.FINALIZED_ROOT_GINDEX),
64+
index=spec.get_subtree_index(spec.FINALIZED_ROOT_GINDEX),
6565
root=state.hash_tree_root(),
6666
)

tests/core/pyspec/eth2spec/test/altair/light_client/test_sync.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def emit_update(test, spec, state, block, attested_state, attested_block, finali
164164
if not with_next:
165165
data.next_sync_committee = spec.SyncCommittee()
166166
data.next_sync_committee_branch = \
167-
[spec.Bytes32() for _ in range(spec.floorlog2(spec.NEXT_SYNC_COMMITTEE_INDEX))]
167+
[spec.Bytes32() for _ in range(spec.floorlog2(spec.NEXT_SYNC_COMMITTEE_GINDEX))]
168168
current_slot = state.slot
169169

170170
upgraded = upgrade_lc_update_to_new_spec(d_spec, test.s_spec, data)

tests/core/pyspec/eth2spec/test/helpers/light_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ def create_update(spec,
6868

6969
if with_next:
7070
update.next_sync_committee = attested_state.next_sync_committee
71-
update.next_sync_committee_branch = spec.compute_merkle_proof(attested_state, spec.NEXT_SYNC_COMMITTEE_INDEX)
71+
update.next_sync_committee_branch = spec.compute_merkle_proof(attested_state, spec.NEXT_SYNC_COMMITTEE_GINDEX)
7272

7373
if with_finality:
7474
update.finalized_header = spec.block_to_light_client_header(finalized_block)
75-
update.finality_branch = spec.compute_merkle_proof(attested_state, spec.FINALIZED_ROOT_INDEX)
75+
update.finality_branch = spec.compute_merkle_proof(attested_state, spec.FINALIZED_ROOT_GINDEX)
7676

7777
update.sync_aggregate, update.signature_slot = get_sync_aggregate(
7878
spec, attested_state, num_participants)

0 commit comments

Comments
 (0)