From 6474c87f3de5477c3c164bc3cc75efcf59d4f102 Mon Sep 17 00:00:00 2001 From: Franco Mangone Date: Fri, 6 Dec 2024 12:07:40 -0300 Subject: [PATCH] feat: reads includes from config and adds flags to circom call --- README.md | 2 ++ src/index.ts | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 14bae9a..261893e 100644 --- a/README.md +++ b/README.md @@ -104,6 +104,8 @@ module.exports = { inputBasePath: "./mycircuits/", // (optional) Base path for files being output, defaults to `./circuits/` outputBasePath: "./client/", + // (optional) Include paths for circuits using libraries (adds `-l` flags to the circom call) + include: ["/path/to/include"], // (required) The final ptau file, relative to inputBasePath, from a Phase 1 ceremony ptau: "pot15_final.ptau", // (required) Each object in this array refers to a separate circuit diff --git a/src/index.ts b/src/index.ts index e797a01..b663939 100644 --- a/src/index.ts +++ b/src/index.ts @@ -106,6 +106,7 @@ export interface CircomCircuitConfig { zkey: string; vkey: string; beacon: string; + include: string[]; } export interface CircomUserConfig { @@ -113,6 +114,7 @@ export interface CircomUserConfig { outputBasePath?: string; ptau: string; circuits: CircomCircuitUserConfig[]; + include?: string[]; } export interface CircomConfig { @@ -121,6 +123,7 @@ export interface CircomConfig { ptau: string; ptauDownload: string | undefined; circuits: CircomCircuitConfig[]; + include: string[]; } extendEnvironment((hre) => { @@ -175,7 +178,7 @@ export const TASK_CIRCOM_TEMPLATE = "circom:template"; extendConfig((config: HardhatConfig, userConfig: Readonly) => { const { root } = config.paths; - const { inputBasePath, outputBasePath, ptau, circuits = [] } = userConfig.circom ?? {}; + const { inputBasePath, outputBasePath, ptau, circuits = [], include = [] } = userConfig.circom ?? {}; if (circuits.length === 0) { throw new HardhatPluginError( @@ -241,6 +244,7 @@ extendConfig((config: HardhatConfig, userConfig: Readonly) => r1cs: r1csPath, zkey: zkeyPath, vkey: vkeyPath, + include, }); } }); @@ -410,8 +414,9 @@ async function circom2({ circuit, debug }: { circuit: CircomCircuitConfig; debug }; }); + const includes = (circuit.include || []).flatMap(path => ["-l", path]) const circom = new CircomRunner({ - args: [circuit.circuit, "--r1cs", "--wat", "--wasm", "--sym", "-o", dir], + args: [circuit.circuit, ...includes, "--r1cs", "--wat", "--wasm", "--sym", "-o", dir], env: {}, // Preopen from the root because we use absolute paths preopens: {