Adopt latest changes to requests hash computation (#2862)

* Adopt latest changes to requests hash computation

* Fix test vector
This commit is contained in:
andri lim 2024-11-27 12:09:26 +07:00 committed by GitHub
parent 0e793aedf8
commit 1721435b3c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 956 additions and 7 deletions

View File

@ -1,5 +1,5 @@
# Nimbus # Nimbus
# Copyright (c) 2021-2024 Status Research & Development GmbH # Copyright (c) 2024 Status Research & Development GmbH
# Licensed under either of # Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
# * MIT license ([LICENSE-MIT](LICENSE-MIT)) # * MIT license ([LICENSE-MIT](LICENSE-MIT))

View File

@ -16,6 +16,7 @@ import
eth/common/[hashes, accounts, headers, addresses], eth/common/[hashes, accounts, headers, addresses],
../db/[ledger, core_db], ../db/[ledger, core_db],
../constants, ../constants,
../utils/utils,
./chain_config ./chain_config
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
@ -78,6 +79,10 @@ proc toGenesisHeader*(
result.excessBlobGas = Opt.some g.excessBlobGas.get(0'u64) result.excessBlobGas = Opt.some g.excessBlobGas.get(0'u64)
result.parentBeaconBlockRoot = Opt.some g.parentBeaconBlockRoot.get(default(Hash32)) result.parentBeaconBlockRoot = Opt.some g.parentBeaconBlockRoot.get(default(Hash32))
if fork >= Prague:
const EmptyRequestsHash = calcRequestsHash()
result.requestsHash = Opt.some(EmptyRequestsHash)
proc toGenesisHeader*( proc toGenesisHeader*(
genesis: Genesis; genesis: Genesis;
fork: HardFork; fork: HardFork;

View File

@ -40,6 +40,7 @@ func calcRequestsHash*(requests: varargs[seq[byte]]): Hash32 =
var ctx: sha256 var ctx: sha256
ctx.init() ctx.init()
for i, data in requests: for i, data in requests:
if data.len > 0:
ctx.update(calcHash(i.byte, data).data) ctx.update(calcHash(i.byte, data).data)
ctx.finish(result.data) ctx.finish(result.data)
ctx.clear() ctx.clear()

File diff suppressed because one or more lines are too long

View File

@ -2,7 +2,7 @@
"payload": { "payload": {
"baseFeePerGas": "0x7", "baseFeePerGas": "0x7",
"blobGasUsed": "0x40000", "blobGasUsed": "0x40000",
"blockHash": "0x187307d7dc9beb87af2a1d8340e9f17a3bbe4738963daeaf6d8e13b27b2d6a7f", "blockHash": "0x2ad74d1c5c12bcdedbdc821ae5d18f44e732b4096b6496a23bd9483d202003c5",
"blockNumber": "0x94b2", "blockNumber": "0x94b2",
"excessBlobGas": "0x0", "excessBlobGas": "0x0",
"extraData": "0xd883010e0c846765746888676f312e32332e32856c696e7578", "extraData": "0xd883010e0c846765746888676f312e32332e32856c696e7578",

View File

@ -12,7 +12,8 @@ import
std/[os], std/[os],
unittest2, unittest2,
../nimbus/config, ../nimbus/config,
../nimbus/common/common ../nimbus/common/common,
../nimbus/utils/utils
const const
baseDir = [".", "tests", ".."/"tests", $DirSep] # path containg repo baseDir = [".", "tests", ".."/"tests", $DirSep] # path containg repo
@ -132,6 +133,21 @@ proc customGenesisTest() =
check com.genesisHeader.blockHash == genesisHash check com.genesisHeader.blockHash == genesisHash
check com.chainId == 17000.ChainId check com.chainId == 17000.ChainId
test "Prague genesis":
# pre Prague
var cg: NetworkParams
check loadNetworkParams("mekong.json".findFilePath, cg)
var com = CommonRef.new(newCoreDbRef DefaultDbMemory, params = cg)
check com.genesisHeader.requestsHash.isNone
# post prague
const EmptyRequestsHash = hash32"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
check loadNetworkParams("prague.json".findFilePath, cg)
com = CommonRef.new(newCoreDbRef DefaultDbMemory, params = cg)
check com.genesisHeader.requestsHash.isSome
check com.genesisHeader.requestsHash.get == EmptyRequestsHash
check calcRequestsHash(default(seq[byte]), default(seq[byte]), default(seq[byte])) == EmptyRequestsHash
proc genesisMain*() = proc genesisMain*() =
genesisTest() genesisTest()
customGenesisTest() customGenesisTest()

View File

@ -18,7 +18,7 @@
"withdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", "withdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"currentExcessBlobGas": "0x2b80000", "currentExcessBlobGas": "0x2b80000",
"blobGasUsed": "0x0", "blobGasUsed": "0x0",
"requestsHash": "0x6036c41849da9c076ed79654d434017387a88fb833c2856b32e18218b3341c5f", "requestsHash": "0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"requests": [ "requests": [
"0x", "0x",
"0x", "0x",

View File

@ -34,7 +34,7 @@
"withdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", "withdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"currentExcessBlobGas": "0x2b80000", "currentExcessBlobGas": "0x2b80000",
"blobGasUsed": "0x0", "blobGasUsed": "0x0",
"requestsHash": "0x6036c41849da9c076ed79654d434017387a88fb833c2856b32e18218b3341c5f", "requestsHash": "0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"requests": [ "requests": [
"0x", "0x",
"0x", "0x",

View File

@ -34,7 +34,7 @@
"withdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", "withdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"currentExcessBlobGas": "0x2b80000", "currentExcessBlobGas": "0x2b80000",
"blobGasUsed": "0x0", "blobGasUsed": "0x0",
"requestsHash": "0xa5c19ed76c01fe25a67b7ef8c227caa34951e8c7e74168408b5be0861dac686d", "requestsHash": "0xf34c7b46f404c6c6f91b540c098b6dfe3f59b7e50ad155807c8c7d2221e52241",
"requests": [ "requests": [
"0x81521c60874daf5b425c21e44caf045c4d475e8b33a557a28cee3c46ef9cf9bd95b4c75a0bb629981b40d0102452dd4c020000000000000000000000332e43696a505ef45b9319973785f837ce5267b9000065cd1d0000008c8f2647f342d2c3e8fd07c6b3b9b16383ac11c4be6a6962c7fc18a789daee5fac20ee0bbe4a10383759aaffacacb72b0d67f998730cdf4995fe73afe434dfce2803b343606f67fc4995597c0af9e0fe9ed00006e5889bec29171f670e7d9be20000000000000000", "0x81521c60874daf5b425c21e44caf045c4d475e8b33a557a28cee3c46ef9cf9bd95b4c75a0bb629981b40d0102452dd4c020000000000000000000000332e43696a505ef45b9319973785f837ce5267b9000065cd1d0000008c8f2647f342d2c3e8fd07c6b3b9b16383ac11c4be6a6962c7fc18a789daee5fac20ee0bbe4a10383759aaffacacb72b0d67f998730cdf4995fe73afe434dfce2803b343606f67fc4995597c0af9e0fe9ed00006e5889bec29171f670e7d9be20000000000000000",
"0x", "0x",