prevent accidentally hashing `BeaconState`/`BeaconBlock` in Deneb (#5852)

Extend protection against accidentally calling computationally expensive
functions when a cache is available to Deneb, as done for earlier forks.
This commit is contained in:
Etan Kissling 2024-02-06 19:57:53 +01:00 committed by GitHub
parent f556b91af0
commit 41403022bb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 2 deletions

View File

@ -18,6 +18,7 @@ from ./datatypes/phase0 import HashedBeaconState, SignedBeaconBlock
from ./datatypes/altair import HashedBeaconState, SignedBeaconBlock
from ./datatypes/bellatrix import HashedBeaconState, SignedBeaconBlock
from ./datatypes/capella import HashedBeaconState, SignedBeaconBlock
from ./datatypes/deneb import HashedBeaconState, SignedBeaconBlock
export ssz_codec, merkleization, proofs
@ -28,12 +29,14 @@ type
# creating recursive module dependency through `forks`.
func hash_tree_root*(
x: phase0.HashedBeaconState | altair.HashedBeaconState |
bellatrix.HashedBeaconState | capella.HashedBeaconState) {.
bellatrix.HashedBeaconState | capella.HashedBeaconState |
deneb.HashedBeaconState) {.
error: "HashedBeaconState should not be hashed".}
func hash_tree_root*(
x: phase0.SignedBeaconBlock | altair.SignedBeaconBlock |
bellatrix.SignedBeaconBlock | capella.SignedBeaconBlock) {.
bellatrix.SignedBeaconBlock | capella.SignedBeaconBlock |
deneb.SignedBeaconBlock) {.
error: "SignedBeaconBlock should not be hashed".}
func depositCountBytes*(x: uint64): array[32, byte] =

View File

@ -551,6 +551,10 @@ template PayloadAttributes*(
else:
{.error: "PayloadAttributes does not support " & $kind.}
# `eth2_merkleization` cannot import `forks` (circular), so the check is here
static: doAssert ConsensusFork.high == ConsensusFork.Deneb,
"eth2_merkleization has been checked and `hash_tree_root` is up to date"
# TODO when https://github.com/nim-lang/Nim/issues/21086 fixed, use return type
# `ref T`
func new*(T: type ForkedHashedBeaconState, data: phase0.BeaconState):