Skip to content

Commit

Permalink
version check for circuit tooling
Browse files Browse the repository at this point in the history
Signed-off-by: Chengxuan Xing <[email protected]>
  • Loading branch information
Chengxuan committed Dec 7, 2024
1 parent b14ad5c commit 23590e2
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 4 deletions.
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

0 comments on commit 23590e2

Please sign in to comment.