Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Initial native version of bb binary. #524

Merged
merged 23 commits into from
Jul 5, 2023
Merged

feat: Initial native version of bb binary. #524

merged 23 commits into from
Jul 5, 2023

Conversation

charlielye
Copy link
Contributor

@charlielye charlielye commented Jun 11, 2023

Description

Just as bb.js provides an architecture agnostic cli prover/verifier, we probably want a native build that follows the same cli args for when we can target the native arch. This overcomes the 512k gate limit and is probably about 5x faster.

This is an initial implementation of the native bb executable.

Todo:

  • We currently just assume a max circuit size of 512k. We can be a bit smarter and determine the number of gates beforehand and adjust accordingly. We do this in bb.js and cache the result in the json file (as it takes a few seconds). That's non trivial in C++ due to no direct JSON support, so I'll probably make it cache the gate count in a file. bb.js could do the same if we wanted "compatibility" between them. But it's also fine perhaps for backends to just create an e.g. .bb.js and .bb folder where they store their backend specific info.
  • We currently assume we're running in a unix like environment with awk gunzip base64 and curl. This should serve linux and mac fine, and probably WSL.
  • We don't print any useful usage info.
  • Maxim added the "proof_as_fields" and "vk_as_fields" commands to help with recursion. I've reimplemented these here, but we should probably just make proof and vk generation write these out at the same time? Or something better?

@kevaundray kevaundray changed the title Initial native version of bb binary. feat: Initial native version of bb binary. Jun 12, 2023
inline std::vector<uint8_t> get_bytecode(const std::string& jsonPath)
{
std::string command =
"awk -F'\"bytecode\":' '{print $2}' " + jsonPath + " | awk -F'\"' '{print $2}' | base64 -d | gunzip";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This essentially stops us executing on Windows ...

Copy link
Contributor Author

@charlielye charlielye Jul 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not on WSL? Current thinking is on windows we just target WSL, but yes I suppose if we want full native builds we need a mingw cross-compile and to rethink the above. Not sure if worth it if most devs have WSL installed.

size_t g1_start = 28;
size_t g1_end = g1_start + num_points * 64 - 1;
std::string command = "curl -s -H \"Range: bytes=" + std::to_string(g1_start) + "-" + std::to_string(g1_end) +
"\" 'https://aztec-ignition.s3.amazonaws.com/MAIN%20IGNITION/monomial/transcript00.dat'";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would we need to consider transcript01.dat..transcript02.dat as well ?

Copy link
Contributor Author

@charlielye charlielye Jul 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, this won't work beyond 2^19 for now, but we've set max circuit size for now even for this binary as 2^19. Just a first pass at getting something in.

Comment on lines +158 to +182
if (command == "prove_and_verify") {
proveAndVerify(json_path, witness_path, recursive);
} else if (command == "prove") {
std::string output_path = getOption(args, "-o", "./proofs/proof");
prove(json_path, witness_path, recursive, output_path);
} else if (command == "gates") {
gateCount(json_path);
} else if (command == "verify") {
verify(proof_path, recursive, vk_path);
} else if (command == "contract") {
std::string output_path = getOption(args, "-o", "./target/contract.sol");
contract(output_path, vk_path);
} else if (command == "write_vk") {
std::string output_path = getOption(args, "-o", "./target/vk");
writeVk(json_path, output_path);
} else if (command == "proof_as_fields") {
std::string output_path = getOption(args, "-o", proof_path + "_fields.json");
proofAsFields(proof_path, vk_path, output_path);
} else if (command == "vk_as_fields") {
std::string output_path = getOption(args, "-o", vk_path + "_fields.json");
vkAsFields(vk_path, output_path);
} else {
std::cerr << "Unknown command: " << command << "\n";
return -1;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are essentially public API's wonder if they could get abstracted away so they would be callable from wasm ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you mean by callable from wasm. This binary is not meant to be used in/from any wasm context?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants