Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
cli.cpp
Go to the documentation of this file.
1
33#include <fstream>
34#include <iostream>
35
36namespace bb {
37
38// TODO(https://github.com/AztecProtocol/barretenberg/issues/1257): Remove unused/seemingly unnecessary flags.
39// TODO(https://github.com/AztecProtocol/barretenberg/issues/1258): Improve defaults.
40
41// Helper function to recursively print active subcommands for CLI11 app debugging
42void print_active_subcommands(const CLI::App& app, const std::string& prefix = "bb command: ")
43{
44 // get_subcommands() returns a vector of pointers to subcommands
45 for (auto* subcmd : app.get_subcommands()) {
46 // Check if this subcommand was activated (nonzero count)
47 if (subcmd->count() > 0) {
48 vinfo(prefix, subcmd->get_name());
49 // Recursively print any subcommands of this subcommand
50 print_active_subcommands(*subcmd, prefix + " ");
51 }
52 }
53}
54
55// Recursive helper to find the deepest parsed subcommand.
56CLI::App* find_deepest_subcommand(CLI::App* app)
57{
58 for (auto& sub : app->get_subcommands()) {
59 if (sub->parsed()) {
60 // Check recursively if this subcommand has a deeper parsed subcommand.
61 if (CLI::App* deeper = find_deepest_subcommand(sub); deeper != nullptr) {
62 return deeper;
63 }
64 return sub;
65 }
66 }
67 return nullptr;
68}
69
70// Helper function to print options for a given subcommand.
71void print_subcommand_options(const CLI::App* sub)
72{
73 for (const auto& opt : sub->get_options()) {
74 if (opt->count() > 0) { // Only print options that were set.
75 if (opt->results().size() > 1) {
76 vinfo(" Warning: the following option is called more than once");
77 }
78 vinfo(" ", opt->get_name(), ": ", opt->results()[0]);
79 }
80 }
81}
82
102int parse_and_run_cli_command(int argc, char* argv[])
103{
104 std::string name = "Barretenberg\nYour favo(u)rite zkSNARK library written in C++, a perfectly good computer "
105 "programming language.";
106
107#ifdef DISABLE_AZTEC_VM
108 name += "\nAztec Virtual Machine (AVM): disabled";
109#else
110 name += "\nAztec Virtual Machine (AVM): enabled";
111#endif
112#ifdef ENABLE_AVM_TRANSPILER
113 name += "\nAVM Transpiler: enabled";
114#else
115 name += "\nAVM Transpiler: disabled";
116#endif
117#ifdef STARKNET_GARAGA_FLAVORS
118 name += "\nStarknet Garaga Extensions: enabled";
119#else
120 name += "\nStarknet Garaga Extensions: disabled";
121#endif
122 CLI::App app{ name };
123 argv = app.ensure_utf8(argv);
124 app.formatter(std::make_shared<Formatter>());
125
126 // If no arguments are provided, print help and exit.
127 if (argc == 1) {
128 std::cout << app.help() << std::endl;
129 return 0;
130 }
131
132 // prevent two or more subcommands being executed
133 app.require_subcommand(0, 1);
134
135 API::Flags flags{};
136 // Some paths, with defaults, that may or may not be set by commands
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{
141 "./out"
142 }; // sometimes a directory where things will be written, sometimes the path of a file to be written
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" };
146 flags.scheme = "";
147 flags.oracle_hash_type = "poseidon2";
148 flags.crs_path = srs::bb_crs_path();
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",
152 _output_path,
153 "Directory to write files or path of file to write, depending on subcommand.");
154 };
155
156 /***************************************************************************************************************
157 * Subcommand: Adders for options that we will create for more than one subcommand
158 ***************************************************************************************************************/
159
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");
163 };
164
165 const auto add_scheme_option = [&](CLI::App* subcommand) {
166 return subcommand
167 ->add_option(
168 "--scheme, -s",
169 flags.scheme,
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"));
175 };
176
177 const auto add_crs_path_option = [&](CLI::App* subcommand) {
178 return subcommand
179 ->add_option("--crs_path, -c",
180 flags.crs_path,
181 "Path CRS directory. Missing CRS files will be retrieved from the internet.")
182 ->check(CLI::ExistingDirectory);
183 };
184
185 const auto add_oracle_hash_option = [&](CLI::App* subcommand) {
186 return subcommand
187 ->add_option(
188 "--oracle_hash",
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"));
196 };
197
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");
200 };
201
202 const auto remove_zk_option = [&](CLI::App* subcommand) {
203 return subcommand->add_flag("--disable_zk",
204 flags.disable_zk,
205 "Use a non-zk version of --scheme. This flag is set to false by default.");
206 };
207
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.");
212 };
213
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.")
216 /* ->check(CLI::ExistingFile) OR stdin indicator - */;
217 };
218
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.")
221 /* ->check(CLI::ExistingFile) OR stdin indicator - */;
222 };
223
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.")
227 /* ->check(CLI::ExistingFile) OR stdin indicator - */;
228 };
229
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.") /* ->check(CLI::ExistingFile) */;
233 };
234
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.") /* ->check(CLI::ExistingFile) */;
238 };
239
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.")
242 /* ->check(CLI::ExistingFile) */;
243 };
244
245 const auto add_verifier_type_option = [&](CLI::App* subcommand) {
246 return subcommand
247 ->add_option("--verifier_type",
248 flags.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 "
256 "ClientIVC class)")
257 ->check(CLI::IsMember({ "standalone", "standalone_hiding", "ivc" }).name("is_member"));
258 };
259
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.");
262 };
263
264 const auto add_debug_flag = [&](CLI::App* subcommand) {
265 return subcommand->add_flag("--debug_logging, -d", flags.debug, "Output debug logs to stderr.");
266 };
267
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.");
272 };
273
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).");
277 };
278
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).");
284 };
285
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.");
288 };
289
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.");
293 };
294
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.");
299 };
300
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.");
304 };
305
306 /***************************************************************************************************************
307 * Top-level flags
308 ***************************************************************************************************************/
309 add_verbose_flag(&app);
310 add_debug_flag(&app);
311 add_crs_path_option(&app);
312
313 /***************************************************************************************************************
314 * Builtin flag: --version
315 ***************************************************************************************************************/
316 app.set_version_flag("--version", BB_VERSION_PLACEHOLDER, "Print the version string.");
317
318 /***************************************************************************************************************
319 * Subcommand: check
320 ***************************************************************************************************************/
321 CLI::App* check = app.add_subcommand(
322 "check",
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.");
326
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);
332
333 /***************************************************************************************************************
334 * Subcommand: gates
335 ***************************************************************************************************************/
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.");
339
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);
346
347 /***************************************************************************************************************
348 * Subcommand: prove
349 ***************************************************************************************************************/
350 CLI::App* prove = app.add_subcommand("prove", "Generate a proof.");
351
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);
370
371 prove->add_flag("--verify", "Verify the proof natively, resulting in a boolean output. Useful for testing.");
372
373 /***************************************************************************************************************
374 * Subcommand: write_vk
375 ***************************************************************************************************************/
376 CLI::App* write_vk =
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.");
381
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);
386
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);
394
395 /***************************************************************************************************************
396 * Subcommand: verify
397 ***************************************************************************************************************/
398 CLI::App* verify = app.add_subcommand("verify", "Verify a proof.");
399
400 add_public_inputs_path_option(verify);
401 add_proof_path_option(verify);
402 add_vk_path_option(verify);
403
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);
411
412 /***************************************************************************************************************
413 * Subcommand: write_solidity_verifier
414 ***************************************************************************************************************/
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.");
420
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);
424
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);
429
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, "");
433 };
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, "");
437 };
438
439 /***************************************************************************************************************
440 * Subcommand: avm_simulate
441 ***************************************************************************************************************/
442 CLI::App* avm_simulate_command = app.add_subcommand("avm_simulate", "");
443 avm_simulate_command->group(""); // hide from list of subcommands
444 add_verbose_flag(avm_simulate_command);
445 add_debug_flag(avm_simulate_command);
446 add_avm_inputs_option(avm_simulate_command);
447
448 /***************************************************************************************************************
449 * Subcommand: avm_prove
450 ***************************************************************************************************************/
451 CLI::App* avm_prove_command = app.add_subcommand("avm_prove", "");
452 avm_prove_command->group(""); // hide from list of subcommands
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);
459
460 /***************************************************************************************************************
461 * Subcommand: avm_check_circuit
462 ***************************************************************************************************************/
463 CLI::App* avm_check_circuit_command = app.add_subcommand("avm_check_circuit", "");
464 avm_check_circuit_command->group(""); // hide from list of subcommands
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);
469
470 /***************************************************************************************************************
471 * Subcommand: avm_verify
472 ***************************************************************************************************************/
473 CLI::App* avm_verify_command = app.add_subcommand("avm_verify", "");
474 avm_verify_command->group(""); // hide from list of subcommands
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);
481
482 /***************************************************************************************************************
483 * Subcommand: aztec_process_artifact
484 ***************************************************************************************************************/
485 CLI::App* aztec_process = app.add_subcommand(
486 "aztec_process",
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 "
489 "directory.");
490
491 std::string artifact_input_path;
492 std::string artifact_output_path;
493 bool force_regenerate = false;
494
495 aztec_process->add_option(
496 "-i,--input",
497 artifact_input_path,
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);
504
505 /***************************************************************************************************************
506 * Subcommand: msgpack
507 ***************************************************************************************************************/
508 CLI::App* msgpack_command = app.add_subcommand("msgpack", "Msgpack API interface.");
509
510 // Subcommand: msgpack schema
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);
514
515 // Subcommand: msgpack run
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)");
522
523 /***************************************************************************************************************
524 * Build the CLI11 App
525 ***************************************************************************************************************/
526
527 CLI11_PARSE(app, argc, argv);
528 // Immediately after parsing, we can init the global CRS factory. Note this does not yet read or download any
529 // points; that is done on-demand.
530 srs::init_net_crs_factory(flags.crs_path);
531 if ((prove->parsed() || write_vk->parsed()) && output_path != "-") {
532 // If writing to an output folder, make sure it exists.
533 std::filesystem::create_directories(output_path);
534 }
535 debug_logging = flags.debug;
536 verbose_logging = debug_logging || flags.verbose;
537 slow_low_memory = flags.slow_low_memory;
538#ifndef __wasm__
539 if (!flags.storage_budget.empty()) {
540 storage_budget = parse_size_string(flags.storage_budget);
541 }
542 if (print_bench || !bench_out.empty()) {
544 }
545#endif
546
548 info("Scheme is: ", flags.scheme, ", num threads: ", get_num_cpus());
549 if (CLI::App* deepest = find_deepest_subcommand(&app)) {
551 }
552
553 // TODO(AD): it is inflexible that CIVC shares an API command (prove) with UH this way. The base API class is a
554 // poor fit. It would be better to have a separate handling for each scheme with subcommands to prove.
555 const auto execute_non_prove_command = [&](API& api) {
556 if (check->parsed()) {
557 api.check(flags, bytecode_path, witness_path);
558 return 0;
559 }
560 if (gates->parsed()) {
561 api.gates(flags, bytecode_path);
562 return 0;
563 }
564 if (write_vk->parsed()) {
565 api.write_vk(flags, bytecode_path, output_path);
566 return 0;
567 }
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;
572 }
573 if (write_solidity_verifier->parsed()) {
574 api.write_solidity_verifier(flags, output_path, vk_path);
575 return 0;
576 }
577 auto subcommands = app.get_subcommands();
578 const std::string message = std::string("No handler for subcommand ") + subcommands[0]->get_name();
579 throw_or_abort(message);
580 return 1;
581 };
582
583 try {
584 // MSGPACK
585 if (msgpack_schema_command->parsed()) {
587 return 0;
588 }
589 if (msgpack_run_command->parsed()) {
590 return execute_msgpack_run(msgpack_input_file);
591 }
592 if (aztec_process->parsed()) {
593#ifdef __wasm__
594 throw_or_abort("Aztec artifact processing is not supported in WASM builds.");
595#else
596 // Default input to current directory if not specified
597 std::string input = artifact_input_path.empty() ? "." : artifact_input_path;
598
599 // Check if input is a directory
600 if (std::filesystem::is_directory(input)) {
601 // If output specified for directory input, that's an error
602 if (!artifact_output_path.empty()) {
604 "Cannot specify --output when input is a directory. Artifacts are updated in-place.");
605 }
606 // Recursively process all artifacts in directory
607 return process_all_artifacts(input, force_regenerate) ? 0 : 1;
608 }
609
610 // Input is a file, process single artifact
611 std::string output = artifact_output_path.empty() ? input : artifact_output_path;
612 return process_aztec_artifact(input, output, force_regenerate) ? 0 : 1;
613#endif
614 }
615 // AVM
616#ifndef DISABLE_AZTEC_VM
617 else if (avm_prove_command->parsed()) {
618 // This outputs both files: proof and vk, under the given directory.
619 avm_prove(avm_inputs_path, avm_prove_output_path);
620 } else if (avm_check_circuit_command->parsed()) {
621 avm_check_circuit(avm_inputs_path);
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()) {
625 avm_simulate(avm_inputs_path);
626 }
627#else
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!");
631 }
632#endif
633 else if (flags.scheme == "client_ivc") {
634 ClientIVCAPI api;
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)");
639 }
640 api.prove(flags, ivc_inputs_path, output_path);
641#ifndef __wasm__
642 if (print_bench) {
644 }
645 if (!bench_out.empty()) {
646 std::ofstream file(bench_out);
648 }
649#endif
650 return 0;
651 }
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)");
656 }
657 return api.check_precomputed_vks(flags, ivc_inputs_path) ? 0 : 1;
658 }
659 return execute_non_prove_command(api);
660 } else if (flags.scheme == "ultra_honk") {
661 UltraHonkAPI api;
662 if (prove->parsed()) {
663 api.prove(flags, bytecode_path, witness_path, vk_path, output_path);
664#ifndef __wasm__
665 if (print_bench) {
667 }
668 if (!bench_out.empty()) {
669 std::ofstream file(bench_out);
671 }
672#endif
673 return 0;
674 }
675 return execute_non_prove_command(api);
676 } else {
677 throw_or_abort("No match for API command");
678 return 1;
679 }
680 } catch (std::runtime_error const& err) {
681#ifndef BB_NO_EXCEPTIONS
682 std::cerr << err.what() << std::endl;
683 return 1;
684#endif
685 }
686 return 0;
687}
688} // namespace bb
size_t parse_size_string(const std::string &size_str)
bool slow_low_memory
size_t storage_budget
UltraHonk-specific command definitions for the Barretenberg RPC API.
Definition api.hpp:7
bool check_precomputed_vks(const Flags &flags, const std::filesystem::path &input_path)
void prove(const Flags &flags, const std::filesystem::path &input_path, const std::filesystem::path &output_dir)
void prove(const Flags &flags, const std::filesystem::path &bytecode_path, const std::filesystem::path &witness_path, const std::filesystem::path &vk_path, const std::filesystem::path &output_dir)
#define CLI11_PARSE(app,...)
#define vinfo(...)
Definition log.hpp:79
void info(Args... args)
Definition log.hpp:74
bool debug_logging
Definition log.cpp:12
bool verbose_logging
Definition log.cpp:6
bool USE_SUMCHECK_IVC
Global flag to control whether to use SumcheckClientIVC instead of ClientIVC.
std::string get_msgpack_schema_as_json()
GlobalBenchStatsContainer GLOBAL_BENCH_STATS
Definition bb_bench.cpp:569
bool use_bb_bench
Definition bb_bench.cpp:172
void init_net_crs_factory(const std::filesystem::path &path)
std::filesystem::path bb_crs_path()
Entry point for Barretenberg command-line interface.
void print_subcommand_options(const CLI::App *sub)
Definition cli.cpp:71
void avm_simulate(const std::filesystem::path &inputs_path)
Simulates an public transaction.
Definition api_avm.cpp:78
const char *const BB_VERSION_PLACEHOLDER
Definition version.cpp:6
int parse_and_run_cli_command(int argc, char *argv[])
Parse command line arguments and run the corresponding command.
Definition cli.cpp:102
bool process_all_artifacts(const std::string &search_path, bool force)
Process all discovered contract artifacts in a directory tree.
bool process_aztec_artifact(const std::string &input_path, const std::string &output_path, bool force)
Process Aztec contract artifacts: transpile and generate verification keys.
size_t get_num_cpus()
Definition thread.cpp:33
int execute_msgpack_run(const std::string &msgpack_input_file)
Execute msgpack run command.
bool avm_verify(const std::filesystem::path &proof_path, const std::filesystem::path &public_inputs_path, const std::filesystem::path &vk_path)
Verifies an avm proof and writes the result to stdout.
Definition api_avm.cpp:62
void print_active_subcommands(const CLI::App &app, const std::string &prefix="bb command: ")
Definition cli.cpp:42
void avm_prove(const std::filesystem::path &inputs_path, const std::filesystem::path &output_path)
Writes an avm proof and corresponding (incomplete) verification key to files.
Definition api_avm.cpp:27
void avm_check_circuit(const std::filesystem::path &inputs_path)
Definition api_avm.cpp:50
CLI::App * find_deepest_subcommand(CLI::App *app)
Definition cli.cpp:56
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
std::string scheme
Definition api.hpp:18
void print_aggregate_counts_hierarchical(std::ostream &) const
Definition bb_bench.cpp:299
void print_aggregate_counts(std::ostream &, size_t) const
Definition bb_bench.cpp:273
void throw_or_abort(std::string const &err)