From 11b9a09fdc6ed040400fe77d761385038091fe54 Mon Sep 17 00:00:00 2001 From: Chengxuan Xing Date: Thu, 26 Sep 2024 14:50:47 +0100 Subject: [PATCH] fixing gen command Signed-off-by: Chengxuan Xing --- zkp/circuits/gen.js | 45 +++++++++++++++++++++++++++++++++++++++------ zkp/js/README.md | 1 + 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/zkp/circuits/gen.js b/zkp/circuits/gen.js index b3fb1dd..9ebd25b 100644 --- a/zkp/circuits/gen.js +++ b/zkp/circuits/gen.js @@ -5,7 +5,39 @@ const { promisify } = require('util'); const axios = require('axios'); const yargs = require('yargs/yargs'); const { hideBin } = require('yargs/helpers'); -const argv = yargs(hideBin(process.argv)).argv; +const argv = yargs(hideBin(process.argv)) + .option('c', { + alias: 'circuit', + describe: 'Specify a single circuit to build', + type: 'string', + }) + .option('v', { + alias: 'verbose', + describe: 'Enable verbose mode', + type: 'boolean', + default: false, + }) + .option('cp', { + alias: 'compileOnly', + describe: 'Compile only', + type: 'boolean', + default: false, + }) + .option('cr', { + alias: 'circuitsRoot', + describe: 'Specify the root folder for storing circuits compilation files', + type: 'string', + }) + .option('pk', { + alias: 'provingKeysRoot', + describe: 'Specify the root folder for storing generated proving keys', + type: 'string', + }) + .option('pt', { + alias: 'ptauDownloadPath', + describe: 'Specify the root folder for storing downloaded PTAU', + type: 'string', + }).argv; const circuitsRoot = process.env.CIRCUITS_ROOT || argv.circuitsRoot; const provingKeysRoot = process.env.PROVING_KEYS_ROOT || argv.provingKeysRoot; @@ -37,6 +69,7 @@ console.log( { specificCircuits, compileOnly, + verbose, parallelLimit, circuitsRoot, provingKeysRoot, @@ -102,7 +135,7 @@ const processCircuit = async (circuit, ptau, skipSolidityGenaration) => { } log(circuit, `Compiling circuit`); - const { cmOut, cmErr } = await execAsync( + const { stdout: cmOut, stderr: cmErr } = await execAsync( `circom ${circomInput} --output ${circuitsRoot} --sym --wasm` ); if (verbose) { @@ -117,7 +150,7 @@ const processCircuit = async (circuit, ptau, skipSolidityGenaration) => { return; } - const { ctOut, ctErr } = await execAsync( + const { stdout: ctOut, stderr: ctErr } = await execAsync( `circom ${circomInput} --output ${provingKeysRoot} --r1cs` ); if (verbose) { @@ -130,7 +163,7 @@ const processCircuit = async (circuit, ptau, skipSolidityGenaration) => { } log(circuit, `Generating test proving key with ${ptau}`); - const { pkOut, pkErr } = await execAsync( + const { stdout: pkOut, stderr: pkErr } = await execAsync( `npx snarkjs groth16 setup ${path.join( provingKeysRoot, `${circuit}.r1cs` @@ -145,7 +178,7 @@ const processCircuit = async (circuit, ptau, skipSolidityGenaration) => { } } log(circuit, `Exporting verification key`); - const { vkOut, vkErr } = await execAsync( + const { stdout: vkOut, stderr: vkErr } = await execAsync( `npx snarkjs zkey export verificationkey ${zkeyOutput} ${path.join( provingKeysRoot, `${circuit}-vkey.json` @@ -173,7 +206,7 @@ const processCircuit = async (circuit, ptau, skipSolidityGenaration) => { 'lib', `verifier_${circuit}.sol` ); - const { svOut, svErr } = await execAsync( + const { stdout: svOut, stderr: svErr } = await execAsync( `npx snarkjs zkey export solidityverifier ${zkeyOutput} ${solidityFile}` ); if (verbose) { diff --git a/zkp/js/README.md b/zkp/js/README.md index 86bdaf5..d2bd54d 100644 --- a/zkp/js/README.md +++ b/zkp/js/README.md @@ -39,6 +39,7 @@ npm i npm run gen ``` **run `npm run gen -- -c $circuit` for developing a single circuit** + **run `npm run gen -- -v` to show details outputs of each command** **use `GEN_CONCURRENCY` to control how many circuits to be processed in parallel, default to 10** > Refer to [generation script explanation](#generation-script-explanation) for what the script does