@@ -7,7 +7,7 @@ import { task } from "hardhat/config";
77import { HardhatPluginError } from "hardhat/plugins" ;
88import { HardhatConfig } from "hardhat/types" ;
99import { NoirCache } from "./cache" ;
10- import { installBb , installNargo } from "./install" ;
10+ import { installNargo } from "./install" ;
1111import { getTarget , ProofFlavor } from "./Noir" ;
1212import { 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
112105async 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