adjust digest hashing not to care about alignment; increase ValidatorPubKey alignment (#5296)

This commit is contained in:
tersec 2023-08-17 03:06:21 +00:00 committed by GitHub
parent a150bc93a6
commit 22b7b721d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 3 deletions

View File

@ -57,12 +57,12 @@ type
##
## It must be 8-byte aligned because `hash(ValidatorPubKey)` just casts a
## ptr to one to a ptr to the other, so it needs a compatible alignment.
blob* {.align: sizeof(Hash).}: array[RawPubKeySize, byte]
blob* {.align: 16.}: array[RawPubKeySize, byte]
UncompressedPubKey* = object
## Uncompressed variation of ValidatorPubKey - this type is faster to
## deserialize but doubles the storage footprint
blob*: array[UncompressedPubKeySize, byte]
blob* {.align: 16.}: array[UncompressedPubKeySize, byte]
CookedPubKey* = distinct blscurve.PublicKey ## Valid deserialized key

View File

@ -130,7 +130,9 @@ template withEth2Hash*(body: untyped): Eth2Digest =
template hash*(x: Eth2Digest): Hash =
## Hash for digests for Nim hash tables
# digests are already good hashes
cast[ptr Hash](unsafeAddr x.data[0])[]
var h {.noinit.}: Hash
copyMem(addr h, unsafeAddr x.data[0], static(sizeof(Hash)))
h
func `==`*(a, b: Eth2Digest): bool =
when nimvm: