EIP-4399 changes: random -> prevRandao

This commit is contained in:
jangko 2022-02-27 11:40:15 +07:00
parent 63add129b8
commit 622e6489d8
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
2 changed files with 6 additions and 7 deletions

View File

@ -244,12 +244,11 @@ func baseFee*(h: BlockHeader | BlockHeaderRef): UInt256 =
template `baseFee=`*(h: BlockHeader | BlockHeaderRef, data: UInt256) = template `baseFee=`*(h: BlockHeader | BlockHeaderRef, data: UInt256) =
h.fee = some(data) h.fee = some(data)
# starting from EIP-4399, `mixHash`/`mixDigest` field will be alled `random` # starting from EIP-4399, `mixHash`/`mixDigest` field will be alled `prevRandao`
# https://github.com/ethereum/EIPs/blob/bd156daf2afa38aa95bc2137d3121ff536e50645/EIPS/eip-4399.md template prevRandao*(h: BlockHeader | BlockHeaderRef): Hash256 =
template random*(h: BlockHeader | BlockHeaderRef): Hash256 =
h.mixDigest h.mixDigest
template `random=`*(h: BlockHeader | BlockHeaderRef, hash: Hash256) = template `prevRandao=`*(h: BlockHeader | BlockHeaderRef, hash: Hash256) =
h.mixDigest = hash h.mixDigest = hash
func toBlockNonce*(n: uint64): BlockNonce = func toBlockNonce*(n: uint64): BlockNonce =

View File

@ -50,9 +50,9 @@ suite "BlockHashOrNumber":
Json.roundtripTest BlockHashOrNumber(isHash: false, number: 1209231231), Json.roundtripTest BlockHashOrNumber(isHash: false, number: 1209231231),
"\"1209231231\"" "\"1209231231\""
test "EIP-4399 random field": test "EIP-4399 prevRandao field":
let hash = Hash256.fromHex "0x7a64245f7f95164f6176d90bd4903dbdd3e5433d555dd1385e81787f9672c588" let hash = Hash256.fromHex "0x7a64245f7f95164f6176d90bd4903dbdd3e5433d555dd1385e81787f9672c588"
var blk: BlockHeader var blk: BlockHeader
blk.random = hash blk.prevRandao = hash
let res = blk.random let res = blk.prevRandao
check hash == res check hash == res