Use proper types when dealing with LC Merkle proofs
This commit is contained in:
parent
cf55918a6f
commit
fca5e3b06a
|
@ -75,7 +75,8 @@ def create_light_client_bootstrap(state: BeaconState,
|
||||||
return LightClientBootstrap(
|
return LightClientBootstrap(
|
||||||
header=block_to_light_client_header(block),
|
header=block_to_light_client_header(block),
|
||||||
current_sync_committee=state.current_sync_committee,
|
current_sync_committee=state.current_sync_committee,
|
||||||
current_sync_committee_branch=compute_merkle_proof(state, CURRENT_SYNC_COMMITTEE_INDEX),
|
current_sync_committee_branch=CurrentSyncCommitteeBranch(
|
||||||
|
compute_merkle_proof(state, CURRENT_SYNC_COMMITTEE_INDEX)),
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -122,7 +123,8 @@ def create_light_client_update(state: BeaconState,
|
||||||
# `next_sync_committee` is only useful if the message is signed by the current sync committee
|
# `next_sync_committee` is only useful if the message is signed by the current sync committee
|
||||||
if update_attested_period == update_signature_period:
|
if update_attested_period == update_signature_period:
|
||||||
update.next_sync_committee = attested_state.next_sync_committee
|
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 = NextSyncCommitteeBranch(
|
||||||
|
compute_merkle_proof(attested_state, NEXT_SYNC_COMMITTEE_INDEX))
|
||||||
|
|
||||||
# Indicate finality whenever possible
|
# Indicate finality whenever possible
|
||||||
if finalized_block is not None:
|
if finalized_block is not None:
|
||||||
|
@ -131,7 +133,8 @@ def create_light_client_update(state: BeaconState,
|
||||||
assert hash_tree_root(update.finalized_header.beacon) == attested_state.finalized_checkpoint.root
|
assert hash_tree_root(update.finalized_header.beacon) == attested_state.finalized_checkpoint.root
|
||||||
else:
|
else:
|
||||||
assert attested_state.finalized_checkpoint.root == Bytes32()
|
assert attested_state.finalized_checkpoint.root == Bytes32()
|
||||||
update.finality_branch = compute_merkle_proof(attested_state, FINALIZED_ROOT_INDEX)
|
update.finality_branch = FinalityBranch(
|
||||||
|
compute_merkle_proof(attested_state, FINALIZED_ROOT_INDEX))
|
||||||
|
|
||||||
update.sync_aggregate = block.message.body.sync_aggregate
|
update.sync_aggregate = block.message.body.sync_aggregate
|
||||||
update.signature_slot = block.message.slot
|
update.signature_slot = block.message.slot
|
||||||
|
|
|
@ -82,7 +82,7 @@ Additional documents describe how the light client sync protocol can be used:
|
||||||
### `FinalityBranch`
|
### `FinalityBranch`
|
||||||
|
|
||||||
```python
|
```python
|
||||||
class FinalityBranch(Vector[Bytes32, floorlog2(FINALIZED_ROOT_INDEX)]):
|
class FinalityBranch(Vector[Bytes32, floorlog2(FINALIZED_ROOT_INDEX)]):
|
||||||
pass
|
pass
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -201,14 +201,14 @@ def is_valid_light_client_header(header: LightClientHeader) -> bool:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def is_sync_committee_update(update: LightClientUpdate) -> bool:
|
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 != NextSyncCommitteeBranch()
|
||||||
```
|
```
|
||||||
|
|
||||||
### `is_finality_update`
|
### `is_finality_update`
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def is_finality_update(update: LightClientUpdate) -> bool:
|
def is_finality_update(update: LightClientUpdate) -> bool:
|
||||||
return update.finality_branch != [Bytes32() for _ in range(floorlog2(FINALIZED_ROOT_INDEX))]
|
return update.finality_branch != FinalityBranch()
|
||||||
```
|
```
|
||||||
|
|
||||||
### `is_better_update`
|
### `is_better_update`
|
||||||
|
@ -520,7 +520,7 @@ def process_light_client_finality_update(store: LightClientStore,
|
||||||
update = LightClientUpdate(
|
update = LightClientUpdate(
|
||||||
attested_header=finality_update.attested_header,
|
attested_header=finality_update.attested_header,
|
||||||
next_sync_committee=SyncCommittee(),
|
next_sync_committee=SyncCommittee(),
|
||||||
next_sync_committee_branch=[Bytes32() for _ in range(floorlog2(NEXT_SYNC_COMMITTEE_INDEX))],
|
next_sync_committee_branch=NextSyncCommitteeBranch(),
|
||||||
finalized_header=finality_update.finalized_header,
|
finalized_header=finality_update.finalized_header,
|
||||||
finality_branch=finality_update.finality_branch,
|
finality_branch=finality_update.finality_branch,
|
||||||
sync_aggregate=finality_update.sync_aggregate,
|
sync_aggregate=finality_update.sync_aggregate,
|
||||||
|
@ -539,9 +539,9 @@ def process_light_client_optimistic_update(store: LightClientStore,
|
||||||
update = LightClientUpdate(
|
update = LightClientUpdate(
|
||||||
attested_header=optimistic_update.attested_header,
|
attested_header=optimistic_update.attested_header,
|
||||||
next_sync_committee=SyncCommittee(),
|
next_sync_committee=SyncCommittee(),
|
||||||
next_sync_committee_branch=[Bytes32() for _ in range(floorlog2(NEXT_SYNC_COMMITTEE_INDEX))],
|
next_sync_committee_branch=NextSyncCommitteeBranch(),
|
||||||
finalized_header=LightClientHeader(),
|
finalized_header=LightClientHeader(),
|
||||||
finality_branch=[Bytes32() for _ in range(floorlog2(FINALIZED_ROOT_INDEX))],
|
finality_branch=FinalityBranch(),
|
||||||
sync_aggregate=optimistic_update.sync_aggregate,
|
sync_aggregate=optimistic_update.sync_aggregate,
|
||||||
signature_slot=optimistic_update.signature_slot,
|
signature_slot=optimistic_update.signature_slot,
|
||||||
)
|
)
|
||||||
|
|
|
@ -46,14 +46,15 @@ def block_to_light_client_header(block: SignedBeaconBlock) -> LightClientHeader:
|
||||||
transactions_root=hash_tree_root(payload.transactions),
|
transactions_root=hash_tree_root(payload.transactions),
|
||||||
withdrawals_root=hash_tree_root(payload.withdrawals),
|
withdrawals_root=hash_tree_root(payload.withdrawals),
|
||||||
)
|
)
|
||||||
execution_branch = compute_merkle_proof(block.message.body, EXECUTION_PAYLOAD_INDEX)
|
execution_branch = ExecutionBranch(
|
||||||
|
compute_merkle_proof(block.message.body, EXECUTION_PAYLOAD_INDEX))
|
||||||
else:
|
else:
|
||||||
# Note that during fork transitions, `finalized_header` may still point to earlier forks.
|
# Note that during fork transitions, `finalized_header` may still point to earlier forks.
|
||||||
# While Bellatrix blocks also contain an `ExecutionPayload` (minus `withdrawals_root`),
|
# While Bellatrix blocks also contain an `ExecutionPayload` (minus `withdrawals_root`),
|
||||||
# it was not included in the corresponding light client data. To ensure compatibility
|
# it was not included in the corresponding light client data. To ensure compatibility
|
||||||
# with legacy data going through `upgrade_lc_header_to_capella`, leave out execution data.
|
# with legacy data going through `upgrade_lc_header_to_capella`, leave out execution data.
|
||||||
execution_header = ExecutionPayloadHeader()
|
execution_header = ExecutionPayloadHeader()
|
||||||
execution_branch = [Bytes32() for _ in range(floorlog2(EXECUTION_PAYLOAD_INDEX))]
|
execution_branch = ExecutionBranch()
|
||||||
|
|
||||||
return LightClientHeader(
|
return LightClientHeader(
|
||||||
beacon=BeaconBlockHeader(
|
beacon=BeaconBlockHeader(
|
||||||
|
|
|
@ -41,7 +41,7 @@ Additional documents describes the impact of the upgrade on certain roles:
|
||||||
### `ExecutionBranch`
|
### `ExecutionBranch`
|
||||||
|
|
||||||
```python
|
```python
|
||||||
class ExecutionBranch(Vector[Bytes32, floorlog2(EXECUTION_PAYLOAD_INDEX)]):
|
class ExecutionBranch(Vector[Bytes32, floorlog2(EXECUTION_PAYLOAD_INDEX)]):
|
||||||
pass
|
pass
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ def is_valid_light_client_header(header: LightClientHeader) -> bool:
|
||||||
if epoch < CAPELLA_FORK_EPOCH:
|
if epoch < CAPELLA_FORK_EPOCH:
|
||||||
return (
|
return (
|
||||||
header.execution == ExecutionPayloadHeader()
|
header.execution == ExecutionPayloadHeader()
|
||||||
and header.execution_branch == [Bytes32() for _ in range(floorlog2(EXECUTION_PAYLOAD_INDEX))]
|
and header.execution_branch == ExecutionBranch()
|
||||||
)
|
)
|
||||||
|
|
||||||
return is_valid_merkle_branch(
|
return is_valid_merkle_branch(
|
||||||
|
|
|
@ -52,14 +52,15 @@ def block_to_light_client_header(block: SignedBeaconBlock) -> LightClientHeader:
|
||||||
execution_header.blob_gas_used = payload.blob_gas_used
|
execution_header.blob_gas_used = payload.blob_gas_used
|
||||||
execution_header.excess_blob_gas = payload.excess_blob_gas
|
execution_header.excess_blob_gas = payload.excess_blob_gas
|
||||||
|
|
||||||
execution_branch = compute_merkle_proof(block.message.body, EXECUTION_PAYLOAD_INDEX)
|
execution_branch = ExecutionBranch(
|
||||||
|
compute_merkle_proof(block.message.body, EXECUTION_PAYLOAD_INDEX))
|
||||||
else:
|
else:
|
||||||
# Note that during fork transitions, `finalized_header` may still point to earlier forks.
|
# Note that during fork transitions, `finalized_header` may still point to earlier forks.
|
||||||
# While Bellatrix blocks also contain an `ExecutionPayload` (minus `withdrawals_root`),
|
# While Bellatrix blocks also contain an `ExecutionPayload` (minus `withdrawals_root`),
|
||||||
# it was not included in the corresponding light client data. To ensure compatibility
|
# it was not included in the corresponding light client data. To ensure compatibility
|
||||||
# with legacy data going through `upgrade_lc_header_to_capella`, leave out execution data.
|
# with legacy data going through `upgrade_lc_header_to_capella`, leave out execution data.
|
||||||
execution_header = ExecutionPayloadHeader()
|
execution_header = ExecutionPayloadHeader()
|
||||||
execution_branch = [Bytes32() for _ in range(floorlog2(EXECUTION_PAYLOAD_INDEX))]
|
execution_branch = ExecutionBranch()
|
||||||
|
|
||||||
return LightClientHeader(
|
return LightClientHeader(
|
||||||
beacon=BeaconBlockHeader(
|
beacon=BeaconBlockHeader(
|
||||||
|
|
|
@ -74,7 +74,7 @@ def is_valid_light_client_header(header: LightClientHeader) -> bool:
|
||||||
if epoch < CAPELLA_FORK_EPOCH:
|
if epoch < CAPELLA_FORK_EPOCH:
|
||||||
return (
|
return (
|
||||||
header.execution == ExecutionPayloadHeader()
|
header.execution == ExecutionPayloadHeader()
|
||||||
and header.execution_branch == [Bytes32() for _ in range(floorlog2(EXECUTION_PAYLOAD_INDEX))]
|
and header.execution_branch == ExecutionBranch()
|
||||||
)
|
)
|
||||||
|
|
||||||
return is_valid_merkle_branch(
|
return is_valid_merkle_branch(
|
||||||
|
|
Loading…
Reference in New Issue