From 4c121ca0413495979be7af87da5474a9f0b093bf Mon Sep 17 00:00:00 2001 From: 0xmad <0xmad@users.noreply.github.com> Date: Mon, 15 Jan 2024 16:12:53 -0600 Subject: [PATCH] fix(circuits): replace execSync with execFileSync --- circuits/ts/compile.ts | 5 +++-- circuits/ts/proofs.ts | 18 +++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/circuits/ts/compile.ts b/circuits/ts/compile.ts index 2ff04f9861..8187c24c66 100644 --- a/circuits/ts/compile.ts +++ b/circuits/ts/compile.ts @@ -1,6 +1,6 @@ import { type CircomkitConfig, type CircuitConfig, Circomkit } from "circomkit"; -import { execSync } from "child_process"; +import { execFileSync } from "child_process"; import fs from "fs"; import path from "path"; @@ -60,7 +60,8 @@ export const compileCircuits = async (cWitness?: boolean, outputPath?: string): if (cWitness) { try { // build - execSync(`cd ${outPath}/${circuit.name}_cpp && make`); + execFileSync("cd", [`${outPath}/${circuit.name}_cpp`]); + execFileSync("make"); } catch (error) { throw new Error(`Failed to compile the c witness for ${circuit.name}`); } diff --git a/circuits/ts/proofs.ts b/circuits/ts/proofs.ts index 8446b40a42..78e6a64eb5 100644 --- a/circuits/ts/proofs.ts +++ b/circuits/ts/proofs.ts @@ -8,7 +8,7 @@ import { type ISnarkJSVerificationKey, } from "snarkjs"; -import { execSync } from "child_process"; +import { execFileSync } from "child_process"; import fs from "fs"; import { tmpdir } from "os"; import path from "path"; @@ -73,21 +73,21 @@ export const genProof = async ({ fs.writeFileSync(inputJsonPath, jsonData); // Generate the witness - const witnessGenCmd = `${witnessExePath} ${inputJsonPath} ${outputWtnsPath}`; - - execSync(witnessGenCmd, { stdio: silent ? "ignore" : "pipe" }); + execFileSync(witnessExePath!, [inputJsonPath, outputWtnsPath], { stdio: silent ? "ignore" : "pipe" }); if (!fs.existsSync(outputWtnsPath)) { - throw new Error(`Error executing ${witnessGenCmd}`); + throw new Error(`Error executing ${witnessExePath} ${inputJsonPath} ${outputWtnsPath}`); } // Generate the proof - const proofGenCmd = `${rapidsnarkExePath} ${zkeyPath} ${outputWtnsPath} ${proofJsonPath} ${publicJsonPath}`; - - execSync(proofGenCmd, { stdio: silent ? "ignore" : "pipe" }); + execFileSync(rapidsnarkExePath!, [zkeyPath, outputWtnsPath, proofJsonPath, publicJsonPath], { + stdio: silent ? "ignore" : "pipe", + }); if (!fs.existsSync(proofJsonPath)) { - throw new Error(`Error executing ${proofGenCmd}`); + throw new Error( + `Error executing ${rapidsnarkExePath} ${zkeyPath} ${outputWtnsPath} ${proofJsonPath} ${publicJsonPath}`, + ); } // Read the proof and public inputs