mirror of
https://github.com/status-im/c-kzg-4844.git
synced 2025-01-11 18:54:11 +00:00
Merge pull request #25 from StefanBratanov/canonical_blobs
[Java binding] Use canonical random blobs in tests
This commit is contained in:
commit
dc3fdcf49b
@ -8,6 +8,11 @@ repositories {
|
|||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
java {
|
||||||
|
sourceCompatibility = 11
|
||||||
|
targetCompatibility = 11
|
||||||
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
|
||||||
def junitVersion = "5.9.1"
|
def junitVersion = "5.9.1"
|
||||||
|
@ -193,7 +193,17 @@ JNIEXPORT jbyteArray JNICALL Java_ethereum_ckzg4844_CKZG4844JNI_blobToKzgCommitm
|
|||||||
jbyte *blob_native = (*env)->GetByteArrayElements(env, blob, NULL);
|
jbyte *blob_native = (*env)->GetByteArrayElements(env, blob, NULL);
|
||||||
|
|
||||||
KZGCommitment c;
|
KZGCommitment c;
|
||||||
blob_to_kzg_commitment(&c, (uint8_t *)blob_native, settings);
|
C_KZG_RET ret;
|
||||||
|
|
||||||
|
ret = blob_to_kzg_commitment(&c, (uint8_t *)blob_native, settings);
|
||||||
|
|
||||||
|
if (ret != C_KZG_OK)
|
||||||
|
{
|
||||||
|
char arr[100];
|
||||||
|
sprintf(arr, "There was an error while converting blob bytes to a commitment: %s", C_KZG_RETURN_TYPES[ret]);
|
||||||
|
throw_exception(env, arr);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
jbyteArray commitment = (*env)->NewByteArray(env, BYTES_PER_COMMITMENT);
|
jbyteArray commitment = (*env)->NewByteArray(env, BYTES_PER_COMMITMENT);
|
||||||
uint8_t *out = (uint8_t *)(*env)->GetByteArrayElements(env, commitment, 0);
|
uint8_t *out = (uint8_t *)(*env)->GetByteArrayElements(env, commitment, 0);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
2
bindings/java/gradlew
vendored
2
bindings/java/gradlew
vendored
@ -237,4 +237,4 @@ eval "set -- $(
|
|||||||
tr '\n' ' '
|
tr '\n' ' '
|
||||||
)" '"$@"'
|
)" '"$@"'
|
||||||
|
|
||||||
exec "$JAVACMD" "$@"
|
exec "$JAVACMD" "$@"
|
||||||
|
2
bindings/java/gradlew.bat
vendored
2
bindings/java/gradlew.bat
vendored
@ -88,4 +88,4 @@ exit /b %EXIT_CODE%
|
|||||||
:mainEnd
|
:mainEnd
|
||||||
if "%OS%"=="Windows_NT" endlocal
|
if "%OS%"=="Windows_NT" endlocal
|
||||||
|
|
||||||
:omega
|
:omega
|
||||||
|
@ -2,6 +2,7 @@ package ethereum.ckzg4844;
|
|||||||
|
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.stream.IntStream;
|
import java.util.stream.IntStream;
|
||||||
@ -20,9 +21,8 @@ public class TestUtils {
|
|||||||
|
|
||||||
public static byte[] createRandomBlob() {
|
public static byte[] createRandomBlob() {
|
||||||
final byte[][] blob = IntStream.range(0, CKZG4844JNI.getFieldElementsPerBlob())
|
final byte[][] blob = IntStream.range(0, CKZG4844JNI.getFieldElementsPerBlob())
|
||||||
.mapToObj(__ -> randomBigIntegerInModulus())
|
.mapToObj(__ -> randomBlsFieldElement())
|
||||||
.map(UInt256::valueOf)
|
.map(blsFieldElement -> blsFieldElement.toArray(ByteOrder.LITTLE_ENDIAN))
|
||||||
.map(UInt256::toArray)
|
|
||||||
.toArray(byte[][]::new);
|
.toArray(byte[][]::new);
|
||||||
return flatten(blob);
|
return flatten(blob);
|
||||||
}
|
}
|
||||||
@ -47,12 +47,12 @@ public class TestUtils {
|
|||||||
return flatten(commitments);
|
return flatten(commitments);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static BigInteger randomBigIntegerInModulus() {
|
private static UInt256 randomBlsFieldElement() {
|
||||||
final BigInteger attempt = new BigInteger(CKZG4844JNI.BLS_MODULUS.bitLength(), RANDOM);
|
final BigInteger attempt = new BigInteger(CKZG4844JNI.BLS_MODULUS.bitLength(), RANDOM);
|
||||||
if (attempt.compareTo(CKZG4844JNI.BLS_MODULUS) < 0) {
|
if (attempt.compareTo(CKZG4844JNI.BLS_MODULUS) < 0) {
|
||||||
return attempt;
|
return UInt256.valueOf(attempt);
|
||||||
}
|
}
|
||||||
return randomBigIntegerInModulus();
|
return randomBlsFieldElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user