@solarity/zkit 0.3.7-rc.1 → 0.3.7
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 -3
- package/dist/core/CircuitZKit.d.ts +1 -3
- package/dist/core/CircuitZKit.d.ts.map +1 -1
- package/dist/core/CircuitZKit.js.map +1 -1
- package/dist/core/protocols/AbstractImplementer.d.ts +1 -2
- package/dist/core/protocols/AbstractImplementer.d.ts.map +1 -1
- package/dist/core/protocols/Groth16Implementer.d.ts +1 -1
- package/dist/core/protocols/Groth16Implementer.d.ts.map +1 -1
- package/dist/core/protocols/PlonkImplementer.d.ts +1 -1
- package/dist/core/protocols/PlonkImplementer.d.ts.map +1 -1
- package/dist/core/templates/verifier_groth16.sol.ejs +34 -46
- package/dist/index.d.ts +2 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -3
- package/dist/index.js.map +1 -1
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +21 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/witness-utils.d.ts +8 -0
- package/dist/types/witness-utils.d.ts.map +1 -0
- package/dist/types/witness-utils.js +3 -0
- package/dist/types/witness-utils.js.map +1 -0
- package/dist/utils/index.d.ts +1 -12
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -52
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/protocol-utils.d.ts +13 -0
- package/dist/utils/protocol-utils.d.ts.map +1 -0
- package/dist/utils/protocol-utils.js +66 -0
- package/dist/utils/protocol-utils.js.map +1 -0
- package/dist/utils/witness-utils.d.ts +15 -5
- package/dist/utils/witness-utils.d.ts.map +1 -1
- package/dist/utils/witness-utils.js +34 -13
- package/dist/utils/witness-utils.js.map +1 -1
- package/package.json +5 -5
- package/src/core/CircuitZKit.ts +12 -4
- package/src/core/protocols/AbstractImplementer.ts +2 -2
- package/src/core/protocols/Groth16Implementer.ts +1 -1
- package/src/core/protocols/PlonkImplementer.ts +1 -1
- package/src/core/templates/verifier_groth16.sol.ejs +34 -46
- package/src/index.ts +2 -3
- package/src/types/index.ts +4 -0
- package/src/types/witness-utils.ts +8 -0
- package/src/utils/index.ts +1 -32
- package/src/utils/protocol-utils.ts +31 -0
- package/src/utils/witness-utils.ts +42 -19
package/README.md
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
- Leverage `groth16` and `plonk` proving systems.
|
|
10
10
|
- Render optimized Solidity | Vyper verifiers.
|
|
11
11
|
- Build and work with ZK witnesses.
|
|
12
|
+
- Substitute witness signals for advanced circuits testing.
|
|
12
13
|
|
|
13
14
|
## Installation
|
|
14
15
|
|
|
@@ -62,18 +63,22 @@ await circuit.createVerifier("sol");
|
|
|
62
63
|
await circuit.createVerifier("sol", "_suffix_");
|
|
63
64
|
```
|
|
64
65
|
|
|
65
|
-
- **`async calculateWitness(inputs) -> bigint[]`**
|
|
66
|
+
- **`async calculateWitness(inputs, witnessOverrides?) -> bigint[]`**
|
|
66
67
|
|
|
67
68
|
Calculates a witness in the `tmp` directory and returns its json representation.
|
|
69
|
+
An optional `witnessOverrides` parameter can be provided to replace specific signal values in the generated witness file.
|
|
68
70
|
|
|
69
71
|
```typescript
|
|
70
72
|
/// witness = [1n, 200n, 20n, 10n]
|
|
71
73
|
const witness = await circuit.calculateWitness({ a: 10, b: 20 });
|
|
74
|
+
|
|
75
|
+
/// witness = [1n, 200n, 35n, 10n]
|
|
76
|
+
const witness = await circuit.calculateWitness({ a: 10, b: 20 }, { "main.a": 35 });
|
|
72
77
|
```
|
|
73
78
|
|
|
74
|
-
- **`async generateProof(inputs) -> proof`**
|
|
79
|
+
- **`async generateProof(inputs, witnessOverrides?) -> proof`**
|
|
75
80
|
|
|
76
|
-
Generates a proof for the given inputs
|
|
81
|
+
Generates a proof for the given `inputs` and `witnessOverrides`.
|
|
77
82
|
|
|
78
83
|
```typescript
|
|
79
84
|
/// { proof: { pi_a, pi_b, pi_c, protocol, curve }, publicSignals: [6] }
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { ArtifactsFileType, CircuitZKitConfig, VerifierLanguageType } from "../types
|
|
2
|
-
import { Signals } from "../types/proof-utils";
|
|
3
|
-
import { CalldataByProtocol, IProtocolImplementer, ProofStructByProtocol, ProvingSystemType } from "../types/protocols";
|
|
1
|
+
import { ArtifactsFileType, CircuitZKitConfig, VerifierLanguageType, Signals, CalldataByProtocol, IProtocolImplementer, ProofStructByProtocol, ProvingSystemType } from "../types";
|
|
4
2
|
/**
|
|
5
3
|
* `CircuitZKit` represents a single circuit and provides a high-level API to work with it.
|
|
6
4
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CircuitZKit.d.ts","sourceRoot":"","sources":["../../src/core/CircuitZKit.ts"],"names":[],"mappings":"AAKA,OAAO,
|
|
1
|
+
{"version":3,"file":"CircuitZKit.d.ts","sourceRoot":"","sources":["../../src/core/CircuitZKit.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,oBAAoB,EACpB,OAAO,EACP,kBAAkB,EAClB,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,EAElB,MAAM,UAAU,CAAC;AAKlB;;GAEG;AACH,qBAAa,WAAW,CAAC,IAAI,SAAS,iBAAiB;IAEnD,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,YAAY;gBADZ,OAAO,EAAE,iBAAiB,EAC1B,YAAY,EAAE,oBAAoB,CAAC,IAAI,CAAC;IAG3D;;;;;;;;;;;OAWG;IACU,cAAc,CAAC,iBAAiB,EAAE,oBAAoB,EAAE,kBAAkB,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAsBhH;;;;;;;;;;;OAWG;IACU,gBAAgB,CAAC,MAAM,EAAE,OAAO,EAAE,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAmB5G;;;;;;;;;;;;;;OAcG;IACU,aAAa,CACxB,MAAM,EAAE,OAAO,EACf,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACxC,OAAO,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAC;IAuBvC;;;;;;;;OAQG;IACU,WAAW,CAAC,KAAK,EAAE,qBAAqB,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;IAM9E;;;;;OAKG;IACU,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;IAIpG;;;;OAIG;IACI,cAAc,IAAI,MAAM;IAI/B;;;;;;;OAOG;IACI,eAAe,CAAC,kBAAkB,CAAC,EAAE,MAAM,GAAG,MAAM;IAI3D;;;;OAIG;IACI,oBAAoB,IAAI,iBAAiB;IAIhD;;;;OAIG;IACI,mBAAmB,CAAC,iBAAiB,EAAE,oBAAoB,GAAG,MAAM;IAI3E;;;;;;;OAOG;IACI,uBAAuB,IAAI,MAAM;IAIxC;;;;;OAKG;IACI,wBAAwB,CAAC,QAAQ,EAAE,iBAAiB,GAAG,MAAM;IAUpE;;;;;OAKG;IACI,oBAAoB,CAAC,QAAQ,EAAE,iBAAiB,GAAG,MAAM;CAgCjE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CircuitZKit.js","sourceRoot":"","sources":["../../src/core/CircuitZKit.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AACxB,iDAAmC;AACnC,mCAAoC;
|
|
1
|
+
{"version":3,"file":"CircuitZKit.js","sourceRoot":"","sources":["../../src/core/CircuitZKit.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,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IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACtC,CAAC;CACF;AAlPD,kCAkPC"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { IProtocolImplementer, ProvingSystemType, ProofStructByProtocol, CalldataByProtocol } from "../../types
|
|
2
|
-
import { VerifierLanguageType } from "../../types/circuit-zkit";
|
|
1
|
+
import { IProtocolImplementer, ProvingSystemType, ProofStructByProtocol, CalldataByProtocol, VerifierLanguageType } from "../../types";
|
|
3
2
|
export declare abstract class AbstractProtocolImplementer<T extends ProvingSystemType> implements IProtocolImplementer<T> {
|
|
4
3
|
createVerifier(vKeyFilePath: string, verifierFilePath: string, languageExtension: VerifierLanguageType): Promise<void>;
|
|
5
4
|
abstract generateProof(zKeyFilePath: string, witnessFilePath: string): Promise<ProofStructByProtocol<T>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AbstractImplementer.d.ts","sourceRoot":"","sources":["../../../src/core/protocols/AbstractImplementer.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,qBAAqB,EACrB,kBAAkB,
|
|
1
|
+
{"version":3,"file":"AbstractImplementer.d.ts","sourceRoot":"","sources":["../../../src/core/protocols/AbstractImplementer.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,qBAAqB,EACrB,kBAAkB,EAClB,oBAAoB,EACrB,MAAM,aAAa,CAAC;AAErB,8BAAsB,2BAA2B,CAAC,CAAC,SAAS,iBAAiB,CAAE,YAAW,oBAAoB,CAAC,CAAC,CAAC;IAClG,cAAc,CACzB,YAAY,EAAE,MAAM,EACpB,gBAAgB,EAAE,MAAM,EACxB,iBAAiB,EAAE,oBAAoB,GACtC,OAAO,CAAC,IAAI,CAAC;aAeA,aAAa,CAAC,YAAY,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;aAE/F,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,EAAE,kBAAkB,CAAC,EAAE,MAAM,GAAG,MAAM;IAOzE,eAAe,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM;IAI5C,eAAe,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM;CAGpD"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AbstractProtocolImplementer } from "./AbstractImplementer";
|
|
2
|
-
import { Groth16ProofStruct, Groth16CalldataStruct, ProvingSystemType } from "../../types
|
|
2
|
+
import { Groth16ProofStruct, Groth16CalldataStruct, ProvingSystemType } from "../../types";
|
|
3
3
|
export declare class Groth16Implementer extends AbstractProtocolImplementer<"groth16"> {
|
|
4
4
|
generateProof(zKeyFilePath: string, witnessFilePath: string): Promise<Groth16ProofStruct>;
|
|
5
5
|
verifyProof(proof: Groth16ProofStruct, vKeyFilePath: string): Promise<boolean>;
|
|
@@ -1 +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,kBAAkB,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,
|
|
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,kBAAkB,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAI3F,qBAAa,kBAAmB,SAAQ,2BAA2B,CAAC,SAAS,CAAC;IAC/D,aAAa,CAAC,YAAY,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAQzF,WAAW,CAAC,KAAK,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAU9E,gBAAgB,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAejF,oBAAoB,IAAI,iBAAiB;CAGjD"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AbstractProtocolImplementer } from "./AbstractImplementer";
|
|
2
|
-
import { PlonkProofStruct, PlonkCalldataStruct, ProvingSystemType } from "../../types
|
|
2
|
+
import { PlonkProofStruct, PlonkCalldataStruct, ProvingSystemType } from "../../types";
|
|
3
3
|
export declare class PlonkImplementer extends AbstractProtocolImplementer<"plonk"> {
|
|
4
4
|
generateProof(zKeyFilePath: string, witnessFilePath: string): Promise<PlonkProofStruct>;
|
|
5
5
|
verifyProof(proof: PlonkProofStruct, vKeyFilePath: string): Promise<boolean>;
|
|
@@ -1 +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,gBAAgB,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,
|
|
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,gBAAgB,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAIvF,qBAAa,gBAAiB,SAAQ,2BAA2B,CAAC,OAAO,CAAC;IAC3D,aAAa,CAAC,YAAY,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAQvF,WAAW,CAAC,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAU5E,gBAAgB,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAgB7E,oBAAoB,IAAI,iBAAiB;CAGjD"}
|
|
@@ -48,9 +48,8 @@ contract <%=verifier_id%> {
|
|
|
48
48
|
<%=IC[i][1]%>;
|
|
49
49
|
<% } -%>
|
|
50
50
|
|
|
51
|
-
/// @dev memory pointer
|
|
52
|
-
|
|
53
|
-
uint16 public constant P_TOTAL_SIZE = 896;
|
|
51
|
+
/// @dev memory pointer size
|
|
52
|
+
uint256 public constant P_TOTAL_SIZE = 768;
|
|
54
53
|
|
|
55
54
|
function verifyProof(
|
|
56
55
|
uint256[2] memory pointA_,
|
|
@@ -63,30 +62,23 @@ contract <%=verifier_id%> {
|
|
|
63
62
|
res_ := lt(signal_, SCALAR_FIELD_SIZE)
|
|
64
63
|
}
|
|
65
64
|
|
|
66
|
-
function g1MulAdd(
|
|
67
|
-
|
|
65
|
+
function g1MulAdd(pointer_, x_, y_, s_) -> res_ {
|
|
66
|
+
mstore(add(pointer_, 64), x_)
|
|
67
|
+
mstore(add(pointer_, 96), y_)
|
|
68
|
+
mstore(add(pointer_, 128), s_)
|
|
68
69
|
|
|
69
|
-
|
|
70
|
-
mstore(add(pointer_, 32), y_)
|
|
71
|
-
mstore(add(pointer_, 64), s_)
|
|
72
|
-
|
|
73
|
-
res_ := staticcall(6000, 7, pointer_, 96, pointer_, 64) // ecMul
|
|
70
|
+
res_ := staticcall(6000, 7, add(pointer_, 64), 96, add(pointer_, 64), 64) // ecMul
|
|
74
71
|
res_ := and(res_, gt(returndatasize(), 0)) // check that multiplication succeeded
|
|
75
72
|
|
|
76
73
|
if iszero(res_) {
|
|
77
74
|
leave
|
|
78
75
|
}
|
|
79
76
|
|
|
80
|
-
|
|
81
|
-
mstore(add(pointer_, 96), mload(add(pR_, 32)))
|
|
82
|
-
|
|
83
|
-
res_ := staticcall(150, 6, pointer_, 128, pR_, 64) // ecAdd
|
|
77
|
+
res_ := staticcall(150, 6, pointer_, 128, pointer_, 64) // ecAdd
|
|
84
78
|
res_ := and(res_, gt(returndatasize(), 0)) // check that addition succeeded
|
|
85
79
|
}
|
|
86
80
|
|
|
87
81
|
function checkPairing(pA_, pB_, pC_, pubSignals_, pointer_) -> res_ {
|
|
88
|
-
let pPairing_ := add(pointer_, P_PUBLIC_SIGNALS_ACCUMULATOR_SIZE)
|
|
89
|
-
|
|
90
82
|
mstore(pointer_, IC0_X)
|
|
91
83
|
mstore(add(pointer_, 32), IC0_Y)
|
|
92
84
|
|
|
@@ -96,51 +88,47 @@ contract <%=verifier_id%> {
|
|
|
96
88
|
}
|
|
97
89
|
<% } -%>
|
|
98
90
|
|
|
91
|
+
/// @dev gamma2
|
|
92
|
+
mstore(add(pointer_, 64), GAMMA_X1)
|
|
93
|
+
mstore(add(pointer_, 96), GAMMA_X2)
|
|
94
|
+
mstore(add(pointer_, 128), GAMMA_Y1)
|
|
95
|
+
mstore(add(pointer_, 160), GAMMA_Y2)
|
|
96
|
+
|
|
99
97
|
/// @dev -A
|
|
100
|
-
mstore(
|
|
98
|
+
mstore(add(pointer_, 192), mload(pA_))
|
|
101
99
|
mstore(
|
|
102
|
-
add(
|
|
100
|
+
add(pointer_, 224),
|
|
103
101
|
mod(sub(BASE_FIELD_SIZE, mload(add(pA_, 32))), BASE_FIELD_SIZE)
|
|
104
102
|
)
|
|
105
103
|
|
|
106
104
|
/// @dev B
|
|
107
|
-
mstore(add(
|
|
108
|
-
mstore(add(
|
|
109
|
-
mstore(add(
|
|
110
|
-
mstore(add(
|
|
105
|
+
mstore(add(pointer_, 256), mload(mload(pB_)))
|
|
106
|
+
mstore(add(pointer_, 288), mload(add(mload(pB_), 32)))
|
|
107
|
+
mstore(add(pointer_, 320), mload(mload(add(pB_, 32))))
|
|
108
|
+
mstore(add(pointer_, 352), mload(add(mload(add(pB_, 32)), 32)))
|
|
111
109
|
|
|
112
110
|
/// @dev alpha1
|
|
113
|
-
mstore(add(
|
|
114
|
-
mstore(add(
|
|
111
|
+
mstore(add(pointer_, 384), ALPHA_X)
|
|
112
|
+
mstore(add(pointer_, 416), ALPHA_Y)
|
|
115
113
|
|
|
116
114
|
/// @dev beta2
|
|
117
|
-
mstore(add(
|
|
118
|
-
mstore(add(
|
|
119
|
-
mstore(add(
|
|
120
|
-
mstore(add(
|
|
121
|
-
|
|
122
|
-
/// @dev public signals
|
|
123
|
-
mstore(add(pPairing_, 384), mload(pointer_))
|
|
124
|
-
mstore(add(pPairing_, 416), mload(add(pointer_, 32)))
|
|
125
|
-
|
|
126
|
-
/// @dev gamma2
|
|
127
|
-
mstore(add(pPairing_, 448), GAMMA_X1)
|
|
128
|
-
mstore(add(pPairing_, 480), GAMMA_X2)
|
|
129
|
-
mstore(add(pPairing_, 512), GAMMA_Y1)
|
|
130
|
-
mstore(add(pPairing_, 544), GAMMA_Y2)
|
|
115
|
+
mstore(add(pointer_, 448), BETA_X1)
|
|
116
|
+
mstore(add(pointer_, 480), BETA_X2)
|
|
117
|
+
mstore(add(pointer_, 512), BETA_Y1)
|
|
118
|
+
mstore(add(pointer_, 544), BETA_Y2)
|
|
131
119
|
|
|
132
120
|
/// @dev C
|
|
133
|
-
mstore(add(
|
|
134
|
-
mstore(add(
|
|
121
|
+
mstore(add(pointer_, 576), mload(pC_))
|
|
122
|
+
mstore(add(pointer_, 608), mload(add(pC_, 32)))
|
|
135
123
|
|
|
136
124
|
/// @dev delta2
|
|
137
|
-
mstore(add(
|
|
138
|
-
mstore(add(
|
|
139
|
-
mstore(add(
|
|
140
|
-
mstore(add(
|
|
125
|
+
mstore(add(pointer_, 640), DELTA_X1)
|
|
126
|
+
mstore(add(pointer_, 672), DELTA_X2)
|
|
127
|
+
mstore(add(pointer_, 704), DELTA_Y1)
|
|
128
|
+
mstore(add(pointer_, 736), DELTA_Y2)
|
|
141
129
|
|
|
142
|
-
res_ := staticcall(181000, 8,
|
|
143
|
-
res_ := and(res_, mload(
|
|
130
|
+
res_ := staticcall(181000, 8, pointer_, 768, pointer_, 32) // ecPairing
|
|
131
|
+
res_ := and(res_, mload(pointer_)) // check that pairing succeeded
|
|
144
132
|
}
|
|
145
133
|
|
|
146
134
|
let pointer_ := mload(64) // free pointer
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export { CircuitZKit } from "./core/CircuitZKit";
|
|
2
2
|
export * from "./core/protocols";
|
|
3
|
-
export * from "./
|
|
4
|
-
export * from "./types
|
|
5
|
-
export * from "./types/protocols";
|
|
3
|
+
export * from "./utils";
|
|
4
|
+
export * from "./types";
|
|
6
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,cAAc,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,cAAc,kBAAkB,CAAC;AACjC,cAAc,SAAS,CAAC;AAExB,cAAc,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -18,7 +18,6 @@ exports.CircuitZKit = void 0;
|
|
|
18
18
|
var CircuitZKit_1 = require("./core/CircuitZKit");
|
|
19
19
|
Object.defineProperty(exports, "CircuitZKit", { enumerable: true, get: function () { return CircuitZKit_1.CircuitZKit; } });
|
|
20
20
|
__exportStar(require("./core/protocols"), exports);
|
|
21
|
-
__exportStar(require("./
|
|
22
|
-
__exportStar(require("./types
|
|
23
|
-
__exportStar(require("./types/protocols"), exports);
|
|
21
|
+
__exportStar(require("./utils"), exports);
|
|
22
|
+
__exportStar(require("./types"), exports);
|
|
24
23
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,kDAAiD;AAAxC,0GAAA,WAAW,OAAA;AACpB,mDAAiC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,kDAAiD;AAAxC,0GAAA,WAAW,OAAA;AACpB,mDAAiC;AACjC,0CAAwB;AAExB,0CAAwB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
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("./circuit-zkit"), exports);
|
|
18
|
+
__exportStar(require("./proof-utils"), exports);
|
|
19
|
+
__exportStar(require("./witness-utils"), exports);
|
|
20
|
+
__exportStar(require("./protocols"), exports);
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA+B;AAC/B,gDAA8B;AAC9B,kDAAgC;AAChC,8CAA4B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"witness-utils.d.ts","sourceRoot":"","sources":["../../src/types/witness-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,MAAM,MAAM,UAAU,GAAG;IACvB,EAAE,EAAE,UAAU,CAAC;IACf,YAAY,EAAE,UAAU,CAAC;IACzB,WAAW,EAAE,UAAU,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"witness-utils.js","sourceRoot":"","sources":["../../src/types/witness-utils.ts"],"names":[],"mappings":""}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Terminates the BN128 curve instance used by SnarkJS.
|
|
3
|
-
*/
|
|
4
|
-
export declare function terminateCurve(): Promise<void>;
|
|
5
|
-
/**
|
|
6
|
-
* Returns the path to the temporary directory used by ZKit.
|
|
7
|
-
*
|
|
8
|
-
* Creates the directory if it does not exist.
|
|
9
|
-
*
|
|
10
|
-
* @returns {string} The path to the temporary `.zkit` directory inside the OS temp folder.
|
|
11
|
-
*/
|
|
12
|
-
export declare function getTmpDir(): string;
|
|
13
1
|
export * from "./witness-utils";
|
|
2
|
+
export * from "./protocol-utils";
|
|
14
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC"}
|
package/dist/utils/index.js
CHANGED
|
@@ -10,61 +10,10 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
10
10
|
if (k2 === undefined) k2 = k;
|
|
11
11
|
o[k2] = m[k];
|
|
12
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 () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
36
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
37
15
|
};
|
|
38
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
-
};
|
|
41
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.terminateCurve = terminateCurve;
|
|
43
|
-
exports.getTmpDir = getTmpDir;
|
|
44
|
-
const os_1 = __importDefault(require("os"));
|
|
45
|
-
const fs_1 = __importDefault(require("fs"));
|
|
46
|
-
const path_1 = __importDefault(require("path"));
|
|
47
|
-
const constants_1 = require("../constants");
|
|
48
|
-
const snarkjs = __importStar(require("snarkjs"));
|
|
49
|
-
/**
|
|
50
|
-
* Terminates the BN128 curve instance used by SnarkJS.
|
|
51
|
-
*/
|
|
52
|
-
async function terminateCurve() {
|
|
53
|
-
await (await snarkjs.curves.getCurveFromName(constants_1.BN128_CURVE_NAME)).terminate();
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Returns the path to the temporary directory used by ZKit.
|
|
57
|
-
*
|
|
58
|
-
* Creates the directory if it does not exist.
|
|
59
|
-
*
|
|
60
|
-
* @returns {string} The path to the temporary `.zkit` directory inside the OS temp folder.
|
|
61
|
-
*/
|
|
62
|
-
function getTmpDir() {
|
|
63
|
-
const tmpDir = path_1.default.join(os_1.default.tmpdir(), ".zkit");
|
|
64
|
-
if (!fs_1.default.existsSync(tmpDir)) {
|
|
65
|
-
fs_1.default.mkdirSync(tmpDir, { recursive: true });
|
|
66
|
-
}
|
|
67
|
-
return tmpDir;
|
|
68
|
-
}
|
|
69
17
|
__exportStar(require("./witness-utils"), exports);
|
|
18
|
+
__exportStar(require("./protocol-utils"), exports);
|
|
70
19
|
//# sourceMappingURL=index.js.map
|
package/dist/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC;AAChC,mDAAiC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Terminates the BN128 curve instance used by SnarkJS.
|
|
3
|
+
*/
|
|
4
|
+
export declare function terminateCurve(): Promise<void>;
|
|
5
|
+
/**
|
|
6
|
+
* Returns the path to the temporary directory used by ZKit.
|
|
7
|
+
*
|
|
8
|
+
* Creates the directory if it does not exist.
|
|
9
|
+
*
|
|
10
|
+
* @returns {string} The path to the temporary `.zkit` directory inside the OS temp folder.
|
|
11
|
+
*/
|
|
12
|
+
export declare function getTmpDir(): string;
|
|
13
|
+
//# sourceMappingURL=protocol-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol-utils.d.ts","sourceRoot":"","sources":["../../src/utils/protocol-utils.ts"],"names":[],"mappings":"AAQA;;GAEG;AACH,wBAAsB,cAAc,kBAEnC;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,IAAI,MAAM,CAQlC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
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 () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.terminateCurve = terminateCurve;
|
|
40
|
+
exports.getTmpDir = getTmpDir;
|
|
41
|
+
const os_1 = __importDefault(require("os"));
|
|
42
|
+
const fs_1 = __importDefault(require("fs"));
|
|
43
|
+
const path_1 = __importDefault(require("path"));
|
|
44
|
+
const snarkjs = __importStar(require("snarkjs"));
|
|
45
|
+
const constants_1 = require("../constants");
|
|
46
|
+
/**
|
|
47
|
+
* Terminates the BN128 curve instance used by SnarkJS.
|
|
48
|
+
*/
|
|
49
|
+
async function terminateCurve() {
|
|
50
|
+
await (await snarkjs.curves.getCurveFromName(constants_1.BN128_CURVE_NAME)).terminate();
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Returns the path to the temporary directory used by ZKit.
|
|
54
|
+
*
|
|
55
|
+
* Creates the directory if it does not exist.
|
|
56
|
+
*
|
|
57
|
+
* @returns {string} The path to the temporary `.zkit` directory inside the OS temp folder.
|
|
58
|
+
*/
|
|
59
|
+
function getTmpDir() {
|
|
60
|
+
const tmpDir = path_1.default.join(os_1.default.tmpdir(), ".zkit");
|
|
61
|
+
if (!fs_1.default.existsSync(tmpDir)) {
|
|
62
|
+
fs_1.default.mkdirSync(tmpDir, { recursive: true });
|
|
63
|
+
}
|
|
64
|
+
return tmpDir;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=protocol-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol-utils.js","sourceRoot":"","sources":["../../src/utils/protocol-utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAWA,wCAEC;AASD,8BAQC;AA9BD,4CAAoB;AACpB,4CAAoB;AACpB,gDAAwB;AAExB,iDAAmC;AAEnC,4CAAgD;AAEhD;;GAEG;AACI,KAAK,UAAU,cAAc;IAClC,MAAM,CAAC,MAAO,OAAe,CAAC,MAAM,CAAC,gBAAgB,CAAC,4BAAgB,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;AACvF,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,SAAS;IACvB,MAAM,MAAM,GAAG,cAAI,CAAC,IAAI,CAAC,YAAE,CAAC,MAAM,EAAE,EAAE,OAAO,CAAC,CAAC;IAE/C,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;QAC3B,YAAE,CAAC,SAAS,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC5C,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { NumberLike, SignalInfo } from "../types";
|
|
1
2
|
/**
|
|
2
3
|
* Validates the provided witness overrides against the `.sym` file and returns the signal-to-index map.
|
|
3
4
|
*
|
|
@@ -8,11 +9,20 @@
|
|
|
8
9
|
* Signal names in `overrides` must be in their full form as represented in the `.sym` file, e.g.,
|
|
9
10
|
* `main.signal`, `main.component.signal`, or `main.component.signal[n][m]`.
|
|
10
11
|
*
|
|
11
|
-
* @param {string}
|
|
12
|
+
* @param {string} symFilePath - Path to the `.sym` file.
|
|
12
13
|
* @param {Record<string, bigint>} overrides - Map of signal names to new witness values.
|
|
13
|
-
* @returns {Promise<Record<string,
|
|
14
|
+
* @returns {Promise<Record<string, NumberLike>>} Map of signal names to their corresponding witness indices.
|
|
14
15
|
*/
|
|
15
|
-
export declare function checkWitnessOverrides(
|
|
16
|
+
export declare function checkWitnessOverrides(symFilePath: string, overrides: Record<string, bigint>): Promise<Record<string, NumberLike>>;
|
|
17
|
+
/**
|
|
18
|
+
* Iterates over signal entries in a `.sym` file line by line.
|
|
19
|
+
*
|
|
20
|
+
* Each line is parsed into a `SignalInfo` object which is passed to the provided callback.
|
|
21
|
+
*
|
|
22
|
+
* @param {string} symFilePath - The full path to the `.sym` file to read.
|
|
23
|
+
* @param {(signalInfo: SignalInfo) => void} onSignal - Callback invoked for each signal line.
|
|
24
|
+
*/
|
|
25
|
+
export declare function iterateSymFile(symFilePath: string, onSignal: (signalInfo: SignalInfo) => void): Promise<void>;
|
|
16
26
|
/**
|
|
17
27
|
* Modifies specific signal values in a witness array.
|
|
18
28
|
* Substitutes signal from `overrides` in the witness array at positions defined in `signalIndexes`.
|
|
@@ -21,11 +31,11 @@ export declare function checkWitnessOverrides(symFile: string, overrides: Record
|
|
|
21
31
|
* `main.signal`, `main.component.signal`, or `main.component.signal[n][m]`.
|
|
22
32
|
*
|
|
23
33
|
* @param {bigint[]} witness - The original witness array.
|
|
24
|
-
* @param {Record<string,
|
|
34
|
+
* @param {Record<string, NumberLike>} signalIndexes - Map of signal names to their witness indices.
|
|
25
35
|
* @param {Record<string, bigint>} overrides - Map of signal names to new witness values.
|
|
26
36
|
* @returns {Promise<bigint[]>} The modified witness array.
|
|
27
37
|
*/
|
|
28
|
-
export declare function modifyWitnessArray(witness: bigint[], signalIndexes: Record<string,
|
|
38
|
+
export declare function modifyWitnessArray(witness: bigint[], signalIndexes: Record<string, NumberLike>, overrides: Record<string, bigint>): Promise<bigint[]>;
|
|
29
39
|
/**
|
|
30
40
|
* Writes a witness array to a `.wtns` binary file.
|
|
31
41
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"witness-utils.d.ts","sourceRoot":"","sources":["../../src/utils/witness-utils.ts"],"names":[],"mappings":"AASA;;;;;;;;;;;;;GAaG;AACH,wBAAsB,qBAAqB,CACzC,
|
|
1
|
+
{"version":3,"file":"witness-utils.d.ts","sourceRoot":"","sources":["../../src/utils/witness-utils.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAElD;;;;;;;;;;;;;GAaG;AACH,wBAAsB,qBAAqB,CACzC,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAChC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAkBrC;AAED;;;;;;;GAOG;AACH,wBAAsB,cAAc,CAAC,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,IAAI,iBAkBnG;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,MAAM,EAAE,EACjB,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,EACzC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAChC,OAAO,CAAC,MAAM,EAAE,CAAC,CAQnB;AAED;;;;;;;GAOG;AACH,wBAAsB,gBAAgB,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,iBAwB5E"}
|
|
@@ -37,6 +37,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.checkWitnessOverrides = checkWitnessOverrides;
|
|
40
|
+
exports.iterateSymFile = iterateSymFile;
|
|
40
41
|
exports.modifyWitnessArray = modifyWitnessArray;
|
|
41
42
|
exports.writeWitnessFile = writeWitnessFile;
|
|
42
43
|
const fs_1 = __importDefault(require("fs"));
|
|
@@ -55,27 +56,47 @@ const binFileUtils = __importStar(require("@iden3/binfileutils"));
|
|
|
55
56
|
* Signal names in `overrides` must be in their full form as represented in the `.sym` file, e.g.,
|
|
56
57
|
* `main.signal`, `main.component.signal`, or `main.component.signal[n][m]`.
|
|
57
58
|
*
|
|
58
|
-
* @param {string}
|
|
59
|
+
* @param {string} symFilePath - Path to the `.sym` file.
|
|
59
60
|
* @param {Record<string, bigint>} overrides - Map of signal names to new witness values.
|
|
60
|
-
* @returns {Promise<Record<string,
|
|
61
|
+
* @returns {Promise<Record<string, NumberLike>>} Map of signal names to their corresponding witness indices.
|
|
61
62
|
*/
|
|
62
|
-
async function checkWitnessOverrides(
|
|
63
|
+
async function checkWitnessOverrides(symFilePath, overrides) {
|
|
63
64
|
const signalToWitnessIndex = {};
|
|
64
65
|
const missingSignals = new Set(Object.keys(overrides));
|
|
65
|
-
|
|
66
|
+
await iterateSymFile(symFilePath, (signalInfo) => {
|
|
67
|
+
if (BigInt(signalInfo.witnessIndex) >= 0) {
|
|
68
|
+
signalToWitnessIndex[signalInfo.signalName] = signalInfo.witnessIndex;
|
|
69
|
+
missingSignals.delete(signalInfo.signalName);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
if (missingSignals.size > 0) {
|
|
73
|
+
throw new Error(`Signals not found in .sym file: ${Array.from(missingSignals).join(", ")}`);
|
|
74
|
+
}
|
|
75
|
+
return signalToWitnessIndex;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Iterates over signal entries in a `.sym` file line by line.
|
|
79
|
+
*
|
|
80
|
+
* Each line is parsed into a `SignalInfo` object which is passed to the provided callback.
|
|
81
|
+
*
|
|
82
|
+
* @param {string} symFilePath - The full path to the `.sym` file to read.
|
|
83
|
+
* @param {(signalInfo: SignalInfo) => void} onSignal - Callback invoked for each signal line.
|
|
84
|
+
*/
|
|
85
|
+
async function iterateSymFile(symFilePath, onSignal) {
|
|
86
|
+
const fileStream = fs_1.default.createReadStream(symFilePath, { encoding: "utf8" });
|
|
66
87
|
const signals = readline.createInterface({ input: fileStream, crlfDelay: Infinity });
|
|
67
88
|
for await (const signal of signals) {
|
|
68
89
|
const signalInfo = signal.split(",");
|
|
69
|
-
if (signalInfo.length != 4
|
|
90
|
+
if (signalInfo.length != 4) {
|
|
70
91
|
continue;
|
|
71
92
|
}
|
|
72
|
-
|
|
73
|
-
|
|
93
|
+
onSignal({
|
|
94
|
+
id: BigInt(signalInfo[0]),
|
|
95
|
+
witnessIndex: BigInt(signalInfo[1]),
|
|
96
|
+
componentId: BigInt(signalInfo[2]),
|
|
97
|
+
signalName: signalInfo[3],
|
|
98
|
+
});
|
|
74
99
|
}
|
|
75
|
-
if (missingSignals.size > 0) {
|
|
76
|
-
throw new Error(`Signals not found in .sym file: ${Array.from(missingSignals).join(", ")}`);
|
|
77
|
-
}
|
|
78
|
-
return signalToWitnessIndex;
|
|
79
100
|
}
|
|
80
101
|
/**
|
|
81
102
|
* Modifies specific signal values in a witness array.
|
|
@@ -85,13 +106,13 @@ async function checkWitnessOverrides(symFile, overrides) {
|
|
|
85
106
|
* `main.signal`, `main.component.signal`, or `main.component.signal[n][m]`.
|
|
86
107
|
*
|
|
87
108
|
* @param {bigint[]} witness - The original witness array.
|
|
88
|
-
* @param {Record<string,
|
|
109
|
+
* @param {Record<string, NumberLike>} signalIndexes - Map of signal names to their witness indices.
|
|
89
110
|
* @param {Record<string, bigint>} overrides - Map of signal names to new witness values.
|
|
90
111
|
* @returns {Promise<bigint[]>} The modified witness array.
|
|
91
112
|
*/
|
|
92
113
|
async function modifyWitnessArray(witness, signalIndexes, overrides) {
|
|
93
114
|
for (const [signal, value] of Object.entries(overrides)) {
|
|
94
|
-
const index = signalIndexes[signal];
|
|
115
|
+
const index = Number(signalIndexes[signal]);
|
|
95
116
|
witness[index] = value;
|
|
96
117
|
}
|
|
97
118
|
return witness;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"witness-utils.js","sourceRoot":"","sources":["../../src/utils/witness-utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"witness-utils.js","sourceRoot":"","sources":["../../src/utils/witness-utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,sDAqBC;AAUD,wCAkBC;AAcD,gDAYC;AAUD,4CAwBC;AAtID,4CAAoB;AAEpB,mDAAqC;AAErC,aAAa;AACb,+CAAsC;AACtC,aAAa;AACb,kEAAoD;AAIpD;;;;;;;;;;;;;GAaG;AACI,KAAK,UAAU,qBAAqB,CACzC,WAAmB,EACnB,SAAiC;IAEjC,MAAM,oBAAoB,GAA+B,EAAE,CAAC;IAE5D,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;IAEvD,MAAM,cAAc,CAAC,WAAW,EAAE,CAAC,UAAU,EAAE,EAAE;QAC/C,IAAI,MAAM,CAAC,UAAU,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;YACzC,oBAAoB,CAAC,UAAU,CAAC,UAAU,CAAC,GAAG,UAAU,CAAC,YAAY,CAAC;YAEtE,cAAc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AAC;IAED,MAAM,YAAY,CAAC,eAAe,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;IAE1C,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC;AACnB,CAAC;AAED;;;;;GAKG;AACH,KAAK,UAAU,eAAe,CAAC,QAAgB;IAC7C,MAAM,EAAE,EAAE,EAAE,QAAQ,EAAE,GAAG,MAAM,YAAY,CAAC,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;IAE7E,MAAM,YAAY,CAAC,sBAAsB,CAAC,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC;IAE3D,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,SAAS,EAAE,CAAC;IAChC,MAAM,KAAK,GAAG,MAAM,YAAY,CAAC,UAAU,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IACpD,MAAM,EAAE,CAAC,SAAS,EAAE,CAAC;IAErB,MAAM,YAAY,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC;IACtC,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC;IAEjB,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solarity/zkit",
|
|
3
|
-
"version": "0.3.7
|
|
3
|
+
"version": "0.3.7",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Distributed Lab",
|
|
6
6
|
"readme": "README.md",
|
|
@@ -39,10 +39,12 @@
|
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"ejs": "3.1.10",
|
|
42
|
-
"snarkjs": "0.7.5"
|
|
42
|
+
"snarkjs": "0.7.5",
|
|
43
|
+
"@iden3/binfileutils": "0.0.12",
|
|
44
|
+
"ffjavascript": "0.3.1",
|
|
45
|
+
"readline": "1.3.0"
|
|
43
46
|
},
|
|
44
47
|
"devDependencies": {
|
|
45
|
-
"@iden3/binfileutils": "^0.0.12",
|
|
46
48
|
"@nomicfoundation/hardhat-ethers": "3.0.5",
|
|
47
49
|
"@nomiclabs/hardhat-vyper": "^3.0.7",
|
|
48
50
|
"@solarity/solidity-lib": "3.0.0-rc.3",
|
|
@@ -54,13 +56,11 @@
|
|
|
54
56
|
"chai": "^4.4.1",
|
|
55
57
|
"chai-as-promised": "^7.1.1",
|
|
56
58
|
"ethers": "^6.11.1",
|
|
57
|
-
"ffjavascript": "^0.3.1",
|
|
58
59
|
"hardhat": "2.22.7",
|
|
59
60
|
"husky": "^9.0.11",
|
|
60
61
|
"mocha": "^10.3.0",
|
|
61
62
|
"nyc": "^15.1.0",
|
|
62
63
|
"prettier": "^3.2.5",
|
|
63
|
-
"readline": "^1.3.0",
|
|
64
64
|
"ts-node": "^10.9.2",
|
|
65
65
|
"typescript": "^5.4.5"
|
|
66
66
|
}
|
package/src/core/CircuitZKit.ts
CHANGED
|
@@ -3,9 +3,17 @@ import path from "path";
|
|
|
3
3
|
import * as snarkjs from "snarkjs";
|
|
4
4
|
import { createHash } from "crypto";
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
import {
|
|
7
|
+
ArtifactsFileType,
|
|
8
|
+
CircuitZKitConfig,
|
|
9
|
+
VerifierLanguageType,
|
|
10
|
+
Signals,
|
|
11
|
+
CalldataByProtocol,
|
|
12
|
+
IProtocolImplementer,
|
|
13
|
+
ProofStructByProtocol,
|
|
14
|
+
ProvingSystemType,
|
|
15
|
+
NumberLike,
|
|
16
|
+
} from "../types";
|
|
9
17
|
|
|
10
18
|
import { MAX_FILE_NAME_LENGTH } from "../constants";
|
|
11
19
|
import { getTmpDir, modifyWitnessArray, checkWitnessOverrides, writeWitnessFile } from "../utils";
|
|
@@ -69,7 +77,7 @@ export class CircuitZKit<Type extends ProvingSystemType> {
|
|
|
69
77
|
const wtnsFile = this.getTemporaryWitnessPath();
|
|
70
78
|
const wasmFile = this.mustGetArtifactsFilePath("wasm");
|
|
71
79
|
|
|
72
|
-
let signalIndexes: Record<string,
|
|
80
|
+
let signalIndexes: Record<string, NumberLike> = {};
|
|
73
81
|
|
|
74
82
|
if (witnessOverrides) {
|
|
75
83
|
const symFile = this.mustGetArtifactsFilePath("sym");
|
|
@@ -7,8 +7,8 @@ import {
|
|
|
7
7
|
ProvingSystemType,
|
|
8
8
|
ProofStructByProtocol,
|
|
9
9
|
CalldataByProtocol,
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
VerifierLanguageType,
|
|
11
|
+
} from "../../types";
|
|
12
12
|
|
|
13
13
|
export abstract class AbstractProtocolImplementer<T extends ProvingSystemType> implements IProtocolImplementer<T> {
|
|
14
14
|
public async createVerifier(
|
|
@@ -3,7 +3,7 @@ import * as snarkjs from "snarkjs";
|
|
|
3
3
|
|
|
4
4
|
import { AbstractProtocolImplementer } from "./AbstractImplementer";
|
|
5
5
|
|
|
6
|
-
import { Groth16ProofStruct, Groth16CalldataStruct, ProvingSystemType } from "../../types
|
|
6
|
+
import { Groth16ProofStruct, Groth16CalldataStruct, ProvingSystemType } from "../../types";
|
|
7
7
|
|
|
8
8
|
import { terminateCurve } from "../../utils";
|
|
9
9
|
|
|
@@ -3,7 +3,7 @@ import * as snarkjs from "snarkjs";
|
|
|
3
3
|
|
|
4
4
|
import { AbstractProtocolImplementer } from "./AbstractImplementer";
|
|
5
5
|
|
|
6
|
-
import { PlonkProofStruct, PlonkCalldataStruct, ProvingSystemType } from "../../types
|
|
6
|
+
import { PlonkProofStruct, PlonkCalldataStruct, ProvingSystemType } from "../../types";
|
|
7
7
|
|
|
8
8
|
import { terminateCurve } from "../../utils";
|
|
9
9
|
|
|
@@ -48,9 +48,8 @@ contract <%=verifier_id%> {
|
|
|
48
48
|
<%=IC[i][1]%>;
|
|
49
49
|
<% } -%>
|
|
50
50
|
|
|
51
|
-
/// @dev memory pointer
|
|
52
|
-
|
|
53
|
-
uint16 public constant P_TOTAL_SIZE = 896;
|
|
51
|
+
/// @dev memory pointer size
|
|
52
|
+
uint256 public constant P_TOTAL_SIZE = 768;
|
|
54
53
|
|
|
55
54
|
function verifyProof(
|
|
56
55
|
uint256[2] memory pointA_,
|
|
@@ -63,30 +62,23 @@ contract <%=verifier_id%> {
|
|
|
63
62
|
res_ := lt(signal_, SCALAR_FIELD_SIZE)
|
|
64
63
|
}
|
|
65
64
|
|
|
66
|
-
function g1MulAdd(
|
|
67
|
-
|
|
65
|
+
function g1MulAdd(pointer_, x_, y_, s_) -> res_ {
|
|
66
|
+
mstore(add(pointer_, 64), x_)
|
|
67
|
+
mstore(add(pointer_, 96), y_)
|
|
68
|
+
mstore(add(pointer_, 128), s_)
|
|
68
69
|
|
|
69
|
-
|
|
70
|
-
mstore(add(pointer_, 32), y_)
|
|
71
|
-
mstore(add(pointer_, 64), s_)
|
|
72
|
-
|
|
73
|
-
res_ := staticcall(6000, 7, pointer_, 96, pointer_, 64) // ecMul
|
|
70
|
+
res_ := staticcall(6000, 7, add(pointer_, 64), 96, add(pointer_, 64), 64) // ecMul
|
|
74
71
|
res_ := and(res_, gt(returndatasize(), 0)) // check that multiplication succeeded
|
|
75
72
|
|
|
76
73
|
if iszero(res_) {
|
|
77
74
|
leave
|
|
78
75
|
}
|
|
79
76
|
|
|
80
|
-
|
|
81
|
-
mstore(add(pointer_, 96), mload(add(pR_, 32)))
|
|
82
|
-
|
|
83
|
-
res_ := staticcall(150, 6, pointer_, 128, pR_, 64) // ecAdd
|
|
77
|
+
res_ := staticcall(150, 6, pointer_, 128, pointer_, 64) // ecAdd
|
|
84
78
|
res_ := and(res_, gt(returndatasize(), 0)) // check that addition succeeded
|
|
85
79
|
}
|
|
86
80
|
|
|
87
81
|
function checkPairing(pA_, pB_, pC_, pubSignals_, pointer_) -> res_ {
|
|
88
|
-
let pPairing_ := add(pointer_, P_PUBLIC_SIGNALS_ACCUMULATOR_SIZE)
|
|
89
|
-
|
|
90
82
|
mstore(pointer_, IC0_X)
|
|
91
83
|
mstore(add(pointer_, 32), IC0_Y)
|
|
92
84
|
|
|
@@ -96,51 +88,47 @@ contract <%=verifier_id%> {
|
|
|
96
88
|
}
|
|
97
89
|
<% } -%>
|
|
98
90
|
|
|
91
|
+
/// @dev gamma2
|
|
92
|
+
mstore(add(pointer_, 64), GAMMA_X1)
|
|
93
|
+
mstore(add(pointer_, 96), GAMMA_X2)
|
|
94
|
+
mstore(add(pointer_, 128), GAMMA_Y1)
|
|
95
|
+
mstore(add(pointer_, 160), GAMMA_Y2)
|
|
96
|
+
|
|
99
97
|
/// @dev -A
|
|
100
|
-
mstore(
|
|
98
|
+
mstore(add(pointer_, 192), mload(pA_))
|
|
101
99
|
mstore(
|
|
102
|
-
add(
|
|
100
|
+
add(pointer_, 224),
|
|
103
101
|
mod(sub(BASE_FIELD_SIZE, mload(add(pA_, 32))), BASE_FIELD_SIZE)
|
|
104
102
|
)
|
|
105
103
|
|
|
106
104
|
/// @dev B
|
|
107
|
-
mstore(add(
|
|
108
|
-
mstore(add(
|
|
109
|
-
mstore(add(
|
|
110
|
-
mstore(add(
|
|
105
|
+
mstore(add(pointer_, 256), mload(mload(pB_)))
|
|
106
|
+
mstore(add(pointer_, 288), mload(add(mload(pB_), 32)))
|
|
107
|
+
mstore(add(pointer_, 320), mload(mload(add(pB_, 32))))
|
|
108
|
+
mstore(add(pointer_, 352), mload(add(mload(add(pB_, 32)), 32)))
|
|
111
109
|
|
|
112
110
|
/// @dev alpha1
|
|
113
|
-
mstore(add(
|
|
114
|
-
mstore(add(
|
|
111
|
+
mstore(add(pointer_, 384), ALPHA_X)
|
|
112
|
+
mstore(add(pointer_, 416), ALPHA_Y)
|
|
115
113
|
|
|
116
114
|
/// @dev beta2
|
|
117
|
-
mstore(add(
|
|
118
|
-
mstore(add(
|
|
119
|
-
mstore(add(
|
|
120
|
-
mstore(add(
|
|
121
|
-
|
|
122
|
-
/// @dev public signals
|
|
123
|
-
mstore(add(pPairing_, 384), mload(pointer_))
|
|
124
|
-
mstore(add(pPairing_, 416), mload(add(pointer_, 32)))
|
|
125
|
-
|
|
126
|
-
/// @dev gamma2
|
|
127
|
-
mstore(add(pPairing_, 448), GAMMA_X1)
|
|
128
|
-
mstore(add(pPairing_, 480), GAMMA_X2)
|
|
129
|
-
mstore(add(pPairing_, 512), GAMMA_Y1)
|
|
130
|
-
mstore(add(pPairing_, 544), GAMMA_Y2)
|
|
115
|
+
mstore(add(pointer_, 448), BETA_X1)
|
|
116
|
+
mstore(add(pointer_, 480), BETA_X2)
|
|
117
|
+
mstore(add(pointer_, 512), BETA_Y1)
|
|
118
|
+
mstore(add(pointer_, 544), BETA_Y2)
|
|
131
119
|
|
|
132
120
|
/// @dev C
|
|
133
|
-
mstore(add(
|
|
134
|
-
mstore(add(
|
|
121
|
+
mstore(add(pointer_, 576), mload(pC_))
|
|
122
|
+
mstore(add(pointer_, 608), mload(add(pC_, 32)))
|
|
135
123
|
|
|
136
124
|
/// @dev delta2
|
|
137
|
-
mstore(add(
|
|
138
|
-
mstore(add(
|
|
139
|
-
mstore(add(
|
|
140
|
-
mstore(add(
|
|
125
|
+
mstore(add(pointer_, 640), DELTA_X1)
|
|
126
|
+
mstore(add(pointer_, 672), DELTA_X2)
|
|
127
|
+
mstore(add(pointer_, 704), DELTA_Y1)
|
|
128
|
+
mstore(add(pointer_, 736), DELTA_Y2)
|
|
141
129
|
|
|
142
|
-
res_ := staticcall(181000, 8,
|
|
143
|
-
res_ := and(res_, mload(
|
|
130
|
+
res_ := staticcall(181000, 8, pointer_, 768, pointer_, 32) // ecPairing
|
|
131
|
+
res_ := and(res_, mload(pointer_)) // check that pairing succeeded
|
|
144
132
|
}
|
|
145
133
|
|
|
146
134
|
let pointer_ := mload(64) // free pointer
|
package/src/index.ts
CHANGED
package/src/utils/index.ts
CHANGED
|
@@ -1,33 +1,2 @@
|
|
|
1
|
-
import os from "os";
|
|
2
|
-
import fs from "fs";
|
|
3
|
-
import path from "path";
|
|
4
|
-
|
|
5
|
-
import { BN128_CURVE_NAME } from "../constants";
|
|
6
|
-
|
|
7
|
-
import * as snarkjs from "snarkjs";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Terminates the BN128 curve instance used by SnarkJS.
|
|
11
|
-
*/
|
|
12
|
-
export async function terminateCurve() {
|
|
13
|
-
await (await (snarkjs as any).curves.getCurveFromName(BN128_CURVE_NAME)).terminate();
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Returns the path to the temporary directory used by ZKit.
|
|
18
|
-
*
|
|
19
|
-
* Creates the directory if it does not exist.
|
|
20
|
-
*
|
|
21
|
-
* @returns {string} The path to the temporary `.zkit` directory inside the OS temp folder.
|
|
22
|
-
*/
|
|
23
|
-
export function getTmpDir(): string {
|
|
24
|
-
const tmpDir = path.join(os.tmpdir(), ".zkit");
|
|
25
|
-
|
|
26
|
-
if (!fs.existsSync(tmpDir)) {
|
|
27
|
-
fs.mkdirSync(tmpDir, { recursive: true });
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return tmpDir;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
1
|
export * from "./witness-utils";
|
|
2
|
+
export * from "./protocol-utils";
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import os from "os";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import path from "path";
|
|
4
|
+
|
|
5
|
+
import * as snarkjs from "snarkjs";
|
|
6
|
+
|
|
7
|
+
import { BN128_CURVE_NAME } from "../constants";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Terminates the BN128 curve instance used by SnarkJS.
|
|
11
|
+
*/
|
|
12
|
+
export async function terminateCurve() {
|
|
13
|
+
await (await (snarkjs as any).curves.getCurveFromName(BN128_CURVE_NAME)).terminate();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Returns the path to the temporary directory used by ZKit.
|
|
18
|
+
*
|
|
19
|
+
* Creates the directory if it does not exist.
|
|
20
|
+
*
|
|
21
|
+
* @returns {string} The path to the temporary `.zkit` directory inside the OS temp folder.
|
|
22
|
+
*/
|
|
23
|
+
export function getTmpDir(): string {
|
|
24
|
+
const tmpDir = path.join(os.tmpdir(), ".zkit");
|
|
25
|
+
|
|
26
|
+
if (!fs.existsSync(tmpDir)) {
|
|
27
|
+
fs.mkdirSync(tmpDir, { recursive: true });
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return tmpDir;
|
|
31
|
+
}
|
|
@@ -7,6 +7,8 @@ import { Scalar } from "ffjavascript";
|
|
|
7
7
|
// @ts-ignore
|
|
8
8
|
import * as binFileUtils from "@iden3/binfileutils";
|
|
9
9
|
|
|
10
|
+
import { NumberLike, SignalInfo } from "../types";
|
|
11
|
+
|
|
10
12
|
/**
|
|
11
13
|
* Validates the provided witness overrides against the `.sym` file and returns the signal-to-index map.
|
|
12
14
|
*
|
|
@@ -17,38 +19,59 @@ import * as binFileUtils from "@iden3/binfileutils";
|
|
|
17
19
|
* Signal names in `overrides` must be in their full form as represented in the `.sym` file, e.g.,
|
|
18
20
|
* `main.signal`, `main.component.signal`, or `main.component.signal[n][m]`.
|
|
19
21
|
*
|
|
20
|
-
* @param {string}
|
|
22
|
+
* @param {string} symFilePath - Path to the `.sym` file.
|
|
21
23
|
* @param {Record<string, bigint>} overrides - Map of signal names to new witness values.
|
|
22
|
-
* @returns {Promise<Record<string,
|
|
24
|
+
* @returns {Promise<Record<string, NumberLike>>} Map of signal names to their corresponding witness indices.
|
|
23
25
|
*/
|
|
24
26
|
export async function checkWitnessOverrides(
|
|
25
|
-
|
|
27
|
+
symFilePath: string,
|
|
26
28
|
overrides: Record<string, bigint>,
|
|
27
|
-
): Promise<Record<string,
|
|
28
|
-
const signalToWitnessIndex: Record<string,
|
|
29
|
+
): Promise<Record<string, NumberLike>> {
|
|
30
|
+
const signalToWitnessIndex: Record<string, NumberLike> = {};
|
|
29
31
|
|
|
30
32
|
const missingSignals = new Set(Object.keys(overrides));
|
|
31
33
|
|
|
32
|
-
|
|
34
|
+
await iterateSymFile(symFilePath, (signalInfo) => {
|
|
35
|
+
if (BigInt(signalInfo.witnessIndex) >= 0) {
|
|
36
|
+
signalToWitnessIndex[signalInfo.signalName] = signalInfo.witnessIndex;
|
|
37
|
+
|
|
38
|
+
missingSignals.delete(signalInfo.signalName);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
if (missingSignals.size > 0) {
|
|
43
|
+
throw new Error(`Signals not found in .sym file: ${Array.from(missingSignals).join(", ")}`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return signalToWitnessIndex;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Iterates over signal entries in a `.sym` file line by line.
|
|
51
|
+
*
|
|
52
|
+
* Each line is parsed into a `SignalInfo` object which is passed to the provided callback.
|
|
53
|
+
*
|
|
54
|
+
* @param {string} symFilePath - The full path to the `.sym` file to read.
|
|
55
|
+
* @param {(signalInfo: SignalInfo) => void} onSignal - Callback invoked for each signal line.
|
|
56
|
+
*/
|
|
57
|
+
export async function iterateSymFile(symFilePath: string, onSignal: (signalInfo: SignalInfo) => void) {
|
|
58
|
+
const fileStream = fs.createReadStream(symFilePath, { encoding: "utf8" });
|
|
33
59
|
const signals = readline.createInterface({ input: fileStream, crlfDelay: Infinity });
|
|
34
60
|
|
|
35
61
|
for await (const signal of signals) {
|
|
36
62
|
const signalInfo = signal.split(",");
|
|
37
63
|
|
|
38
|
-
if (signalInfo.length != 4
|
|
64
|
+
if (signalInfo.length != 4) {
|
|
39
65
|
continue;
|
|
40
66
|
}
|
|
41
67
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
68
|
+
onSignal({
|
|
69
|
+
id: BigInt(signalInfo[0]),
|
|
70
|
+
witnessIndex: BigInt(signalInfo[1]),
|
|
71
|
+
componentId: BigInt(signalInfo[2]),
|
|
72
|
+
signalName: signalInfo[3],
|
|
73
|
+
});
|
|
45
74
|
}
|
|
46
|
-
|
|
47
|
-
if (missingSignals.size > 0) {
|
|
48
|
-
throw new Error(`Signals not found in .sym file: ${Array.from(missingSignals).join(", ")}`);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return signalToWitnessIndex;
|
|
52
75
|
}
|
|
53
76
|
|
|
54
77
|
/**
|
|
@@ -59,17 +82,17 @@ export async function checkWitnessOverrides(
|
|
|
59
82
|
* `main.signal`, `main.component.signal`, or `main.component.signal[n][m]`.
|
|
60
83
|
*
|
|
61
84
|
* @param {bigint[]} witness - The original witness array.
|
|
62
|
-
* @param {Record<string,
|
|
85
|
+
* @param {Record<string, NumberLike>} signalIndexes - Map of signal names to their witness indices.
|
|
63
86
|
* @param {Record<string, bigint>} overrides - Map of signal names to new witness values.
|
|
64
87
|
* @returns {Promise<bigint[]>} The modified witness array.
|
|
65
88
|
*/
|
|
66
89
|
export async function modifyWitnessArray(
|
|
67
90
|
witness: bigint[],
|
|
68
|
-
signalIndexes: Record<string,
|
|
91
|
+
signalIndexes: Record<string, NumberLike>,
|
|
69
92
|
overrides: Record<string, bigint>,
|
|
70
93
|
): Promise<bigint[]> {
|
|
71
94
|
for (const [signal, value] of Object.entries(overrides)) {
|
|
72
|
-
const index = signalIndexes[signal];
|
|
95
|
+
const index = Number(signalIndexes[signal]);
|
|
73
96
|
|
|
74
97
|
witness[index] = value;
|
|
75
98
|
}
|