Skip to content
Open
10 changes: 5 additions & 5 deletions bindings/c/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ pub unsafe extern "C" fn free_error_message(c_message: *mut std::os::raw::c_char
/// If the other arguments are null, this method will dereference a null pointer and result in undefined behavior.
#[no_mangle]
#[must_use]
pub extern "C" fn blob_to_kzg_commitment(
pub extern "C" fn peerdas_blob_to_kzg_commitment(
ctx: *const PeerDASContext,

blob: *const u8,
Expand Down Expand Up @@ -184,7 +184,7 @@ pub extern "C" fn blob_to_kzg_commitment(
/// If the other arguments are null, this method will dereference a null pointer and result in undefined behavior.
#[no_mangle]
#[must_use]
pub extern "C" fn compute_cells_and_kzg_proofs(
pub extern "C" fn peerdas_compute_cells_and_kzg_proofs(
ctx: *const PeerDASContext,

blob: *const u8,
Expand Down Expand Up @@ -214,7 +214,7 @@ pub extern "C" fn compute_cells_and_kzg_proofs(
///
#[no_mangle]
#[must_use]
pub extern "C" fn verify_cell_kzg_proof(
pub extern "C" fn peerdas_verify_cell_kzg_proof(
ctx: *const PeerDASContext,
cell: *const u8,
commitment: *const u8,
Expand Down Expand Up @@ -269,7 +269,7 @@ fn verification_result_to_bool_cresult(
/// If the other arguments are null, this method will dereference a null pointer and result in undefined behavior.
#[no_mangle]
#[must_use]
pub extern "C" fn verify_cell_kzg_proof_batch(
pub extern "C" fn peerdas_verify_cell_kzg_proof_batch(
ctx: *const PeerDASContext,

row_commitments_length: u64,
Expand Down Expand Up @@ -332,7 +332,7 @@ pub extern "C" fn verify_cell_kzg_proof_batch(
/// If the other arguments are null, this method will dereference a null pointer and result in undefined behavior.
#[no_mangle]
#[must_use]
pub extern "C" fn recover_cells_and_proofs(
pub extern "C" fn peerdas_recover_cells_and_proofs(
ctx: *const PeerDASContext,

cells_length: u64,
Expand Down
4 changes: 2 additions & 2 deletions bindings/nim/nim_code/nim_peerdas_kzg/build_utils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const

proc getInstallDir*(): string =
when defined(macosx):
when defined(aarch64) or defined(amd64):
when defined(aarch64) or defined(amd64) or defined(arm64):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In nimbus, it was returning arm64 instead of aarch64

return universalAppleDarwin
else:
raise newException(ValueError, "Unsupported architecture on macOS")
Expand All @@ -21,7 +21,7 @@ proc getInstallDir*(): string =
elif defined(linux):
when defined(amd64):
return x86_64UnknownLinuxGnu
elif defined(aarch64):
elif defined(aarch64) or defined(arm64):
return aarch64UnknownLinuxGnu
else:
raise newException(ValueError, "Unsupported architecture on Linux")
Expand Down
64 changes: 32 additions & 32 deletions bindings/nim/nim_code/nim_peerdas_kzg/header.nim
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ proc free_error_message*(c_message: pointer): void {.importc: "free_error_messag
#
# - This implementation will check if the ctx pointer is null, but it will not check if the other arguments are null.
# If the other arguments are null, this method will dereference a null pointer and result in undefined behavior.
proc blob_to_kzg_commitment*(ctx: ptr PeerDASContext,
blob: pointer,
outx: pointer): CResult {.importc: "blob_to_kzg_commitment".}
proc peerdas_blob_to_kzg_commitment*(ctx: ptr PeerDASContext,
blob: pointer,
outx: pointer): CResult {.importc: "peerdas_blob_to_kzg_commitment".}

## Computes the cells and KZG proofs for a given blob.
#
Expand All @@ -78,10 +78,10 @@ proc blob_to_kzg_commitment*(ctx: ptr PeerDASContext,
#
# - This implementation will check if the ctx pointer is null, but it will not check if the other arguments are null.
# If the other arguments are null, this method will dereference a null pointer and result in undefined behavior.
proc compute_cells_and_kzg_proofs*(ctx: ptr PeerDASContext,
blob: pointer,
out_cells: ptr pointer,
out_proofs: ptr pointer): CResult {.importc: "compute_cells_and_kzg_proofs".}
proc peerdas_compute_cells_and_kzg_proofs*(ctx: ptr PeerDASContext,
blob: pointer,
out_cells: ptr pointer,
out_proofs: ptr pointer): CResult {.importc: "peerdas_compute_cells_and_kzg_proofs".}

## Verifies a cell corresponds to a particular commitment.
#
Expand All @@ -96,12 +96,12 @@ proc compute_cells_and_kzg_proofs*(ctx: ptr PeerDASContext,
# - This implementation will check if the ctx pointer is null, but it will not check if the other arguments are null.
# If the other arguments are null, this method will dereference a null pointer and result in undefined behavior.
#
proc verify_cell_kzg_proof*(ctx: ptr PeerDASContext,
cell: pointer,
commitment: pointer,
cell_id: uint64,
proof: pointer,
verified: pointer): CResult {.importc: "verify_cell_kzg_proof".}
proc peerdas_verify_cell_kzg_proof*(ctx: ptr PeerDASContext,
cell: pointer,
commitment: pointer,
cell_id: uint64,
proof: pointer,
verified: pointer): CResult {.importc: "peerdas_verify_cell_kzg_proof".}

## Verifies a batch of cells and their KZG proofs.
#
Expand All @@ -128,18 +128,18 @@ proc verify_cell_kzg_proof*(ctx: ptr PeerDASContext,
#
# - This implementation will check if the ctx pointer is null, but it will not check if the other arguments are null.
# If the other arguments are null, this method will dereference a null pointer and result in undefined behavior.
proc verify_cell_kzg_proof_batch*(ctx: ptr PeerDASContext,
row_commitments_length: uint64,
row_commitments: ptr pointer,
row_indices_length: uint64,
row_indices: pointer,
column_indices_length: uint64,
column_indices: pointer,
cells_length: uint64,
cells: ptr pointer,
proofs_length: uint64,
proofs: ptr pointer,
verified: pointer): CResult {.importc: "verify_cell_kzg_proof_batch".}
proc peerdas_verify_cell_kzg_proof_batch*(ctx: ptr PeerDASContext,
row_commitments_length: uint64,
row_commitments: ptr pointer,
row_indices_length: uint64,
row_indices: pointer,
column_indices_length: uint64,
column_indices: pointer,
cells_length: uint64,
cells: ptr pointer,
proofs_length: uint64,
proofs: ptr pointer,
verified: pointer): CResult {.importc: "peerdas_verify_cell_kzg_proof_batch".}

## Recovers all cells and their KZG proofs from the given cell ids and cells
#
Expand All @@ -163,13 +163,13 @@ proc verify_cell_kzg_proof_batch*(ctx: ptr PeerDASContext,
#
# - This implementation will check if the ctx pointer is null, but it will not check if the other arguments are null.
# If the other arguments are null, this method will dereference a null pointer and result in undefined behavior.
proc recover_cells_and_proofs*(ctx: ptr PeerDASContext,
cells_length: uint64,
cells: ptr pointer,
cell_ids_length: uint64,
cell_ids: pointer,
out_cells: ptr pointer,
out_proofs: ptr pointer): CResult {.importc: "recover_cells_and_proofs".}
proc peerdas_recover_cells_and_proofs*(ctx: ptr PeerDASContext,
cells_length: uint64,
cells: ptr pointer,
cell_ids_length: uint64,
cell_ids: pointer,
out_cells: ptr pointer,
out_proofs: ptr pointer): CResult {.importc: "peerdas_recover_cells_and_proofs".}

proc constant_bytes_per_cell*(): uint64 {.importc: "constant_bytes_per_cell".}

Expand Down
18 changes: 10 additions & 8 deletions bindings/nim/nim_code/nim_peerdas_kzg/nim_peerdas_kzg.nim
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,11 @@ type
# for the custom destructor so it must ensure that
# this is not called twice.
# https://forum.nim-lang.org/t/11229
proc `=destroy`(x: typeof KZGCtx()[]) =
if x.ctx_ptr != nil:
peerdas_context_free(x.ctx_ptr)
# TODO: Fix (this does not work in nimbus)
# TOOD: `Error: signature for '=destroy' must be proc[T: object](x: var T)`
# proc `=destroy`(x: typeof KZGCtx()[]) =
# if x.ctx_ptr != nil:
# peerdas_context_free(x.ctx_ptr)

proc newKZGCtx*(): KZGCtx =
var kzgCtx = KZGCtx()
Expand All @@ -94,7 +96,7 @@ proc newKZGCtx*(): KZGCtx =
proc blobToKZGCommitment*(ctx: KZGCtx, blob : Blob): Result[KZGCommitment, string] {.gcsafe.} =
var ret: KZGCommitment

let res = blob_to_kzg_commitment(
let res = peerdas_blob_to_kzg_commitment(
ctx.ctx_ptr,

blob.bytes.getPtr,
Expand All @@ -109,7 +111,7 @@ proc computeCellsAndProofs*(ctx: KZGCtx, blob : Blob): Result[CellsAndProofs, st
let outCellsPtr = toPtrPtr(ret.cells)
let outProofsPtr = toPtrPtr(ret.proofs)

let res = compute_cells_and_kzg_proofs(
let res = peerdas_compute_cells_and_kzg_proofs(
ctx.ctx_ptr,

blob.bytes.getPtr,
Expand All @@ -126,7 +128,7 @@ proc computeCells*(ctx: KZGCtx, blob : Blob): Result[Cells, string] {.gcsafe.} =
proc verifyCellKZGProof*(ctx: KZGCtx, commitment: Bytes48, cellId: uint64, cell: Cell, proof: Bytes48): Result[bool, string] =
var valid: bool

let res = verify_cell_kzg_proof(
let res = peerdas_verify_cell_kzg_proof(
ctx.ctx_ptr,

cell.bytes.getPtr,
Expand All @@ -152,7 +154,7 @@ proc verifyCellKZGProofBatch*(ctx: KZGCtx, rowCommitments: openArray[Bytes48],
let proofsPtr = toPtrPtr(proofs)
let commitmentsPtr = toPtrPtr(rowCommitments)

let res = verify_cell_kzg_proof_batch(
let res = peerdas_verify_cell_kzg_proof_batch(
ctx.ctx_ptr,

uint64(len(rowCommitments)),
Expand Down Expand Up @@ -184,7 +186,7 @@ proc recoverCellsAndProofs*(ctx: KZGCtx,
let outProofsPtr = toPtrPtr(ret.proofs)
let inputCellsPtr = toPtrPtr(cells)

let res = recover_cells_and_proofs(
let res = peerdas_recover_cells_and_proofs(
ctx.ctx_ptr,

uint64(len(cells)),
Expand Down