-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.ts
40 lines (36 loc) · 1.8 KB
/
index.ts
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
import { WitnessGenerator } from './src/witness_generator';
import { Checker } from './src/checker';
import * as path from 'path';
import * as fs from 'fs';
const walkSync = require('walk-sync');
async function compileCircuitDir(circuitDir, options) {
const circuitName = path.basename(circuitDir);
let witnessGenerator = new WitnessGenerator(circuitName, options);
await witnessGenerator.compile(circuitDir);
}
// 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 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(r1csFilepath, symFilepath);
await checker.checkConstraintsAndOutput(witnessFile + '.wtns', expectedOutputFile);
}
console.log('\ntest', testCaseDir, 'done');
}
}
export { compileCircuitDir, testCircuitDir };