Skip to content

Commit

Permalink
feat: Add info command to bb (#2010)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
2 people authored and AztecBot committed Sep 5, 2023
1 parent 0b24711 commit 2882d97
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 2 deletions.
36 changes: 36 additions & 0 deletions cpp/src/barretenberg/bb/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint8_t> 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<std::string>& args, const std::string& flag)
{
return std::find(args.begin(), args.end(), flag) != args.end();
Expand Down Expand Up @@ -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;
Expand Down
22 changes: 22 additions & 0 deletions ts/src/info.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
22 changes: 21 additions & 1 deletion ts/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -333,4 +344,13 @@ program
await vkAsFields(vkPath, outputPath);
});

program
.command('info')
.description('Return ACVM related metadata about the backend')
.requiredOption('-o, --output-path <path>', 'Specify the path to write the JSON information to')
.action(({ outputPath }) => {
handleGlobalOptions();
acvmInfo(outputPath);
});

program.name('bb.js').parse(process.argv);
2 changes: 1 addition & 1 deletion ts/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
"rootDir": "src",
"tsBuildInfoFile": ".tsbuildinfo"
},
"include": ["src"]
"include": ["src", "src/info.json"]
}

0 comments on commit 2882d97

Please sign in to comment.