Skip to content

Commit

Permalink
initial commit for verkle functions
Browse files Browse the repository at this point in the history
Signed-off-by: Nischal Sharma <nischal@web3labs.com>
  • Loading branch information
NickSneo committed Oct 4, 2024
1 parent e788032 commit cd25b4e
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
21 changes: 21 additions & 0 deletions constantine/jna_ethereum_evm_precompiles.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit cd25b4e

Please sign in to comment.