Skip to content

Commit dc84860

Browse files
committed
vk generation
1 parent e3560af commit dc84860

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

ethereum/oracles/src/noir/circuit/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ Unfortunately `nargo` does not generate any of the recursion artifacts. Noir tea
1919
- Compiled artifact - `target/${name}.json`
2020
- generated from code using `nargo compile --package ${name}`
2121
- It's a JSON that contains [`base64`](https://en.wikipedia.org/wiki/Base64) encoded bytecode under the `.bytecode` key
22+
- The bytecode is gzip-compressed before base64 encoding
2223
- Acir bytecode
23-
- generated from **compiled artifact** by taking the bytecode and decoding it as `base64`, as **bb** expects it in plain binary form. We use a temp file for it as it's fast to generate and we only use it during **VK** generation
24+
- generated from **compiled artifact** by decoding the bytecode from `base64` and decompressing it (gzipped), as **bb** expects it in plain binary form. We use a temp file for it as it's fast to generate and we only use it during **VK** generation
2425
- VK - `target/${name}.vk.bin`
2526
- verification key is generated from **acir bytecode** by running:
2627
- `./bb write_vk -b ${acirPath} -o ${vkPath}`

ethereum/oracles/src/noir/circuit/vk.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
import { readObject, withTempFile } from '../../util/file.js';
22
import { writeFile } from 'fs/promises';
3+
import { gunzipSync } from 'zlib';
34
import { Barretenberg } from './barretenberg.js';
45

56
export async function generateVk(bytecode: string, vkPath: string, vkAsFieldsPath: string): Promise<void> {
67
return await withTempFile(async (acirPath) => {
7-
await writeFile(acirPath, Buffer.from(bytecode, 'base64'));
8+
// Decode base64 bytecode
9+
const compressedBytecode = Buffer.from(bytecode, 'base64');
10+
// Decompress if gzipped (Nargo compresses bytecode before base64 encoding)
11+
const decompressedBytecode = compressedBytecode[0] === 0x1f && compressedBytecode[1] === 0x8b
12+
? gunzipSync(compressedBytecode)
13+
: compressedBytecode;
14+
15+
await writeFile(acirPath, decompressedBytecode);
816

917
const barretenberg = await Barretenberg.create();
1018
await barretenberg.writeVK(acirPath, vkPath);

0 commit comments

Comments
 (0)