-
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.
Constantine bindings for EIP196 (#184)
* constantine bindings for EIP-196, EIP-197 Signed-off-by: Nischal Sharma <nischal@web3labs.com> Co-authored-by: garyschulte <garyschulte@gmail.com>
- Loading branch information
1 parent
d0e3d0d
commit 462238e
Showing
17 changed files
with
836 additions
and
2 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 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 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,145 @@ | ||
plugins { | ||
id 'java-library' | ||
id 'maven-publish' | ||
id 'com.jfrog.artifactory' version '5.2.3' | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation 'net.java.dev.jna:jna:5.12.1' | ||
testImplementation 'com.google.guava:guava:31.1-jre' | ||
testImplementation 'io.tmio:tuweni-bytes:2.4.2' | ||
testImplementation 'junit:junit:4.13.2' | ||
} | ||
|
||
java { | ||
toolchain { | ||
languageVersion = JavaLanguageVersion.of(21) | ||
} | ||
} | ||
|
||
tasks.withType(JavaCompile) { | ||
options.encoding = 'UTF-8' | ||
} | ||
|
||
def osName = System.getProperty('os.name').toLowerCase() | ||
def osArch = System.getProperty('os.arch') | ||
def libDir | ||
|
||
if (osName.contains('mac') && osArch.contains('aarch64')) { | ||
libDir = 'darwin-aarch64' | ||
} else if (osName.contains('mac')) { | ||
libDir = 'darwin-x86-64' | ||
} else if (osName.contains('linux') && osArch.contains('aarch64')) { | ||
libDir = 'linux-gnu-aarch64' | ||
} else { | ||
libDir = 'linux-gnu-x86_64' | ||
} | ||
|
||
task libCopy(type: Copy) { | ||
from "build/${libDir}/lib/" | ||
into "build/resources/main/lib/${libDir}" | ||
} | ||
|
||
processResources.dependsOn libCopy | ||
|
||
task compileJavaSource(type: Exec) { | ||
description = 'Compiles the Java source files' | ||
commandLine 'javac', '-d', 'build', 'src/main/java/org/hyperledger/besu/nativelib/constantine/LibConstantineEIP196.java' | ||
dependsOn libCopy | ||
} | ||
|
||
tasks.named('test', Test) { | ||
description = 'Runs the Java tests' | ||
useJUnit { | ||
include '**/*Test.class' | ||
} | ||
environment 'LD_LIBRARY_PATH', "${System.env.LD_LIBRARY_PATH}:build/resources/main/lib/${libDir}" | ||
jvmArgs = ["-Djava.library.path=build/resources/main/lib/${libDir}"] | ||
dependsOn compileJavaSource | ||
} | ||
|
||
jar { | ||
archiveBaseName = 'besu-native-constantine' | ||
includeEmptyDirs = false | ||
manifest { | ||
attributes( | ||
'Specification-Title': archiveBaseName, | ||
'Specification-Version': project.version, | ||
'Implementation-Title': archiveBaseName, | ||
'Implementation-Version': project.version, | ||
'Automatic-Module-Name': 'org.hyperledger.besu.nativelib.constantine' | ||
) | ||
} | ||
} | ||
|
||
task sourcesJar(type: Jar, dependsOn: classes) { | ||
archiveBaseName = 'besu-native-constantine' | ||
archiveClassifier = 'sources' | ||
from sourceSets.main.allSource | ||
} | ||
|
||
task javadocJar(type: Jar, dependsOn: javadoc) { | ||
archiveBaseName = 'besu-native-constantine' | ||
archiveClassifier = 'javadoc' | ||
from javadoc.destinationDir | ||
} | ||
|
||
publishing { | ||
publications { | ||
mavenJava(MavenPublication) { | ||
groupId "org.hyperledger.besu" | ||
artifactId 'constantine' | ||
version "${project.version}" | ||
|
||
from components.java | ||
artifact sourcesJar | ||
artifact javadocJar | ||
|
||
pom { | ||
name = "Besu Native - ${project.name}" | ||
description = 'Adapter for native constantine library' | ||
url = 'http://github.com/hyperledger/besu-native' | ||
licenses { | ||
license { | ||
name = 'The Apache License, Version 2.0' | ||
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt' | ||
} | ||
} | ||
scm { | ||
connection = 'scm:git:git://github.com/hyperledger/besu-native.git' | ||
developerConnection = 'scm:git:ssh://github.com/hyperledger/besu-native.git' | ||
url = 'https://github.com/hyperledger/besu-native' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
def artifactoryUser = project.hasProperty('artifactoryUser') ? project.property('artifactoryUser') : System.getenv('ARTIFACTORY_USER') | ||
def artifactoryKey = project.hasProperty('artifactoryApiKey') ? project.property('artifactoryApiKey') : System.getenv('ARTIFACTORY_KEY') | ||
def artifactoryRepo = System.getenv('ARTIFACTORY_REPO') ?: 'besu-maven' | ||
def artifactoryOrg = System.getenv('ARTIFACTORY_ORG') ?: 'hyperledger' | ||
|
||
artifactory { | ||
contextUrl = "https://hyperledger.jfrog.io/${artifactoryOrg}" | ||
publish { | ||
repository { | ||
repoKey = artifactoryRepo | ||
username = artifactoryUser | ||
password = artifactoryKey | ||
} | ||
defaults { | ||
publications('mavenJava') | ||
publishArtifacts = true | ||
publishPom = true | ||
} | ||
} | ||
} | ||
|
||
test { | ||
useJUnit() | ||
} |
Submodule constantine
added at
b13816
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,51 @@ | ||
#include <jni.h> | ||
#include "ethereum_evm_precompiles.h" | ||
#include <constantine.h> | ||
#include <stdio.h> | ||
|
||
void printByteArray(const char* label, const byte* array, size_t len) { | ||
printf("%s: [", label); | ||
for (size_t i = 0; i < len; i++) { | ||
printf("%02x", array[i]); | ||
if (i < len - 1) { | ||
printf(", "); | ||
} | ||
} | ||
printf("]\n"); | ||
} | ||
|
||
JNIEXPORT jint JNICALL Java_org_hyperledger_besu_nativelib_constantine_LibConstantineEIP196_ctt_1eth_1evm_1bn254_1g1add(JNIEnv *env, jobject obj, jbyteArray jr, jint r_len, jbyteArray jinputs, jint inputs_len) { | ||
jbyte *r = (*env)->GetByteArrayElements(env, jr, NULL); | ||
jbyte *inputs = (*env)->GetByteArrayElements(env, jinputs, NULL); | ||
|
||
ctt_evm_status status = ctt_eth_evm_bn254_g1add((byte *)r, (ptrdiff_t)r_len, (const byte *)inputs, (ptrdiff_t)inputs_len); | ||
|
||
(*env)->ReleaseByteArrayElements(env, jr, r, 0); | ||
(*env)->ReleaseByteArrayElements(env, jinputs, inputs, 0); | ||
|
||
return (jint)status; | ||
} | ||
|
||
JNIEXPORT jint JNICALL Java_org_hyperledger_besu_nativelib_constantine_LibConstantineEIP196_ctt_1eth_1evm_1bn254_1g1mul(JNIEnv *env, jobject obj, jbyteArray jr, jint r_len, jbyteArray jinputs, jint inputs_len) { | ||
jbyte *r = (*env)->GetByteArrayElements(env, jr, NULL); | ||
jbyte *inputs = (*env)->GetByteArrayElements(env, jinputs, NULL); | ||
|
||
ctt_evm_status status = ctt_eth_evm_bn254_g1mul((byte *)r, (ptrdiff_t)r_len, (const byte *)inputs, (ptrdiff_t)inputs_len); | ||
|
||
(*env)->ReleaseByteArrayElements(env, jr, r, 0); | ||
(*env)->ReleaseByteArrayElements(env, jinputs, inputs, 0); | ||
|
||
return (jint)status; | ||
} | ||
|
||
JNIEXPORT jint JNICALL Java_org_hyperledger_besu_nativelib_constantine_LibConstantineEIP196_ctt_1eth_1evm_1bn254_1pairingCheck(JNIEnv *env, jobject obj, jbyteArray jr, jint r_len, jbyteArray jinputs, jint inputs_len) { | ||
jbyte *r = (*env)->GetByteArrayElements(env, jr, NULL); | ||
jbyte *inputs = (*env)->GetByteArrayElements(env, jinputs, NULL); | ||
|
||
ctt_evm_status status = ctt_eth_evm_bn254_ecpairingcheck((byte *)r, (ptrdiff_t)r_len, (const byte *)inputs, (ptrdiff_t)inputs_len); | ||
|
||
(*env)->ReleaseByteArrayElements(env, jr, r, 0); | ||
(*env)->ReleaseByteArrayElements(env, jinputs, inputs, 0); | ||
|
||
return (jint)status; | ||
} |
Oops, something went wrong.