Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(circuits): add constraint info print script #1749

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading