Skip to content

Commit

Permalink
android snark impl success 🎉
Browse files Browse the repository at this point in the history
  • Loading branch information
kyoungbinkim committed Feb 18, 2023
1 parent af113bd commit 73d5eb9
Show file tree
Hide file tree
Showing 15 changed files with 228,562 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"java.configuration.updateBuildConfiguration": "interactive"
}
15 changes: 13 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ import org.apache.tools.ant.taskdefs.condition.Os

project.ext.react = [
enableHermes: true, // clean and rebuild if changing
// deleteDebugFilesForVariant: { false },
]

apply from: "../../node_modules/react-native/react.gradle"
Expand Down Expand Up @@ -134,6 +135,13 @@ android {

compileSdkVersion rootProject.ext.compileSdkVersion

packagingOptions {
pickFirst 'lib/x86/libc++_shared.so'
pickFirst 'lib/x86_64/libc++_shared.so'
pickFirst 'lib/armeabi-v7a/libc++_shared.so'
pickFirst 'jniLibs/arm64-v8a/libc++_shared.so'
}

defaultConfig {
applicationId "com.datatradeapp"
minSdkVersion rootProject.ext.minSdkVersion
Expand Down Expand Up @@ -164,11 +172,14 @@ android {
if (isNewArchitectureEnabled()) {
// We configure the NDK build only if you decide to opt-in for the New Architecture.
externalNativeBuild {
cmake {
// path "$projectDir/src/main/jni/CMakeLists.txt"
// cmake {
// path "$projectDir/src/main/jni/CMakeLists.txt"
// }
ndkBuild {
path "$projectDir/src/main/jni/Android.mk"
}
}

def reactAndroidProjectDir = project(':ReactAndroid').projectDir
def packageReactNdkDebugLibs = tasks.register("packageReactNdkDebugLibs", Copy) {
dependsOn(":ReactAndroid:packageReactNdkDebugLibsForBuck")
Expand Down
Binary file not shown.
228,328 changes: 228,328 additions & 0 deletions android/app/src/main/assets/crs/GenTrade_crs_pk.json

Large diffs are not rendered by default.

Binary file not shown.
120 changes: 120 additions & 0 deletions android/app/src/main/assets/crs/GenTrade_crs_vk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
{
"ABC" : [
[
"0x248CFD373A62AD5C8D07207E6C8DCF4C63EF630CD59029598C27ACC2DCB74331" ,
"0x0D8915486E0F9D7727482398228AE1AF9E656D35919DE474BFE67075695079FD"
] ,
[
"0x256BE4CB8CCE09C71EC6930F8D75C809A4C99B85BA271D5C094960D880C8FB81" ,
"0x1B791FCEAD2978290EE0A9C13BE646C011A2FD00F2B9B55F147DB7D0C009BCCC"
] ,
[
"0x2126DAF05B699143FCAE4AF1204996A972267A8BC7D1F236774D1CFDFBF8E97B" ,
"0x0AC9B1BEE6DC1DF3625883665F08C49C16B7C9C9746AD44F226AA10D0D1DA93E"
] ,
[
"0x2EB41C16155A95E603C9BE93A0B1C4A0523588A90D7A020CD22CABC7A4D1B640" ,
"0x242937CBC9D04407EFB5FFD25DF8F04858DEB26EAEACBAAA1A2091A290B51A99"
] ,
[
"0x076FE43EAEE8A6CB39E718CEB81A73CCC04BF6E95547B243E212F771AA4412E5" ,
"0x0A5CA6D34DBC13D22392E3AF65812A1EF473C7AD723019F53B51F40193BB4E90"
] ,
[
"0x0E6E8DB97013D85AB8682148B0E780A01B253518059EEBF7AE79558456AD96E9" ,
"0x1DB558F9274E1851502AF1F5E09178160FC8BA37DD7DC82236AFE005A1F8EB70"
] ,
[
"0x2291B3FE967028E61073D46773AE5029667223700B610E6DDFA77D212E03920E" ,
"0x072CECC42987ABB995F9CE18FA704FD6765EAEBB0874B1B4CD53DBACE6F686F0"
] ,
[
"0x161A3660A53349C3D175D9EF66BC5A0158851EE26E13AC701B2FD7076502970E" ,
"0x0C49F3C201366C56440960D2E7BCFFFFC0F91F4E60E8F35BDCD2FDC397E39C42"
] ,
[
"0x0BDD592F4433C36F1E1850E9C10E99E19A7E4B5FFE32E2EF5BC1A7D5798B7AE1" ,
"0x1939983D95F85B0FE10828EF79DB20A035FACBE1D755F67D2EE146DF70A2EEA6"
] ,
[
"0x0216CF391A4EE6E9A593A558A62342D687F74C0ECE05CCE6F8E4E6523CAFB32E" ,
"0x2EE5D0054868D1B025F79B6006334AA28A95308952EB7D1A8F5CB8FAA100C608"
] ,
[
"0x278CC1112860758A4FAE92483126FF3FA0791259B52FD54660DA46E1478FBD3B" ,
"0x1BB30343EA811468EE2468F618A190E0272E3DF22B8402574A6DE57C3F4E8336"
] ,
[
"0x04E7E292A6992CC9BD56285300ADD104062DF14AD7ECA6CCB5DF61CBEFC61029" ,
"0x14FA9272BC81F5E65F93D7B271A499EFAAA0836552E4ADB412F72E220CE05C5E"
] ,
[
"0x26FD8300F986315D3563DB220E87A4A10A35291D33B0BAF053786A1A88AA473C" ,
"0x01B26087CC0475820CBDFB296F4AC264ED8512C4D4C51E350BC7B2D7C9A6D54C"
] ,
[
"0x2E81B0433853BB4FFD02DA981C1351C4004382319350FC6036A274D5370ED3D2" ,
"0x02D18D8162DBD674EA5F1C39719393B469F2620FA4386E28C13418C132A29B2E"
] ,
[
"0x1C67EB619BCBD98510625ACF3C26B823E312CE95ACD0FCD33F2A421CCC530039" ,
"0x1957E24D179783600948C42B8FB224C829CDA37D94D79086C8651FE30EE26D79"
] ,
[
"0x0D81AF6C6457989DABB8A4D010F3E8CC334A0B94F5C3E198C18898660EC230F6" ,
"0x251FB6C493704A033F3B446A587C8E3DF94F688E424A071DA82641D047A40676"
] ,
[
"0x1F5754B081CFE11B50A4D4F2D70CF057A78387DDE918ECF889B1AC87F2B3152B" ,
"0x204500FFE04D443AAD7ECDA67276A4BD029CC858E0DD7562702BC664FEA68BCA"
] ,
[
"0x272C43E6BE4D279FA06207A8BF347410954CB71F1611B5E11128EDA97DC8B128" ,
"0x245B29E642174FAD51A03136A1967FE44D227A071FC05108FD40D24E5AC0A69F"
]
] ,
"Domain Size" : 17 ,
"Indices" : [
0 ,
1 ,
2 ,
3 ,
4 ,
5 ,
6 ,
7 ,
8 ,
9 ,
10 ,
11 ,
12 ,
13 ,
14 ,
15 ,
16
] ,
"alpha" : [
"0x109BF5C9859C67857677D6D356EC040D48E51475C2E48BC0C94120320CAA7CE3" ,
"0x0170DEDC7723DF71699451E4824CF5B5DC4A2E6499E3897708B1A721F639FBB4"
] ,
"beta" : [
[
"0x0257627EFE78D8A3C4F9B6A6198E52EF9C58029EB7092DCD41DE8E6D6562234B" ,
"0x0D46BFA199F289F4D0E5A42C5DDE6ED5FAC94E73EF5D3C0B48AC73BF5698B6DE"
] ,
[
"0x1CA1B68D65AA5336A0BC16D3D61ADE58661B3EA1D979BDCD7186E97C1768BCA5" ,
"0x0DC16119AD58B8CF945C3C4B6BE34BB22F3B5FC688E7CF1625597952FE491D93"
]
] ,
"delta" : [
[
"0x16ABA93A632749C9ABB1AA5E442F50E5AF445570E70B9EF3A50071B8D7BC324F" ,
"0x29F180CF4EFAD03D8C3F53358F5CA2DD003A32ED5AA79D93D8B1FF86751FF8E9"
] ,
[
"0x1F1B8B9ED6053202AE0FDB728B4B18918DA793AC59752BE63CADB5103DF532B7" ,
"0x217E37B83B8D74937CFF1C77B6EA44B0E860466EB4D8B23371889C5438331C6A"
]
]
}
70 changes: 70 additions & 0 deletions android/app/src/main/java/com/datatradeapp/LibsnarkModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,76 @@ public void createCircuitContext(String circuitName, String treeHeight, String h
promise.resolve(resolveData);
}

@ReactMethod
public void createGenTradeCircuitContext(String circuitName, int serializeFormat, int ecSelection, Promise promise) {
int _contextId = snarkJNI.createCircuitContext(circuitName, R1CS_GG, ecSelection, "", "", "");

contextId = _contextId;
contextIdMap.put(circuitName, _contextId);

snarkJNI.serializeFormat(_contextId, serializeFormat);


AssetManager assetManager = reactApplicationContext.getResources().getAssets();
InputStream pkIs = null;
InputStream vkIs = null;
try {
pkIs = assetManager.open("crs/" + circuitName + "_crs_pk.dat");
vkIs = assetManager.open("crs/" + circuitName + "_crs_vk.dat");
long pkFileSize = pkIs.available();
long vkFileSize = vkIs.available();

if (pkFileSize > 0 && vkFileSize > 0) {

byte[] tempPkData = new byte[(int) pkFileSize];
byte[] tempVkData = new byte[(int) vkFileSize];

int pkLen = pkIs.read(tempPkData);
int vkLen = vkIs.read(tempVkData);

// copy CRS
File crsDir = new File(crsDefaultPath + "/crs");

if (!crsDir.exists()) {
crsDir.mkdir();
}
File pkOutFile = new File(crsDir + "/" + circuitName + "_crs_pk.dat");
File vkOutFile = new File(crsDir + "/" + circuitName + "_crs_vk.dat");

if (!pkOutFile.exists() || !vkOutFile.exists()) {
boolean a = pkOutFile.createNewFile();
boolean b = vkOutFile.createNewFile();
}

FileOutputStream pkFW = new FileOutputStream(pkOutFile, false);
FileOutputStream vkFW = new FileOutputStream(vkOutFile, false);

while (pkLen != -1) {
pkFW.write(tempPkData, 0, pkLen);
pkLen = pkIs.read(tempPkData);
}
pkFW.flush();
pkFW.close();
pkIs.close();

while (vkLen != -1) {
vkFW.write(tempVkData, 0, vkLen);
vkLen = vkIs.read(tempVkData);
}
vkFW.flush();
vkFW.close();
vkIs.close();
}
} catch (Exception e) {
Log.e("Exception", String.valueOf(e));
promise.reject(e);
}

WritableMap resolveData = new WritableNativeMap();
resolveData.putString("circuitName", circuitName);
resolveData.putString("contextId", Integer.toString(_contextId));
promise.resolve(resolveData);
}
@ReactMethod
public void buildCircuit(Promise promise) {
int rtn = snarkJNI.buildCircuit(contextId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public List<NativeModule> createNativeModules(
List<NativeModule> modules = new ArrayList<>();

modules.add(new LibsnarkModule(reactContext));

modules.add(new testModule(reactContext));
return modules;
}

Expand Down
23 changes: 23 additions & 0 deletions android/app/src/main/java/com/datatradeapp/testModule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.datatradeapp;

import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;

public class testModule extends ReactContextBaseJavaModule {

testModule(ReactApplicationContext context) {
super(context);
}

@Override
public String getName(){
return "testModule";
}

@ReactMethod
public void helloWorld( Promise promise) {
promise.resolve("HELLO");
}
}
4 changes: 4 additions & 0 deletions android/app/src/main/jni/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ project(datatradeapp_appmodules)

# This file includes all the necessary to let you build your application with the New Architecture.
include(${REACT_ANDROID_DIR}/cmake-utils/ReactNative-application.cmake)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fopenmp -static-openmp")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp -static-openmp")
arguments "-DANDROID_ARM_MODE=arm", "-DANDROID_STL=c++_shared"
Binary file not shown.
Binary file removed android/app/src/main/jniLibs/arm64-v8a/libgmpxx.so
Binary file not shown.
Binary file removed android/app/src/main/jniLibs/arm64-v8a/libssl.so
Binary file not shown.
Binary file not shown.
Binary file added android/app/src/main/jniLibs/x86_64/libSnark.so
Binary file not shown.

0 comments on commit 73d5eb9

Please sign in to comment.