@solarity/zkit 0.2.6 → 0.3.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/CircuitZKit.d.ts +22 -21
- package/dist/core/CircuitZKit.d.ts.map +1 -1
- package/dist/core/CircuitZKit.js +28 -43
- package/dist/core/CircuitZKit.js.map +1 -1
- package/dist/core/protocols/AbstractImplementer.d.ts +15 -0
- package/dist/core/protocols/AbstractImplementer.d.ts.map +1 -0
- package/dist/core/protocols/AbstractImplementer.js +36 -0
- package/dist/core/protocols/AbstractImplementer.js.map +1 -0
- package/dist/core/protocols/Groth16Implementer.d.ts +10 -0
- package/dist/core/protocols/Groth16Implementer.d.ts.map +1 -0
- package/dist/core/protocols/Groth16Implementer.js +50 -0
- package/dist/core/protocols/Groth16Implementer.js.map +1 -0
- package/dist/core/protocols/PlonkImplementer.d.ts +10 -0
- package/dist/core/protocols/PlonkImplementer.d.ts.map +1 -0
- package/dist/core/protocols/PlonkImplementer.js +51 -0
- package/dist/core/protocols/PlonkImplementer.js.map +1 -0
- package/dist/core/protocols/index.d.ts +4 -0
- package/dist/core/protocols/index.d.ts.map +1 -0
- package/dist/core/protocols/index.js +10 -0
- package/dist/core/protocols/index.js.map +1 -0
- package/dist/core/templates/verifier_groth16.vy.ejs +3 -3
- package/dist/core/templates/verifier_plonk.sol.ejs +779 -0
- package/dist/core/templates/verifier_plonk.vy.ejs +650 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/types/circuit-zkit.d.ts +0 -34
- package/dist/types/circuit-zkit.d.ts.map +1 -1
- package/dist/types/proof-utils.d.ts +7 -0
- package/dist/types/proof-utils.d.ts.map +1 -0
- package/dist/types/proof-utils.js +3 -0
- package/dist/types/proof-utils.js.map +1 -0
- package/dist/types/protocols/groth16.d.ts +28 -0
- package/dist/types/protocols/groth16.d.ts.map +1 -0
- package/dist/types/protocols/groth16.js +3 -0
- package/dist/types/protocols/groth16.js.map +1 -0
- package/dist/types/protocols/index.d.ts +31 -0
- package/dist/types/protocols/index.d.ts.map +1 -0
- package/dist/types/protocols/index.js +19 -0
- package/dist/types/protocols/index.js.map +1 -0
- package/dist/types/protocols/plonk.d.ts +26 -0
- package/dist/types/protocols/plonk.d.ts.map +1 -0
- package/dist/types/{types.js → protocols/plonk.js} +1 -1
- package/dist/types/protocols/plonk.js.map +1 -0
- package/package.json +1 -1
- package/src/core/CircuitZKit.ts +40 -63
- package/src/core/protocols/AbstractImplementer.ts +67 -0
- package/src/core/protocols/Groth16Implementer.ts +29 -0
- package/src/core/protocols/PlonkImplementer.ts +32 -0
- package/src/core/protocols/index.ts +3 -0
- package/src/core/templates/verifier_groth16.vy.ejs +3 -3
- package/src/core/templates/verifier_plonk.sol.ejs +779 -0
- package/src/core/templates/verifier_plonk.vy.ejs +650 -0
- package/src/index.ts +5 -1
- package/src/types/circuit-zkit.ts +0 -31
- package/src/types/proof-utils.ts +9 -0
- package/src/types/protocols/groth16.ts +21 -0
- package/src/types/protocols/index.ts +49 -0
- package/src/types/protocols/plonk.ts +28 -0
- package/dist/config/config.d.ts +0 -27
- package/dist/config/config.d.ts.map +0 -1
- package/dist/config/config.js +0 -19
- package/dist/config/config.js.map +0 -1
- package/dist/core/CircomZKit.d.ts +0 -39
- package/dist/core/CircomZKit.d.ts.map +0 -1
- package/dist/core/CircomZKit.js +0 -94
- package/dist/core/CircomZKit.js.map +0 -1
- package/dist/core/ManagerZKit.d.ts +0 -97
- package/dist/core/ManagerZKit.d.ts.map +0 -1
- package/dist/core/ManagerZKit.js +0 -222
- package/dist/core/ManagerZKit.js.map +0 -1
- package/dist/types/types.d.ts +0 -46
- package/dist/types/types.d.ts.map +0 -1
- package/dist/types/types.js.map +0 -1
- package/dist/utils/utils.d.ts +0 -18
- package/dist/utils/utils.d.ts.map +0 -1
- package/dist/utils/utils.js +0 -58
- package/dist/utils/utils.js.map +0 -1
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
import { ArtifactsFileType,
|
|
1
|
+
import { ArtifactsFileType, CircuitZKitConfig, VerifierLanguageType } from "../types/circuit-zkit";
|
|
2
|
+
import { Signals } from "../types/proof-utils";
|
|
3
|
+
import { CalldataByProtocol, IProtocolImplementer, ProofStructByProtocol, ProvingSystemType } from "../types/protocols";
|
|
2
4
|
/**
|
|
3
5
|
* `CircuitZKit` represents a single circuit and provides a high-level API to work with it.
|
|
4
6
|
*/
|
|
5
|
-
export declare class CircuitZKit {
|
|
7
|
+
export declare class CircuitZKit<Type extends ProvingSystemType> {
|
|
6
8
|
private readonly _config;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
* Returns the verifier template for the specified proving system and contract language.
|
|
10
|
-
*
|
|
11
|
-
* @param {VerifierProvingSystem} provingSystem - The template proving system.
|
|
12
|
-
* @param {VerifierLanguageType} fileExtension - The file extension.
|
|
13
|
-
* @returns {string} The verifier template.
|
|
14
|
-
*/
|
|
15
|
-
static getTemplate(provingSystem: VerifierProvingSystem, fileExtension: VerifierLanguageType): string;
|
|
9
|
+
private readonly _implementer;
|
|
10
|
+
constructor(_config: CircuitZKitConfig, _implementer: IProtocolImplementer<Type>);
|
|
16
11
|
/**
|
|
17
12
|
* Creates a verifier contract for the specified contract language.
|
|
18
13
|
*/
|
|
@@ -30,28 +25,28 @@ export declare class CircuitZKit {
|
|
|
30
25
|
* @dev The `inputs` should be in the same order as the circuit expects them.
|
|
31
26
|
*
|
|
32
27
|
* @param {Signals} inputs - The inputs for the circuit.
|
|
33
|
-
* @returns {Promise<
|
|
28
|
+
* @returns {Promise<ProofStructByProtocol<Type>>} The generated proof.
|
|
34
29
|
* @todo Add support for other proving systems.
|
|
35
30
|
*/
|
|
36
|
-
generateProof(inputs: Signals): Promise<
|
|
31
|
+
generateProof(inputs: Signals): Promise<ProofStructByProtocol<Type>>;
|
|
37
32
|
/**
|
|
38
33
|
* Verifies the given proof.
|
|
39
34
|
*
|
|
40
35
|
* @dev The `proof` can be generated using the `generateProof` method.
|
|
41
36
|
* @dev The `proof.publicSignals` should be in the same order as the circuit expects them.
|
|
42
37
|
*
|
|
43
|
-
* @param {
|
|
38
|
+
* @param {ProofStructByProtocol<Type>} proof - The proof to verify.
|
|
44
39
|
* @returns {Promise<boolean>} Whether the proof is valid.
|
|
45
40
|
*/
|
|
46
|
-
verifyProof(proof:
|
|
41
|
+
verifyProof(proof: ProofStructByProtocol<Type>): Promise<boolean>;
|
|
47
42
|
/**
|
|
48
43
|
* Generates the calldata for the given proof. The calldata can be used to verify the proof on-chain.
|
|
49
44
|
*
|
|
50
|
-
* @param {
|
|
51
|
-
* @returns {Promise<
|
|
45
|
+
* @param {ProofStructByProtocol<Type>} proof - The proof to generate calldata for.
|
|
46
|
+
* @returns {Promise<CalldataByProtocol<Type>>} - The generated calldata.
|
|
52
47
|
* @todo Add other types of calldata.
|
|
53
48
|
*/
|
|
54
|
-
generateCalldata(proof:
|
|
49
|
+
generateCalldata(proof: ProofStructByProtocol<Type>): Promise<CalldataByProtocol<Type>>;
|
|
55
50
|
/**
|
|
56
51
|
* Returns the circuit name. The circuit name is the name of the circuit file without the extension.
|
|
57
52
|
*
|
|
@@ -65,11 +60,17 @@ export declare class CircuitZKit {
|
|
|
65
60
|
*/
|
|
66
61
|
getVerifierName(): string;
|
|
67
62
|
/**
|
|
68
|
-
* Returns the
|
|
63
|
+
* Returns the type of the proving protocol
|
|
64
|
+
*
|
|
65
|
+
* @returns {ProvingSystemType} The protocol proving system type.
|
|
66
|
+
*/
|
|
67
|
+
getProvingSystemType(): ProvingSystemType;
|
|
68
|
+
/**
|
|
69
|
+
* Returns the Solidity verifier template.
|
|
69
70
|
*
|
|
70
|
-
* @returns {
|
|
71
|
+
* @returns {string} The Solidity verifier template.
|
|
71
72
|
*/
|
|
72
|
-
|
|
73
|
+
getVerifierTemplate(languageExtension: VerifierLanguageType): string;
|
|
73
74
|
/**
|
|
74
75
|
* Returns the path to the file of the given type inside artifacts directory. Throws an error if the file doesn't exist.
|
|
75
76
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CircuitZKit.d.ts","sourceRoot":"","sources":["../../src/core/CircuitZKit.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"CircuitZKit.d.ts","sourceRoot":"","sources":["../../src/core/CircuitZKit.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AACnG,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAExH;;GAEG;AACH,qBAAa,WAAW,CAAC,IAAI,SAAS,iBAAiB;IAEnD,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,YAAY;gBADZ,OAAO,EAAE,iBAAiB,EAC1B,YAAY,EAAE,oBAAoB,CAAC,IAAI,CAAC;IAG3D;;OAEG;IACU,cAAc,CAAC,iBAAiB,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;IAUnF;;;;;OAKG;IACU,gBAAgB,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAejE;;;;;;;;OAQG;IACU,aAAa,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAC;IAOjF;;;;;;;;OAQG;IACU,WAAW,CAAC,KAAK,EAAE,qBAAqB,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;IAM9E;;;;;;OAMG;IACU,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;IAIpG;;;;OAIG;IACI,cAAc,IAAI,MAAM;IAI/B;;;;OAIG;IACI,eAAe,IAAI,MAAM;IAIhC;;;;OAIG;IACI,oBAAoB,IAAI,iBAAiB;IAIhD;;;;OAIG;IACI,mBAAmB,CAAC,iBAAiB,EAAE,oBAAoB,GAAG,MAAM;IAI3E;;;;;OAKG;IACI,wBAAwB,CAAC,QAAQ,EAAE,iBAAiB,GAAG,MAAM;IAUpE;;;;;OAKG;IACI,oBAAoB,CAAC,QAAQ,EAAE,iBAAiB,GAAG,MAAM;CAgCjE"}
|
package/dist/core/CircuitZKit.js
CHANGED
|
@@ -27,48 +27,27 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.CircuitZKit = void 0;
|
|
30
|
-
const ejs_1 = __importDefault(require("ejs"));
|
|
31
30
|
const fs_1 = __importDefault(require("fs"));
|
|
32
|
-
const os = __importStar(require("os"));
|
|
33
31
|
const path_1 = __importDefault(require("path"));
|
|
32
|
+
const os = __importStar(require("os"));
|
|
34
33
|
const snarkjs = __importStar(require("snarkjs"));
|
|
35
34
|
/**
|
|
36
35
|
* `CircuitZKit` represents a single circuit and provides a high-level API to work with it.
|
|
37
36
|
*/
|
|
38
37
|
class CircuitZKit {
|
|
39
38
|
_config;
|
|
40
|
-
|
|
39
|
+
_implementer;
|
|
40
|
+
constructor(_config, _implementer) {
|
|
41
41
|
this._config = _config;
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Returns the verifier template for the specified proving system and contract language.
|
|
45
|
-
*
|
|
46
|
-
* @param {VerifierProvingSystem} provingSystem - The template proving system.
|
|
47
|
-
* @param {VerifierLanguageType} fileExtension - The file extension.
|
|
48
|
-
* @returns {string} The verifier template.
|
|
49
|
-
*/
|
|
50
|
-
static getTemplate(provingSystem, fileExtension) {
|
|
51
|
-
switch (provingSystem) {
|
|
52
|
-
case "groth16":
|
|
53
|
-
return fs_1.default.readFileSync(path_1.default.join(__dirname, "templates", `verifier_groth16.${fileExtension}.ejs`), "utf8");
|
|
54
|
-
default:
|
|
55
|
-
throw new Error(`Ambiguous proving system: ${provingSystem}.`);
|
|
56
|
-
}
|
|
42
|
+
this._implementer = _implementer;
|
|
57
43
|
}
|
|
58
44
|
/**
|
|
59
45
|
* Creates a verifier contract for the specified contract language.
|
|
60
46
|
*/
|
|
61
47
|
async createVerifier(languageExtension) {
|
|
62
48
|
const vKeyFilePath = this.mustGetArtifactsFilePath("vkey");
|
|
63
|
-
const verifierFilePath = path_1.default.join(this._config.verifierDirPath, `${this.getVerifierName()}.${languageExtension}`);
|
|
64
|
-
|
|
65
|
-
if (!fs_1.default.existsSync(this._config.verifierDirPath)) {
|
|
66
|
-
fs_1.default.mkdirSync(this._config.verifierDirPath, { recursive: true });
|
|
67
|
-
}
|
|
68
|
-
const templateParams = JSON.parse(fs_1.default.readFileSync(vKeyFilePath, "utf-8"));
|
|
69
|
-
templateParams["verifier_id"] = this.getVerifierName();
|
|
70
|
-
const verifierCode = ejs_1.default.render(verifierTemplate, templateParams);
|
|
71
|
-
fs_1.default.writeFileSync(verifierFilePath, verifierCode, "utf-8");
|
|
49
|
+
const verifierFilePath = path_1.default.join(this._config.verifierDirPath, `${this._implementer.getVerifierName(this._config.circuitName)}.${languageExtension}`);
|
|
50
|
+
this._implementer.createVerifier(this._config.circuitName, vKeyFilePath, verifierFilePath, languageExtension);
|
|
72
51
|
}
|
|
73
52
|
/**
|
|
74
53
|
* Calculates a witness for the given inputs.
|
|
@@ -92,13 +71,13 @@ class CircuitZKit {
|
|
|
92
71
|
* @dev The `inputs` should be in the same order as the circuit expects them.
|
|
93
72
|
*
|
|
94
73
|
* @param {Signals} inputs - The inputs for the circuit.
|
|
95
|
-
* @returns {Promise<
|
|
74
|
+
* @returns {Promise<ProofStructByProtocol<Type>>} The generated proof.
|
|
96
75
|
* @todo Add support for other proving systems.
|
|
97
76
|
*/
|
|
98
77
|
async generateProof(inputs) {
|
|
99
78
|
const zKeyFile = this.mustGetArtifactsFilePath("zkey");
|
|
100
79
|
const wasmFile = this.mustGetArtifactsFilePath("wasm");
|
|
101
|
-
return
|
|
80
|
+
return await this._implementer.generateProof(inputs, zKeyFile, wasmFile);
|
|
102
81
|
}
|
|
103
82
|
/**
|
|
104
83
|
* Verifies the given proof.
|
|
@@ -106,24 +85,22 @@ class CircuitZKit {
|
|
|
106
85
|
* @dev The `proof` can be generated using the `generateProof` method.
|
|
107
86
|
* @dev The `proof.publicSignals` should be in the same order as the circuit expects them.
|
|
108
87
|
*
|
|
109
|
-
* @param {
|
|
88
|
+
* @param {ProofStructByProtocol<Type>} proof - The proof to verify.
|
|
110
89
|
* @returns {Promise<boolean>} Whether the proof is valid.
|
|
111
90
|
*/
|
|
112
91
|
async verifyProof(proof) {
|
|
113
92
|
const vKeyFile = this.mustGetArtifactsFilePath("vkey");
|
|
114
|
-
|
|
115
|
-
return await snarkjs.groth16.verify(verifier, proof.publicSignals, proof.proof);
|
|
93
|
+
return this._implementer.verifyProof(proof, vKeyFile);
|
|
116
94
|
}
|
|
117
95
|
/**
|
|
118
96
|
* Generates the calldata for the given proof. The calldata can be used to verify the proof on-chain.
|
|
119
97
|
*
|
|
120
|
-
* @param {
|
|
121
|
-
* @returns {Promise<
|
|
98
|
+
* @param {ProofStructByProtocol<Type>} proof - The proof to generate calldata for.
|
|
99
|
+
* @returns {Promise<CalldataByProtocol<Type>>} - The generated calldata.
|
|
122
100
|
* @todo Add other types of calldata.
|
|
123
101
|
*/
|
|
124
102
|
async generateCalldata(proof) {
|
|
125
|
-
|
|
126
|
-
return JSON.parse(`[${calldata}]`);
|
|
103
|
+
return await this._implementer.generateCalldata(proof);
|
|
127
104
|
}
|
|
128
105
|
/**
|
|
129
106
|
* Returns the circuit name. The circuit name is the name of the circuit file without the extension.
|
|
@@ -139,15 +116,23 @@ class CircuitZKit {
|
|
|
139
116
|
* @returns {string} The verifier name.
|
|
140
117
|
*/
|
|
141
118
|
getVerifierName() {
|
|
142
|
-
return
|
|
119
|
+
return this._implementer.getVerifierName(this._config.circuitName);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Returns the type of the proving protocol
|
|
123
|
+
*
|
|
124
|
+
* @returns {ProvingSystemType} The protocol proving system type.
|
|
125
|
+
*/
|
|
126
|
+
getProvingSystemType() {
|
|
127
|
+
return this._implementer.getProvingSystemType();
|
|
143
128
|
}
|
|
144
129
|
/**
|
|
145
|
-
* Returns the
|
|
130
|
+
* Returns the Solidity verifier template.
|
|
146
131
|
*
|
|
147
|
-
* @returns {
|
|
132
|
+
* @returns {string} The Solidity verifier template.
|
|
148
133
|
*/
|
|
149
|
-
|
|
150
|
-
return this.
|
|
134
|
+
getVerifierTemplate(languageExtension) {
|
|
135
|
+
return this._implementer.getTemplate(languageExtension);
|
|
151
136
|
}
|
|
152
137
|
/**
|
|
153
138
|
* Returns the path to the file of the given type inside artifacts directory. Throws an error if the file doesn't exist.
|
|
@@ -177,10 +162,10 @@ class CircuitZKit {
|
|
|
177
162
|
fileName = `${circuitName}.r1cs`;
|
|
178
163
|
break;
|
|
179
164
|
case "zkey":
|
|
180
|
-
fileName = `${circuitName}
|
|
165
|
+
fileName = `${this._implementer.getZKeyFileName(circuitName)}`;
|
|
181
166
|
break;
|
|
182
167
|
case "vkey":
|
|
183
|
-
fileName = `${circuitName}
|
|
168
|
+
fileName = `${this._implementer.getVKeyFileName(circuitName)}`;
|
|
184
169
|
break;
|
|
185
170
|
case "sym":
|
|
186
171
|
fileName = `${circuitName}.sym`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CircuitZKit.js","sourceRoot":"","sources":["../../src/core/CircuitZKit.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"CircuitZKit.js","sourceRoot":"","sources":["../../src/core/CircuitZKit.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CA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AE,QAAQ,CAAC,CAAC;IACtC,CAAC;CACF;AA5KD,kCA4KC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Signals } from "../../types/proof-utils";
|
|
2
|
+
import { IProtocolImplementer, ProvingSystemType, ProofStructByProtocol, CalldataByProtocol } from "../../types/protocols";
|
|
3
|
+
import { VerifierLanguageType } from "../../types/circuit-zkit";
|
|
4
|
+
export declare abstract class AbstractProtocolImplementer<T extends ProvingSystemType> implements IProtocolImplementer<T> {
|
|
5
|
+
createVerifier(circuitName: string, vKeyFilePath: string, verifierFilePath: string, languageExtension: VerifierLanguageType): Promise<void>;
|
|
6
|
+
abstract generateProof(inputs: Signals, zKeyFilePath: string, wasmFilePath: string): Promise<ProofStructByProtocol<T>>;
|
|
7
|
+
abstract verifyProof(proof: ProofStructByProtocol<T>, vKeyFilePath: string): Promise<boolean>;
|
|
8
|
+
abstract generateCalldata(proof: ProofStructByProtocol<T>): Promise<CalldataByProtocol<T>>;
|
|
9
|
+
abstract getProvingSystemType(): ProvingSystemType;
|
|
10
|
+
getTemplate(languageExtension: VerifierLanguageType): string;
|
|
11
|
+
getVerifierName(circuitName: string): string;
|
|
12
|
+
getZKeyFileName(circuitName: string): string;
|
|
13
|
+
getVKeyFileName(circuitName: string): string;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=AbstractImplementer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AbstractImplementer.d.ts","sourceRoot":"","sources":["../../../src/core/protocols/AbstractImplementer.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,qBAAqB,EACrB,kBAAkB,EACnB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAEhE,8BAAsB,2BAA2B,CAAC,CAAC,SAAS,iBAAiB,CAAE,YAAW,oBAAoB,CAAC,CAAC,CAAC;IAClG,cAAc,CACzB,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,EACpB,gBAAgB,EAAE,MAAM,EACxB,iBAAiB,EAAE,oBAAoB,GACtC,OAAO,CAAC,IAAI,CAAC;aAeA,aAAa,CAC3B,MAAM,EAAE,OAAO,EACf,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;aAEpB,WAAW,CAAC,KAAK,EAAE,qBAAqB,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;aAEpF,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC;aAEjF,oBAAoB,IAAI,iBAAiB;IAElD,WAAW,CAAC,iBAAiB,EAAE,oBAAoB,GAAG,MAAM;IAO5D,eAAe,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM;IAM5C,eAAe,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM;IAI5C,eAAe,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM;CAGpD"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.AbstractProtocolImplementer = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const ejs_1 = __importDefault(require("ejs"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
class AbstractProtocolImplementer {
|
|
11
|
+
async createVerifier(circuitName, vKeyFilePath, verifierFilePath, languageExtension) {
|
|
12
|
+
const verifierTemplate = this.getTemplate(languageExtension);
|
|
13
|
+
if (!fs_1.default.existsSync(path_1.default.dirname(verifierFilePath))) {
|
|
14
|
+
fs_1.default.mkdirSync(path_1.default.dirname(verifierFilePath), { recursive: true });
|
|
15
|
+
}
|
|
16
|
+
const templateParams = JSON.parse(fs_1.default.readFileSync(vKeyFilePath, "utf-8"));
|
|
17
|
+
templateParams["verifier_id"] = this.getVerifierName(circuitName);
|
|
18
|
+
const verifierCode = ejs_1.default.render(verifierTemplate, templateParams);
|
|
19
|
+
fs_1.default.writeFileSync(verifierFilePath, verifierCode, "utf-8");
|
|
20
|
+
}
|
|
21
|
+
getTemplate(languageExtension) {
|
|
22
|
+
return fs_1.default.readFileSync(path_1.default.join(__dirname, "..", "templates", `verifier_${this.getProvingSystemType()}.${languageExtension}.ejs`), "utf8");
|
|
23
|
+
}
|
|
24
|
+
getVerifierName(circuitName) {
|
|
25
|
+
const protocolType = this.getProvingSystemType();
|
|
26
|
+
return `${circuitName}${protocolType.charAt(0).toUpperCase() + protocolType.slice(1)}Verifier`;
|
|
27
|
+
}
|
|
28
|
+
getZKeyFileName(circuitName) {
|
|
29
|
+
return `${circuitName}.${this.getProvingSystemType()}.zkey`;
|
|
30
|
+
}
|
|
31
|
+
getVKeyFileName(circuitName) {
|
|
32
|
+
return `${circuitName}.${this.getProvingSystemType()}.vkey.json`;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.AbstractProtocolImplementer = AbstractProtocolImplementer;
|
|
36
|
+
//# sourceMappingURL=AbstractImplementer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AbstractImplementer.js","sourceRoot":"","sources":["../../../src/core/protocols/AbstractImplementer.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,8CAAsB;AACtB,gDAAwB;AAWxB,MAAsB,2BAA2B;IACxC,KAAK,CAAC,cAAc,CACzB,WAAmB,EACnB,YAAoB,EACpB,gBAAwB,EACxB,iBAAuC;QAEvC,MAAM,gBAAgB,GA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,WAAW,IAAI,IAAI,CAAC,oBAAoB,EAAE,YAAY,CAAC;IACnE,CAAC;CACF;AArDD,kEAqDC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AbstractProtocolImplementer } from "./AbstractImplementer";
|
|
2
|
+
import { Signals } from "../../types/proof-utils";
|
|
3
|
+
import { Groth16ProofStruct, ProvingSystemType, Groth16Calldata } from "../../types/protocols";
|
|
4
|
+
export declare class Groth16Implementer extends AbstractProtocolImplementer<"groth16"> {
|
|
5
|
+
generateProof(inputs: Signals, zKeyFilePath: string, wasmFilePath: string): Promise<Groth16ProofStruct>;
|
|
6
|
+
verifyProof(proof: Groth16ProofStruct, vKeyFilePath: string): Promise<boolean>;
|
|
7
|
+
generateCalldata(proof: Groth16ProofStruct): Promise<Groth16Calldata>;
|
|
8
|
+
getProvingSystemType(): ProvingSystemType;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=Groth16Implementer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Groth16Implementer.d.ts","sourceRoot":"","sources":["../../../src/core/protocols/Groth16Implementer.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAC;AAEpE,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE/F,qBAAa,kBAAmB,SAAQ,2BAA2B,CAAC,SAAS,CAAC;IAC/D,aAAa,CAAC,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAIvG,WAAW,CAAC,KAAK,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAM9E,gBAAgB,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,eAAe,CAAC;IAM3E,oBAAoB,IAAI,iBAAiB;CAGjD"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.Groth16Implementer = void 0;
|
|
30
|
+
const fs_1 = __importDefault(require("fs"));
|
|
31
|
+
const snarkjs = __importStar(require("snarkjs"));
|
|
32
|
+
const AbstractImplementer_1 = require("./AbstractImplementer");
|
|
33
|
+
class Groth16Implementer extends AbstractImplementer_1.AbstractProtocolImplementer {
|
|
34
|
+
async generateProof(inputs, zKeyFilePath, wasmFilePath) {
|
|
35
|
+
return (await snarkjs.groth16.fullProve(inputs, wasmFilePath, zKeyFilePath));
|
|
36
|
+
}
|
|
37
|
+
async verifyProof(proof, vKeyFilePath) {
|
|
38
|
+
const verifier = JSON.parse(fs_1.default.readFileSync(vKeyFilePath).toString());
|
|
39
|
+
return await snarkjs.groth16.verify(verifier, proof.publicSignals, proof.proof);
|
|
40
|
+
}
|
|
41
|
+
async generateCalldata(proof) {
|
|
42
|
+
const calldata = await snarkjs.groth16.exportSolidityCallData(proof.proof, proof.publicSignals);
|
|
43
|
+
return JSON.parse(`[${calldata}]`);
|
|
44
|
+
}
|
|
45
|
+
getProvingSystemType() {
|
|
46
|
+
return "groth16";
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.Groth16Implementer = Groth16Implementer;
|
|
50
|
+
//# sourceMappingURL=Groth16Implementer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Groth16Implementer.js","sourceRoot":"","sources":["../../../src/core/protocols/Groth16Implementer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAAoB;AACpB,iDAAmC;AAEnC,+DAAoE;AAKpE,MAAa,kBAAmB,SAAQ,iDAAsC;IACrE,KAAK,CAAC,aAAa,CAAC,MAAe,EAAE,YAAoB,EAAE,YAAoB;QACpF,OAAO,CAAC,MAAM,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,MAAM,EAAE,YAAY,EAAE,YAAY,CAAC,CAAuB,CAAC;IACrG,CAAC;IAEM,KAAK,CAAC,WAAW,CAAC,KAAyB,EAAE,YAAoB;QACtE,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,YAAE,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;QAEtE,OAAO,MAAM,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,aAAa,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;IAClF,CAAC;IAEM,KAAK,CAAC,gBAAgB,CAAC,KAAyB;QACrD,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,sBAAsB,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC;QAEhG,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,QAAQ,GAAG,CAAoB,CAAC;IACxD,CAAC;IAEM,oBAAoB;QACzB,OAAO,SAAS,CAAC;IACnB,CAAC;CACF;AApBD,gDAoBC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AbstractProtocolImplementer } from "./AbstractImplementer";
|
|
2
|
+
import { Signals } from "../../types/proof-utils";
|
|
3
|
+
import { PlonkCalldata, PlonkProofStruct, ProvingSystemType } from "../../types/protocols";
|
|
4
|
+
export declare class PlonkImplementer extends AbstractProtocolImplementer<"plonk"> {
|
|
5
|
+
generateProof(inputs: Signals, zKeyFilePath: string, wasmFilePath: string): Promise<PlonkProofStruct>;
|
|
6
|
+
verifyProof(proof: PlonkProofStruct, vKeyFilePath: string): Promise<boolean>;
|
|
7
|
+
generateCalldata(proof: PlonkProofStruct): Promise<PlonkCalldata>;
|
|
8
|
+
getProvingSystemType(): ProvingSystemType;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=PlonkImplementer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PlonkImplementer.d.ts","sourceRoot":"","sources":["../../../src/core/protocols/PlonkImplementer.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAC;AAEpE,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE3F,qBAAa,gBAAiB,SAAQ,2BAA2B,CAAC,OAAO,CAAC;IAC3D,aAAa,CAAC,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAIrG,WAAW,CAAC,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAM5E,gBAAgB,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,aAAa,CAAC;IASvE,oBAAoB,IAAI,iBAAiB;CAGjD"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.PlonkImplementer = void 0;
|
|
30
|
+
const fs_1 = __importDefault(require("fs"));
|
|
31
|
+
const snarkjs = __importStar(require("snarkjs"));
|
|
32
|
+
const AbstractImplementer_1 = require("./AbstractImplementer");
|
|
33
|
+
class PlonkImplementer extends AbstractImplementer_1.AbstractProtocolImplementer {
|
|
34
|
+
async generateProof(inputs, zKeyFilePath, wasmFilePath) {
|
|
35
|
+
return (await snarkjs.plonk.fullProve(inputs, wasmFilePath, zKeyFilePath));
|
|
36
|
+
}
|
|
37
|
+
async verifyProof(proof, vKeyFilePath) {
|
|
38
|
+
const verifier = JSON.parse(fs_1.default.readFileSync(vKeyFilePath).toString());
|
|
39
|
+
return await snarkjs.plonk.verify(verifier, proof.publicSignals, proof.proof);
|
|
40
|
+
}
|
|
41
|
+
async generateCalldata(proof) {
|
|
42
|
+
const calldata = await snarkjs.plonk.exportSolidityCallData(proof.proof, proof.publicSignals);
|
|
43
|
+
const proofArrEndIndex = calldata.indexOf("]") + 1;
|
|
44
|
+
return JSON.parse(`[${calldata.slice(0, proofArrEndIndex)},${calldata.slice(proofArrEndIndex, calldata.length)}]`);
|
|
45
|
+
}
|
|
46
|
+
getProvingSystemType() {
|
|
47
|
+
return "plonk";
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.PlonkImplementer = PlonkImplementer;
|
|
51
|
+
//# sourceMappingURL=PlonkImplementer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PlonkImplementer.js","sourceRoot":"","sources":["../../../src/core/protocols/PlonkImplementer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAAoB;AACpB,iDAAmC;AAEnC,+DAAoE;AAKpE,MAAa,gBAAiB,SAAQ,iDAAoC;IACjE,K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B,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PlonkImplementer = exports.Groth16Implementer = exports.AbstractProtocolImplementer = void 0;
|
|
4
|
+
var AbstractImplementer_1 = require("./AbstractImplementer");
|
|
5
|
+
Object.defineProperty(exports, "AbstractProtocolImplementer", { enumerable: true, get: function () { return AbstractImplementer_1.AbstractProtocolImplementer; } });
|
|
6
|
+
var Groth16Implementer_1 = require("./Groth16Implementer");
|
|
7
|
+
Object.defineProperty(exports, "Groth16Implementer", { enumerable: true, get: function () { return Groth16Implementer_1.Groth16Implementer; } });
|
|
8
|
+
var PlonkImplementer_1 = require("./PlonkImplementer");
|
|
9
|
+
Object.defineProperty(exports, "PlonkImplementer", { enumerable: true, get: function () { return PlonkImplementer_1.PlonkImplementer; } });
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/protocols/index.ts"],"names":[],"mappings":";;;AAAA,6DAAoE;AAA3D,kIAAA,2BAA2B,OAAA;AACpC,2DAA0D;AAAjD,wHAAA,kBAAkB,OAAA;AAC3B,uDAAsD;AAA7C,oHAAA,gBAAgB,OAAA"}
|
|
@@ -22,7 +22,7 @@ DELTA_Y1: constant(uint256) = <%=vk_delta_2[1][1]%>
|
|
|
22
22
|
DELTA_Y2: constant(uint256) = <%=vk_delta_2[1][0] -%>
|
|
23
23
|
|
|
24
24
|
|
|
25
|
-
IC: constant(uint256[<%=IC.length%>]
|
|
25
|
+
IC: constant(uint256[2][<%=IC.length%>]) = [
|
|
26
26
|
<% IC.forEach(function(innerArray, index) { %> [
|
|
27
27
|
<%= innerArray[0] %>,
|
|
28
28
|
<%= innerArray[1] %>
|
|
@@ -36,7 +36,7 @@ EC_PAIRING_PRECOMPILED_ADDRESS: constant(address) = 0x00000000000000000000000000
|
|
|
36
36
|
|
|
37
37
|
@view
|
|
38
38
|
@external
|
|
39
|
-
def verifyProof(pointA: uint256[2], pointB: uint256[2][2], pointC: uint256[2], publicSignals: uint256[<%=IC.length-1%>]) -> bool:
|
|
39
|
+
def verifyProof(pointA: uint256[2], pointB: uint256[2][2], pointC: uint256[2], publicSignals: uint256[<%=IC.length - 1%>]) -> bool:
|
|
40
40
|
# @dev check that all public signals are in F
|
|
41
41
|
for signal: uint256 in publicSignals:
|
|
42
42
|
if signal >= BASE_FIELD_SIZE:
|
|
@@ -84,7 +84,7 @@ def _g1MulAdd(pR: uint256[2], pP: uint256[2], s: uint256) -> (bool, uint256[2]):
|
|
|
84
84
|
|
|
85
85
|
@view
|
|
86
86
|
@internal
|
|
87
|
-
def _checkPairing(pA: uint256[2], pB: uint256[2][2], pC: uint256[2], pubSignals: uint256[<%=IC.length-1%>]) -> bool:
|
|
87
|
+
def _checkPairing(pA: uint256[2], pB: uint256[2][2], pC: uint256[2], pubSignals: uint256[<%=IC.length - 1%>]) -> bool:
|
|
88
88
|
success: bool = True
|
|
89
89
|
mulAddResult: uint256[2] = IC[0]
|
|
90
90
|
|