From 4fd2ecddec31b28821c0882cfcd5f7c4136159f5 Mon Sep 17 00:00:00 2001 From: Kim De Mey Date: Wed, 19 Jun 2024 03:57:45 +0200 Subject: [PATCH] Bump nim-eth/web3/kzg4844/nimbus-eth2 and related fixes (#2392) Bump nim-eth, which requires nimbus-eth2 bump, which requires bumps of web3 and kzg4844 + related fixes to all those bumps. --- fluffy/fluffy.nim | 6 ++-- fluffy/tests/test_helpers.nim | 8 ++--- .../beacon_lc_bridge/beacon_lc_bridge.nim | 3 +- fluffy/tools/portalcli.nim | 2 +- fluffy/tools/utp_testing/utp_test_app.nim | 10 +++--- nimbus/beacon/api_handler/api_newpayload.nim | 4 +-- nimbus/core/eip4844.nim | 32 ++++++++----------- .../nimbus_verified_proxy.nim | 4 +-- vendor/nim-eth | 2 +- vendor/nim-kzg4844 | 2 +- vendor/nim-web3 | 2 +- vendor/nimbus-eth2 | 2 +- 12 files changed, 34 insertions(+), 43 deletions(-) diff --git a/fluffy/fluffy.nim b/fluffy/fluffy.nim index 944450763..f808c2691 100644 --- a/fluffy/fluffy.nim +++ b/fluffy/fluffy.nim @@ -137,7 +137,7 @@ proc run(config: PortalConf) {.raises: [CatchableError].} = d = newProtocol( netkey, extIp, - none(Port), + Opt.none(Port), extUdpPort, # Note: The addition of default clientInfo to the ENR is a temporary # measure to easily identify & debug the clients used in the testnet. @@ -147,9 +147,9 @@ proc run(config: PortalConf) {.raises: [CatchableError].} = previousRecord = # TODO: discv5/enr code still uses Option, to be changed. if previousEnr.isSome(): - some(previousEnr.get()) + Opt.some(previousEnr.get()) else: - none(enr.Record) + Opt.none(enr.Record) , bindIp = bindIp, bindPort = udpPort, diff --git a/fluffy/tests/test_helpers.nim b/fluffy/tests/test_helpers.nim index 4a170066d..f1d6dd086 100644 --- a/fluffy/tests/test_helpers.nim +++ b/fluffy/tests/test_helpers.nim @@ -24,16 +24,16 @@ proc initDiscoveryNode*( address: Address, bootstrapRecords: openArray[Record] = [], localEnrFields: openArray[(string, seq[byte])] = [], - previousRecord = none[enr.Record](), + previousRecord = Opt.none(enr.Record), ): discv5_protocol.Protocol {.raises: [CatchableError].} = # set bucketIpLimit to allow bucket split let config = DiscoveryConfig.init(1000, 24, 5) result = newProtocol( privKey, - some(address.ip), - some(address.port), - some(address.port), + Opt.some(address.ip), + Opt.some(address.port), + Opt.some(address.port), bindPort = address.port, bootstrapRecords = bootstrapRecords, localEnrFields = localEnrFields, diff --git a/fluffy/tools/beacon_lc_bridge/beacon_lc_bridge.nim b/fluffy/tools/beacon_lc_bridge/beacon_lc_bridge.nim index 2e5f72fff..718f7a47d 100644 --- a/fluffy/tools/beacon_lc_bridge/beacon_lc_bridge.nim +++ b/fluffy/tools/beacon_lc_bridge/beacon_lc_bridge.nim @@ -264,7 +264,7 @@ proc run(config: BeaconBridgeConf) {.raises: [CatchableError].} = portalRpcClient = newRpcHttpClient() optimisticHandler = proc( - signedBlock: ForkedMsgTrustedSignedBeaconBlock + signedBlock: ForkedSignedBeaconBlock ): Future[void] {.async: (raises: [CancelledError]).} = # TODO: Should not be gossiping optimistic blocks, but instead store them # in a cache and only gossip them after they are confirmed due to an LC @@ -512,7 +512,6 @@ proc run(config: BeaconBridgeConf) {.raises: [CatchableError].} = withForkyHeader(optimisticHeader): when lcDataFork > LightClientDataFork.None: info "New LC optimistic header", optimistic_header = shortLog(forkyHeader) - optimisticProcessor.setOptimisticHeader(forkyHeader.beacon) lightClient.onFinalizedHeader = onFinalizedHeader lightClient.onOptimisticHeader = onOptimisticHeader diff --git a/fluffy/tools/portalcli.nim b/fluffy/tools/portalcli.nim index 9c13d5159..98abee2c6 100644 --- a/fluffy/tools/portalcli.nim +++ b/fluffy/tools/portalcli.nim @@ -231,7 +231,7 @@ proc run(config: PortalCliConf) = let d = newProtocol( config.networkKey, extIp, - none(Port), + Opt.none(Port), extUdpPort, bootstrapRecords = bootstrapRecords, bindIp = bindIp, diff --git a/fluffy/tools/utp_testing/utp_test_app.nim b/fluffy/tools/utp_testing/utp_test_app.nim index 6ec55905b..783f30be2 100644 --- a/fluffy/tools/utp_testing/utp_test_app.nim +++ b/fluffy/tools/utp_testing/utp_test_app.nim @@ -12,7 +12,7 @@ import chronicles, confutils, confutils/std/net as confNet, - stew/[byteutils, endians2], + stew/byteutils, json_rpc/servers/httpserver, eth/p2p/discoveryv5/protocol, eth/p2p/discoveryv5/enr, @@ -54,7 +54,7 @@ proc installUtpHandlers( d: protocol.Protocol, s: UtpDiscv5Protocol, t: ref Table[SKey, UtpSocket[NodeAddress]], -) {.raises: [CatchableError].} = +) {.raises: [].} = srv.rpc("utp_connect") do(r: enr.Record) -> SKey: let nodeRes = newNode(r) @@ -148,9 +148,9 @@ when isMainModule: let d = newProtocol( key, - some(discAddress), - none(Port), - some(conf.udpPort), + Opt.some(discAddress), + Opt.none(Port), + Opt.some(conf.udpPort), bootstrapRecords = @[], bindIp = discAddress, bindPort = conf.udpPort, diff --git a/nimbus/beacon/api_handler/api_newpayload.nim b/nimbus/beacon/api_handler/api_newpayload.nim index 18579b76b..b52c998c9 100644 --- a/nimbus/beacon/api_handler/api_newpayload.nim +++ b/nimbus/beacon/api_handler/api_newpayload.nim @@ -83,9 +83,9 @@ template validatePayload(apiVersion, version, payload) = "excessBlobGas is expected from execution payload") if apiVersion >= Version.V4 or version >= Version.V4: - if payload.depositReceipts.isNone: + if payload.depositRequests.isNone: raise invalidParams("newPayload" & $apiVersion & - "depositReceipts is expected from execution payload") + "depositRequests is expected from execution payload") if payload.exits.isNone: raise invalidParams("newPayload" & $apiVersion & "exits is expected from execution payload") diff --git a/nimbus/core/eip4844.nim b/nimbus/core/eip4844.nim index 774b214ba..c5c67849b 100644 --- a/nimbus/core/eip4844.nim +++ b/nimbus/core/eip4844.nim @@ -10,6 +10,7 @@ import std/[os, strutils], + stew/arrayops, nimcrypto/sha2, kzg4844/kzg_ex as kzg, results, @@ -39,8 +40,8 @@ const # kzgToVersionedHash implements kzg_to_versioned_hash from EIP-4844 -proc kzgToVersionedHash*(kzg: kzg.KZGCommitment): VersionedHash = - result = sha256.digest(kzg.bytes) +proc kzgToVersionedHash*(kzg: kzg.KzgCommitment): VersionedHash = + result = sha256.digest(kzg) result.data[0] = VERSIONED_HASH_VERSION_KZG # pointEvaluation implements point_evaluation_precompile from EIP-4844 @@ -54,20 +55,14 @@ proc pointEvaluation*(input: openArray[byte]): Result[void, string] = if input.len != PrecompileInputLength: return err("invalid input length") - var - versionedHash: KzgBytes32 - z: KzgBytes32 - y: KzgBytes32 - commitment: KzgBytes48 - kzgProof: KzgBytes48 + let + versionedHash = KzgBytes32.initCopyFrom(input.toOpenArray(0, 31)) + z = KzgBytes32.initCopyFrom(input.toOpenArray(32, 63)) + y = KzgBytes32.initCopyFrom(input.toOpenArray(64, 95)) + commitment = KzgBytes48.initCopyFrom(input.toOpenArray(96, 143)) + kzgProof = KzgBytes48.initCopyFrom(input.toOpenArray(144, 191)) - versionedHash.bytes[0..<32] = input[0..<32] - z.bytes[0..<32] = input[32..<64] - y.bytes[0..<32] = input[64..<96] - commitment.bytes[0..<48] = input[96..<144] - kzgProof.bytes[0..<48] = input[144..<192] - - if kzgToVersionedHash(commitment).data != versionedHash.bytes: + if kzgToVersionedHash(commitment).data != versionedHash: return err("versionedHash should equal to kzgToVersionedHash(commitment)") # Verify KZG proof @@ -183,14 +178,13 @@ proc validateBlobTransactionWrapper*(tx: PooledTransaction): if not goodFormatted: return err("tx wrapper is ill formatted") - let commitments = tx.networkPayload.commitments.mapIt( - kzg.KzgCommitment(bytes: it)) + let commitments = tx.networkPayload.commitments # Verify that commitments match the blobs by checking the KZG proof let res = kzg.verifyBlobKzgProofBatch( - tx.networkPayload.blobs.mapIt(kzg.KzgBlob(bytes: it)), + tx.networkPayload.blobs, commitments, - tx.networkPayload.proofs.mapIt(kzg.KzgProof(bytes: it))) + tx.networkPayload.proofs) if res.isErr: return err(res.error) diff --git a/nimbus_verified_proxy/nimbus_verified_proxy.nim b/nimbus_verified_proxy/nimbus_verified_proxy.nim index 7bc90cb9e..d46ebfd54 100644 --- a/nimbus_verified_proxy/nimbus_verified_proxy.nim +++ b/nimbus_verified_proxy/nimbus_verified_proxy.nim @@ -46,7 +46,6 @@ func getConfiguredChainId(networkMetadata: Eth2NetworkMetadata): Quantity = chainId = case net of mainnet: 1.Quantity - of goerli: 5.Quantity of sepolia: 11155111.Quantity of holesky: 17000.Quantity return chainId @@ -130,7 +129,7 @@ proc run*( verifiedProxy = VerifiedRpcProxy.new(rpcProxy, blockCache, chainId) optimisticHandler = proc( - signedBlock: ForkedMsgTrustedSignedBeaconBlock + signedBlock: ForkedSignedBeaconBlock ): Future[void] {.async: (raises: [CancelledError]).} = notice "New LC optimistic block", opt = signedBlock.toBlockId(), wallSlot = getBeaconTime().slotOrZero @@ -214,7 +213,6 @@ proc run*( withForkyHeader(optimisticHeader): when lcDataFork > LightClientDataFork.None: info "New LC optimistic header", optimistic_header = shortLog(forkyHeader) - optimisticProcessor.setOptimisticHeader(forkyHeader.beacon) if headerCallback != nil: try: headerCallback(cstring(Json.encode(forkyHeader)), 1) diff --git a/vendor/nim-eth b/vendor/nim-eth index f169068df..26212c881 160000 --- a/vendor/nim-eth +++ b/vendor/nim-eth @@ -1 +1 @@ -Subproject commit f169068df6c11a2aeba27584c60e354e19c42e94 +Subproject commit 26212c881b464ed64cac20442fb45144d3ecd3b3 diff --git a/vendor/nim-kzg4844 b/vendor/nim-kzg4844 index 2f5cee7be..f12616d06 160000 --- a/vendor/nim-kzg4844 +++ b/vendor/nim-kzg4844 @@ -1 +1 @@ -Subproject commit 2f5cee7bea0d62e2b502ff668f752bda7f3eb0c4 +Subproject commit f12616d0675d9f6346141ca95f0840ab227eb213 diff --git a/vendor/nim-web3 b/vendor/nim-web3 index b705f8164..fc226d451 160000 --- a/vendor/nim-web3 +++ b/vendor/nim-web3 @@ -1 +1 @@ -Subproject commit b705f816439f0068ece8c234336bc7093222d00f +Subproject commit fc226d4511199aa57a3fcd5cc44695c6b365a6bf diff --git a/vendor/nimbus-eth2 b/vendor/nimbus-eth2 index c5326619a..7a8c1d818 160000 --- a/vendor/nimbus-eth2 +++ b/vendor/nimbus-eth2 @@ -1 +1 @@ -Subproject commit c5326619a4d094db6f9e36c18992e0fa62fdc3d1 +Subproject commit 7a8c1d818a835312cc661e941154556ace0d70b4