Fix for gcc-14 issues in kzg-4844. (#6403)

* Bump nim-kzg4844.

* Fix code to use proper KZG types.

* Add missing coma.

* Fix compilation issue.

* Bump nim-kzg4844.

* Add debugging output.

* Remove debugging output.

* Restore groupBlobs function.
This commit is contained in:
Eugene Kabanov 2024-07-03 13:01:33 +03:00 committed by GitHub
parent e54b3e8fda
commit 84a35c85c5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 47 additions and 30 deletions

View File

@ -491,9 +491,11 @@ func asConsensusType*(payload: engine_api.GetPayloadV3Response):
# Both are defined as `array[N, byte]` under the hood. # Both are defined as `array[N, byte]` under the hood.
blobsBundle: deneb.BlobsBundle( blobsBundle: deneb.BlobsBundle(
commitments: KzgCommitments.init( commitments: KzgCommitments.init(
payload.blobsBundle.commitments.mapIt(it.bytes)), payload.blobsBundle.commitments.mapIt(
kzg_abi.KzgCommitment(bytes: it.bytes))),
proofs: KzgProofs.init( proofs: KzgProofs.init(
payload.blobsBundle.proofs.mapIt(it.bytes)), payload.blobsBundle.proofs.mapIt(
kzg_abi.KzgProof(bytes: it.bytes))),
blobs: Blobs.init( blobs: Blobs.init(
payload.blobsBundle.blobs.mapIt(it.bytes)))) 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. # Both are defined as `array[N, byte]` under the hood.
blobsBundle: deneb.BlobsBundle( blobsBundle: deneb.BlobsBundle(
commitments: KzgCommitments.init( commitments: KzgCommitments.init(
payload.blobsBundle.commitments.mapIt(it.bytes)), payload.blobsBundle.commitments.mapIt(
kzg_abi.KzgCommitment(bytes: it.bytes))),
proofs: KzgProofs.init( proofs: KzgProofs.init(
payload.blobsBundle.proofs.mapIt(it.bytes)), payload.blobsBundle.proofs.mapIt(
kzg_abi.KzgProof(bytes: it.bytes))),
blobs: Blobs.init( blobs: Blobs.init(
payload.blobsBundle.blobs.mapIt(it.bytes)))) payload.blobsBundle.blobs.mapIt(it.bytes))))

View File

@ -186,7 +186,7 @@ proc storeBackfillBlock(
let blobs = blobsOpt.get() let blobs = blobsOpt.get()
let kzgCommits = signedBlock.message.body.blob_kzg_commitments.asSeq let kzgCommits = signedBlock.message.body.blob_kzg_commitments.asSeq
if blobs.len > 0 or kzgCommits.len > 0: 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)) blobs.mapIt(it.kzg_proof))
if r.isErr(): if r.isErr():
debug "backfill blob validation failed", debug "backfill blob validation failed",
@ -578,7 +578,7 @@ proc storeBlock(
let blobs = blobsOpt.get() let blobs = blobsOpt.get()
let kzgCommits = signedBlock.message.body.blob_kzg_commitments.asSeq let kzgCommits = signedBlock.message.body.blob_kzg_commitments.asSeq
if blobs.len > 0 or kzgCommits.len > 0: 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)) blobs.mapIt(it.kzg_proof))
if r.isErr(): if r.isErr():
debug "blob validation failed", debug "blob validation failed",

View File

@ -458,7 +458,7 @@ proc validateBlobSidecar*(
# blob_sidecar.blob, blob_sidecar.kzg_commitment, blob_sidecar.kzg_proof)`. # blob_sidecar.blob, blob_sidecar.kzg_commitment, blob_sidecar.kzg_proof)`.
block: block:
let ok = verifyProof( let ok = verifyProof(
blob_sidecar.blob, KzgBlob(bytes: blob_sidecar.blob),
blob_sidecar.kzg_commitment, blob_sidecar.kzg_commitment,
blob_sidecar.kzg_proof).valueOr: blob_sidecar.kzg_proof).valueOr:
return dag.checkedReject("BlobSidecar: blob verify failed") return dag.checkedReject("BlobSidecar: blob verify failed")

View File

@ -528,7 +528,7 @@ func initHashedBeaconState*(s: BeaconState): HashedBeaconState =
HashedBeaconState(data: s) HashedBeaconState(data: s)
func shortLog*(v: KzgCommitment | KzgProof): auto = func shortLog*(v: KzgCommitment | KzgProof): auto =
to0xHex(v) to0xHex(v.bytes)
func shortLog*(v: Blob): auto = func shortLog*(v: Blob): auto =
to0xHex(v.toOpenArray(0, 31)) to0xHex(v.toOpenArray(0, 31))

View File

@ -1362,7 +1362,7 @@ proc readValue*(reader: var JsonReader[RestJson],
value: var (KzgCommitment|KzgProof)) {. value: var (KzgCommitment|KzgProof)) {.
raises: [IOError, SerializationError].} = raises: [IOError, SerializationError].} =
try: try:
hexToByteArray(reader.readValue(string), distinctBase(value)) hexToByteArray(reader.readValue(string), distinctBase(value.bytes))
except ValueError: except ValueError:
raiseUnexpectedValue(reader, raiseUnexpectedValue(reader,
"KzgCommitment value should be a valid hex string") "KzgCommitment value should be a valid hex string")
@ -1370,7 +1370,7 @@ proc readValue*(reader: var JsonReader[RestJson],
proc writeValue*( proc writeValue*(
writer: var JsonWriter[RestJson], value: KzgCommitment | KzgProof writer: var JsonWriter[RestJson], value: KzgCommitment | KzgProof
) {.raises: [IOError].} = ) {.raises: [IOError].} =
writeValue(writer, hexOriginal(distinctBase(value))) writeValue(writer, hexOriginal(distinctBase(value.bytes)))
## GraffitiBytes ## GraffitiBytes
proc writeValue*( proc writeValue*(

View File

@ -1085,7 +1085,7 @@ func kzg_commitment_to_versioned_hash*(
var res: VersionedHash var res: VersionedHash
res[0] = VERSIONED_HASH_VERSION_KZG 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 res
proc validate_blobs*( proc validate_blobs*(

View File

@ -117,7 +117,9 @@ proc routeSignedBeaconBlock*(
let blobs = blobsOpt.get() let blobs = blobsOpt.get()
let kzgCommits = blck.message.body.blob_kzg_commitments.asSeq let kzgCommits = blck.message.body.blob_kzg_commitments.asSeq
if blobs.len > 0 or kzgCommits.len > 0: if blobs.len > 0 or kzgCommits.len > 0:
let res = validate_blobs(kzgCommits, blobs.mapIt(it.blob), let res = validate_blobs(
kzgCommits,
blobs.mapIt(KzgBlob(bytes: it.blob)),
blobs.mapIt(it.kzg_proof)) blobs.mapIt(it.kzg_proof))
if res.isErr(): if res.isErr():
warn "blobs failed validation", warn "blobs failed validation",

View File

@ -129,7 +129,7 @@ proc unblindAndRouteBlockMEV*(
bundle.data.blobs_bundle.commitments: bundle.data.blobs_bundle.commitments:
return err("unblinded blobs bundle has unexpected commitments") return err("unblinded blobs bundle has unexpected commitments")
let ok = verifyProofs( let ok = verifyProofs(
asSeq blobs_bundle.blobs, blobs_bundle.blobs.mapIt(KzgBlob(bytes: it)),
asSeq blobs_bundle.commitments, asSeq blobs_bundle.commitments,
asSeq blobs_bundle.proofs).valueOr: asSeq blobs_bundle.proofs).valueOr:
return err("unblinded blobs bundle fails verification") return err("unblinded blobs bundle fails verification")

View File

@ -136,7 +136,8 @@ proc loadOps(
blobs: distinctBase(parseTest( blobs: distinctBase(parseTest(
path/(step["blobs"].getStr()) & ".ssz_snappy", path/(step["blobs"].getStr()) & ".ssz_snappy",
SSZ, List[KzgBlob, Limit MAX_BLOBS_PER_BLOCK])), 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: else:
Opt.none(BlobData) Opt.none(BlobData)
else: else:

View File

@ -50,12 +50,12 @@ proc runBlobToKzgCommitmentTest(suiteName, suitePath, path: string) =
if blob.isNone: if blob.isNone:
check output.kind == JNull check output.kind == JNull
else: else:
let commitment = blobToKzgCommitment(blob.get) let commitment = blobToKzgCommitment(KzgBlob(bytes: blob.get))
check: check:
if commitment.isErr: if commitment.isErr:
output.kind == JNull output.kind == JNull
else: else:
commitment.get == fromHex[48](output.getStr).get commitment.get().bytes == fromHex[48](output.getStr).get
proc runVerifyKzgProofTest(suiteName, suitePath, path: string) = proc runVerifyKzgProofTest(suiteName, suitePath, path: string) =
let relativePathComponent = path.relativeTestPathComponent(suitePath) 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: if commitment.isNone or z.isNone or y.isNone or proof.isNone:
check output.kind == JNull check output.kind == JNull
else: 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: check:
if v.isErr: if v.isErr:
output.kind == JNull output.kind == JNull
@ -100,7 +103,10 @@ proc runVerifyBlobKzgProofTest(suiteName, suitePath, path: string) =
if blob.isNone or commitment.isNone or proof.isNone: if blob.isNone or commitment.isNone or proof.isNone:
check output.kind == JNull check output.kind == JNull
else: 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: check:
if v.isErr: if v.isErr:
output.kind == JNull output.kind == JNull
@ -127,7 +133,9 @@ proc runVerifyBlobKzgProofBatchTest(suiteName, suitePath, path: string) =
check output.kind == JNull check output.kind == JNull
else: else:
let v = verifyBlobKzgProofBatch( 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: check:
if v.isErr: if v.isErr:
output.kind == JNull output.kind == JNull
@ -150,7 +158,8 @@ proc runComputeKzgProofTest(suiteName, suitePath, path: string) =
if blob.isNone or z.isNone: if blob.isNone or z.isNone:
check output.kind == JNull check output.kind == JNull
else: else:
let p = computeKzgProof(blob.get, z.get) let p = computeKzgProof(
KzgBlob(bytes: blob.get), KzgBytes32(bytes: z.get))
if p.isErr: if p.isErr:
check output.kind == JNull check output.kind == JNull
else: else:
@ -158,8 +167,8 @@ proc runComputeKzgProofTest(suiteName, suitePath, path: string) =
proof = fromHex[48](output[0].getStr) proof = fromHex[48](output[0].getStr)
y = fromHex[32](output[1].getStr) y = fromHex[32](output[1].getStr)
check: check:
p.get.proof == proof.get p.get.proof.bytes == proof.get
p.get.y == y.get p.get.y.bytes == y.get
proc runComputeBlobKzgProofTest(suiteName, suitePath, path: string) = proc runComputeBlobKzgProofTest(suiteName, suitePath, path: string) =
let relativePathComponent = path.relativeTestPathComponent(suitePath) let relativePathComponent = path.relativeTestPathComponent(suitePath)
@ -177,11 +186,12 @@ proc runComputeBlobKzgProofTest(suiteName, suitePath, path: string) =
if blob.isNone or commitment.isNone: if blob.isNone or commitment.isNone:
check output.kind == JNull check output.kind == JNull
else: else:
let p = computeBlobKzgProof(blob.get, commitment.get) let p = computeBlobKzgProof(
KzgBlob(bytes: blob.get), KzgBytes48(bytes: commitment.get))
if p.isErr: if p.isErr:
check output.kind == JNull check output.kind == JNull
else: else:
check p.get == fromHex[48](output.getStr).get check p.get.bytes == fromHex[48](output.getStr).get
from std/algorithm import sorted from std/algorithm import sorted

View File

@ -213,7 +213,7 @@ from stew/byteutils import hexToByteArray
func fromHex(T: typedesc[KzgCommitment], s: string): T {. func fromHex(T: typedesc[KzgCommitment], s: string): T {.
raises: [ValueError].} = raises: [ValueError].} =
var res: T var res: T
hexToByteArray(s, res) hexToByteArray(s, res.bytes)
res res
suite "REST JSON encoding and decoding": suite "REST JSON encoding and decoding":

2
vendor/nim-kzg4844 vendored

@ -1 +1 @@
Subproject commit f12616d0675d9f6346141ca95f0840ab227eb213 Subproject commit 2f5cee7bea0d62e2b502ff668f752bda7f3eb0c4