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

version check for circuit tooling #108

Merged
merged 1 commit into from
Dec 10, 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
1 change: 1 addition & 0 deletions zkp/circuits/gen-config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"circomVersion": "2.1.9",
"anon": {
"ptau": "powersOfTau28_hez_final_12",
"batchPtau": "powersOfTau28_hez_final_14",
Expand Down
61 changes: 57 additions & 4 deletions zkp/circuits/gen.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ console.log(
"\n",
);

// load circuits
// load genConfig

const circuits = require("./gen-config.json");
const genConfig = require("./gen-config.json");

const toCamelCase = (str) => {
return str
Expand Down Expand Up @@ -243,14 +243,14 @@ const run = async () => {

// if specific circuits are provided, check it's in the map
for (const circuit of onlyCircuits) {
if (!circuits[circuit]) {
if (!genConfig[circuit]) {
console.error(`Error: Unknown circuit: ${circuit}`);
process.exit(1);
}
}
}

const circuitsArray = Object.entries(circuits);
const circuitsArray = Object.entries(genConfig);
const activePromises = new Set();

for (const [
Expand All @@ -261,6 +261,59 @@ const run = async () => {
continue;
}

let snarkjsVersion;
// first check cirom version and snarkjs version matches the one in the package.json
try {
const { stdout: circomVersion } = await execAsync("circom --version");
// Trigger error to get snarkjs version
try {
await execAsync("npx snarkjs --version");
} catch (error) {
// Extract snarkjs version from error message
snarkjsVersion = error.stdout.match(/snarkjs@([\d.]+)/)?.[1];
if (!snarkjsVersion) {
throw new Error(
"Failed to extract SnarkJS version from error output.",
);
}
}
const { stdout: packageJson } = await execAsync("cat package.json");

const packageJsonObj = JSON.parse(packageJson);
const expectedCircomVersion = genConfig.circomVersion;

// Sanitize and extract version numbers
const circomVersionTrimmed = circomVersion
.trim()
.replace("circom compiler ", "");
let hasMismatch = false;
if (circomVersionTrimmed !== expectedCircomVersion) {
console.error(
`Error: circom version mismatch with the version in gen-config.json :\n` +
`\tExpected circom: ${expectedCircomVersion}, got: ${circomVersionTrimmed}\n` +
`\tFollow https://docs.circom.io/getting-started/installation/ to update your circom\n`,
);
hasMismatch = true;
}

if (snarkjsVersion !== packageJsonObj.devDependencies.snarkjs) {
console.error(
`Error: snarkjs version mismatch with package.json:\n` +
`\tExpected snarkjs: ${packageJsonObj.devDependencies.snarkjs}, got: ${snarkjsVersion}\n` +
`\tUse npm to update your snarkjs node module\n`,
);
hasMismatch = true;
}
if (hasMismatch) {
process.exit(1);
}

console.log("Version check passed.");
} catch (error) {
console.error(`An error occurred: ${error.message}`);
process.exit(1);
}

const pcPromise = processCircuit(circuit, ptau, skipSolidityGenaration);
activePromises.add(pcPromise);

Expand Down
Loading