mirror of
https://github.com/selfxyz/self.git
synced 2026-04-27 03:01:15 -04:00
Adding witnesscalc + rapidsnark build flows for PoP circuit
- Copying the whole witnesscalc repo in `app` - Using git submodule for `nlohmann/json`, might switch later to script that clones the repo if it's simpler - Currently not supporting download of zkey, so it temporarily has to be built and copied first - Keeping artifacts of their AuthV2 circuit for reference
This commit is contained in:
27
app/App.tsx
27
app/App.tsx
@@ -69,33 +69,24 @@ function App(): JSX.Element {
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
init()
|
||||
// init()
|
||||
}, []);
|
||||
|
||||
async function init() {
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
console.log('launching init')
|
||||
// const res = await NativeModules.Prover.runInitAction()
|
||||
const res = await NativeModules.Prover.runInitAction()
|
||||
console.log('init done')
|
||||
// console.log('init res', res)
|
||||
console.log('init res', res)
|
||||
}
|
||||
|
||||
const handleStartCameraScan = async () => {
|
||||
// await NativeModules.Prover.runInitAction();
|
||||
|
||||
const startTime = Date.now();
|
||||
console.log('running mopro prove action');
|
||||
const response = await NativeModules.Prover.runProveAction({});
|
||||
console.log('proof response:', response);
|
||||
const endTime = Date.now();
|
||||
console.log('Total proof time from frontend:', endTime - startTime);
|
||||
|
||||
// startCameraScan({
|
||||
// setPassportNumber,
|
||||
// setDateOfBirth,
|
||||
// setDateOfExpiry,
|
||||
// setStep,
|
||||
// });
|
||||
startCameraScan({
|
||||
setPassportNumber,
|
||||
setDateOfBirth,
|
||||
setDateOfExpiry,
|
||||
setStep,
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -2,5 +2,5 @@
|
||||
// Use this file to import your target's public headers that you would like to expose to Swift.
|
||||
//
|
||||
|
||||
#include "witnesscalc_authV2.h"
|
||||
#include "witnesscalc_proof_of_passport.h"
|
||||
#include "groth16_prover.h"
|
||||
|
||||
@@ -8,19 +8,15 @@
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
00E356F31AD99517003FC87E /* ProofOfPassportTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 00E356F21AD99517003FC87E /* ProofOfPassportTests.m */; };
|
||||
056247BA2BB26D4400FFBD3B /* Contents.json in Resources */ = {isa = PBXBuildFile; fileRef = 056247B82BB26D4400FFBD3B /* Contents.json */; };
|
||||
056247BB2BB26D4400FFBD3B /* authV2.dat in Resources */ = {isa = PBXBuildFile; fileRef = 056247B92BB26D4400FFBD3B /* authV2.dat */; };
|
||||
0569F35B2BBC9015006670BD /* librapidsnark.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 0569F35A2BBC900D006670BD /* librapidsnark.a */; };
|
||||
0569F35D2BBC921F006670BD /* authV2.zkey in Resources */ = {isa = PBXBuildFile; fileRef = 0569F35C2BBC921F006670BD /* authV2.zkey */; };
|
||||
0569F35F2BBC98D5006670BD /* libfq.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 0569F35E2BBC98C9006670BD /* libfq.a */; };
|
||||
0569F3612BBCE4EF006670BD /* libwitnesscalc_proof_of_passport.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 0569F3602BBCE4EB006670BD /* libwitnesscalc_proof_of_passport.a */; };
|
||||
05BD9DCC2B548AA900823023 /* MoproKit in Resources */ = {isa = PBXBuildFile; fileRef = 05BD9DCB2B548AA900823023 /* MoproKit */; };
|
||||
05BD9DCE2B554FA300823023 /* libmopro_ffi.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 05BD9DCD2B554FA300823023 /* libmopro_ffi.a */; };
|
||||
05D985F52BB331AB00F58EEA /* libgmp.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 05D985F22BB331AB00F58EEA /* libgmp.a */; };
|
||||
05D985F62BB331AB00F58EEA /* libfr.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 05D985F32BB331AB00F58EEA /* libfr.a */; };
|
||||
05D985F72BB331AB00F58EEA /* libfq.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 05D985F42BB331AB00F58EEA /* libfq.a */; };
|
||||
05D985F92BB3335B00F58EEA /* authV2.dat in Resources */ = {isa = PBXBuildFile; fileRef = 05D985F82BB3335B00F58EEA /* authV2.dat */; };
|
||||
05D985FB2BB3344600F58EEA /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 05D985FA2BB3344600F58EEA /* Assets.xcassets */; };
|
||||
05E2174E2E7E48EB80B9C8D8 /* Luciole-Bold.ttf in Resources */ = {isa = PBXBuildFile; fileRef = ABB740B68A8141229E6118AC /* Luciole-Bold.ttf */; };
|
||||
05E439192BB32D5800E57227 /* libwitnesscalc_authV2.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 056247BD2BB328C800FFBD3B /* libwitnesscalc_authV2.a */; };
|
||||
05EDEDC62B52D25D00AA51AD /* Prover.m in Sources */ = {isa = PBXBuildFile; fileRef = 05EDEDC42B52D25D00AA51AD /* Prover.m */; };
|
||||
05EDEDC72B52D25D00AA51AD /* Prover.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05EDEDC52B52D25D00AA51AD /* Prover.swift */; };
|
||||
0651723A94C70A2B31E3E4F8 /* Pods_ProofOfPassport.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3DAAF621B99F62C9ED35AA07 /* Pods_ProofOfPassport.framework */; };
|
||||
@@ -76,19 +72,17 @@
|
||||
00E356EE1AD99517003FC87E /* ProofOfPassportTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ProofOfPassportTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
00E356F11AD99517003FC87E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
00E356F21AD99517003FC87E /* ProofOfPassportTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ProofOfPassportTests.m; sourceTree = "<group>"; };
|
||||
056247B82BB26D4400FFBD3B /* Contents.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = Contents.json; sourceTree = "<group>"; };
|
||||
056247B92BB26D4400FFBD3B /* authV2.dat */ = {isa = PBXFileReference; lastKnownFileType = file; path = authV2.dat; sourceTree = "<group>"; };
|
||||
056247BD2BB328C800FFBD3B /* libwitnesscalc_authV2.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libwitnesscalc_authV2.a; sourceTree = "<group>"; };
|
||||
0569F35A2BBC900D006670BD /* librapidsnark.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = librapidsnark.a; sourceTree = "<group>"; };
|
||||
0569F35C2BBC921F006670BD /* authV2.zkey */ = {isa = PBXFileReference; lastKnownFileType = file; name = authV2.zkey; path = ProofOfPassport/Assets.xcassets/authV2.zkey.dataset/authV2.zkey; sourceTree = "<group>"; };
|
||||
0569F35E2BBC98C9006670BD /* libfq.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libfq.a; sourceTree = "<group>"; };
|
||||
0569F3602BBCE4EB006670BD /* libwitnesscalc_proof_of_passport.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libwitnesscalc_proof_of_passport.a; sourceTree = "<group>"; };
|
||||
0569F3622BBCE52D006670BD /* proof_of_passport.zkey */ = {isa = PBXFileReference; lastKnownFileType = file; name = proof_of_passport.zkey; path = ProofOfPassport/Assets.xcassets/proof_of_passport.zkey.dataset/proof_of_passport.zkey; sourceTree = "<group>"; };
|
||||
0569F3642BBCE53D006670BD /* proof_of_passport.dat */ = {isa = PBXFileReference; lastKnownFileType = file; name = proof_of_passport.dat; path = ProofOfPassport/Assets.xcassets/proof_of_passport.dat.dataset/proof_of_passport.dat; sourceTree = "<group>"; };
|
||||
057DFC5E2B56DC0D003D24A3 /* libmopro_ffi.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libmopro_ffi.a; path = MoproKit/Libs/libmopro_ffi.a; sourceTree = "<group>"; };
|
||||
05A0773D2B5333CE0037E489 /* MoproKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = MoproKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
05BD9DCB2B548AA900823023 /* MoproKit */ = {isa = PBXFileReference; lastKnownFileType = folder; path = MoproKit; sourceTree = "<group>"; };
|
||||
05BD9DCD2B554FA300823023 /* libmopro_ffi.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libmopro_ffi.a; path = MoproKit/Libs/libmopro_ffi.a; sourceTree = "<group>"; };
|
||||
05D985F22BB331AB00F58EEA /* libgmp.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libgmp.a; sourceTree = "<group>"; };
|
||||
05D985F32BB331AB00F58EEA /* libfr.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libfr.a; sourceTree = "<group>"; };
|
||||
05D985F42BB331AB00F58EEA /* libfq.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libfq.a; sourceTree = "<group>"; };
|
||||
05D985F82BB3335B00F58EEA /* authV2.dat */ = {isa = PBXFileReference; lastKnownFileType = file; name = authV2.dat; path = ProofOfPassport/Assets.xcassets/authV2.dat.dataset/authV2.dat; sourceTree = "<group>"; };
|
||||
05D985FA2BB3344600F58EEA /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Assets.xcassets; path = ProofOfPassport/Assets.xcassets; sourceTree = "<group>"; };
|
||||
05EDEDC42B52D25D00AA51AD /* Prover.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Prover.m; sourceTree = "<group>"; };
|
||||
05EDEDC52B52D25D00AA51AD /* Prover.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Prover.swift; sourceTree = "<group>"; };
|
||||
@@ -155,10 +149,10 @@
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
05D985F72BB331AB00F58EEA /* libfq.a in Frameworks */,
|
||||
05E439192BB32D5800E57227 /* libwitnesscalc_authV2.a in Frameworks */,
|
||||
0651723A94C70A2B31E3E4F8 /* Pods_ProofOfPassport.framework in Frameworks */,
|
||||
0569F3612BBCE4EF006670BD /* libwitnesscalc_proof_of_passport.a in Frameworks */,
|
||||
05D985F52BB331AB00F58EEA /* libgmp.a in Frameworks */,
|
||||
0569F35F2BBC98D5006670BD /* libfq.a in Frameworks */,
|
||||
0569F35B2BBC9015006670BD /* librapidsnark.a in Frameworks */,
|
||||
05BD9DCE2B554FA300823023 /* libmopro_ffi.a in Frameworks */,
|
||||
05D985F62BB331AB00F58EEA /* libfr.a in Frameworks */,
|
||||
@@ -185,16 +179,6 @@
|
||||
name = "Supporting Files";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
056247B72BB26D4400FFBD3B /* authV2.dat.dataset */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
056247B82BB26D4400FFBD3B /* Contents.json */,
|
||||
056247B92BB26D4400FFBD3B /* authV2.dat */,
|
||||
);
|
||||
name = authV2.dat.dataset;
|
||||
path = ProofOfPassport/Assets.xcassets/authV2.dat.dataset;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
13B07FAE1A68108700A75B9A /* ProofOfPassport */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
@@ -202,13 +186,10 @@
|
||||
05EDEDC52B52D25D00AA51AD /* Prover.swift */,
|
||||
905B700A2A72A5E900AFA232 /* masterList.pem */,
|
||||
905B70082A729CD400AFA232 /* ProofOfPassport.entitlements */,
|
||||
05D985F42BB331AB00F58EEA /* libfq.a */,
|
||||
05D985F32BB331AB00F58EEA /* libfr.a */,
|
||||
05D985F82BB3335B00F58EEA /* authV2.dat */,
|
||||
05D985FA2BB3344600F58EEA /* Assets.xcassets */,
|
||||
05D985F22BB331AB00F58EEA /* libgmp.a */,
|
||||
057DFC5E2B56DC0D003D24A3 /* libmopro_ffi.a */,
|
||||
056247B72BB26D4400FFBD3B /* authV2.dat.dataset */,
|
||||
13B07FAF1A68108700A75B9A /* AppDelegate.h */,
|
||||
05BD9DCB2B548AA900823023 /* MoproKit */,
|
||||
13B07FB01A68108700A75B9A /* AppDelegate.mm */,
|
||||
@@ -219,7 +200,6 @@
|
||||
13B07FB71A68108700A75B9A /* main.m */,
|
||||
905B70042A72767900AFA232 /* PassportReader.swift */,
|
||||
905B70032A72767800AFA232 /* ProofOfPassport-Bridging-Header.h */,
|
||||
056247BD2BB328C800FFBD3B /* libwitnesscalc_authV2.a */,
|
||||
165E76C22B8DC8370000FA90 /* ScannerHostingController.swift */,
|
||||
905B70062A72774000AFA232 /* PassportReader.m */,
|
||||
165E76BC2B8DC4A00000FA90 /* MRZScannerModule.swift */,
|
||||
@@ -232,6 +212,8 @@
|
||||
2D16E6871FA4F8E400B85C8A /* Frameworks */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
0569F3602BBCE4EB006670BD /* libwitnesscalc_proof_of_passport.a */,
|
||||
0569F35E2BBC98C9006670BD /* libfq.a */,
|
||||
0569F35A2BBC900D006670BD /* librapidsnark.a */,
|
||||
05A0773D2B5333CE0037E489 /* MoproKit.framework */,
|
||||
ED297162215061F000B7C4FE /* JavaScriptCore.framework */,
|
||||
@@ -283,7 +265,8 @@
|
||||
83CBB9F61A601CBA00E9B192 = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
0569F35C2BBC921F006670BD /* authV2.zkey */,
|
||||
0569F3642BBCE53D006670BD /* proof_of_passport.dat */,
|
||||
0569F3622BBCE52D006670BD /* proof_of_passport.zkey */,
|
||||
13B07FAE1A68108700A75B9A /* ProofOfPassport */,
|
||||
832341AE1AAA6A7D00B99B32 /* Libraries */,
|
||||
00E356EF1AD99517003FC87E /* ProofOfPassportTests */,
|
||||
@@ -409,19 +392,15 @@
|
||||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
056247BB2BB26D4400FFBD3B /* authV2.dat in Resources */,
|
||||
905B700B2A72A5E900AFA232 /* masterList.pem in Resources */,
|
||||
05BD9DCC2B548AA900823023 /* MoproKit in Resources */,
|
||||
81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */,
|
||||
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */,
|
||||
2FA7C90AFAF5417DAA7BCB1E /* Inter-Black.otf in Resources */,
|
||||
056247BA2BB26D4400FFBD3B /* Contents.json in Resources */,
|
||||
C9B733B168F84BBA818C6CB8 /* Inter-BlackItalic.otf in Resources */,
|
||||
15AAF7651FCF40EB993543A3 /* Inter-BoldItalic.otf in Resources */,
|
||||
1D2A11340C7041909B820A90 /* Inter-ExtraBold.otf in Resources */,
|
||||
E4BC7CC193684992A11E3135 /* Inter-ExtraBoldItalic.otf in Resources */,
|
||||
0569F35D2BBC921F006670BD /* authV2.zkey in Resources */,
|
||||
05D985F92BB3335B00F58EEA /* authV2.dat in Resources */,
|
||||
1BA25F26C91C45F697D55099 /* Inter-ExtraLight.otf in Resources */,
|
||||
05D985FB2BB3344600F58EEA /* Assets.xcassets in Resources */,
|
||||
625D35EA2F1643E89F9887CE /* Inter-ExtraLightItalic.otf in Resources */,
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"data" : [
|
||||
{
|
||||
"filename" : "authV2.dat",
|
||||
"filename" : "proof_of_passport.dat",
|
||||
"idiom" : "universal",
|
||||
"universal-type-identifier" : "dyn.ah62d4rv4ge80k2py"
|
||||
}
|
||||
Binary file not shown.
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"data" : [
|
||||
{
|
||||
"filename" : "authV2.zkey",
|
||||
"filename" : "proof_of_passport.zkey",
|
||||
"idiom" : "universal",
|
||||
"universal-type-identifier" : "dyn.ah62d4rv4ge81y45fte"
|
||||
}
|
||||
@@ -10,8 +10,8 @@ import React
|
||||
import Security
|
||||
import MoproKit
|
||||
|
||||
#if canImport(witnesscalc_authV2)
|
||||
import witnesscalc_authV2
|
||||
#if canImport(witnesscalc_proof_of_passport)
|
||||
import witnesscalc_proof_of_passport
|
||||
#endif
|
||||
|
||||
#if canImport(groth16_prover)
|
||||
@@ -101,12 +101,8 @@ class Prover: NSObject {
|
||||
// inputs["pubkey"] = pubkey;
|
||||
// inputs["address"] = address;
|
||||
|
||||
// guard let inputs = inputs else {
|
||||
// throw "inputs is not valid"
|
||||
// }
|
||||
|
||||
let inputsDict = ["a": "2", "b": "4"]
|
||||
let inputsMul = try! JSONEncoder().encode(inputsDict)
|
||||
let inputsMul = try! JSONEncoder().encode(inputs)
|
||||
print("inputsMul size: \(inputsMul.count) bytes")
|
||||
print("inputsMul data: \(String(data: inputsMul, encoding: .utf8) ?? "")")
|
||||
|
||||
@@ -114,92 +110,35 @@ class Prover: NSObject {
|
||||
|
||||
let wtns = try! calcWtnsAuthV2(inputsJson: inputsMul)
|
||||
print("wtns size: \(wtns.count) bytes")
|
||||
print("wtns data (hex): \(wtns.map { String(format: "%02hhx", $0) }.joined())")
|
||||
// print("wtns data (hex): \(wtns.map { String(format: "%02hhx", $0) }.joined())")
|
||||
|
||||
let (proofRaw, pubSignalsRaw) = try groth16AuthV2(wtns: wtns)
|
||||
|
||||
let proof = try JSONDecoder().decode(Proof.self, from: proofRaw)
|
||||
|
||||
print("Proof: \(proof)")
|
||||
|
||||
let pubSignals = try JSONDecoder().decode([String].self, from: pubSignalsRaw)
|
||||
|
||||
print("PubSignals: \(pubSignals)")
|
||||
|
||||
let zkproof = Zkproof(proof: proof, pubSignals: pubSignals)
|
||||
let proofObject: [String: Any] = [
|
||||
"proof": [
|
||||
"a": proof.piA,
|
||||
"b": proof.piB,
|
||||
"c": proof.piC,
|
||||
],
|
||||
"inputs": pubSignals
|
||||
]
|
||||
|
||||
print("Zkproof: \(zkproof)")
|
||||
|
||||
// return try JSONEncoder().encode(zkproof)
|
||||
|
||||
// // Generate Proof
|
||||
// let generateProofResult = try generateProof2(circuitInputs: inputs)
|
||||
// assert(!generateProofResult.proof.isEmpty, "Proof should not be empty")
|
||||
|
||||
// // Record end time and compute duration
|
||||
// let end = CFAbsoluteTimeGetCurrent()
|
||||
// let timeTaken = end - start
|
||||
// print("Proof generation took \(timeTaken) seconds.")
|
||||
|
||||
// // Store the generated proof and public inputs for later verification
|
||||
// print("generateProofResult", generateProofResult)
|
||||
// generatedProof = generateProofResult.proof
|
||||
// publicInputs = generateProofResult.inputs
|
||||
|
||||
// // Convert Data to array of bytes
|
||||
// let proofBytes = [UInt8](generateProofResult.proof)
|
||||
// let inputsBytes = [UInt8](generateProofResult.inputs)
|
||||
|
||||
// print("proofBytes", proofBytes)
|
||||
// print("inputsBytes", inputsBytes)
|
||||
|
||||
// // Create a dictionary with byte arrays
|
||||
// let resultDict: [String: [UInt8]] = [
|
||||
// "proof": proofBytes,
|
||||
// "inputs": inputsBytes
|
||||
// ]
|
||||
|
||||
// // Serialize dictionary to JSON
|
||||
// let jsonData = try JSONSerialization.data(withJSONObject: resultDict, options: [])
|
||||
// let jsonString = String(data: jsonData, encoding: .utf8)!
|
||||
|
||||
// resolve(jsonString)
|
||||
} catch let error as MoproError {
|
||||
print("MoproError: \(error)")
|
||||
reject("PROVER", "An error occurred during proof generation", error)
|
||||
let proofData = try JSONSerialization.data(withJSONObject: proofObject, options: [])
|
||||
let proofObjectString = String(data: proofData, encoding: .utf8) ?? ""
|
||||
print("Proof Object: \(proofObjectString)")
|
||||
resolve(proofObjectString)
|
||||
} catch {
|
||||
print("Unexpected error: \(error)")
|
||||
reject("PROVER", "An error occurred during proof generation", error)
|
||||
}
|
||||
}
|
||||
|
||||
@objc(runVerifyAction:reject:)
|
||||
func runVerifyAction(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
||||
// Logic for verify
|
||||
guard let proof = generatedProof,
|
||||
let publicInputs = publicInputs else {
|
||||
print("Proof has not been generated yet.")
|
||||
return
|
||||
}
|
||||
do {
|
||||
// Verify Proof
|
||||
let isValid = try verifyProof2(proof: proof, publicInput: publicInputs)
|
||||
assert(isValid, "Proof verification should succeed")
|
||||
|
||||
print("Proof verification succeeded.")
|
||||
resolve(isValid)
|
||||
} catch let error as MoproError {
|
||||
print("MoproError: \(error)")
|
||||
reject("PROVER", "An error occurred during proof verification", error)
|
||||
} catch {
|
||||
print("Unexpected error: \(error)")
|
||||
reject("PROVER", "An error occurred during proof verification", error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public func calcWtnsAuthV2(inputsJson: Data) throws -> Data {
|
||||
let dat = NSDataAsset(name: "authV2.dat")!.data
|
||||
let dat = NSDataAsset(name: "proof_of_passport.dat")!.data
|
||||
return try _calcWtnsAuthV2(dat: dat, jsonData: inputsJson)
|
||||
}
|
||||
|
||||
@@ -220,7 +159,7 @@ private func _calcWtnsAuthV2(dat: Data, jsonData: Data) throws -> Data {
|
||||
let wtnsBuffer = UnsafeMutablePointer<UInt8>.allocate(capacity: (100 * 1024 * 1024))
|
||||
let errorBuffer = UnsafeMutablePointer<UInt8>.allocate(capacity: Int(errorSize))
|
||||
|
||||
let result = witnesscalc_authV2(
|
||||
let result = witnesscalc_proof_of_passport(
|
||||
(dat as NSData).bytes, datSize,
|
||||
(jsonData as NSData).bytes, jsonDataSize,
|
||||
wtnsBuffer, wtnsSize,
|
||||
@@ -242,7 +181,7 @@ private func _calcWtnsAuthV2(dat: Data, jsonData: Data) throws -> Data {
|
||||
|
||||
|
||||
public func groth16AuthV2(wtns: Data) throws -> (proof: Data, publicInputs: Data) {
|
||||
return try _groth16Prover(zkey: NSDataAsset(name: "authV2.zkey")!.data, wtns: wtns)
|
||||
return try _groth16Prover(zkey: NSDataAsset(name: "proof_of_passport.zkey")!.data, wtns: wtns)
|
||||
}
|
||||
|
||||
public func _groth16Prover(zkey: Data, wtns: Data) throws -> (proof: Data, publicInputs: Data) {
|
||||
|
||||
Binary file not shown.
BIN
app/ios/libwitnesscalc_proof_of_passport.a
Normal file
BIN
app/ios/libwitnesscalc_proof_of_passport.a
Normal file
Binary file not shown.
41
app/ios/witnesscalc_proof_of_passport.h
Normal file
41
app/ios/witnesscalc_proof_of_passport.h
Normal file
@@ -0,0 +1,41 @@
|
||||
#ifndef WITNESSCALC_PROOFOFPASSPORT_H
|
||||
#define WITNESSCALC_PROOFOFPASSPORT_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_proof_of_passport(
|
||||
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 // WITNESSCALC_PROOFOFPASSPORT_H
|
||||
|
||||
|
||||
#endif // WITNESSCALC_PROOFOFPASSPORT_H
|
||||
@@ -1,55 +1,44 @@
|
||||
#!/bin/bash
|
||||
|
||||
# This is adapted from mopro
|
||||
DEVELOPMENT_TEAM="<add-yours-here>"
|
||||
|
||||
ARCHITECTURE="aarch64-apple-ios" # or "x86_64-apple-ios" for "x86_64", "aarch64-apple-ios-sim" for simulator
|
||||
LIB_DIR="release" # or "debug"
|
||||
PROJECT_DIR=$(pwd)
|
||||
cp ../circuits/build/proof_of_passport_cpp/proof_of_passport.cpp witnesscalc/src
|
||||
cp ../circuits/build/proof_of_passport_cpp/proof_of_passport.dat witnesscalc/src
|
||||
|
||||
# Assert we're in the /app dir
|
||||
if [[ ! -d "mopro-ffi" || ! -d "mopro-core" || ! -d "ark-zkey" ]]; then
|
||||
echo -e "${RED}Error: This script must be run from the /app dir that contains mopro-ffi, mopro-core and ark-zkey folders.${DEFAULT}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check for target support
|
||||
check_target_support() {
|
||||
rustup target list | grep installed | grep -q "$1"
|
||||
}
|
||||
|
||||
# check target is installed
|
||||
if ! check_target_support $ARCHITECTURE; then
|
||||
rustup target add $ARCHITECTURE
|
||||
cd witnesscalc/src
|
||||
# This adds the namespace to the circuit file as described in the README
|
||||
last_include=$(grep -n '#include' proof_of_passport.cpp | tail -1 | cut -d: -f1)
|
||||
if [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
# macOS requires an empty string with the -i flag and handles backslashes differently
|
||||
sed -i "" "${last_include}a\\
|
||||
namespace CIRCUIT_NAME {" proof_of_passport.cpp
|
||||
else
|
||||
echo "Target $ARCHITECTURE already installed, skipping."
|
||||
# Linux
|
||||
sed -i "${last_include}a \\nnamespace CIRCUIT_NAME {" proof_of_passport.cpp
|
||||
fi
|
||||
echo "}" >> proof_of_passport.cpp
|
||||
|
||||
cd ../../..
|
||||
git submodule init
|
||||
git submodule update
|
||||
|
||||
cd mopro-core
|
||||
cargo build --release
|
||||
cd app/witnesscalc
|
||||
./build_gmp.sh ios
|
||||
make ios
|
||||
|
||||
cd ../mopro-ffi
|
||||
echo "Building mopro-ffi static library..."
|
||||
cargo build --release --target ${ARCHITECTURE}
|
||||
cp target/${ARCHITECTURE}/${LIB_DIR}/libmopro_ffi.a ../ios/MoproKit/Libs/
|
||||
echo "copied libmopro_ffi.a to ios/Moprokit/Libs/"
|
||||
|
||||
cd ../ios
|
||||
pod install
|
||||
./post_install.sh
|
||||
|
||||
# TODO: if functions signatures change, we have to rebuild the bindings by adapting theses lines:
|
||||
# cd ..
|
||||
# Install uniffi-bindgen binary in mopro-ffi
|
||||
# echo "[ffi] Installing uniffi-bindgen..."
|
||||
# if ! command -v uniffi-bindgen &> /dev/null
|
||||
# then
|
||||
# cargo install --bin uniffi-bindgen --path .
|
||||
# else
|
||||
# echo "uniffi-bindgen already installed, skipping."
|
||||
# fi
|
||||
# echo "Updating mopro-ffi bindings and library..."
|
||||
# uniffi-bindgen generate mopro-ffi/src/mopro.udl --language swift --out-dir ${TARGET_DIR}/SwiftBindings
|
||||
# cp ${TARGET_DIR}/SwiftBindings/moproFFI.h ${MOPROKIT_DIR}/Include/
|
||||
# cp ${TARGET_DIR}/SwiftBindings/mopro.swift ${MOPROKIT_DIR}/Bindings/
|
||||
# cp ${TARGET_DIR}/SwiftBindings/moproFFI.modulemap ${MOPROKIT_DIR}/Resources/
|
||||
cd build_witnesscalc_ios
|
||||
xcodebuild -project witnesscalc.xcodeproj \
|
||||
-scheme proof_of_passport \
|
||||
-sdk iphoneos \
|
||||
-configuration Release \
|
||||
DEVELOPMENT_TEAM="$DEVELOPMENT_TEAM" \
|
||||
ARCHS="arm64" \
|
||||
-destination 'generic/platform=iOS' \
|
||||
PRODUCT_BUNDLE_IDENTIFIER=com.warrom.witnesscalc \
|
||||
build
|
||||
cd ../..
|
||||
cp witnesscalc/build_witnesscalc_ios/src/Debug-iphoneos/libwitnesscalc_proof_of_passport.a ios
|
||||
mkdir -p ios/ProofOfPassport/Assets.xcassets/proof_of_passport.dat.dataset
|
||||
mkdir -p ios/ProofOfPassport/Assets.xcassets/proof_of_passport.zkey.dataset
|
||||
cp witnesscalc/src/proof_of_passport.dat ios/ProofOfPassport/Assets.xcassets/proof_of_passport.dat.dataset/proof_of_passport.dat
|
||||
cp ../circuits/build/proof_of_passport.zkey ios/ProofOfPassport/Assets.xcassets/proof_of_passport.zkey.dataset/proof_of_passport.zkey
|
||||
|
||||
@@ -83,34 +83,45 @@ const generateProof = async (
|
||||
console.log('launching generateProof function');
|
||||
console.log('inputs in App.tsx', inputs);
|
||||
|
||||
await NativeModules.Prover.runInitAction();
|
||||
// await NativeModules.Prover.runInitAction();
|
||||
|
||||
const startTime = Date.now();
|
||||
console.log('running mopro prove action');
|
||||
const startTime = Date.now();
|
||||
const response = await NativeModules.Prover.runProveAction(inputs);
|
||||
console.log('proof response:', response);
|
||||
|
||||
const parsedResponse = Platform.OS === 'android'
|
||||
? parseProofAndroid(response)
|
||||
: JSON.parse(response);
|
||||
console.log('parsedResponse', parsedResponse);
|
||||
|
||||
const endTime = Date.now();
|
||||
console.log('time spent:', endTime - startTime);
|
||||
console.log('proof response:', response);
|
||||
console.log('typeof proof response:', typeof response);
|
||||
setProofTime(endTime - startTime);
|
||||
|
||||
console.log('running mopro verify action');
|
||||
const res = await NativeModules.Prover.runVerifyAction();
|
||||
console.log('verify response:', res);
|
||||
if (Platform.OS === 'android') {
|
||||
const parsedResponse = parseProofAndroid(response);
|
||||
const finalProof = {
|
||||
proof: JSON.stringify(formatProof(parsedResponse.proof)),
|
||||
inputs: JSON.stringify(formatInputs(parsedResponse.inputs)),
|
||||
};
|
||||
console.log('finalProof:', finalProof);
|
||||
|
||||
const finalProof = {
|
||||
proof: JSON.stringify(formatProof(parsedResponse.proof)),
|
||||
inputs: JSON.stringify(formatInputs(parsedResponse.inputs)),
|
||||
};
|
||||
console.log('finalProof:', finalProof);
|
||||
setProof(finalProof);
|
||||
setGeneratingProof(false);
|
||||
setStep(Steps.PROOF_GENERATED);
|
||||
} else {
|
||||
const parsedResponse = JSON.parse(response);
|
||||
console.log('parsedResponse', parsedResponse);
|
||||
|
||||
console.log('parsedResponse.proof:', parsedResponse.proof);
|
||||
console.log('parsedResponse.inputs:', parsedResponse.inputs);
|
||||
|
||||
setProof(finalProof);
|
||||
setGeneratingProof(false);
|
||||
setStep(Steps.PROOF_GENERATED);
|
||||
const finalProof = {
|
||||
proof: JSON.stringify(parsedResponse.proof),
|
||||
inputs: JSON.stringify(parsedResponse.inputs),
|
||||
};
|
||||
console.log('finalProof:', finalProof);
|
||||
|
||||
setProof(finalProof);
|
||||
setGeneratingProof(false);
|
||||
setStep(Steps.PROOF_GENERATED);
|
||||
}
|
||||
} catch (err: any) {
|
||||
console.log('err', err);
|
||||
}
|
||||
|
||||
78
app/witnesscalc/.gitignore
vendored
Normal file
78
app/witnesscalc/.gitignore
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
# build/
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# Typescript v1 declaration files
|
||||
typings/
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variables file
|
||||
.env
|
||||
|
||||
# next.js build output
|
||||
.next
|
||||
|
||||
tmp
|
||||
temp
|
||||
|
||||
.DS_Store
|
||||
|
||||
# Workspace files are user-specific
|
||||
*.sublime-workspace
|
||||
CMakeLists.txt.user
|
||||
|
||||
depends/gmp*
|
||||
|
||||
build/*.o
|
||||
build_*
|
||||
package*
|
||||
|
||||
.idea/
|
||||
60
app/witnesscalc/CMakeLists.txt
Normal file
60
app/witnesscalc/CMakeLists.txt
Normal file
@@ -0,0 +1,60 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
include(cmake/platform.cmake)
|
||||
|
||||
set(USE_ASM ON CACHE BOOL "Use asm implementation for Fr and Fq")
|
||||
|
||||
project(witnesscalc LANGUAGES CXX ASM)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
message("USE_ASM=" ${USE_ASM})
|
||||
message("CMAKE_CROSSCOMPILING=" ${CMAKE_CROSSCOMPILING})
|
||||
|
||||
message("GMP_PREFIX=" ${GMP_PREFIX})
|
||||
message("GMP_INCLUDE_DIR=" ${GMP_INCLUDE_DIR})
|
||||
message("GMP_LIB_DIR=" ${GMP_LIB_DIR})
|
||||
|
||||
if (NOT EXISTS ${GMP_INCLUDE_FILE_FULLPATH})
|
||||
message("WARNING: ${GMP_INCLUDE_FILE_FULLPATH} is not found and so system ${GMP_INCLUDE_FILE} is used.")
|
||||
endif()
|
||||
|
||||
if (NOT EXISTS ${GMP_LIB_FILE_FULLPATH})
|
||||
message("WARNING: ${GMP_LIB_FILE_FULLPATH} is not found and so system ${GMP_LIB_FILE} is used.")
|
||||
set(GMP_LIB gmp)
|
||||
endif()
|
||||
|
||||
|
||||
include_directories(BEFORE ${GMP_INCLUDE_DIR})
|
||||
|
||||
add_subdirectory(src)
|
||||
|
||||
|
||||
install(TARGETS
|
||||
tests
|
||||
test_platform
|
||||
authV2
|
||||
proof_of_passport
|
||||
witnesscalc_proof_of_passport
|
||||
witnesscalc_proof_of_passportStatic
|
||||
witnesscalc_authV2
|
||||
witnesscalc_authV2Static
|
||||
fr
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
|
||||
BUNDLE DESTINATION ${CMAKE_INSTALL_PREFIX}/app
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
|
||||
|
||||
install(FILES "${GMP_LIB_DIR}/${GMP_LIB_FILE}"
|
||||
DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
|
||||
|
||||
install(FILES
|
||||
src/proof_of_passport.dat
|
||||
src/authV2.dat
|
||||
DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
|
||||
|
||||
install(FILES
|
||||
src/witnesscalc.h
|
||||
src/witnesscalc_proof_of_passport.h
|
||||
src/witnesscalc_authV2.h
|
||||
DESTINATION ${CMAKE_INSTALL_PREFIX}/include)
|
||||
675
app/witnesscalc/COPYING
Normal file
675
app/witnesscalc/COPYING
Normal file
@@ -0,0 +1,675 @@
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2021 0Kims Association <https://0kims.org>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
{one line to give the program's name and a brief idea of what it does.}
|
||||
Copyright (C) {year} {name of author}
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
{project} Copyright (C) {year} {fullname}
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
||||
33
app/witnesscalc/Makefile
Normal file
33
app/witnesscalc/Makefile
Normal file
@@ -0,0 +1,33 @@
|
||||
###
|
||||
|
||||
#Build targets
|
||||
host:
|
||||
rm -rf build_witnesscalc && mkdir build_witnesscalc && cd build_witnesscalc && \
|
||||
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package && \
|
||||
make -j4 -vvv && make install
|
||||
|
||||
arm64_host:
|
||||
rm -rf build_witnesscalc && mkdir build_witnesscalc && cd build_witnesscalc && \
|
||||
cmake .. -DTARGET_PLATFORM=arm64_host -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package && \
|
||||
make -j4 -vvv && make install
|
||||
|
||||
android:
|
||||
rm -rf build_witnesscalc_android && mkdir build_witnesscalc_android && cd build_witnesscalc_android && \
|
||||
cmake .. -DTARGET_PLATFORM=ANDROID -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package_android && \
|
||||
make -j4 -vvv && make install
|
||||
|
||||
android_x86_64:
|
||||
rm -rf build_witnesscalc_android_x86_64 && mkdir build_witnesscalc_android_x86_64 && cd build_witnesscalc_android_x86_64 && \
|
||||
cmake .. -DTARGET_PLATFORM=ANDROID_x86_64 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package_android_x86_64 && \
|
||||
make -j4 -vvv && make install
|
||||
|
||||
ios:
|
||||
rm -rf build_witnesscalc_ios && mkdir build_witnesscalc_ios && cd build_witnesscalc_ios && \
|
||||
cmake .. -GXcode -DTARGET_PLATFORM=IOS -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package_ios && \
|
||||
echo "" && echo "Now open Xcode and compile the generated project" && echo ""
|
||||
|
||||
ios_x86_64:
|
||||
rm -rf build_witnesscalc_ios_x86_64 && mkdir build_witnesscalc_ios_x86_64 && cd build_witnesscalc_ios_x86_64 && \
|
||||
cmake .. -GXcode -DTARGET_PLATFORM=IOS_x86_64 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package_ios_x86_64 && \
|
||||
echo "" && echo "Now open Xcode and compile the generated project" && echo ""
|
||||
|
||||
92
app/witnesscalc/README.md
Normal file
92
app/witnesscalc/README.md
Normal file
@@ -0,0 +1,92 @@
|
||||
## Dependencies
|
||||
|
||||
You should have installed gcc and cmake
|
||||
|
||||
In ubuntu:
|
||||
|
||||
```sh
|
||||
sudo apt install build-essential cmake m4
|
||||
```
|
||||
|
||||
## Compilation
|
||||
|
||||
### Preparation
|
||||
```sh
|
||||
git submodule init
|
||||
git submodule update
|
||||
```
|
||||
|
||||
### Compile witnesscalc for x86_64 host machine
|
||||
|
||||
```sh
|
||||
./build_gmp.sh host
|
||||
make host
|
||||
```
|
||||
|
||||
### Compile witnesscalc for arm64 host machine
|
||||
|
||||
```sh
|
||||
./build_gmp.sh host
|
||||
make arm64_host
|
||||
```
|
||||
|
||||
### Compile witnesscalc for Android
|
||||
|
||||
Install Android NDK from https://developer.android.com/ndk or with help of "SDK Manager" in Android Studio.
|
||||
|
||||
Set the value of ANDROID_NDK environment variable to the absolute path of Android NDK root directory.
|
||||
|
||||
Examples:
|
||||
|
||||
```sh
|
||||
export ANDROID_NDK=/home/test/Android/Sdk/ndk/23.1.7779620 # NDK is installed by "SDK Manager" in Android Studio.
|
||||
export ANDROID_NDK=/home/test/android-ndk-r23b # NDK is installed as a stand-alone package.
|
||||
```
|
||||
|
||||
Compilation for arm64:
|
||||
|
||||
```sh
|
||||
./build_gmp.sh android
|
||||
make android
|
||||
```
|
||||
|
||||
Compilation for x86_64:
|
||||
|
||||
```sh
|
||||
./build_gmp.sh android_x86_64
|
||||
make android_x86_64
|
||||
```
|
||||
|
||||
### Compile witnesscalc for iOS
|
||||
|
||||
Requirements: Xcode.
|
||||
|
||||
1. Run:
|
||||
````sh
|
||||
./build_gmp.sh ios
|
||||
make ios
|
||||
````
|
||||
2. Open generated Xcode project.
|
||||
3. Add compilation flag `-D_LONG_LONG_LIMB` to all build targets.
|
||||
4. Add compilation flag `-DCIRCUIT_NAME=auth`, `-DCIRCUIT_NAME=sig` and `-DCIRCUIT_NAME=mtp` to the respective targets.
|
||||
5. Compile witnesscalc.
|
||||
|
||||
## Updating circuits
|
||||
1. Compile a circuit with compile-circuit.sh script in circuits repo as usual.
|
||||
2. Replace existing <circuitname>.cpp and <circuitname>.dat files with generated ones (e.g. auth.cpp & auth.dat).
|
||||
3. Enclose all the code inside <circuitname>.cpp file with `namespace CIRCUIT_NAME` (do not replace `CIRCUIT_NAME` with the real name, it will be replaced at compilation), like this:
|
||||
```c++
|
||||
#include ...
|
||||
#include ...
|
||||
|
||||
namespace CIRCUIT_NAME {
|
||||
|
||||
// millions of code lines here
|
||||
|
||||
} // namespace
|
||||
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
witnesscalc is part of the iden3 project copyright 2022 0KIMS association and published with GPL-3 license. Please check the COPYING file for more details.
|
||||
82
app/witnesscalc/cmake/platform.cmake
Normal file
82
app/witnesscalc/cmake/platform.cmake
Normal file
@@ -0,0 +1,82 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
string(TOLOWER "${TARGET_PLATFORM}" TARGET_PLATFORM)
|
||||
|
||||
message("Building for " ${TARGET_PLATFORM})
|
||||
|
||||
set(GMP_ROOT depends/gmp)
|
||||
|
||||
if(TARGET_PLATFORM MATCHES "android")
|
||||
|
||||
if(NOT DEFINED ENV{ANDROID_NDK})
|
||||
message("ANDROID_NDK environment variable is not set.")
|
||||
message("It must be an absolute path to the root directory of Android NDK.")
|
||||
message(" For instance /home/test/Android/Sdk/ndk/23.1.7779620")
|
||||
message(FATAL_ERROR "Build failed.")
|
||||
else()
|
||||
message("Android NDK path is " $ENV{ANDROID_NDK})
|
||||
endif()
|
||||
|
||||
set(CMAKE_SYSTEM_NAME Android)
|
||||
set(CMAKE_SYSTEM_VERSION 23) # API level
|
||||
|
||||
if(TARGET_PLATFORM MATCHES "android_x86_64")
|
||||
set(CMAKE_ANDROID_ARCH_ABI x86_64)
|
||||
set(GMP_PREFIX ${GMP_ROOT}/package_android_x86_64)
|
||||
set(ARCH x86_64)
|
||||
else()
|
||||
set(CMAKE_ANDROID_ARCH_ABI arm64-v8a)
|
||||
set(GMP_PREFIX ${GMP_ROOT}/package_android_arm64)
|
||||
set(ARCH arm64)
|
||||
endif()
|
||||
|
||||
message("CMAKE_ANDROID_ARCH_ABI=" ${CMAKE_ANDROID_ARCH_ABI})
|
||||
|
||||
elseif(TARGET_PLATFORM MATCHES "ios")
|
||||
|
||||
set(CMAKE_SYSTEM_NAME iOS)
|
||||
|
||||
if(TARGET_PLATFORM MATCHES "ios_x86_64")
|
||||
set(CMAKE_OSX_ARCHITECTURES x86_64)
|
||||
set(GMP_PREFIX ${GMP_ROOT}/package_ios_x86_64)
|
||||
set(ARCH x86_64)
|
||||
else()
|
||||
set(CMAKE_OSX_ARCHITECTURES arm64)
|
||||
set(GMP_PREFIX ${GMP_ROOT}/package_ios_arm64)
|
||||
set(ARCH arm64)
|
||||
endif()
|
||||
|
||||
elseif(TARGET_PLATFORM MATCHES "aarch64")
|
||||
|
||||
set(GMP_PREFIX ${GMP_ROOT}/package_aarch64)
|
||||
set(ARCH arm64)
|
||||
|
||||
elseif(TARGET_PLATFORM MATCHES "arm64_host")
|
||||
|
||||
set(GMP_PREFIX ${GMP_ROOT}/package)
|
||||
set(ARCH arm64)
|
||||
|
||||
else()
|
||||
set(GMP_PREFIX ${GMP_ROOT}/package)
|
||||
set(ARCH x86_64)
|
||||
|
||||
endif()
|
||||
|
||||
if (CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin")
|
||||
set(GMP_DEFINIONS -D_LONG_LONG_LIMB)
|
||||
endif()
|
||||
|
||||
|
||||
set(GMP_INCLUDE_DIR ${GMP_PREFIX}/include)
|
||||
set(GMP_INCLUDE_FILE gmp.h)
|
||||
set(GMP_LIB_DIR ${GMP_PREFIX}/lib)
|
||||
set(GMP_LIB_FILE libgmp.a)
|
||||
|
||||
set(GMP_LIB_FILE_FULLPATH ${CMAKE_SOURCE_DIR}/${GMP_LIB_DIR}/${GMP_LIB_FILE})
|
||||
set(GMP_INCLUDE_FILE_FULLPATH ${CMAKE_SOURCE_DIR}/${GMP_INCLUDE_DIR}/${GMP_INCLUDE_FILE})
|
||||
|
||||
set(GMP_LIB ${GMP_LIB_FILE_FULLPATH})
|
||||
|
||||
message("CMAKE_HOST_SYSTEM_NAME=" ${CMAKE_HOST_SYSTEM_NAME})
|
||||
message("CMAKE_SYSTEM_NAME=" ${CMAKE_SYSTEM_NAME})
|
||||
message("ARCH=" ${ARCH})
|
||||
1
app/witnesscalc/depends/json
Submodule
1
app/witnesscalc/depends/json
Submodule
Submodule app/witnesscalc/depends/json added at 199dea11b1
102
app/witnesscalc/src/CMakeLists.txt
Normal file
102
app/witnesscalc/src/CMakeLists.txt
Normal file
@@ -0,0 +1,102 @@
|
||||
include_directories(
|
||||
../src
|
||||
../build
|
||||
../depends/json/single_include)
|
||||
|
||||
link_libraries(${GMP_LIB})
|
||||
|
||||
add_definitions(${GMP_DEFINIONS})
|
||||
|
||||
if(USE_ASM)
|
||||
if(ARCH MATCHES "arm64")
|
||||
add_definitions(-DUSE_ASM -DARCH_ARM64)
|
||||
elseif(ARCH MATCHES "x86_64")
|
||||
add_definitions(-DUSE_ASM -DARCH_X86_64)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(USE_ASM AND ARCH MATCHES "x86_64")
|
||||
|
||||
if (CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin")
|
||||
set(NASM_FLAGS -fmacho64 --prefix _)
|
||||
else()
|
||||
set(NASM_FLAGS -felf64 -DPIC)
|
||||
endif()
|
||||
|
||||
add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/build/fq_asm.o
|
||||
COMMAND nasm ${NASM_FLAGS} fq.asm -o fq_asm.o
|
||||
DEPENDS ${CMAKE_SOURCE_DIR}/build/fq.asm
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/build)
|
||||
|
||||
add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/build/fr_asm.o
|
||||
COMMAND nasm ${NASM_FLAGS} fr.asm -o fr_asm.o
|
||||
DEPENDS ${CMAKE_SOURCE_DIR}/build/fr.asm
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/build)
|
||||
endif()
|
||||
|
||||
set(FR_SOURCES
|
||||
../build/fr.hpp
|
||||
../build/fr.cpp
|
||||
)
|
||||
|
||||
if(USE_ASM)
|
||||
if(ARCH MATCHES "arm64")
|
||||
set(FR_SOURCES ${FR_SOURCES} ../build/fr_raw_arm64.s ../build/fr_raw_generic.cpp ../build/fr_generic.cpp)
|
||||
elseif(ARCH MATCHES "x86_64")
|
||||
set(FR_SOURCES ${FR_SOURCES} ../build/fr_asm.o)
|
||||
endif()
|
||||
else()
|
||||
set(FR_SOURCES ${FR_SOURCES} ../build/fr_generic.cpp ../build/fr_raw_generic.cpp)
|
||||
endif()
|
||||
|
||||
add_library(fr STATIC ${FR_SOURCES})
|
||||
set_target_properties(fr PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
link_libraries(fr)
|
||||
|
||||
|
||||
add_executable(tests tests.cpp)
|
||||
add_executable(test_platform test_platform.cpp)
|
||||
|
||||
|
||||
set(LIB_SOURCES
|
||||
calcwit.cpp
|
||||
witnesscalc.h
|
||||
witnesscalc.cpp
|
||||
)
|
||||
|
||||
# authV2
|
||||
set(AUTHV2_SOURCES ${LIB_SOURCES}
|
||||
authV2.cpp
|
||||
witnesscalc_authV2.h
|
||||
witnesscalc_authV2.cpp
|
||||
)
|
||||
|
||||
add_library(witnesscalc_authV2 SHARED ${AUTHV2_SOURCES})
|
||||
add_library(witnesscalc_authV2Static STATIC ${AUTHV2_SOURCES})
|
||||
set_target_properties(witnesscalc_authV2Static PROPERTIES OUTPUT_NAME witnesscalc_authV2)
|
||||
|
||||
add_executable(authV2 main.cpp)
|
||||
target_link_libraries(authV2 witnesscalc_authV2Static)
|
||||
|
||||
target_compile_definitions(witnesscalc_authV2 PUBLIC CIRCUIT_NAME=authV2)
|
||||
target_compile_definitions(witnesscalc_authV2Static PUBLIC CIRCUIT_NAME=authV2)
|
||||
target_compile_definitions(authV2 PUBLIC CIRCUIT_NAME=authV2)
|
||||
|
||||
# proof_of_passport
|
||||
set(PROOFOFPASSPORT_SOURCES ${LIB_SOURCES}
|
||||
proof_of_passport.cpp
|
||||
witnesscalc_proof_of_passport.h
|
||||
witnesscalc_proof_of_passport.cpp
|
||||
)
|
||||
|
||||
add_library(witnesscalc_proof_of_passport SHARED ${PROOFOFPASSPORT_SOURCES})
|
||||
add_library(witnesscalc_proof_of_passportStatic STATIC ${PROOFOFPASSPORT_SOURCES})
|
||||
set_target_properties(witnesscalc_proof_of_passportStatic PROPERTIES OUTPUT_NAME witnesscalc_proof_of_passport)
|
||||
|
||||
add_executable(proof_of_passport main.cpp)
|
||||
target_link_libraries(proof_of_passport witnesscalc_proof_of_passportStatic)
|
||||
|
||||
target_compile_definitions(witnesscalc_proof_of_passport PUBLIC CIRCUIT_NAME=proof_of_passport)
|
||||
target_compile_definitions(witnesscalc_proof_of_passportStatic PUBLIC CIRCUIT_NAME=proof_of_passport)
|
||||
target_compile_definitions(proof_of_passport PUBLIC CIRCUIT_NAME=proof_of_passport)
|
||||
947587
app/witnesscalc/src/authV2.cpp
Normal file
947587
app/witnesscalc/src/authV2.cpp
Normal file
File diff suppressed because it is too large
Load Diff
BIN
app/witnesscalc/src/authV2.dat
Normal file
BIN
app/witnesscalc/src/authV2.dat
Normal file
Binary file not shown.
148
app/witnesscalc/src/calcwit.cpp
Normal file
148
app/witnesscalc/src/calcwit.cpp
Normal file
@@ -0,0 +1,148 @@
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include "calcwit.hpp"
|
||||
|
||||
namespace CIRCUIT_NAME {
|
||||
|
||||
extern void run(Circom_CalcWit* ctx);
|
||||
|
||||
|
||||
void check(bool condition) {
|
||||
if (!condition) {
|
||||
std::cerr << "assert failed" << std::endl;
|
||||
throw std::runtime_error("assert failed");
|
||||
}
|
||||
}
|
||||
|
||||
void checkWithMsg(bool condition, const char* failMsg) {
|
||||
if (!condition) {
|
||||
std::stringstream stream;
|
||||
stream << "assert failed: "
|
||||
<< failMsg;
|
||||
std::cerr << stream.str() << std::endl;
|
||||
throw std::runtime_error(stream.str());
|
||||
}
|
||||
}
|
||||
|
||||
std::string int_to_hex( u64 i )
|
||||
{
|
||||
std::stringstream stream;
|
||||
stream << "0x"
|
||||
<< std::setfill ('0') << std::setw(16)
|
||||
<< std::hex << i;
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
u64 fnv1a(std::string s) {
|
||||
u64 hash = 0xCBF29CE484222325LL;
|
||||
for(char& c : s) {
|
||||
hash ^= u64(c);
|
||||
hash *= 0x100000001B3LL;
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
Circom_CalcWit::Circom_CalcWit (Circom_Circuit *aCircuit, uint maxTh) {
|
||||
circuit = aCircuit;
|
||||
inputSignalAssignedCounter = get_main_input_signal_no();
|
||||
inputSignalAssigned = new bool[inputSignalAssignedCounter];
|
||||
for (int i = 0; i< inputSignalAssignedCounter; i++) {
|
||||
inputSignalAssigned[i] = false;
|
||||
}
|
||||
signalValues = new FrElement[get_total_signal_no()];
|
||||
Fr_str2element(&signalValues[0], "1", 10);
|
||||
componentMemory = new Circom_Component[get_number_of_components()];
|
||||
circuitConstants = circuit ->circuitConstants;
|
||||
templateInsId2IOSignalInfo = circuit -> templateInsId2IOSignalInfo;
|
||||
|
||||
maxThread = maxTh;
|
||||
|
||||
// parallelism
|
||||
numThread = 0;
|
||||
|
||||
}
|
||||
|
||||
Circom_CalcWit::~Circom_CalcWit() {
|
||||
// ...
|
||||
}
|
||||
|
||||
uint Circom_CalcWit::getInputSignalHashPosition(u64 h) {
|
||||
uint n = get_size_of_input_hashmap();
|
||||
uint pos = (uint)(h % (u64)n);
|
||||
if (circuit->InputHashMap[pos].hash!=h){
|
||||
uint inipos = pos;
|
||||
pos++;
|
||||
while (pos != inipos) {
|
||||
if (circuit->InputHashMap[pos].hash==h) return pos;
|
||||
if (circuit->InputHashMap[pos].hash==0) {
|
||||
fprintf(stderr, "Signal not found\n");
|
||||
throw std::runtime_error("Signal not found");
|
||||
}
|
||||
pos = (pos+1)%n;
|
||||
}
|
||||
fprintf(stderr, "Signals not found\n");
|
||||
throw std::runtime_error("Signals not found");
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
|
||||
void Circom_CalcWit::tryRunCircuit(){
|
||||
if (inputSignalAssignedCounter == 0) {
|
||||
run(this);
|
||||
}
|
||||
}
|
||||
|
||||
void Circom_CalcWit::setInputSignal(u64 h, uint i, FrElement & val){
|
||||
if (inputSignalAssignedCounter == 0) {
|
||||
fprintf(stderr, "No more signals to be assigned\n");
|
||||
throw std::runtime_error("No more signals to be assigned");
|
||||
}
|
||||
uint pos = getInputSignalHashPosition(h);
|
||||
if (i >= circuit->InputHashMap[pos].signalsize) {
|
||||
fprintf(stderr, "Input signal array access exceeds the size\n");
|
||||
throw std::runtime_error("Input signal array access exceeds the size");
|
||||
}
|
||||
|
||||
uint si = circuit->InputHashMap[pos].signalid+i;
|
||||
if (inputSignalAssigned[si-get_main_input_signal_start()]) {
|
||||
fprintf(stderr, "Signal assigned twice: %d\n", si);
|
||||
const size_t errLn = 256;
|
||||
char err[errLn];
|
||||
snprintf(err, errLn, "Signal assigned twice: %d", si);
|
||||
throw std::runtime_error(err);
|
||||
}
|
||||
signalValues[si] = val;
|
||||
inputSignalAssigned[si-get_main_input_signal_start()] = true;
|
||||
inputSignalAssignedCounter--;
|
||||
tryRunCircuit();
|
||||
}
|
||||
|
||||
u64 Circom_CalcWit::getInputSignalSize(u64 h) {
|
||||
uint pos = getInputSignalHashPosition(h);
|
||||
return circuit->InputHashMap[pos].signalsize;
|
||||
}
|
||||
|
||||
std::string Circom_CalcWit::getTrace(u64 id_cmp){
|
||||
if (id_cmp == 0) return componentMemory[id_cmp].componentName;
|
||||
else{
|
||||
u64 id_father = componentMemory[id_cmp].idFather;
|
||||
std::string my_name = componentMemory[id_cmp].componentName;
|
||||
|
||||
return Circom_CalcWit::getTrace(id_father) + "." + my_name;
|
||||
}
|
||||
}
|
||||
|
||||
std::string Circom_CalcWit::generate_position_array(uint* dimensions, uint size_dimensions, uint index){
|
||||
std::string positions = "";
|
||||
|
||||
for (uint i = 0 ; i < size_dimensions; i++){
|
||||
uint last_pos = index % dimensions[size_dimensions -1 - i];
|
||||
index = index / dimensions[size_dimensions -1 - i];
|
||||
std::string new_pos = "[" + std::to_string(last_pos) + "]";
|
||||
positions = new_pos + positions;
|
||||
}
|
||||
return positions;
|
||||
}
|
||||
|
||||
} //namespace
|
||||
76
app/witnesscalc/src/calcwit.hpp
Normal file
76
app/witnesscalc/src/calcwit.hpp
Normal file
@@ -0,0 +1,76 @@
|
||||
#ifndef CIRCOM_CALCWIT_H
|
||||
#define CIRCOM_CALCWIT_H
|
||||
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include <functional>
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
|
||||
#include "circom.hpp"
|
||||
#include "fr.hpp"
|
||||
|
||||
#define NMUTEXES 12 //512
|
||||
|
||||
namespace CIRCUIT_NAME {
|
||||
|
||||
u64 fnv1a(std::string s);
|
||||
|
||||
void check(bool condition);
|
||||
void checkWithMsg(bool condition, const char* failMsg);
|
||||
|
||||
class Circom_CalcWit {
|
||||
|
||||
bool *inputSignalAssigned;
|
||||
uint inputSignalAssignedCounter;
|
||||
|
||||
Circom_Circuit *circuit;
|
||||
|
||||
public:
|
||||
|
||||
FrElement *signalValues;
|
||||
Circom_Component* componentMemory;
|
||||
FrElement* circuitConstants;
|
||||
std::map<u32,IODefPair> templateInsId2IOSignalInfo;
|
||||
std::string* listOfTemplateMessages;
|
||||
|
||||
// parallelism
|
||||
std::mutex numThreadMutex;
|
||||
std::condition_variable ntcvs;
|
||||
uint numThread;
|
||||
|
||||
uint maxThread;
|
||||
|
||||
// Functions called by the circuit
|
||||
Circom_CalcWit(Circom_Circuit *aCircuit, uint numTh = NMUTEXES);
|
||||
~Circom_CalcWit();
|
||||
|
||||
// Public functions
|
||||
void setInputSignal(u64 h, uint i, FrElement &val);
|
||||
void tryRunCircuit();
|
||||
|
||||
u64 getInputSignalSize(u64 h);
|
||||
|
||||
inline uint getRemaingInputsToBeSet() {
|
||||
return inputSignalAssignedCounter;
|
||||
}
|
||||
|
||||
inline void getWitness(uint idx, PFrElement val) {
|
||||
Fr_copy(val, &signalValues[circuit->witness2SignalList[idx]]);
|
||||
}
|
||||
|
||||
std::string getTrace(u64 id_cmp);
|
||||
|
||||
std::string generate_position_array(uint* dimensions, uint size_dimensions, uint index);
|
||||
|
||||
private:
|
||||
|
||||
uint getInputSignalHashPosition(u64 h);
|
||||
|
||||
};
|
||||
|
||||
typedef void (*Circom_TemplateFunction)(uint __cIdx, Circom_CalcWit* __ctx);
|
||||
|
||||
} //namespace
|
||||
|
||||
#endif // CIRCOM_CALCWIT_H
|
||||
93
app/witnesscalc/src/circom.hpp
Normal file
93
app/witnesscalc/src/circom.hpp
Normal file
@@ -0,0 +1,93 @@
|
||||
#ifndef __CIRCOM_H
|
||||
#define __CIRCOM_H
|
||||
|
||||
#include <map>
|
||||
#include <gmp.h>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include <thread>
|
||||
|
||||
#include "fr.hpp"
|
||||
|
||||
namespace CIRCUIT_NAME {
|
||||
|
||||
typedef unsigned long long u64;
|
||||
typedef uint32_t u32;
|
||||
typedef uint8_t u8;
|
||||
|
||||
//only for the main inputs
|
||||
struct __attribute__((__packed__)) HashSignalInfo {
|
||||
u64 hash;
|
||||
u64 signalid;
|
||||
u64 signalsize;
|
||||
};
|
||||
|
||||
struct IODef {
|
||||
u32 offset;
|
||||
u32 len;
|
||||
u32 *lengths;
|
||||
};
|
||||
|
||||
struct IODefPair {
|
||||
u32 len;
|
||||
IODef* defs;
|
||||
};
|
||||
|
||||
struct Circom_Circuit {
|
||||
// const char *P;
|
||||
HashSignalInfo* InputHashMap;
|
||||
u64* witness2SignalList;
|
||||
FrElement* circuitConstants;
|
||||
std::map<u32,IODefPair> templateInsId2IOSignalInfo;
|
||||
};
|
||||
|
||||
|
||||
struct Circom_Component {
|
||||
u32 templateId;
|
||||
u64 signalStart;
|
||||
u32 inputCounter;
|
||||
std::string templateName;
|
||||
std::string componentName;
|
||||
u64 idFather;
|
||||
u32* subcomponents;
|
||||
bool* subcomponentsParallel;
|
||||
bool *outputIsSet; //one for each output
|
||||
std::mutex *mutexes; //one for each output
|
||||
std::condition_variable *cvs;
|
||||
std::thread *sbct; //subcomponent threads
|
||||
|
||||
Circom_Component()
|
||||
: subcomponents(0), subcomponentsParallel(0), outputIsSet(0), mutexes(0), cvs(0), sbct(0)
|
||||
{}
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
For every template instantiation create two functions:
|
||||
- name_create
|
||||
- name_run
|
||||
|
||||
//PFrElement: pointer to FrElement
|
||||
|
||||
Every name_run or circom_function has:
|
||||
=====================================
|
||||
|
||||
//array of PFrElements for auxiliars in expression computation (known size);
|
||||
PFrElements expaux[];
|
||||
|
||||
//array of PFrElements for local vars (known size)
|
||||
PFrElements lvar[];
|
||||
|
||||
*/
|
||||
|
||||
uint get_main_input_signal_start();
|
||||
uint get_main_input_signal_no();
|
||||
uint get_total_signal_no();
|
||||
uint get_number_of_components();
|
||||
uint get_size_of_input_hashmap();
|
||||
uint get_size_of_witness();
|
||||
uint get_size_of_constants();
|
||||
uint get_size_of_io_map();
|
||||
|
||||
} //namespace
|
||||
#endif // __CIRCOM_H
|
||||
47
app/witnesscalc/src/filemaploader.hpp
Normal file
47
app/witnesscalc/src/filemaploader.hpp
Normal file
@@ -0,0 +1,47 @@
|
||||
#ifndef WITNESSCALC_INTERNAL_H
|
||||
#define WITNESSCALC_INTERNAL_H
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/mman.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
class FileMapLoader
|
||||
{
|
||||
public:
|
||||
explicit FileMapLoader(const std::string &datFileName)
|
||||
{
|
||||
int fd;
|
||||
struct stat sb;
|
||||
|
||||
fd = open(datFileName.c_str(), O_RDONLY);
|
||||
if (fd == -1) {
|
||||
std::cout << ".dat file not found: " << datFileName << "\n";
|
||||
throw std::system_error(errno, std::generic_category(), "open");
|
||||
}
|
||||
|
||||
if (fstat(fd, &sb) == -1) { /* To obtain file size */
|
||||
close(fd);
|
||||
throw std::system_error(errno, std::generic_category(), "fstat");
|
||||
}
|
||||
|
||||
size = sb.st_size;
|
||||
buffer = (char*)mmap(NULL, size, PROT_READ , MAP_PRIVATE, fd, 0);
|
||||
close(fd);
|
||||
}
|
||||
|
||||
~FileMapLoader()
|
||||
{
|
||||
munmap(buffer, size);
|
||||
}
|
||||
|
||||
FileMapLoader(const FileMapLoader&) = delete; // Delete the copy constructor
|
||||
FileMapLoader& operator=(const FileMapLoader&) = delete; // Delete the copy assignment operator
|
||||
|
||||
char *buffer;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
#endif //WITNESSCALC_INTERNAL_H
|
||||
76
app/witnesscalc/src/main.cpp
Normal file
76
app/witnesscalc/src/main.cpp
Normal file
@@ -0,0 +1,76 @@
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
#include "witnesscalc.h"
|
||||
#include "filemaploader.hpp"
|
||||
|
||||
#define handle_error(msg) \
|
||||
do { perror(msg); exit(EXIT_FAILURE); } while (0)
|
||||
|
||||
void writeBinWitness(char *witnessBuffer, unsigned long witnessSize, std::string wtnsFileName)
|
||||
{
|
||||
FILE *write_ptr;
|
||||
write_ptr = fopen(wtnsFileName.c_str(),"wb");
|
||||
|
||||
if (write_ptr == NULL) {
|
||||
std::string msg("Could not open ");
|
||||
msg += wtnsFileName + " for write";
|
||||
throw std::system_error(errno, std::generic_category(), msg);
|
||||
}
|
||||
|
||||
fwrite(witnessBuffer, witnessSize, 1, write_ptr);
|
||||
fclose(write_ptr);
|
||||
}
|
||||
|
||||
static const size_t WitnessBufferSize = 4*1024*1024;
|
||||
static char WitnessBuffer[WitnessBufferSize];
|
||||
|
||||
int main (int argc, char *argv[]) {
|
||||
|
||||
std::string cl(argv[0]);
|
||||
|
||||
if (argc!=3) {
|
||||
std::cout << "Usage: " << cl << " <input.json> <output.wtns>\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
try {
|
||||
std::string datfile = cl + ".dat";
|
||||
std::string jsonfile(argv[1]);
|
||||
std::string wtnsFileName(argv[2]);
|
||||
|
||||
size_t witnessSize = sizeof(WitnessBuffer);
|
||||
char errorMessage[256];
|
||||
|
||||
FileMapLoader jsonLoader(jsonfile);
|
||||
|
||||
int error = CIRCUIT_NAME::witnesscalc_from_dat_file(datfile.c_str(),
|
||||
jsonLoader.buffer, jsonLoader.size,
|
||||
WitnessBuffer, &witnessSize,
|
||||
errorMessage, sizeof(errorMessage));
|
||||
|
||||
if (error == WITNESSCALC_ERROR_SHORT_BUFFER) {
|
||||
|
||||
std::cerr << "Error: Short buffer for witness."
|
||||
<< " It should " << witnessSize << " bytes at least." << '\n';
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
else if (error) {
|
||||
|
||||
std::cerr << errorMessage << '\n';
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
writeBinWitness(WitnessBuffer, witnessSize, wtnsFileName);
|
||||
|
||||
} catch (std::exception* e) {
|
||||
std::cerr << e->what() << '\n';
|
||||
return EXIT_FAILURE;
|
||||
|
||||
} catch (std::exception& e) {
|
||||
std::cerr << e.what() << '\n';
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
972301
app/witnesscalc/src/proof_of_passport.cpp
Normal file
972301
app/witnesscalc/src/proof_of_passport.cpp
Normal file
File diff suppressed because it is too large
Load Diff
BIN
app/witnesscalc/src/proof_of_passport.dat
Normal file
BIN
app/witnesscalc/src/proof_of_passport.dat
Normal file
Binary file not shown.
21
app/witnesscalc/src/stub.cpp
Normal file
21
app/witnesscalc/src/stub.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#include "circom.hpp"
|
||||
#include "calcwit.hpp"
|
||||
|
||||
uint get_main_input_signal_start() {return 0;}
|
||||
|
||||
uint get_main_input_signal_no() {return 0;}
|
||||
|
||||
uint get_total_signal_no() {return 0;}
|
||||
|
||||
uint get_number_of_components() {return 0;}
|
||||
|
||||
uint get_size_of_input_hashmap() {return 0;}
|
||||
|
||||
uint get_size_of_witness() {return 0;}
|
||||
|
||||
uint get_size_of_constants() {return 0;}
|
||||
|
||||
uint get_size_of_io_map() {return 0;}
|
||||
|
||||
void run(Circom_CalcWit* ctx){
|
||||
}
|
||||
28
app/witnesscalc/src/test_platform.cpp
Normal file
28
app/witnesscalc/src/test_platform.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
#include <gmp.h>
|
||||
#include "fr.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cout << "sizeof int32_t : " << sizeof(int32_t) << std::endl;
|
||||
std::cout << "sizeof int64_t : " << sizeof(int64_t) << std::endl;
|
||||
|
||||
std::cout << "sizeof int : " << sizeof(int) << std::endl;
|
||||
std::cout << "sizeof unsigned int : " << sizeof(unsigned int) << std::endl;
|
||||
std::cout << "sizeof long : " << sizeof(long) << std::endl;
|
||||
std::cout << "sizeof unsigned long : " << sizeof(unsigned long) << std::endl;
|
||||
std::cout << "sizeof long long : " << sizeof(long long) << std::endl;
|
||||
std::cout << "sizeof unsigned long long : " << sizeof(unsigned long long) << std::endl;
|
||||
std::cout << "sizeof mp_limb_t : " << sizeof(mp_limb_t) << std::endl;
|
||||
std::cout << "sizeof mp_limb_signed_t : " << sizeof(mp_limb_signed_t) << std::endl;
|
||||
std::cout << "sizeof FrRawElement : " << sizeof(FrRawElement) << std::endl;
|
||||
std::cout << "sizeof FrElement : " << sizeof(FrElement) << std::endl;
|
||||
|
||||
int32_t x = -5;
|
||||
uint32_t y = 5;
|
||||
|
||||
std::cout << "-5 >> 1 : " << (x >> 1) << std::endl;
|
||||
std::cout << "5 >> 1 : " << (y >> 1) << std::endl;
|
||||
}
|
||||
5611
app/witnesscalc/src/tests.cpp
Normal file
5611
app/witnesscalc/src/tests.cpp
Normal file
File diff suppressed because it is too large
Load Diff
339
app/witnesscalc/src/witnesscalc.cpp
Normal file
339
app/witnesscalc/src/witnesscalc.cpp
Normal file
@@ -0,0 +1,339 @@
|
||||
#include "witnesscalc.h"
|
||||
#include "filemaploader.hpp"
|
||||
#include "calcwit.hpp"
|
||||
#include "circom.hpp"
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <sstream>
|
||||
#include <memory>
|
||||
|
||||
namespace CIRCUIT_NAME {
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
Circom_Circuit* loadCircuit(const void *buffer, unsigned long buffer_size) {
|
||||
if (buffer_size % sizeof(u32) != 0) {
|
||||
throw std::runtime_error("Invalid circuit file: wrong buffer_size");
|
||||
}
|
||||
|
||||
Circom_Circuit *circuit = new Circom_Circuit;
|
||||
|
||||
u8* bdata = (u8*)buffer;
|
||||
|
||||
circuit->InputHashMap = new HashSignalInfo[get_size_of_input_hashmap()];
|
||||
uint dsize = get_size_of_input_hashmap()*sizeof(HashSignalInfo);
|
||||
if (buffer_size < dsize) {
|
||||
throw std::runtime_error("Invalid circuit file: buffer_size <= dsize");
|
||||
}
|
||||
memcpy((void *)(circuit->InputHashMap), (void *)bdata, dsize);
|
||||
|
||||
circuit->witness2SignalList = new u64[get_size_of_witness()];
|
||||
uint inisize = dsize;
|
||||
dsize = get_size_of_witness()*sizeof(u64);
|
||||
if (buffer_size < dsize + inisize) {
|
||||
throw std::runtime_error("Invalid circuit file: buffer_size <= dsize + inisize");
|
||||
}
|
||||
memcpy((void *)(circuit->witness2SignalList), (void *)(bdata+inisize), dsize);
|
||||
|
||||
circuit->circuitConstants = new FrElement[get_size_of_constants()];
|
||||
if (get_size_of_constants()>0) {
|
||||
inisize += dsize;
|
||||
dsize = get_size_of_constants()*sizeof(FrElement);
|
||||
if (buffer_size < dsize + inisize) {
|
||||
throw std::runtime_error("Invalid circuit file: buffer_size <= dsize + inisize");
|
||||
}
|
||||
memcpy((void *)(circuit->circuitConstants), (void *)(bdata+inisize), dsize);
|
||||
}
|
||||
|
||||
std::map<u32,IODefPair> templateInsId2IOSignalInfo1;
|
||||
if (get_size_of_io_map()>0) {
|
||||
u32 index[get_size_of_io_map()];
|
||||
inisize += dsize;
|
||||
dsize = get_size_of_io_map()*sizeof(u32);
|
||||
if (buffer_size < dsize + inisize) {
|
||||
throw std::runtime_error("Invalid circuit file: buffer_size <= dsize + inisize");
|
||||
}
|
||||
memcpy((void *)index, (void *)(bdata+inisize), dsize);
|
||||
inisize += dsize;
|
||||
if (inisize % sizeof(u32) != 0) {
|
||||
throw std::runtime_error("Invalid circuit file: wrong inisize");
|
||||
}
|
||||
if (buffer_size <= inisize) {
|
||||
throw std::runtime_error("Invalid circuit file: buffer_size <= inisize");
|
||||
}
|
||||
u32 dataiomap[(buffer_size-inisize)/sizeof(u32)];
|
||||
memcpy((void *)dataiomap, (void *)(bdata+inisize), buffer_size-inisize);
|
||||
u32* pu32 = dataiomap;
|
||||
|
||||
for (int i = 0; i < get_size_of_io_map(); i++) {
|
||||
u32 n = *pu32;
|
||||
IODefPair p;
|
||||
p.len = n;
|
||||
IODef defs[n];
|
||||
pu32 += 1;
|
||||
for (u32 j = 0; j <n; j++){
|
||||
defs[j].offset=*pu32;
|
||||
u32 len = *(pu32+1);
|
||||
defs[j].len = len;
|
||||
defs[j].lengths = new u32[len];
|
||||
memcpy((void *)defs[j].lengths,(void *)(pu32+2),len*sizeof(u32));
|
||||
pu32 += len + 2;
|
||||
}
|
||||
p.defs = (IODef*)calloc(10, sizeof(IODef));
|
||||
for (u32 j = 0; j < p.len; j++){
|
||||
p.defs[j] = defs[j];
|
||||
}
|
||||
templateInsId2IOSignalInfo1[index[i]] = p;
|
||||
}
|
||||
}
|
||||
circuit->templateInsId2IOSignalInfo = std::move(templateInsId2IOSignalInfo1);
|
||||
|
||||
return circuit;
|
||||
}
|
||||
|
||||
bool check_valid_number(std::string & s, uint base){
|
||||
bool is_valid = true;
|
||||
if (base == 16){
|
||||
for (uint i = 0; i < s.size(); i++){
|
||||
is_valid &= (
|
||||
('0' <= s[i] && s[i] <= '9') ||
|
||||
('a' <= s[i] && s[i] <= 'f') ||
|
||||
('A' <= s[i] && s[i] <= 'F')
|
||||
);
|
||||
}
|
||||
} else{
|
||||
for (uint i = 0; i < s.size(); i++){
|
||||
is_valid &= ('0' <= s[i] && s[i] < char(int('0') + base));
|
||||
}
|
||||
}
|
||||
return is_valid;
|
||||
}
|
||||
|
||||
void json2FrElements (json val, std::vector<FrElement> & vval){
|
||||
if (!val.is_array()) {
|
||||
FrElement v;
|
||||
std::string s_aux, s;
|
||||
uint base;
|
||||
if (val.is_string()) {
|
||||
s_aux = val.get<std::string>();
|
||||
std::string possible_prefix = s_aux.substr(0, 2);
|
||||
if (possible_prefix == "0b" || possible_prefix == "0B"){
|
||||
s = s_aux.substr(2, s_aux.size() - 2);
|
||||
base = 2;
|
||||
} else if (possible_prefix == "0o" || possible_prefix == "0O"){
|
||||
s = s_aux.substr(2, s_aux.size() - 2);
|
||||
base = 8;
|
||||
} else if (possible_prefix == "0x" || possible_prefix == "0X"){
|
||||
s = s_aux.substr(2, s_aux.size() - 2);
|
||||
base = 16;
|
||||
} else{
|
||||
s = s_aux;
|
||||
base = 10;
|
||||
}
|
||||
if (!check_valid_number(s, base)){
|
||||
std::ostringstream errStrStream;
|
||||
errStrStream << "Invalid number in JSON input: " << s_aux << "\n";
|
||||
throw std::runtime_error(errStrStream.str() );
|
||||
}
|
||||
} else if (val.is_number()) {
|
||||
double vd = val.get<double>();
|
||||
std::stringstream stream;
|
||||
stream << std::fixed << std::setprecision(0) << vd;
|
||||
s = stream.str();
|
||||
base = 10;
|
||||
} else {
|
||||
throw std::runtime_error("Invalid JSON type");
|
||||
}
|
||||
Fr_str2element (&v, s.c_str(), base);
|
||||
vval.push_back(v);
|
||||
} else {
|
||||
for (uint i = 0; i < val.size(); i++) {
|
||||
json2FrElements (val[i], vval);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void loadJson(Circom_CalcWit *ctx, const char *json_buffer, unsigned long buffer_size) {
|
||||
|
||||
json j = json::parse(json_buffer, json_buffer + buffer_size);
|
||||
|
||||
u64 nItems = j.size();
|
||||
// printf("Items : %llu\n",nItems);
|
||||
if (nItems == 0){
|
||||
ctx->tryRunCircuit();
|
||||
}
|
||||
for (json::iterator it = j.begin(); it != j.end(); ++it) {
|
||||
// std::cout << it.key() << " => " << it.value() << '\n';
|
||||
u64 h = fnv1a(it.key());
|
||||
std::vector<FrElement> v;
|
||||
json2FrElements(it.value(),v);
|
||||
uint signalSize = ctx->getInputSignalSize(h);
|
||||
if (v.size() < signalSize) {
|
||||
std::ostringstream errStrStream;
|
||||
errStrStream << "Error loading signal " << it.key() << ": Not enough values\n";
|
||||
throw std::runtime_error(errStrStream.str() );
|
||||
}
|
||||
if (v.size() > signalSize) {
|
||||
std::ostringstream errStrStream;
|
||||
errStrStream << "Error loading signal " << it.key() << ": Too many values\n";
|
||||
throw std::runtime_error(errStrStream.str() );
|
||||
}
|
||||
for (uint i = 0; i<v.size(); i++){
|
||||
try {
|
||||
// std::cout << it.key() << "," << i << " => " << Fr_element2str(&(v[i])) << '\n';
|
||||
ctx->setInputSignal(h,i,v[i]);
|
||||
} catch (std::runtime_error e) {
|
||||
std::ostringstream errStrStream;
|
||||
errStrStream << "Error setting signal: " << it.key() << "\n" << e.what();
|
||||
throw std::runtime_error(errStrStream.str() );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsigned long getBinWitnessSize() {
|
||||
|
||||
uint Nwtns = get_size_of_witness();
|
||||
|
||||
return 44 + Fr_N64*8 * (Nwtns + 1);
|
||||
}
|
||||
|
||||
char *appendBuffer(char *buffer, const void *src, unsigned long src_size) {
|
||||
|
||||
memcpy(buffer, src, src_size);
|
||||
return buffer + src_size;
|
||||
}
|
||||
|
||||
char *appendBuffer(char *buffer, const u32 src) {
|
||||
|
||||
return appendBuffer(buffer, &src, 4);
|
||||
}
|
||||
|
||||
char *appendBuffer(char *buffer, const u64 src) {
|
||||
|
||||
return appendBuffer(buffer, &src, 8);
|
||||
}
|
||||
|
||||
char *appendBuffer(char *buffer, const FrRawElement src) {
|
||||
|
||||
return appendBuffer(buffer, src, Fr_N64*8);
|
||||
}
|
||||
|
||||
void storeBinWitness(Circom_CalcWit *ctx, char *buffer) {
|
||||
|
||||
buffer = appendBuffer(buffer, "wtns", 4);
|
||||
|
||||
u32 version = 2;
|
||||
buffer = appendBuffer(buffer, version);
|
||||
|
||||
u32 nSections = 2;
|
||||
buffer = appendBuffer(buffer, nSections);
|
||||
|
||||
// Header
|
||||
u32 idSection1 = 1;
|
||||
buffer = appendBuffer(buffer, idSection1);
|
||||
|
||||
u32 n8 = Fr_N64*8;
|
||||
|
||||
u64 idSection1length = 8 + n8;
|
||||
buffer = appendBuffer(buffer, idSection1length);
|
||||
|
||||
buffer = appendBuffer(buffer, n8);
|
||||
|
||||
buffer = appendBuffer(buffer, Fr_q.longVal);
|
||||
|
||||
uint Nwtns = get_size_of_witness();
|
||||
|
||||
u32 nVars = (u32)Nwtns;
|
||||
buffer = appendBuffer(buffer, nVars);
|
||||
|
||||
// Data
|
||||
u32 idSection2 = 2;
|
||||
buffer = appendBuffer(buffer, idSection2);
|
||||
|
||||
u64 idSection2length = (u64)n8*(u64)Nwtns;
|
||||
buffer = appendBuffer(buffer, idSection2length);
|
||||
|
||||
FrElement v;
|
||||
|
||||
for (int i=0;i<Nwtns;i++) {
|
||||
ctx->getWitness(i, &v);
|
||||
Fr_toLongNormal(&v, &v);
|
||||
buffer = appendBuffer(buffer, v.longVal);
|
||||
}
|
||||
}
|
||||
|
||||
int witnesscalc(
|
||||
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)
|
||||
{
|
||||
unsigned long witnessSize = getBinWitnessSize();
|
||||
|
||||
if (*wtns_size < witnessSize) {
|
||||
*wtns_size = witnessSize;
|
||||
return WITNESSCALC_ERROR_SHORT_BUFFER;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
std::unique_ptr<Circom_Circuit> circuit(loadCircuit(circuit_buffer, circuit_size));
|
||||
|
||||
std::unique_ptr<Circom_CalcWit> ctx(new Circom_CalcWit(circuit.get()));
|
||||
|
||||
loadJson(ctx.get(), json_buffer, json_size);
|
||||
|
||||
if (ctx->getRemaingInputsToBeSet() != 0) {
|
||||
std::stringstream stream;
|
||||
stream << "Not all inputs have been set. Only "
|
||||
<< get_main_input_signal_no()-ctx->getRemaingInputsToBeSet()
|
||||
<< " out of " << get_main_input_signal_no();
|
||||
|
||||
strncpy(error_msg, stream.str().c_str(), error_msg_maxsize);
|
||||
return WITNESSCALC_ERROR;
|
||||
}
|
||||
|
||||
storeBinWitness(ctx.get(), wtns_buffer);
|
||||
*wtns_size = witnessSize;
|
||||
|
||||
} catch (std::exception& e) {
|
||||
|
||||
if (error_msg) {
|
||||
strncpy(error_msg, e.what(), error_msg_maxsize);
|
||||
}
|
||||
return WITNESSCALC_ERROR;
|
||||
|
||||
} catch (std::exception *e) {
|
||||
|
||||
if (error_msg) {
|
||||
strncpy(error_msg, e->what(), error_msg_maxsize);
|
||||
}
|
||||
delete e;
|
||||
return WITNESSCALC_ERROR;
|
||||
|
||||
} catch (...) {
|
||||
if (error_msg) {
|
||||
strncpy(error_msg, "unknown error", error_msg_maxsize);
|
||||
}
|
||||
return WITNESSCALC_ERROR;
|
||||
}
|
||||
|
||||
return WITNESSCALC_OK;
|
||||
}
|
||||
|
||||
int witnesscalc_from_dat_file(
|
||||
const char *dat_fname,
|
||||
const char *json_buffer, unsigned long json_size,
|
||||
char *wtns_buffer, unsigned long *wtns_size,
|
||||
char *error_msg, unsigned long error_msg_maxsize)
|
||||
{
|
||||
|
||||
std::string s(dat_fname);
|
||||
FileMapLoader dat(dat_fname);
|
||||
return witnesscalc(dat.buffer, dat.size, json_buffer,
|
||||
json_size, wtns_buffer, wtns_size,
|
||||
error_msg, error_msg_maxsize);
|
||||
}
|
||||
|
||||
|
||||
} // namespace
|
||||
44
app/witnesscalc/src/witnesscalc.h
Normal file
44
app/witnesscalc/src/witnesscalc.h
Normal file
@@ -0,0 +1,44 @@
|
||||
#ifndef WITNESSCALC_H
|
||||
#define WITNESSCALC_H
|
||||
|
||||
namespace CIRCUIT_NAME {
|
||||
|
||||
#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(
|
||||
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);
|
||||
|
||||
/**
|
||||
* A wrapper function for `witnesscalc` that takes the circuit as a .dat file
|
||||
* name instead of a buffer.
|
||||
*/
|
||||
int
|
||||
witnesscalc_from_dat_file(
|
||||
const char *dat_fname,
|
||||
const char *json_buffer, unsigned long json_size,
|
||||
char *wtns_buffer, unsigned long *wtns_size,
|
||||
char *error_msg, unsigned long error_msg_maxsize);
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif // WITNESSCALC_H
|
||||
15
app/witnesscalc/src/witnesscalc_authV2.cpp
Normal file
15
app/witnesscalc/src/witnesscalc_authV2.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#include "witnesscalc_authV2.h"
|
||||
#include "witnesscalc.h"
|
||||
|
||||
int
|
||||
witnesscalc_authV2(
|
||||
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)
|
||||
{
|
||||
return CIRCUIT_NAME::witnesscalc(circuit_buffer, circuit_size,
|
||||
json_buffer, json_size,
|
||||
wtns_buffer, wtns_size,
|
||||
error_msg, error_msg_maxsize);
|
||||
}
|
||||
@@ -33,9 +33,7 @@ witnesscalc_authV2(
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
|
||||
#endif // WITNESSCALC_AUTHV2_H
|
||||
#endif
|
||||
|
||||
|
||||
#endif // WITNESSCALC_AUTHV2_H
|
||||
15
app/witnesscalc/src/witnesscalc_proof_of_passport.cpp
Normal file
15
app/witnesscalc/src/witnesscalc_proof_of_passport.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#include "witnesscalc_proof_of_passport.h"
|
||||
#include "witnesscalc.h"
|
||||
|
||||
int
|
||||
witnesscalc_proof_of_passport(
|
||||
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)
|
||||
{
|
||||
return CIRCUIT_NAME::witnesscalc(circuit_buffer, circuit_size,
|
||||
json_buffer, json_size,
|
||||
wtns_buffer, wtns_size,
|
||||
error_msg, error_msg_maxsize);
|
||||
}
|
||||
39
app/witnesscalc/src/witnesscalc_proof_of_passport.h
Normal file
39
app/witnesscalc/src/witnesscalc_proof_of_passport.h
Normal file
@@ -0,0 +1,39 @@
|
||||
#ifndef WITNESSCALC_PROOFOFPASSPORT_H
|
||||
#define WITNESSCALC_PROOFOFPASSPORT_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_proof_of_passport(
|
||||
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_PROOFOFPASSPORT_H
|
||||
179
app/witnesscalc/testdata/authV2_input.json
vendored
Normal file
179
app/witnesscalc/testdata/authV2_input.json
vendored
Normal file
@@ -0,0 +1,179 @@
|
||||
{
|
||||
"genesisID": "23148936466334350744548790012294489365207440754509988986684797708370051073",
|
||||
"profileNonce": "10",
|
||||
"authClaim": [
|
||||
"80551937543569765027552589160822318028",
|
||||
"0",
|
||||
"4720763745722683616702324599137259461509439547324750011830105416383780791263",
|
||||
"4844030361230692908091131578688419341633213823133966379083981236400104720538",
|
||||
"16547485850637761685",
|
||||
"0",
|
||||
"0",
|
||||
"0"
|
||||
],
|
||||
"authClaimIncMtp": [
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0"
|
||||
],
|
||||
"authClaimNonRevMtp": [
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0"
|
||||
],
|
||||
"authClaimNonRevMtpAuxHi": "0",
|
||||
"authClaimNonRevMtpAuxHv": "0",
|
||||
"authClaimNonRevMtpNoAux": "1",
|
||||
"challenge": "12345",
|
||||
"challengeSignatureR8x": "15829360093371098546177008474519342171461782120259125067189481965541223738777",
|
||||
"challengeSignatureR8y": "10840522802382821290541462398953040493080116495308402635486440290351677745960",
|
||||
"challengeSignatureS": "1196477404779941775725836688033485533497812196897664950083199167075327114562",
|
||||
"claimsTreeRoot": "8162166103065016664685834856644195001371303013149727027131225893397958846382",
|
||||
"revTreeRoot": "0",
|
||||
"rootsTreeRoot": "0",
|
||||
"state": "8039964009611210398788855768060749920589777058607598891238307089541758339342",
|
||||
"gistRoot": "1243904711429961858774220647610724273798918457991486031567244100767259239747",
|
||||
"gistMtp": [
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0",
|
||||
"0"
|
||||
],
|
||||
"gistMtpAuxHi": "1",
|
||||
"gistMtpAuxHv": "1",
|
||||
"gistMtpNoAux": "0"
|
||||
}
|
||||
Reference in New Issue
Block a user