-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for EIP2537 Constantine Lib (#210)
Signed-off-by: Nischal Sharma <nischal@web3labs.com> Signed-off-by: garyschulte <garyschulte@gmail.com> Co-authored-by: garyschulte <garyschulte@gmail.com>
- Loading branch information
1 parent
78acdf6
commit 85ebf97
Showing
27 changed files
with
1,744 additions
and
141 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
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
This file was deleted.
Oops, something went wrong.
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
110 changes: 110 additions & 0 deletions
110
...ntine/src/main/java/org/hyperledger/besu/nativelib/constantine/LibConstantineEIP2537.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,110 @@ | ||
package org.hyperledger.besu.nativelib.constantine; | ||
|
||
import com.sun.jna.Native; | ||
|
||
public class LibConstantineEIP2537 { | ||
public static final boolean ENABLED; | ||
|
||
static { | ||
boolean enabled; | ||
try { | ||
Native.register(LibConstantineEIP2537.class, "constantinebindings"); | ||
enabled = true; | ||
} catch (final Throwable t) { | ||
t.printStackTrace(); | ||
enabled = false; | ||
} | ||
ENABLED = enabled; | ||
} | ||
|
||
public static native int bls12381_g1add(byte[] r, int r_len, byte[] inputs, int inputs_len); | ||
public static native int bls12381_g2add(byte[] r, int r_len, byte[] inputs, int inputs_len); | ||
public static native int bls12381_g1mul(byte[] r, int r_len, byte[] inputs, int inputs_len); | ||
public static native int bls12381_g2mul(byte[] r, int r_len, byte[] inputs, int inputs_len); | ||
public static native int bls12381_g1msm(byte[] r, int r_len, byte[] inputs, int inputs_len); | ||
public static native int bls12381_g2msm(byte[] r, int r_len, byte[] inputs, int inputs_len); | ||
public static native int bls12381_pairingCheck(byte[] r, int r_len, byte[] inputs, int inputs_len); | ||
public static native int bls12381_mapFpToG1(byte[] r, int r_len, byte[] inputs, int inputs_len); | ||
public static native int bls12381_mapFp2ToG2(byte[] r, int r_len, byte[] inputs, int inputs_len); | ||
|
||
public static byte[] g1add(byte[] inputs) { | ||
byte[] result = new byte[128]; | ||
int status = bls12381_g1add(result, result.length, inputs, inputs.length); | ||
if (status != 0) { | ||
throw new RuntimeException("eth_evm_bls12381_g1add failed with status: " + status); | ||
} | ||
return result; | ||
} | ||
|
||
public static byte[] g2add(byte[] inputs) { | ||
byte[] result = new byte[256]; | ||
int status = bls12381_g2add(result, result.length, inputs, inputs.length); | ||
if (status != 0) { | ||
throw new RuntimeException("eth_evm_bls12381_g2add failed with status: " + status); | ||
} | ||
return result; | ||
} | ||
|
||
public static byte[] g1mul(byte[] inputs) { | ||
byte[] result = new byte[128]; | ||
int status = bls12381_g1mul(result, result.length, inputs, inputs.length); | ||
if (status != 0) { | ||
throw new RuntimeException("eth_evm_bls12381_g1mul failed with status: " + status); | ||
} | ||
return result; | ||
} | ||
|
||
public static byte[] g2mul(byte[] inputs) { | ||
byte[] result = new byte[256]; | ||
int status = bls12381_g2mul(result, result.length, inputs, inputs.length); | ||
if (status != 0) { | ||
throw new RuntimeException("eth_evm_bls12381_g2mul failed with status: " + status); | ||
} | ||
return result; | ||
} | ||
|
||
public static byte[] g1msm(byte[] inputs) { | ||
byte[] result = new byte[128]; | ||
int status = bls12381_g1msm(result, result.length, inputs, inputs.length); | ||
if (status != 0) { | ||
throw new RuntimeException("eth_evm_bls12381_g1msm failed with status: " + status); | ||
} | ||
return result; | ||
} | ||
|
||
public static byte[] g2msm(byte[] inputs) { | ||
byte[] result = new byte[256]; | ||
int status = bls12381_g2msm(result, result.length, inputs, inputs.length); | ||
if (status != 0) { | ||
throw new RuntimeException("eth_evm_bls12381_g2msm failed with status: " + status); | ||
} | ||
return result; | ||
} | ||
|
||
public static byte[] pairingCheck(byte[] inputs) { | ||
byte[] result = new byte[32]; | ||
int status = bls12381_pairingCheck(result, result.length, inputs, inputs.length); | ||
if (status != 0) { | ||
throw new RuntimeException("eth_evm_bls12381_pairingcheck failed with status: " + status); | ||
} | ||
return result; | ||
} | ||
|
||
public static byte[] mapFpToG1(byte[] inputs) { | ||
byte[] result = new byte[128]; | ||
int status = bls12381_mapFpToG1(result, result.length, inputs, inputs.length); | ||
if (status != 0) { | ||
throw new RuntimeException("eth_evm_bls12381_map_fp_to_g1 failed with status: " + status); | ||
} | ||
return result; | ||
} | ||
|
||
public static byte[] mapFp2ToG2(byte[] inputs) { | ||
byte[] result = new byte[256]; | ||
int status = bls12381_mapFp2ToG2(result, result.length, inputs, inputs.length); | ||
if (status != 0) { | ||
throw new RuntimeException("eth_evm_bls12381_map_fp2_to_g2 failed with status: " + status); | ||
} | ||
return result; | ||
} | ||
} |
Oops, something went wrong.