@solarity/zkit 0.2.5 → 0.3.0-rc.0

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.
Files changed (80) hide show
  1. package/README.md +8 -8
  2. package/dist/core/CircuitZKit.d.ts +24 -22
  3. package/dist/core/CircuitZKit.d.ts.map +1 -1
  4. package/dist/core/CircuitZKit.js +30 -44
  5. package/dist/core/CircuitZKit.js.map +1 -1
  6. package/dist/core/protocols/AbstractImplementer.d.ts +15 -0
  7. package/dist/core/protocols/AbstractImplementer.d.ts.map +1 -0
  8. package/dist/core/protocols/AbstractImplementer.js +36 -0
  9. package/dist/core/protocols/AbstractImplementer.js.map +1 -0
  10. package/dist/core/protocols/Groth16Implementer.d.ts +10 -0
  11. package/dist/core/protocols/Groth16Implementer.d.ts.map +1 -0
  12. package/dist/core/protocols/Groth16Implementer.js +50 -0
  13. package/dist/core/protocols/Groth16Implementer.js.map +1 -0
  14. package/dist/core/protocols/PlonkImplementer.d.ts +10 -0
  15. package/dist/core/protocols/PlonkImplementer.d.ts.map +1 -0
  16. package/dist/core/protocols/PlonkImplementer.js +51 -0
  17. package/dist/core/protocols/PlonkImplementer.js.map +1 -0
  18. package/dist/core/protocols/index.d.ts +4 -0
  19. package/dist/core/protocols/index.d.ts.map +1 -0
  20. package/dist/core/protocols/index.js +10 -0
  21. package/dist/core/protocols/index.js.map +1 -0
  22. package/dist/core/templates/verifier_groth16.vy.ejs +118 -0
  23. package/dist/core/templates/verifier_plonk.sol.ejs +681 -0
  24. package/dist/core/templates/verifier_plonk.vy.ejs +650 -0
  25. package/dist/index.d.ts +4 -1
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +6 -1
  28. package/dist/index.js.map +1 -1
  29. package/dist/types/circuit-zkit.d.ts +1 -34
  30. package/dist/types/circuit-zkit.d.ts.map +1 -1
  31. package/dist/types/proof-utils.d.ts +7 -0
  32. package/dist/types/proof-utils.d.ts.map +1 -0
  33. package/dist/types/proof-utils.js +3 -0
  34. package/dist/types/proof-utils.js.map +1 -0
  35. package/dist/types/protocols/groth16.d.ts +28 -0
  36. package/dist/types/protocols/groth16.d.ts.map +1 -0
  37. package/dist/types/protocols/groth16.js +3 -0
  38. package/dist/types/protocols/groth16.js.map +1 -0
  39. package/dist/types/protocols/index.d.ts +31 -0
  40. package/dist/types/protocols/index.d.ts.map +1 -0
  41. package/dist/types/protocols/index.js +19 -0
  42. package/dist/types/protocols/index.js.map +1 -0
  43. package/dist/types/protocols/plonk.d.ts +26 -0
  44. package/dist/types/protocols/plonk.d.ts.map +1 -0
  45. package/dist/types/{types.js → protocols/plonk.js} +1 -1
  46. package/dist/types/protocols/plonk.js.map +1 -0
  47. package/package.json +7 -6
  48. package/src/core/CircuitZKit.ts +42 -63
  49. package/src/core/protocols/AbstractImplementer.ts +67 -0
  50. package/src/core/protocols/Groth16Implementer.ts +29 -0
  51. package/src/core/protocols/PlonkImplementer.ts +32 -0
  52. package/src/core/protocols/index.ts +3 -0
  53. package/src/core/templates/verifier_groth16.vy.ejs +118 -0
  54. package/src/core/templates/verifier_plonk.sol.ejs +681 -0
  55. package/src/core/templates/verifier_plonk.vy.ejs +650 -0
  56. package/src/index.ts +5 -1
  57. package/src/types/circuit-zkit.ts +1 -31
  58. package/src/types/proof-utils.ts +9 -0
  59. package/src/types/protocols/groth16.ts +21 -0
  60. package/src/types/protocols/index.ts +49 -0
  61. package/src/types/protocols/plonk.ts +28 -0
  62. package/dist/config/config.d.ts +0 -27
  63. package/dist/config/config.d.ts.map +0 -1
  64. package/dist/config/config.js +0 -19
  65. package/dist/config/config.js.map +0 -1
  66. package/dist/core/CircomZKit.d.ts +0 -39
  67. package/dist/core/CircomZKit.d.ts.map +0 -1
  68. package/dist/core/CircomZKit.js +0 -94
  69. package/dist/core/CircomZKit.js.map +0 -1
  70. package/dist/core/ManagerZKit.d.ts +0 -97
  71. package/dist/core/ManagerZKit.d.ts.map +0 -1
  72. package/dist/core/ManagerZKit.js +0 -222
  73. package/dist/core/ManagerZKit.js.map +0 -1
  74. package/dist/types/types.d.ts +0 -46
  75. package/dist/types/types.d.ts.map +0 -1
  76. package/dist/types/types.js.map +0 -1
  77. package/dist/utils/utils.d.ts +0 -18
  78. package/dist/utils/utils.d.ts.map +0 -1
  79. package/dist/utils/utils.js +0 -58
  80. package/dist/utils/utils.js.map +0 -1
package/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
  **A zero knowledge kit that helps you interact with Circom circuits.**
7
7
 
8
8
  - Generate and verify ZK proofs with a single line of code.
9
- - Render optimized Solidity verifiers.
9
+ - Render optimized Solidity | Vyper verifiers.
10
10
  - Build and work with ZK witnesses.
11
11
 
12
12
  ## Installation
@@ -33,7 +33,7 @@ CircuitZKitConfig = {
33
33
  circuitName: string;
34
34
  circuitArtifactsPath: string;
35
35
  verifierDirPath: string;
36
- templateType?: VerifierTemplateType;
36
+ provingSystem?: VerifierProvingSystem;
37
37
  };
38
38
  ```
39
39
 
@@ -41,23 +41,23 @@ This config contains all the information required to work with the circuit, name
41
41
 
42
42
  - `circuitName` - Name of the circuit file without extension
43
43
  - `circuitArtifactsPath` - Full path to compilation artifacts for the desired circuit
44
- - `verifierDirPath` - Full path to the directory where Solidity verifier file will be generated
45
- - `templateType` - The type of template that will be used to generate the Solidity verifier contract. Right now only `groth16` is supported
44
+ - `verifierDirPath` - Full path to the directory where Solidity | Vyper verifier file will be generated
45
+ - `provingSystem` - The proving system that will be used to generate the verifier contract. Right now only `groth16` is supported
46
46
 
47
47
  #### getTemplate()
48
48
 
49
49
  Static `CircuitZKit` function that returns the contents of a template file by the passed type.
50
50
 
51
51
  ```typescript
52
- const templateContent = CircuitZKit.getTemplate("groth16");
52
+ const templateContent = CircuitZKit.getTemplate("groth16", "sol");
53
53
  ```
54
54
 
55
55
  #### createVerifier()
56
56
 
57
- Creates a Solidity verifier contract on `verifierDirPath` path, which was specified in the config.
57
+ Creates a Solidity | Vyper verifier contract on `verifierDirPath` path, which was specified in the config.
58
58
 
59
59
  ```typescript
60
- await multiplier.createVerifier();
60
+ await multiplier.createVerifier("sol");
61
61
  ```
62
62
 
63
63
  #### calculateWitness()
@@ -89,7 +89,7 @@ const isValidProof = await multiplier.verifyProof(proof);
89
89
 
90
90
  #### generateCalldata()
91
91
 
92
- Generates calldata by proof for the Solidity verifier's `verifyProof()` method.
92
+ Generates calldata by proof for the Solidity | Vyper verifier's `verifyProof()` method.
93
93
 
94
94
  ```typescript
95
95
  /// You can use this calldata to call the verifier contract
@@ -1,21 +1,17 @@
1
- import { ArtifactsFileType, Calldata, CircuitZKitConfig, Signals, ProofStruct, VerifierTemplateType } from "../types/circuit-zkit";
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
- constructor(_config: CircuitZKitConfig);
9
+ private readonly _implementer;
10
+ constructor(_config: CircuitZKitConfig, _implementer: IProtocolImplementer<Type>);
8
11
  /**
9
- * Returns the Solidity verifier template for the specified proving system.
10
- *
11
- * @param {VerifierTemplateType} templateType - The template type.
12
- * @returns {string} The Solidity verifier template.
13
- */
14
- static getTemplate(templateType: VerifierTemplateType): string;
15
- /**
16
- * Creates a Solidity verifier contract.
12
+ * Creates a verifier contract for the specified contract language.
17
13
  */
18
- createVerifier(): Promise<void>;
14
+ createVerifier(languageExtension: VerifierLanguageType): Promise<void>;
19
15
  /**
20
16
  * Calculates a witness for the given inputs.
21
17
  *
@@ -29,28 +25,28 @@ export declare class CircuitZKit {
29
25
  * @dev The `inputs` should be in the same order as the circuit expects them.
30
26
  *
31
27
  * @param {Signals} inputs - The inputs for the circuit.
32
- * @returns {Promise<ProofStruct>} The generated proof.
28
+ * @returns {Promise<ProofStructByProtocol<Type>>} The generated proof.
33
29
  * @todo Add support for other proving systems.
34
30
  */
35
- generateProof(inputs: Signals): Promise<ProofStruct>;
31
+ generateProof(inputs: Signals): Promise<ProofStructByProtocol<Type>>;
36
32
  /**
37
33
  * Verifies the given proof.
38
34
  *
39
35
  * @dev The `proof` can be generated using the `generateProof` method.
40
36
  * @dev The `proof.publicSignals` should be in the same order as the circuit expects them.
41
37
  *
42
- * @param {ProofStruct} proof - The proof to verify.
38
+ * @param {ProofStructByProtocol<Type>} proof - The proof to verify.
43
39
  * @returns {Promise<boolean>} Whether the proof is valid.
44
40
  */
45
- verifyProof(proof: ProofStruct): Promise<boolean>;
41
+ verifyProof(proof: ProofStructByProtocol<Type>): Promise<boolean>;
46
42
  /**
47
43
  * Generates the calldata for the given proof. The calldata can be used to verify the proof on-chain.
48
44
  *
49
- * @param {ProofStruct} proof - The proof to generate calldata for.
50
- * @returns {Promise<Calldata>} - The generated calldata.
45
+ * @param {ProofStructByProtocol<Type>} proof - The proof to generate calldata for.
46
+ * @returns {Promise<CalldataByProtocol<Type>>} - The generated calldata.
51
47
  * @todo Add other types of calldata.
52
48
  */
53
- generateCalldata(proof: ProofStruct): Promise<Calldata>;
49
+ generateCalldata(proof: ProofStructByProtocol<Type>): Promise<CalldataByProtocol<Type>>;
54
50
  /**
55
51
  * Returns the circuit name. The circuit name is the name of the circuit file without the extension.
56
52
  *
@@ -64,11 +60,17 @@ export declare class CircuitZKit {
64
60
  */
65
61
  getVerifierName(): string;
66
62
  /**
67
- * Returns the type of verifier template that was stored in the config
63
+ * Returns the type of the proving protocol
68
64
  *
69
- * @returns {VerifierTemplateType} The verifier template type.
65
+ * @returns {ProvingSystemType} The protocol proving system type.
66
+ */
67
+ getProvingSystemType(): ProvingSystemType;
68
+ /**
69
+ * Returns the Solidity verifier template.
70
+ *
71
+ * @returns {string} The Solidity verifier template.
70
72
  */
71
- getTemplateType(): VerifierTemplateType;
73
+ getVerifierTemplate(languageExtension: VerifierLanguageType): string;
72
74
  /**
73
75
  * Returns the path to the file of the given type inside artifacts directory. Throws an error if the file doesn't exist.
74
76
  *
@@ -1 +1 @@
1
- {"version":3,"file":"CircuitZKit.d.ts","sourceRoot":"","sources":["../../src/core/CircuitZKit.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,iBAAiB,EACjB,QAAQ,EACR,iBAAiB,EACjB,OAAO,EACP,WAAW,EACX,oBAAoB,EACrB,MAAM,uBAAuB,CAAC;AAE/B;;GAEG;AACH,qBAAa,WAAW;IACV,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAAP,OAAO,EAAE,iBAAiB;IAEvD;;;;;OAKG;WACW,WAAW,CAAC,YAAY,EAAE,oBAAoB,GAAG,MAAM;IASrE;;OAEG;IACU,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAkB5C;;;;;OAKG;IACU,gBAAgB,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAejE;;;;;;;;OAQG;IACU,aAAa,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,WAAW,CAAC;IAOjE;;;;;;;;OAQG;IACU,WAAW,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC;IAQ9D;;;;;;OAMG;IACU,gBAAgB,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC;IAMpE;;;;OAIG;IACI,cAAc,IAAI,MAAM;IAI/B;;;;OAIG;IACI,eAAe,IAAI,MAAM;IAIhC;;;;OAIG;IACI,eAAe,IAAI,oBAAoB;IAI9C;;;;;OAKG;IACI,wBAAwB,CAAC,QAAQ,EAAE,iBAAiB,GAAG,MAAM;IAUpE;;;;;OAKG;IACI,oBAAoB,CAAC,QAAQ,EAAE,iBAAiB,GAAG,MAAM;CAgCjE"}
1
+ {"version":3,"file":"CircuitZKit.d.ts","sourceRoot":"","sources":["../../src/core/CircuitZKit.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AAM;IAUpE;;;;;OAKG;IACI,oBAAoB,CAAC,QAAQ,EAAE,iBAAiB,GAAG,MAAM;CAgCjE"}
@@ -27,47 +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
- constructor(_config) {
39
+ _implementer;
40
+ constructor(_config, _implementer) {
41
41
  this._config = _config;
42
+ this._implementer = _implementer;
42
43
  }
43
44
  /**
44
- * Returns the Solidity verifier template for the specified proving system.
45
- *
46
- * @param {VerifierTemplateType} templateType - The template type.
47
- * @returns {string} The Solidity verifier template.
45
+ * Creates a verifier contract for the specified contract language.
48
46
  */
49
- static getTemplate(templateType) {
50
- switch (templateType) {
51
- case "groth16":
52
- return fs_1.default.readFileSync(path_1.default.join(__dirname, "templates", "verifier_groth16.sol.ejs"), "utf8");
53
- default:
54
- throw new Error(`Ambiguous template type: ${templateType}.`);
55
- }
56
- }
57
- /**
58
- * Creates a Solidity verifier contract.
59
- */
60
- async createVerifier() {
47
+ async createVerifier(languageExtension) {
61
48
  const vKeyFilePath = this.mustGetArtifactsFilePath("vkey");
62
- const verifierFilePath = path_1.default.join(this._config.verifierDirPath, `${this.getVerifierName()}.sol`);
63
- const verifierTemplate = CircuitZKit.getTemplate(this.getTemplateType());
64
- if (!fs_1.default.existsSync(this._config.verifierDirPath)) {
65
- fs_1.default.mkdirSync(this._config.verifierDirPath, { recursive: true });
66
- }
67
- const templateParams = JSON.parse(fs_1.default.readFileSync(vKeyFilePath, "utf-8"));
68
- templateParams["verifier_id"] = this.getVerifierName();
69
- const verifierCode = ejs_1.default.render(verifierTemplate, templateParams);
70
- 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);
71
51
  }
72
52
  /**
73
53
  * Calculates a witness for the given inputs.
@@ -91,13 +71,13 @@ class CircuitZKit {
91
71
  * @dev The `inputs` should be in the same order as the circuit expects them.
92
72
  *
93
73
  * @param {Signals} inputs - The inputs for the circuit.
94
- * @returns {Promise<ProofStruct>} The generated proof.
74
+ * @returns {Promise<ProofStructByProtocol<Type>>} The generated proof.
95
75
  * @todo Add support for other proving systems.
96
76
  */
97
77
  async generateProof(inputs) {
98
78
  const zKeyFile = this.mustGetArtifactsFilePath("zkey");
99
79
  const wasmFile = this.mustGetArtifactsFilePath("wasm");
100
- return (await snarkjs.groth16.fullProve(inputs, wasmFile, zKeyFile));
80
+ return await this._implementer.generateProof(inputs, zKeyFile, wasmFile);
101
81
  }
102
82
  /**
103
83
  * Verifies the given proof.
@@ -105,24 +85,22 @@ class CircuitZKit {
105
85
  * @dev The `proof` can be generated using the `generateProof` method.
106
86
  * @dev The `proof.publicSignals` should be in the same order as the circuit expects them.
107
87
  *
108
- * @param {ProofStruct} proof - The proof to verify.
88
+ * @param {ProofStructByProtocol<Type>} proof - The proof to verify.
109
89
  * @returns {Promise<boolean>} Whether the proof is valid.
110
90
  */
111
91
  async verifyProof(proof) {
112
92
  const vKeyFile = this.mustGetArtifactsFilePath("vkey");
113
- const verifier = JSON.parse(fs_1.default.readFileSync(vKeyFile).toString());
114
- return await snarkjs.groth16.verify(verifier, proof.publicSignals, proof.proof);
93
+ return this._implementer.verifyProof(proof, vKeyFile);
115
94
  }
116
95
  /**
117
96
  * Generates the calldata for the given proof. The calldata can be used to verify the proof on-chain.
118
97
  *
119
- * @param {ProofStruct} proof - The proof to generate calldata for.
120
- * @returns {Promise<Calldata>} - The generated calldata.
98
+ * @param {ProofStructByProtocol<Type>} proof - The proof to generate calldata for.
99
+ * @returns {Promise<CalldataByProtocol<Type>>} - The generated calldata.
121
100
  * @todo Add other types of calldata.
122
101
  */
123
102
  async generateCalldata(proof) {
124
- const calldata = await snarkjs.groth16.exportSolidityCallData(proof.proof, proof.publicSignals);
125
- return JSON.parse(`[${calldata}]`);
103
+ return await this._implementer.generateCalldata(proof);
126
104
  }
127
105
  /**
128
106
  * Returns the circuit name. The circuit name is the name of the circuit file without the extension.
@@ -138,15 +116,23 @@ class CircuitZKit {
138
116
  * @returns {string} The verifier name.
139
117
  */
140
118
  getVerifierName() {
141
- return `${this._config.circuitName}Verifier`;
119
+ return this._implementer.getVerifierName(this._config.circuitName);
142
120
  }
143
121
  /**
144
- * Returns the type of verifier template that was stored in the config
122
+ * Returns the type of the proving protocol
145
123
  *
146
- * @returns {VerifierTemplateType} The verifier template type.
124
+ * @returns {ProvingSystemType} The protocol proving system type.
125
+ */
126
+ getProvingSystemType() {
127
+ return this._implementer.getProvingSystemType();
128
+ }
129
+ /**
130
+ * Returns the Solidity verifier template.
131
+ *
132
+ * @returns {string} The Solidity verifier template.
147
133
  */
148
- getTemplateType() {
149
- return this._config.templateType ?? "groth16";
134
+ getVerifierTemplate(languageExtension) {
135
+ return this._implementer.getTemplate(languageExtension);
150
136
  }
151
137
  /**
152
138
  * Returns the path to the file of the given type inside artifacts directory. Throws an error if the file doesn't exist.
@@ -176,10 +162,10 @@ class CircuitZKit {
176
162
  fileName = `${circuitName}.r1cs`;
177
163
  break;
178
164
  case "zkey":
179
- fileName = `${circuitName}.zkey`;
165
+ fileName = `${this._implementer.getZKeyFileName(circuitName)}`;
180
166
  break;
181
167
  case "vkey":
182
- fileName = `${circuitName}.vkey.json`;
168
+ fileName = `${this._implementer.getVKeyFileName(circuitName)}`;
183
169
  break;
184
170
  case "sym":
185
171
  fileName = `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tocol, 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,GAAW,IAAI,CAAC,WAAW,CAAC,iBAAiB,CAAC,CAAC;QAErE,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,cAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,EAAE,CAAC;YACnD,YAAE,CAAC,SAAS,CAAC,cAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACpE,CAAC;QAED,MAAM,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,YAAE,CAAC,YAAY,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC,CAAC;QAC1E,cAAc,CAAC,aAAa,CAAC,GAAG,IAAI,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC;QAElE,MAAM,YAAY,GAAG,aAAG,CAAC,MAAM,CAAC,gBAAgB,EAAE,cAAc,CAAC,CAAC;QAElE,YAAE,CAAC,aAAa,CAAC,gBAAgB,EAAE,YAAY,EAAE,OAAO,CAAC,CAAC;IAC5D,CAAC;IAcM,WAAW,CAAC,iBAAuC;QACxD,OAAO,YAAE,CAAC,YAAY,CACpB,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,WAAW,EAAE,YAAY,IAAI,CAAC,oBAAoB,EAAE,IAAI,iBAAiB,MAAM,CAAC,EAC3G,MAAM,CACP,CAAC;IACJ,CAAC;IAEM,eAAe,CAAC,WAAmB;QACxC,MAAM,YAAY,GAAsB,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAEpE,OAAO,GAAG,WAAW,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC;IACjG,CAAC;IAEM,eAAe,CAAC,WAAmB;QACxC,OAAO,GAAG,WAAW,IAAI,IAAI,CAAC,oBAAoB,EAAE,OAAO,CAAC;IAC9D,CAAC;IAEM,eAAe,CAAC,WAAmB;QACxC,OAAO,GAAG,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,KAAK,CAAC,aAAa,CAAC,MAAe,EAAE,YAAoB,EAAE,YAAoB;QACpF,OAAO,CAAC,MAAM,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,EAAE,YAAY,EAAE,YAAY,CAAC,CAAqB,CAAC;IACjG,CAAC;IAEM,KAAK,CAAC,WAAW,CAAC,KAAuB,EAAE,YAAoB;QACpE,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,YAAE,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;QAEtE,OAAO,MAAM,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,aAAa,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;IAChF,CAAC;IAEM,KAAK,CAAC,gBAAgB,CAAC,KAAuB;QACnD,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,sBAAsB,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC;QAC9F,MAAM,gBAAgB,GAAW,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAE3D,OAAO,IAAI,CAAC,KAAK,CACf,IAAI,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,gBAAgB,CAAC,IAAI,QAAQ,CAAC,KAAK,CAAC,gBAAgB,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,CAC/E,CAAC;IACrB,CAAC;IAEM,oBAAoB;QACzB,OAAO,OAAO,CAAC;IACjB,CAAC;CACF;AAvBD,4CAuBC"}
@@ -0,0 +1,4 @@
1
+ export { AbstractProtocolImplementer } from "./AbstractImplementer";
2
+ export { Groth16Implementer } from "./Groth16Implementer";
3
+ export { PlonkImplementer } from "./PlonkImplementer";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/protocols/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAC;AACpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,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"}