Skip to content
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: 0 additions & 5 deletions src/Noir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,3 @@ export async function getTarget(noirDir: string | HardhatConfig) {
const path = await import("path");
return path.join(noirDir, "target");
}

export type ProofFlavor = keyof typeof ProofFlavor;
export const ProofFlavor = {
ultra_keccak_honk: "ultra_keccak_honk",
} as const;
11 changes: 2 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { extendConfig, extendEnvironment } from "hardhat/config";
import { HardhatPluginError, lazyObject } from "hardhat/plugins";
import { lazyObject } from "hardhat/plugins";
import { HardhatConfig, HardhatUserConfig } from "hardhat/types";
import path from "path";
import { NoirExtension, ProofFlavor } from "./Noir";
import { NoirExtension } from "./Noir";
import "./tasks";
import "./type-extensions";
import { PLUGIN_NAME } from "./utils";

extendConfig(
(config: HardhatConfig, userConfig: Readonly<HardhatUserConfig>) => {
Expand Down Expand Up @@ -42,14 +41,8 @@ extendConfig(
function resolveNoirConfig(
u: HardhatUserConfig["noir"],
): HardhatConfig["noir"] {
const flavor: ProofFlavor[] = u.flavor
? Array.isArray(u.flavor)
? u.flavor
: [u.flavor]
: [ProofFlavor.ultra_keccak_honk];
return {
version: u.version,
flavor,
skipNargoWorkspaceCheck: u.skipNargoWorkspaceCheck ?? false,
};
}
Expand Down
44 changes: 11 additions & 33 deletions src/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { HardhatPluginError } from "hardhat/plugins";
import { HardhatConfig } from "hardhat/types";
import { NoirCache } from "./cache";
import { installNargo } from "./install";
import { getTarget, ProofFlavor } from "./Noir";
import { getTarget } from "./Noir";
import { makeRunCommand, PLUGIN_NAME } from "./utils";

task(TASK_COMPILE, "Compile and generate circuits and contracts").setAction(
Expand Down Expand Up @@ -40,12 +40,7 @@ task(TASK_COMPILE, "Compile and generate circuits and contracts").setAction(
return;
}

for (const flavor of Object.values(ProofFlavor) as ProofFlavor[]) {
if (!config.noir.flavor.includes(flavor)) {
continue;
}
await generateSolidityVerifier(file, targetDir, flavor);
}
await generateSolidityVerifier(file, targetDir);
await cache.saveJsonFileHash(file);
}),
);
Expand Down Expand Up @@ -102,43 +97,26 @@ task(
},
);

async function generateSolidityVerifier(
file: string,
targetDir: string,
flavor: ProofFlavor,
) {
async function generateSolidityVerifier(file: string, targetDir: string) {
const path = await import("path");
const fs = await import("fs");
const { UltraHonkBackend } = await import("@aztec/bb.js");

let verifier: string;
const program = JSON.parse(fs.readFileSync(file, "utf-8"));
switch (flavor) {
case "ultra_keccak_honk": {
const backend = new UltraHonkBackend(program.bytecode);
const vk = await backend.getVerificationKey({ keccak: true });
verifier = await backend.getSolidityVerifier(vk);
break;
}
default: {
flavor satisfies never;
throw new HardhatPluginError(
PLUGIN_NAME,
`Unsupported Noir proof flavor: ${flavor}`,
);
}
}

const backend = new UltraHonkBackend(program.bytecode);
const vk = await backend.getVerificationKey({ keccak: true });
let verifier = await backend.getSolidityVerifier(vk);

if (typeof verifier !== "string") {
// bug in bb types
verifier = new TextDecoder().decode(verifier);
}

const name = path.basename(file, ".json");
console.log(`Generating Solidity ${flavor} verifier for ${name}...`);
const nameSuffix =
flavor === ProofFlavor.ultra_keccak_honk ? "" : `_${flavor}`;
fs.writeFileSync(path.join(targetDir, `${name}${nameSuffix}.sol`), verifier);
console.log(`Generated Solidity ${flavor} verifier for ${name}`);
console.log(`Generating Solidity verifier for ${name}...`);
fs.writeFileSync(path.join(targetDir, `${name}.sol`), verifier);
console.log(`Generated Solidity verifier for ${name}`);
}

async function checkNargoWorkspace(config: HardhatConfig) {
Expand Down
12 changes: 7 additions & 5 deletions src/type-extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// To extend one of Hardhat's types, you need to import the module where it has been defined, and redeclare it.
import "hardhat/types/config";
import "hardhat/types/runtime";
import { NoirExtension, ProofFlavor } from "./Noir";
import { NoirExtension } from "./Noir";

declare module "hardhat/types/config" {
// This is an example of an extension to one of the Hardhat config values.
Expand All @@ -28,15 +28,17 @@ declare module "hardhat/types/config" {
export interface HardhatUserConfig {
noir: {
version: string;
flavor?: ProofFlavor | ProofFlavor[];
/**
* @deprecated no longer used
*/
// TODO: remove this
flavor?: unknown;
skipNargoWorkspaceCheck?: boolean;
};
}

export interface HardhatConfig {
noir: Omit<Required<HardhatUserConfig["noir"]>, "flavor"> & {
flavor: ProofFlavor[];
};
noir: Omit<Required<HardhatUserConfig["noir"]>, "flavor">;
}
}

Expand Down
1 change: 0 additions & 1 deletion test/fixture-projects/hardhat-project/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const config: HardhatUserConfig = {
},
noir: {
version: TEST_NOIR_VERSION,
flavor: ["ultra_keccak_honk"],
},
};

Expand Down