diff --git a/constantine/jna_ethereum_evm_precompiles.c b/constantine/jna_ethereum_evm_precompiles.c index 11641275..1acfd74b 100644 --- a/constantine/jna_ethereum_evm_precompiles.c +++ b/constantine/jna_ethereum_evm_precompiles.c @@ -60,4 +60,25 @@ int bls12381_mapFpToG1(byte* r, int r_len, const byte* inputs, int inputs_len) { int bls12381_mapFp2ToG2(byte* r, int r_len, const byte* inputs, int inputs_len) { return (int) ctt_eth_evm_bls12381_map_fp2_to_g2(r, (ptrdiff_t)r_len, inputs, (ptrdiff_t)inputs_len); +} + +// Verkle functions +int ipa_commit(byte* r, int r_len, const byte* inputs, int inputs_len) { + return (int) ipa_commit(r, (ptrdiff_t)r_len, inputs, (ptrdiff_t)inputs_len); +} + +int ipa_prove(byte* r, int r_len, const byte* inputs, int inputs_len) { + return (int) ipa_prove(r, (ptrdiff_t)r_len, inputs, (ptrdiff_t)inputs_len); +} + +int ipa_verify(byte* r, int r_len, const byte* inputs, int inputs_len) { + return (int) ipa_verify(r, (ptrdiff_t)r_len, inputs, (ptrdiff_t)inputs_len); +} + +int ipa_multi_prove(byte* r, int r_len, const byte* inputs, int inputs_len) { + return (int) ipa_multi_prove(r, (ptrdiff_t)r_len, inputs, (ptrdiff_t)inputs_len); +} + +int ipa_multi_verify(byte* r, int r_len, const byte* inputs, int inputs_len) { + return (int) ipa_multi_verify(r, (ptrdiff_t)r_len, inputs, (ptrdiff_t)inputs_len); } \ No newline at end of file diff --git a/constantine/src/main/java/org/hyperledger/besu/nativelib/constantine/LibConstantineVerkle.java b/constantine/src/main/java/org/hyperledger/besu/nativelib/constantine/LibConstantineVerkle.java new file mode 100644 index 00000000..ab15f3b1 --- /dev/null +++ b/constantine/src/main/java/org/hyperledger/besu/nativelib/constantine/LibConstantineVerkle.java @@ -0,0 +1,72 @@ +package org.hyperledger.besu.nativelib.constantine; + +import com.sun.jna.Native; + +public class LibConstantineVerkle { + public static final boolean ENABLED; + + static { + boolean enabled; + try { + Native.register(LibConstantineVerkle.class, "verkle"); + enabled = true; + } catch (final Throwable t) { + t.printStackTrace(); + enabled = false; + } + ENABLED = enabled; + } + + // Declare native methods + public static native int ipa_commit(byte[] r, int r_len, byte[] inputs, int inputs_len); + public static native int ipa_prove(byte[] r, int r_len, byte[] inputs, int inputs_len); + public static native int ipa_verify(byte[] r, int r_len, byte[] inputs, int inputs_len); + public static native int ipa_multi_prove(byte[] r, int r_len, byte[] inputs, int inputs_len); + public static native int ipa_multi_verify(byte[] r, int r_len, byte[] inputs, int inputs_len); + + // Add utility methods for easier access in Java + public static byte[] commit(byte[] inputs) { + byte[] result = new byte[128]; + int status = ipa_commit(result, result.length, inputs, inputs.length); + if (status != 0) { + throw new RuntimeException("ipa_commit failed with status: " + status); + } + return result; + } + + public static byte[] prove(byte[] inputs) { + byte[] result = new byte[128]; + int status = ipa_prove(result, result.length, inputs, inputs.length); + if (status != 0) { + throw new RuntimeException("ipa_prove failed with status: " + status); + } + return result; + } + + public static byte[] verify(byte[] inputs) { + byte[] result = new byte[128]; + int status = ipa_verify(result, result.length, inputs, inputs.length); + if (status != 0) { + throw new RuntimeException("ipa_verify failed with status: " + status); + } + return result; + } + + public static byte[] multiProve(byte[] inputs) { + byte[] result = new byte[128]; + int status = ipa_multi_prove(result, result.length, inputs, inputs.length); + if (status != 0) { + throw new RuntimeException("ipa_multi_prove failed with status: " + status); + } + return result; + } + + public static byte[] multiVerify(byte[] inputs) { + byte[] result = new byte[128]; + int status = ipa_multi_verify(result, result.length, inputs, inputs.length); + if (status != 0) { + throw new RuntimeException("ipa_multi_verify failed with status: " + status); + } + return result; + } +}