Skip to content

Commit

Permalink
bump nim-ssz-serialization to `3db6cc0f282708aca6c290914488edd832971d…
Browse files Browse the repository at this point in the history
…61` (#3119)

This updates `nim-ssz-serialization` to
`3db6cc0f282708aca6c290914488edd832971d61`.

Notable changes:
- Use `uint64` for `GeneralizedIndex`
- Add support for building merkle multiproofs
  • Loading branch information
etan-status authored Jun 26, 2022
1 parent b764f4f commit aa1b8e4
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 527 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
2 changes: 1 addition & 1 deletion beacon_chain/consensus_object_pools/blockchain_dag.nim
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ proc init*(T: type ChainDAGRef, cfg: RuntimeConfig, db: BeaconChainDB,

# The only allowed flag right now is verifyFinalization, as the others all
# allow skipping some validation.
updateFlags: {verifyFinalization} * updateFlags,
updateFlags: {verifyFinalization, enableTestFeatures} * updateFlags,
cfg: cfg,

vanityLogs: vanityLogs,
Expand Down
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.lcDataStore.cache.data.hasKeyOrPut(bid, cachedData):
doAssert false, "Redundant `cacheLightClientData` call"

Expand Down Expand Up @@ -529,16 +526,14 @@ proc initLightClientBootstrapForPeriod(
boundarySlot = bid.slot.nextEpochBoundarySlot
if boundarySlot == nextBoundarySlot and bid.slot >= lowSlot and
not dag.lcDataStore.cache.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.lcDataStore.cache.bootstrap[bid.slot] = cachedBootstrap

Expand Down Expand Up @@ -679,15 +674,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 @@ -819,11 +812,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.lcDataStore.cache.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 aa1b8e4

Please sign in to comment.