Skip to content

Commit d1b9b8d

Browse files
authored
Merge pull request #94 from AztecProtocol/zpedro/noir_bb_honk
updating to 0.36.0 with oleh's Hardhat Plugin
2 parents ae3919d + 8060297 commit d1b9b8d

29 files changed

+204
-7652
lines changed

.github/workflows/vite_hardhat.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,8 @@ jobs:
2929
- name: Install dependencies
3030
run: bun install
3131

32+
- name: Compile
33+
run: bunx hardhat compile
34+
3235
- name: Run tests
3336
run: bun test

.github/workflows/vite_hardhat_nightly.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ jobs:
8282
@noir-lang/noir_wasm@${{ matrix.version }} \
8383
@noir-lang/types@${{ matrix.version }}
8484
85+
- name: Compile
86+
run: bunx hardhat compile
87+
8588
- name: Run tests
8689
run: bun test
8790

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "create-noir",
2+
"name": "noir-starter",
33
"version": "0.1.1",
44
"type": "module",
55
"description": "This is a reference repo to help you get started with writing zero-knowledge circuits with [Noir](https://noir-lang.org/).",

vite-hardhat/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,4 @@ artifacts
5656

5757
circuit/target/
5858
dist
59+
deployment.json

vite-hardhat/README.md

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,23 @@ Want to get started in a pinch? Start your project in a free Github Codespace!
2626
bun i # "npm i" or "yarn"
2727
```
2828

29-
3. Run the app
29+
3. Run a node
3030

31-
You can run a separate Ethereum node from the dev environment:
31+
```bash
32+
bunx hardhat node
33+
```
3234

33-
```bash
34-
bunx hardhat node
35-
```
35+
4. Deploy the verifier contract
3636

37-
and run the dev environment separately:
37+
```bash
38+
bun run deploy
39+
```
3840

39-
```bash
40-
bunx hardhat dev
41-
```
41+
5. Run the dev environment
42+
43+
```bash
44+
bun dev
45+
```
4246

4347
### Testing
4448

@@ -48,10 +52,7 @@ You can run the [example test file](./test/index.test.ts) with
4852
bun test
4953
```
5054

51-
This test shows the basic usage of Noir in a TypeScript Node.js environment.
52-
53-
> [!NOTE] The test is a script, not an executable (we're running `bun test` or `yarn test` instead
54-
> of `bunx` or `npx`). This is because the test runs its own network and executables.
55+
This test shows the basic usage of Noir in a TypeScript Node.js environment. It also starts its own network and deploys the verifier contract.
5556

5657
### Deploying on other networks
5758

@@ -69,12 +70,10 @@ network:
6970
bunx hardhat vars set holesky <your_testnet_private_key>
7071
```
7172

72-
You can then run all the commands using that network by passing the `--network` flag. For example:
73+
You can then deploy on that network by passing the `--network` flag. For example:
7374

7475
```bash
75-
bunx hardhat dev --network holesky # deploys and runs a development server on holesky
7676
bunx hardhat deploy --network holesky # deploys on holesky
77-
bunx hardhat build --network holesky # builds the frontend with the holesky target
7877
```
7978

8079
Feel free to add more networks, as long as they're supported by `wagmi`
@@ -83,13 +82,3 @@ Feel free to add more networks, as long as they're supported by `wagmi`
8382
- Have funds in these accounts
8483
- Add their configuration in the `networks` property in `hardhat.config.cts`
8584
- Use the name that wagmi expects (for example `ethereum` won't work, as `wagmi` calls it `mainnet`)
86-
87-
#### Attaching to an existing contract
88-
89-
You probably don't want to redeploy everytime you build your project. To attach the build to an
90-
already deployed contract, pass the `--attach` flag:
91-
92-
```bash
93-
bunx hardhat deploy --network mainnet # deploys on ethereum mainnet $$$$$!
94-
bunx hardhat dev --network mainnet --attach 0x<yourethereumcontract> # you're now developing using an existing verifier contract
95-
```

vite-hardhat/bun.lockb

142 KB
Binary file not shown.

vite-hardhat/hardhat.config.cts

Lines changed: 23 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -1,141 +1,34 @@
11
import '@nomicfoundation/hardhat-toolbox-viem';
22
import '@nomicfoundation/hardhat-viem';
33
import '@nomicfoundation/hardhat-chai-matchers';
4+
import 'hardhat-plugin-noir';
45

5-
import { HardhatUserConfig, scope, task, types } from 'hardhat/config';
6-
7-
import { subtask, vars } from 'hardhat/config';
8-
import { TASK_COMPILE_SOLIDITY } from 'hardhat/builtin-tasks/task-names';
9-
import { join, resolve } from 'path';
10-
import { writeFile } from 'fs/promises';
11-
import { mkdirSync, writeFileSync } from 'fs';
12-
import { gunzipSync } from 'zlib';
13-
import { Barretenberg, RawBuffer, Crs } from '@aztec/bb.js';
14-
import { createFileManager, compile } from '@noir-lang/noir_wasm';
15-
import { CompiledCircuit } from '@noir-lang/types';
16-
import { exec } from 'shelljs';
6+
import hre, { vars, HardhatUserConfig, task } from 'hardhat/config';
7+
import { writeFileSync } from 'fs';
178
import { Chain } from 'viem';
189

19-
subtask(TASK_COMPILE_SOLIDITY).setAction(async (_, { config }, runSuper) => {
20-
const superRes = await runSuper();
21-
22-
try {
23-
await writeFile(join(config.paths.root, 'artifacts', 'package.json'), '{ "type": "commonjs" }');
24-
} catch (error) {
25-
console.error('Error writing package.json: ', error);
26-
}
27-
28-
return superRes;
29-
});
30-
31-
export async function compileCircuit(path = './circuit') {
32-
const basePath = resolve(join(path));
33-
const fm = createFileManager(basePath);
34-
const result = await compile(fm);
35-
if (!('program' in result)) {
36-
throw new Error('Compilation failed');
37-
}
38-
return result.program as CompiledCircuit;
39-
}
10+
task('deploy', 'Deploys the verifier contract').setAction(async ({ attach }, hre) => {
11+
const verifier = await hre.viem.deployContract('UltraVerifier');
4012

41-
export async function generateArtifacts(path = './circuit', crsPath = './crs') {
42-
const circuit = await compileCircuit(path);
43-
const decompressed = gunzipSync(Buffer.from(circuit.bytecode, 'base64'));
44-
const api = await Barretenberg.new({ threads: 8 });
45-
const [exact, total, subgroup] = await api.acirGetCircuitSizes(decompressed, false);
46-
const subgroupSize = Math.pow(2, Math.ceil(Math.log2(total)));
13+
const networkConfig = (await import(`viem/chains`))[hre.network.name] as Chain;
14+
const config = {
15+
name: hre.network.name,
16+
address: verifier.address,
17+
networkConfig: {
18+
...networkConfig,
19+
id: hre.network.config.chainId,
20+
},
21+
};
4722

48-
const crs = await Crs.new(subgroupSize + 1, crsPath);
49-
await api.commonInitSlabAllocator(subgroupSize);
50-
await api.srsInitSrs(
51-
new RawBuffer(crs.getG1Data()),
52-
crs.numPoints,
53-
new RawBuffer(crs.getG2Data()),
23+
console.log(
24+
`Attached to address ${verifier.address} at network ${hre.network.name} with chainId ${networkConfig.id}...`,
5425
);
55-
56-
const acirComposer = await api.acirNewAcirComposer(subgroupSize);
57-
await api.acirInitProvingKey(acirComposer, decompressed);
58-
await api.acirInitVerificationKey(acirComposer);
59-
60-
const contract = await api.acirGetSolidityVerifier(acirComposer);
61-
return { circuit, contract };
62-
}
63-
64-
task('compile', 'Compile and generate circuits and contracts').setAction(
65-
async (_, __, runSuper) => {
66-
const { circuit, contract } = await generateArtifacts();
67-
mkdirSync('artifacts', { recursive: true });
68-
writeFileSync('artifacts/circuit.json', JSON.stringify(circuit), { flag: 'w' });
69-
writeFileSync('artifacts/contract.sol', contract, { flag: 'w' });
70-
await runSuper();
71-
},
72-
);
73-
74-
task('deploy', 'Deploys the verifier contract')
75-
.addOptionalParam('attach', 'Attach to an existing address', '', types.string)
76-
.setAction(async ({ attach }, hre) => {
77-
let verifier;
78-
if (attach) {
79-
verifier = await hre.viem.getContractAt('UltraVerifier', attach);
80-
} else {
81-
verifier = await hre.viem.deployContract('UltraVerifier');
82-
}
83-
84-
const networkConfig = (await import(`viem/chains`))[hre.network.name] as Chain;
85-
console.log(networkConfig);
86-
const config = {
87-
name: hre.network.name,
88-
address: verifier.address,
89-
networkConfig: {
90-
...networkConfig,
91-
id: hre.network.config.chainId || networkConfig.id,
92-
},
93-
};
94-
95-
console.log(
96-
`Attached to address ${verifier.address} at network ${hre.network.name} with chainId ${config.networkConfig.id}...`,
97-
);
98-
writeFileSync('artifacts/deployment.json', JSON.stringify(config), { flag: 'w' });
99-
});
100-
101-
subtask('generateHooks', 'Generates hooks for the verifier contract').setAction(async (_, hre) => {
102-
exec('wagmi generate');
103-
});
104-
105-
subtask('prep', 'Compiles and deploys the verifier contract')
106-
.addParam('attach', 'Attach to an already deployed contract', '', types.string)
107-
.setAction(async ({ attach }, hre) => {
108-
console.log('Preparing...');
109-
console.log('Compiling circuits and generating contracts...');
110-
111-
await hre.run('compile');
112-
await hre.run('deploy', { attach });
113-
114-
console.log('Generating hooks...');
115-
await hre.run('generateHooks');
116-
});
117-
118-
task('dev', 'Deploys and starts in a development environment')
119-
.addOptionalParam('attach', 'Attach to an existing address', '', types.string)
120-
.setAction(async ({ attach }, hre) => {
121-
await hre.run('prep', { attach });
122-
exec('vite dev');
123-
});
124-
125-
task('build', 'Builds the frontend project')
126-
.addOptionalParam('attach', 'Attach to an existing address', '', types.string)
127-
.setAction(async ({ attach }, hre) => {
128-
await hre.run('prep', { attach });
129-
exec('vite build');
130-
});
131-
132-
task('serve', 'Serves the frontend project').setAction(async (_, hre) => {
133-
exec('vite preview');
26+
writeFileSync('deployment.json', JSON.stringify(config), { flag: 'w' });
13427
});
13528

13629
const config: HardhatUserConfig = {
13730
solidity: {
138-
version: '0.8.18',
31+
version: '0.8.21',
13932
settings: {
14033
optimizer: { enabled: true, runs: 5000 },
14134
},
@@ -158,10 +51,12 @@ const config: HardhatUserConfig = {
15851
accounts: vars.has('holesky') ? [vars.get('holesky')] : [],
15952
},
16053
},
54+
noir: {
55+
version: '0.36.0',
56+
},
16157
paths: {
162-
root: './',
163-
sources: './artifacts',
164-
artifacts: './artifacts/hardhat',
58+
root: 'packages',
59+
tests: 'tests',
16560
},
16661
};
16762

vite-hardhat/package.json

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
{
2-
"name": "noir-starter",
3-
"version": "1.0.0",
4-
"type": "module",
2+
"name": "vite-hardhat",
53
"description": "A template repository to get started with writing zero knowledge programs with Noir.",
4+
"private": true,
5+
"workspaces": [
6+
"packages/*"
7+
],
68
"scripts": {
7-
"test": "test/test.sh"
9+
"deploy": "bunx hardhat compile && bunx hardhat deploy",
10+
"dev": "bun --filter vite dev",
11+
"test:hardhat": "bunx hardhat test",
12+
"node": "bunx hardhat node"
13+
},
14+
"type": "module",
15+
"devDependencies": {
16+
"hardhat-plugin-noir": "0.1.3",
17+
"@types/bun": "^1.1.12",
18+
"hardhat": "^2.19.2"
819
},
920
"dependencies": {
1021
"@aztec/bb.js": "^0.62.0",
@@ -13,44 +24,20 @@
1324
"@noir-lang/types": "0.36.0",
1425
"@nomicfoundation/hardhat-ignition": "^0.15.5",
1526
"@nomicfoundation/hardhat-ignition-viem": "^0.15.5",
16-
"@tanstack/query-sync-storage-persister": "5.0.5",
17-
"@tanstack/react-query": "5.44.0",
18-
"@tanstack/react-query-persist-client": "5.0.5",
1927
"commander": "^12.1.0",
2028
"dotenv": "^16.0.3",
21-
"hardhat": "^2.19.2",
22-
"react": "^18.2.0",
23-
"react-dom": "^18.2.0",
24-
"react-toastify": "^9.1.1",
2529
"shelljs": "^0.8.5",
26-
"tsx": "^4.15.4",
27-
"viem": "2.x",
28-
"wagmi": "2.10.0"
29-
},
30-
"devDependencies": {
31-
"@nomicfoundation/hardhat-chai-matchers": "^2.0.7",
3230
"@nomicfoundation/hardhat-ethers": "^3.0.6",
3331
"@nomicfoundation/hardhat-network-helpers": "^1.0.11",
3432
"@nomicfoundation/hardhat-toolbox-viem": "3.0.0",
3533
"@nomicfoundation/hardhat-verify": "^2.0.8",
3634
"@nomicfoundation/hardhat-viem": "2.0.2",
37-
"@tanstack/react-query-devtools": "5.0.5",
38-
"@types/bun": "^1.1.4",
3935
"@types/mocha": "^10.0.1",
40-
"@types/node": "^18.15.5",
41-
"@types/react": "^18.0.26",
4236
"@types/shelljs": "^0.8.7",
43-
"@vitejs/plugin-react-swc": "^3.5.0",
44-
"@wagmi/cli": "^2.1.10",
45-
"chai": "^4.2.0",
4637
"hardhat-gas-reporter": "^1.0.9",
47-
"solidity-coverage": "^0.8.5",
48-
"ts-node": "^10.9.1",
49-
"typechain": "^8.1.0",
50-
"typescript": "^4.9.3",
51-
"vite": "^5.0.6"
38+
"solidity-coverage": "^0.8.5"
5239
},
53-
"engines": {
54-
"node": "^20.10.0"
40+
"peerDependencies": {
41+
"typescript": "^5.0.0"
5542
}
5643
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
target
File renamed without changes.

0 commit comments

Comments
 (0)