-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
41 lines (41 loc) · 2.14 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.testCircuitDir = exports.compileCircuitDir = void 0;
const witness_generator_1 = require("./src/witness_generator");
const checker_1 = require("./src/checker");
const path = require("path");
const fs = require("fs");
const walkSync = require('walk-sync');
async function compileCircuitDir(circuitDir, options) {
const circuitName = path.basename(circuitDir);
let witnessGenerator = new witness_generator_1.WitnessGenerator(circuitName, options);
await witnessGenerator.compile(circuitDir);
}
exports.compileCircuitDir = compileCircuitDir;
// in the new rust circom, constraints are already checked in the witgen process
// so we need not check again manually.
async function testCircuitDir(circuitDir, dataDir, options) {
// make sure the circuit is compiled
const circuitName = path.basename(circuitDir);
let witnessGenerator = new witness_generator_1.WitnessGenerator(circuitName, options);
const { r1csFilepath, symFilepath } = await witnessGenerator.compile(circuitDir);
if (dataDir == null || dataDir == '') {
dataDir = circuitDir;
}
for (const input of walkSync(path.resolve(dataDir), { includeBasePath: true, globs: ['**/input.json'] })) {
const testCaseDir = path.normalize(path.dirname(input));
console.log('\ntest', testCaseDir);
const inputFile = path.join(testCaseDir, 'input.json');
//backend generated by circom2 has no json output anymore, need to be converted via snarkjs
const witnessFile = path.join(testCaseDir, 'witness');
const expectedOutputFile = path.join(testCaseDir, 'output.json');
await witnessGenerator.generateWitness(inputFile, witnessFile, options.witnessFileType == 'text');
if (!options.sanityCheck || fs.existsSync(expectedOutputFile)) {
const checker = new checker_1.Checker(r1csFilepath, symFilepath);
await checker.checkConstraintsAndOutput(witnessFile + '.wtns', expectedOutputFile);
}
console.log('\ntest', testCaseDir, 'done');
}
}
exports.testCircuitDir = testCircuitDir;
//# sourceMappingURL=index.js.map