Add compute_kzg_proof to java bindings (#94)
This commit is contained in:
parent
9076280cd2
commit
e4f280f17f
|
@ -125,6 +125,34 @@ JNIEXPORT void JNICALL Java_ethereum_ckzg4844_CKZG4844JNI_freeTrustedSetup(JNIEn
|
|||
reset_trusted_setup();
|
||||
}
|
||||
|
||||
JNIEXPORT jbyteArray JNICALL Java_ethereum_ckzg4844_CKZG4844JNI_computeKzgProof(JNIEnv *env, jclass thisCls, jbyteArray blob, jbyteArray z_bytes)
|
||||
{
|
||||
if (settings == NULL)
|
||||
{
|
||||
throw_exception(env, TRUSTED_SETUP_NOT_LOADED);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Blob *blob_native = (Blob *)(*env)->GetByteArrayElements(env, blob, NULL);
|
||||
Bytes32 *z_native = (Bytes32 *)(*env)->GetByteArrayElements(env, z_bytes, NULL);
|
||||
|
||||
jbyteArray proof = (*env)->NewByteArray(env, BYTES_PER_PROOF);
|
||||
KZGProof *proof_native = (KZGProof *)(uint8_t *)(*env)->GetByteArrayElements(env, proof, NULL);
|
||||
|
||||
C_KZG_RET ret = compute_kzg_proof(proof_native, blob_native, z_native, settings);
|
||||
|
||||
(*env)->ReleaseByteArrayElements(env, blob, (jbyte *)blob_native, JNI_ABORT);
|
||||
(*env)->ReleaseByteArrayElements(env, proof, (jbyte *)proof_native, 0);
|
||||
|
||||
if (ret != C_KZG_OK)
|
||||
{
|
||||
throw_c_kzg_exception(env, ret, "There was an error while computing kzg proof.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return proof;
|
||||
}
|
||||
|
||||
JNIEXPORT jbyteArray JNICALL Java_ethereum_ckzg4844_CKZG4844JNI_computeAggregateKzgProof(JNIEnv *env, jclass thisCls, jbyteArray blobs, jlong count)
|
||||
{
|
||||
if (settings == NULL)
|
||||
|
|
|
@ -42,6 +42,13 @@ extern "C"
|
|||
*/
|
||||
JNIEXPORT void JNICALL Java_ethereum_ckzg4844_CKZG4844JNI_freeTrustedSetup(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: ethereum_ckzg4844_CKZG4844JNI
|
||||
* Method: computeKzgProof
|
||||
* Signature: ([B[B)[B
|
||||
*/
|
||||
JNIEXPORT jbyteArray JNICALL Java_ethereum_ckzg4844_CKZG4844JNI_computeKzgProof(JNIEnv *, jclass, jbyteArray, jbyteArray);
|
||||
|
||||
/*
|
||||
* Class: ethereum_ckzg4844_CKZG4844JNI
|
||||
* Method: computeAggregateKzgProof
|
||||
|
|
|
@ -113,6 +113,16 @@ public class CKZG4844JNI {
|
|||
*/
|
||||
public static native void freeTrustedSetup();
|
||||
|
||||
/**
|
||||
* Compute proof at point z for the polynomial represented by blob.
|
||||
*
|
||||
* @param blob blob bytes
|
||||
* @param z_bytes a point
|
||||
* @return the proof
|
||||
* @throws CKZGException if there is a crypto error
|
||||
*/
|
||||
public static native byte[] computeKzgProof(byte[] blob, byte[] z_bytes);
|
||||
|
||||
/**
|
||||
* Calculates aggregated proof for the given blobs
|
||||
*
|
||||
|
|
|
@ -82,6 +82,15 @@ public class CKZG4844JNITest {
|
|||
parameters.getProof()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkComputeKzgProof() {
|
||||
loadTrustedSetup();
|
||||
final byte[] blob = TestUtils.createRandomBlob();
|
||||
final byte[] z_bytes = TestUtils.randomBLSFieldElementBytes();
|
||||
CKZG4844JNI.computeKzgProof(blob, z_bytes);
|
||||
CKZG4844JNI.freeTrustedSetup();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkCustomExceptionIsThrownAsExpected() {
|
||||
|
||||
|
|
|
@ -128,6 +128,10 @@ public class TestUtils {
|
|||
return randomBLSFieldElement();
|
||||
}
|
||||
|
||||
public static byte[] randomBLSFieldElementBytes() {
|
||||
return randomBLSFieldElement().toArray(ByteOrder.LITTLE_ENDIAN);
|
||||
}
|
||||
|
||||
private static InputStream readResource(final String resource) {
|
||||
return Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue