nim-bindings: fix GCC-14 [-Wincompatible-pointer-types] issue (#430)

This commit is contained in:
andri lim 2024-05-29 21:09:41 +07:00 committed by GitHub
parent b87053224e
commit d7511cd728
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 67 additions and 54 deletions

View File

@ -130,7 +130,7 @@ proc toCommitment*(ctx: KzgCtx,
blob: KzgBlob):
Result[KzgCommitment, string] {.gcsafe.} =
var ret: KzgCommitment
let res = blob_to_kzg_commitment(ret, blob, ctx.val)
let res = blob_to_kzg_commitment(ret, blob.getPtr, ctx.val)
verify(res, ret)
proc computeProof*(ctx: KzgCtx,
@ -140,8 +140,8 @@ proc computeProof*(ctx: KzgCtx,
let res = compute_kzg_proof(
ret.proof,
ret.y,
blob,
z,
blob.getPtr,
z.getPtr,
ctx.val)
verify(res, ret)
@ -151,8 +151,8 @@ proc computeProof*(ctx: KzgCtx,
var proof: KzgProof
let res = compute_blob_kzg_proof(
proof,
blob,
commitmentBytes,
blob.getPtr,
commitmentBytes.getPtr,
ctx.val)
verify(res, proof)
@ -164,10 +164,10 @@ proc verifyProof*(ctx: KzgCtx,
var valid: bool
let res = verify_kzg_proof(
valid,
commitment,
z,
y,
proof,
commitment.getPtr,
z.getPtr,
y.getPtr,
proof.getPtr,
ctx.val)
verify(res, valid)
@ -178,9 +178,9 @@ proc verifyProof*(ctx: KzgCtx,
var valid: bool
let res = verify_blob_kzg_proof(
valid,
blob,
commitment,
proof,
blob.getPtr,
commitment.getPtr,
proof.getPtr,
ctx.val)
verify(res, valid)

View File

@ -57,15 +57,21 @@ type
header: "c_kzg_4844.h", byref.} = object
# A basic blob data.
KzgBlob* = array[KzgBlobSize, byte]
KzgBlob* {.importc: "Blob",
header: "c_kzg_4844.h".} = object
bytes*: array[KzgBlobSize, uint8]
# An array of 48 bytes. Represents an untrusted
# (potentially invalid) commitment/proof.
KzgBytes48* = array[48, byte]
KzgBytes48* {.importc: "Bytes48",
header: "c_kzg_4844.h".} = object
bytes*: array[48, uint8]
# An array of 32 bytes. Represents an untrusted
# (potentially invalid) field element.
KzgBytes32* = array[32, byte]
KzgBytes32* {.importc: "Bytes32",
header: "c_kzg_4844.h".} = object
bytes*: array[32, uint8]
# A trusted (valid) KZG commitment.
KzgCommitment* = KzgBytes48
@ -87,31 +93,31 @@ proc load_trusted_setup_file*(res: KzgSettings,
proc free_trusted_setup*(s: KzgSettings) {.kzg_abi.}
proc blob_to_kzg_commitment*(res: var KzgCommitment,
blob: KzgBlob,
blob: ptr KzgBlob,
s: KzgSettings): KZG_RET {.kzg_abi.}
proc compute_kzg_proof*(res: var KzgProof,
yOut: var KzgBytes32,
blob: KzgBlob,
zBytes: KzgBytes32,
blob: ptr KzgBlob,
zBytes: ptr KzgBytes32,
s: KzgSettings): KZG_RET {.kzg_abi.}
proc compute_blob_kzg_proof*(res: var KzgProof,
blob: KzgBlob,
commitmentBytes: KzgBytes48,
blob: ptr KzgBlob,
commitmentBytes: ptr KzgBytes48,
s: KzgSettings): KZG_RET {.kzg_abi.}
proc verify_kzg_proof*(res: var bool,
commitmentBytes: KzgBytes48,
zBytes: KzgBytes32,
yBytes: KzgBytes32,
proofBytes: KzgBytes48,
commitmentBytes: ptr KzgBytes48,
zBytes: ptr KzgBytes32,
yBytes: ptr KzgBytes32,
proofBytes: ptr KzgBytes48,
s: KzgSettings): KZG_RET {.kzg_abi.}
proc verify_blob_kzg_proof*(res: var bool,
blob: KzgBlob,
commitmentsBytes: KzgBytes48,
proofBytes: KzgBytes48,
blob: ptr KzgBlob,
commitmentsBytes: ptr KzgBytes48,
proofBytes: ptr KzgBytes48,
s: KzgSettings): KZG_RET {.kzg_abi.}
proc verify_blob_kzg_proof_batch*(res: var bool,

View File

@ -45,16 +45,16 @@ proc readSetup(filename: string): KzgSettings =
proc createKateBlobs(s: KzgSettings, n: int): KateBlobs =
for i in 0..<n:
var blob: KzgBlob
discard urandom(blob)
for i in 0..<len(blob):
discard urandom(blob.bytes)
for i in 0..<blob.bytes.len:
# don't overflow modulus
if blob[i] > MAX_TOP_BYTE and i %% BYTES_PER_FIELD_ELEMENT == 0:
blob[i] = MAX_TOP_BYTE
if blob.bytes[i] > MAX_TOP_BYTE and i %% BYTES_PER_FIELD_ELEMENT == 0:
blob.bytes[i] = MAX_TOP_BYTE
result.blobs.add(blob)
for i in 0..<n:
var kate: KzgCommitment
doAssert blob_to_kzg_commitment(kate, result.blobs[i], s) == KZG_OK
doAssert blob_to_kzg_commitment(kate, result.blobs[i].addr, s) == KZG_OK
result.kates.add(kate)
let
@ -69,7 +69,7 @@ suite "verify proof (abi)":
var kp: array[nblobs, KzgProof]
for i in 0..<nblobs:
let res = compute_blob_kzg_proof(kp[i], kb.blobs[i], kb.kates[i], kzgs)
let res = compute_blob_kzg_proof(kp[i], kb.blobs[i].addr, kb.kates[i].addr, kzgs)
check res == KZG_OK
var ok: bool
@ -87,12 +87,12 @@ suite "verify proof (abi)":
var kp: array[nblobs, KzgProof]
for i in 0..<nblobs:
let res = compute_blob_kzg_proof(kp[i], kb.blobs[i], kb.kates[i], kzgs)
let res = compute_blob_kzg_proof(kp[i], kb.blobs[i].addr, kb.kates[i].addr, kzgs)
check res == KZG_OK
var other = kzgs.createKateBlobs(nblobs)
for i in 0..<nblobs:
let res = compute_blob_kzg_proof(kp[i], other.blobs[i], other.kates[i], kzgs)
let res = compute_blob_kzg_proof(kp[i], other.blobs[i].addr, other.kates[i].addr, kzgs)
check res == KZG_OK
var ok: bool
@ -107,24 +107,24 @@ suite "verify proof (abi)":
test "verify blob proof":
var kp: KzgProof
var res = compute_blob_kzg_proof(kp, blob, commitment, kzgs)
var res = compute_blob_kzg_proof(kp, blob.addr, commitment.addr, kzgs)
check res == KZG_OK
var ok: bool
res = verify_blob_kzg_proof(ok, blob, commitment, kp, kzgs)
res = verify_blob_kzg_proof(ok, blob.addr, commitment.addr, kp.addr, kzgs)
check res == KZG_OK
check ok
test "verify proof":
var kp: KzgProof
var ky: KzgBytes32
var res = compute_kzg_proof(kp, ky, blob, inputPoint, kzgs)
var res = compute_kzg_proof(kp, ky, blob.addr, inputPoint.addr, kzgs)
check res == KZG_OK
check kp == proof
check ky == claimedValue
var ok: bool
res = verify_kzg_proof(ok, commitment, inputPoint, claimedValue, kp, kzgs)
res = verify_kzg_proof(ok, commitment.addr, inputPoint.addr, claimedValue.addr, kp.addr, kzgs)
check res == KZG_OK
check ok

View File

@ -8,11 +8,11 @@ import
proc createKateBlobs(ctx: KzgCtx, n: int): KateBlobs =
var blob: KzgBlob
for i in 0..<n:
discard urandom(blob)
for i in 0..<len(blob):
discard urandom(blob.bytes)
for i in 0..<blob.bytes.len:
# don't overflow modulus
if blob[i] > MAX_TOP_BYTE and i %% BYTES_PER_FIELD_ELEMENT == 0:
blob[i] = MAX_TOP_BYTE
if blob.bytes[i] > MAX_TOP_BYTE and i %% BYTES_PER_FIELD_ELEMENT == 0:
blob.bytes[i] = MAX_TOP_BYTE
result.blobs.add(blob)
for i in 0..<n:

View File

@ -8,11 +8,11 @@ import
proc createKateBlobs(n: int): KateBlobs =
var blob: KzgBlob
for i in 0..<n:
discard urandom(blob)
for i in 0..<len(blob):
discard urandom(blob.bytes)
for i in 0..<blob.bytes.len:
# don't overflow modulus
if blob[i] > MAX_TOP_BYTE and i %% BYTES_PER_FIELD_ELEMENT == 0:
blob[i] = MAX_TOP_BYTE
if blob.bytes[i] > MAX_TOP_BYTE and i %% BYTES_PER_FIELD_ELEMENT == 0:
blob.bytes[i] = MAX_TOP_BYTE
result.blobs.add(blob)
for i in 0..<n:

View File

@ -29,9 +29,9 @@ proc loadYaml(filename: string): YamlNode =
s.close()
proc fromHex(T: type, x: string): T =
if (x.len - 2) div 2 > sizeof(T):
if (x.len - 2) div 2 > sizeof(result.bytes):
raise newException(ValueError, "invalid hex")
hexToByteArray(x, sizeof(T))
result.bytes = hexToByteArray(x, sizeof(result.bytes))
proc fromHex(T: type, x: YamlNode): T =
T.fromHex(x.content)

File diff suppressed because one or more lines are too long