@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.
- package/README.md +8 -8
- package/dist/core/CircuitZKit.d.ts +24 -22
- package/dist/core/CircuitZKit.d.ts.map +1 -1
- package/dist/core/CircuitZKit.js +30 -44
- 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 +118 -0
- package/dist/core/templates/verifier_plonk.sol.ejs +681 -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 +1 -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 +7 -6
- package/src/core/CircuitZKit.ts +42 -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 +118 -0
- package/src/core/templates/verifier_plonk.sol.ejs +681 -0
- package/src/core/templates/verifier_plonk.vy.ejs +650 -0
- package/src/index.ts +5 -1
- package/src/types/circuit-zkit.ts +1 -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,41 +1,8 @@
|
|
|
1
|
-
export type NumericString = `${number}` | string;
|
|
2
|
-
export type PublicSignals = NumericString[];
|
|
3
|
-
export type Groth16Proof = {
|
|
4
|
-
pi_a: [NumericString, NumericString];
|
|
5
|
-
pi_b: [[NumericString, NumericString], [NumericString, NumericString]];
|
|
6
|
-
pi_c: [NumericString, NumericString];
|
|
7
|
-
protocol: string;
|
|
8
|
-
curve: string;
|
|
9
|
-
};
|
|
10
|
-
export type Calldata = [
|
|
11
|
-
[
|
|
12
|
-
NumericString,
|
|
13
|
-
NumericString
|
|
14
|
-
],
|
|
15
|
-
[
|
|
16
|
-
[NumericString, NumericString],
|
|
17
|
-
[NumericString, NumericString]
|
|
18
|
-
],
|
|
19
|
-
[
|
|
20
|
-
NumericString,
|
|
21
|
-
NumericString
|
|
22
|
-
],
|
|
23
|
-
PublicSignals
|
|
24
|
-
];
|
|
25
|
-
export type ProofStruct = {
|
|
26
|
-
proof: Groth16Proof;
|
|
27
|
-
publicSignals: PublicSignals;
|
|
28
|
-
};
|
|
29
|
-
export type NumberLike = number | bigint | `${number}`;
|
|
30
|
-
export type ArrayLike = NumberLike[] | ArrayLike[];
|
|
31
|
-
export type Signal = NumberLike | ArrayLike;
|
|
32
|
-
export type Signals = Record<string, Signal>;
|
|
33
1
|
export type ArtifactsFileType = "r1cs" | "zkey" | "vkey" | "sym" | "json" | "wasm";
|
|
34
|
-
export type
|
|
2
|
+
export type VerifierLanguageType = "sol" | "vy";
|
|
35
3
|
export type CircuitZKitConfig = {
|
|
36
4
|
circuitName: string;
|
|
37
5
|
circuitArtifactsPath: string;
|
|
38
6
|
verifierDirPath: string;
|
|
39
|
-
templateType?: VerifierTemplateType;
|
|
40
7
|
};
|
|
41
8
|
//# sourceMappingURL=circuit-zkit.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"circuit-zkit.d.ts","sourceRoot":"","sources":["../../src/types/circuit-zkit.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"circuit-zkit.d.ts","sourceRoot":"","sources":["../../src/types/circuit-zkit.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,GAAG,MAAM,GAAG,MAAM,CAAC;AACnF,MAAM,MAAM,oBAAoB,GAAG,KAAK,GAAG,IAAI,CAAC;AAEhD,MAAM,MAAM,iBAAiB,GAAG;IAC9B,WAAW,EAAE,MAAM,CAAC;IACpB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type NumericString = `${number}` | string;
|
|
2
|
+
export type PublicSignals = NumericString[];
|
|
3
|
+
export type NumberLike = number | bigint | `${number}`;
|
|
4
|
+
export type ArrayLike = NumberLike[] | ArrayLike[];
|
|
5
|
+
export type Signal = NumberLike | ArrayLike;
|
|
6
|
+
export type Signals = Record<string, Signal>;
|
|
7
|
+
//# sourceMappingURL=proof-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proof-utils.d.ts","sourceRoot":"","sources":["../../src/types/proof-utils.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GAAG,GAAG,MAAM,EAAE,GAAG,MAAM,CAAC;AAEjD,MAAM,MAAM,aAAa,GAAG,aAAa,EAAE,CAAC;AAE5C,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,GAAG,MAAM,EAAE,CAAC;AACvD,MAAM,MAAM,SAAS,GAAG,UAAU,EAAE,GAAG,SAAS,EAAE,CAAC;AAEnD,MAAM,MAAM,MAAM,GAAG,UAAU,GAAG,SAAS,CAAC;AAC5C,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proof-utils.js","sourceRoot":"","sources":["../../src/types/proof-utils.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { NumericString, PublicSignals } from "../proof-utils";
|
|
2
|
+
export interface Groth16Proof {
|
|
3
|
+
pi_a: [NumericString, NumericString];
|
|
4
|
+
pi_b: [[NumericString, NumericString], [NumericString, NumericString]];
|
|
5
|
+
pi_c: [NumericString, NumericString];
|
|
6
|
+
protocol: string;
|
|
7
|
+
curve: string;
|
|
8
|
+
}
|
|
9
|
+
export interface Groth16ProofStruct {
|
|
10
|
+
proof: Groth16Proof;
|
|
11
|
+
publicSignals: PublicSignals;
|
|
12
|
+
}
|
|
13
|
+
export type Groth16Calldata = [
|
|
14
|
+
[
|
|
15
|
+
NumericString,
|
|
16
|
+
NumericString
|
|
17
|
+
],
|
|
18
|
+
[
|
|
19
|
+
[NumericString, NumericString],
|
|
20
|
+
[NumericString, NumericString]
|
|
21
|
+
],
|
|
22
|
+
[
|
|
23
|
+
NumericString,
|
|
24
|
+
NumericString
|
|
25
|
+
],
|
|
26
|
+
PublicSignals
|
|
27
|
+
];
|
|
28
|
+
//# sourceMappingURL=groth16.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"groth16.d.ts","sourceRoot":"","sources":["../../../src/types/protocols/groth16.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE9D,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;IACrC,IAAI,EAAE,CAAC,CAAC,aAAa,EAAE,aAAa,CAAC,EAAE,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC,CAAC;IACvE,IAAI,EAAE,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;IACrC,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,YAAY,CAAC;IACpB,aAAa,EAAE,aAAa,CAAC;CAC9B;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B;QAAC,aAAa;QAAE,aAAa;KAAC;IAC9B;QAAC,CAAC,aAAa,EAAE,aAAa,CAAC;QAAE,CAAC,aAAa,EAAE,aAAa,CAAC;KAAC;IAChE;QAAC,aAAa;QAAE,aAAa;KAAC;IAC9B,aAAa;CACd,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"groth16.js","sourceRoot":"","sources":["../../../src/types/protocols/groth16.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Groth16ProofStruct, Groth16Calldata } from "./groth16";
|
|
2
|
+
import { PlonkProofStruct, PlonkCalldata } from "./plonk";
|
|
3
|
+
import { Signals } from "../proof-utils";
|
|
4
|
+
import { VerifierLanguageType } from "../circuit-zkit";
|
|
5
|
+
export * from "./groth16";
|
|
6
|
+
export * from "./plonk";
|
|
7
|
+
export interface IProtocolImplementer<T extends ProvingSystemType> {
|
|
8
|
+
createVerifier(circuitName: string, vKeyFilePath: string, verifierFilePath: string, languageExtension: VerifierLanguageType): Promise<void>;
|
|
9
|
+
generateProof(inputs: Signals, zKeyFilePath: string, wasmFilePath: string): Promise<ProofStructByProtocol<T>>;
|
|
10
|
+
verifyProof(proof: ProofStructByProtocol<T>, vKeyFilePath: string): Promise<boolean>;
|
|
11
|
+
generateCalldata(proof: ProofStructByProtocol<T>): Promise<CalldataByProtocol<T>>;
|
|
12
|
+
getProvingSystemType(): ProvingSystemType;
|
|
13
|
+
getTemplate(fileExtension: VerifierLanguageType): string;
|
|
14
|
+
getVerifierName(circuitName: string): string;
|
|
15
|
+
getZKeyFileName(circuitName: string): string;
|
|
16
|
+
getVKeyFileName(circuitName: string): string;
|
|
17
|
+
}
|
|
18
|
+
export interface ProvingSystemStructMap {
|
|
19
|
+
groth16: {
|
|
20
|
+
proofStruct: Groth16ProofStruct;
|
|
21
|
+
calldata: Groth16Calldata;
|
|
22
|
+
};
|
|
23
|
+
plonk: {
|
|
24
|
+
proofStruct: PlonkProofStruct;
|
|
25
|
+
calldata: PlonkCalldata;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export type ProvingSystemType = keyof ProvingSystemStructMap;
|
|
29
|
+
export type ProofStructByProtocol<T extends ProvingSystemType> = ProvingSystemStructMap[T]["proofStruct"];
|
|
30
|
+
export type CalldataByProtocol<T extends ProvingSystemType> = ProvingSystemStructMap[T]["calldata"];
|
|
31
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/protocols/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE1D,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAEvD,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AAExB,MAAM,WAAW,oBAAoB,CAAC,CAAC,SAAS,iBAAiB;IAC/D,cAAc,CACZ,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,EACpB,gBAAgB,EAAE,MAAM,EACxB,iBAAiB,EAAE,oBAAoB,GACtC,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjB,aAAa,CAAC,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,CAAC;IAE9G,WAAW,CAAC,KAAK,EAAE,qBAAqB,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAErF,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC;IAElF,oBAAoB,IAAI,iBAAiB,CAAC;IAE1C,WAAW,CAAC,aAAa,EAAE,oBAAoB,GAAG,MAAM,CAAC;IAEzD,eAAe,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAAC;IAE7C,eAAe,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAAC;IAE7C,eAAe,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAAC;CAC9C;AAED,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE;QACP,WAAW,EAAE,kBAAkB,CAAC;QAChC,QAAQ,EAAE,eAAe,CAAC;KAC3B,CAAC;IACF,KAAK,EAAE;QACL,WAAW,EAAE,gBAAgB,CAAC;QAC9B,QAAQ,EAAE,aAAa,CAAC;KACzB,CAAC;CACH;AAED,MAAM,MAAM,iBAAiB,GAAG,MAAM,sBAAsB,CAAC;AAE7D,MAAM,MAAM,qBAAqB,CAAC,CAAC,SAAS,iBAAiB,IAAI,sBAAsB,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC;AAC1G,MAAM,MAAM,kBAAkB,CAAC,CAAC,SAAS,iBAAiB,IAAI,sBAAsB,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./groth16"), exports);
|
|
18
|
+
__exportStar(require("./plonk"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/protocols/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAMA,4CAA0B;AAC1B,0CAAwB"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { NumericString, PublicSignals } from "../proof-utils";
|
|
2
|
+
export interface PlonkProof {
|
|
3
|
+
A: [NumericString, NumericString];
|
|
4
|
+
B: [NumericString, NumericString];
|
|
5
|
+
C: [NumericString, NumericString];
|
|
6
|
+
Z: [NumericString, NumericString];
|
|
7
|
+
T1: [NumericString, NumericString];
|
|
8
|
+
T2: [NumericString, NumericString];
|
|
9
|
+
T3: [NumericString, NumericString];
|
|
10
|
+
Wxi: [NumericString, NumericString];
|
|
11
|
+
Wxiw: [NumericString, NumericString];
|
|
12
|
+
eval_a: NumericString;
|
|
13
|
+
eval_b: NumericString;
|
|
14
|
+
eval_c: NumericString;
|
|
15
|
+
eval_s1: NumericString;
|
|
16
|
+
eval_s2: NumericString;
|
|
17
|
+
eval_zw: NumericString;
|
|
18
|
+
protocol: string;
|
|
19
|
+
curve: string;
|
|
20
|
+
}
|
|
21
|
+
export interface PlonkProofStruct {
|
|
22
|
+
proof: PlonkProof;
|
|
23
|
+
publicSignals: PublicSignals;
|
|
24
|
+
}
|
|
25
|
+
export type PlonkCalldata = [NumericString[], PublicSignals];
|
|
26
|
+
//# sourceMappingURL=plonk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plonk.d.ts","sourceRoot":"","sources":["../../../src/types/protocols/plonk.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE9D,MAAM,WAAW,UAAU;IACzB,CAAC,EAAE,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;IAClC,CAAC,EAAE,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;IAClC,CAAC,EAAE,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;IAClC,CAAC,EAAE,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;IAClC,EAAE,EAAE,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;IACnC,EAAE,EAAE,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;IACnC,EAAE,EAAE,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;IACnC,GAAG,EAAE,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;IACpC,IAAI,EAAE,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;IACrC,MAAM,EAAE,aAAa,CAAC;IACtB,MAAM,EAAE,aAAa,CAAC;IACtB,MAAM,EAAE,aAAa,CAAC;IACtB,OAAO,EAAE,aAAa,CAAC;IACvB,OAAO,EAAE,aAAa,CAAC;IACvB,OAAO,EAAE,aAAa,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,UAAU,CAAC;IAClB,aAAa,EAAE,aAAa,CAAC;CAC9B;AAED,MAAM,MAAM,aAAa,GAAG,CAAC,aAAa,EAAE,EAAE,aAAa,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plonk.js","sourceRoot":"","sources":["../../../src/types/protocols/plonk.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solarity/zkit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0-rc.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Distributed Lab",
|
|
6
6
|
"readme": "README.md",
|
|
@@ -43,18 +43,19 @@
|
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@nomicfoundation/hardhat-ethers": "3.0.5",
|
|
46
|
-
"@
|
|
47
|
-
"@types/snarkjs": "^0.7.8",
|
|
46
|
+
"@nomiclabs/hardhat-vyper": "^3.0.7",
|
|
48
47
|
"@types/chai": "^4.3.12",
|
|
49
48
|
"@types/chai-as-promised": "^7.1.8",
|
|
49
|
+
"@types/ejs": "^3.1.5",
|
|
50
50
|
"@types/mocha": "^10.0.6",
|
|
51
|
+
"@types/snarkjs": "^0.7.8",
|
|
51
52
|
"chai": "^4.4.1",
|
|
52
53
|
"chai-as-promised": "^7.1.1",
|
|
53
|
-
"mocha": "^10.3.0",
|
|
54
|
-
"nyc": "^15.1.0",
|
|
55
54
|
"ethers": "6.11.1",
|
|
56
|
-
"hardhat": "2.
|
|
55
|
+
"hardhat": "2.22.7",
|
|
57
56
|
"husky": "^9.0.11",
|
|
57
|
+
"mocha": "^10.3.0",
|
|
58
|
+
"nyc": "^15.1.0",
|
|
58
59
|
"prettier": "^3.2.5",
|
|
59
60
|
"ts-node": "^10.9.2",
|
|
60
61
|
"typescript": "^5.4.5"
|
package/src/core/CircuitZKit.ts
CHANGED
|
@@ -1,58 +1,32 @@
|
|
|
1
|
-
import ejs from "ejs";
|
|
2
1
|
import fs from "fs";
|
|
3
|
-
import * as os from "os";
|
|
4
2
|
import path from "path";
|
|
3
|
+
import * as os from "os";
|
|
5
4
|
import * as snarkjs from "snarkjs";
|
|
6
5
|
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
CircuitZKitConfig,
|
|
11
|
-
Signals,
|
|
12
|
-
ProofStruct,
|
|
13
|
-
VerifierTemplateType,
|
|
14
|
-
} from "../types/circuit-zkit";
|
|
6
|
+
import { ArtifactsFileType, CircuitZKitConfig, VerifierLanguageType } from "../types/circuit-zkit";
|
|
7
|
+
import { Signals } from "../types/proof-utils";
|
|
8
|
+
import { CalldataByProtocol, IProtocolImplementer, ProofStructByProtocol, ProvingSystemType } from "../types/protocols";
|
|
15
9
|
|
|
16
10
|
/**
|
|
17
11
|
* `CircuitZKit` represents a single circuit and provides a high-level API to work with it.
|
|
18
12
|
*/
|
|
19
|
-
export class CircuitZKit {
|
|
20
|
-
constructor(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
*
|
|
25
|
-
* @param {VerifierTemplateType} templateType - The template type.
|
|
26
|
-
* @returns {string} The Solidity verifier template.
|
|
27
|
-
*/
|
|
28
|
-
public static getTemplate(templateType: VerifierTemplateType): string {
|
|
29
|
-
switch (templateType) {
|
|
30
|
-
case "groth16":
|
|
31
|
-
return fs.readFileSync(path.join(__dirname, "templates", "verifier_groth16.sol.ejs"), "utf8");
|
|
32
|
-
default:
|
|
33
|
-
throw new Error(`Ambiguous template type: ${templateType}.`);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
13
|
+
export class CircuitZKit<Type extends ProvingSystemType> {
|
|
14
|
+
constructor(
|
|
15
|
+
private readonly _config: CircuitZKitConfig,
|
|
16
|
+
private readonly _implementer: IProtocolImplementer<Type>,
|
|
17
|
+
) {}
|
|
36
18
|
|
|
37
19
|
/**
|
|
38
|
-
* Creates a
|
|
20
|
+
* Creates a verifier contract for the specified contract language.
|
|
39
21
|
*/
|
|
40
|
-
public async createVerifier(): Promise<void> {
|
|
22
|
+
public async createVerifier(languageExtension: VerifierLanguageType): Promise<void> {
|
|
41
23
|
const vKeyFilePath: string = this.mustGetArtifactsFilePath("vkey");
|
|
42
|
-
const verifierFilePath = path.join(
|
|
43
|
-
|
|
44
|
-
|
|
24
|
+
const verifierFilePath = path.join(
|
|
25
|
+
this._config.verifierDirPath,
|
|
26
|
+
`${this._implementer.getVerifierName(this._config.circuitName)}.${languageExtension}`,
|
|
27
|
+
);
|
|
45
28
|
|
|
46
|
-
|
|
47
|
-
fs.mkdirSync(this._config.verifierDirPath, { recursive: true });
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const templateParams = JSON.parse(fs.readFileSync(vKeyFilePath, "utf-8"));
|
|
51
|
-
templateParams["verifier_id"] = this.getVerifierName();
|
|
52
|
-
|
|
53
|
-
const verifierCode = ejs.render(verifierTemplate, templateParams);
|
|
54
|
-
|
|
55
|
-
fs.writeFileSync(verifierFilePath, verifierCode, "utf-8");
|
|
29
|
+
this._implementer.createVerifier(this._config.circuitName, vKeyFilePath, verifierFilePath, languageExtension);
|
|
56
30
|
}
|
|
57
31
|
|
|
58
32
|
/**
|
|
@@ -82,14 +56,14 @@ export class CircuitZKit {
|
|
|
82
56
|
* @dev The `inputs` should be in the same order as the circuit expects them.
|
|
83
57
|
*
|
|
84
58
|
* @param {Signals} inputs - The inputs for the circuit.
|
|
85
|
-
* @returns {Promise<
|
|
59
|
+
* @returns {Promise<ProofStructByProtocol<Type>>} The generated proof.
|
|
86
60
|
* @todo Add support for other proving systems.
|
|
87
61
|
*/
|
|
88
|
-
public async generateProof(inputs: Signals): Promise<
|
|
62
|
+
public async generateProof(inputs: Signals): Promise<ProofStructByProtocol<Type>> {
|
|
89
63
|
const zKeyFile = this.mustGetArtifactsFilePath("zkey");
|
|
90
64
|
const wasmFile = this.mustGetArtifactsFilePath("wasm");
|
|
91
65
|
|
|
92
|
-
return
|
|
66
|
+
return await this._implementer.generateProof(inputs, zKeyFile, wasmFile);
|
|
93
67
|
}
|
|
94
68
|
|
|
95
69
|
/**
|
|
@@ -98,28 +72,24 @@ export class CircuitZKit {
|
|
|
98
72
|
* @dev The `proof` can be generated using the `generateProof` method.
|
|
99
73
|
* @dev The `proof.publicSignals` should be in the same order as the circuit expects them.
|
|
100
74
|
*
|
|
101
|
-
* @param {
|
|
75
|
+
* @param {ProofStructByProtocol<Type>} proof - The proof to verify.
|
|
102
76
|
* @returns {Promise<boolean>} Whether the proof is valid.
|
|
103
77
|
*/
|
|
104
|
-
public async verifyProof(proof:
|
|
78
|
+
public async verifyProof(proof: ProofStructByProtocol<Type>): Promise<boolean> {
|
|
105
79
|
const vKeyFile = this.mustGetArtifactsFilePath("vkey");
|
|
106
80
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
return await snarkjs.groth16.verify(verifier, proof.publicSignals, proof.proof);
|
|
81
|
+
return this._implementer.verifyProof(proof, vKeyFile);
|
|
110
82
|
}
|
|
111
83
|
|
|
112
84
|
/**
|
|
113
85
|
* Generates the calldata for the given proof. The calldata can be used to verify the proof on-chain.
|
|
114
86
|
*
|
|
115
|
-
* @param {
|
|
116
|
-
* @returns {Promise<
|
|
87
|
+
* @param {ProofStructByProtocol<Type>} proof - The proof to generate calldata for.
|
|
88
|
+
* @returns {Promise<CalldataByProtocol<Type>>} - The generated calldata.
|
|
117
89
|
* @todo Add other types of calldata.
|
|
118
90
|
*/
|
|
119
|
-
public async generateCalldata(proof:
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
return JSON.parse(`[${calldata}]`) as Calldata;
|
|
91
|
+
public async generateCalldata(proof: ProofStructByProtocol<Type>): Promise<CalldataByProtocol<Type>> {
|
|
92
|
+
return await this._implementer.generateCalldata(proof);
|
|
123
93
|
}
|
|
124
94
|
|
|
125
95
|
/**
|
|
@@ -137,16 +107,25 @@ export class CircuitZKit {
|
|
|
137
107
|
* @returns {string} The verifier name.
|
|
138
108
|
*/
|
|
139
109
|
public getVerifierName(): string {
|
|
140
|
-
return
|
|
110
|
+
return this._implementer.getVerifierName(this._config.circuitName);
|
|
141
111
|
}
|
|
142
112
|
|
|
143
113
|
/**
|
|
144
|
-
* Returns the type of
|
|
114
|
+
* Returns the type of the proving protocol
|
|
145
115
|
*
|
|
146
|
-
* @returns {
|
|
116
|
+
* @returns {ProvingSystemType} The protocol proving system type.
|
|
117
|
+
*/
|
|
118
|
+
public getProvingSystemType(): ProvingSystemType {
|
|
119
|
+
return this._implementer.getProvingSystemType();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Returns the Solidity verifier template.
|
|
124
|
+
*
|
|
125
|
+
* @returns {string} The Solidity verifier template.
|
|
147
126
|
*/
|
|
148
|
-
public
|
|
149
|
-
return this.
|
|
127
|
+
public getVerifierTemplate(languageExtension: VerifierLanguageType): string {
|
|
128
|
+
return this._implementer.getTemplate(languageExtension);
|
|
150
129
|
}
|
|
151
130
|
|
|
152
131
|
/**
|
|
@@ -182,10 +161,10 @@ export class CircuitZKit {
|
|
|
182
161
|
fileName = `${circuitName}.r1cs`;
|
|
183
162
|
break;
|
|
184
163
|
case "zkey":
|
|
185
|
-
fileName = `${circuitName}
|
|
164
|
+
fileName = `${this._implementer.getZKeyFileName(circuitName)}`;
|
|
186
165
|
break;
|
|
187
166
|
case "vkey":
|
|
188
|
-
fileName = `${circuitName}
|
|
167
|
+
fileName = `${this._implementer.getVKeyFileName(circuitName)}`;
|
|
189
168
|
break;
|
|
190
169
|
case "sym":
|
|
191
170
|
fileName = `${circuitName}.sym`;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import ejs from "ejs";
|
|
3
|
+
import path from "path";
|
|
4
|
+
|
|
5
|
+
import { Signals } from "../../types/proof-utils";
|
|
6
|
+
import {
|
|
7
|
+
IProtocolImplementer,
|
|
8
|
+
ProvingSystemType,
|
|
9
|
+
ProofStructByProtocol,
|
|
10
|
+
CalldataByProtocol,
|
|
11
|
+
} from "../../types/protocols";
|
|
12
|
+
import { VerifierLanguageType } from "../../types/circuit-zkit";
|
|
13
|
+
|
|
14
|
+
export abstract class AbstractProtocolImplementer<T extends ProvingSystemType> implements IProtocolImplementer<T> {
|
|
15
|
+
public async createVerifier(
|
|
16
|
+
circuitName: string,
|
|
17
|
+
vKeyFilePath: string,
|
|
18
|
+
verifierFilePath: string,
|
|
19
|
+
languageExtension: VerifierLanguageType,
|
|
20
|
+
): Promise<void> {
|
|
21
|
+
const verifierTemplate: string = this.getTemplate(languageExtension);
|
|
22
|
+
|
|
23
|
+
if (!fs.existsSync(path.dirname(verifierFilePath))) {
|
|
24
|
+
fs.mkdirSync(path.dirname(verifierFilePath), { recursive: true });
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const templateParams = JSON.parse(fs.readFileSync(vKeyFilePath, "utf-8"));
|
|
28
|
+
templateParams["verifier_id"] = this.getVerifierName(circuitName);
|
|
29
|
+
|
|
30
|
+
const verifierCode = ejs.render(verifierTemplate, templateParams);
|
|
31
|
+
|
|
32
|
+
fs.writeFileSync(verifierFilePath, verifierCode, "utf-8");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public abstract generateProof(
|
|
36
|
+
inputs: Signals,
|
|
37
|
+
zKeyFilePath: string,
|
|
38
|
+
wasmFilePath: string,
|
|
39
|
+
): Promise<ProofStructByProtocol<T>>;
|
|
40
|
+
|
|
41
|
+
public abstract verifyProof(proof: ProofStructByProtocol<T>, vKeyFilePath: string): Promise<boolean>;
|
|
42
|
+
|
|
43
|
+
public abstract generateCalldata(proof: ProofStructByProtocol<T>): Promise<CalldataByProtocol<T>>;
|
|
44
|
+
|
|
45
|
+
public abstract getProvingSystemType(): ProvingSystemType;
|
|
46
|
+
|
|
47
|
+
public getTemplate(languageExtension: VerifierLanguageType): string {
|
|
48
|
+
return fs.readFileSync(
|
|
49
|
+
path.join(__dirname, "..", "templates", `verifier_${this.getProvingSystemType()}.${languageExtension}.ejs`),
|
|
50
|
+
"utf8",
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public getVerifierName(circuitName: string): string {
|
|
55
|
+
const protocolType: ProvingSystemType = this.getProvingSystemType();
|
|
56
|
+
|
|
57
|
+
return `${circuitName}${protocolType.charAt(0).toUpperCase() + protocolType.slice(1)}Verifier`;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public getZKeyFileName(circuitName: string): string {
|
|
61
|
+
return `${circuitName}.${this.getProvingSystemType()}.zkey`;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public getVKeyFileName(circuitName: string): string {
|
|
65
|
+
return `${circuitName}.${this.getProvingSystemType()}.vkey.json`;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import * as snarkjs from "snarkjs";
|
|
3
|
+
|
|
4
|
+
import { AbstractProtocolImplementer } from "./AbstractImplementer";
|
|
5
|
+
|
|
6
|
+
import { Signals } from "../../types/proof-utils";
|
|
7
|
+
import { Groth16ProofStruct, ProvingSystemType, Groth16Calldata } from "../../types/protocols";
|
|
8
|
+
|
|
9
|
+
export class Groth16Implementer extends AbstractProtocolImplementer<"groth16"> {
|
|
10
|
+
public async generateProof(inputs: Signals, zKeyFilePath: string, wasmFilePath: string): Promise<Groth16ProofStruct> {
|
|
11
|
+
return (await snarkjs.groth16.fullProve(inputs, wasmFilePath, zKeyFilePath)) as Groth16ProofStruct;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
public async verifyProof(proof: Groth16ProofStruct, vKeyFilePath: string): Promise<boolean> {
|
|
15
|
+
const verifier = JSON.parse(fs.readFileSync(vKeyFilePath).toString());
|
|
16
|
+
|
|
17
|
+
return await snarkjs.groth16.verify(verifier, proof.publicSignals, proof.proof);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public async generateCalldata(proof: Groth16ProofStruct): Promise<Groth16Calldata> {
|
|
21
|
+
const calldata = await snarkjs.groth16.exportSolidityCallData(proof.proof, proof.publicSignals);
|
|
22
|
+
|
|
23
|
+
return JSON.parse(`[${calldata}]`) as Groth16Calldata;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public getProvingSystemType(): ProvingSystemType {
|
|
27
|
+
return "groth16";
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import * as snarkjs from "snarkjs";
|
|
3
|
+
|
|
4
|
+
import { AbstractProtocolImplementer } from "./AbstractImplementer";
|
|
5
|
+
|
|
6
|
+
import { Signals } from "../../types/proof-utils";
|
|
7
|
+
import { PlonkCalldata, PlonkProofStruct, ProvingSystemType } from "../../types/protocols";
|
|
8
|
+
|
|
9
|
+
export class PlonkImplementer extends AbstractProtocolImplementer<"plonk"> {
|
|
10
|
+
public async generateProof(inputs: Signals, zKeyFilePath: string, wasmFilePath: string): Promise<PlonkProofStruct> {
|
|
11
|
+
return (await snarkjs.plonk.fullProve(inputs, wasmFilePath, zKeyFilePath)) as PlonkProofStruct;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
public async verifyProof(proof: PlonkProofStruct, vKeyFilePath: string): Promise<boolean> {
|
|
15
|
+
const verifier = JSON.parse(fs.readFileSync(vKeyFilePath).toString());
|
|
16
|
+
|
|
17
|
+
return await snarkjs.plonk.verify(verifier, proof.publicSignals, proof.proof);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public async generateCalldata(proof: PlonkProofStruct): Promise<PlonkCalldata> {
|
|
21
|
+
const calldata = await snarkjs.plonk.exportSolidityCallData(proof.proof, proof.publicSignals);
|
|
22
|
+
const proofArrEndIndex: number = calldata.indexOf("]") + 1;
|
|
23
|
+
|
|
24
|
+
return JSON.parse(
|
|
25
|
+
`[${calldata.slice(0, proofArrEndIndex)},${calldata.slice(proofArrEndIndex, calldata.length)}]`,
|
|
26
|
+
) as PlonkCalldata;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public getProvingSystemType(): ProvingSystemType {
|
|
30
|
+
return "plonk";
|
|
31
|
+
}
|
|
32
|
+
}
|