Skip to content

Commit

Permalink
prevRandao -> Bytes32 (#740)
Browse files Browse the repository at this point in the history
This one is a bit of a mess because it has different names and types
across specs :/
  • Loading branch information
arnetheduck authored Oct 2, 2024
1 parent 70b7519 commit 5ce3c45
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions eth/common/headers.nim
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ type
gasUsed*: GasInt
timestamp*: EthTime
extraData*: seq[byte]
mixHash*: Hash32
mixHash*: Bytes32
## AKA mix_digest in some specs - Hash32 in the eth API but Bytes32 in
## the execution API and spec!
nonce*: Bytes8
baseFeePerGas*: Opt[UInt256] # EIP-1559
withdrawalsRoot*: Opt[Hash32] # EIP-4895
Expand All @@ -39,10 +41,10 @@ type
requestsRoot*: Opt[Hash32] # EIP-7685

# starting from EIP-4399, `mixDigest` field is called `prevRandao`
template prevRandao*(h: Header): Hash32 =
template prevRandao*(h: Header): Bytes32 =
h.mixHash

template `prevRandao=`*(h: Header, hash: Hash32) =
template `prevRandao=`*(h: Header, hash: Bytes32) =
h.mixHash = hash

template txRoot*(h: Header): Root = h.transactionsRoot
4 changes: 2 additions & 2 deletions tests/common/test_eth_types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ suite "BlockHashOrNumber":
suite "Block encodings":
test "EIP-4399 prevRandao field":
var blk: BlockHeader
blk.prevRandao = testHash
blk.prevRandao = Bytes32 testHash
let res = blk.prevRandao
check testHash == res
check Bytes32(testHash) == res

test "EIP-4788 parentBeaconBlockRoot field":
let header = BlockHeader(
Expand Down

0 comments on commit 5ce3c45

Please sign in to comment.