Skip to content
Open
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,15 @@ export interface CircomCircuitConfig {
zkey: string;
vkey: string;
beacon: string;
include: string[];
}

export interface CircomUserConfig {
inputBasePath?: string;
outputBasePath?: string;
ptau: string;
circuits: CircomCircuitUserConfig[];
include?: string[];
}

export interface CircomConfig {
Expand All @@ -121,6 +123,7 @@ export interface CircomConfig {
ptau: string;
ptauDownload: string | undefined;
circuits: CircomCircuitConfig[];
include: string[];
}

extendEnvironment((hre) => {
Expand Down Expand Up @@ -175,7 +178,7 @@ export const TASK_CIRCOM_TEMPLATE = "circom:template";
extendConfig((config: HardhatConfig, userConfig: Readonly<HardhatUserConfig>) => {
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(
Expand Down Expand Up @@ -241,6 +244,7 @@ extendConfig((config: HardhatConfig, userConfig: Readonly<HardhatUserConfig>) =>
r1cs: r1csPath,
zkey: zkeyPath,
vkey: vkeyPath,
include,
});
}
});
Expand Down Expand Up @@ -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: {
Expand Down