From 17a3101e44468e930dd6844165ed0ab01cc9f692 Mon Sep 17 00:00:00 2001 From: Kevaundray Wedderburn Date: Tue, 13 Aug 2024 17:10:29 +0100 Subject: [PATCH 1/8] add namespace to c methods --- bindings/c/src/lib.rs | 29 ++++++--- .../EthKZG.bindings/native_methods.g.cs | 40 ++++++------ bindings/java/rust_code/src/lib.rs | 4 +- bindings/nim/nim_code/nim_eth_kzg/header.nim | 61 ++++++++++--------- 4 files changed, 72 insertions(+), 62 deletions(-) diff --git a/bindings/c/src/lib.rs b/bindings/c/src/lib.rs index 95df0235..10ef0494 100644 --- a/bindings/c/src/lib.rs +++ b/bindings/c/src/lib.rs @@ -18,6 +18,15 @@ pub use rust_eth_kzg::constants::{ }; use rust_eth_kzg::Error; +/** + * Note: All methods in this file have been prefixed with `eth_kzg`. + * This is so that when they are imported into languages such as nim, + * they will have a separate namespace to other c libraries. + * + * ie Nim will take two c libraries and put their methods in the same + * namespace. + */ + // This is a wrapper around the DASContext from the eip7594 library. // We need to wrap it as some bindgen tools cannot pick up items // not defined in this file. @@ -39,7 +48,7 @@ impl DASContext { /// To avoid memory leaks, one should ensure that the pointer is freed after use /// by calling `das_context_free`. #[no_mangle] -pub extern "C" fn das_context_new() -> *mut DASContext { +pub extern "C" fn eth_kzg_das_context_new() -> *mut DASContext { let ctx = Box::::default(); Box::into_raw(ctx) } @@ -59,7 +68,7 @@ pub extern "C" fn das_context_new() -> *mut DASContext { /// a pointer that was not created by `das_context_new`. #[allow(clippy::not_unsafe_ptr_arg_deref)] #[no_mangle] -pub extern "C" fn das_context_free(ctx: *mut DASContext) { +pub extern "C" fn eth_kzg_das_context_free(ctx: *mut DASContext) { if ctx.is_null() { return; } @@ -120,7 +129,7 @@ impl CResult { /// - The caller must ensure that the pointer is valid. If the pointer is null, this method will return early. /// - The caller should also avoid a double-free by setting the pointer to null after calling this method. #[no_mangle] -pub unsafe extern "C" fn free_error_message(c_message: *mut std::os::raw::c_char) { +pub unsafe extern "C" fn eth_kzg_free_error_message(c_message: *mut std::os::raw::c_char) { // check if the pointer is null if c_message.is_null() { return; @@ -145,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 eth_kzg_blob_to_kzg_commitment( ctx: *const DASContext, blob: *const u8, @@ -175,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 eth_kzg_compute_cells_and_kzg_proofs( ctx: *const DASContext, blob: *const u8, @@ -230,7 +239,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 eth_kzg_verify_cell_kzg_proof_batch( ctx: *const DASContext, commitments_length: u64, @@ -288,7 +297,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 eth_kzg_recover_cells_and_proofs( ctx: *const DASContext, cells_length: u64, @@ -317,14 +326,14 @@ pub extern "C" fn recover_cells_and_proofs( // Expose the constants to the C API so that languages that have to define them // manually can use them in tests. #[no_mangle] -pub extern "C" fn constant_bytes_per_cell() -> u64 { +pub extern "C" fn eth_kzg_constant_bytes_per_cell() -> u64 { BYTES_PER_CELL as u64 } #[no_mangle] -pub extern "C" fn constant_bytes_per_proof() -> u64 { +pub extern "C" fn eth_kzg_constant_bytes_per_proof() -> u64 { BYTES_PER_COMMITMENT as u64 } #[no_mangle] -pub extern "C" fn constant_cells_per_ext_blob() -> u64 { +pub extern "C" fn eth_kzg_constant_cells_per_ext_blob() -> u64 { CELLS_PER_EXT_BLOB as u64 } diff --git a/bindings/csharp/csharp_code/EthKZG.bindings/native_methods.g.cs b/bindings/csharp/csharp_code/EthKZG.bindings/native_methods.g.cs index 09ed63b1..d692aae6 100644 --- a/bindings/csharp/csharp_code/EthKZG.bindings/native_methods.g.cs +++ b/bindings/csharp/csharp_code/EthKZG.bindings/native_methods.g.cs @@ -24,8 +24,8 @@ internal static unsafe partial class NativeMethods /// To avoid memory leaks, one should ensure that the pointer is freed after use /// by calling `das_context_free`. /// - [DllImport(__DllName, EntryPoint = "das_context_new", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] - internal static extern DASContext* das_context_new(); + [DllImport(__DllName, EntryPoint = "eth_kzg_das_context_new", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern DASContext* eth_kzg_das_context_new(); /// /// # Safety @@ -42,8 +42,8 @@ internal static unsafe partial class NativeMethods /// - Since the `ctx` is created in Rust, we can only get undefined behavior, if the caller passes in /// a pointer that was not created by `das_context_new`. /// - [DllImport(__DllName, EntryPoint = "das_context_free", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] - internal static extern void das_context_free(DASContext* ctx); + [DllImport(__DllName, EntryPoint = "eth_kzg_das_context_free", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern void eth_kzg_das_context_free(DASContext* ctx); /// /// Free the memory allocated for the error message. @@ -53,8 +53,8 @@ internal static unsafe partial class NativeMethods /// - The caller must ensure that the pointer is valid. If the pointer is null, this method will return early. /// - The caller should also avoid a double-free by setting the pointer to null after calling this method. /// - [DllImport(__DllName, EntryPoint = "free_error_message", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] - internal static extern void free_error_message(byte* c_message); + [DllImport(__DllName, EntryPoint = "eth_kzg_free_error_message", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern void eth_kzg_free_error_message(byte* c_message); /// /// Compute a commitment from a Blob @@ -70,8 +70,8 @@ internal static unsafe partial class NativeMethods /// - 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. /// - [DllImport(__DllName, EntryPoint = "blob_to_kzg_commitment", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] - internal static extern CResult blob_to_kzg_commitment(DASContext* ctx, byte* blob, byte* @out); + [DllImport(__DllName, EntryPoint = "eth_kzg_blob_to_kzg_commitment", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern CResult eth_kzg_blob_to_kzg_commitment(DASContext* ctx, byte* blob, byte* @out); /// /// Computes the cells and KZG proofs for a given blob. @@ -90,8 +90,8 @@ internal static unsafe partial class NativeMethods /// - 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. /// - [DllImport(__DllName, EntryPoint = "compute_cells_and_kzg_proofs", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] - internal static extern CResult compute_cells_and_kzg_proofs(DASContext* ctx, byte* blob, byte** out_cells, byte** out_proofs); + [DllImport(__DllName, EntryPoint = "eth_kzg_compute_cells_and_kzg_proofs", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern CResult eth_kzg_compute_cells_and_kzg_proofs(DASContext* ctx, byte* blob, byte** out_cells, byte** out_proofs); /// /// Verifies a batch of cells and their KZG proofs. @@ -120,8 +120,8 @@ internal static unsafe partial class NativeMethods /// - 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. /// - [DllImport(__DllName, EntryPoint = "verify_cell_kzg_proof_batch", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] - internal static extern CResult verify_cell_kzg_proof_batch(DASContext* ctx, ulong commitments_length, byte** commitments, ulong cell_indices_length, ulong* cell_indices, ulong cells_length, byte** cells, ulong proofs_length, byte** proofs, bool* verified); + [DllImport(__DllName, EntryPoint = "eth_kzg_verify_cell_kzg_proof_batch", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern CResult eth_kzg_verify_cell_kzg_proof_batch(DASContext* ctx, ulong commitments_length, byte** commitments, ulong cell_indices_length, ulong* cell_indices, ulong cells_length, byte** cells, ulong proofs_length, byte** proofs, bool* verified); /// /// Recovers all cells and their KZG proofs from the given cell indices and cells @@ -147,17 +147,17 @@ internal static unsafe partial class NativeMethods /// - 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. /// - [DllImport(__DllName, EntryPoint = "recover_cells_and_proofs", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] - internal static extern CResult recover_cells_and_proofs(DASContext* ctx, ulong cells_length, byte** cells, ulong cell_indices_length, ulong* cell_indices, byte** out_cells, byte** out_proofs); + [DllImport(__DllName, EntryPoint = "eth_kzg_recover_cells_and_proofs", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern CResult eth_kzg_recover_cells_and_proofs(DASContext* ctx, ulong cells_length, byte** cells, ulong cell_indices_length, ulong* cell_indices, byte** out_cells, byte** out_proofs); - [DllImport(__DllName, EntryPoint = "constant_bytes_per_cell", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] - internal static extern ulong constant_bytes_per_cell(); + [DllImport(__DllName, EntryPoint = "eth_kzg_constant_bytes_per_cell", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern ulong eth_kzg_constant_bytes_per_cell(); - [DllImport(__DllName, EntryPoint = "constant_bytes_per_proof", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] - internal static extern ulong constant_bytes_per_proof(); + [DllImport(__DllName, EntryPoint = "eth_kzg_constant_bytes_per_proof", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern ulong eth_kzg_constant_bytes_per_proof(); - [DllImport(__DllName, EntryPoint = "constant_cells_per_ext_blob", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] - internal static extern ulong constant_cells_per_ext_blob(); + [DllImport(__DllName, EntryPoint = "eth_kzg_constant_cells_per_ext_blob", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern ulong eth_kzg_constant_cells_per_ext_blob(); } diff --git a/bindings/java/rust_code/src/lib.rs b/bindings/java/rust_code/src/lib.rs index ef97632d..cad10069 100644 --- a/bindings/java/rust_code/src/lib.rs +++ b/bindings/java/rust_code/src/lib.rs @@ -13,7 +13,7 @@ pub extern "system" fn Java_ethereum_cryptography_LibEthKZG_DASContextNew( _class: JClass, ) -> jlong { // TODO: Switch to using the Rust DASContext object - c_eth_kzg::das_context_new() as jlong + c_eth_kzg::eth_kzg_das_context_new() as jlong } #[no_mangle] @@ -23,7 +23,7 @@ pub extern "system" fn Java_ethereum_cryptography_LibEthKZG_DASContextDestroy( ctx_ptr: jlong, ) { // TODO: Switch to using the Rust DASContext object - c_eth_kzg::das_context_free(ctx_ptr as *mut DASContext); + c_eth_kzg::eth_kzg_das_context_free(ctx_ptr as *mut DASContext); } #[no_mangle] diff --git a/bindings/nim/nim_code/nim_eth_kzg/header.nim b/bindings/nim/nim_code/nim_eth_kzg/header.nim index 9c026cee..d3c59e9f 100644 --- a/bindings/nim/nim_code/nim_eth_kzg/header.nim +++ b/bindings/nim/nim_code/nim_eth_kzg/header.nim @@ -7,6 +7,7 @@ type CResultStatus* = enum Ok Err +## * Note: All methods in this file have been prefixed with `eth_kzg`. * This is so that when they are imported into languages such as nim, * they will have a separate namespace to other c libraries. * * ie Nim will take two c libraries and put their methods in the same * namespace. type DASContext* {.incompleteStruct.} = object ## A C-style struct to represent the success result of a function call. @@ -22,7 +23,7 @@ type CResult* = object # # To avoid memory leaks, one should ensure that the pointer is freed after use # by calling `das_context_free`. -proc das_context_new*(): ptr DASContext {.importc: "das_context_new".} +proc eth_kzg_das_context_new*(): ptr DASContext {.importc: "eth_kzg_das_context_new".} ## # Safety # @@ -37,7 +38,7 @@ proc das_context_new*(): ptr DASContext {.importc: "das_context_new".} # # - Since the `ctx` is created in Rust, we can only get undefined behavior, if the caller passes in # a pointer that was not created by `das_context_new`. -proc das_context_free*(ctx: ptr DASContext): void {.importc: "das_context_free".} +proc eth_kzg_das_context_free*(ctx: ptr DASContext): void {.importc: "eth_kzg_das_context_free".} ## Free the memory allocated for the error message. # @@ -45,7 +46,7 @@ proc das_context_free*(ctx: ptr DASContext): void {.importc: "das_context_free". # # - The caller must ensure that the pointer is valid. If the pointer is null, this method will return early. # - The caller should also avoid a double-free by setting the pointer to null after calling this method. -proc free_error_message*(c_message: pointer): void {.importc: "free_error_message".} +proc eth_kzg_free_error_message*(c_message: pointer): void {.importc: "eth_kzg_free_error_message".} ## Compute a commitment from a Blob # @@ -59,9 +60,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 DASContext, - blob: pointer, - outx: pointer): CResult {.importc: "blob_to_kzg_commitment".} +proc eth_kzg_blob_to_kzg_commitment*(ctx: ptr DASContext, + blob: pointer, + outx: pointer): CResult {.importc: "eth_kzg_blob_to_kzg_commitment".} ## Computes the cells and KZG proofs for a given blob. # @@ -78,10 +79,10 @@ proc blob_to_kzg_commitment*(ctx: ptr DASContext, # # - 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 DASContext, - blob: pointer, - out_cells: ptr pointer, - out_proofs: ptr pointer): CResult {.importc: "compute_cells_and_kzg_proofs".} +proc eth_kzg_compute_cells_and_kzg_proofs*(ctx: ptr DASContext, + blob: pointer, + out_cells: ptr pointer, + out_proofs: ptr pointer): CResult {.importc: "eth_kzg_compute_cells_and_kzg_proofs".} ## Verifies a batch of cells and their KZG proofs. # @@ -108,16 +109,16 @@ proc compute_cells_and_kzg_proofs*(ctx: ptr DASContext, # # - 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 DASContext, - commitments_length: uint64, - commitments: ptr pointer, - cell_indices_length: uint64, - cell_indices: pointer, - cells_length: uint64, - cells: ptr pointer, - proofs_length: uint64, - proofs: ptr pointer, - verified: pointer): CResult {.importc: "verify_cell_kzg_proof_batch".} +proc eth_kzg_verify_cell_kzg_proof_batch*(ctx: ptr DASContext, + commitments_length: uint64, + commitments: ptr pointer, + cell_indices_length: uint64, + cell_indices: pointer, + cells_length: uint64, + cells: ptr pointer, + proofs_length: uint64, + proofs: ptr pointer, + verified: pointer): CResult {.importc: "eth_kzg_verify_cell_kzg_proof_batch".} ## Recovers all cells and their KZG proofs from the given cell indices and cells # @@ -141,16 +142,16 @@ proc verify_cell_kzg_proof_batch*(ctx: ptr DASContext, # # - 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 DASContext, - cells_length: uint64, - cells: ptr pointer, - cell_indices_length: uint64, - cell_indices: pointer, - out_cells: ptr pointer, - out_proofs: ptr pointer): CResult {.importc: "recover_cells_and_proofs".} +proc eth_kzg_recover_cells_and_proofs*(ctx: ptr DASContext, + cells_length: uint64, + cells: ptr pointer, + cell_indices_length: uint64, + cell_indices: pointer, + out_cells: ptr pointer, + out_proofs: ptr pointer): CResult {.importc: "eth_kzg_recover_cells_and_proofs".} -proc constant_bytes_per_cell*(): uint64 {.importc: "constant_bytes_per_cell".} +proc eth_kzg_constant_bytes_per_cell*(): uint64 {.importc: "eth_kzg_constant_bytes_per_cell".} -proc constant_bytes_per_proof*(): uint64 {.importc: "constant_bytes_per_proof".} +proc eth_kzg_constant_bytes_per_proof*(): uint64 {.importc: "eth_kzg_constant_bytes_per_proof".} -proc constant_cells_per_ext_blob*(): uint64 {.importc: "constant_cells_per_ext_blob".} +proc eth_kzg_constant_cells_per_ext_blob*(): uint64 {.importc: "eth_kzg_constant_cells_per_ext_blob".} From 2ea08520a6867abdfed82aa37cf2cb3cbd114703 Mon Sep 17 00:00:00 2001 From: Kevaundray Wedderburn Date: Tue, 13 Aug 2024 18:13:06 +0100 Subject: [PATCH 2/8] add eth_kzg prefix to csharp methods --- bindings/csharp/csharp_code/EthKZG.bindings/ethkzg.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bindings/csharp/csharp_code/EthKZG.bindings/ethkzg.cs b/bindings/csharp/csharp_code/EthKZG.bindings/ethkzg.cs index cbff2620..4488c900 100644 --- a/bindings/csharp/csharp_code/EthKZG.bindings/ethkzg.cs +++ b/bindings/csharp/csharp_code/EthKZG.bindings/ethkzg.cs @@ -37,7 +37,7 @@ public void Dispose() { if (_context != null) { - das_context_free(_context); + eth_kzg_das_context_free(_context); _context = null; } } @@ -56,7 +56,7 @@ public unsafe byte[] BlobToKzgCommitment(byte[] blob) fixed (byte* blobPtr = blob) fixed (byte* commitmentPtr = commitment) { - CResult result = blob_to_kzg_commitment(_context, blobPtr, commitmentPtr); + CResult result = eth_kzg_blob_to_kzg_commitment(_context, blobPtr, commitmentPtr); ThrowOnError(result); } @@ -105,7 +105,7 @@ public unsafe (byte[][], byte[][]) ComputeCellsAndKZGProofs(byte[] blob) } } - CResult result = compute_cells_and_kzg_proofs(_context, blobPtr, outCellsPtrPtr, outProofsPtrPtr); + CResult result = eth_kzg_compute_cells_and_kzg_proofs(_context, blobPtr, outCellsPtrPtr, outProofsPtrPtr); ThrowOnError(result); } return (outCells, outProofs); @@ -182,7 +182,7 @@ public bool VerifyCellKZGProofBatch(byte[][] commitments, ulong[] cellIndices, b } } - CResult result = verify_cell_kzg_proof_batch(_context, Convert.ToUInt64(commitments.Length), commitmentPtrPtr, Convert.ToUInt64(cellIndices.Length), cellIndicesPtr, Convert.ToUInt64(cells.Length), cellsPtrPtr, Convert.ToUInt64(proofs.Length), proofsPtrPtr, verifiedPtr); + CResult result = eth_kzg_verify_cell_kzg_proof_batch(_context, Convert.ToUInt64(commitments.Length), commitmentPtrPtr, Convert.ToUInt64(cellIndices.Length), cellIndicesPtr, Convert.ToUInt64(cells.Length), cellsPtrPtr, Convert.ToUInt64(proofs.Length), proofsPtrPtr, verifiedPtr); ThrowOnError(result); } return verified; @@ -244,7 +244,7 @@ public bool VerifyCellKZGProofBatch(byte[][] commitments, ulong[] cellIndices, b } } - CResult result = recover_cells_and_proofs(_context, Convert.ToUInt64(numInputCells), inputCellsPtrPtr, Convert.ToUInt64(cellIds.Length), cellIdsPtr, outCellsPtrPtr, outProofsPtrPtr); + CResult result = eth_kzg_recover_cells_and_proofs(_context, Convert.ToUInt64(numInputCells), inputCellsPtrPtr, Convert.ToUInt64(cellIds.Length), cellIdsPtr, outCellsPtrPtr, outProofsPtrPtr); ThrowOnError(result); } From e98231caf4067e427f49e55b6723fbce337dc8a9 Mon Sep 17 00:00:00 2001 From: Kevaundray Wedderburn Date: Tue, 13 Aug 2024 18:14:01 +0100 Subject: [PATCH 3/8] modify golang code --- bindings/golang/prover.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bindings/golang/prover.go b/bindings/golang/prover.go index 77a48efd..4da542cb 100644 --- a/bindings/golang/prover.go +++ b/bindings/golang/prover.go @@ -46,10 +46,10 @@ type DASContext struct { } func NewProverContext() *DASContext { - self := &DASContext{_inner: C.das_context_new()} + self := &DASContext{_inner: C.eth_kzg_das_context_new()} runtime.SetFinalizer(self, func(self *DASContext) { - C.das_context_free(self.inner()) + C.eth_kzg_das_context_free(self.inner()) }) return self @@ -60,7 +60,7 @@ func (prover *DASContext) BlobToKZGCommitment(blob []byte) ([]byte, error) { return nil, errors.New("invalid blob size") } out := make([]byte, 48) - C.blob_to_kzg_commitment(prover.inner(), (*C.uint8_t)(&blob[0]), (*C.uint8_t)(&out[0])) + C.eth_kzg_blob_to_kzg_commitment(prover.inner(), (*C.uint8_t)(&blob[0]), (*C.uint8_t)(&out[0])) return out, nil } From 22a43be83466a2f05f5678773b1ad519dfb6202e Mon Sep 17 00:00:00 2001 From: Kevaundray Wedderburn Date: Tue, 13 Aug 2024 18:15:36 +0100 Subject: [PATCH 4/8] update nim bindings --- bindings/nim/nim_code/nim_eth_kzg/nim_eth_kzg.nim | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bindings/nim/nim_code/nim_eth_kzg/nim_eth_kzg.nim b/bindings/nim/nim_code/nim_eth_kzg/nim_eth_kzg.nim index d639a944..4cd4e2d7 100644 --- a/bindings/nim/nim_code/nim_eth_kzg/nim_eth_kzg.nim +++ b/bindings/nim/nim_code/nim_eth_kzg/nim_eth_kzg.nim @@ -83,18 +83,18 @@ type # https://forum.nim-lang.org/t/11229 proc `=destroy`(x: typeof KZGCtx()[]) = if x.ctx_ptr != nil: - das_context_free(x.ctx_ptr) + eth_kzg_das_context_free(x.ctx_ptr) proc newKZGCtx*(): KZGCtx = var kzgCtx = KZGCtx() - kzgCtx.ctx_ptr = das_context_new() + kzgCtx.ctx_ptr = eth_kzg_das_context_new() return kzgCtx proc blobToKZGCommitment*(ctx: KZGCtx, blob : Blob): Result[KZGCommitment, string] {.gcsafe.} = var ret: KZGCommitment - let res = blob_to_kzg_commitment( + let res = eth_kzg_blob_to_kzg_commitment( ctx.ctx_ptr, blob.bytes.getPtr, @@ -109,7 +109,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 = eth_kzg_compute_cells_and_kzg_proofs( ctx.ctx_ptr, blob.bytes.getPtr, @@ -129,7 +129,7 @@ proc verifyCellKZGProofBatch*(ctx: KZGCtx, commitments: openArray[Bytes48], let proofsPtr = toPtrPtr(proofs) let commitmentsPtr = toPtrPtr(commitments) - let res = verify_cell_kzg_proof_batch( + let res = eth_kzg_verify_cell_kzg_proof_batch( ctx.ctx_ptr, uint64(len(commitments)), @@ -158,7 +158,7 @@ proc recoverCellsAndProofs*(ctx: KZGCtx, let outProofsPtr = toPtrPtr(ret.proofs) let inputCellsPtr = toPtrPtr(cells) - let res = recover_cells_and_proofs( + let res = eth_kzg_recover_cells_and_proofs( ctx.ctx_ptr, uint64(len(cells)), From 294bbee7b2b78af4ee63581592183aced1fff857 Mon Sep 17 00:00:00 2001 From: Kevaundray Wedderburn Date: Tue, 13 Aug 2024 18:33:16 +0100 Subject: [PATCH 5/8] add missing prefix --- bindings/csharp/csharp_code/EthKZG.bindings/ethkzg.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/csharp/csharp_code/EthKZG.bindings/ethkzg.cs b/bindings/csharp/csharp_code/EthKZG.bindings/ethkzg.cs index 4488c900..eb105071 100644 --- a/bindings/csharp/csharp_code/EthKZG.bindings/ethkzg.cs +++ b/bindings/csharp/csharp_code/EthKZG.bindings/ethkzg.cs @@ -261,7 +261,7 @@ private static void ThrowOnError(CResult result) if (errorMessage != null) { // Free the error message that we allocated on the rust side - free_error_message(result.error_msg); + eth_kzg_free_error_message(result.error_msg); throw new ArgumentException($"an error occurred from the bindings: {errorMessage}"); } else From 012406e7fef83bfb3b1a32a0efa072abde7d3988 Mon Sep 17 00:00:00 2001 From: Kevaundray Wedderburn Date: Tue, 13 Aug 2024 19:32:03 +0100 Subject: [PATCH 6/8] fix comment --- bindings/c/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/c/src/lib.rs b/bindings/c/src/lib.rs index 10ef0494..522ed38b 100644 --- a/bindings/c/src/lib.rs +++ b/bindings/c/src/lib.rs @@ -18,7 +18,7 @@ pub use rust_eth_kzg::constants::{ }; use rust_eth_kzg::Error; -/** +/* * Note: All methods in this file have been prefixed with `eth_kzg`. * This is so that when they are imported into languages such as nim, * they will have a separate namespace to other c libraries. From fd9328e63503ba9e74a7505734005dbe45810611 Mon Sep 17 00:00:00 2001 From: Kevaundray Wedderburn Date: Tue, 13 Aug 2024 19:32:08 +0100 Subject: [PATCH 7/8] update header --- bindings/nim/nim_code/nim_eth_kzg/header.nim | 1 - 1 file changed, 1 deletion(-) diff --git a/bindings/nim/nim_code/nim_eth_kzg/header.nim b/bindings/nim/nim_code/nim_eth_kzg/header.nim index d3c59e9f..81575afb 100644 --- a/bindings/nim/nim_code/nim_eth_kzg/header.nim +++ b/bindings/nim/nim_code/nim_eth_kzg/header.nim @@ -7,7 +7,6 @@ type CResultStatus* = enum Ok Err -## * Note: All methods in this file have been prefixed with `eth_kzg`. * This is so that when they are imported into languages such as nim, * they will have a separate namespace to other c libraries. * * ie Nim will take two c libraries and put their methods in the same * namespace. type DASContext* {.incompleteStruct.} = object ## A C-style struct to represent the success result of a function call. From 1845b271e6e2b0aab1d6934409fa50d5ad5b2817 Mon Sep 17 00:00:00 2001 From: Kevaundray Wedderburn Date: Tue, 13 Aug 2024 19:53:45 +0100 Subject: [PATCH 8/8] update method call --- bindings/csharp/csharp_code/EthKZG.bindings/ethkzg.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/csharp/csharp_code/EthKZG.bindings/ethkzg.cs b/bindings/csharp/csharp_code/EthKZG.bindings/ethkzg.cs index eb105071..87bf673a 100644 --- a/bindings/csharp/csharp_code/EthKZG.bindings/ethkzg.cs +++ b/bindings/csharp/csharp_code/EthKZG.bindings/ethkzg.cs @@ -30,7 +30,7 @@ public sealed unsafe class EthKZG : IDisposable public EthKZG() { - _context = das_context_new(); + _context = eth_kzg_das_context_new(); } public void Dispose()