Skip to content

Commit

Permalink
Merge branch 'main' into update-versions-v2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jtraglia authored Aug 16, 2024
2 parents ec68a83 + a060be0 commit 45893af
Show file tree
Hide file tree
Showing 33 changed files with 389 additions and 359 deletions.
78 changes: 44 additions & 34 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ no-threads = ["blst/no-threads"]

[dependencies]
arbitrary = { version = "1", features = ["derive"] }
blst = { version = "0.3.11", default-features = false }
blst = { version = "0.3.12", default-features = false }
hex = { version = "0.4.2", default-features = false, features = ["alloc"] }
libc = { version = "0.2", default-features = false }
serde = { version = "1.0", optional = true, default-features = false, features = [
Expand Down
8 changes: 4 additions & 4 deletions bindings/csharp/Ckzg.Bindings/Ckzg.Bindings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private static IntPtr LoadNativeLibrary(Assembly _, string path)
}

[DllImport("ckzg", EntryPoint = "load_trusted_setup_wrap")]
private static extern IntPtr InternalLoadTrustedSetup(string filename, ulong precompute);
private static extern IntPtr InternalLoadTrustedSetup(string filename, UInt64 precompute);

[DllImport("ckzg", EntryPoint = "free_trusted_setup_wrap", CallingConvention = CallingConvention.Cdecl)]
private static extern void InternalFreeTrustedSetup(IntPtr ts);
Expand All @@ -58,18 +58,18 @@ private static extern unsafe KzgResult VerifyBlobKzgProof(out bool result, byte*

[DllImport("ckzg", EntryPoint = "verify_blob_kzg_proof_batch", CallingConvention = CallingConvention.Cdecl)]
private static extern unsafe KzgResult VerifyBlobKzgProofBatch(out bool result, byte* blobs, byte* commitments,
byte* proofs, ulong count, IntPtr ts);
byte* proofs, UInt64 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);

[DllImport("ckzg", EntryPoint = "recover_cells_and_kzg_proofs", CallingConvention = CallingConvention.Cdecl)]
private static extern unsafe KzgResult RecoverCellsAndKzgProofs(byte* recovered_cells, byte* recovered_proofs,
ulong* cell_indices, byte* cells, ulong num_cells, IntPtr ts);
UInt64* cell_indices, byte* cells, UInt64 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,
ulong* cell_indices, byte* cells, byte* proofs, ulong num_cells, IntPtr ts);
UInt64* cell_indices, byte* cells, byte* proofs, UInt64 num_cells, IntPtr ts);

private enum KzgResult
{
Expand Down
2 changes: 2 additions & 0 deletions bindings/csharp/Ckzg.Bindings/Ckzg.Bindings.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
<RepositoryUrl>https://github.com/ethereum/c-kzg-4844</RepositoryUrl>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<Version>0.2.0.0</Version>
<!-- Disable the warnings about using UInt64-->
<NoWarn>$(NoWarn);IDE0049</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down
22 changes: 11 additions & 11 deletions bindings/csharp/Ckzg.Bindings/Ckzg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static IntPtr LoadTrustedSetup(string filepath, int precompute)
{
if (!File.Exists(filepath)) throw new ArgumentException("Trusted setup file does not exist", nameof(filepath));

IntPtr ckzgSetup = InternalLoadTrustedSetup(filepath, (ulong)precompute);
IntPtr ckzgSetup = InternalLoadTrustedSetup(filepath, (UInt64)precompute);

if (ckzgSetup == IntPtr.Zero) throw new InvalidOperationException("Unable to load trusted setup");
return ckzgSetup;
Expand Down Expand Up @@ -194,7 +194,7 @@ 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);
VerifyBlobKzgProofBatch(out var result, blobsPtr, commitmentsPtr, proofsPtr, (UInt64)count, ckzgSetup);
ThrowOnError(kzgResult);
return result;
}
Expand Down Expand Up @@ -230,15 +230,15 @@ public static unsafe void ComputeCellsAndKzgProofs(Span<byte> cells, Span<byte>
/// </summary>
/// <param name="recoveredCells">Recovered cells as a flattened byte array</param>
/// <param name="recoveredProofs">Recovered proofs as a flattened byte array</param>
/// <param name="cellIndices">Cell indices as a flattened ulong array</param>
/// <param name="cellIndices">Cell indices as a flattened UInt64 array</param>
/// <param name="cells">Cells as a flattened byte array</param>
/// <param name="numCells">The number of cells provided</param>
/// <param name="ckzgSetup">Trusted setup settings</param>
/// <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,
ReadOnlySpan<ulong> cellIndices, ReadOnlySpan<byte> cells, int numCells, IntPtr ckzgSetup)
ReadOnlySpan<UInt64> cellIndices, ReadOnlySpan<byte> cells, int numCells, IntPtr ckzgSetup)
{
ThrowOnUninitializedTrustedSetup(ckzgSetup);
ThrowOnInvalidLength(recoveredCells, nameof(recoveredCells), BytesPerCell * CellsPerExtBlob);
Expand All @@ -248,10 +248,10 @@ public static unsafe void RecoverCellsAndKzgProofs(Span<byte> recoveredCells, Sp

fixed (byte* recoveredCellsPtr = recoveredCells, recoveredProofsPtr = recoveredProofs, cellsPtr = cells)
{
fixed(ulong* cellIndicesPtr = cellIndices)
fixed(UInt64* cellIndicesPtr = cellIndices)
{
KzgResult result = RecoverCellsAndKzgProofs(recoveredCellsPtr, recoveredProofsPtr, cellIndicesPtr,
cellsPtr, (ulong)numCells, ckzgSetup);
cellsPtr, (UInt64)numCells, ckzgSetup);
ThrowOnError(result);
}
}
Expand All @@ -261,7 +261,7 @@ public static unsafe void RecoverCellsAndKzgProofs(Span<byte> recoveredCells, Sp
/// Given some cells, verify that their proofs are valid.
/// </summary>
/// <param name="commitmentsBytes">The commitments associated with the rows</param>
/// <param name="cellIndices">Cell indices as a flattened ulong array</param>
/// <param name="cellIndices">Cell indices as a flattened UInt64 array</param>
/// <param name="cells">Cells as a flattened byte array</param>
/// <param name="proofsBytes">Proofs as a flattened byte array</param>
/// <param name="numCells">The number of cells provided</param>
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<UInt64> cellIndices,
ReadOnlySpan<byte> cells, ReadOnlySpan<byte> proofs, int numCells, IntPtr ckzgSetup)
{
ThrowOnUninitializedTrustedSetup(ckzgSetup);
Expand All @@ -281,10 +281,10 @@ public static unsafe bool VerifyCellKzgProofBatch(ReadOnlySpan<byte> commitments

fixed (byte* commitmentsPtr = commitments, cellsPtr = cells, proofsPtr = proofs)
{
fixed (ulong* cellIndicesPtr = cellIndices)
fixed (UInt64* cellIndicesPtr = cellIndices)
{
KzgResult kzgResult = VerifyCellKzgProofBatch(out var result, commitmentsPtr,
cellIndicesPtr, cellsPtr, proofsPtr, (ulong)numCells, ckzgSetup);
cellIndicesPtr, cellsPtr, proofsPtr, (UInt64)numCells, ckzgSetup);
ThrowOnError(kzgResult);
return result;
}
Expand Down Expand Up @@ -317,7 +317,7 @@ private static void ThrowOnInvalidLength(ReadOnlySpan<byte> data, string fieldNa
throw new ArgumentException($"Invalid data size, got {data.Length}, expected {expectedLength}", fieldName);
}

private static void ThrowOnInvalidLength(ReadOnlySpan<ulong> data, string fieldName, int expectedLength)
private static void ThrowOnInvalidLength(ReadOnlySpan<UInt64> data, string fieldName, int expectedLength)
{
if (data.Length != expectedLength)
throw new ArgumentException($"Invalid data size, got {data.Length}, expected {expectedLength}", fieldName);
Expand Down
2 changes: 2 additions & 0 deletions bindings/csharp/Ckzg.Test/Ckzg.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<IsPackable>false</IsPackable>
<!-- Disable the warnings about using UInt64-->
<NoWarn>$(NoWarn);IDE0049</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down
8 changes: 4 additions & 4 deletions bindings/csharp/Ckzg.Test/ReferenceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ public void TestComputeCellsAndKzgProofs(ComputeCellsAndKzgProofsTest test)

public class RecoverCellsAndKzgProofsInput
{
public List<ulong> CellIndices { get; set; } = null!;
public List<UInt64> CellIndices { get; set; } = null!;
public List<string> Cells { get; set; } = null!;
}

Expand Down Expand Up @@ -451,7 +451,7 @@ public void TestRecoverCellsAndKzgProofs(RecoverCellsAndKzgProofsTest test)
{
byte[] recoveredCells = new byte[CellsPerExtBlob * Ckzg.BytesPerCell];
byte[] recoveredProofs = new byte[CellsPerExtBlob * Ckzg.BytesPerProof];
ulong[] cellIndices = test.Input.CellIndices.ToArray();
UInt64[] cellIndices = test.Input.CellIndices.ToArray();
byte[] cells = GetFlatBytes(test.Input.Cells);
int numCells = cells.Length / Ckzg.BytesPerCell;

Expand All @@ -477,7 +477,7 @@ public void TestRecoverCellsAndKzgProofs(RecoverCellsAndKzgProofsTest test)
public class VerifyCellKzgProofBatchInput
{
public List<string> Commitments { get; set; } = null!;
public List<ulong> CellIndices { get; set; } = null!;
public List<UInt64> CellIndices { get; set; } = null!;
public List<string> Cells { get; set; } = null!;
public List<string> Proofs { get; set; } = null!;
}
Expand Down Expand Up @@ -506,7 +506,7 @@ private static IEnumerable<VerifyCellKzgProofBatchTest> GetVerifyCellKzgProofBat
public void TestVerifyCellKzgProofBatch(VerifyCellKzgProofBatchTest test)
{
byte[] commitments = GetFlatBytes(test.Input.Commitments);
ulong[] cellIndices = test.Input.CellIndices.ToArray();
UInt64[] cellIndices = test.Input.CellIndices.ToArray();
byte[] cells = GetFlatBytes(test.Input.Cells);
byte[] proofs = GetFlatBytes(test.Input.Proofs);
int numCells = cells.Length / Ckzg.BytesPerCell;
Expand Down
Loading

0 comments on commit 45893af

Please sign in to comment.