Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename Kzg to KZG in bindings #484

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions .github/workflows/csharp-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
uses: actions/upload-artifact@v3
with:
name: ckzg-library-wrapper-${{ matrix.target.location }}
path: bindings/csharp/Ckzg.Bindings/runtimes/${{ matrix.target.location }}/native
path: bindings/csharp/CKZG.Bindings/runtimes/${{ matrix.target.location }}/native

test-ckzg-dotnet:
name: Test .NET wrapper
Expand All @@ -85,9 +85,9 @@ jobs:
- uses: actions/download-artifact@v3
with:
name: ckzg-library-wrapper-${{ matrix.target.location }}
path: bindings/csharp/Ckzg.Bindings/runtimes/${{ matrix.target.location }}/native
path: bindings/csharp/CKZG.Bindings/runtimes/${{ matrix.target.location }}/native
- name: Test
run: dotnet test -c release bindings/csharp/Ckzg.sln
run: dotnet test -c release bindings/csharp/CKZG.sln

build-ckzg-dotnet:
name: Build .NET wrapper
Expand All @@ -98,23 +98,23 @@ jobs:
- uses: actions/download-artifact@v3
with:
name: ckzg-library-wrapper-linux-x64
path: bindings/csharp/Ckzg.Bindings/runtimes/linux-x64/native
path: bindings/csharp/CKZG.Bindings/runtimes/linux-x64/native
- uses: actions/download-artifact@v3
with:
name: ckzg-library-wrapper-osx-x64
path: bindings/csharp/Ckzg.Bindings/runtimes/osx-x64/native
path: bindings/csharp/CKZG.Bindings/runtimes/osx-x64/native
- uses: actions/download-artifact@v3
with:
name: ckzg-library-wrapper-win-x64
path: bindings/csharp/Ckzg.Bindings/runtimes/win-x64/native
path: bindings/csharp/CKZG.Bindings/runtimes/win-x64/native
- uses: actions/download-artifact@v3
with:
name: ckzg-library-wrapper-osx-arm64
path: bindings/csharp/Ckzg.Bindings/runtimes/osx-arm64/native
path: bindings/csharp/CKZG.Bindings/runtimes/osx-arm64/native
- uses: actions/download-artifact@v3
with:
name: ckzg-library-wrapper-linux-arm64
path: bindings/csharp/Ckzg.Bindings/runtimes/linux-arm64/native
path: bindings/csharp/CKZG.Bindings/runtimes/linux-arm64/native
- name: Set up .NET
uses: actions/setup-dotnet@v3
- name: Install dependencies
Expand All @@ -124,8 +124,8 @@ jobs:
- name: Upload package
uses: actions/upload-artifact@v3
with:
name: Ckzg.Bindings-${{ inputs.version || env.binding_build_number_based_version }}
path: bindings/csharp/nupkgs/Ckzg.Bindings.*.nupkg
name: CKZG.Bindings-${{ inputs.version || env.binding_build_number_based_version }}
path: bindings/csharp/nupkgs/CKZG.Bindings.*.nupkg
- name: Publish .NET package
if: github.ref == 'refs/heads/main'
run: dotnet nuget push bindings/csharp/nupkgs/*.nupkg -k ${{ secrets.CSHARP_NUGET_APIKEY }} -s https://api.nuget.org/v3/index.json
2 changes: 1 addition & 1 deletion bindings/csharp/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
.vscode
*.DotSettings.user

Ckzg.Bindings/runtimes/*/native/*
CKZG.Bindings/runtimes/*/native/*
!**/.gitkeep
test_ckzg*
*.so
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
using System.Runtime.InteropServices;
using System.Runtime.Loader;

namespace Ckzg;
namespace CKZG;

public static partial class Ckzg
public static partial class CKZG
{
static Ckzg() => AssemblyLoadContext.Default.ResolvingUnmanagedDll += LoadNativeLibrary;
static CKZG() => AssemblyLoadContext.Default.ResolvingUnmanagedDll += LoadNativeLibrary;

private static IntPtr LoadNativeLibrary(Assembly _, string path)
{
Expand Down Expand Up @@ -40,38 +40,38 @@ private static IntPtr LoadNativeLibrary(Assembly _, string path)
private static extern void InternalFreeTrustedSetup(IntPtr ts);

[DllImport("ckzg", EntryPoint = "blob_to_kzg_commitment", CallingConvention = CallingConvention.Cdecl)]
private static extern unsafe KzgResult BlobToKzgCommitment(byte* commitment, byte* blob, IntPtr ts);
private static extern unsafe KZGResult BlobToKZGCommitment(byte* commitment, byte* blob, IntPtr ts);

[DllImport("ckzg", EntryPoint = "compute_kzg_proof", CallingConvention = CallingConvention.Cdecl)]
private static extern unsafe KzgResult ComputeKzgProof(byte* proof_out, byte* y_out, byte* blob, byte* z, IntPtr ts);
private static extern unsafe KZGResult ComputeKZGProof(byte* proof_out, byte* y_out, byte* blob, byte* z, IntPtr ts);

[DllImport("ckzg", EntryPoint = "compute_blob_kzg_proof", CallingConvention = CallingConvention.Cdecl)]
private static extern unsafe KzgResult ComputeBlobKzgProof(byte* proof, byte* blob, byte* commitment, IntPtr ts);
private static extern unsafe KZGResult ComputeBlobKZGProof(byte* proof, byte* blob, byte* commitment, IntPtr ts);

[DllImport("ckzg", EntryPoint = "verify_kzg_proof", CallingConvention = CallingConvention.Cdecl)]
private static extern unsafe KzgResult VerifyKzgProof(out bool result, byte* commitment, byte* z,
private static extern unsafe KZGResult VerifyKZGProof(out bool result, byte* commitment, byte* z,
byte* y, byte* proof, IntPtr ts);

[DllImport("ckzg", EntryPoint = "verify_blob_kzg_proof", CallingConvention = CallingConvention.Cdecl)]
private static extern unsafe KzgResult VerifyBlobKzgProof(out bool result, byte* blob, byte* commitment,
private static extern unsafe KZGResult VerifyBlobKZGProof(out bool result, byte* blob, byte* commitment,
byte* proof, IntPtr ts);

[DllImport("ckzg", EntryPoint = "verify_blob_kzg_proof_batch", CallingConvention = CallingConvention.Cdecl)]
private static extern unsafe KzgResult VerifyBlobKzgProofBatch(out bool result, byte* blobs, byte* commitments,
private static extern unsafe KZGResult VerifyBlobKZGProofBatch(out bool result, byte* blobs, byte* commitments,
byte* proofs, ulong count, IntPtr ts);

[DllImport("ckzg", EntryPoint = "compute_cells_and_kzg_proofs", CallingConvention = CallingConvention.Cdecl)]
private static extern unsafe KzgResult ComputeCellsAndKzgProofs(byte* cells, byte* proofs, byte* blob, IntPtr ts);
private static extern unsafe KZGResult ComputeCellsAndKZGProofs(byte* cells, byte* proofs, byte* blob, IntPtr ts);

[DllImport("ckzg", EntryPoint = "recover_cells_and_kzg_proofs", CallingConvention = CallingConvention.Cdecl)]
private static extern unsafe KzgResult RecoverCellsAndKzgProofs(byte* recovered_cells, byte* recovered_proofs,
private static extern unsafe KZGResult RecoverCellsAndKZGProofs(byte* recovered_cells, byte* recovered_proofs,
ulong* cell_indices, byte* cells, ulong num_cells, IntPtr ts);

[DllImport("ckzg", EntryPoint = "verify_cell_kzg_proof_batch", CallingConvention = CallingConvention.Cdecl)]
private static extern unsafe KzgResult VerifyCellKzgProofBatch(out bool result, byte* commitments,
private static extern unsafe KZGResult VerifyCellKZGProofBatch(out bool result, byte* commitments,
ulong* cell_indices, byte* cells, byte* proofs, ulong num_cells, IntPtr ts);

private enum KzgResult
private enum KZGResult
{
// Success!
Ok,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<OutputType>Library</OutputType>
<RootNamespace>Ckzg</RootNamespace>
<RootNamespace>CKZG</RootNamespace>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

Expand All @@ -16,7 +16,7 @@
<Description>The C# bindings for the Polynomial Commitments API library for EIP-4844 and EIP-7594</Description>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<IncludeSymbols>true</IncludeSymbols>
<PackageId>Ckzg.Bindings</PackageId>
<PackageId>CKZG.Bindings</PackageId>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageTags>c-kzg eip-4844 eip-7594</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Ckzg;
namespace CKZG;

public static partial class Ckzg
public static partial class CKZG
{
public const int BytesPerBlob = FieldElementsPerBlob * BytesPerFieldElement;
public const int BytesPerCell = FieldElementsPerCell * BytesPerFieldElement;
Expand Down Expand Up @@ -49,15 +49,15 @@ public static void FreeTrustedSetup(IntPtr ckzgSetup)
/// <exception cref="ArgumentException">Thrown when length of an argument is not correct or settings are not correct</exception>
/// <exception cref="ApplicationException">Thrown when the library returns unexpected Error code</exception>
/// <exception cref="InsufficientMemoryException">Thrown when the library has no enough memory to process</exception>
public static unsafe void BlobToKzgCommitment(Span<byte> commitment, ReadOnlySpan<byte> blob, IntPtr ckzgSetup)
public static unsafe void BlobToKZGCommitment(Span<byte> commitment, ReadOnlySpan<byte> blob, IntPtr ckzgSetup)
{
ThrowOnUninitializedTrustedSetup(ckzgSetup);
ThrowOnInvalidLength(commitment, nameof(commitment), BytesPerCommitment);
ThrowOnInvalidLength(blob, nameof(blob), BytesPerBlob);

fixed (byte* commitmentPtr = commitment, blobPtr = blob)
{
KzgResult result = BlobToKzgCommitment(commitmentPtr, blobPtr, ckzgSetup);
KZGResult result = BlobToKZGCommitment(commitmentPtr, blobPtr, ckzgSetup);
ThrowOnError(result);
}
}
Expand All @@ -73,7 +73,7 @@ public static unsafe void BlobToKzgCommitment(Span<byte> commitment, ReadOnlySpa
/// <exception cref="ArgumentException">Thrown when length of an argument is not correct or settings are not correct</exception>
/// <exception cref="ApplicationException">Thrown when the library returns unexpected Error code</exception>
/// <exception cref="InsufficientMemoryException">Thrown when the library has no enough memory to process</exception>
public static unsafe void ComputeKzgProof(Span<byte> proof, Span<byte> y, ReadOnlySpan<byte> blob,
public static unsafe void ComputeKZGProof(Span<byte> proof, Span<byte> y, ReadOnlySpan<byte> blob,
ReadOnlySpan<byte> z, IntPtr ckzgSetup)
{
ThrowOnUninitializedTrustedSetup(ckzgSetup);
Expand All @@ -84,7 +84,7 @@ public static unsafe void ComputeKzgProof(Span<byte> proof, Span<byte> y, ReadOn

fixed (byte* proofPtr = proof, yPtr = y, blobPtr = blob, zPtr = z)
{
KzgResult result = ComputeKzgProof(proofPtr, yPtr, blobPtr, zPtr, ckzgSetup);
KZGResult result = ComputeKZGProof(proofPtr, yPtr, blobPtr, zPtr, ckzgSetup);
ThrowOnError(result);
}
}
Expand All @@ -99,7 +99,7 @@ public static unsafe void ComputeKzgProof(Span<byte> proof, Span<byte> y, ReadOn
/// <exception cref="ArgumentException">Thrown when length of an argument is not correct or settings are not correct</exception>
/// <exception cref="ApplicationException">Thrown when the library returns unexpected Error code</exception>
/// <exception cref="InsufficientMemoryException">Thrown when the library has no enough memory to process</exception>
public static unsafe void ComputeBlobKzgProof(Span<byte> proof, ReadOnlySpan<byte> blob,
public static unsafe void ComputeBlobKZGProof(Span<byte> proof, ReadOnlySpan<byte> blob,
ReadOnlySpan<byte> commitment, IntPtr ckzgSetup)
{
ThrowOnUninitializedTrustedSetup(ckzgSetup);
Expand All @@ -109,7 +109,7 @@ public static unsafe void ComputeBlobKzgProof(Span<byte> proof, ReadOnlySpan<byt

fixed (byte* proofPtr = proof, blobPtr = blob, commitmentPtr = commitment)
{
KzgResult result = ComputeBlobKzgProof(proofPtr, blobPtr, commitmentPtr, ckzgSetup);
KZGResult result = ComputeBlobKZGProof(proofPtr, blobPtr, commitmentPtr, ckzgSetup);
ThrowOnError(result);
}
}
Expand All @@ -126,7 +126,7 @@ public static unsafe void ComputeBlobKzgProof(Span<byte> proof, ReadOnlySpan<byt
/// <exception cref="ApplicationException">Thrown when the library returns unexpected Error code</exception>
/// <exception cref="InsufficientMemoryException">Thrown when the library has no enough memory to process</exception>
/// <returns>Verification result</returns>
public static unsafe bool VerifyKzgProof(ReadOnlySpan<byte> commitment, ReadOnlySpan<byte> z, ReadOnlySpan<byte> y,
public static unsafe bool VerifyKZGProof(ReadOnlySpan<byte> commitment, ReadOnlySpan<byte> z, ReadOnlySpan<byte> y,
ReadOnlySpan<byte> proof, IntPtr ckzgSetup)
{

Expand All @@ -138,7 +138,7 @@ public static unsafe bool VerifyKzgProof(ReadOnlySpan<byte> commitment, ReadOnly

fixed (byte* commitmentPtr = commitment, zPtr = z, yPtr = y, proofPtr = proof)
{
KzgResult kzgResult = VerifyKzgProof(out var result, commitmentPtr, zPtr, yPtr, proofPtr, ckzgSetup);
KZGResult kzgResult = VerifyKZGProof(out var result, commitmentPtr, zPtr, yPtr, proofPtr, ckzgSetup);
ThrowOnError(kzgResult);
return result;
}
Expand All @@ -155,7 +155,7 @@ public static unsafe bool VerifyKzgProof(ReadOnlySpan<byte> commitment, ReadOnly
/// <exception cref="ApplicationException">Thrown when the library returns unexpected Error code</exception>
/// <exception cref="InsufficientMemoryException">Thrown when the library has no enough memory to process</exception>
/// <returns>Verification result</returns>
public static unsafe bool VerifyBlobKzgProof(ReadOnlySpan<byte> blob, ReadOnlySpan<byte> commitment,
public static unsafe bool VerifyBlobKZGProof(ReadOnlySpan<byte> blob, ReadOnlySpan<byte> commitment,
ReadOnlySpan<byte> proof, IntPtr ckzgSetup)
{
ThrowOnUninitializedTrustedSetup(ckzgSetup);
Expand All @@ -165,7 +165,7 @@ public static unsafe bool VerifyBlobKzgProof(ReadOnlySpan<byte> blob, ReadOnlySp

fixed (byte* blobPtr = blob, commitmentPtr = commitment, proofPtr = proof)
{
KzgResult kzgResult = VerifyBlobKzgProof(out var result, blobPtr, commitmentPtr, proofPtr, ckzgSetup);
KZGResult kzgResult = VerifyBlobKZGProof(out var result, blobPtr, commitmentPtr, proofPtr, ckzgSetup);
ThrowOnError(kzgResult);
return result;
}
Expand All @@ -183,7 +183,7 @@ public static unsafe bool VerifyBlobKzgProof(ReadOnlySpan<byte> blob, ReadOnlySp
/// <exception cref="ApplicationException">Thrown when the library returns unexpected Error code</exception>
/// <exception cref="InsufficientMemoryException">Thrown when the library has no enough memory to process</exception>
/// <returns>Verification result</returns>
public static unsafe bool VerifyBlobKzgProofBatch(ReadOnlySpan<byte> blobs, ReadOnlySpan<byte> commitments,
public static unsafe bool VerifyBlobKZGProofBatch(ReadOnlySpan<byte> blobs, ReadOnlySpan<byte> commitments,
ReadOnlySpan<byte> proofs, int count, IntPtr ckzgSetup)
{
ThrowOnUninitializedTrustedSetup(ckzgSetup);
Expand All @@ -193,8 +193,8 @@ public static unsafe bool VerifyBlobKzgProofBatch(ReadOnlySpan<byte> blobs, Read

fixed (byte* blobsPtr = blobs, commitmentsPtr = commitments, proofsPtr = proofs)
{
KzgResult kzgResult =
VerifyBlobKzgProofBatch(out var result, blobsPtr, commitmentsPtr, proofsPtr, (ulong)count, ckzgSetup);
KZGResult kzgResult =
VerifyBlobKZGProofBatch(out var result, blobsPtr, commitmentsPtr, proofsPtr, (ulong)count, ckzgSetup);
ThrowOnError(kzgResult);
return result;
}
Expand All @@ -210,7 +210,7 @@ public static unsafe bool VerifyBlobKzgProofBatch(ReadOnlySpan<byte> blobs, Read
/// <exception cref="ArgumentException">Thrown when length of an argument is not correct or settings are not correct</exception>
/// <exception cref="ApplicationException">Thrown when the library returns unexpected Error code</exception>
/// <exception cref="InsufficientMemoryException">Thrown when the library has no enough memory to process</exception>
public static unsafe void ComputeCellsAndKzgProofs(Span<byte> cells, Span<byte> proofs, ReadOnlySpan<byte> blob,
public static unsafe void ComputeCellsAndKZGProofs(Span<byte> cells, Span<byte> proofs, ReadOnlySpan<byte> blob,
IntPtr ckzgSetup)
{
ThrowOnUninitializedTrustedSetup(ckzgSetup);
Expand All @@ -220,7 +220,7 @@ public static unsafe void ComputeCellsAndKzgProofs(Span<byte> cells, Span<byte>

fixed (byte* cellsPtr = cells, proofsPtr = proofs, blobPtr = blob)
{
KzgResult result = ComputeCellsAndKzgProofs(cellsPtr, proofsPtr, blobPtr, ckzgSetup);
KZGResult result = ComputeCellsAndKZGProofs(cellsPtr, proofsPtr, blobPtr, ckzgSetup);
ThrowOnError(result);
}
}
Expand All @@ -237,7 +237,7 @@ public static unsafe void ComputeCellsAndKzgProofs(Span<byte> cells, Span<byte>
/// <exception cref="ArgumentException">Thrown when length of an argument is not correct or settings are not correct</exception>
/// <exception cref="ApplicationException">Thrown when the library returns unexpected Error code</exception>
/// <exception cref="InsufficientMemoryException">Thrown when the library has no enough memory to process</exception>
public static unsafe void RecoverCellsAndKzgProofs(Span<byte> recoveredCells, Span<byte> recoveredProofs,
public static unsafe void RecoverCellsAndKZGProofs(Span<byte> recoveredCells, Span<byte> recoveredProofs,
ReadOnlySpan<ulong> cellIndices, ReadOnlySpan<byte> cells, int numCells, IntPtr ckzgSetup)
{
ThrowOnUninitializedTrustedSetup(ckzgSetup);
Expand All @@ -250,7 +250,7 @@ public static unsafe void RecoverCellsAndKzgProofs(Span<byte> recoveredCells, Sp
{
fixed(ulong* cellIndicesPtr = cellIndices)
{
KzgResult result = RecoverCellsAndKzgProofs(recoveredCellsPtr, recoveredProofsPtr, cellIndicesPtr,
KZGResult result = RecoverCellsAndKZGProofs(recoveredCellsPtr, recoveredProofsPtr, cellIndicesPtr,
cellsPtr, (ulong)numCells, ckzgSetup);
ThrowOnError(result);
}
Expand All @@ -270,7 +270,7 @@ public static unsafe void RecoverCellsAndKzgProofs(Span<byte> recoveredCells, Sp
/// <exception cref="ApplicationException">Thrown when the library returns unexpected Error code</exception>
/// <exception cref="InsufficientMemoryException">Thrown when the library has no enough memory to process</exception>
/// <returns>Verification result</returns>
public static unsafe bool VerifyCellKzgProofBatch(ReadOnlySpan<byte> commitments, ReadOnlySpan<ulong> cellIndices,
public static unsafe bool VerifyCellKZGProofBatch(ReadOnlySpan<byte> commitments, ReadOnlySpan<ulong> cellIndices,
ReadOnlySpan<byte> cells, ReadOnlySpan<byte> proofs, int numCells, IntPtr ckzgSetup)
{
ThrowOnUninitializedTrustedSetup(ckzgSetup);
Expand All @@ -283,7 +283,7 @@ public static unsafe bool VerifyCellKzgProofBatch(ReadOnlySpan<byte> commitments
{
fixed (ulong* cellIndicesPtr = cellIndices)
{
KzgResult kzgResult = VerifyCellKzgProofBatch(out var result, commitmentsPtr,
KZGResult kzgResult = VerifyCellKZGProofBatch(out var result, commitmentsPtr,
cellIndicesPtr, cellsPtr, proofsPtr, (ulong)numCells, ckzgSetup);
ThrowOnError(kzgResult);
return result;
Expand All @@ -292,13 +292,13 @@ public static unsafe bool VerifyCellKzgProofBatch(ReadOnlySpan<byte> commitments
}

#region Argument verification helpers
private static void ThrowOnError(KzgResult result)
private static void ThrowOnError(KZGResult result)
{
switch (result)
{
case KzgResult.BadArgs: throw new ArgumentException();
case KzgResult.Malloc: throw new InsufficientMemoryException();
case KzgResult.Ok:
case KZGResult.BadArgs: throw new ArgumentException();
case KZGResult.Malloc: throw new InsufficientMemoryException();
case KZGResult.Ok:
return;
default:
throw new ApplicationException("KZG returned unexpected result");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Ckzg.Bindings\Ckzg.Bindings.csproj" />
<ProjectReference Include="..\CKZG.Bindings\CKZG.Bindings.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading
Loading