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.
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))))

View File

@ -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",

View File

@ -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")

View File

@ -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))

View File

@ -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*(

View File

@ -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*(

View File

@ -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),

View File

@ -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")

View File

@ -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")
fcSuite("Sync", "sync")

View File

@ -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
doAssert Kzg.freeTrustedSetup().isOk

View File

@ -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
validator.exit_epoch == FAR_FUTURE_EPOCH

2
vendor/nim-kzg4844 vendored

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