From 22338b7870826885ffc426b96b9f0e64de4d374e Mon Sep 17 00:00:00 2001 From: Etan Kissling Date: Tue, 13 Dec 2022 21:06:26 +0100 Subject: [PATCH] bump `nim-eth` for `eip4844` support The `BlockHeader` structure in `nim-eth` was updated with support for EIP-4844 (danksharding). To enable the `nim-eth` bump, the ingress of `BlockHeader` structures has been hardened to reject headers that have the new `excessDataGas` field until proper EIP4844 support exists. https://github.com/status-im/nim-eth/pull/570 --- fluffy/network/history/history_network.nim | 3 +++ nimbus/core/eip4844.nim | 21 +++++++++++++++++++++ nimbus/core/validate.nim | 7 +++++-- nimbus/sync/legacy.nim | 8 +++++++- nimbus/utils/debug.nim | 2 ++ tests/replay/pp.nim | 3 ++- vendor/nim-eth | 2 +- 7 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 nimbus/core/eip4844.nim diff --git a/fluffy/network/history/history_network.nim b/fluffy/network/history/history_network.nim index 1f1946fb6..bd0dfd263 100644 --- a/fluffy/network/history/history_network.nim +++ b/fluffy/network/history/history_network.nim @@ -132,6 +132,9 @@ func validateBlockHeaderBytes*( let header = ? decodeRlp(bytes, BlockHeader) + if header.excessDataGas.isSome: + return err("EIP-4844 not yet implemented") + if header.withdrawalsRoot.isSome: return err("Withdrawals not yet implemented") diff --git a/nimbus/core/eip4844.nim b/nimbus/core/eip4844.nim new file mode 100644 index 000000000..45db642ec --- /dev/null +++ b/nimbus/core/eip4844.nim @@ -0,0 +1,21 @@ +# Nimbus +# Copyright (c) 2022 Status Research & Development GmbH +# Licensed under either of +# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or +# http://www.apache.org/licenses/LICENSE-2.0) +# * MIT license ([LICENSE-MIT](LICENSE-MIT) or +# http://opensource.org/licenses/MIT) +# at your option. This file may not be copied, modified, or distributed except +# according to those terms. + +import + stew/results, + ../common/common + +# https://eips.ethereum.org/EIPS/eip-4844 +func validateEip4844Header*( + com: CommonRef, header: BlockHeader +): Result[void, string] {.raises: [Defect].} = + if header.excessDataGas.isSome: + return err("EIP-4844 not yet implemented") + return ok() diff --git a/nimbus/core/validate.nim b/nimbus/core/validate.nim index f114cd944..e31bec531 100644 --- a/nimbus/core/validate.nim +++ b/nimbus/core/validate.nim @@ -13,7 +13,7 @@ import ../db/accounts_cache, ".."/[transaction, common/common], ".."/[vm_state, vm_types, errors], - "."/[dao, gaslimit, withdrawals], + "."/[dao, eip4844, gaslimit, withdrawals], ./pow/[difficulty, header], ./pow, chronicles, @@ -129,7 +129,10 @@ proc validateHeader(com: CommonRef; header, parentHeader: BlockHeader; if checkSealOK: return pow.validateSeal(header) - com.validateWithdrawals(header) + ? com.validateWithdrawals(header) + ? com.validateEip4844Header(header) + + ok() func validateUncle(currBlock, uncle, uncleParent: BlockHeader): Result[void,string] = diff --git a/nimbus/sync/legacy.nim b/nimbus/sync/legacy.nim index 835cd0449..5a4549054 100644 --- a/nimbus/sync/legacy.nim +++ b/nimbus/sync/legacy.nim @@ -17,7 +17,7 @@ import eth/p2p/[private/p2p_types, peer_pool], stew/byteutils, "."/[protocol, types], - ../core/[chain, clique/clique_sealer, gaslimit, withdrawals], + ../core/[chain, clique/clique_sealer, eip4844, gaslimit, withdrawals], ../core/pow/difficulty, ../constants, ../utils/utils, @@ -239,6 +239,12 @@ proc validateHeader(ctx: LegacySyncRef, header: BlockHeader, msg=res.error return false + res = com.validateEip4844Header(header) + if res.isErr: + trace "validate eip4844 error", + msg=res.error + return false + return true # ------------------------------------------------------------------------------ diff --git a/nimbus/utils/debug.nim b/nimbus/utils/debug.nim index 16507bf13..c00b0b568 100644 --- a/nimbus/utils/debug.nim +++ b/nimbus/utils/debug.nim @@ -49,6 +49,8 @@ proc debug*(h: BlockHeader): string = result.add "fee : " & $h.fee.get() & "\n" if h.withdrawalsRoot.isSome: result.add "withdrawalsRoot: " & $h.withdrawalsRoot.get() & "\n" + if h.excessDataGas.isSome: + result.add "excessDataGas: " & $h.excessDataGas.get() & "\n" result.add "blockHash : " & $blockHash(h) & "\n" proc dumpAccount(stateDB: AccountsCache, address: EthAddress): JsonNode = diff --git a/tests/replay/pp.nim b/tests/replay/pp.nim index ba7743799..8681fbd77 100644 --- a/tests/replay/pp.nim +++ b/tests/replay/pp.nim @@ -55,7 +55,8 @@ proc pp*(h: BlockHeader; sep = " "): string = &"receiptRoot={h.receiptRoot.pp}{sep}" & &"stateRoot={h.stateRoot.pp}{sep}" & &"baseFee={h.baseFee}{sep}" & - &"withdrawalsRoot={h.withdrawalsRoot.get(EMPTY_ROOT_HASH)}" + &"withdrawalsRoot={h.withdrawalsRoot.get(EMPTY_ROOT_HASH)}{sep}" & + &"excessDataGas={h.excessDataGas.get(GasInt(0))}" proc pp*(g: Genesis; sep = " "): string = "" & diff --git a/vendor/nim-eth b/vendor/nim-eth index 22d0ac81e..2b5f2a27e 160000 --- a/vendor/nim-eth +++ b/vendor/nim-eth @@ -1 +1 @@ -Subproject commit 22d0ac81e1495960e61df65d80d8a9c6f31d0726 +Subproject commit 2b5f2a27e303b13127bb525b0c7a309eaa7fbed9