Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug Eip2537 constantine build #211

Closed
wants to merge 14 commits into from
Closed
14 changes: 14 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,11 @@ jobs:
with:
name: gnark native build artifacts
path: gnark/build/
- name: Download constantine into build path
uses: actions/download-artifact@v3
with:
name: constantine native build artifacts
path: constantine/build/resources/main
- name: Download constantine
uses: actions/download-artifact@v3
with:
Expand All @@ -352,10 +357,19 @@ jobs:
distribution: adopt
java-version: 21
cache: gradle
- name: Dump environment
run: |
echo $OSTYPE: ${OSTYPE%%[0-9.]*}-`arch` && echo 'System.out.println(System.getProperty("os.name")+"-"+System.getProperty("os.arch") + "\n" + System.getProperty("java.library.path"));' |jshell -
- name: Dump info on constantine libs
run: |
find . -name 'libconstantine*' |xargs -r file
- name: gradle build
uses: gradle/gradle-build-action@v2.4.2
with:
arguments: --no-daemon --parallel build --scan
- name: Dump info on constantine libs
run: |
find . -name 'libconstantine*' |xargs -r file
- uses: actions/upload-artifact@v3.1.0
with:
name: jars
Expand Down
6 changes: 4 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,11 @@ build_constantine() {

# Compile the native library
if [[ "$OSTYPE" == "darwin"* ]]; then
clang -I"${JAVA_HOME}/include" -I"${JAVA_HOME}/include/darwin" -shared -o "$SCRIPTDIR/constantine/build/${OSARCH}/lib/libconstantineeip196.dylib" jna_ethereum_evm_precompiles.c -Iconstantine/include -I. constantine/lib/libconstantine.a
# link against the static libconstantine.a so we do not have to deal with multiple libraries in jni/jna:
clang -I"${JAVA_HOME}/include" -I"${JAVA_HOME}/include/darwin" -shared -o "$SCRIPTDIR/constantine/build/${OSARCH}/lib/libconstantinebindings.dylib" jna_ethereum_evm_precompiles.c -Iconstantine/include -I. constantine/lib/libconstantine.a
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
gcc -I"${JAVA_HOME}/include" -I"${JAVA_HOME}/include/linux" -fPIC -shared -o "$SCRIPTDIR/constantine/build/${OSARCH}/lib/libconstantineeip196.so" jna_ethereum_evm_precompiles.c -Iconstantine/include -I. -Lconstantine/lib constantine/lib/libconstantine.a
# link against the static libconstantine.a so we do not have to deal with multiple libraries in jni/jna:
gcc -I"${JAVA_HOME}/include" -I"${JAVA_HOME}/include/linux" -fPIC -shared -o "$SCRIPTDIR/constantine/build/${OSARCH}/lib/libconstantinebindings.so" jna_ethereum_evm_precompiles.c -Iconstantine/include -I. -Lconstantine/lib constantine/lib/libconstantine.a
else
echo "Unsupported OS/architecture: ${OSARCH}"
exit 1
Expand Down
34 changes: 19 additions & 15 deletions constantine/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,36 +26,40 @@ tasks.withType(JavaCompile) {
}

task macArmLibCopy(type: Copy) {
from "build/darwin-aarch64/lib/libconstantineeip196.dylib"
into 'build/resources/main/darwin-aarch64'
from "build/darwin-aarch64/lib/libconstantinebindings.dylib"
into 'build/resources/main/darwin-aarch64/'
}

task macLibCopy(type: Copy) {
from "build/darwin-x86-64/lib/libconstantineeip196.dylib"
into 'build/resources/main/darwin-x86-64'
from "build/darwin-x86-64/lib/libconstantinebindings.dylib"
into 'build/resources/main/darwin-x86-64/'
}

task linuxLibCopy(type: Copy) {
from "build/linux-gnu-x86_64/lib/libconstantineeip196.so"
into 'build/resources/main/linux-gnu-x86_64'
from "build/linux-gnu-x86_64/lib/libconstantinebindings.so"
into 'build/resources/main/linux-gnu-x86_64/'

}

task linuxArm64LibCopy(type: Copy) {
from "build/linux-gnu-aarch64/lib/libconstantineeip196.so"
into 'build/resources/main/linux-gnu-aarch64'
from "build/linux-gnu-aarch64/lib/libconstantinebindings.so"
into 'build/resources/main/linux-gnu-aarch64/'
}

processResources.dependsOn macArmLibCopy, macLibCopy, linuxLibCopy, linuxArm64LibCopy

tasks.named('test', Test) {
description = 'Runs the Java tests'
useJUnit {
include '**/*Test.class'
task printClasspath {
doLast {
println "Test classpath:"
tasks.test.classpath.each { println it }
}
environment 'LD_LIBRARY_PATH', "${System.env.LD_LIBRARY_PATH}:build/resources/main/linux-gnu-x86_64"

dependsOn macArmLibCopy, macLibCopy, linuxLibCopy, linuxArm64LibCopy
}
test {
dependsOn printClasspath, macArmLibCopy, macLibCopy, linuxLibCopy, linuxArm64LibCopy
environment 'LD_LIBRARY_PATH', "${System.env.LD_LIBRARY_PATH}:./build/resources/main/linux-gnu-x86_64/lib"
var x86LibLocation = file('./build/resources/main/linux-gnu-x86_64/lib').absolutePath
print("x86 jna absolute path: " + x86LibLocation)
systemProperty 'jna.library.path', x86LibLocation
}

jar {
Expand Down
51 changes: 0 additions & 51 deletions constantine/ethereum_evm_precompiles.c

This file was deleted.

37 changes: 0 additions & 37 deletions constantine/ethereum_evm_precompiles.h

This file was deleted.

41 changes: 37 additions & 4 deletions constantine/jna_ethereum_evm_precompiles.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include "jna_ethereum_evm_precompiles.h"
#include <constantine.h>
#include <stdio.h>

Expand All @@ -13,18 +12,52 @@ void printByteArray(const char* label, const byte* array, size_t len) {
printf("]\n");
}

// BN254 functions
int bn254_g1add(byte* r, int r_len, const byte* inputs, int inputs_len) {
// Call the original function
return (int) ctt_eth_evm_bn254_g1add(r, (ptrdiff_t)r_len, inputs, (ptrdiff_t)inputs_len);
}

int bn254_g1mul(byte* r, int r_len, const byte* inputs, int inputs_len) {
// Call the original function
return (int) ctt_eth_evm_bn254_g1mul(r, (ptrdiff_t)r_len, inputs, (ptrdiff_t)inputs_len);
}

int bn254_pairingCheck(byte* r, int r_len, const byte* inputs, int inputs_len) {
// Call the original function
return (int) ctt_eth_evm_bn254_ecpairingcheck(r, (ptrdiff_t)r_len, inputs, (ptrdiff_t)inputs_len);
}

// BLS12-381 functions
int bls12381_g1add(byte* r, int r_len, const byte* inputs, int inputs_len) {
return (int) ctt_eth_evm_bls12381_g1add(r, (ptrdiff_t)r_len, inputs, (ptrdiff_t)inputs_len);
}

int bls12381_g2add(byte* r, int r_len, const byte* inputs, int inputs_len) {
return (int) ctt_eth_evm_bls12381_g2add(r, (ptrdiff_t)r_len, inputs, (ptrdiff_t)inputs_len);
}

int bls12381_g1mul(byte* r, int r_len, const byte* inputs, int inputs_len) {
return (int) ctt_eth_evm_bls12381_g1mul(r, (ptrdiff_t)r_len, inputs, (ptrdiff_t)inputs_len);
}

int bls12381_g2mul(byte* r, int r_len, const byte* inputs, int inputs_len) {
return (int) ctt_eth_evm_bls12381_g2mul(r, (ptrdiff_t)r_len, inputs, (ptrdiff_t)inputs_len);
}

int bls12381_g1msm(byte* r, int r_len, const byte* inputs, int inputs_len) {
return (int) ctt_eth_evm_bls12381_g1msm(r, (ptrdiff_t)r_len, inputs, (ptrdiff_t)inputs_len);
}

int bls12381_g2msm(byte* r, int r_len, const byte* inputs, int inputs_len) {
return (int) ctt_eth_evm_bls12381_g2msm(r, (ptrdiff_t)r_len, inputs, (ptrdiff_t)inputs_len);
}

int bls12381_pairingCheck(byte* r, int r_len, const byte* inputs, int inputs_len) {
return (int) ctt_eth_evm_bls12381_pairingcheck(r, (ptrdiff_t)r_len, inputs, (ptrdiff_t)inputs_len);
}

int bls12381_mapFpToG1(byte* r, int r_len, const byte* inputs, int inputs_len) {
return (int) ctt_eth_evm_bls12381_map_fp_to_g1(r, (ptrdiff_t)r_len, inputs, (ptrdiff_t)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);
}
34 changes: 0 additions & 34 deletions constantine/jna_ethereum_evm_precompiles.h

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class LibConstantineEIP196 {
static {
boolean enabled;
try {
Native.register(LibConstantineEIP196.class, "constantineeip196");
Native.register(LibConstantineEIP196.class, "constantinebindings");
enabled = true;
} catch (final Throwable t) {
t.printStackTrace();
Expand Down
Loading
Loading