mirror of
https://github.com/status-im/c-kzg-4844.git
synced 2025-02-02 13:23:57 +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)
|
||||
public static class ComputeAndVerifyState {
|
||||
|
||||
@ -97,6 +110,11 @@ public class CKZG4844JNIBenchmark {
|
||||
return CKZG4844JNI.blobToKzgCommitment(state.blob);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public byte[] computeKzgProof(final ComputeKzgProofState state) {
|
||||
return CKZG4844JNI.computeKzgProof(state.blob, state.z);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public byte[] computeAggregateKzgProof(final ComputeAndVerifyState state) {
|
||||
return CKZG4844JNI.computeAggregateKzgProof(state.blobs, state.count);
|
||||
|
@ -104,8 +104,7 @@ public class CKZG4844JNI {
|
||||
* @param g2Count the count of the g2 values
|
||||
* @throws CKZGException if there is a crypto error
|
||||
*/
|
||||
public static native void loadTrustedSetup(byte[] g1, long g1Count, byte[] g2,
|
||||
long g2Count);
|
||||
public static native void loadTrustedSetup(byte[] g1, long g1Count, byte[] g2, long g2Count);
|
||||
|
||||
/**
|
||||
* Free the current trusted setup. This method will throw an exception if no trusted setup has
|
||||
@ -116,7 +115,7 @@ public class CKZG4844JNI {
|
||||
/**
|
||||
* Compute proof at point z for the polynomial represented by blob.
|
||||
*
|
||||
* @param blob blob bytes
|
||||
* @param blob blob bytes
|
||||
* @param z_bytes a point
|
||||
* @return the proof
|
||||
* @throws CKZGException if there is a crypto error
|
||||
@ -136,15 +135,16 @@ public class CKZG4844JNI {
|
||||
/**
|
||||
* Verify aggregated proof and commitments for the given blobs
|
||||
*
|
||||
* @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
|
||||
* @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_bytes, long count,
|
||||
byte[] aggregated_proof_bytes);
|
||||
public static native boolean verifyAggregateKzgProof(byte[] blobs, byte[] commitments_bytes,
|
||||
long count, byte[] aggregated_proof_bytes);
|
||||
|
||||
/**
|
||||
* Calculates commitment for a given blob
|
||||
@ -158,14 +158,14 @@ public class CKZG4844JNI {
|
||||
/**
|
||||
* Verify the proof by point evaluation for the given commitment
|
||||
*
|
||||
* @param commitment_bytes commitment bytes
|
||||
* @param z_bytes Z
|
||||
* @param y_bytes Y
|
||||
* @param proof_bytes 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_bytes, byte[] z_bytes, byte[] y_bytes,
|
||||
byte[] proof_bytes);
|
||||
public static native boolean verifyKzgProof(byte[] commitment_bytes, byte[] z_bytes,
|
||||
byte[] y_bytes, byte[] proof_bytes);
|
||||
|
||||
}
|
||||
|
@ -84,11 +84,18 @@ public class CKZG4844JNITest {
|
||||
|
||||
@Test
|
||||
public void checkComputeKzgProof() {
|
||||
|
||||
loadTrustedSetup();
|
||||
|
||||
final byte[] blob = TestUtils.createRandomBlob();
|
||||
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();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
x
Reference in New Issue
Block a user