104 std::string name =
"Barretenberg\nYour favo(u)rite zkSNARK library written in C++, a perfectly good computer "
105 "programming language.";
107#ifdef DISABLE_AZTEC_VM
108 name +=
"\nAztec Virtual Machine (AVM): disabled";
110 name +=
"\nAztec Virtual Machine (AVM): enabled";
112#ifdef ENABLE_AVM_TRANSPILER
113 name +=
"\nAVM Transpiler: enabled";
115 name +=
"\nAVM Transpiler: disabled";
117#ifdef STARKNET_GARAGA_FLAVORS
118 name +=
"\nStarknet Garaga Extensions: enabled";
120 name +=
"\nStarknet Garaga Extensions: disabled";
122 CLI::App app{ name };
123 argv = app.ensure_utf8(argv);
133 app.require_subcommand(0, 1);
137 std::filesystem::path bytecode_path{
"./target/program.json" };
138 std::filesystem::path witness_path{
"./target/witness.gz" };
139 std::filesystem::path ivc_inputs_path{
"./ivc-inputs.msgpack" };
140 std::filesystem::path output_path{
143 std::filesystem::path public_inputs_path{
"./target/public_inputs" };
144 std::filesystem::path proof_path{
"./target/proof" };
145 std::filesystem::path vk_path{
"./target/vk" };
147 flags.oracle_hash_type =
"poseidon2";
149 flags.include_gates_per_opcode =
false;
150 const auto add_output_path_option = [&](CLI::App* subcommand,
auto& _output_path) {
151 return subcommand->add_option(
"--output_path, -o",
153 "Directory to write files or path of file to write, depending on subcommand.");
160 const auto add_ipa_accumulation_flag = [&](CLI::App* subcommand) {
161 return subcommand->add_flag(
162 "--ipa_accumulation", flags.ipa_accumulation,
"Accumulate/Aggregate IPA (Inner Product Argument) claims");
165 const auto add_scheme_option = [&](CLI::App* subcommand) {
170 "The type of proof to be constructed. This can specify a proving system, an accumulation scheme, or a "
171 "particular type of circuit to be constructed and proven for some implicit scheme.")
172 ->envname(
"BB_SCHEME")
173 ->default_val(
"ultra_honk")
174 ->check(CLI::IsMember({
"client_ivc",
"avm",
"ultra_honk" }).name(
"is_member"));
177 const auto add_crs_path_option = [&](CLI::App* subcommand) {
179 ->add_option(
"--crs_path, -c",
181 "Path CRS directory. Missing CRS files will be retrieved from the internet.")
182 ->check(CLI::ExistingDirectory);
185 const auto add_oracle_hash_option = [&](CLI::App* subcommand) {
189 flags.oracle_hash_type,
190 "The hash function used by the prover as random oracle standing in for a verifier's challenge "
191 "generation. Poseidon2 is to be used for proofs that are intended to be verified inside of a "
192 "circuit. Keccak is optimized for verification in an Ethereum smart contract, where Keccak "
193 "has a privileged position due to the existence of an EVM precompile. Starknet is optimized "
194 "for verification in a Starknet smart contract, which can be generated using the Garaga library.")
195 ->check(CLI::IsMember({
"poseidon2",
"keccak",
"starknet" }).name(
"is_member"));
198 const auto add_write_vk_flag = [&](CLI::App* subcommand) {
199 return subcommand->add_flag(
"--write_vk", flags.write_vk,
"Write the provided circuit's verification key");
202 const auto remove_zk_option = [&](CLI::App* subcommand) {
203 return subcommand->add_flag(
"--disable_zk",
205 "Use a non-zk version of --scheme. This flag is set to false by default.");
208 const auto add_use_sumcheck_ivc_flag = [&](CLI::App* subcommand) {
209 return subcommand->add_flag(
"--use-sumcheck-ivc",
211 "Use SumcheckClientIVC instead of ClientIVC for IVC proving.");
214 const auto add_bytecode_path_option = [&](CLI::App* subcommand) {
215 subcommand->add_option(
"--bytecode_path, -b", bytecode_path,
"Path to ACIR bytecode generated by Noir.")
219 const auto add_witness_path_option = [&](CLI::App* subcommand) {
220 subcommand->add_option(
"--witness_path, -w", witness_path,
"Path to partial witness generated by Noir.")
224 const auto add_ivc_inputs_path_options = [&](CLI::App* subcommand) {
225 subcommand->add_option(
226 "--ivc_inputs_path", ivc_inputs_path,
"For IVC, path to input stack with bytecode and witnesses.")
230 const auto add_public_inputs_path_option = [&](CLI::App* subcommand) {
231 return subcommand->add_option(
232 "--public_inputs_path, -i", public_inputs_path,
"Path to public inputs.") ;
235 const auto add_proof_path_option = [&](CLI::App* subcommand) {
236 return subcommand->add_option(
237 "--proof_path, -p", proof_path,
"Path to a proof.") ;
240 const auto add_vk_path_option = [&](CLI::App* subcommand) {
241 return subcommand->add_option(
"--vk_path, -k", vk_path,
"Path to a verification key.")
245 const auto add_verifier_type_option = [&](CLI::App* subcommand) {
247 ->add_option(
"--verifier_type",
249 "Is a verification key for use a standalone single circuit verifier (e.g. a SNARK or folding "
250 "recursive verifier) or is it for an ivc verifier? `standalone` produces a verification key "
251 "is sufficient for verifying proofs about a single circuit (including the non-encsapsulated "
252 "use case where an IVC scheme is manually constructed via recursive UltraHonk proof "
253 "verification). `standalone_hiding` is similar to `standalone` but is used for the last step "
254 "where the structured trace is not utilized. `ivc` produces a verification key for verifying "
255 "the stack of run though a dedicated ivc verifier class (currently the only option is the "
257 ->check(CLI::IsMember({
"standalone",
"standalone_hiding",
"ivc" }).name(
"is_member"));
260 const auto add_verbose_flag = [&](CLI::App* subcommand) {
261 return subcommand->add_flag(
"--verbose, --verbose_logging, -v", flags.verbose,
"Output all logs to stderr.");
264 const auto add_debug_flag = [&](CLI::App* subcommand) {
265 return subcommand->add_flag(
"--debug_logging, -d", flags.debug,
"Output debug logs to stderr.");
268 const auto add_include_gates_per_opcode_flag = [&](CLI::App* subcommand) {
269 return subcommand->add_flag(
"--include_gates_per_opcode",
270 flags.include_gates_per_opcode,
271 "Include gates_per_opcode in the output of the gates command.");
274 const auto add_slow_low_memory_flag = [&](CLI::App* subcommand) {
275 return subcommand->add_flag(
276 "--slow_low_memory", flags.slow_low_memory,
"Enable low memory mode (can be 2x slower or more).");
279 const auto add_storage_budget_option = [&](CLI::App* subcommand) {
280 return subcommand->add_option(
"--storage_budget",
281 flags.storage_budget,
282 "Storage budget for FileBackedMemory (e.g. '500m', '2g'). When exceeded, falls "
283 "back to RAM (requires --slow_low_memory).");
286 const auto add_update_inputs_flag = [&](CLI::App* subcommand) {
287 return subcommand->add_flag(
"--update_inputs", flags.update_inputs,
"Update inputs if vk check fails.");
290 const auto add_optimized_solidity_verifier_flag = [&](CLI::App* subcommand) {
291 return subcommand->add_flag(
292 "--optimized", flags.optimized_solidity_verifier,
"Use the optimized Solidity verifier.");
295 bool print_bench =
false;
296 const auto add_print_bench_flag = [&](CLI::App* subcommand) {
297 return subcommand->add_flag(
298 "--print_bench", print_bench,
"Pretty print op counts to standard error in a human-readable format.");
301 std::string bench_out;
302 const auto add_bench_out_option = [&](CLI::App* subcommand) {
303 return subcommand->add_option(
"--bench_out", bench_out,
"Path to write the op counts in a json.");
309 add_verbose_flag(&app);
310 add_debug_flag(&app);
311 add_crs_path_option(&app);
321 CLI::App* check = app.add_subcommand(
323 "A debugging tool to quickly check whether a witness satisfies a circuit The "
324 "function constructs the execution trace and iterates through it row by row, applying the "
325 "polynomial relations defining the gate types. For client IVC, we check the VKs in the folding stack.");
327 add_scheme_option(check);
328 add_bytecode_path_option(check);
329 add_witness_path_option(check);
330 add_ivc_inputs_path_options(check);
331 add_update_inputs_flag(check);
336 CLI::App* gates = app.add_subcommand(
"gates",
337 "Construct a circuit from the given bytecode (in particular, expand black box "
338 "functions) and return the gate count information.");
340 add_scheme_option(gates);
341 add_verbose_flag(gates);
342 add_bytecode_path_option(gates);
343 add_include_gates_per_opcode_flag(gates);
344 add_oracle_hash_option(gates);
345 add_ipa_accumulation_flag(gates);
350 CLI::App* prove = app.add_subcommand(
"prove",
"Generate a proof.");
352 add_scheme_option(prove);
353 add_bytecode_path_option(prove);
354 add_witness_path_option(prove);
355 add_output_path_option(prove, output_path);
356 add_ivc_inputs_path_options(prove);
357 add_vk_path_option(prove);
358 add_verbose_flag(prove);
359 add_debug_flag(prove);
360 add_crs_path_option(prove);
361 add_oracle_hash_option(prove);
362 add_write_vk_flag(prove);
363 add_ipa_accumulation_flag(prove);
364 remove_zk_option(prove);
365 add_use_sumcheck_ivc_flag(prove);
366 add_slow_low_memory_flag(prove);
367 add_print_bench_flag(prove);
368 add_bench_out_option(prove);
369 add_storage_budget_option(prove);
371 prove->add_flag(
"--verify",
"Verify the proof natively, resulting in a boolean output. Useful for testing.");
377 app.add_subcommand(
"write_vk",
378 "Write the verification key of a circuit. The circuit is constructed using "
379 "quickly generated but invalid witnesses (which must be supplied in Barretenberg in order "
380 "to expand ACIR black box opcodes), and no proof is constructed.");
382 add_scheme_option(write_vk);
383 add_bytecode_path_option(write_vk);
384 add_output_path_option(write_vk, output_path);
385 add_ivc_inputs_path_options(write_vk);
387 add_verbose_flag(write_vk);
388 add_debug_flag(write_vk);
389 add_crs_path_option(write_vk);
390 add_oracle_hash_option(write_vk);
391 add_ipa_accumulation_flag(write_vk);
392 add_verifier_type_option(write_vk)->default_val(
"standalone");
393 remove_zk_option(write_vk);
398 CLI::App* verify = app.add_subcommand(
"verify",
"Verify a proof.");
400 add_public_inputs_path_option(verify);
401 add_proof_path_option(verify);
402 add_vk_path_option(verify);
404 add_verbose_flag(verify);
405 add_debug_flag(verify);
406 add_scheme_option(verify);
407 add_crs_path_option(verify);
408 add_oracle_hash_option(verify);
409 remove_zk_option(verify);
410 add_ipa_accumulation_flag(verify);
415 CLI::App* write_solidity_verifier =
416 app.add_subcommand(
"write_solidity_verifier",
417 "Write a Solidity smart contract suitable for verifying proofs of circuit "
418 "satisfiability for the circuit with verification key at vk_path. Not all "
419 "hash types are implemented due to efficiency concerns.");
421 add_scheme_option(write_solidity_verifier);
422 add_vk_path_option(write_solidity_verifier);
423 add_output_path_option(write_solidity_verifier, output_path);
425 add_verbose_flag(write_solidity_verifier);
426 remove_zk_option(write_solidity_verifier);
427 add_crs_path_option(write_solidity_verifier);
428 add_optimized_solidity_verifier_flag(write_solidity_verifier);
430 std::filesystem::path avm_inputs_path{
"./target/avm_inputs.bin" };
431 const auto add_avm_inputs_option = [&](CLI::App* subcommand) {
432 return subcommand->add_option(
"--avm-inputs", avm_inputs_path,
"");
434 std::filesystem::path avm_public_inputs_path{
"./target/avm_public_inputs.bin" };
435 const auto add_avm_public_inputs_option = [&](CLI::App* subcommand) {
436 return subcommand->add_option(
"--avm-public-inputs", avm_public_inputs_path,
"");
442 CLI::App* avm_simulate_command = app.add_subcommand(
"avm_simulate",
"");
443 avm_simulate_command->group(
"");
444 add_verbose_flag(avm_simulate_command);
445 add_debug_flag(avm_simulate_command);
446 add_avm_inputs_option(avm_simulate_command);
451 CLI::App* avm_prove_command = app.add_subcommand(
"avm_prove",
"");
452 avm_prove_command->group(
"");
453 add_verbose_flag(avm_prove_command);
454 add_debug_flag(avm_prove_command);
455 add_crs_path_option(avm_prove_command);
456 std::filesystem::path avm_prove_output_path{
"./proofs" };
457 add_output_path_option(avm_prove_command, avm_prove_output_path);
458 add_avm_inputs_option(avm_prove_command);
463 CLI::App* avm_check_circuit_command = app.add_subcommand(
"avm_check_circuit",
"");
464 avm_check_circuit_command->group(
"");
465 add_verbose_flag(avm_check_circuit_command);
466 add_debug_flag(avm_check_circuit_command);
467 add_crs_path_option(avm_check_circuit_command);
468 add_avm_inputs_option(avm_check_circuit_command);
473 CLI::App* avm_verify_command = app.add_subcommand(
"avm_verify",
"");
474 avm_verify_command->group(
"");
475 add_verbose_flag(avm_verify_command);
476 add_debug_flag(avm_verify_command);
477 add_crs_path_option(avm_verify_command);
478 add_avm_public_inputs_option(avm_verify_command);
479 add_proof_path_option(avm_verify_command);
480 add_vk_path_option(avm_verify_command);
485 CLI::App* aztec_process = app.add_subcommand(
487 "Process Aztec contract artifacts: transpile and generate verification keys for all private functions.\n"
488 "If input is a directory (and no output specified), recursively processes all artifacts found in the "
491 std::string artifact_input_path;
492 std::string artifact_output_path;
493 bool force_regenerate =
false;
495 aztec_process->add_option(
498 "Input artifact JSON path or directory to search (optional, defaults to current directory)");
499 aztec_process->add_option(
500 "-o,--output", artifact_output_path,
"Output artifact JSON path (optional, same as input if not specified)");
501 aztec_process->add_flag(
"-f,--force", force_regenerate,
"Force regeneration of verification keys");
502 add_verbose_flag(aztec_process);
503 add_debug_flag(aztec_process);
508 CLI::App* msgpack_command = app.add_subcommand(
"msgpack",
"Msgpack API interface.");
511 CLI::App* msgpack_schema_command =
512 msgpack_command->add_subcommand(
"schema",
"Output a msgpack schema encoded as JSON to stdout.");
513 add_verbose_flag(msgpack_schema_command);
516 CLI::App* msgpack_run_command =
517 msgpack_command->add_subcommand(
"run",
"Execute msgpack API commands from stdin or file.");
518 add_verbose_flag(msgpack_run_command);
519 std::string msgpack_input_file;
520 msgpack_run_command->add_option(
521 "-i,--input", msgpack_input_file,
"Input file containing msgpack buffers (defaults to stdin)");
531 if ((prove->parsed() || write_vk->parsed()) && output_path !=
"-") {
533 std::filesystem::create_directories(output_path);
539 if (!flags.storage_budget.empty()) {
542 if (print_bench || !bench_out.empty()) {
555 const auto execute_non_prove_command = [&](
API& api) {
556 if (check->parsed()) {
557 api.check(flags, bytecode_path, witness_path);
560 if (gates->parsed()) {
561 api.gates(flags, bytecode_path);
564 if (write_vk->parsed()) {
565 api.write_vk(flags, bytecode_path, output_path);
568 if (verify->parsed()) {
569 const bool verified = api.verify(flags, public_inputs_path, proof_path, vk_path);
570 vinfo(
"verified: ", verified);
571 return verified ? 0 : 1;
573 if (write_solidity_verifier->parsed()) {
574 api.write_solidity_verifier(flags, output_path, vk_path);
577 auto subcommands = app.get_subcommands();
578 const std::string message = std::string(
"No handler for subcommand ") + subcommands[0]->get_name();
585 if (msgpack_schema_command->parsed()) {
589 if (msgpack_run_command->parsed()) {
592 if (aztec_process->parsed()) {
594 throw_or_abort(
"Aztec artifact processing is not supported in WASM builds.");
597 std::string input = artifact_input_path.empty() ?
"." : artifact_input_path;
600 if (std::filesystem::is_directory(input)) {
602 if (!artifact_output_path.empty()) {
604 "Cannot specify --output when input is a directory. Artifacts are updated in-place.");
611 std::string output = artifact_output_path.empty() ? input : artifact_output_path;
616#ifndef DISABLE_AZTEC_VM
617 else if (avm_prove_command->parsed()) {
619 avm_prove(avm_inputs_path, avm_prove_output_path);
620 }
else if (avm_check_circuit_command->parsed()) {
622 }
else if (avm_verify_command->parsed()) {
623 return avm_verify(proof_path, avm_public_inputs_path, vk_path) ? 0 : 1;
624 }
else if (avm_simulate_command->parsed()) {
628 else if (avm_prove_command->parsed() || avm_check_circuit_command->parsed() || avm_verify_command->parsed() ||
629 avm_simulate_command->parsed()) {
630 throw_or_abort(
"The Aztec Virtual Machine (AVM) is disabled in this environment!");
633 else if (flags.scheme ==
"client_ivc") {
635 if (prove->parsed()) {
636 if (!std::filesystem::exists(ivc_inputs_path)) {
637 throw_or_abort(
"The prove command for ClientIVC expect a valid file passed with --ivc_inputs_path "
638 "<ivc-inputs.msgpack> (default ./ivc-inputs.msgpack)");
640 api.
prove(flags, ivc_inputs_path, output_path);
645 if (!bench_out.empty()) {
646 std::ofstream file(bench_out);
652 if (check->parsed()) {
653 if (!std::filesystem::exists(ivc_inputs_path)) {
654 throw_or_abort(
"The check command for ClientIVC expect a valid file passed with --ivc_inputs_path "
655 "<ivc-inputs.msgpack> (default ./ivc-inputs.msgpack)");
659 return execute_non_prove_command(api);
660 }
else if (flags.scheme ==
"ultra_honk") {
662 if (prove->parsed()) {
663 api.
prove(flags, bytecode_path, witness_path, vk_path, output_path);
668 if (!bench_out.empty()) {
669 std::ofstream file(bench_out);
675 return execute_non_prove_command(api);
680 }
catch (std::runtime_error
const& err) {
681#ifndef BB_NO_EXCEPTIONS