Add spotless to the java bindings (#136)

* Add spotless to the java bindings

* Use check task which includes test + all verification
This commit is contained in:
Stefan Bratanov 2023-02-16 11:26:26 +00:00 committed by GitHub
parent 8c3dc2df41
commit 9a764de619
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 178 additions and 127 deletions

View File

@ -65,7 +65,7 @@ build:
.PHONY: test
test:
${GRADLE_COMMAND} clean test
${GRADLE_COMMAND} clean check
.PHONY: benchmark
benchmark:

View File

@ -2,6 +2,7 @@ plugins {
id "application"
id "java-test-fixtures"
id "me.champeau.jmh" version "0.6.8"
id "com.diffplug.spotless" version "6.15.0"
}
repositories {
@ -15,16 +16,22 @@ java {
dependencies {
def junitVersion = "5.9.1"
def junitVersion = "5.9.2"
testImplementation("org.junit.jupiter:junit-jupiter:${junitVersion}")
testImplementation("org.junit.jupiter:junit-jupiter-params:${junitVersion}")
testFixturesImplementation("org.apache.tuweni:tuweni-units:2.3.1")
testFixturesImplementation("com.fasterxml.jackson.core:jackson-databind:2.14.1")
testFixturesImplementation("com.fasterxml.jackson.core:jackson-databind:2.14.2")
}
spotless {
java {
googleJavaFormat()
}
}
test {
useJUnitPlatform()
}

View File

@ -67,10 +67,12 @@ public class CKZG4844JNIBenchmark {
public void setUp() {
final byte[][] blobs = new byte[count][];
final byte[][] commitments = new byte[count][];
IntStream.range(0, count).forEach(i -> {
blobs[i] = TestUtils.createRandomBlob();
commitments[i] = CKZG4844JNI.blobToKzgCommitment(blobs[i]);
});
IntStream.range(0, count)
.forEach(
i -> {
blobs[i] = TestUtils.createRandomBlob();
commitments[i] = CKZG4844JNI.blobToKzgCommitment(blobs[i]);
});
this.blobs = TestUtils.flatten(blobs);
this.commitments = TestUtils.flatten(commitments);
proof = CKZG4844JNI.computeAggregateKzgProof(TestUtils.flatten(blobs), count);
@ -122,8 +124,8 @@ public class CKZG4844JNIBenchmark {
@Benchmark
public boolean verifyAggregateKzgProof(final ComputeAndVerifyState state) {
return CKZG4844JNI.verifyAggregateKzgProof(state.blobs, state.commitments, state.count,
state.proof);
return CKZG4844JNI.verifyAggregateKzgProof(
state.blobs, state.commitments, state.count, state.proof);
}
@Benchmark
@ -131,5 +133,4 @@ public class CKZG4844JNIBenchmark {
public boolean verifyKzgProof(final VerifyKzgProofState state) {
return CKZG4844JNI.verifyKzgProof(state.commitment, state.z, state.y, state.proof);
}
}
}

View File

@ -20,16 +20,21 @@ public class CKZG4844JNI {
*/
public static void loadNativeLibrary(Preset preset) {
String libraryResourcePath =
"lib/" + System.getProperty("os.arch") + "/" + preset.name().toLowerCase() + "/"
"lib/"
+ System.getProperty("os.arch")
+ "/"
+ preset.name().toLowerCase()
+ "/"
+ PLATFORM_NATIVE_LIBRARY_NAME;
InputStream libraryResource = CKZG4844JNI.class.getResourceAsStream(libraryResourcePath);
if (libraryResource == null) {
try {
System.loadLibrary(LIBRARY_NAME);
} catch (UnsatisfiedLinkError __) {
String exceptionMessage = String.format(
"Couldn't load native library (%s). It wasn't available at %s or the library path.",
LIBRARY_NAME, libraryResourcePath);
String exceptionMessage =
String.format(
"Couldn't load native library (%s). It wasn't available at %s or the library path.",
LIBRARY_NAME, libraryResourcePath);
throw new RuntimeException(exceptionMessage);
}
} else {
@ -48,7 +53,8 @@ public class CKZG4844JNI {
}
public enum Preset {
MAINNET(4096), MINIMAL(4);
MAINNET(4096),
MINIMAL(4);
public final int fieldElementsPerBlob;
@ -57,14 +63,14 @@ public class CKZG4844JNI {
}
}
public static final BigInteger BLS_MODULUS = new BigInteger(
"52435875175126190479447740508185965837690552500527637822603658699938581184513");
public static final BigInteger BLS_MODULUS =
new BigInteger(
"52435875175126190479447740508185965837690552500527637822603658699938581184513");
public static final int BYTES_PER_COMMITMENT = 48;
public static final int BYTES_PER_PROOF = 48;
public static final int BYTES_PER_FIELD_ELEMENT = 32;
private CKZG4844JNI() {
}
private CKZG4844JNI() {}
/**
* Calculates the bytes per blob based on the output from {@link #getFieldElementsPerBlob()}
@ -85,9 +91,9 @@ public class CKZG4844JNI {
/**
* Loads the trusted setup from a file. Once loaded, the same setup will be used for all the
* crypto native calls. To load a new setup, free the current one by calling
* {@link #freeTrustedSetup()} and then load the new one. If no trusted setup has been loaded, all
* the crypto native calls will throw a {@link RuntimeException}.
* crypto native calls. To load a new setup, free the current one by calling {@link
* #freeTrustedSetup()} and then load the new one. If no trusted setup has been loaded, all the
* crypto native calls will throw a {@link RuntimeException}.
*
* @param file a path to a trusted setup file
* @throws CKZGException if there is a crypto error
@ -98,9 +104,9 @@ public class CKZG4844JNI {
* An alternative to {@link #loadTrustedSetup(String)}. Loads the trusted setup from method
* parameters instead of a file.
*
* @param g1 g1 values as bytes
* @param g1 g1 values as bytes
* @param g1Count the count of the g1 values
* @param g2 g2 values as bytes
* @param g2 g2 values as bytes
* @param g2Count the count of the g2 values
* @throws CKZGException if there is a crypto error
*/
@ -110,11 +116,11 @@ public class CKZG4844JNI {
* An alternative to {@link #loadTrustedSetup(String)}. Loads the trusted setup from a resource.
*
* @param resource the resource name that contains the trusted setup
* @param clazz the class to use to get the resource
* @param clazz the class to use to get the resource
* @throws CKZGException if there is a crypto error
* @throws IllegalArgumentException if the resource does not exist
*/
public static void loadTrustedSetupFromResource(String resource, Class clazz) {
public static <T> void loadTrustedSetupFromResource(String resource, Class<T> clazz) {
InputStream is = clazz.getResourceAsStream(resource);
if (is == null) {
throw new IllegalArgumentException("Resource " + resource + " does not exist.");
@ -139,7 +145,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
@ -159,16 +165,15 @@ public class CKZG4844JNI {
/**
* Verify aggregated proof and commitments for the given blobs
*
* @param blobs blobs as flattened bytes
* @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 count the count of the blobs (should be same as the count of the commitments)
* @param aggregated_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
@ -183,12 +188,12 @@ 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 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);
}

View File

@ -4,9 +4,7 @@ import static ethereum.ckzg4844.CKZGException.CKZGError.fromErrorCode;
import java.util.Arrays;
/**
* Thrown when there is an error in the underlying c-kzg library.
*/
/** Thrown when there is an error in the underlying c-kzg library. */
public class CKZGException extends RuntimeException {
private final CKZGError error;
@ -27,8 +25,10 @@ public class CKZGException extends RuntimeException {
}
public enum CKZGError {
UNKNOWN(0), C_KZG_BADARGS(1), C_KZG_ERROR(2), C_KZG_MALLOC(3);
UNKNOWN(0),
C_KZG_BADARGS(1),
C_KZG_ERROR(2),
C_KZG_MALLOC(3);
public final int errorCode;
@ -37,9 +37,10 @@ public class CKZGException extends RuntimeException {
}
public static CKZGError fromErrorCode(int errorCode) {
return Arrays.stream(CKZGError.values()).filter(error -> error.errorCode == errorCode)
.findFirst().orElse(UNKNOWN);
return Arrays.stream(CKZGError.values())
.filter(error -> error.errorCode == errorCode)
.findFirst()
.orElse(UNKNOWN);
}
}
}

View File

@ -25,22 +25,34 @@ public class CKZG4844JNITest {
private static final Preset PRESET;
private static final Map<Preset, String> TRUSTED_SETUP_FILE_BY_PRESET = Map.of(Preset.MAINNET,
"../../src/trusted_setup.txt", Preset.MINIMAL, "../../src/trusted_setup_4.txt");
private static final Map<Preset, String> TRUSTED_SETUP_FILE_BY_PRESET =
Map.of(
Preset.MAINNET,
"../../src/trusted_setup.txt",
Preset.MINIMAL,
"../../src/trusted_setup_4.txt");
private static final Map<Preset, String> TRUSTED_SETUP_RESOURCE_BY_PRESET = Map.of(Preset.MAINNET,
"/test-vectors/trusted_setup.txt", Preset.MINIMAL, "/test-vectors/trusted_setup_4.txt");
private static final Map<Preset, String> TRUSTED_SETUP_RESOURCE_BY_PRESET =
Map.of(
Preset.MAINNET,
"/test-vectors/trusted_setup.txt",
Preset.MINIMAL,
"/test-vectors/trusted_setup_4.txt");
static {
PRESET = Optional.ofNullable(System.getenv("PRESET")).map(String::toUpperCase)
.map(Preset::valueOf).orElse(Preset.MAINNET);
PRESET =
Optional.ofNullable(System.getenv("PRESET"))
.map(String::toUpperCase)
.map(Preset::valueOf)
.orElse(Preset.MAINNET);
CKZG4844JNI.loadNativeLibrary(PRESET);
}
@Test
public void getsTheConfiguredFieldElementsPerBlob() {
assertEquals(PRESET.fieldElementsPerBlob, CKZG4844JNI.getFieldElementsPerBlob());
assertEquals(PRESET.fieldElementsPerBlob * CKZG4844JNI.BYTES_PER_FIELD_ELEMENT,
assertEquals(
PRESET.fieldElementsPerBlob * CKZG4844JNI.BYTES_PER_FIELD_ELEMENT,
CKZG4844JNI.getBytesPerBlob());
}
@ -54,10 +66,12 @@ public class CKZG4844JNITest {
final byte[][] blobsArray = new byte[count][];
final byte[][] commitmentsArray = new byte[count][];
IntStream.range(0, count).forEach(i -> {
blobsArray[i] = TestUtils.createRandomBlob();
commitmentsArray[i] = CKZG4844JNI.blobToKzgCommitment(blobsArray[i]);
});
IntStream.range(0, count)
.forEach(
i -> {
blobsArray[i] = TestUtils.createRandomBlob();
commitmentsArray[i] = CKZG4844JNI.blobToKzgCommitment(blobsArray[i]);
});
final byte[] blobs = TestUtils.flatten(blobsArray);
final byte[] commitments = TestUtils.flatten(commitmentsArray);
@ -79,14 +93,16 @@ public class CKZG4844JNITest {
assertFalse(CKZG4844JNI.verifyAggregateKzgProof(blobs, fakeCommitments, count, proof));
CKZG4844JNI.freeTrustedSetup();
}
@ParameterizedTest(name = "{index}")
@MethodSource("getVerifyKzgProofTestVectors")
public void testVerifyKzgProof(final VerifyKzgProofParameters parameters) {
assertTrue(
CKZG4844JNI.verifyKzgProof(parameters.getCommitment(), parameters.getZ(), parameters.getY(),
CKZG4844JNI.verifyKzgProof(
parameters.getCommitment(),
parameters.getZ(),
parameters.getY(),
parameters.getProof()));
}
@ -103,7 +119,6 @@ public class CKZG4844JNITest {
assertEquals(CKZG4844JNI.BYTES_PER_PROOF, proof.length);
CKZG4844JNI.freeTrustedSetup();
}
@Test
@ -113,12 +128,12 @@ public class CKZG4844JNITest {
final byte[] blob = TestUtils.createNonCanonicalBlob();
final CKZGException exception = assertThrows(CKZGException.class,
() -> CKZG4844JNI.blobToKzgCommitment(blob));
final CKZGException exception =
assertThrows(CKZGException.class, () -> CKZG4844JNI.blobToKzgCommitment(blob));
assertEquals(CKZGError.C_KZG_BADARGS, exception.getError());
assertEquals("There was an error while converting blob to commitment.",
exception.getErrorMessage());
assertEquals(
"There was an error while converting blob to commitment.", exception.getErrorMessage());
CKZG4844JNI.freeTrustedSetup();
}
@ -134,12 +149,14 @@ public class CKZG4844JNITest {
// different length for commitments
final byte[] commitments = TestUtils.createRandomCommitments(3);
final CKZGException exception = assertThrows(CKZGException.class,
() -> CKZG4844JNI.verifyAggregateKzgProof(blobs, commitments, count, proof));
final CKZGException exception =
assertThrows(
CKZGException.class,
() -> CKZG4844JNI.verifyAggregateKzgProof(blobs, commitments, count, proof));
assertEquals(CKZGError.C_KZG_BADARGS, exception.getError());
assertEquals("Invalid commitments size. Expected 96 bytes but got 144.",
exception.getErrorMessage());
assertEquals(
"Invalid commitments size. Expected 96 bytes but got 144.", exception.getErrorMessage());
CKZG4844JNI.freeTrustedSetup();
}
@ -149,29 +166,39 @@ public class CKZG4844JNITest {
loadTrustedSetup();
CKZGException exception = assertThrows(CKZGException.class,
() -> CKZG4844JNI.blobToKzgCommitment(new byte[0]));
CKZGException exception =
assertThrows(CKZGException.class, () -> CKZG4844JNI.blobToKzgCommitment(new byte[0]));
assertEquals(CKZGError.C_KZG_BADARGS, exception.getError());
assertEquals(String.format("Invalid blob size. Expected %d bytes but got 0.",
CKZG4844JNI.getBytesPerBlob()),
assertEquals(
String.format(
"Invalid blob size. Expected %d bytes but got 0.", CKZG4844JNI.getBytesPerBlob()),
exception.getErrorMessage());
exception = assertThrows(CKZGException.class,
() -> CKZG4844JNI.computeAggregateKzgProof(new byte[123], 1));
exception =
assertThrows(
CKZGException.class, () -> CKZG4844JNI.computeAggregateKzgProof(new byte[123], 1));
assertEquals(CKZGError.C_KZG_BADARGS, exception.getError());
assertEquals(String.format("Invalid blobs size. Expected %d bytes but got 123.",
CKZG4844JNI.getBytesPerBlob()),
assertEquals(
String.format(
"Invalid blobs size. Expected %d bytes but got 123.", CKZG4844JNI.getBytesPerBlob()),
exception.getErrorMessage());
exception = assertThrows(CKZGException.class,
() -> CKZG4844JNI.verifyAggregateKzgProof(new byte[42], TestUtils.createRandomCommitment(),
2, TestUtils.createRandomProof(2)));
exception =
assertThrows(
CKZGException.class,
() ->
CKZG4844JNI.verifyAggregateKzgProof(
new byte[42],
TestUtils.createRandomCommitment(),
2,
TestUtils.createRandomProof(2)));
assertEquals(CKZGError.C_KZG_BADARGS, exception.getError());
assertEquals(String.format("Invalid blobs size. Expected %d bytes but got 42.",
CKZG4844JNI.getBytesPerBlob() * 2),
assertEquals(
String.format(
"Invalid blobs size. Expected %d bytes but got 42.", CKZG4844JNI.getBytesPerBlob() * 2),
exception.getErrorMessage());
CKZG4844JNI.freeTrustedSetup();
@ -180,11 +207,12 @@ public class CKZG4844JNITest {
@Test
public void throwsIfMethodIsUsedWithoutLoadingTrustedSetup() {
final RuntimeException exception = assertThrows(RuntimeException.class,
() -> CKZG4844JNI.blobToKzgCommitment(TestUtils.createRandomBlob()));
final RuntimeException exception =
assertThrows(
RuntimeException.class,
() -> CKZG4844JNI.blobToKzgCommitment(TestUtils.createRandomBlob()));
assertExceptionIsTrustedSetupIsNotLoaded(exception);
}
@Test
@ -192,24 +220,23 @@ public class CKZG4844JNITest {
loadTrustedSetup();
final RuntimeException exception = assertThrows(RuntimeException.class,
CKZG4844JNITest::loadTrustedSetup);
final RuntimeException exception =
assertThrows(RuntimeException.class, CKZG4844JNITest::loadTrustedSetup);
assertEquals("Trusted Setup is already loaded. Free it before loading a new one.",
assertEquals(
"Trusted Setup is already loaded. Free it before loading a new one.",
exception.getMessage());
CKZG4844JNI.freeTrustedSetup();
}
@Test
public void throwsIfTryToFreeTrustedSetupWithoutLoadingIt() {
final RuntimeException exception = assertThrows(RuntimeException.class,
CKZG4844JNI::freeTrustedSetup);
final RuntimeException exception =
assertThrows(RuntimeException.class, CKZG4844JNI::freeTrustedSetup);
assertExceptionIsTrustedSetupIsNotLoaded(exception);
}
private void assertExceptionIsTrustedSetupIsNotLoaded(final RuntimeException exception) {
@ -222,10 +249,7 @@ public class CKZG4844JNITest {
loadTrustedSetup();
break;
case PARAMETERS:
final LoadTrustedSetupParameters parameters = TestUtils.createLoadTrustedSetupParameters(
TRUSTED_SETUP_FILE_BY_PRESET.get(PRESET));
CKZG4844JNI.loadTrustedSetup(parameters.getG1(), parameters.getG1Count(), parameters.getG2(),
parameters.getG2Count());
loadTrustedSetupFromParameters();
break;
case RESOURCE:
loadTrustedSetupFromResource();
@ -237,8 +261,16 @@ public class CKZG4844JNITest {
CKZG4844JNI.loadTrustedSetup(TRUSTED_SETUP_FILE_BY_PRESET.get(PRESET));
}
private static void loadTrustedSetupFromParameters() {
final LoadTrustedSetupParameters parameters =
TestUtils.createLoadTrustedSetupParameters(TRUSTED_SETUP_FILE_BY_PRESET.get(PRESET));
CKZG4844JNI.loadTrustedSetup(
parameters.getG1(), parameters.getG1Count(), parameters.getG2(), parameters.getG2Count());
}
public static void loadTrustedSetupFromResource() {
CKZG4844JNI.loadTrustedSetupFromResource(TRUSTED_SETUP_RESOURCE_BY_PRESET.get(PRESET), CKZG4844JNITest.class);
CKZG4844JNI.loadTrustedSetupFromResource(
TRUSTED_SETUP_RESOURCE_BY_PRESET.get(PRESET), CKZG4844JNITest.class);
}
private static Stream<VerifyKzgProofParameters> getVerifyKzgProofTestVectors() {

View File

@ -7,8 +7,8 @@ public class LoadTrustedSetupParameters {
private final byte[] g2;
private final long g2Count;
public LoadTrustedSetupParameters(final byte[] g1, final long g1Count, final byte[] g2,
final long g2Count) {
public LoadTrustedSetupParameters(
final byte[] g1, final long g1Count, final byte[] g2, final long g2Count) {
this.g1 = g1;
this.g1Count = g1Count;
this.g2 = g2;

View File

@ -35,15 +35,17 @@ public class TestUtils {
}
public static byte[] createRandomBlob() {
final byte[][] blob = IntStream.range(0, CKZG4844JNI.getFieldElementsPerBlob())
.mapToObj(__ -> randomBLSFieldElement())
.map(fieldElement -> fieldElement.toArray(ByteOrder.LITTLE_ENDIAN)).toArray(byte[][]::new);
final byte[][] blob =
IntStream.range(0, CKZG4844JNI.getFieldElementsPerBlob())
.mapToObj(__ -> randomBLSFieldElement())
.map(fieldElement -> fieldElement.toArray(ByteOrder.LITTLE_ENDIAN))
.toArray(byte[][]::new);
return flatten(blob);
}
public static byte[] createRandomBlobs(final int count) {
final byte[][] blobs = IntStream.range(0, count).mapToObj(__ -> createRandomBlob())
.toArray(byte[][]::new);
final byte[][] blobs =
IntStream.range(0, count).mapToObj(__ -> createRandomBlob()).toArray(byte[][]::new);
return flatten(blobs);
}
@ -56,16 +58,17 @@ public class TestUtils {
}
public static byte[] createRandomCommitments(final int count) {
final byte[][] commitments = IntStream.range(0, count).mapToObj(__ -> createRandomCommitment())
.toArray(byte[][]::new);
final byte[][] commitments =
IntStream.range(0, count).mapToObj(__ -> createRandomCommitment()).toArray(byte[][]::new);
return flatten(commitments);
}
public static byte[] createNonCanonicalBlob() {
final byte[][] blob = IntStream.range(0, CKZG4844JNI.getFieldElementsPerBlob())
.mapToObj(__ -> UInt256.valueOf(CKZG4844JNI.BLS_MODULUS.add(BigInteger.valueOf(42))))
.map(greaterThanModulus -> greaterThanModulus.toArray(ByteOrder.LITTLE_ENDIAN))
.toArray(byte[][]::new);
final byte[][] blob =
IntStream.range(0, CKZG4844JNI.getFieldElementsPerBlob())
.mapToObj(__ -> UInt256.valueOf(CKZG4844JNI.BLS_MODULUS.add(BigInteger.valueOf(42))))
.map(greaterThanModulus -> greaterThanModulus.toArray(ByteOrder.LITTLE_ENDIAN))
.toArray(byte[][]::new);
return flatten(blob);
}
@ -75,8 +78,8 @@ public class TestUtils {
*/
public static List<VerifyKzgProofParameters> getVerifyKzgProofTestVectors() {
final JsonNode jsonNode;
try (final InputStream testVectors = readResource(
"test-vectors/public_verify_kzg_proof.json")) {
try (final InputStream testVectors =
readResource("test-vectors/public_verify_kzg_proof.json")) {
jsonNode = OBJECT_MAPPER.readTree(testVectors);
} catch (final IOException ex) {
throw new UncheckedIOException(ex);
@ -84,17 +87,21 @@ public class TestUtils {
final ArrayNode testCases = (ArrayNode) jsonNode.get("TestCases");
final Stream.Builder<VerifyKzgProofParameters> testVectors = Stream.builder();
testVectors.add(VerifyKzgProofParameters.ZERO);
IntStream.range(0, jsonNode.get("NumTestCases").asInt()).mapToObj(i -> {
final JsonNode testCase = testCases.get(i);
final Bytes32 z = Bytes32.fromHexString(testCase.get("InputPoint").asText());
final Bytes32 y = Bytes32.fromHexString(testCase.get("ClaimedValue").asText());
final Bytes commitment = Bytes.fromHexString(testCase.get("Commitment").asText(),
CKZG4844JNI.BYTES_PER_COMMITMENT);
final Bytes proof = Bytes.fromHexString(testCase.get("Proof").asText(),
CKZG4844JNI.BYTES_PER_PROOF);
return new VerifyKzgProofParameters(commitment.toArray(), z.toArray(), y.toArray(),
proof.toArray());
}).forEach(testVectors::add);
IntStream.range(0, jsonNode.get("NumTestCases").asInt())
.mapToObj(
i -> {
final JsonNode testCase = testCases.get(i);
final Bytes32 z = Bytes32.fromHexString(testCase.get("InputPoint").asText());
final Bytes32 y = Bytes32.fromHexString(testCase.get("ClaimedValue").asText());
final Bytes commitment =
Bytes.fromHexString(
testCase.get("Commitment").asText(), CKZG4844JNI.BYTES_PER_COMMITMENT);
final Bytes proof =
Bytes.fromHexString(testCase.get("Proof").asText(), CKZG4844JNI.BYTES_PER_PROOF);
return new VerifyKzgProofParameters(
commitment.toArray(), z.toArray(), y.toArray(), proof.toArray());
})
.forEach(testVectors::add);
return testVectors.build().collect(Collectors.toList());
}
@ -135,5 +142,4 @@ public class TestUtils {
private static InputStream readResource(final String resource) {
return Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
}
}

View File

@ -19,8 +19,8 @@ public class VerifyKzgProofParameters {
private final byte[] y;
private final byte[] proof;
public VerifyKzgProofParameters(final byte[] commitment, final byte[] z, final byte[] y,
final byte[] proof) {
public VerifyKzgProofParameters(
final byte[] commitment, final byte[] z, final byte[] y, final byte[] proof) {
this.commitment = commitment;
this.z = z;
this.y = y;
@ -42,5 +42,4 @@ public class VerifyKzgProofParameters {
public byte[] getProof() {
return proof;
}
}