Skip to content

Commit 006b04d

Browse files
authored
feat!: update to 0.82.3 using bb.js (#8)
Update to 0.82.3 and use bb.js to generate solidity verifiers. Supersedes #7 as noir-wasm does not fully support nested deps & workspaces. closes #4
1 parent efe2686 commit 006b04d

File tree

10 files changed

+67
-138
lines changed

10 files changed

+67
-138
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.DS_Store
2+
13
/dist
24

35
# Logs

README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ This plugin automatically manages `nargo` and `bb` versions and compiles Noir on
1515
Install the plugin and Noir dependencies:
1616

1717
```bash
18-
npm install hardhat-plugin-noir @noir-lang/[email protected].1 @aztec/bb.js@0.67.0
18+
npm install hardhat-plugin-noir @noir-lang/[email protected].3 @aztec/bb.js@0.82.3
1919
```
2020

2121
Import the plugin in your `hardhat.config.ts`:
@@ -34,7 +34,7 @@ const config: HardhatUserConfig = {
3434
settings: { optimizer: { enabled: true, runs: 100000000 } },
3535
},
3636
noir: {
37-
version: "1.0.0-beta.1",
37+
version: "1.0.0-beta.3",
3838
},
3939
};
4040
```
@@ -106,7 +106,7 @@ it("proves and verifies on-chain", async () => {
106106

107107
// Verify the proof on-chain
108108
// slice the proof to remove length information
109-
const result = await contract.verify(proof.slice(4), input.y);
109+
const result = await contract.verify(proof, input.y);
110110
expect(result).to.eq(true);
111111

112112
// You can also verify in JavaScript.
@@ -145,9 +145,7 @@ Configure Noir and Barretenberg (bb) versions in `hardhat.config.ts`:
145145
export default {
146146
noir: {
147147
// Noir version, optional, will use the latest known Noir version by default
148-
version: "1.0.0-beta.1",
149-
// bb version, optional, will be inferred if possible
150-
bbVersion: "0.67.0",
148+
version: "1.0.0-beta.3",
151149
},
152150
};
153151
```

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hardhat-plugin-noir",
3-
"version": "0.3.1",
3+
"version": "0.4.0",
44
"description": "Hardhat plugin for Noir language",
55
"repository": "github:olehmisar/hardhat-noir",
66
"author": "Oleh Misarosh <[email protected]>",
@@ -18,8 +18,8 @@
1818
],
1919
"scripts": {
2020
"lint:fix": "prettier --write 'src/**/*.{js,ts}' 'test/**/*.{js,ts}'",
21-
"lint": "tsc --noEmit && prettier --check 'src/**/*.{js,ts}' 'test/**/*.{js,ts}'",
22-
"test": "mocha --exit --recursive 'test/**/*.test.ts' && tsc --noEmit",
21+
"lint": "tsc --noEmit --skipLibCheck && prettier --check 'src/**/*.{js,ts}' 'test/**/*.{js,ts}'",
22+
"test": "mocha --exit --recursive 'test/**/*.test.ts' && pnpm lint",
2323
"build": "rm -rf dist && tsc",
2424
"watch": "tsc -w",
2525
"prepublishOnly": "pnpm test && pnpm build"
@@ -31,8 +31,7 @@
3131
"README.md"
3232
],
3333
"devDependencies": {
34-
"@aztec/bb.js": "0.67.0",
35-
"@noir-lang/noir_js": "1.0.0-beta.1",
34+
"@noir-lang/noir_js": "1.0.0-beta.3",
3635
"@nomicfoundation/hardhat-ethers": "^3.0.8",
3736
"@types/chai": "^5.0.0",
3837
"@types/mocha": "^10.0.9",
@@ -48,6 +47,7 @@
4847
"hardhat": "^2.0.0"
4948
},
5049
"dependencies": {
50+
"@aztec/bb.js": ">=0.82.0",
5151
"glob": "^11.0.0",
5252
"zod": "^3.23.8"
5353
}

pnpm-lock.yaml

Lines changed: 29 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,26 +42,13 @@ extendConfig(
4242
function resolveNoirConfig(
4343
u: HardhatUserConfig["noir"],
4444
): HardhatConfig["noir"] {
45-
const bbVersionMap: Record<string, string> = {
46-
"1.0.0-beta.1": "0.67.0",
47-
};
48-
u = u || {};
49-
const version = u.version;
50-
const bbVersion = u.bbVersion ?? bbVersionMap[version];
51-
if (!bbVersion) {
52-
throw new HardhatPluginError(
53-
PLUGIN_NAME,
54-
`cannot infer bb version for noir@${version}. Please specify \`noir.bbVersion\` in Hardhat config`,
55-
);
56-
}
5745
const flavor: ProofFlavor[] = u.flavor
5846
? Array.isArray(u.flavor)
5947
? u.flavor
6048
: [u.flavor]
6149
: [ProofFlavor.ultra_keccak_honk];
6250
return {
63-
version,
64-
bbVersion,
51+
version: u.version,
6552
flavor,
6653
skipNargoWorkspaceCheck: u.skipNargoWorkspaceCheck ?? false,
6754
};

src/install.ts

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ async function installNoirup() {
1111
const runCommand = makeRunCommand();
1212
console.log("Installing noirup");
1313
const installScript = await downloadScript(
14-
"https://raw.githubusercontent.com/noir-lang/noirup/main/install",
14+
"https://raw.githubusercontent.com/noir-lang/noirup/refs/heads/main/install",
1515
);
1616
await runCommand("bash", ["-c", installScript]);
1717
}
@@ -48,51 +48,6 @@ async function getNargoHome() {
4848
return path.join(os.homedir(), ".nargo");
4949
}
5050

51-
async function installBbup() {
52-
const path = await import("path");
53-
const fs = await import("fs");
54-
const bbupBinary = path.join(await getBbHome(), "bbup");
55-
if (!fs.existsSync(bbupBinary)) {
56-
const runCommand = makeRunCommand();
57-
console.log("Installing bbup");
58-
const installScript = await downloadScript(
59-
"https://raw.githubusercontent.com/AztecProtocol/aztec-packages/master/barretenberg/cpp/installation/install",
60-
);
61-
await runCommand("bash", ["-c", installScript]);
62-
}
63-
return bbupBinary;
64-
}
65-
66-
export async function installBb(bbVersion: string): Promise<string> {
67-
const bbupBinary = await installBbup();
68-
69-
const fs = await import("fs");
70-
const path = await import("path");
71-
const bbHome = await getBbHome();
72-
const bbBinary = path.join(
73-
bbHome,
74-
installationSeparator,
75-
`v${bbVersion}`,
76-
"bb",
77-
);
78-
if (!fs.existsSync(bbBinary)) {
79-
const runCommand = makeRunCommand();
80-
const bbDir = path.dirname(bbBinary);
81-
fs.mkdirSync(bbDir, { recursive: true });
82-
console.log(`Installing bb@${bbVersion} in ${bbDir}`);
83-
await runCommand(bbupBinary, ["-v", bbVersion], {
84-
env: { BB_HOME: bbDir },
85-
});
86-
}
87-
return bbBinary;
88-
}
89-
90-
async function getBbHome() {
91-
const os = await import("os");
92-
const path = await import("path");
93-
return path.join(os.homedir(), ".bb");
94-
}
95-
9651
async function downloadScript(url: string) {
9752
const res = await fetch(url);
9853
if (!res.ok) {

src/tasks.ts

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { task } from "hardhat/config";
77
import { HardhatPluginError } from "hardhat/plugins";
88
import { HardhatConfig } from "hardhat/types";
99
import { NoirCache } from "./cache";
10-
import { installBb, installNargo } from "./install";
10+
import { installNargo } from "./install";
1111
import { getTarget, ProofFlavor } from "./Noir";
1212
import { makeRunCommand, PLUGIN_NAME } from "./utils";
1313

@@ -19,7 +19,6 @@ task(TASK_COMPILE, "Compile and generate circuits and contracts").setAction(
1919
const runCommand = makeRunCommand(config.paths.noir);
2020

2121
const nargoBinary = await installNargo(config.noir.version);
22-
const bbBinary = await installBb(config.noir.bbVersion);
2322

2423
await checkNargoWorkspace(config);
2524
await addGitIgnore(noirDir);
@@ -45,13 +44,7 @@ task(TASK_COMPILE, "Compile and generate circuits and contracts").setAction(
4544
if (!config.noir.flavor.includes(flavor)) {
4645
continue;
4746
}
48-
await generateSolidityVerifier(
49-
config,
50-
file,
51-
bbBinary,
52-
targetDir,
53-
flavor,
54-
);
47+
await generateSolidityVerifier(file, targetDir, flavor);
5548
}
5649
await cache.saveJsonFileHash(file);
5750
}),
@@ -110,51 +103,46 @@ task(
110103
);
111104

112105
async function generateSolidityVerifier(
113-
config: HardhatConfig,
114106
file: string,
115-
bbBinary: string,
116107
targetDir: string,
117108
flavor: ProofFlavor,
118109
) {
119110
const path = await import("path");
111+
const fs = await import("fs");
112+
const { UltraHonkBackend, UltraPlonkBackend } = await import("@aztec/bb.js");
120113

121-
const runCommand = makeRunCommand(config.paths.noir);
122-
123-
const name = path.basename(file, ".json");
124-
console.log(`Generating Solidity ${flavor} verifier for ${name}...`);
125-
let writeVkCmd: string, contractCmd: string;
114+
let verifier: string;
115+
const program = JSON.parse(fs.readFileSync(file, "utf-8"));
126116
switch (flavor) {
127117
case "ultra_plonk": {
128-
writeVkCmd = "write_vk";
129-
contractCmd = "contract";
118+
const backend = new UltraPlonkBackend(program.bytecode);
119+
verifier = await backend.getSolidityVerifier();
130120
break;
131121
}
132122
case "ultra_keccak_honk": {
133-
writeVkCmd = "write_vk_ultra_keccak_honk";
134-
contractCmd = "contract_ultra_honk";
123+
const backend = new UltraHonkBackend(program.bytecode);
124+
const vk = await backend.getVerificationKey({ keccak: true });
125+
verifier = await backend.getSolidityVerifier(vk);
135126
break;
136127
}
137128
default: {
138129
flavor satisfies never;
139-
return;
130+
throw new HardhatPluginError(
131+
PLUGIN_NAME,
132+
`Unsupported Noir proof flavor: ${flavor}`,
133+
);
140134
}
141135
}
136+
if (typeof verifier !== "string") {
137+
// bug in bb types
138+
verifier = new TextDecoder().decode(verifier);
139+
}
140+
141+
const name = path.basename(file, ".json");
142+
console.log(`Generating Solidity ${flavor} verifier for ${name}...`);
142143
const nameSuffix =
143144
flavor === ProofFlavor.ultra_keccak_honk ? "" : `_${flavor}`;
144-
await runCommand(bbBinary, [
145-
writeVkCmd,
146-
"-b",
147-
`${targetDir}/${name}.json`,
148-
"-o",
149-
`${targetDir}/${name}${nameSuffix}_vk`,
150-
]);
151-
await runCommand(bbBinary, [
152-
contractCmd,
153-
"-k",
154-
`${targetDir}/${name}${nameSuffix}_vk`,
155-
"-o",
156-
`${targetDir}/${name}${nameSuffix}.sol`,
157-
]);
145+
fs.writeFileSync(path.join(targetDir, `${name}${nameSuffix}.sol`), verifier);
158146
console.log(`Generated Solidity ${flavor} verifier for ${name}`);
159147
}
160148

0 commit comments

Comments
 (0)