diff --git a/arithmetic/build.gradle b/arithmetic/build.gradle index fdabb730..a81e96c9 100644 --- a/arithmetic/build.gradle +++ b/arithmetic/build.gradle @@ -22,7 +22,7 @@ plugins { dependencies { implementation 'net.java.dev.jna:jna:5.12.1' testImplementation 'com.google.guava:guava:31.1-jre' - testImplementation 'org.apache.tuweni:tuweni-bytes:2.2.0' + testImplementation 'io.tmio:tuweni-bytes:2.4.2' testImplementation 'org.assertj:assertj-core:3.22.0' testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2' testImplementation 'org.junit.jupiter:junit-jupiter-params:5.8.2' diff --git a/bls12-381/build.gradle b/bls12-381/build.gradle index a72bb85a..2ac5a06b 100644 --- a/bls12-381/build.gradle +++ b/bls12-381/build.gradle @@ -1,5 +1,5 @@ /* - * Copyright ConsenSys AG. + * Copyright Hyperledger Besu contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at @@ -23,7 +23,7 @@ dependencies { implementation 'net.java.dev.jna:jna:5.12.1' testImplementation 'com.google.guava:guava:31.1-jre' testImplementation 'junit:junit:4.13.2' - testImplementation 'org.apache.tuweni:tuweni-bytes:2.2.0' + testImplementation 'io.tmio:tuweni-bytes:2.4.2' testImplementation 'org.assertj:assertj-core:3.22.0' } diff --git a/gnark/build.gradle b/gnark/build.gradle index 3142d34a..6bff6c8a 100644 --- a/gnark/build.gradle +++ b/gnark/build.gradle @@ -21,8 +21,9 @@ plugins { dependencies { implementation 'net.java.dev.jna:jna:5.12.1' + testImplementation 'com.google.guava:guava:31.1-jre' testImplementation 'net.java.dev.jna:jna:5.12.1' - implementation 'org.apache.tuweni:tuweni-bytes:2.2.0' + testImplementation 'io.tmio:tuweni-bytes:2.4.2' testImplementation 'junit:junit:4.13.2' testImplementation 'org.assertj:assertj-core:3.22.0' testImplementation 'org.mockito:mockito-core:4.4.0' diff --git a/gnark/src/main/java/org/hyperledger/besu/nativelib/gnark/LibGnarkEIP196.java b/gnark/src/main/java/org/hyperledger/besu/nativelib/gnark/LibGnarkEIP196.java index 06ffaac1..17b1c7af 100644 --- a/gnark/src/main/java/org/hyperledger/besu/nativelib/gnark/LibGnarkEIP196.java +++ b/gnark/src/main/java/org/hyperledger/besu/nativelib/gnark/LibGnarkEIP196.java @@ -2,7 +2,6 @@ import com.sun.jna.Native; import com.sun.jna.ptr.IntByReference; -import org.apache.tuweni.bytes.Bytes; public class LibGnarkEIP196 { @@ -61,8 +60,7 @@ public static int eip196_perform_operation( } if (ret != 0) { - var errBytes = Bytes.wrap(err); - err_len.setValue(errBytes.size() - errBytes.numberOfTrailingZeroBytes()); + err_len.setValue(LibGnarkUtils.findFirstTrailingZeroIndex(err)); o_len.setValue(0); } else { err_len.setValue(0); @@ -70,7 +68,6 @@ public static int eip196_perform_operation( return ret; } - public static native int eip196altbn128G1Add( byte[] input, byte[] output, diff --git a/gnark/src/main/java/org/hyperledger/besu/nativelib/gnark/LibGnarkEIP2537.java b/gnark/src/main/java/org/hyperledger/besu/nativelib/gnark/LibGnarkEIP2537.java index 1c56c5b6..7cf245d8 100644 --- a/gnark/src/main/java/org/hyperledger/besu/nativelib/gnark/LibGnarkEIP2537.java +++ b/gnark/src/main/java/org/hyperledger/besu/nativelib/gnark/LibGnarkEIP2537.java @@ -3,9 +3,6 @@ import com.sun.jna.Library; import com.sun.jna.Native; import com.sun.jna.ptr.IntByReference; -import org.apache.tuweni.bytes.Bytes; - -import java.nio.charset.StandardCharsets; public class LibGnarkEIP2537 implements Library { @@ -110,8 +107,7 @@ public static int eip2537_perform_operation( } if (ret != 0) { - var errBytes = Bytes.wrap(err); - err_len.setValue(errBytes.size() - errBytes.numberOfTrailingZeroBytes()); + err_len.setValue(LibGnarkUtils.findFirstTrailingZeroIndex(err)); o_len.setValue(0); } else { err_len.setValue(0); diff --git a/gnark/src/main/java/org/hyperledger/besu/nativelib/gnark/LibGnarkUtils.java b/gnark/src/main/java/org/hyperledger/besu/nativelib/gnark/LibGnarkUtils.java new file mode 100644 index 00000000..e8fc70d1 --- /dev/null +++ b/gnark/src/main/java/org/hyperledger/besu/nativelib/gnark/LibGnarkUtils.java @@ -0,0 +1,14 @@ +package org.hyperledger.besu.nativelib.gnark; + +public class LibGnarkUtils { + + public static int findFirstTrailingZeroIndex(byte[] array) { + for (int i = array.length - 1; i >= 0; i--) { + if (array[i] != 0) { + return i + 1; // The first trailing zero is after this non-zero byte + } + } + // If all bytes are zero, return 0 + return 0; + } +} diff --git a/ipa-multipoint/build.gradle b/ipa-multipoint/build.gradle index c86ca91b..103a7bb7 100644 --- a/ipa-multipoint/build.gradle +++ b/ipa-multipoint/build.gradle @@ -21,7 +21,7 @@ plugins { dependencies { implementation 'net.java.dev.jna:jna:5.12.1' - testImplementation 'org.apache.tuweni:tuweni-bytes:2.3.1' + testImplementation 'io.tmio:tuweni-bytes:2.4.2' testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.2' testImplementation 'org.junit.jupiter:junit-jupiter-params:5.7.2' testImplementation 'com.fasterxml.jackson.core:jackson-databind:2.12.5' diff --git a/secp256r1/build.gradle b/secp256r1/build.gradle index d948cab4..2111de60 100644 --- a/secp256r1/build.gradle +++ b/secp256r1/build.gradle @@ -1,5 +1,5 @@ /* - * Copyright ConsenSys AG. + * Copyright Hyperledger Besu contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at @@ -24,7 +24,7 @@ dependencies { testImplementation 'com.google.guava:guava:31.1-jre' testImplementation 'junit:junit:4.13.2' - testImplementation 'org.apache.tuweni:tuweni-bytes:2.2.0' + testImplementation 'io.tmio:tuweni-bytes:2.4.2' testImplementation 'org.assertj:assertj-core:3.22.0' }