Skip to content

Commit

Permalink
chore: Generate declaration files for VKs (#7391)
Browse files Browse the repository at this point in the history
Follows the trick that @alexghr pulled for circuit and contracts
artifacts, this time for VKs. See #7181.
  • Loading branch information
spalladino authored Jul 9, 2024
1 parent 6b2a351 commit 7c96636
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,18 +184,22 @@ async function readVKFromS3(artifactName, artifactHash) {
if (process.env.DISABLE_VK_S3_CACHE) {
return;
}
const key = `${PREFIX}/${artifactName}-${artifactHash}.json`;

try {
const s3 = generateS3Client();
const { Body: response } = await s3.getObject({
Bucket: BUCKET_NAME,
Key: `${PREFIX}/${artifactName}-${artifactHash}.json`,
Key: key,
});

const result = JSON.parse(await response.transformToString());
return result;
} catch (err) {
console.warn("Could not read VK from remote cache", err.message);
console.warn(
`Could not read VK from remote cache at s3://${BUCKET_NAME}/${key}`,
err.message
);
return undefined;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,31 @@ import { fileURLToPath } from '@aztec/foundation/url';
import { readdir, writeFile } from 'fs/promises';
import { join } from 'path';

const content = `\
const contract = `\
import { type NoirCompiledCircuit } from '@aztec/types/noir';
const circuit: NoirCompiledCircuit;
export = circuit;
`;

const target = fileURLToPath(new URL('../../artifacts', import.meta.url).href);
const files = await readdir(target);
for (const file of files) {
// guard against running this script twice without cleaning the artifacts/ dir first
if (!file.endsWith('.json')) {
continue;
const vk = `\
const vk: { keyAsBytes: string; keyAsFields: string[] };
export = vk;
`;

async function generateDeclarationFor(target: string, content: string) {
const files = await readdir(target);
for (const file of files) {
// guard against running this script twice without cleaning the artifacts/ dir first
if (!file.endsWith('.json')) {
continue;
}
const name = file.replace('.json', '');
await writeFile(join(target, `${name}.d.json.ts`), content);
}
const name = file.replace('.json', '');
await writeFile(join(target, `${name}.d.json.ts`), content);
}

// Generate declaration files for contracts
await generateDeclarationFor(fileURLToPath(new URL('../../artifacts', import.meta.url).href), contract);

// Generate declaration files for vks
await generateDeclarationFor(fileURLToPath(new URL('../../artifacts/keys', import.meta.url).href), vk);
2 changes: 1 addition & 1 deletion yarn-project/noir-protocol-circuits-types/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@
"path": "../merkle-tree"
}
],
"include": ["src", "artifacts/*.d.json.ts"]
"include": ["src", "artifacts/*.d.json.ts", "artifacts/**/*.d.json.ts", ]
}

0 comments on commit 7c96636

Please sign in to comment.