diff --git a/beacon_chain/el/el_manager.nim b/beacon_chain/el/el_manager.nim index e7bc1377f..d9bff2662 100644 --- a/beacon_chain/el/el_manager.nim +++ b/beacon_chain/el/el_manager.nim @@ -491,9 +491,11 @@ func asConsensusType*(payload: engine_api.GetPayloadV3Response): # Both are defined as `array[N, byte]` under the hood. blobsBundle: deneb.BlobsBundle( commitments: KzgCommitments.init( - payload.blobsBundle.commitments.mapIt(it.bytes)), + payload.blobsBundle.commitments.mapIt( + kzg_abi.KzgCommitment(bytes: it.bytes))), proofs: KzgProofs.init( - payload.blobsBundle.proofs.mapIt(it.bytes)), + payload.blobsBundle.proofs.mapIt( + kzg_abi.KzgProof(bytes: it.bytes))), blobs: Blobs.init( payload.blobsBundle.blobs.mapIt(it.bytes)))) @@ -568,9 +570,11 @@ func asConsensusType*(payload: engine_api.GetPayloadV4Response): # Both are defined as `array[N, byte]` under the hood. blobsBundle: deneb.BlobsBundle( commitments: KzgCommitments.init( - payload.blobsBundle.commitments.mapIt(it.bytes)), + payload.blobsBundle.commitments.mapIt( + kzg_abi.KzgCommitment(bytes: it.bytes))), proofs: KzgProofs.init( - payload.blobsBundle.proofs.mapIt(it.bytes)), + payload.blobsBundle.proofs.mapIt( + kzg_abi.KzgProof(bytes: it.bytes))), blobs: Blobs.init( payload.blobsBundle.blobs.mapIt(it.bytes)))) diff --git a/beacon_chain/gossip_processing/block_processor.nim b/beacon_chain/gossip_processing/block_processor.nim index 37e1174be..a89023812 100644 --- a/beacon_chain/gossip_processing/block_processor.nim +++ b/beacon_chain/gossip_processing/block_processor.nim @@ -186,7 +186,7 @@ proc storeBackfillBlock( let blobs = blobsOpt.get() let kzgCommits = signedBlock.message.body.blob_kzg_commitments.asSeq if blobs.len > 0 or kzgCommits.len > 0: - let r = validate_blobs(kzgCommits, blobs.mapIt(it.blob), + let r = validate_blobs(kzgCommits, blobs.mapIt(KzgBlob(bytes: it.blob)), blobs.mapIt(it.kzg_proof)) if r.isErr(): debug "backfill blob validation failed", @@ -578,7 +578,7 @@ proc storeBlock( let blobs = blobsOpt.get() let kzgCommits = signedBlock.message.body.blob_kzg_commitments.asSeq if blobs.len > 0 or kzgCommits.len > 0: - let r = validate_blobs(kzgCommits, blobs.mapIt(it.blob), + let r = validate_blobs(kzgCommits, blobs.mapIt(KzgBlob(bytes: it.blob)), blobs.mapIt(it.kzg_proof)) if r.isErr(): debug "blob validation failed", diff --git a/beacon_chain/gossip_processing/gossip_validation.nim b/beacon_chain/gossip_processing/gossip_validation.nim index 9f8659488..8b417836f 100644 --- a/beacon_chain/gossip_processing/gossip_validation.nim +++ b/beacon_chain/gossip_processing/gossip_validation.nim @@ -458,7 +458,7 @@ proc validateBlobSidecar*( # blob_sidecar.blob, blob_sidecar.kzg_commitment, blob_sidecar.kzg_proof)`. block: let ok = verifyProof( - blob_sidecar.blob, + KzgBlob(bytes: blob_sidecar.blob), blob_sidecar.kzg_commitment, blob_sidecar.kzg_proof).valueOr: return dag.checkedReject("BlobSidecar: blob verify failed") diff --git a/beacon_chain/spec/datatypes/deneb.nim b/beacon_chain/spec/datatypes/deneb.nim index 722094948..d2b9ae24c 100644 --- a/beacon_chain/spec/datatypes/deneb.nim +++ b/beacon_chain/spec/datatypes/deneb.nim @@ -528,7 +528,7 @@ func initHashedBeaconState*(s: BeaconState): HashedBeaconState = HashedBeaconState(data: s) func shortLog*(v: KzgCommitment | KzgProof): auto = - to0xHex(v) + to0xHex(v.bytes) func shortLog*(v: Blob): auto = to0xHex(v.toOpenArray(0, 31)) diff --git a/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim b/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim index d2a223f32..45b5e372b 100644 --- a/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim +++ b/beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim @@ -1362,7 +1362,7 @@ proc readValue*(reader: var JsonReader[RestJson], value: var (KzgCommitment|KzgProof)) {. raises: [IOError, SerializationError].} = try: - hexToByteArray(reader.readValue(string), distinctBase(value)) + hexToByteArray(reader.readValue(string), distinctBase(value.bytes)) except ValueError: raiseUnexpectedValue(reader, "KzgCommitment value should be a valid hex string") @@ -1370,7 +1370,7 @@ proc readValue*(reader: var JsonReader[RestJson], proc writeValue*( writer: var JsonWriter[RestJson], value: KzgCommitment | KzgProof ) {.raises: [IOError].} = - writeValue(writer, hexOriginal(distinctBase(value))) + writeValue(writer, hexOriginal(distinctBase(value.bytes))) ## GraffitiBytes proc writeValue*( diff --git a/beacon_chain/spec/state_transition_block.nim b/beacon_chain/spec/state_transition_block.nim index e9ad6237e..eb8bd16b0 100644 --- a/beacon_chain/spec/state_transition_block.nim +++ b/beacon_chain/spec/state_transition_block.nim @@ -1085,7 +1085,7 @@ func kzg_commitment_to_versioned_hash*( var res: VersionedHash res[0] = VERSIONED_HASH_VERSION_KZG - res[1 .. 31] = eth2digest(kzg_commitment).data.toOpenArray(1, 31) + res[1 .. 31] = eth2digest(kzg_commitment.bytes).data.toOpenArray(1, 31) res proc validate_blobs*( diff --git a/beacon_chain/validators/message_router.nim b/beacon_chain/validators/message_router.nim index c70adb743..2ebd2e65a 100644 --- a/beacon_chain/validators/message_router.nim +++ b/beacon_chain/validators/message_router.nim @@ -117,8 +117,10 @@ proc routeSignedBeaconBlock*( let blobs = blobsOpt.get() let kzgCommits = blck.message.body.blob_kzg_commitments.asSeq if blobs.len > 0 or kzgCommits.len > 0: - let res = validate_blobs(kzgCommits, blobs.mapIt(it.blob), - blobs.mapIt(it.kzg_proof)) + let res = validate_blobs( + kzgCommits, + blobs.mapIt(KzgBlob(bytes: it.blob)), + blobs.mapIt(it.kzg_proof)) if res.isErr(): warn "blobs failed validation", blockRoot = shortLog(blck.root), diff --git a/beacon_chain/validators/message_router_mev.nim b/beacon_chain/validators/message_router_mev.nim index 7dad0b76d..049b956b4 100644 --- a/beacon_chain/validators/message_router_mev.nim +++ b/beacon_chain/validators/message_router_mev.nim @@ -129,7 +129,7 @@ proc unblindAndRouteBlockMEV*( bundle.data.blobs_bundle.commitments: return err("unblinded blobs bundle has unexpected commitments") let ok = verifyProofs( - asSeq blobs_bundle.blobs, + blobs_bundle.blobs.mapIt(KzgBlob(bytes: it)), asSeq blobs_bundle.commitments, asSeq blobs_bundle.proofs).valueOr: return err("unblinded blobs bundle fails verification") diff --git a/tests/consensus_spec/test_fixture_fork_choice.nim b/tests/consensus_spec/test_fixture_fork_choice.nim index 8334ef825..163996b8f 100644 --- a/tests/consensus_spec/test_fixture_fork_choice.nim +++ b/tests/consensus_spec/test_fixture_fork_choice.nim @@ -136,7 +136,8 @@ proc loadOps( blobs: distinctBase(parseTest( path/(step["blobs"].getStr()) & ".ssz_snappy", SSZ, List[KzgBlob, Limit MAX_BLOBS_PER_BLOCK])), - proofs: step["proofs"].mapIt(KzgProof.fromHex(it.getStr()))) + proofs: step["proofs"].mapIt( + KzgProof(bytes: fromHex(array[48, byte], it.getStr())))) else: Opt.none(BlobData) else: @@ -407,4 +408,4 @@ from ../../beacon_chain/conf import loadKzgTrustedSetup discard loadKzgTrustedSetup() # Required for Deneb tests fcSuite("ForkChoice", "fork_choice") -fcSuite("Sync", "sync") \ No newline at end of file +fcSuite("Sync", "sync") diff --git a/tests/consensus_spec/test_fixture_kzg.nim b/tests/consensus_spec/test_fixture_kzg.nim index 94a0610d9..8ce41b25c 100644 --- a/tests/consensus_spec/test_fixture_kzg.nim +++ b/tests/consensus_spec/test_fixture_kzg.nim @@ -50,12 +50,12 @@ proc runBlobToKzgCommitmentTest(suiteName, suitePath, path: string) = if blob.isNone: check output.kind == JNull else: - let commitment = blobToKzgCommitment(blob.get) + let commitment = blobToKzgCommitment(KzgBlob(bytes: blob.get)) check: if commitment.isErr: output.kind == JNull else: - commitment.get == fromHex[48](output.getStr).get + commitment.get().bytes == fromHex[48](output.getStr).get proc runVerifyKzgProofTest(suiteName, suitePath, path: string) = let relativePathComponent = path.relativeTestPathComponent(suitePath) @@ -75,7 +75,10 @@ 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(commitment.get, z.get, y.get, proof.get) + let v = verifyProof( + KzgCommitment(bytes: commitment.get), + KzgBytes32(bytes: z.get), KzgBytes32(bytes: y.get), + KzgBytes48(bytes: proof.get)) check: if v.isErr: output.kind == JNull @@ -100,7 +103,10 @@ proc runVerifyBlobKzgProofTest(suiteName, suitePath, path: string) = if blob.isNone or commitment.isNone or proof.isNone: check output.kind == JNull else: - let v = verifyBlobKzgProof(blob.get, commitment.get, proof.get) + let v = verifyBlobKzgProof( + KzgBlob(bytes: blob.get), + KzgBytes48(bytes: commitment.get), + KzgBytes48(bytes: proof.get)) check: if v.isErr: output.kind == JNull @@ -127,7 +133,9 @@ proc runVerifyBlobKzgProofBatchTest(suiteName, suitePath, path: string) = check output.kind == JNull else: let v = verifyBlobKzgProofBatch( - blobs.mapIt(it.get), commitments.mapIt(it.get), proofs.mapIt(it.get)) + blobs.mapIt(KzgBlob(bytes: it.get)), + commitments.mapIt(KzgCommitment(bytes: it.get)), + proofs.mapIt(KzgProof(bytes: it.get))) check: if v.isErr: output.kind == JNull @@ -150,7 +158,8 @@ proc runComputeKzgProofTest(suiteName, suitePath, path: string) = if blob.isNone or z.isNone: check output.kind == JNull else: - let p = computeKzgProof(blob.get, z.get) + let p = computeKzgProof( + KzgBlob(bytes: blob.get), KzgBytes32(bytes: z.get)) if p.isErr: check output.kind == JNull else: @@ -158,8 +167,8 @@ proc runComputeKzgProofTest(suiteName, suitePath, path: string) = proof = fromHex[48](output[0].getStr) y = fromHex[32](output[1].getStr) check: - p.get.proof == proof.get - p.get.y == y.get + p.get.proof.bytes == proof.get + p.get.y.bytes == y.get proc runComputeBlobKzgProofTest(suiteName, suitePath, path: string) = let relativePathComponent = path.relativeTestPathComponent(suitePath) @@ -177,11 +186,12 @@ proc runComputeBlobKzgProofTest(suiteName, suitePath, path: string) = if blob.isNone or commitment.isNone: check output.kind == JNull else: - let p = computeBlobKzgProof(blob.get, commitment.get) + let p = computeBlobKzgProof( + KzgBlob(bytes: blob.get), KzgBytes48(bytes: commitment.get)) if p.isErr: check output.kind == JNull else: - check p.get == fromHex[48](output.getStr).get + check p.get.bytes == fromHex[48](output.getStr).get from std/algorithm import sorted @@ -227,4 +237,4 @@ suite suiteName: for kind, path in walkDir(testsDir, relative = true, checkDir = true): runComputeBlobKzgProofTest(suiteName, testsDir, testsDir / path) -doAssert Kzg.freeTrustedSetup().isOk \ No newline at end of file +doAssert Kzg.freeTrustedSetup().isOk diff --git a/tests/test_rest_json_serialization.nim b/tests/test_rest_json_serialization.nim index ba0404f96..e3d2a7fe9 100644 --- a/tests/test_rest_json_serialization.nim +++ b/tests/test_rest_json_serialization.nim @@ -213,7 +213,7 @@ from stew/byteutils import hexToByteArray func fromHex(T: typedesc[KzgCommitment], s: string): T {. raises: [ValueError].} = var res: T - hexToByteArray(s, res) + hexToByteArray(s, res.bytes) res suite "REST JSON encoding and decoding": @@ -353,4 +353,4 @@ suite "REST JSON encoding and decoding": check: validator.pubkey == ValidatorPubKey.fromHex( "0x933ad9491b62059dd065b560d256d8957a8c402cc6e8d8ee7290ae11e8f7329267a8811c397529dac52ae1342ba58c95")[] - validator.exit_epoch == FAR_FUTURE_EPOCH \ No newline at end of file + validator.exit_epoch == FAR_FUTURE_EPOCH diff --git a/vendor/nim-kzg4844 b/vendor/nim-kzg4844 index f12616d06..2f5cee7be 160000 --- a/vendor/nim-kzg4844 +++ b/vendor/nim-kzg4844 @@ -1 +1 @@ -Subproject commit f12616d0675d9f6346141ca95f0840ab227eb213 +Subproject commit 2f5cee7bea0d62e2b502ff668f752bda7f3eb0c4