Skip to content

Commit

Permalink
chore: Pw/refactor bb prover (#6349)
Browse files Browse the repository at this point in the history
This PR moves all native BB code into a new package used by both the
`pxe` for client circuits and the `prover-client` for server circuits.
This removes some of the duplication.

Some duplication is still present. This will remain until we know more
about the differences in proving client and server circuits.
  • Loading branch information
PhilWindle authored May 14, 2024
1 parent 219efd6 commit 8eb0398
Show file tree
Hide file tree
Showing 58 changed files with 915 additions and 548 deletions.
1 change: 1 addition & 0 deletions yarn-project/bb-prover/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('@aztec/foundation/eslint');
85 changes: 85 additions & 0 deletions yarn-project/bb-prover/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{
"name": "@aztec/bb-prover",
"version": "0.1.0",
"type": "module",
"exports": {
".": "./dest/index.js"
},
"bin": {
"bb-cli": "./dest/bb/index.js"
},
"typedocOptions": {
"entryPoints": [
"./src/index.ts"
],
"name": "BB Prover",
"tsconfig": "./tsconfig.json"
},
"inherits": [
"../package.common.json"
],
"scripts": {
"build": "yarn clean && tsc -b",
"build:dev": "tsc -b --watch",
"clean": "rm -rf ./dest .tsbuildinfo",
"formatting": "run -T prettier --check ./src && run -T eslint ./src",
"formatting:fix": "run -T eslint --fix ./src && run -T prettier -w ./src",
"bb": "node --no-warnings ./dest/bb/index.js",
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests"
},
"jest": {
"moduleNameMapper": {
"^(\\.{1,2}/.*)\\.[cm]?js$": "$1"
},
"testRegex": "./src/.*\\.test\\.(js|mjs|ts)$",
"rootDir": "./src",
"transform": {
"^.+\\.tsx?$": [
"@swc/jest"
]
},
"extensionsToTreatAsEsm": [
".ts"
],
"reporters": [
[
"default",
{
"summaryThreshold": 9999
}
]
]
},
"dependencies": {
"@aztec/circuit-types": "workspace:^",
"@aztec/circuits.js": "workspace:^",
"@aztec/foundation": "workspace:^",
"@aztec/noir-protocol-circuits-types": "workspace:^",
"@aztec/simulator": "workspace:^",
"@noir-lang/noirc_abi": "portal:../../noir/packages/noirc_abi",
"@noir-lang/types": "portal:../../noir/packages/types",
"commander": "^9.0.0",
"source-map-support": "^0.5.21",
"tslib": "^2.4.0"
},
"devDependencies": {
"@jest/globals": "^29.5.0",
"@types/jest": "^29.5.0",
"@types/memdown": "^3.0.0",
"@types/node": "^18.7.23",
"@types/source-map-support": "^0.5.10",
"jest": "^29.5.0",
"jest-mock-extended": "^3.0.3",
"ts-node": "^10.9.1",
"typescript": "^5.0.4"
},
"files": [
"dest",
"src",
"!*.test.*"
],
"types": "./dest/index.d.ts",
"engines": {
"node": ">=18"
}
}
92 changes: 92 additions & 0 deletions yarn-project/bb-prover/src/bb/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { type LogFn } from '@aztec/foundation/log';
import { type ProtocolArtifact, ProtocolCircuitArtifacts } from '@aztec/noir-protocol-circuits-types';

import { Command } from 'commander';
import * as fs from 'fs/promises';

import { generateKeyForNoirCircuit } from './execute.js';

const { BB_WORKING_DIRECTORY, BB_BINARY_PATH } = process.env;

/**
* Returns commander program that defines the CLI.
* @param log - Console logger.
* @returns The CLI.
*/
export function getProgram(log: LogFn): Command {
const program = new Command();

program.name('bb-cli').description('CLI for interacting with Barretenberg.');

program
.command('protocol-circuits')
.description('Lists the available protocol circuit artifacts')
.action(() => {
log(Object.keys(ProtocolCircuitArtifacts).reduce((prev: string, x: string) => prev.concat(`\n${x}`)));
});

program
.command('write-pk')
.description('Generates the proving key for the specified circuit')
.requiredOption(
'-w, --working-directory <string>',
'A directory to use for storing input/output files',
BB_WORKING_DIRECTORY,
)
.requiredOption('-b, --bb-path <string>', 'The path to the BB binary', BB_BINARY_PATH)
.requiredOption('-c, --circuit <string>', 'The name of a protocol circuit')
.action(async options => {
const compiledCircuit = ProtocolCircuitArtifacts[options.circuit as ProtocolArtifact];
if (!compiledCircuit) {
log(`Failed to find circuit ${options.circuit}`);
return;
}
try {
await fs.access(options.workingDirectory, fs.constants.W_OK);
} catch (error) {
log(`Working directory does not exist`);
return;
}
await generateKeyForNoirCircuit(
options.bbPath,
options.workingDirectory,
options.circuit,
compiledCircuit,
'pk',
log,
);
});

program
.command('write-vk')
.description('Generates the verification key for the specified circuit')
.requiredOption(
'-w, --working-directory <string>',
'A directory to use for storing input/output files',
BB_WORKING_DIRECTORY,
)
.requiredOption('-b, --bb-path <string>', 'The path to the BB binary', BB_BINARY_PATH)
.requiredOption('-c, --circuit <string>', 'The name of a protocol circuit')
.action(async options => {
const compiledCircuit = ProtocolCircuitArtifacts[options.circuit as ProtocolArtifact];
if (!compiledCircuit) {
log(`Failed to find circuit ${options.circuit}`);
return;
}
try {
await fs.access(options.workingDirectory, fs.constants.W_OK);
} catch (error) {
log(`Working directory does not exist`);
return;
}
await generateKeyForNoirCircuit(
options.bbPath,
options.workingDirectory,
options.circuit,
compiledCircuit,
'vk',
log,
);
});
return program;
}
Loading

0 comments on commit 8eb0398

Please sign in to comment.