@solarity/zkit 0.1.1 → 0.2.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/README.md +23 -51
- package/dist/core/CircuitZKit.d.ts +30 -89
- package/dist/core/CircuitZKit.d.ts.map +1 -1
- package/dist/core/CircuitZKit.js +80 -235
- package/dist/core/CircuitZKit.js.map +1 -1
- package/dist/index.d.ts +1 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -6
- package/dist/index.js.map +1 -1
- package/dist/types/circuit-zkit.d.ts +43 -0
- package/dist/types/circuit-zkit.d.ts.map +1 -0
- package/dist/types/circuit-zkit.js +3 -0
- package/dist/types/circuit-zkit.js.map +1 -0
- package/package.json +21 -10
- package/src/core/CircuitZKit.ts +88 -283
- package/src/index.ts +1 -6
- package/src/types/{types.ts → circuit-zkit.ts} +8 -12
- package/src/config/config.ts +0 -43
- package/src/core/CircomZKit.ts +0 -110
- package/src/core/ManagerZKit.ts +0 -231
- package/src/utils/utils.ts +0 -60
package/README.md
CHANGED
|
@@ -3,12 +3,11 @@
|
|
|
3
3
|
|
|
4
4
|
# ZKit - Circom Zero Knowledge Kit
|
|
5
5
|
|
|
6
|
-
**A zero knowledge kit that helps you
|
|
6
|
+
**A zero knowledge kit that helps you interact with Circom circuits.**
|
|
7
7
|
|
|
8
|
-
- Compile and interact with circuits without snarkjs hassle.
|
|
9
8
|
- Generate and verify ZK proofs with a single line of code.
|
|
10
9
|
- Render optimized Solidity verifiers.
|
|
11
|
-
-
|
|
10
|
+
- Build and work with ZK witnesses.
|
|
12
11
|
|
|
13
12
|
## Installation
|
|
14
13
|
|
|
@@ -20,67 +19,42 @@ npm install --save-dev @solarity/zkit
|
|
|
20
19
|
|
|
21
20
|
## Usage
|
|
22
21
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
ZKit is a configless package, which means you don't need to provide any configuration to use it:
|
|
26
|
-
|
|
27
|
-
```typescript
|
|
28
|
-
import { CircomZKit } from "@solarity/zkit";
|
|
29
|
-
|
|
30
|
-
async function main() {
|
|
31
|
-
const zkit = new CircomZKit();
|
|
32
|
-
|
|
33
|
-
const multiplier = zkit.getCircuit("Multiplier");
|
|
34
|
-
|
|
35
|
-
// Generates artifacts in the "./zkit-artifacts" directory
|
|
36
|
-
await multiplier.compile();
|
|
37
|
-
|
|
38
|
-
// Generates ZK proof
|
|
39
|
-
const proof = await multiplier.generateProof({ a: 2, b: 3});
|
|
40
|
-
}
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
By default, ZKit will look for the circuit file in the `./circuits` directory. However, you can change this by providing a custom one:
|
|
44
|
-
|
|
45
|
-
```typescript
|
|
46
|
-
new CircomZKit({ circuitsDir: "./my-circuits" });
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
To generate zkey, the power-of-tau file is required. ZKit automatically downloads those files from [Hermes](https://hermez.s3-eu-west-1.amazonaws.com/) to the `${HOME}/.zkit/.ptau` directory, so you don't need to re-download them every time you start a new project.
|
|
50
|
-
|
|
51
|
-
You can also provide a custom path to the directory where the power-of-tau files are stored:
|
|
22
|
+
> [!IMPORTANT]
|
|
23
|
+
> The kit is not meant to be used directly as its fitness relies heavily on the environment, Circom compilation artifacts management, processing of remappings, etc. Consider using [hardhat-zkit](https://github.com/dl-solarity/hardhat-zkit) which is a complete, developer-friendly package.
|
|
52
24
|
|
|
53
|
-
|
|
54
|
-
new CircomZKit({ ptauDir: "./my-ptau" });
|
|
55
|
-
```
|
|
25
|
+
### CircuitZKit
|
|
56
26
|
|
|
57
|
-
|
|
58
|
-
> Note that all the files in the `ptauDir` directory must have the `powers-of-tau-{x}.ptau` name format, where `{x}` is a maximum degree (2<sup>x</sup>) of constraints a `ptau` supports.
|
|
27
|
+
`CircuitZKit` is a user-friendly interface for interacting with circom circuits.
|
|
59
28
|
|
|
60
|
-
|
|
29
|
+
To create a CircuitZKit object it is necessary to pass a config:
|
|
61
30
|
|
|
62
31
|
```typescript
|
|
63
|
-
|
|
32
|
+
CircuitZKitConfig = {
|
|
33
|
+
circuitName: string;
|
|
34
|
+
circuitArtifactsPath: string;
|
|
35
|
+
verifierDirPath: string;
|
|
36
|
+
templateType?: VerifierTemplateType;
|
|
37
|
+
};
|
|
64
38
|
```
|
|
65
39
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
Once you created a `CircuitZKit` instance using the `getCircuit` method, you can manage the underlying circuit using the following methods:
|
|
40
|
+
This config contains all the information required to work with the circuit, namely:
|
|
69
41
|
|
|
70
|
-
|
|
71
|
-
|
|
42
|
+
- `circuitName` - Name of the circuit file without extension
|
|
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
|
|
72
46
|
|
|
73
|
-
####
|
|
47
|
+
#### getTemplate()
|
|
74
48
|
|
|
75
|
-
|
|
49
|
+
Static `CircuitZKit` function that returns the contents of a template file by the passed type.
|
|
76
50
|
|
|
77
51
|
```typescript
|
|
78
|
-
|
|
52
|
+
const templateContent = CircuitZKit.getTemplate("groth16");
|
|
79
53
|
```
|
|
80
54
|
|
|
81
55
|
#### createVerifier()
|
|
82
56
|
|
|
83
|
-
Creates Solidity verifier contract
|
|
57
|
+
Creates a Solidity verifier contract on `verifierDirPath` path, which was specified in the config.
|
|
84
58
|
|
|
85
59
|
```typescript
|
|
86
60
|
await multiplier.createVerifier();
|
|
@@ -92,7 +66,7 @@ Generates a proof for the given inputs.
|
|
|
92
66
|
|
|
93
67
|
```typescript
|
|
94
68
|
/// { proof: { pi_a, pi_b, pi_c, protocol, curve }, publicSignals: [6] }
|
|
95
|
-
const proof = await multiplier.generateProof({ a: 2, b: 3});
|
|
69
|
+
const proof = await multiplier.generateProof({ a: 2, b: 3 });
|
|
96
70
|
```
|
|
97
71
|
|
|
98
72
|
#### verifyProof()
|
|
@@ -116,5 +90,3 @@ const calldata = await multiplier.generateCalldata(proof);
|
|
|
116
90
|
## Known limitations
|
|
117
91
|
|
|
118
92
|
- Currently, ZKit supports only the Groth16 proving system.
|
|
119
|
-
- Zkey generation doesn't allow additional contributions.
|
|
120
|
-
- The `compile` method may cause [issues](https://github.com/iden3/snarkjs/issues/494).
|
|
@@ -1,34 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ManagerZKit } from "./ManagerZKit";
|
|
3
|
-
import { Calldata, Inputs, ProofStruct } from "../types/types";
|
|
1
|
+
import { ArtifactsFileType, Calldata, CircuitZKitConfig, Inputs, ProofStruct, VerifierTemplateType } from "../types/circuit-zkit";
|
|
4
2
|
/**
|
|
5
3
|
* `CircuitZKit` represents a single circuit and provides a high-level API to work with it.
|
|
6
|
-
*
|
|
7
|
-
* @dev This class is not meant to be used directly. Use the `CircomZKit` to create its instance.
|
|
8
4
|
*/
|
|
9
5
|
export declare class CircuitZKit {
|
|
10
|
-
private readonly
|
|
11
|
-
|
|
6
|
+
private readonly _config;
|
|
7
|
+
constructor(_config: CircuitZKitConfig);
|
|
12
8
|
/**
|
|
13
|
-
*
|
|
9
|
+
* Returns the Solidity verifier template for the specified proving system.
|
|
14
10
|
*
|
|
15
|
-
* @param {
|
|
16
|
-
* @
|
|
11
|
+
* @param {VerifierTemplateType} templateType - The template type.
|
|
12
|
+
* @returns {string} The Solidity verifier template.
|
|
17
13
|
*/
|
|
18
|
-
|
|
14
|
+
static getTemplate(templateType: VerifierTemplateType): string;
|
|
19
15
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* @dev If compilation fails, the latest valid artifacts will be preserved.
|
|
23
|
-
* @dev Doesn't show the compilation error if `quiet` is set to `true`.
|
|
24
|
-
*
|
|
25
|
-
* @param {Partial<CompileOptions>} [options=defaultCompileOptions] - Compilation options.
|
|
16
|
+
* Creates a Solidity verifier contract.
|
|
26
17
|
*/
|
|
27
|
-
|
|
18
|
+
createVerifier(): Promise<void>;
|
|
28
19
|
/**
|
|
29
|
-
* Creates a
|
|
20
|
+
* Creates a witness for the given inputs.
|
|
21
|
+
*
|
|
22
|
+
* @dev The `inputs` should be in the same order as the circuit expects them.
|
|
23
|
+
*
|
|
24
|
+
* @param {Inputs} inputs - The inputs for the circuit.
|
|
30
25
|
*/
|
|
31
|
-
|
|
26
|
+
createWitness(inputs: Inputs): Promise<void>;
|
|
32
27
|
/**
|
|
33
28
|
* Generates a proof for the given inputs.
|
|
34
29
|
*
|
|
@@ -58,90 +53,36 @@ export declare class CircuitZKit {
|
|
|
58
53
|
*/
|
|
59
54
|
generateCalldata(proof: ProofStruct): Promise<Calldata>;
|
|
60
55
|
/**
|
|
61
|
-
* Returns the circuit
|
|
56
|
+
* Returns the circuit name. The circuit name is the name of the circuit file without the extension.
|
|
62
57
|
*
|
|
63
|
-
* @returns {string} The circuit
|
|
58
|
+
* @returns {string} The circuit name.
|
|
64
59
|
*/
|
|
65
|
-
|
|
60
|
+
getCircuitName(): string;
|
|
66
61
|
/**
|
|
67
|
-
* Returns the verifier
|
|
62
|
+
* Returns the verifier name. The verifier name is the name of the circuit file without the extension, suffixed with "Verifier".
|
|
68
63
|
*
|
|
69
|
-
* @returns {string} The verifier
|
|
64
|
+
* @returns {string} The verifier name.
|
|
70
65
|
*/
|
|
71
|
-
|
|
66
|
+
getVerifierName(): string;
|
|
72
67
|
/**
|
|
73
|
-
*
|
|
68
|
+
* Returns the type of verifier template that was stored in the config
|
|
74
69
|
*
|
|
75
|
-
* @
|
|
76
|
-
* @param {string} outDir - The directory to save the generated key.
|
|
77
|
-
* @todo This method may cause issues https://github.com/iden3/snarkjs/issues/494
|
|
70
|
+
* @returns {VerifierTemplateType} The verifier template type.
|
|
78
71
|
*/
|
|
79
|
-
|
|
72
|
+
getTemplateType(): VerifierTemplateType;
|
|
80
73
|
/**
|
|
81
|
-
*
|
|
74
|
+
* Returns the path to the file of the given type inside artifacts directory. Throws an error if the file doesn't exist.
|
|
82
75
|
*
|
|
83
|
-
* @param {
|
|
84
|
-
*/
|
|
85
|
-
private _generateVKey;
|
|
86
|
-
/**
|
|
87
|
-
* Returns the arguments to compile the circuit.
|
|
88
|
-
*
|
|
89
|
-
* @param {CompileOptions} options - Compilation options.
|
|
90
|
-
* @param {string} outDir - The directory to save the compiled artifacts.
|
|
91
|
-
* @returns {string[]} The arguments to compile the circuit.
|
|
92
|
-
*/
|
|
93
|
-
private _getCompileArgs;
|
|
94
|
-
/**
|
|
95
|
-
* Compiles the circuit.
|
|
96
|
-
*
|
|
97
|
-
* @param {CompileOptions} options - Compilation options.
|
|
98
|
-
* @param {string} outDir - The directory to save the compiled artifacts.
|
|
99
|
-
*/
|
|
100
|
-
private _compile;
|
|
101
|
-
/**
|
|
102
|
-
* Returns the number of constraints in the circuit. This value is used to fetch the correct `ptau` file.
|
|
103
|
-
*
|
|
104
|
-
* @param {string} outDir - The directory where the compiled artifacts are saved.
|
|
105
|
-
* @returns {Promise<number>} The number of constraints in the circuit.
|
|
106
|
-
*/
|
|
107
|
-
_getConstraints(outDir: string): Promise<number>;
|
|
108
|
-
/**
|
|
109
|
-
* Returns the path to the file of the given type.
|
|
110
|
-
*
|
|
111
|
-
* @param {FileType} fileType - The type of the file.
|
|
112
|
-
* @param {string | undefined} temp - The temporary directory to use.
|
|
76
|
+
* @param {ArtifactsFileType} fileType - The type of the file.
|
|
113
77
|
* @returns {string} The path to the file.
|
|
114
78
|
*/
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Returns the path to the directory of the given type.
|
|
118
|
-
*
|
|
119
|
-
* @param {DirType} dirType - The type of the directory.
|
|
120
|
-
* @returns {string} The path to the directory.
|
|
121
|
-
*/
|
|
122
|
-
private _getDir;
|
|
79
|
+
mustGetArtifactsFilePath(fileType: ArtifactsFileType): string;
|
|
123
80
|
/**
|
|
124
|
-
* Returns the path to the file of the given type
|
|
81
|
+
* Returns the path to the file of the given type inside artifacts directory.
|
|
125
82
|
*
|
|
126
|
-
* @param {
|
|
127
|
-
* @param {string | undefined} temp - The temporary directory to use.
|
|
83
|
+
* @param {ArtifactsFileType} fileType - The type of the file.
|
|
128
84
|
* @returns {string} The path to the file.
|
|
129
85
|
*/
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Moves the files from the temporary directory to the output directory.
|
|
133
|
-
*
|
|
134
|
-
* @param {string} tempDir - The temporary directory.
|
|
135
|
-
* @param {string} outDir - The output directory.
|
|
136
|
-
*/
|
|
137
|
-
private _moveFromTempDirToOutDir;
|
|
138
|
-
/**
|
|
139
|
-
* Returns a new instance of `CircomRunner`. The `CircomRunner` is used to compile the circuit.
|
|
140
|
-
*
|
|
141
|
-
* @param {string[]} args - The arguments to run the `circom` compiler.
|
|
142
|
-
* @param {boolean} quiet - Whether to suppress the compilation error.
|
|
143
|
-
* @returns {typeof CircomRunner} The `CircomRunner` instance.
|
|
144
|
-
*/
|
|
145
|
-
private _getCircomRunner;
|
|
86
|
+
getArtifactsFilePath(fileType: ArtifactsFileType): string;
|
|
146
87
|
}
|
|
147
88
|
//# sourceMappingURL=CircuitZKit.d.ts.map
|
|
@@ -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,EACL,iBAAiB,EACjB,QAAQ,EACR,iBAAiB,EACjB,MAAM,EACN,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;;;;;;OAMG;IACU,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOzD;;;;;;;;OAQG;IACU,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAOhE;;;;;;;;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;CAmCjE"}
|