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

fix(circuits): replace execSync with execFileSync #1029

Merged
merged 1 commit into from
Jan 16, 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
5 changes: 3 additions & 2 deletions circuits/ts/compile.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -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}`);
}
Expand Down
18 changes: 9 additions & 9 deletions circuits/ts/proofs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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
Expand Down
Loading