Rename ByteArrayTuple to ProofAndY (#233)
This commit is contained in:
parent
cc10ef024d
commit
fd3500fe7b
|
@ -207,7 +207,7 @@ JNIEXPORT jobject JNICALL Java_ethereum_ckzg4844_CKZG4844JNI_computeKzgProof(JNI
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/* The output variables, will be combined in a tuple */
|
||||
/* The output variables, will be combined in a ProofAndY object */
|
||||
jbyteArray proof = (*env)->NewByteArray(env, BYTES_PER_PROOF);
|
||||
jbyteArray y = (*env)->NewByteArray(env, BYTES_PER_FIELD_ELEMENT);
|
||||
|
||||
|
@ -230,28 +230,28 @@ JNIEXPORT jobject JNICALL Java_ethereum_ckzg4844_CKZG4844JNI_computeKzgProof(JNI
|
|||
return NULL;
|
||||
}
|
||||
|
||||
jclass tuple_class = (*env)->FindClass(env, "ethereum/ckzg4844/ByteArrayTuple");
|
||||
if (tuple_class == NULL)
|
||||
jclass proof_and_y_class = (*env)->FindClass(env, "ethereum/ckzg4844/ProofAndY");
|
||||
if (proof_and_y_class == NULL)
|
||||
{
|
||||
throw_exception(env, "Failed to find ByteArrayTuple class.");
|
||||
throw_exception(env, "Failed to find ProofAndY class.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
jmethodID tuple_constructor = (*env)->GetMethodID(env, tuple_class, "<init>", "([B[B)V");
|
||||
if (tuple_constructor == NULL)
|
||||
jmethodID proof_and_y_constructor = (*env)->GetMethodID(env, proof_and_y_class, "<init>", "([B[B)V");
|
||||
if (proof_and_y_constructor == NULL)
|
||||
{
|
||||
throw_exception(env, "Failed to find ByteArrayTuple constructor.");
|
||||
throw_exception(env, "Failed to find ProofAndY constructor.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
jobject tuple = (*env)->NewObject(env, tuple_class, tuple_constructor, proof, y);
|
||||
if (tuple == NULL)
|
||||
jobject proof_and_y = (*env)->NewObject(env, proof_and_y_class, proof_and_y_constructor, proof, y);
|
||||
if (proof_and_y == NULL)
|
||||
{
|
||||
throw_exception(env, "Failed to instantiate new ByteArrayTuple.");
|
||||
throw_exception(env, "Failed to instantiate new ProofAndY.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return tuple;
|
||||
return proof_and_y;
|
||||
}
|
||||
|
||||
JNIEXPORT jbyteArray JNICALL Java_ethereum_ckzg4844_CKZG4844JNI_computeBlobKzgProof(JNIEnv *env, jclass thisCls, jbyteArray blob, jbyteArray commitment_bytes)
|
||||
|
|
|
@ -56,7 +56,7 @@ JNIEXPORT jbyteArray JNICALL Java_ethereum_ckzg4844_CKZG4844JNI_blobToKzgCommitm
|
|||
/*
|
||||
* Class: ethereum_ckzg4844_CKZG4844JNI
|
||||
* Method: computeKzgProof
|
||||
* Signature: ([B[B)Lethereum/ckzg4844/Tuple;
|
||||
* Signature: ([B[B)Lethereum/ckzg4844/ProofAndY;
|
||||
*/
|
||||
JNIEXPORT jobject JNICALL Java_ethereum_ckzg4844_CKZG4844JNI_computeKzgProof
|
||||
(JNIEnv *, jclass, jbyteArray, jbyteArray);
|
||||
|
|
|
@ -125,7 +125,7 @@ public class CKZG4844JNIBenchmark {
|
|||
}
|
||||
|
||||
@Benchmark
|
||||
public ByteArrayTuple computeKzgProof(final ComputeKzgProofState state) {
|
||||
public ProofAndY computeKzgProof(final ComputeKzgProofState state) {
|
||||
return CKZG4844JNI.computeKzgProof(state.blob, state.z);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
package ethereum.ckzg4844;
|
||||
|
||||
/** A tuple holding 2 byte arrays. */
|
||||
public class ByteArrayTuple {
|
||||
private final byte[] first;
|
||||
private final byte[] second;
|
||||
|
||||
public ByteArrayTuple(byte[] first, byte[] second) {
|
||||
this.first = first;
|
||||
this.second = second;
|
||||
}
|
||||
|
||||
public byte[] getFirst() {
|
||||
return first;
|
||||
}
|
||||
|
||||
public byte[] getSecond() {
|
||||
return second;
|
||||
}
|
||||
|
||||
public static ByteArrayTuple of(byte[] first, byte[] second) {
|
||||
return new ByteArrayTuple(first, second);
|
||||
}
|
||||
}
|
|
@ -161,10 +161,10 @@ public class CKZG4844JNI {
|
|||
*
|
||||
* @param blob blob bytes
|
||||
* @param z_bytes a point
|
||||
* @return an instance of {@link ByteArrayTuple} holding the proof and the value y = f(z)
|
||||
* @return an instance of {@link ProofAndY} holding the proof and the value y = f(z)
|
||||
* @throws CKZGException if there is a crypto error
|
||||
*/
|
||||
public static native ByteArrayTuple computeKzgProof(byte[] blob, byte[] z_bytes);
|
||||
public static native ProofAndY computeKzgProof(byte[] blob, byte[] z_bytes);
|
||||
|
||||
/**
|
||||
* Given a blob, return the KZG proof that is used to verify it against the commitment
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
package ethereum.ckzg4844;
|
||||
|
||||
public class ProofAndY {
|
||||
private final byte[] proof;
|
||||
private final byte[] y;
|
||||
|
||||
public ProofAndY(byte[] proof, byte[] y) {
|
||||
this.proof = proof;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public byte[] getProof() {
|
||||
return proof;
|
||||
}
|
||||
|
||||
public byte[] getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public static ProofAndY of(byte[] proof, byte[] y) {
|
||||
return new ProofAndY(proof, y);
|
||||
}
|
||||
}
|
|
@ -70,10 +70,10 @@ public class CKZG4844JNITest {
|
|||
if (PRESET != Preset.MAINNET) return;
|
||||
|
||||
try {
|
||||
ByteArrayTuple tuple =
|
||||
ProofAndY proofAndY =
|
||||
CKZG4844JNI.computeKzgProof(test.getInput().getBlob(), test.getInput().getZ());
|
||||
assertArrayEquals(test.getOutput().getFirst(), tuple.getFirst());
|
||||
assertArrayEquals(test.getOutput().getSecond(), tuple.getSecond());
|
||||
assertArrayEquals(test.getOutput().getProof(), proofAndY.getProof());
|
||||
assertArrayEquals(test.getOutput().getY(), proofAndY.getY());
|
||||
} catch (CKZGException ex) {
|
||||
assertNull(test.getOutput());
|
||||
}
|
||||
|
@ -192,9 +192,9 @@ public class CKZG4844JNITest {
|
|||
loadTrustedSetup();
|
||||
final byte[] blob = TestUtils.createRandomBlob();
|
||||
final byte[] z_bytes = TestUtils.randomBLSFieldElementBytes();
|
||||
final ByteArrayTuple tuple = CKZG4844JNI.computeKzgProof(blob, z_bytes);
|
||||
assertEquals(CKZG4844JNI.BYTES_PER_PROOF, tuple.getFirst().length);
|
||||
assertEquals(CKZG4844JNI.BYTES_PER_FIELD_ELEMENT, tuple.getSecond().length);
|
||||
final ProofAndY proofAndY = CKZG4844JNI.computeKzgProof(blob, z_bytes);
|
||||
assertEquals(CKZG4844JNI.BYTES_PER_PROOF, proofAndY.getProof().length);
|
||||
assertEquals(CKZG4844JNI.BYTES_PER_FIELD_ELEMENT, proofAndY.getY().length);
|
||||
CKZG4844JNI.freeTrustedSetup();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package ethereum.ckzg4844.test_formats;
|
||||
|
||||
import ethereum.ckzg4844.ByteArrayTuple;
|
||||
import ethereum.ckzg4844.ProofAndY;
|
||||
import java.util.List;
|
||||
import org.apache.tuweni.bytes.Bytes;
|
||||
|
||||
|
@ -25,12 +25,12 @@ public class ComputeKzgProofTest {
|
|||
return input;
|
||||
}
|
||||
|
||||
public ByteArrayTuple getOutput() {
|
||||
public ProofAndY getOutput() {
|
||||
if (output == null) {
|
||||
return null;
|
||||
}
|
||||
byte[] proof = Bytes.fromHexString(output.get(0)).toArray();
|
||||
byte[] y = Bytes.fromHexString(output.get(1)).toArray();
|
||||
return ByteArrayTuple.of(proof, y);
|
||||
return ProofAndY.of(proof, y);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue