Skip to content
Merged
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
4 changes: 2 additions & 2 deletions bindings/csharp/Ckzg.Bindings/Ckzg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static Ckzg() => AssemblyLoadContext.Default.ResolvingUnmanagedDll += (assembly,
/// <param name="ts">Trusted setup settings</param>
/// <returns>Returns error code or <c>0</c> if the proof is correct</returns>
[DllImport("ckzg", EntryPoint = "verify_aggregate_kzg_proof_wrap", CallingConvention = CallingConvention.Cdecl)]
public unsafe static extern int VerifyAggregatedKzgProof(byte* blobs, byte* commitments, int count, byte* proof, IntPtr ts);
public unsafe static extern int VerifyAggregatedKzgProof(byte* blobs, byte* commitments_bytes, int count, byte* aggregated_proof_bytes, IntPtr ts);

/// <summary>
/// Verify the proof by point evaluation for the given commitment
Expand All @@ -65,7 +65,7 @@ static Ckzg() => AssemblyLoadContext.Default.ResolvingUnmanagedDll += (assembly,
/// <param name="ts">Trusted setup settings</param>
/// <returns>Returns error code or <c>0</c> if the proof is correct</returns>
[DllImport("ckzg", EntryPoint = "verify_kzg_proof_wrap", CallingConvention = CallingConvention.Cdecl)]
public unsafe static extern int VerifyKzgProof(byte* commitment, byte* z, byte* y, byte* proof, IntPtr ts);
public unsafe static extern int VerifyKzgProof(byte* commitment_bytes, byte* z_bytes, byte* y_bytes, byte* proof_bytes, IntPtr ts);

/// <summary>
/// Load trusted setup settings from file
Expand Down
8 changes: 4 additions & 4 deletions bindings/csharp/ckzg.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ void free_trusted_setup_wrap(KZGSettings *s) {
free(s);
}

int verify_aggregate_kzg_proof_wrap(const Blob *blobs, const KZGCommitment *commitments, size_t n, const KZGProof *proof, const KZGSettings *s) {
int verify_aggregate_kzg_proof_wrap(const Blob *blobs, const Bytes48 *commitments_bytes, size_t n, const Bytes48 *aggregated_proof_bytes, const KZGSettings *s) {
bool b;
C_KZG_RET ret = verify_aggregate_kzg_proof(&b, blobs, commitments, n, proof, s);
C_KZG_RET ret = verify_aggregate_kzg_proof(&b, blobs, commitments_bytes, n, aggregated_proof_bytes, s);
if (ret != C_KZG_OK) return -1;

return b ? 0 : 1;
}

int verify_kzg_proof_wrap(const KZGCommitment *c, const Bytes32 *z, const Bytes32 *y, const KZGProof *p, KZGSettings *s) {
int verify_kzg_proof_wrap(const Bytes48 *commitment_bytes, const Bytes32 *z_bytes, const Bytes32 *y_bytes, const Bytes48 *proof_bytes, KZGSettings *s) {
bool out;
if (verify_kzg_proof(&out, c, z, y, p, s) != C_KZG_OK)
if (verify_kzg_proof(&out, commitment_bytes, z_bytes, y_bytes, proof_bytes, s) != C_KZG_OK)
return -2;

return out ? 0 : 1;
Expand Down
4 changes: 2 additions & 2 deletions bindings/csharp/ckzg.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ DLLEXPORT void free_trusted_setup_wrap(KZGSettings *s);

DLLEXPORT C_KZG_RET blob_to_kzg_commitment(KZGCommitment *out, const Blob *blob, const KZGSettings *s);

DLLEXPORT int verify_aggregate_kzg_proof_wrap(const Blob blobs[], const KZGCommitment *commitments, size_t n, const KZGProof *proof, const KZGSettings *s);
DLLEXPORT int verify_aggregate_kzg_proof_wrap(const Blob blobs[], const Bytes48 *commitments_bytes, size_t n, const Bytes48 *aggregated_proof_bytes, const KZGSettings *s);

DLLEXPORT C_KZG_RET compute_aggregate_kzg_proof(KZGProof *out, const Blob blobs[], size_t n, const KZGSettings *s);

DLLEXPORT int verify_kzg_proof_wrap(const KZGCommitment *c, const Bytes32 *z, const Bytes32 *y, const KZGProof *p, KZGSettings *s);
DLLEXPORT int verify_kzg_proof_wrap(const Bytes48 *commitment_bytes, const Bytes32 *z_bytes, const Bytes32 *y_bytes, const Bytes48 *proof_bytes, KZGSettings *s);
30 changes: 15 additions & 15 deletions bindings/java/c_kzg_4844_jni.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ JNIEXPORT jbyteArray JNICALL Java_ethereum_ckzg4844_CKZG4844JNI_computeAggregate
return proof;
}

JNIEXPORT jboolean JNICALL Java_ethereum_ckzg4844_CKZG4844JNI_verifyAggregateKzgProof(JNIEnv *env, jclass thisCls, jbyteArray blobs, jbyteArray commitments, jlong count, jbyteArray proof)
JNIEXPORT jboolean JNICALL Java_ethereum_ckzg4844_CKZG4844JNI_verifyAggregateKzgProof(JNIEnv *env, jclass thisCls, jbyteArray blobs, jbyteArray commitments_bytes, jlong count, jbyteArray proof_bytes)
{
if (settings == NULL)
{
Expand All @@ -178,23 +178,23 @@ JNIEXPORT jboolean JNICALL Java_ethereum_ckzg4844_CKZG4844JNI_verifyAggregateKzg
return 0;
}

size_t commitments_size = (size_t)(*env)->GetArrayLength(env, commitments);
size_t commitments_size = (size_t)(*env)->GetArrayLength(env, commitments_bytes);
size_t expected_commitments_size = BYTES_PER_COMMITMENT * count_native;
if (commitments_size != expected_commitments_size)
{
throw_invalid_size_exception(env, "Invalid commitments size.", commitments_size, expected_commitments_size);
return 0;
}

KZGProof *proof_native = (KZGProof *)(*env)->GetByteArrayElements(env, proof, NULL);
KZGCommitment *commitments_native = (KZGCommitment *)(*env)->GetByteArrayElements(env, commitments, NULL);
Bytes48 *proof_native = (Bytes48 *)(*env)->GetByteArrayElements(env, proof_bytes, NULL);
Bytes48 *commitments_native = (Bytes48 *)(*env)->GetByteArrayElements(env, commitments_bytes, NULL);
jbyte *blobs_native = (*env)->GetByteArrayElements(env, blobs, NULL);

bool out;
C_KZG_RET ret = verify_aggregate_kzg_proof(&out, (const Blob *)blobs_native, commitments_native, count_native, proof_native, settings);

(*env)->ReleaseByteArrayElements(env, proof, (jbyte *)proof_native, JNI_ABORT);
(*env)->ReleaseByteArrayElements(env, commitments, (jbyte *)commitments_native, JNI_ABORT);
(*env)->ReleaseByteArrayElements(env, proof_bytes, (jbyte *)proof_native, JNI_ABORT);
(*env)->ReleaseByteArrayElements(env, commitments_bytes, (jbyte *)commitments_native, JNI_ABORT);
(*env)->ReleaseByteArrayElements(env, blobs, blobs_native, JNI_ABORT);

if (ret != C_KZG_OK)
Expand Down Expand Up @@ -239,26 +239,26 @@ JNIEXPORT jbyteArray JNICALL Java_ethereum_ckzg4844_CKZG4844JNI_blobToKzgCommitm
return commitment;
}

JNIEXPORT jboolean JNICALL Java_ethereum_ckzg4844_CKZG4844JNI_verifyKzgProof(JNIEnv *env, jclass thisCls, jbyteArray commitment, jbyteArray z, jbyteArray y, jbyteArray proof)
JNIEXPORT jboolean JNICALL Java_ethereum_ckzg4844_CKZG4844JNI_verifyKzgProof(JNIEnv *env, jclass thisCls, jbyteArray commitment_bytes, jbyteArray z_bytes, jbyteArray y_bytes, jbyteArray proof_bytes)
{
if (settings == NULL)
{
throw_exception(env, TRUSTED_SETUP_NOT_LOADED);
return 0;
}

KZGCommitment *commitment_native = (KZGCommitment *)(*env)->GetByteArrayElements(env, commitment, NULL);
KZGProof *proof_native = (KZGProof *)(*env)->GetByteArrayElements(env, proof, NULL);
Bytes32 *z_native = (Bytes32 *)(*env)->GetByteArrayElements(env, z, NULL);
Bytes32 *y_native = (Bytes32 *)(*env)->GetByteArrayElements(env, y, NULL);
Bytes48 *commitment_native = (Bytes48 *)(*env)->GetByteArrayElements(env, commitment_bytes, NULL);
Bytes48 *proof_native = (Bytes48 *)(*env)->GetByteArrayElements(env, proof_bytes, NULL);
Bytes32 *z_native = (Bytes32 *)(*env)->GetByteArrayElements(env, z_bytes, NULL);
Bytes32 *y_native = (Bytes32 *)(*env)->GetByteArrayElements(env, y_bytes, NULL);

bool out;
C_KZG_RET ret = verify_kzg_proof(&out, commitment_native, z_native, y_native, proof_native, settings);

(*env)->ReleaseByteArrayElements(env, commitment, (jbyte *)commitment_native, JNI_ABORT);
(*env)->ReleaseByteArrayElements(env, z, (jbyte *)z_native, JNI_ABORT);
(*env)->ReleaseByteArrayElements(env, y, (jbyte *)y_native, JNI_ABORT);
(*env)->ReleaseByteArrayElements(env, proof, (jbyte *)proof_native, JNI_ABORT);
(*env)->ReleaseByteArrayElements(env, commitment_bytes, (jbyte *)commitment_native, JNI_ABORT);
(*env)->ReleaseByteArrayElements(env, z_bytes, (jbyte *)z_native, JNI_ABORT);
(*env)->ReleaseByteArrayElements(env, y_bytes, (jbyte *)y_native, JNI_ABORT);
(*env)->ReleaseByteArrayElements(env, proof_bytes, (jbyte *)proof_native, JNI_ABORT);

if (ret != C_KZG_OK)
{
Expand Down
23 changes: 12 additions & 11 deletions bindings/java/src/main/java/ethereum/ckzg4844/CKZG4844JNI.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,15 @@ public static native void loadTrustedSetup(byte[] g1, long g1Count, byte[] g2,
/**
* Verify aggregated proof and commitments for the given blobs
*
* @param blobs blobs as flattened bytes
* @param commitments commitments as flattened bytes
* @param count the count of the blobs (should be same as the count of the commitments)
* @param proof the proof that needs verifying
* @param blobs blobs as flattened bytes
* @param commitments_bytes commitments as flattened bytes
* @param count the count of the blobs (should be same as the count of the commitments)
* @param proof_bytes the proof that needs verifying
* @return true if the proof is valid and false otherwise
* @throws CKZGException if there is a crypto error
*/
public static native boolean verifyAggregateKzgProof(byte[] blobs, byte[] commitments, long count,
byte[] proof);
public static native boolean verifyAggregateKzgProof(byte[] blobs, byte[] commitments_bytes, long count,
byte[] aggregated_proof_bytes);

/**
* Calculates commitment for a given blob
Expand All @@ -148,13 +148,14 @@ public static native boolean verifyAggregateKzgProof(byte[] blobs, byte[] commit
/**
* Verify the proof by point evaluation for the given commitment
*
* @param commitment commitment bytes
* @param z Z
* @param y Y
* @param proof the proof that needs verifying
* @param commitment_bytes commitment bytes
* @param z_bytes Z
* @param y_bytes Y
* @param proof_bytes the proof that needs verifying
* @return true if the proof is valid and false otherwise
* @throws CKZGException if there is a crypto error
*/
public static native boolean verifyKzgProof(byte[] commitment, byte[] z, byte[] y, byte[] proof);
public static native boolean verifyKzgProof(byte[] commitment_bytes, byte[] z_bytes, byte[] y_bytes,
byte[] proof_bytes);

}
24 changes: 12 additions & 12 deletions bindings/node.js/kzg.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ Napi::Value ComputeAggregateKzgProof(const Napi::CallbackInfo& info) {
return napi_typed_array_from_bytes((uint8_t *)(&proof), BYTES_PER_PROOF, env);
}

// verifyAggregateKzgProof: (blobs: Blob[], expectedKzgCommitments: KZGCommitment[], kzgAggregatedProof: KZGProof, setupHandle: SetupHandle) => boolean;
// verifyAggregateKzgProof: (blobs: Blob[], commitmentsBytes: Bytes48[], aggregatedProofBytes: Bytes48, setupHandle: SetupHandle) => boolean;
Napi::Value VerifyAggregateKzgProof(const Napi::CallbackInfo& info) {
auto env = info.Env();

Expand All @@ -221,7 +221,7 @@ Napi::Value VerifyAggregateKzgProof(const Napi::CallbackInfo& info) {
return env.Null();
};

auto commitments = (KZGCommitment*)calloc(blobs_count, sizeof(KZGCommitment));
auto commitments = (Bytes48*)calloc(blobs_count, sizeof(Bytes48));
if (commitments == NULL) {
free(blobs);
Napi::Error::New(env, "Error while allocating memory for commitments").ThrowAsJavaScriptException();
Expand All @@ -248,7 +248,7 @@ Napi::Value VerifyAggregateKzgProof(const Napi::CallbackInfo& info) {
blobs,
commitments,
blobs_count,
(KZGProof *)proof_bytes,
(Bytes48 *)proof_bytes,
kzg_settings
);

Expand All @@ -266,7 +266,7 @@ Napi::Value VerifyAggregateKzgProof(const Napi::CallbackInfo& info) {
return Napi::Boolean::New(env, verification_result);
}

// verifyKzgProof: (polynomialKzg: KZGCommitment, z: Bytes32, y: Bytes32, kzgProof: KZGProof, setupHandle: SetupHandle) => boolean;
// verifyKzgProof: (commitmentBytes: Bytes48, zBytes: Bytes32, yBytes: Bytes32, proofBytes: Bytes48, setupHandle: SetupHandle) => boolean;
Napi::Value VerifyKzgProof(const Napi::CallbackInfo& info) {
auto env = info.Env();

Expand All @@ -276,10 +276,10 @@ Napi::Value VerifyKzgProof(const Napi::CallbackInfo& info) {
return throw_invalid_arguments_count(expected_argument_count, argument_count, env);
}

auto polynomial_kzg = extract_byte_array_from_param(info, 0, "polynomialKzg");
auto z = extract_byte_array_from_param(info, 1, "z");
auto y = extract_byte_array_from_param(info, 2, "y");
auto kzg_proof = extract_byte_array_from_param(info, 3, "kzgProof");
auto commitment_bytes = extract_byte_array_from_param(info, 0, "commitmentBytes");
auto z_bytes = extract_byte_array_from_param(info, 1, "zBytes");
auto y_bytes = extract_byte_array_from_param(info, 2, "yBytes");
auto proof_bytes = extract_byte_array_from_param(info, 3, "proofBytes");
auto kzg_settings = info[4].As<Napi::External<KZGSettings>>().Data();

if (env.IsExceptionPending()) {
Expand All @@ -289,10 +289,10 @@ Napi::Value VerifyKzgProof(const Napi::CallbackInfo& info) {
bool out;
C_KZG_RET ret = verify_kzg_proof(
&out,
(KZGCommitment *)polynomial_kzg,
(Bytes32 *)z,
(Bytes32 *)y,
(KZGProof *)kzg_proof,
(Bytes48 *)commitment_bytes,
(Bytes32 *)z_bytes,
(Bytes32 *)y_bytes,
(Bytes48 *)proof_bytes,
kzg_settings
);

Expand Down
37 changes: 19 additions & 18 deletions bindings/node.js/kzg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const kzg: KZG = require("./kzg.node");
const fs = require("fs");

export type Bytes32 = Uint8Array; // 32 bytes
export type Bytes48 = Uint8Array; // 48 bytes
export type KZGProof = Uint8Array; // 48 bytes
export type KZGCommitment = Uint8Array; // 48 bytes
export type Blob = Uint8Array; // 4096 * 32 bytes
Expand All @@ -30,16 +31,16 @@ type KZG = {

verifyAggregateKzgProof: (
blobs: Blob[],
expectedKzgCommitments: KZGCommitment[],
kzgAggregatedProof: KZGProof,
commitmentsBytes: Bytes48[],
aggregatedProofBytes: Bytes48,
setupHandle: SetupHandle,
) => boolean;

verifyKzgProof: (
polynomialKzg: KZGCommitment,
z: Bytes32,
y: Bytes32,
kzgProof: KZGProof,
commitmentBytes: Bytes48,
zBytes: Bytes32,
yBytes: Bytes32,
proofBytes: Bytes48,
setupHandle: SetupHandle,
) => boolean;
};
Expand Down Expand Up @@ -114,29 +115,29 @@ export function computeAggregateKzgProof(blobs: Blob[]): KZGProof {
}

export function verifyKzgProof(
polynomialKzg: KZGCommitment,
z: Bytes32,
y: Bytes32,
kzgProof: KZGProof,
commitmentBytes: Bytes48,
zBytes: Bytes32,
yBytes: Bytes32,
proofBytes: Bytes48,
): boolean {
return kzg.verifyKzgProof(
polynomialKzg,
z,
y,
kzgProof,
commitmentBytes,
zBytes,
yBytes,
proofBytes,
requireSetupHandle(),
);
}

export function verifyAggregateKzgProof(
blobs: Blob[],
expectedKzgCommitments: KZGCommitment[],
kzgAggregatedProof: KZGProof,
commitmentsBytes: Bytes48[],
proofBytes: Bytes48,
): boolean {
return kzg.verifyAggregateKzgProof(
blobs,
expectedKzgCommitments,
kzgAggregatedProof,
commitmentsBytes,
proofBytes,
requireSetupHandle(),
);
}
6 changes: 3 additions & 3 deletions bindings/python/ckzg.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ static PyObject* verify_aggregate_kzg_proof_wrap(PyObject *self, PyObject *args)
return PyErr_Format(PyExc_ValueError, "expected same number of commitments as polynomials");

const Blob* blobs = (Blob *)PyBytes_AsString(b);
const KZGProof *proof = (KZGProof *)PyBytes_AsString(p);
const KZGCommitment *commitments = (KZGCommitment *)PyBytes_AsString(c);
const Bytes48 *proof_bytes = (Bytes48 *)PyBytes_AsString(p);
const Bytes48 *commitments_bytes = (Bytes48 *)PyBytes_AsString(c);

bool out;
if (verify_aggregate_kzg_proof(&out,
blobs, commitments, n, proof,
blobs, commitments_bytes, n, proof_bytes,
PyCapsule_GetPointer(s, "KZGSettings")) != C_KZG_OK) {
return PyErr_Format(PyExc_RuntimeError, "verify_aggregate_kzg_proof failed");
}
Expand Down
27 changes: 21 additions & 6 deletions bindings/rust/src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ struct blst_fr {
struct blst_fp {
l: [limb_t; 6usize],
}

#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
struct blst_fp2 {
fp: [blst_fp; 2usize],
}

#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
struct blst_fp6 {
Expand Down Expand Up @@ -90,6 +92,19 @@ impl Deref for Bytes32 {
}
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct Bytes48 {
bytes: [u8; 48],
}

impl Deref for Bytes48 {
type Target = [u8; 48];
fn deref(&self) -> &Self::Target {
&self.bytes
}
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct Blob {
Expand Down Expand Up @@ -207,9 +222,9 @@ extern "C" {
pub fn verify_aggregate_kzg_proof(
out: *mut bool,
blobs: *const Blob,
expected_kzg_commitments: *const KZGCommitment,
commitments_bytes: *const Bytes48,
n: usize,
kzg_aggregated_proof: *const KZGProof,
aggregated_proof_bytes: *const Bytes48,
s: *const KZGSettings,
) -> C_KZG_RET;

Expand All @@ -221,10 +236,10 @@ extern "C" {

pub fn verify_kzg_proof(
out: *mut bool,
polynomial_kzg: *const KZGCommitment,
z: *const Bytes32,
y: *const Bytes32,
kzg_proof: *const KZGProof,
commitment_bytes: *const Bytes48,
z_bytes: *const Bytes32,
y_bytes: *const Bytes32,
proof_bytes: *const Bytes48,
s: *const KZGSettings,
) -> C_KZG_RET;
}
Loading