From f263e99dc6a92357ada9fa654321878cb0532ddd Mon Sep 17 00:00:00 2001 From: Agnish Ghosh Date: Fri, 16 Aug 2024 01:11:29 +0530 Subject: [PATCH] fixes for new simpler nim bindings --- .gitmodules | 2 +- beacon_chain/conf.nim | 6 +++--- beacon_chain/el/el_manager.nim | 1 + beacon_chain/gossip_processing/gossip_validation.nim | 3 ++- beacon_chain/spec/state_transition_block.nim | 4 ++-- beacon_chain/validators/message_router_mev.nim | 2 +- tests/consensus_spec/test_fixture_kzg.nim | 8 ++++---- vendor/nim-kzg4844 | 2 +- 8 files changed, 15 insertions(+), 13 deletions(-) diff --git a/.gitmodules b/.gitmodules index 532f3df52..7c7d1888f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -214,7 +214,7 @@ path = vendor/nim-kzg4844 url = https://github.com/agnxsh/nim-kzg4844.git ignore = untracked - branch = ckzg-7594/upstream + branch = ckzg-jt-test [submodule "vendor/nim-results"] path = vendor/nim-results url = https://github.com/arnetheduck/nim-results.git diff --git a/beacon_chain/conf.nim b/beacon_chain/conf.nim index 23aec8b90..7af201858 100644 --- a/beacon_chain/conf.nim +++ b/beacon_chain/conf.nim @@ -22,7 +22,7 @@ import eth/p2p/discoveryv5/enr, json_serialization, web3/[primitives, confutils_defs], chronos/transports/common, - kzg4844/kzg_ex, + kzg4844/kzg, ./spec/[engine_authentication, keystore, network, crypto], ./spec/datatypes/base, ./networking/network_metadata, @@ -1508,11 +1508,11 @@ proc loadKzgTrustedSetup*(): Result[void, string] = vendorDir & "/nim-kzg4844/kzg4844/csources/src/trusted_setup.txt") static: doAssert const_preset in ["mainnet", "gnosis", "minimal"] - Kzg.loadTrustedSetupFromString(trustedSetup, 0) + loadTrustedSetupFromString(trustedSetup, 0) proc loadKzgTrustedSetup*(trustedSetupPath: string): Result[void, string] = try: - Kzg.loadTrustedSetupFromString(readFile(trustedSetupPath), 0) + loadTrustedSetupFromString(readFile(trustedSetupPath), 0) except IOError as err: err(err.msg) diff --git a/beacon_chain/el/el_manager.nim b/beacon_chain/el/el_manager.nim index 1a2c99e37..cae39b513 100644 --- a/beacon_chain/el/el_manager.nim +++ b/beacon_chain/el/el_manager.nim @@ -14,6 +14,7 @@ import json_rpc/[client, errors], web3, web3/[engine_api, primitives, conversions], eth/common/eth_types, + kzg4844/[kzg_abi, kzg], results, stew/[assign2, byteutils, objects], # Local modules: diff --git a/beacon_chain/gossip_processing/gossip_validation.nim b/beacon_chain/gossip_processing/gossip_validation.nim index 1f2e3dd35..7ac3d4358 100644 --- a/beacon_chain/gossip_processing/gossip_validation.nim +++ b/beacon_chain/gossip_processing/gossip_validation.nim @@ -11,6 +11,7 @@ import # Status chronicles, chronos, metrics, results, + kzg4844/[kzg, kzg_abi], stew/byteutils, # Internals ../spec/[ @@ -458,7 +459,7 @@ proc validateBlobSidecar*( # [REJECT] The sidecar's blob is valid as verified by `verify_blob_kzg_proof( # blob_sidecar.blob, blob_sidecar.kzg_commitment, blob_sidecar.kzg_proof)`. block: - let ok = verifyProof( + let ok = verifyBlobKzgProof( KzgBlob(bytes: blob_sidecar.blob), blob_sidecar.kzg_commitment, blob_sidecar.kzg_proof).valueOr: diff --git a/beacon_chain/spec/state_transition_block.nim b/beacon_chain/spec/state_transition_block.nim index eb8bd16b0..82e5458a8 100644 --- a/beacon_chain/spec/state_transition_block.nim +++ b/beacon_chain/spec/state_transition_block.nim @@ -29,7 +29,7 @@ import ../extras, ./datatypes/[phase0, altair, bellatrix, deneb], "."/[beaconstate, eth2_merkleization, helpers, validator, signatures], - kzg4844/kzg_abi, kzg4844/kzg_ex + kzg4844/kzg_abi, kzg4844/kzg from std/algorithm import fill, sorted from std/sequtils import count, filterIt, mapIt @@ -1091,7 +1091,7 @@ func kzg_commitment_to_versioned_hash*( proc validate_blobs*( expected_kzg_commitments: seq[KzgCommitment], blobs: seq[KzgBlob], proofs: seq[KzgProof]): Result[void, string] = - let res = verifyProofs(blobs, expected_kzg_commitments, proofs).valueOr: + let res = verifyBlobKzgProofBatch(blobs, expected_kzg_commitments, proofs).valueOr: return err("validate_blobs proof verification error: " & error()) if not res: diff --git a/beacon_chain/validators/message_router_mev.nim b/beacon_chain/validators/message_router_mev.nim index 049b956b4..e2e64a8da 100644 --- a/beacon_chain/validators/message_router_mev.nim +++ b/beacon_chain/validators/message_router_mev.nim @@ -128,7 +128,7 @@ proc unblindAndRouteBlockMEV*( if blindedBlock.message.body.blob_kzg_commitments != bundle.data.blobs_bundle.commitments: return err("unblinded blobs bundle has unexpected commitments") - let ok = verifyProofs( + let ok = verifyBlobKzgProofBatch( blobs_bundle.blobs.mapIt(KzgBlob(bytes: it)), asSeq blobs_bundle.commitments, asSeq blobs_bundle.proofs).valueOr: diff --git a/tests/consensus_spec/test_fixture_kzg.nim b/tests/consensus_spec/test_fixture_kzg.nim index c85227cb7..1036082f3 100644 --- a/tests/consensus_spec/test_fixture_kzg.nim +++ b/tests/consensus_spec/test_fixture_kzg.nim @@ -11,7 +11,7 @@ import std/json, yaml/tojson, - kzg4844/kzg_ex, + kzg4844/kzg, stew/byteutils, ../testutil, ./fixtures_utils, ./os_ops @@ -31,7 +31,7 @@ func fromHex[N: static int](s: string): Opt[array[N, byte]] = block: template sourceDir: string = currentSourcePath.rsplit(DirSep, 1)[0] - doAssert Kzg.loadTrustedSetup( + doAssert loadTrustedSetup( sourceDir & "/../../vendor/nim-kzg4844/kzg4844/csources/src/trusted_setup.txt", 0).isOk @@ -75,7 +75,7 @@ proc runVerifyKzgProofTest(suiteName, suitePath, path: string) = if commitment.isNone or z.isNone or y.isNone or proof.isNone: check output.kind == JNull else: - let v = verifyProof( + let v = verifyKzgProof( KzgCommitment(bytes: commitment.get), KzgBytes32(bytes: z.get), KzgBytes32(bytes: y.get), KzgBytes48(bytes: proof.get)) @@ -237,4 +237,4 @@ suite suiteName: for kind, path in walkDir(testsDir, relative = true, checkDir = true): runComputeBlobKzgProofTest(suiteName, testsDir, testsDir / path) -doAssert Kzg.freeTrustedSetup().isOk +doAssert freeTrustedSetup().isOk diff --git a/vendor/nim-kzg4844 b/vendor/nim-kzg4844 index e576c9bab..b602f5684 160000 --- a/vendor/nim-kzg4844 +++ b/vendor/nim-kzg4844 @@ -1 +1 @@ -Subproject commit e576c9bab93c425c6c8c0f3603d98a149599d942 +Subproject commit b602f5684c6aa535bb5aae8619df67527dd369e5