@@ -13,22 +13,20 @@ async function convertVkBinaryToFields(vkDirPath: string, vkAsFieldsPath: string
1313 const vkPath = path . join ( vkDirPath , 'vk' ) ;
1414 const vkHashPath = path . join ( vkDirPath , 'vk_hash' ) ;
1515
16- // Read binary files
1716 const vkBinary = await readFile ( vkPath ) ;
1817 const vkHashBinary = await readFile ( vkHashPath ) ;
1918
20- // Use official bb.js API to convert VK to fields
19+ // convert VK to fields
2120 const api = await BarretenbergAPI . new ( { threads : 1 } ) ;
2221 try {
2322 const result = await api . vkAsFields ( { verificationKey : vkBinary } ) ;
2423
25- // Convert Fr objects (Uint8Array) to hex strings
24+ // Convert Fr objects to hex strings
2625 const vkAsFields = result . fields . map ( ( field ) => '0x' + Buffer . from ( field ) . toString ( 'hex' ) ) ;
2726
28- // Convert hash to hex string
2927 const vkHash = '0x' + vkHashBinary . toString ( 'hex' ) ;
3028
31- // Write as JSON: [vkHash, ...vkAsFields]
29+ // write as JSON
3230 await writeObject ( [ vkHash , ...vkAsFields ] , vkAsFieldsPath ) ;
3331 } finally {
3432 await api . destroy ( ) ;
@@ -46,30 +44,23 @@ export async function generateVk(
4644 let artifact : CompiledCircuit ;
4745
4846 if ( typeof bytecodeOrArtifact === 'string' ) {
49- // Legacy: just bytecode string - create minimal artifact
50- // bb expects circuit JSON (not raw bytecode) when file has .json extension
47+ // bb expects circuit JSON when file has .json extension
5148 artifact = {
5249 noir_version : '1.0.0' ,
5350 hash : 0 ,
5451 abi : { parameters : [ ] , return_type : null , error_types : { } } ,
55- bytecode : bytecodeOrArtifact , // Keep compressed - bb handles decompression
52+ bytecode : bytecodeOrArtifact
5653 } as any ;
5754 } else {
58- // New: full artifact - use as-is
59- // bb expects bytecode to remain compressed (gzipped + base64)
6055 artifact = bytecodeOrArtifact ;
6156 }
6257
63- // Write circuit JSON to temp file
64- // bb reads .json files as JSON format and decompresses bytecode internally
6558 await writeFile ( acirPath , JSON . stringify ( artifact ) ) ;
6659
6760 const barretenberg = await Barretenberg . create ( ) ;
68- // write_vk creates a directory with 'vk' and 'vk_hash' files
6961 await barretenberg . writeVK ( acirPath , vkPath ) ;
7062
7163 // Convert binary VK files to field representation
72- // vk_as_fields CLI command was removed in newer bb, so we do it in TypeScript
7364 await convertVkBinaryToFields ( vkPath , vkAsFieldsPath ) ;
7465 } ) ;
7566}
0 commit comments