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

add aadhaar verifier #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added android/app/src/main/assets/aadhaar_verifier.dat
Binary file not shown.
1 change: 1 addition & 0 deletions android/app/src/main/assets/aadhaar_verifier_input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"qrDataPadded":["86","50","255","51","255","50","54","57","55","50","48","50","52","48","52","50","48","48","49","52","53","53","50","57","51","48","255","83","117","109","105","116","32","75","117","109","97","114","255","48","49","45","48","49","45","49","57","56","52","255","77","255","67","47","79","32","73","115","104","119","97","114","32","67","104","97","110","100","255","69","97","115","116","32","68","101","108","104","105","255","255","66","45","51","49","44","32","51","114","100","32","70","108","111","111","114","255","255","49","49","48","48","53","49","255","75","114","105","115","104","110","97","32","78","97","103","97","114","255","68","101","108","104","105","255","82","97","100","104","101","121","32","83","104","121","97","109","32","80","97","114","107","32","69","120","116","101","110","115","105","111","110","255","71","97","110","100","104","105","32","78","97","103","97","114","255","75","114","105","115","104","110","97","32","78","97","103","97","114","255","49","50","51","52","255","255","79","255","81","0","47","0","0","0","0","0","60","0","0","0","60","0","0","0","0","0","0","0","0","0","0","0","60","0","0","0","60","0","0","0","0","0","0","0","0","0","3","7","1","1","7","1","1","7","1","1","255","82","0","12","2","0","0","1","1","5","4","4","0","0","255","92","0","35","66","111","24","110","234","110","234","110","188","103","0","103","0","102","226","95","76","95","76","95","100","72","3","72","3","72","69","79","210","79","210","79","97","255","100","0","34","0","1","67","114","101","97","116","101","100","32","98","121","58","32","74","74","50","48","48","48","32","118","101","114","115","105","111","110","32","52","46","49","255","144","0","10","0","0","0","0","2","236","0","1","255","82","0","12","2","0","0","1","1","5","4","4","0","0","255","147","255","145","0","4","0","0","195","235","5","4","11","128","38","166","255","145","0","4","0","1","192","249","65","128","16","124","55","255","145","0","4","0","2","192","249","65","0","14","175","255","145","0","4","0","3","195","238","4","131","237","4","131","232","8","15","61","227","128","14","78","244","198","10","190","128","74","255","145","0","4","0","4","192","30","10","3","229","7","0","240","64","15","157","12","56","206","16","124","255","145","0","4","0","5","192","120","40","7","196","14","1","224","128","16","128","16","144","102","15","55","255","145","0","4","0","6","195","235","15","131","232","29","7","202","36","35","123","119","32","21","133","220","173","123","29","124","190","51","158","143","0","4","234","216","145","15","189","91","82","210","45","90","170","52","34","209","158","13","108","213","78","158","137","255","145","0","4","0","7","192","56","56","15","132","112","35","164","155","1","61","240","240","232","42","148","255","145","0","4","0","8","192","49","32","29","20","7","59","113","163","24","138","108","156","26","255","145","0","4","0","9","193","241","27","135","206","122","15","144","184","25","25","211","9","237","209","173","196","150","111","25","246","238","110","167","245","97","24","144","213","187","170","6","133","23","21","199","31","204","1","35","171","39","5","127","48","209","141","130","143","72","200","150","233","85","241","55","128","173","216","49","52","216","139","110","91","225","30","109","204","188","146","157","214","18","87","32","89","157","101","246","187","223","117","50","62","81","65","205","126","255","145","0","4","0","10","160","28","48","34","126","189","171","105","217","255","145","0","4","0","11","160","58","48","35","137","175","61","198","184","255","145","0","4","0","12","199","200","222","62","71","240","248","106","128","111","222","255","137","22","12","202","78","23","233","116","114","125","113","100","226","16","241","69","36","122","23","17","120","240","5","127","168","109","250","155","59","7","206","127","108","18","105","216","235","32","159","93","175","208","238","70","166","172","160","62","58","51","254","8","55","97","246","138","129","137","16","33","165","205","22","186","92","163","108","70","25","168","130","96","162","13","106","78","71","254","89","108","233","225","39","97","63","17","13","42","95","0","30","0","130","28","154","5","162","1","51","178","125","65","235","47","162","24","112","152","119","13","83","212","102","84","248","36","193","63","193","101","254","213","80","59","106","79","74","170","227","110","2","204","201","182","60","114","60","65","195","148","232","145","30","46","232","19","28","159","29","153","101","206","162","28","108","80","229","255","145","0","4","0","13","128","255","145","0","4","0","14","128","255","145","0","4","0","15","195","224","188","135","193","127","15","134","196","158","62","204","245","173","53","224","68","102","215","173","58","244","81","11","131","110","245","166","156","166","215","76","158","156","10","170","148","182","60","115","173","176","16","1","15","169","187","111","38","226","185","241","97","88","34","140","218","123","203","88","112","88","143","74","108","17","106","37","69","149","69","151","215","37","209","201","125","81","117","124","102","108","252","251","26","14","104","229","35","22","219","199","180","110","24","47","126","104","141","232","237","115","47","31","176","190","111","243","116","185","32","185","121","57","59","197","65","61","233","98","18","172","235","82","146","150","241","30","186","172","161","155","148","171","212","237","170","123","85","177","76","132","230","38","114","51","254","36","37","236","202","21","44","48","203","191","154","22","219","13","67","28","214","71","72","63","173","24","137","62","141","14","123","11","237","106","219","68","40","62","29","255","145","0","4","0","16","128","255","145","0","4","0","17","128","255","217","235","89","152","53","59","33","186","193","56","29","117","14","31","162","102","65","224","150","175","57","29","17","95","173","173","212","123","244","250","47","255","139","96","54","34","219","243","92","100","240","182","255","21","167","91","244","127","53","165","180","223","131","221","184","74","53","233","255","238","30","166","5","157","243","128","0","0","0","0","0","0","0","0","0","0","0","0","35","136","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"],"qrDataPaddedLength":1152,"delimiterIndices":[2,4,26,38,49,51,68,79,80,96,97,104,118,124,152,165,179,184],"signature":["1635459164600794819723229437097683843","731579319891476802727850175880972091","1407568402518625741694175368695710666","1969231381860561427088294865568595851","680721088757540816756737225096203871","1265916219309172122125214025571675628","938909390560310035609654475514795176","1711286653840369728609014642235961493","2337020151812458322685252976155470461","2127073810111429691160689763222427394","1324009412273542353578555013609564058","42239721403899080491149735459764323","2157695869608638804792578180950042607","1797033642230153063821090382791875450","1336640899752958703680484328536459911","1558088181164143166587225792852773891","2697425324616182758865404886762430"],"pubKey":["1640818228760052179859042244355947249","2556500785716576226415796061849734159","1773663274924506786300654122545997574","156007087115998107687088234502964965","1007983086444915868913459627234715796","1207907671574654908578158113785868692","661583974440108157749604450701607929","2294674184689511060148392370957342314","2125217202257742866740569471305663059","757604698857004563734075326539558731","200007885942223577865900248803094107","634836160982611096393054589936335825","1449711680328986902465274550271974011","203106953707476066515237197004426128","531393944197892908304277361531706813","2243235350875430237629201981240106035","3040469700157016219231660416032053"],"nullifierSeed":12345678,"signalHash":"10010552857485068401460384516712912466659718519570795790728634837432493097374","revealGender":"0","revealAgeAbove18":"0","revealPinCode":"0","revealState":"0"}
6 changes: 5 additions & 1 deletion android/app/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,13 @@ set_target_properties(semaphore PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}
add_library(sha256_512 SHARED IMPORTED)
set_target_properties(sha256_512 PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/lib/libwitnesscalc_sha256_512.so)

add_library(aadhaar_verifier SHARED IMPORTED)
set_target_properties(aadhaar_verifier PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/lib/libwitnesscalc_aadhaar_verifier.so)


add_library(${CMAKE_PROJECT_NAME} SHARED
moproapp.cpp)

target_link_libraries(${CMAKE_PROJECT_NAME}
android
log rapidsnark keccak256_256_test rsa_main semaphore sha256_512)
log rapidsnark keccak256_256_test rsa_main semaphore sha256_512 aadhaar_verifier)
39 changes: 39 additions & 0 deletions android/app/src/main/cpp/include/witnesscalc_aadhaar_verifier.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#ifndef WITNESSCALC_AADHAARVERIFIER_H
#define WITNESSCALC_AADHAARVERIFIER_H


#ifdef __cplusplus
extern "C" {
#endif

#define WITNESSCALC_OK 0x0
#define WITNESSCALC_ERROR 0x1
#define WITNESSCALC_ERROR_SHORT_BUFFER 0x2

/**
*
* @return error code:
* WITNESSCALC_OK - in case of success.
* WITNESSCALC_ERROR - in case of an error.
*
* On success wtns_buffer is filled with witness data and
* wtns_size contains the number bytes copied to wtns_buffer.
*
* If wtns_buffer is too small then the function returns WITNESSCALC_ERROR_SHORT_BUFFER
* and the minimum size for wtns_buffer in wtns_size.
*
*/

int
witnesscalc_aadhaar_verifier(
const char *circuit_buffer, unsigned long circuit_size,
const char *json_buffer, unsigned long json_size,
char *wtns_buffer, unsigned long *wtns_size,
char *error_msg, unsigned long error_msg_maxsize);

#ifdef __cplusplus
}
#endif


#endif // WITNESSCALC_AADHAARVERIFIER_H
Binary file not shown.
40 changes: 40 additions & 0 deletions android/app/src/main/cpp/moproapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "include/witnesscalc_rsa_main.h"
#include "include/witnesscalc_semaphore.h"
#include "include/witnesscalc_sha256_512.h"
#include "include/witnesscalc_aadhaar_verifier.h"

// Write C++ code here.
//
Expand Down Expand Up @@ -225,4 +226,43 @@ Java_com_example_moproapp_ZKPTools_groth16ProveWithZKeyFilePath(JNIEnv *env, job
env->ReleaseLongArrayElements(publicSize, (jlong *) nativePublicSizeArr, 0);

return status_code;
}
extern "C"
JNIEXPORT jint JNICALL
Java_com_example_moproapp_ZKPTools_witnesscalcAadhaarVerifier(JNIEnv *env, jobject thiz,
jbyteArray circuit_buffer,
jlong circuit_size,
jbyteArray json_buffer,
jlong json_size,
jbyteArray wtns_buffer,
jlongArray wtns_size,
jbyteArray error_msg,
jlong error_msg_max_size) {
const char *circuitBuffer = reinterpret_cast<const char *>(env->GetByteArrayElements(
circuit_buffer, nullptr));
const char *jsonBuffer = reinterpret_cast<const char *>(env->GetByteArrayElements(json_buffer,
nullptr));
char *wtnsBuffer = reinterpret_cast<char *>(env->GetByteArrayElements(wtns_buffer, nullptr));
char *errorMsg = reinterpret_cast<char *>(env->GetByteArrayElements(error_msg, nullptr));

unsigned long wtnsSize = env->GetLongArrayElements(wtns_size, nullptr)[0];


int result = witnesscalc_aadhaar_verifier(
circuitBuffer, static_cast<unsigned long>(circuit_size),
jsonBuffer, static_cast<unsigned long>(json_size),
wtnsBuffer, &wtnsSize,
errorMsg, static_cast<unsigned long>(error_msg_max_size));

// Set the result and release the resources
env->SetLongArrayRegion(wtns_size, 0, 1, reinterpret_cast<jlong *>(&wtnsSize));

env->ReleaseByteArrayElements(circuit_buffer,
reinterpret_cast<jbyte *>(const_cast<char *>(circuitBuffer)), 0);
env->ReleaseByteArrayElements(json_buffer,
reinterpret_cast<jbyte *>(const_cast<char *>(jsonBuffer)), 0);
env->ReleaseByteArrayElements(wtns_buffer, reinterpret_cast<jbyte *>(wtnsBuffer), 0);
env->ReleaseByteArrayElements(error_msg, reinterpret_cast<jbyte *>(errorMsg), 0);

return result;
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ fun MultiplierComponent() {
val sha256ZkeyPath = getFilePathFromAssets("sha256_512_final.zkey")
val rsaZkeyPath = getFilePathFromAssets("rsa_main_final.zkey")
val semaphoreZkeyPath = getFilePathFromAssets("semaphore-32.zkey")
val aadhaarZkeyPath = getFilePathFromAssets("circuit_final.zkey")

var keccak256CircuitPath = getFilePathFromAssets(name = "keccak256_256_test.dat")
var keccak256JsonPath = getFilePathFromAssets(name = "keccak256.json")
Expand All @@ -68,6 +69,9 @@ fun MultiplierComponent() {
var rsaCircuitPath = getFilePathFromAssets(name = "rsa_main.dat")
var rsaJsonPath = getFilePathFromAssets(name = "rsa_main.json")

var aadhaarCircuitPath = getFilePathFromAssets(name = "aadhaar_verifier.dat")
var aadhaarJsonPath = getFilePathFromAssets(name = "aadhaar_verifier_input.json")


Box(modifier = Modifier
.fillMaxSize()
Expand All @@ -77,11 +81,11 @@ fun MultiplierComponent() {
Thread(
Runnable {
val rapidsnarkInputs = prepareCircuitInputs(
rsaCircuitPath,
rsaJsonPath,
aadhaarCircuitPath,
aadhaarJsonPath,
)
val startTime = System.currentTimeMillis()
var wtnsRes = zkpTools.witnesscalcRSA(
var wtnsRes = zkpTools.witnesscalcAadhaarVerifier(
rapidsnarkInputs.circuitBuffer,
rapidsnarkInputs.circuitSize,
rapidsnarkInputs.jsonBuffer,
Expand All @@ -96,7 +100,7 @@ fun MultiplierComponent() {
println(rapidsnarkInputs.errorMsg.toString(Charsets.UTF_8))

var proofRes = zkpTools.groth16ProveWithZKeyFilePath(
rsaZkeyPath,
aadhaarZkeyPath,
rapidsnarkInputs.wtnsBuffer,
rapidsnarkInputs.wtnsSize[0],
rapidsnarkInputs.proofData,
Expand Down
9 changes: 9 additions & 0 deletions android/app/src/main/java/com/example/moproapp/ZKPTool.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ class ZKPTools(val context: Context) {
errorMsg: ByteArray,
errorMsgMaxSize: Long): Int

external fun witnesscalcAadhaarVerifier(circuitBuffer: ByteArray,
circuitSize: Long,
jsonBuffer: ByteArray,
jsonSize: Long,
wtnsBuffer: ByteArray,
wtnsSize: LongArray,
errorMsg: ByteArray,
errorMsgMaxSize: Long): Int

// external fun CalcPublicBufferSize(zkeyBuffer: ByteArray, zkeySize: Long): Long
external fun groth16ProveWithZKeyFilePath(
zkeyPath: String,
Expand Down