@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,42 +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 VerifierProvingSystem = "groth16";
|
|
35
2
|
export type VerifierLanguageType = "sol" | "vy";
|
|
36
3
|
export type CircuitZKitConfig = {
|
|
37
4
|
circuitName: string;
|
|
38
5
|
circuitArtifactsPath: string;
|
|
39
6
|
verifierDirPath: string;
|
|
40
|
-
provingSystem?: VerifierProvingSystem;
|
|
41
7
|
};
|
|
42
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
package/src/core/CircuitZKit.ts
CHANGED
|
@@ -1,60 +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
|
-
VerifierProvingSystem,
|
|
14
|
-
VerifierLanguageType,
|
|
15
|
-
} 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";
|
|
16
9
|
|
|
17
10
|
/**
|
|
18
11
|
* `CircuitZKit` represents a single circuit and provides a high-level API to work with it.
|
|
19
12
|
*/
|
|
20
|
-
export class CircuitZKit {
|
|
21
|
-
constructor(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
*
|
|
26
|
-
* @param {VerifierProvingSystem} provingSystem - The template proving system.
|
|
27
|
-
* @param {VerifierLanguageType} fileExtension - The file extension.
|
|
28
|
-
* @returns {string} The verifier template.
|
|
29
|
-
*/
|
|
30
|
-
public static getTemplate(provingSystem: VerifierProvingSystem, fileExtension: VerifierLanguageType): string {
|
|
31
|
-
switch (provingSystem) {
|
|
32
|
-
case "groth16":
|
|
33
|
-
return fs.readFileSync(path.join(__dirname, "templates", `verifier_groth16.${fileExtension}.ejs`), "utf8");
|
|
34
|
-
default:
|
|
35
|
-
throw new Error(`Ambiguous proving system: ${provingSystem}.`);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
13
|
+
export class CircuitZKit<Type extends ProvingSystemType> {
|
|
14
|
+
constructor(
|
|
15
|
+
private readonly _config: CircuitZKitConfig,
|
|
16
|
+
private readonly _implementer: IProtocolImplementer<Type>,
|
|
17
|
+
) {}
|
|
38
18
|
|
|
39
19
|
/**
|
|
40
20
|
* Creates a verifier contract for the specified contract language.
|
|
41
21
|
*/
|
|
42
22
|
public async createVerifier(languageExtension: VerifierLanguageType): Promise<void> {
|
|
43
23
|
const vKeyFilePath: string = this.mustGetArtifactsFilePath("vkey");
|
|
44
|
-
const verifierFilePath = path.join(
|
|
24
|
+
const verifierFilePath = path.join(
|
|
25
|
+
this._config.verifierDirPath,
|
|
26
|
+
`${this._implementer.getVerifierName(this._config.circuitName)}.${languageExtension}`,
|
|
27
|
+
);
|
|
45
28
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if (!fs.existsSync(this._config.verifierDirPath)) {
|
|
49
|
-
fs.mkdirSync(this._config.verifierDirPath, { recursive: true });
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const templateParams = JSON.parse(fs.readFileSync(vKeyFilePath, "utf-8"));
|
|
53
|
-
templateParams["verifier_id"] = this.getVerifierName();
|
|
54
|
-
|
|
55
|
-
const verifierCode = ejs.render(verifierTemplate, templateParams);
|
|
56
|
-
|
|
57
|
-
fs.writeFileSync(verifierFilePath, verifierCode, "utf-8");
|
|
29
|
+
this._implementer.createVerifier(this._config.circuitName, vKeyFilePath, verifierFilePath, languageExtension);
|
|
58
30
|
}
|
|
59
31
|
|
|
60
32
|
/**
|
|
@@ -84,14 +56,14 @@ export class CircuitZKit {
|
|
|
84
56
|
* @dev The `inputs` should be in the same order as the circuit expects them.
|
|
85
57
|
*
|
|
86
58
|
* @param {Signals} inputs - The inputs for the circuit.
|
|
87
|
-
* @returns {Promise<
|
|
59
|
+
* @returns {Promise<ProofStructByProtocol<Type>>} The generated proof.
|
|
88
60
|
* @todo Add support for other proving systems.
|
|
89
61
|
*/
|
|
90
|
-
public async generateProof(inputs: Signals): Promise<
|
|
62
|
+
public async generateProof(inputs: Signals): Promise<ProofStructByProtocol<Type>> {
|
|
91
63
|
const zKeyFile = this.mustGetArtifactsFilePath("zkey");
|
|
92
64
|
const wasmFile = this.mustGetArtifactsFilePath("wasm");
|
|
93
65
|
|
|
94
|
-
return
|
|
66
|
+
return await this._implementer.generateProof(inputs, zKeyFile, wasmFile);
|
|
95
67
|
}
|
|
96
68
|
|
|
97
69
|
/**
|
|
@@ -100,28 +72,24 @@ export class CircuitZKit {
|
|
|
100
72
|
* @dev The `proof` can be generated using the `generateProof` method.
|
|
101
73
|
* @dev The `proof.publicSignals` should be in the same order as the circuit expects them.
|
|
102
74
|
*
|
|
103
|
-
* @param {
|
|
75
|
+
* @param {ProofStructByProtocol<Type>} proof - The proof to verify.
|
|
104
76
|
* @returns {Promise<boolean>} Whether the proof is valid.
|
|
105
77
|
*/
|
|
106
|
-
public async verifyProof(proof:
|
|
78
|
+
public async verifyProof(proof: ProofStructByProtocol<Type>): Promise<boolean> {
|
|
107
79
|
const vKeyFile = this.mustGetArtifactsFilePath("vkey");
|
|
108
80
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
return await snarkjs.groth16.verify(verifier, proof.publicSignals, proof.proof);
|
|
81
|
+
return this._implementer.verifyProof(proof, vKeyFile);
|
|
112
82
|
}
|
|
113
83
|
|
|
114
84
|
/**
|
|
115
85
|
* Generates the calldata for the given proof. The calldata can be used to verify the proof on-chain.
|
|
116
86
|
*
|
|
117
|
-
* @param {
|
|
118
|
-
* @returns {Promise<
|
|
87
|
+
* @param {ProofStructByProtocol<Type>} proof - The proof to generate calldata for.
|
|
88
|
+
* @returns {Promise<CalldataByProtocol<Type>>} - The generated calldata.
|
|
119
89
|
* @todo Add other types of calldata.
|
|
120
90
|
*/
|
|
121
|
-
public async generateCalldata(proof:
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
return JSON.parse(`[${calldata}]`) as Calldata;
|
|
91
|
+
public async generateCalldata(proof: ProofStructByProtocol<Type>): Promise<CalldataByProtocol<Type>> {
|
|
92
|
+
return await this._implementer.generateCalldata(proof);
|
|
125
93
|
}
|
|
126
94
|
|
|
127
95
|
/**
|
|
@@ -139,16 +107,25 @@ export class CircuitZKit {
|
|
|
139
107
|
* @returns {string} The verifier name.
|
|
140
108
|
*/
|
|
141
109
|
public getVerifierName(): string {
|
|
142
|
-
return
|
|
110
|
+
return this._implementer.getVerifierName(this._config.circuitName);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Returns the type of the proving protocol
|
|
115
|
+
*
|
|
116
|
+
* @returns {ProvingSystemType} The protocol proving system type.
|
|
117
|
+
*/
|
|
118
|
+
public getProvingSystemType(): ProvingSystemType {
|
|
119
|
+
return this._implementer.getProvingSystemType();
|
|
143
120
|
}
|
|
144
121
|
|
|
145
122
|
/**
|
|
146
|
-
* Returns the
|
|
123
|
+
* Returns the Solidity verifier template.
|
|
147
124
|
*
|
|
148
|
-
* @returns {
|
|
125
|
+
* @returns {string} The Solidity verifier template.
|
|
149
126
|
*/
|
|
150
|
-
public
|
|
151
|
-
return this.
|
|
127
|
+
public getVerifierTemplate(languageExtension: VerifierLanguageType): string {
|
|
128
|
+
return this._implementer.getTemplate(languageExtension);
|
|
152
129
|
}
|
|
153
130
|
|
|
154
131
|
/**
|
|
@@ -184,10 +161,10 @@ export class CircuitZKit {
|
|
|
184
161
|
fileName = `${circuitName}.r1cs`;
|
|
185
162
|
break;
|
|
186
163
|
case "zkey":
|
|
187
|
-
fileName = `${circuitName}
|
|
164
|
+
fileName = `${this._implementer.getZKeyFileName(circuitName)}`;
|
|
188
165
|
break;
|
|
189
166
|
case "vkey":
|
|
190
|
-
fileName = `${circuitName}
|
|
167
|
+
fileName = `${this._implementer.getVKeyFileName(circuitName)}`;
|
|
191
168
|
break;
|
|
192
169
|
case "sym":
|
|
193
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
|
+
}
|
|
@@ -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
|
|