mirror of
https://github.com/status-im/c-kzg-4844.git
synced 2025-02-13 02:26:33 +00:00
Add java benchmarking for compute_kzg_proof
(#122)
This commit is contained in:
parent
dc28b03f9d
commit
5cfbc34135
@ -40,6 +40,19 @@ public class CKZG4844JNIBenchmark {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@State(Scope.Benchmark)
|
||||||
|
public static class ComputeKzgProofState {
|
||||||
|
|
||||||
|
private byte[] blob;
|
||||||
|
private byte[] z;
|
||||||
|
|
||||||
|
@Setup(Level.Iteration)
|
||||||
|
public void setUp() {
|
||||||
|
blob = TestUtils.createRandomBlob();
|
||||||
|
z = TestUtils.randomBLSFieldElementBytes();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@State(Scope.Benchmark)
|
@State(Scope.Benchmark)
|
||||||
public static class ComputeAndVerifyState {
|
public static class ComputeAndVerifyState {
|
||||||
|
|
||||||
@ -97,6 +110,11 @@ public class CKZG4844JNIBenchmark {
|
|||||||
return CKZG4844JNI.blobToKzgCommitment(state.blob);
|
return CKZG4844JNI.blobToKzgCommitment(state.blob);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Benchmark
|
||||||
|
public byte[] computeKzgProof(final ComputeKzgProofState state) {
|
||||||
|
return CKZG4844JNI.computeKzgProof(state.blob, state.z);
|
||||||
|
}
|
||||||
|
|
||||||
@Benchmark
|
@Benchmark
|
||||||
public byte[] computeAggregateKzgProof(final ComputeAndVerifyState state) {
|
public byte[] computeAggregateKzgProof(final ComputeAndVerifyState state) {
|
||||||
return CKZG4844JNI.computeAggregateKzgProof(state.blobs, state.count);
|
return CKZG4844JNI.computeAggregateKzgProof(state.blobs, state.count);
|
||||||
|
@ -104,8 +104,7 @@ public class CKZG4844JNI {
|
|||||||
* @param g2Count the count of the g2 values
|
* @param g2Count the count of the g2 values
|
||||||
* @throws CKZGException if there is a crypto error
|
* @throws CKZGException if there is a crypto error
|
||||||
*/
|
*/
|
||||||
public static native void loadTrustedSetup(byte[] g1, long g1Count, byte[] g2,
|
public static native void loadTrustedSetup(byte[] g1, long g1Count, byte[] g2, long g2Count);
|
||||||
long g2Count);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Free the current trusted setup. This method will throw an exception if no trusted setup has
|
* Free the current trusted setup. This method will throw an exception if no trusted setup has
|
||||||
@ -138,13 +137,14 @@ public class CKZG4844JNI {
|
|||||||
*
|
*
|
||||||
* @param blobs blobs as flattened bytes
|
* @param blobs blobs as flattened bytes
|
||||||
* @param commitments_bytes commitments 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 count the count of the blobs (should be same as the count of the
|
||||||
|
* commitments)
|
||||||
* @param proof_bytes the proof that needs verifying
|
* @param proof_bytes the proof that needs verifying
|
||||||
* @return true if the proof is valid and false otherwise
|
* @return true if the proof is valid and false otherwise
|
||||||
* @throws CKZGException if there is a crypto error
|
* @throws CKZGException if there is a crypto error
|
||||||
*/
|
*/
|
||||||
public static native boolean verifyAggregateKzgProof(byte[] blobs, byte[] commitments_bytes, long count,
|
public static native boolean verifyAggregateKzgProof(byte[] blobs, byte[] commitments_bytes,
|
||||||
byte[] aggregated_proof_bytes);
|
long count, byte[] aggregated_proof_bytes);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates commitment for a given blob
|
* Calculates commitment for a given blob
|
||||||
@ -165,7 +165,7 @@ public class CKZG4844JNI {
|
|||||||
* @return true if the proof is valid and false otherwise
|
* @return true if the proof is valid and false otherwise
|
||||||
* @throws CKZGException if there is a crypto error
|
* @throws CKZGException if there is a crypto error
|
||||||
*/
|
*/
|
||||||
public static native boolean verifyKzgProof(byte[] commitment_bytes, byte[] z_bytes, byte[] y_bytes,
|
public static native boolean verifyKzgProof(byte[] commitment_bytes, byte[] z_bytes,
|
||||||
byte[] proof_bytes);
|
byte[] y_bytes, byte[] proof_bytes);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -84,11 +84,18 @@ public class CKZG4844JNITest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void checkComputeKzgProof() {
|
public void checkComputeKzgProof() {
|
||||||
|
|
||||||
loadTrustedSetup();
|
loadTrustedSetup();
|
||||||
|
|
||||||
final byte[] blob = TestUtils.createRandomBlob();
|
final byte[] blob = TestUtils.createRandomBlob();
|
||||||
final byte[] z_bytes = TestUtils.randomBLSFieldElementBytes();
|
final byte[] z_bytes = TestUtils.randomBLSFieldElementBytes();
|
||||||
CKZG4844JNI.computeKzgProof(blob, z_bytes);
|
|
||||||
|
final byte[] proof = CKZG4844JNI.computeKzgProof(blob, z_bytes);
|
||||||
|
|
||||||
|
assertEquals(CKZG4844JNI.BYTES_PER_PROOF, proof.length);
|
||||||
|
|
||||||
CKZG4844JNI.freeTrustedSetup();
|
CKZG4844JNI.freeTrustedSetup();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
x
Reference in New Issue
Block a user