Skip to content

Commit

Permalink
Merge pull request #1749 from privacy-scaling-explorations/chore/cons…
Browse files Browse the repository at this point in the history
…traints-info

chore(circuits): add constraint info print script
  • Loading branch information
0xmad authored Aug 7, 2024
2 parents 18dbda3 + a9cc93e commit bc6b5ed
Show file tree
Hide file tree
Showing 3 changed files with 304 additions and 16 deletions.
2 changes: 2 additions & 0 deletions packages/circuits/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"build-test-circuits-c": "ts-node ./ts/compile.ts --cWitness",
"build-test-circuits-wasm": "ts-node ./ts/compile.ts",
"gen-zkeys": "ts-node ./ts/genZkeys.ts",
"info": "NODE_OPTIONS=--max-old-space-size=4096 ts-node ./ts/info.ts",
"watch": "tsc --watch",
"build": "tsc -p tsconfig.build.json",
"circom:build": "NODE_OPTIONS=--max-old-space-size=4096 circomkit compile",
Expand Down Expand Up @@ -55,6 +56,7 @@
"chai": "^4.3.10",
"chai-as-promised": "^7.1.2",
"fast-check": "^3.20.0",
"glob": "^11.0.0",
"mocha": "^10.7.0",
"ts-mocha": "^10.0.0",
"ts-node": "^10.9.1",
Expand Down
47 changes: 47 additions & 0 deletions packages/circuits/ts/info.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { glob } from "glob";

import childProcess from "child_process";
import fs from "fs";
import path from "path";

import type { CircuitConfig } from "circomkit";

export async function info(zkeysPath: string): Promise<void> {
const files = await glob("**/*.r1cs", { cwd: zkeysPath });

const circuitsConfigPath = path.resolve(__dirname, "..", "circom", "circuits.json");
const circuitsConfig = JSON.parse(await fs.promises.readFile(circuitsConfigPath, "utf-8")) as unknown as Record<
string,
CircuitConfig
>;

const params = files
.map((file) => ({ config: circuitsConfig[file.split("/")[0]], file }))
.reduce<Record<string, string>>((acc, { config, file }) => {
acc[file] = `${config.template} [${config.params?.toString()}]`;

return acc;
}, {});

const { promisify } = await import("util");
const execFile = promisify(childProcess.execFile);

const data: { stdout: string; stderr: string }[] = [];

// eslint-disable-next-line @typescript-eslint/prefer-for-of
for (let index = 0; index < files.length; index += 1) {
// eslint-disable-next-line no-await-in-loop
const result = await execFile("snarkjs", ["r1cs", "info", path.resolve(zkeysPath, files[index])]);
data.push(result);
}

// eslint-disable-next-line no-console
console.log(data.map(({ stdout }, index) => `${files[index]}\n${params[files[index]]}\n${stdout}`).join("\n"));
}

if (require.main === module) {
(async () => {
await info(process.argv[process.argv.indexOf("--zkeys") + 1]);
})();
}
Loading

0 comments on commit bc6b5ed

Please sign in to comment.