11import '@nomicfoundation/hardhat-toolbox-viem' ;
22import '@nomicfoundation/hardhat-viem' ;
33import '@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' ;
178import { 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
13629const 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
0 commit comments