Skip to content

Commit

Permalink
bump nim-ssz-serialization to 9e754ec08217fc4eb4837a226d18a4cca51e6e09
Browse files Browse the repository at this point in the history
This updates `nim-ssz-serialization` to
`9e754ec08217fc4eb4837a226d18a4cca51e6e09`.

Notable changes:
- Use `uint64` for `GeneralizedIndex`
- Add support for building merkle multiproofs
  • Loading branch information
etan-status committed Jun 23, 2022
1 parent e25cfe5 commit b23ab41
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 526 deletions.
9 changes: 2 additions & 7 deletions AllTests-mainnet.md
Original file line number Diff line number Diff line change
Expand Up @@ -410,14 +410,9 @@ OK: 1/1 Fail: 0/1 Skip: 0/1
## Spec helpers
```diff
+ build_proof - BeaconState OK
+ get_branch_indices OK
+ get_helper_indices OK
+ get_path_indices OK
+ integer_squareroot OK
+ is_valid_merkle_branch OK
+ verify_merkle_multiproof OK
```
OK: 7/7 Fail: 0/7 Skip: 0/7
OK: 2/2 Fail: 0/2 Skip: 0/2
## Specific field types
```diff
+ root update OK
Expand Down Expand Up @@ -573,4 +568,4 @@ OK: 1/1 Fail: 0/1 Skip: 0/1
OK: 9/9 Fail: 0/9 Skip: 0/9

---TOTAL---
OK: 318/323 Fail: 0/323 Skip: 5/323
OK: 313/318 Fail: 0/318 Skip: 5/318
45 changes: 18 additions & 27 deletions beacon_chain/consensus_object_pools/blockchain_dag_light_client.nim
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,15 @@ proc cacheLightClientData(
## Cache data for a given block and its post-state to speed up creating future
## `LightClientUpdate` and `LightClientBootstrap` instances that refer to this
## block and state.
var cachedData {.noinit.}: CachedLightClientData
state.data.build_proof(
altair.CURRENT_SYNC_COMMITTEE_INDEX,
cachedData.current_sync_committee_branch)
state.data.build_proof(
altair.NEXT_SYNC_COMMITTEE_INDEX,
cachedData.next_sync_committee_branch)
cachedData.finalized_slot =
state.data.finalized_checkpoint.epoch.start_slot
state.data.build_proof(
altair.FINALIZED_ROOT_INDEX,
cachedData.finality_branch)
let cachedData = CachedLightClientData(
current_sync_committee_branch:
state.data.build_proof(altair.CURRENT_SYNC_COMMITTEE_INDEX).get,
next_sync_committee_branch:
state.data.build_proof(altair.NEXT_SYNC_COMMITTEE_INDEX).get,
finalized_slot:
state.data.finalized_checkpoint.epoch.start_slot,
finality_branch:
state.data.build_proof(altair.FINALIZED_ROOT_INDEX).get)
if dag.lightClientCache.data.hasKeyOrPut(bid, cachedData):
doAssert false, "Redundant `cacheLightClientData` call"

Expand Down Expand Up @@ -517,16 +514,14 @@ proc initLightClientBootstrapForPeriod(
boundarySlot = bid.slot.nextEpochBoundarySlot
if boundarySlot == nextBoundarySlot and bid.slot >= lowSlot and
not dag.lightClientCache.bootstrap.hasKey(bid.slot):
var cachedBootstrap {.noinit.}: CachedLightClientBootstrap
if not dag.updateExistingState(
tmpState[], bid.atSlot, save = false, tmpCache):
dag.handleUnexpectedLightClientError(bid.slot)
continue
withState(tmpState[]):
var cachedBootstrap {.noinit.}: CachedLightClientBootstrap
cachedBootstrap.current_sync_committee_branch = withState(tmpState[]):
when stateFork >= BeaconStateFork.Altair:
state.data.build_proof(
altair.CURRENT_SYNC_COMMITTEE_INDEX,
cachedBootstrap.current_sync_committee_branch)
state.data.build_proof(altair.CURRENT_SYNC_COMMITTEE_INDEX).get
else: raiseAssert "Unreachable"
dag.lightClientCache.bootstrap[bid.slot] = cachedBootstrap

Expand Down Expand Up @@ -667,15 +662,13 @@ proc initLightClientUpdateForPeriod(
when stateFork >= BeaconStateFork.Altair:
update.attested_header = blck.toBeaconBlockHeader()
update.next_sync_committee = state.data.next_sync_committee
state.data.build_proof(
altair.NEXT_SYNC_COMMITTEE_INDEX,
update.next_sync_committee_branch)
update.next_sync_committee_branch =
state.data.build_proof(altair.NEXT_SYNC_COMMITTEE_INDEX).get
if finalizedBid.slot == FAR_FUTURE_SLOT:
update.finality_branch.reset()
else:
state.data.build_proof(
altair.FINALIZED_ROOT_INDEX,
update.finality_branch)
update.finality_branch =
state.data.build_proof(altair.FINALIZED_ROOT_INDEX).get
else: raiseAssert "Unreachable"
do:
dag.handleUnexpectedLightClientError(attestedBid.slot)
Expand Down Expand Up @@ -807,11 +800,9 @@ proc getLightClientBootstrap*(
let bsi = ? dag.getExistingBlockIdAtSlot(slot)
var tmpState = assignClone(dag.headState)
dag.withUpdatedExistingState(tmpState[], bsi) do:
withState(state):
cachedBootstrap.current_sync_committee_branch = withState(state):
when stateFork >= BeaconStateFork.Altair:
state.data.build_proof(
altair.CURRENT_SYNC_COMMITTEE_INDEX,
cachedBootstrap.current_sync_committee_branch)
state.data.build_proof(altair.CURRENT_SYNC_COMMITTEE_INDEX).get
else: raiseAssert "Unreachable"
do: return err()
dag.lightClientCache.bootstrap[slot] = cachedBootstrap
Expand Down
6 changes: 3 additions & 3 deletions beacon_chain/spec/eth2_merkleization.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# beacon_chain
# Copyright (c) 2018-2021 Status Research & Development GmbH
# Copyright (c) 2018-2022 Status Research & Development GmbH
# Licensed and distributed under either of
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
Expand All @@ -10,11 +10,11 @@
# Import this module to get access to `hash_tree_root` for spec types

import
ssz_serialization/merkleization,
ssz_serialization/[merkleization, proofs],
./ssz_codec,
./datatypes/[phase0, altair]

export ssz_codec, merkleization
export ssz_codec, merkleization, proofs

func hash_tree_root*(x: phase0.HashedBeaconState | altair.HashedBeaconState) {.
error: "HashedBeaconState should not be hashed".}
Expand Down
Loading

0 comments on commit b23ab41

Please sign in to comment.