From 2882d97f5165239badb328be80568e7d683c0465 Mon Sep 17 00:00:00 2001 From: kevaundray Date: Tue, 5 Sep 2023 20:55:46 +0100 Subject: [PATCH] feat: Add `info` command to bb (#2010) Resolves #1922 Resolves #1923 # Checklist: Remove the checklist to signal you've completed it. Enable auto-merge if the PR is ready to merge. - [ ] If the pull request requires a cryptography review (e.g. cryptographic algorithm implementations) I have added the 'crypto' tag. - [ ] I have reviewed my diff in github, line by line and removed unexpected formatting changes, testing logs, or commented-out code. - [ ] Every change is related to the PR description. - [ ] I have [linked](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue) this pull request to relevant issues (if any exist). --------- Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com> --- cpp/src/barretenberg/bb/main.cpp | 36 ++++++++++++++++++++++++++++++++ ts/src/info.json | 22 +++++++++++++++++++ ts/src/main.ts | 22 ++++++++++++++++++- ts/tsconfig.json | 2 +- 4 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 ts/src/info.json diff --git a/cpp/src/barretenberg/bb/main.cpp b/cpp/src/barretenberg/bb/main.cpp index 3b527b5db..c6a58b5e0 100644 --- a/cpp/src/barretenberg/bb/main.cpp +++ b/cpp/src/barretenberg/bb/main.cpp @@ -269,6 +269,39 @@ void vkAsFields(const std::string& vk_path, const std::string& output_path) } } +/** + * @brief Returns ACVM related backend information + * + * Communication: + * - stdout: The json string is written to stdout + * - Filesystem: The json string is written to the path specified + * + * @param output_path Path to write the information to + */ +void acvmInfo(const std::string& output_path) +{ + + const char* jsonData = R"({ + "language": { + "name" : "PLONK-CSAT", + "width" : 3 + }, + "opcodes_supported" : ["arithmetic", "directive", "brillig", "memory_init", "memory_op"], + "black_box_functions_supported" : ["and", "xor", "range", "sha256", "blake2s", "keccak256", "schnorr_verify", "pedersen", "hash_to_field_128_security", "ecdsa_secp256k1", "ecdsa_secp256r1", "fixed_base_scalar_mul", "recursive_aggregation"] + })"; + + size_t length = strlen(jsonData); + std::vector data(jsonData, jsonData + length); + + if (output_path == "-") { + writeRawBytesToStdout(data); + vinfo("info written to stdout"); + } else { + write_file(output_path, data); + vinfo("info written to: ", output_path); + } +} + bool flagPresent(std::vector& args, const std::string& flag) { return std::find(args.begin(), args.end(), flag) != args.end(); @@ -322,6 +355,9 @@ int main(int argc, char* argv[]) } else if (command == "vk_as_fields") { std::string output_path = getOption(args, "-o", vk_path + "_fields.json"); vkAsFields(vk_path, output_path); + } else if (command == "info") { + std::string output_path = getOption(args, "-o", "info.json"); + acvmInfo(output_path); } else { std::cerr << "Unknown command: " << command << "\n"; return 1; diff --git a/ts/src/info.json b/ts/src/info.json new file mode 100644 index 000000000..7c9bcdfb3 --- /dev/null +++ b/ts/src/info.json @@ -0,0 +1,22 @@ +{ + "language": { + "name": "PLONK-CSAT", + "width": 3 + }, + "opcodes_supported": ["arithmetic", "directive", "brillig", "memory_init", "memory_op"], + "black_box_functions_supported": [ + "and", + "xor", + "range", + "sha256", + "blake2s", + "keccak256", + "schnorr_verify", + "pedersen", + "hash_to_field_128_security", + "ecdsa_secp256k1", + "ecdsa_secp256r1", + "fixed_base_scalar_mul", + "recursive_aggregation" + ] +} diff --git a/ts/src/main.ts b/ts/src/main.ts index 187813af5..cec51a0cf 100755 --- a/ts/src/main.ts +++ b/ts/src/main.ts @@ -4,7 +4,7 @@ import createDebug from 'debug'; import { readFileSync, writeFileSync } from 'fs'; import { gunzipSync } from 'zlib'; import { Command } from 'commander'; - +import acvmInfoJson from './info.json' assert { type: 'json' }; createDebug.log = console.error.bind(console); const debug = createDebug('bb.js'); @@ -132,6 +132,17 @@ export async function gateCount(bytecodePath: string) { } } +export function acvmInfo(outputPath: string) { + const stringifiedJson = JSON.stringify(acvmInfoJson, null, 2); + if (outputPath === '-') { + process.stdout.write(stringifiedJson); + debug(`info written to stdout`); + } else { + writeFileSync(outputPath, stringifiedJson); + debug(`info written to: ${outputPath}`); + } +} + export async function verify(proofPath: string, isRecursive: boolean, vkPath: string) { const { api, acirComposer } = await initLite(); try { @@ -333,4 +344,13 @@ program await vkAsFields(vkPath, outputPath); }); +program + .command('info') + .description('Return ACVM related metadata about the backend') + .requiredOption('-o, --output-path ', 'Specify the path to write the JSON information to') + .action(({ outputPath }) => { + handleGlobalOptions(); + acvmInfo(outputPath); + }); + program.name('bb.js').parse(process.argv); diff --git a/ts/tsconfig.json b/ts/tsconfig.json index aff973758..eb31a38f9 100644 --- a/ts/tsconfig.json +++ b/ts/tsconfig.json @@ -17,5 +17,5 @@ "rootDir": "src", "tsBuildInfoFile": ".tsbuildinfo" }, - "include": ["src"] + "include": ["src", "src/info.json"] }