Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
cli.cpp
Go to the documentation of this file.
1
32#include <fstream>
33#include <iostream>
34
35namespace bb {
36// This is updated in-place by bootstrap.sh during the release process. This prevents
37// the version string from needing to be present at build-time, simplifying e.g. caching.
38const char* const BB_VERSION_PLACEHOLDER = "00000000.00000000.00000000";
39
40// TODO(https://github.com/AztecProtocol/barretenberg/issues/1257): Remove unused/seemingly unnecessary flags.
41// TODO(https://github.com/AztecProtocol/barretenberg/issues/1258): Improve defaults.
42
43// Helper function to recursively print active subcommands for CLI11 app debugging
44void print_active_subcommands(const CLI::App& app, const std::string& prefix = "bb command: ")
45{
46 // get_subcommands() returns a vector of pointers to subcommands
47 for (auto* subcmd : app.get_subcommands()) {
48 // Check if this subcommand was activated (nonzero count)
49 if (subcmd->count() > 0) {
50 vinfo(prefix, subcmd->get_name());
51 // Recursively print any subcommands of this subcommand
52 print_active_subcommands(*subcmd, prefix + " ");
53 }
54 }
55}
56
57// Recursive helper to find the deepest parsed subcommand.
58CLI::App* find_deepest_subcommand(CLI::App* app)
59{
60 for (auto& sub : app->get_subcommands()) {
61 if (sub->parsed()) {
62 // Check recursively if this subcommand has a deeper parsed subcommand.
63 if (CLI::App* deeper = find_deepest_subcommand(sub); deeper != nullptr) {
64 return deeper;
65 }
66 return sub;
67 }
68 }
69 return nullptr;
70}
71
72// Helper function to print options for a given subcommand.
73void print_subcommand_options(const CLI::App* sub)
74{
75 for (const auto& opt : sub->get_options()) {
76 if (opt->count() > 0) { // Only print options that were set.
77 if (opt->results().size() > 1) {
78 vinfo(" Warning: the following option is called more than once");
79 }
80 vinfo(" ", opt->get_name(), ": ", opt->results()[0]);
81 }
82 }
83}
84
104int parse_and_run_cli_command(int argc, char* argv[])
105{
106 std::string name = "Barretenberg\nYour favo(u)rite zkSNARK library written in C++, a perfectly good computer "
107 "programming language.";
108
109#ifdef DISABLE_AZTEC_VM
110 name += "\nAztec Virtual Machine (AVM): disabled";
111#else
112 name += "\nAztec Virtual Machine (AVM): enabled";
113#endif
114#ifdef STARKNET_GARAGA_FLAVORS
115 name += "\nStarknet Garaga Extensions: enabled";
116#else
117 name += "\nStarknet Garaga Extensions: disabled";
118#endif
119 CLI::App app{ name };
120 argv = app.ensure_utf8(argv);
121 app.formatter(std::make_shared<Formatter>());
122
123 // If no arguments are provided, print help and exit.
124 if (argc == 1) {
125 std::cout << app.help() << std::endl;
126 return 0;
127 }
128
129 // prevent two or more subcommands being executed
130 app.require_subcommand(0, 1);
131
132 API::Flags flags{};
133 // Some paths, with defaults, that may or may not be set by commands
134 std::filesystem::path bytecode_path{ "./target/program.json" };
135 std::filesystem::path witness_path{ "./target/witness.gz" };
136 std::filesystem::path ivc_inputs_path{ "./ivc-inputs.msgpack" };
137 std::filesystem::path output_path{
138 "./out"
139 }; // sometimes a directory where things will be written, sometimes the path of a file to be written
140 std::filesystem::path public_inputs_path{ "./target/public_inputs" };
141 std::filesystem::path proof_path{ "./target/proof" };
142 std::filesystem::path vk_path{ "./target/vk" };
143 flags.scheme = "";
144 flags.oracle_hash_type = "poseidon2";
145 flags.output_format = "bytes";
146 flags.crs_path = srs::bb_crs_path();
147 flags.include_gates_per_opcode = false;
148 const auto add_output_path_option = [&](CLI::App* subcommand, auto& _output_path) {
149 return subcommand->add_option("--output_path, -o",
150 _output_path,
151 "Directory to write files or path of file to write, depending on subcommand.");
152 };
153
154 /***************************************************************************************************************
155 * Subcommand: Adders for options that we will create for more than one subcommand
156 ***************************************************************************************************************/
157
158 const auto add_ipa_accumulation_flag = [&](CLI::App* subcommand) {
159 return subcommand->add_flag(
160 "--ipa_accumulation", flags.ipa_accumulation, "Accumulate/Aggregate IPA (Inner Product Argument) claims");
161 };
162
163 const auto add_scheme_option = [&](CLI::App* subcommand) {
164 return subcommand
165 ->add_option(
166 "--scheme, -s",
167 flags.scheme,
168 "The type of proof to be constructed. This can specify a proving system, an accumulation scheme, or a "
169 "particular type of circuit to be constructed and proven for some implicit scheme.")
170 ->envname("BB_SCHEME")
171 ->default_val("ultra_honk")
172 ->check(CLI::IsMember({ "client_ivc", "avm", "ultra_honk" }).name("is_member"));
173 };
174
175 const auto add_crs_path_option = [&](CLI::App* subcommand) {
176 return subcommand
177 ->add_option("--crs_path, -c",
178 flags.crs_path,
179 "Path CRS directory. Missing CRS files will be retrieved from the internet.")
180 ->check(CLI::ExistingDirectory);
181 };
182
183 const auto add_oracle_hash_option = [&](CLI::App* subcommand) {
184 return subcommand
185 ->add_option(
186 "--oracle_hash",
187 flags.oracle_hash_type,
188 "The hash function used by the prover as random oracle standing in for a verifier's challenge "
189 "generation. Poseidon2 is to be used for proofs that are intended to be verified inside of a "
190 "circuit. Keccak is optimized for verification in an Ethereum smart contract, where Keccak "
191 "has a privileged position due to the existence of an EVM precompile. Starknet is optimized "
192 "for verification in a Starknet smart contract, which can be generated using the Garaga library.")
193 ->check(CLI::IsMember({ "poseidon2", "keccak", "starknet" }).name("is_member"));
194 };
195
196 const auto add_output_format_option = [&](CLI::App* subcommand) {
197 return subcommand
198 ->add_option(
199 "--output_format",
200 flags.output_format,
201 "The type of the data to be written by the command. If bytes, output the raw bytes prefixed with "
202 "header information for deserialization. If fields, output a string representation of an array of "
203 "field elements. If bytes_and_fields do both. If fields_msgpack, outputs a msgpack buffer of Fr "
204 "elements.")
205 ->check(CLI::IsMember({ "bytes", "fields", "bytes_and_fields", "fields_msgpack" }).name("is_member"));
206 };
207
208 const auto add_write_vk_flag = [&](CLI::App* subcommand) {
209 return subcommand->add_flag("--write_vk", flags.write_vk, "Write the provided circuit's verification key");
210 };
211
212 const auto remove_zk_option = [&](CLI::App* subcommand) {
213 return subcommand->add_flag("--disable_zk",
214 flags.disable_zk,
215 "Use a non-zk version of --scheme. This flag is set to false by default.");
216 };
217
218 const auto add_bytecode_path_option = [&](CLI::App* subcommand) {
219 subcommand->add_option("--bytecode_path, -b", bytecode_path, "Path to ACIR bytecode generated by Noir.")
220 /* ->check(CLI::ExistingFile) OR stdin indicator - */;
221 };
222
223 const auto add_witness_path_option = [&](CLI::App* subcommand) {
224 subcommand->add_option("--witness_path, -w", witness_path, "Path to partial witness generated by Noir.")
225 /* ->check(CLI::ExistingFile) OR stdin indicator - */;
226 };
227
228 const auto add_ivc_inputs_path_options = [&](CLI::App* subcommand) {
229 subcommand->add_option(
230 "--ivc_inputs_path", ivc_inputs_path, "For IVC, path to input stack with bytecode and witnesses.")
231 /* ->check(CLI::ExistingFile) OR stdin indicator - */;
232 };
233
234 const auto add_public_inputs_path_option = [&](CLI::App* subcommand) {
235 return subcommand->add_option(
236 "--public_inputs_path, -i", public_inputs_path, "Path to public inputs.") /* ->check(CLI::ExistingFile) */;
237 };
238
239 const auto add_proof_path_option = [&](CLI::App* subcommand) {
240 return subcommand->add_option(
241 "--proof_path, -p", proof_path, "Path to a proof.") /* ->check(CLI::ExistingFile) */;
242 };
243
244 const auto add_vk_path_option = [&](CLI::App* subcommand) {
245 return subcommand->add_option("--vk_path, -k", vk_path, "Path to a verification key.")
246 /* ->check(CLI::ExistingFile) */;
247 };
248
249 const auto add_verifier_type_option = [&](CLI::App* subcommand) {
250 return subcommand
251 ->add_option("--verifier_type",
252 flags.verifier_type,
253 "Is a verification key for use a standalone single circuit verifier (e.g. a SNARK or folding "
254 "recursive verifier) or is it for an ivc verifier? `standalone` produces a verification key "
255 "is sufficient for verifying proofs about a single circuit (including the non-encsapsulated "
256 "use case where an IVC scheme is manually constructed via recursive UltraHonk proof "
257 "verification). `ivc` produces a verification key for verifying the stack of run though a "
258 "dedicated ivc verifier class (currently the only option is the ClientIVC class) ")
259 ->check(CLI::IsMember({ "standalone", "ivc" }).name("is_member"));
260 };
261
262 const auto add_verbose_flag = [&](CLI::App* subcommand) {
263 return subcommand->add_flag("--verbose, --verbose_logging, -v", flags.verbose, "Output all logs to stderr.");
264 };
265
266 const auto add_debug_flag = [&](CLI::App* subcommand) {
267 return subcommand->add_flag("--debug_logging, -d", flags.debug, "Output debug logs to stderr.");
268 };
269
270 const auto add_include_gates_per_opcode_flag = [&](CLI::App* subcommand) {
271 return subcommand->add_flag("--include_gates_per_opcode",
272 flags.include_gates_per_opcode,
273 "Include gates_per_opcode in the output of the gates command.");
274 };
275
276 const auto add_slow_low_memory_flag = [&](CLI::App* subcommand) {
277 return subcommand->add_flag(
278 "--slow_low_memory", flags.slow_low_memory, "Enable low memory mode (can be 2x slower or more).");
279 };
280
281 const auto add_update_inputs_flag = [&](CLI::App* subcommand) {
282 return subcommand->add_flag("--update_inputs", flags.update_inputs, "Update inputs if vk check fails.");
283 };
284
285 bool print_op_counts = false;
286 const auto add_print_op_counts_flag = [&](CLI::App* subcommand) {
287 return subcommand->add_flag("--print_op_counts", print_op_counts, "Print op counts to json on one line.");
288 };
289
290 std::string op_counts_out;
291 const auto add_op_counts_out_option = [&](CLI::App* subcommand) {
292 return subcommand->add_option("--op_counts_out", op_counts_out, "Path to write the op counts in a json.");
293 };
294
295 /***************************************************************************************************************
296 * Top-level flags
297 ***************************************************************************************************************/
298 add_verbose_flag(&app);
299 add_debug_flag(&app);
300 add_crs_path_option(&app);
301
302 /***************************************************************************************************************
303 * Builtin flag: --version
304 ***************************************************************************************************************/
305 app.set_version_flag("--version", BB_VERSION_PLACEHOLDER, "Print the version string.");
306
307 /***************************************************************************************************************
308 * Subcommand: check
309 ***************************************************************************************************************/
310 CLI::App* check = app.add_subcommand(
311 "check",
312 "A debugging tool to quickly check whether a witness satisfies a circuit The "
313 "function constructs the execution trace and iterates through it row by row, applying the "
314 "polynomial relations defining the gate types. For client IVC, we check the VKs in the folding stack.");
315
316 add_scheme_option(check);
317 add_bytecode_path_option(check);
318 add_witness_path_option(check);
319 add_ivc_inputs_path_options(check);
320 add_update_inputs_flag(check);
321
322 /***************************************************************************************************************
323 * Subcommand: gates
324 ***************************************************************************************************************/
325 CLI::App* gates = app.add_subcommand("gates",
326 "Construct a circuit from the given bytecode (in particular, expand black box "
327 "functions) and return the gate count information.");
328
329 add_scheme_option(gates);
330 add_verbose_flag(gates);
331 add_bytecode_path_option(gates);
332 add_include_gates_per_opcode_flag(gates);
333
334 /***************************************************************************************************************
335 * Subcommand: prove
336 ***************************************************************************************************************/
337 CLI::App* prove = app.add_subcommand("prove", "Generate a proof.");
338
339 add_scheme_option(prove);
340 add_bytecode_path_option(prove);
341 add_witness_path_option(prove);
342 add_output_path_option(prove, output_path);
343 add_ivc_inputs_path_options(prove);
344 add_vk_path_option(prove);
345 add_verbose_flag(prove);
346 add_debug_flag(prove);
347 add_crs_path_option(prove);
348 add_oracle_hash_option(prove);
349 add_output_format_option(prove);
350 add_write_vk_flag(prove);
351 add_ipa_accumulation_flag(prove);
352 remove_zk_option(prove);
353 add_slow_low_memory_flag(prove);
354 add_print_op_counts_flag(prove);
355 add_op_counts_out_option(prove);
356
357 prove->add_flag("--verify", "Verify the proof natively, resulting in a boolean output. Useful for testing.");
358
359 /***************************************************************************************************************
360 * Subcommand: write_vk
361 ***************************************************************************************************************/
362 CLI::App* write_vk =
363 app.add_subcommand("write_vk",
364 "Write the verification key of a circuit. The circuit is constructed using "
365 "quickly generated but invalid witnesses (which must be supplied in Barretenberg in order "
366 "to expand ACIR black box opcodes), and no proof is constructed.");
367
368 add_scheme_option(write_vk);
369 add_bytecode_path_option(write_vk);
370 add_output_path_option(write_vk, output_path);
371 add_ivc_inputs_path_options(write_vk);
372
373 add_verbose_flag(write_vk);
374 add_debug_flag(write_vk);
375 add_output_format_option(write_vk);
376 add_crs_path_option(write_vk);
377 add_oracle_hash_option(write_vk);
378 add_ipa_accumulation_flag(write_vk);
379 add_verifier_type_option(write_vk)->default_val("standalone");
380 remove_zk_option(write_vk);
381
382 /***************************************************************************************************************
383 * Subcommand: verify
384 ***************************************************************************************************************/
385 CLI::App* verify = app.add_subcommand("verify", "Verify a proof.");
386
387 add_public_inputs_path_option(verify);
388 add_proof_path_option(verify);
389 add_vk_path_option(verify);
390
391 add_verbose_flag(verify);
392 add_debug_flag(verify);
393 add_scheme_option(verify);
394 add_crs_path_option(verify);
395 add_oracle_hash_option(verify);
396 remove_zk_option(verify);
397 add_ipa_accumulation_flag(verify);
398
399 /***************************************************************************************************************
400 * Subcommand: write_solidity_verifier
401 ***************************************************************************************************************/
402 CLI::App* write_solidity_verifier =
403 app.add_subcommand("write_solidity_verifier",
404 "Write a Solidity smart contract suitable for verifying proofs of circuit "
405 "satisfiability for the circuit with verification key at vk_path. Not all "
406 "hash types are implemented due to efficiency concerns.");
407
408 add_scheme_option(write_solidity_verifier);
409 add_vk_path_option(write_solidity_verifier);
410 add_output_path_option(write_solidity_verifier, output_path);
411
412 add_verbose_flag(write_solidity_verifier);
413 remove_zk_option(write_solidity_verifier);
414 add_crs_path_option(write_solidity_verifier);
415
416 /***************************************************************************************************************
417 * Subcommand: OLD_API
418 ***************************************************************************************************************/
419 CLI::App* OLD_API = app.add_subcommand("OLD_API", "Access some old API commands");
420
421 /***************************************************************************************************************
422 * Subcommand: OLD_API write_arbitrary_valid_client_ivc_proof_and_vk_to_file
423 ***************************************************************************************************************/
424 CLI::App* OLD_API_write_arbitrary_valid_client_ivc_proof_and_vk_to_file =
425 OLD_API->add_subcommand("write_arbitrary_valid_client_ivc_proof_and_vk_to_file", "");
426 add_verbose_flag(OLD_API_write_arbitrary_valid_client_ivc_proof_and_vk_to_file);
427 add_debug_flag(OLD_API_write_arbitrary_valid_client_ivc_proof_and_vk_to_file);
428 add_crs_path_option(OLD_API_write_arbitrary_valid_client_ivc_proof_and_vk_to_file);
429 std::string arbitrary_valid_proof_path{ "./proofs/proof" };
430 add_output_path_option(OLD_API_write_arbitrary_valid_client_ivc_proof_and_vk_to_file, arbitrary_valid_proof_path);
431
432 /***************************************************************************************************************
433 * Subcommand: OLD_API gates
434 ***************************************************************************************************************/
435 CLI::App* OLD_API_gates = OLD_API->add_subcommand("gates", "");
436 add_verbose_flag(OLD_API_gates);
437 add_debug_flag(OLD_API_gates);
438 add_crs_path_option(OLD_API_gates);
439 add_bytecode_path_option(OLD_API_gates);
440
441 /***************************************************************************************************************
442 * Subcommand: OLD_API verify
443 ***************************************************************************************************************/
444 CLI::App* OLD_API_verify = OLD_API->add_subcommand("verify", "");
445 add_verbose_flag(OLD_API_verify);
446 add_debug_flag(OLD_API_verify);
447 add_crs_path_option(OLD_API_verify);
448 add_bytecode_path_option(OLD_API_verify);
449 add_proof_path_option(OLD_API_verify);
450 add_vk_path_option(OLD_API_verify);
451
452 /***************************************************************************************************************
453 * Subcommand: OLD_API prove_and_verify
454 ***************************************************************************************************************/
455 CLI::App* OLD_API_prove_and_verify = OLD_API->add_subcommand("prove_and_verify", "");
456 add_verbose_flag(OLD_API_prove_and_verify);
457 add_debug_flag(OLD_API_prove_and_verify);
458 add_crs_path_option(OLD_API_prove_and_verify);
459 add_bytecode_path_option(OLD_API_prove_and_verify);
460
461 std::filesystem::path avm_inputs_path{ "./target/avm_inputs.bin" };
462 const auto add_avm_inputs_option = [&](CLI::App* subcommand) {
463 return subcommand->add_option("--avm-inputs", avm_inputs_path, "");
464 };
465 std::filesystem::path avm_public_inputs_path{ "./target/avm_public_inputs.bin" };
466 const auto add_avm_public_inputs_option = [&](CLI::App* subcommand) {
467 return subcommand->add_option("--avm-public-inputs", avm_public_inputs_path, "");
468 };
469
470 /***************************************************************************************************************
471 * Subcommand: avm_prove
472 ***************************************************************************************************************/
473 CLI::App* avm_prove_command = app.add_subcommand("avm_prove", "");
474 avm_prove_command->group(""); // hide from list of subcommands
475 add_verbose_flag(avm_prove_command);
476 add_debug_flag(avm_prove_command);
477 add_crs_path_option(avm_prove_command);
478 std::filesystem::path avm_prove_output_path{ "./proofs" };
479 add_output_path_option(avm_prove_command, avm_prove_output_path);
480 add_avm_inputs_option(avm_prove_command);
481
482 /***************************************************************************************************************
483 * Subcommand: avm_check_circuit
484 ***************************************************************************************************************/
485 CLI::App* avm_check_circuit_command = app.add_subcommand("avm_check_circuit", "");
486 avm_check_circuit_command->group(""); // hide from list of subcommands
487 add_verbose_flag(avm_check_circuit_command);
488 add_debug_flag(avm_check_circuit_command);
489 add_crs_path_option(avm_check_circuit_command);
490 add_avm_inputs_option(avm_check_circuit_command);
491
492 /***************************************************************************************************************
493 * Subcommand: avm_verify
494 ***************************************************************************************************************/
495 CLI::App* avm_verify_command = app.add_subcommand("avm_verify", "");
496 avm_verify_command->group(""); // hide from list of subcommands
497 add_verbose_flag(avm_verify_command);
498 add_debug_flag(avm_verify_command);
499 add_crs_path_option(avm_verify_command);
500 add_avm_public_inputs_option(avm_verify_command);
501 add_proof_path_option(avm_verify_command);
502 add_vk_path_option(avm_verify_command);
503
504 /***************************************************************************************************************
505 * Subcommand: msgpack
506 ***************************************************************************************************************/
507 CLI::App* msgpack_command = app.add_subcommand("msgpack", "Msgpack API interface.");
508
509 // Subcommand: msgpack schema
510 CLI::App* msgpack_schema_command =
511 msgpack_command->add_subcommand("schema", "Output a msgpack schema encoded as JSON to stdout.");
512 add_verbose_flag(msgpack_schema_command);
513
514 // Subcommand: msgpack run
515 CLI::App* msgpack_run_command =
516 msgpack_command->add_subcommand("run", "Execute msgpack API commands from stdin or file.");
517 add_verbose_flag(msgpack_run_command);
518 std::string msgpack_input_file;
519 msgpack_run_command->add_option(
520 "-i,--input", msgpack_input_file, "Input file containing msgpack buffers (defaults to stdin)");
521
522 /***************************************************************************************************************
523 * Subcommand: prove_tube
524 ***************************************************************************************************************/
525 CLI ::App* prove_tube_command = app.add_subcommand("prove_tube", "");
526 prove_tube_command->group(""); // hide from list of subcommands
527 add_verbose_flag(prove_tube_command);
528 add_debug_flag(prove_tube_command);
529 add_crs_path_option(prove_tube_command);
530 add_vk_path_option(prove_tube_command);
531 std::string prove_tube_output_path{ "./target" };
532 add_output_path_option(prove_tube_command, prove_tube_output_path);
533
534 /***************************************************************************************************************
535 * Subcommand: verify_tube
536 ***************************************************************************************************************/
537 CLI::App* verify_tube_command = app.add_subcommand("verify_tube", "");
538 verify_tube_command->group(""); // hide from list of subcommands
539 add_verbose_flag(verify_tube_command);
540 add_debug_flag(verify_tube_command);
541 add_crs_path_option(verify_tube_command);
542 // doesn't make sense that this is set by -o but that's how it was
543 std::string tube_proof_and_vk_path{ "./target" };
544 add_output_path_option(verify_tube_command, tube_proof_and_vk_path);
545
546 /***************************************************************************************************************
547 * Build the CLI11 App
548 ***************************************************************************************************************/
549
550 CLI11_PARSE(app, argc, argv);
551 // Immediately after parsing, we can init the global CRS factory. Note this does not yet read or download any
552 // points; that is done on-demand.
553 srs::init_net_crs_factory(flags.crs_path);
554 if ((prove->parsed() || write_vk->parsed()) && output_path != "-") {
555 // If writing to an output folder, make sure it exists.
556 std::filesystem::create_directories(output_path);
557 }
558 debug_logging = flags.debug;
559 verbose_logging = debug_logging || flags.verbose;
560 slow_low_memory = flags.slow_low_memory;
561#ifndef __wasm__
562 if (print_op_counts || !op_counts_out.empty()) {
564 }
567 }
568#endif
569
571 info("Scheme is: ", flags.scheme, ", num threads: ", get_num_cpus());
572 if (CLI::App* deepest = find_deepest_subcommand(&app)) {
574 }
575
576 // TODO(AD): it is inflexible that CIVC shares an API command (prove) with UH this way. The base API class is a
577 // poor fit. It would be better to have a separate handling for each scheme with subcommands to prove.
578 const auto execute_non_prove_command = [&](API& api) {
579 if (check->parsed()) {
580 api.check(flags, bytecode_path, witness_path);
581 return 0;
582 }
583 if (gates->parsed()) {
584 api.gates(flags, bytecode_path);
585 return 0;
586 }
587 if (write_vk->parsed()) {
588 api.write_vk(flags, bytecode_path, output_path);
589 return 0;
590 }
591 if (verify->parsed()) {
592 const bool verified = api.verify(flags, public_inputs_path, proof_path, vk_path);
593 vinfo("verified: ", verified);
594 return verified ? 0 : 1;
595 }
596 if (write_solidity_verifier->parsed()) {
597 api.write_solidity_verifier(flags, output_path, vk_path);
598 return 0;
599 }
600 auto subcommands = app.get_subcommands();
601 const std::string message = std::string("No handler for subcommand ") + subcommands[0]->get_name();
602 throw_or_abort(message);
603 return 1;
604 };
605
606 try {
607 // MSGPACK
608 if (msgpack_schema_command->parsed()) {
610 return 0;
611 }
612 if (msgpack_run_command->parsed()) {
613 return execute_msgpack_run(msgpack_input_file);
614 }
615 // TUBE
616 if (prove_tube_command->parsed()) {
617 // TODO(https://github.com/AztecProtocol/barretenberg/issues/1201): Potentially remove this extra logic.
618 prove_tube(prove_tube_output_path, vk_path);
619 } else if (verify_tube_command->parsed()) {
620 // TODO(https://github.com/AztecProtocol/barretenberg/issues/1322): Remove verify_tube logic.
621 auto tube_public_inputs_path = tube_proof_and_vk_path + "/public_inputs";
622 auto tube_proof_path = tube_proof_and_vk_path + "/proof";
623 auto tube_vk_path = tube_proof_and_vk_path + "/vk";
624 UltraHonkAPI api;
625 return api.verify({ .ipa_accumulation = true }, tube_public_inputs_path, tube_proof_path, tube_vk_path) ? 0
626 : 1;
627 }
628 // AVM
629#ifndef DISABLE_AZTEC_VM
630 else if (avm_prove_command->parsed()) {
631 // This outputs both files: proof and vk, under the given directory.
632 avm_prove(avm_inputs_path, avm_prove_output_path);
633 } else if (avm_check_circuit_command->parsed()) {
634 avm_check_circuit(avm_inputs_path);
635 } else if (avm_verify_command->parsed()) {
636 return avm_verify(proof_path, avm_public_inputs_path, vk_path) ? 0 : 1;
637 }
638#else
639 else if (avm_prove_command->parsed()) {
640 throw_or_abort("The Aztec Virtual Machine (AVM) is disabled in this environment!");
641 } else if (avm_check_circuit_command->parsed()) {
642 throw_or_abort("The Aztec Virtual Machine (AVM) is disabled in this environment!");
643 } else if (avm_verify_command->parsed()) {
644 throw_or_abort("The Aztec Virtual Machine (AVM) is disabled in this environment!");
645 }
646#endif
647 else if (OLD_API_write_arbitrary_valid_client_ivc_proof_and_vk_to_file->parsed()) {
649 return 0;
650 }
651 // NEW STANDARD API
652 // NOTE(AD): We likely won't really have a standard API if our main flavours are UH or CIVC, with CIVC so
653 // different
654 else if (flags.scheme == "client_ivc") {
655 ClientIVCAPI api;
656 if (prove->parsed()) {
657 if (!std::filesystem::exists(ivc_inputs_path)) {
658 throw_or_abort("The prove command for ClientIVC expect a valid file passed with --ivc_inputs_path "
659 "<ivc-inputs.msgpack> (default ./ivc-inputs.msgpack)");
660 }
661 api.prove(flags, ivc_inputs_path, output_path);
662#ifndef __wasm__
663 if (print_op_counts) {
665 }
666 if (!op_counts_out.empty()) {
667 std::ofstream file(op_counts_out);
669 }
670#endif
671 return 0;
672 }
673 if (check->parsed()) {
674 if (!std::filesystem::exists(ivc_inputs_path)) {
675 throw_or_abort("The check command for ClientIVC expect a valid file passed with --ivc_inputs_path "
676 "<ivc-inputs.msgpack> (default ./ivc-inputs.msgpack)");
677 }
678 return api.check_precomputed_vks(flags, ivc_inputs_path) ? 0 : 1;
679 }
680 return execute_non_prove_command(api);
681 } else if (flags.scheme == "ultra_honk") {
682 UltraHonkAPI api;
683 if (prove->parsed()) {
684 api.prove(flags, bytecode_path, witness_path, vk_path, output_path);
685#ifndef __wasm__
686 if (print_op_counts) {
688 }
689 if (!op_counts_out.empty()) {
690 std::ofstream file(op_counts_out);
692 }
693#endif
694 return 0;
695 }
696 return execute_non_prove_command(api);
697 } else {
698 throw_or_abort("No match for API command");
699 return 1;
700 }
701 } catch (std::runtime_error const& err) {
702#ifndef BB_NO_EXCEPTIONS
703 std::cerr << err.what() << std::endl;
704 return 1;
705#endif
706 }
707 return 0;
708}
709} // namespace bb
bool slow_low_memory
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)
bool verify(const Flags &flags, const std::filesystem::path &public_inputs_path, const std::filesystem::path &proof_path, const std::filesystem::path &vk_path) override
#define CLI11_PARSE(app,...)
void vinfo(Args... args)
Definition log.hpp:76
void info(Args... args)
Definition log.hpp:70
bool debug_logging
Definition log.cpp:12
bool verbose_logging
Definition log.cpp:6
std::string get_msgpack_schema_as_json()
bool use_op_count_time
Definition op_count.cpp:11
GlobalOpCountContainer GLOBAL_OP_COUNTS
Definition op_count.cpp:87
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:73
const char *const BB_VERSION_PLACEHOLDER
Definition cli.cpp:38
int parse_and_run_cli_command(int argc, char *argv[])
Parse command line arguments and run the corresponding command.
Definition cli.cpp:104
void write_arbitrary_valid_client_ivc_proof_and_vk_to_file(const std::filesystem::path &output_dir)
size_t get_num_cpus()
Definition thread.hpp:12
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:44
void prove_tube(const std::string &output_path, const std::string &vk_path)
Creates a Honk Proof for the Tube circuit responsible for recursively verifying a ClientIVC proof.
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:58
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
std::string scheme
Definition api.hpp:18
void print_aggregate_counts(std::ostream &, size_t) const
Definition op_count.cpp:58
void throw_or_abort(std::string const &err)