From 8c3d1cd3aa807b7d085b3d9ea2da49989ece208e Mon Sep 17 00:00:00 2001 From: tersec Date: Tue, 8 Aug 2023 19:01:32 +0000 Subject: [PATCH] ensure `ValidatorPubKey` int-compatibly aligned to fix UB (#5277) * ensure ValidatorPubKey int-compatibly aligned * use sizeof(Hash) explicitly --- beacon_chain/spec/crypto.nim | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/beacon_chain/spec/crypto.nim b/beacon_chain/spec/crypto.nim index 51ef3db37..b5b1eaa06 100644 --- a/beacon_chain/spec/crypto.nim +++ b/beacon_chain/spec/crypto.nim @@ -54,7 +54,10 @@ type ## eagerly load keys - deserialization is slow, as are equality checks - ## however, it is not guaranteed that the key is valid (except in some ## cases, like the database state) - blob*: array[RawPubKeySize, byte] + ## + ## 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] UncompressedPubKey* = object ## Uncompressed variation of ValidatorPubKey - this type is faster to