-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Nischal Sharma <nischal@web3labs.com>
- Loading branch information
Showing
2 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...antine/src/main/java/org/hyperledger/besu/nativelib/constantine/LibConstantineVerkle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |