Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
cli.cpp
Go to the documentation of this file.
1
39#include <atomic>
40#include <fstream>
41#include <iostream>
42#include <mutex>
43
44namespace bb {
45
46// TODO(https://github.com/AztecProtocol/barretenberg/issues/1257): Remove unused/seemingly unnecessary flags.
47// TODO(https://github.com/AztecProtocol/barretenberg/issues/1258): Improve defaults.
48
49// Helper function to recursively print active subcommands for CLI11 app debugging
50void print_active_subcommands(const CLI::App& app, const std::string& prefix = "bb command: ")
51{
52 // get_subcommands() returns a vector of pointers to subcommands
53 for (auto* subcmd : app.get_subcommands()) {
54 // Check if this subcommand was activated (nonzero count)
55 if (subcmd->count() > 0) {
56 vinfo(prefix, subcmd->get_name());
57 // Recursively print any subcommands of this subcommand
58 print_active_subcommands(*subcmd, prefix + " ");
59 }
60 }
61}
62
63// Recursive helper to find the deepest parsed subcommand.
64CLI::App* find_deepest_subcommand(CLI::App* app)
65{
66 for (auto& sub : app->get_subcommands()) {
67 if (sub->parsed()) {
68 // Check recursively if this subcommand has a deeper parsed subcommand.
69 if (CLI::App* deeper = find_deepest_subcommand(sub); deeper != nullptr) {
70 return deeper;
71 }
72 return sub;
73 }
74 }
75 return nullptr;
76}
77
78// Helper function to print options for a given subcommand.
79void print_subcommand_options(const CLI::App* sub)
80{
81 for (const auto& opt : sub->get_options()) {
82 if (opt->count() > 0) { // Only print options that were set.
83 if (opt->results().size() > 1) {
84 vinfo(" Warning: the following option is called more than once");
85 }
86 vinfo(" ", opt->get_name(), ": ", opt->results()[0]);
87 }
88 }
89}
90
110int parse_and_run_cli_command(int argc, char* argv[])
111{
112 std::string name = "Barretenberg\nYour favo(u)rite zkSNARK library written in C++, a perfectly good computer "
113 "programming language.";
114
115 // Check AVM support at runtime via global boolean
116 if (avm_enabled) {
117 name += "\nAztec Virtual Machine (AVM): enabled";
118 } else {
119 name += "\nAztec Virtual Machine (AVM): disabled";
120 }
121#ifdef ENABLE_AVM_TRANSPILER
122 name += "\nAVM Transpiler: enabled";
123#else
124 name += "\nAVM Transpiler: disabled";
125#endif
126#ifdef STARKNET_GARAGA_FLAVORS
127 name += "\nStarknet Garaga Extensions: enabled";
128#else
129 name += "\nStarknet Garaga Extensions: disabled";
130#endif
131 CLI::App app{ name };
132 argv = app.ensure_utf8(argv);
133 app.formatter(std::make_shared<Formatter>());
134
135 // If no arguments are provided, print help and exit.
136 if (argc == 1) {
137 std::cout << app.help() << std::endl;
138 return 0;
139 }
140
141 // prevent two or more subcommands being executed
142 app.require_subcommand(0, 1);
143
144 API::Flags flags{};
145 // Some paths, with defaults, that may or may not be set by commands
146 std::filesystem::path bytecode_path{ "./target/program.json" };
147 std::filesystem::path witness_path{ "./target/witness.gz" };
148 std::filesystem::path ivc_inputs_path{ "./ivc-inputs.msgpack" };
149 std::filesystem::path output_path{
150 "./out"
151 }; // sometimes a directory where things will be written, sometimes the path of a file to be written
152 std::filesystem::path public_inputs_path{ "./target/public_inputs" };
153 std::filesystem::path proof_path{ "./target/proof" };
154 std::filesystem::path vk_path{ "./target/vk" };
155 flags.scheme = "";
156 flags.oracle_hash_type = "poseidon2";
157 flags.crs_path = srs::bb_crs_path();
158 flags.include_gates_per_opcode = false;
159
160 /***************************************************************************************************************
161 * Flag: --help-extended (detected early to set group visibility)
162 ***************************************************************************************************************/
163 // Check if --help-extended was passed before parsing (since we need to modify group visibility before CLI setup)
164 bool show_extended_help = false;
165 for (int i = 1; i < argc; ++i) {
166 if (std::string(argv[i]) == "--help-extended") {
167 show_extended_help = true;
168 break;
169 }
170 }
171 // Group names - empty string hides the group from help, non-empty shows it
172 const std::string advanced_group = show_extended_help ? "Advanced Options (Aztec/Power Users)" : "";
173 const std::string aztec_internal_group = show_extended_help ? "Aztec Internal Commands" : "";
174
175 const auto add_output_path_option = [&](CLI::App* subcommand, auto& _output_path) {
176 return subcommand->add_option("--output_path, -o",
177 _output_path,
178 "Directory to write files or path of file to write, depending on subcommand.");
179 };
180
181 // Helper to add --help-extended to subcommands (for help consistency)
182 const auto add_help_extended_flag = [&](CLI::App* subcommand) {
183 subcommand->add_flag("--help-extended", "Show all options including advanced ones.");
184 };
185
186 /***************************************************************************************************************
187 * Subcommand: Adders for options that we will create for more than one subcommand
188 ***************************************************************************************************************/
189
190 const auto add_ipa_accumulation_flag = [&](CLI::App* subcommand) {
191 return subcommand
192 ->add_flag("--ipa_accumulation",
193 flags.ipa_accumulation,
194 "Accumulate/Aggregate IPA (Inner Product Argument) claims")
195 ->group(advanced_group);
196 };
197
198 const auto add_scheme_option = [&](CLI::App* subcommand) {
199 return subcommand
200 ->add_option(
201 "--scheme, -s",
202 flags.scheme,
203 "The type of proof to be constructed. This can specify a proving system, an accumulation scheme, or a "
204 "particular type of circuit to be constructed and proven for some implicit scheme.")
205 ->envname("BB_SCHEME")
206 ->default_val("ultra_honk")
207 ->check(CLI::IsMember({ "chonk", "avm", "ultra_honk" }).name("is_member"))
208 ->group(advanced_group);
209 };
210
211 const auto add_crs_path_option = [&](CLI::App* subcommand) {
212 return subcommand
213 ->add_option("--crs_path, -c",
214 flags.crs_path,
215 "Path CRS directory. Missing CRS files will be retrieved from the internet.")
216 ->check(CLI::ExistingDirectory)
217 ->group(advanced_group);
218 };
219
220 const auto add_oracle_hash_option = [&](CLI::App* subcommand) {
221 return subcommand
222 ->add_option(
223 "--oracle_hash",
224 flags.oracle_hash_type,
225 "The hash function used by the prover as random oracle standing in for a verifier's challenge "
226 "generation. Poseidon2 is to be used for proofs that are intended to be verified inside of a "
227 "circuit. Keccak is optimized for verification in an Ethereum smart contract, where Keccak "
228 "has a privileged position due to the existence of an EVM precompile. Starknet is optimized "
229 "for verification in a Starknet smart contract, which can be generated using the Garaga library. "
230 "Prefer using --verifier_target instead.")
231 ->check(CLI::IsMember({ "poseidon2", "keccak", "starknet" }).name("is_member"))
232 ->group(advanced_group);
233 };
234
235 const auto add_verifier_target_option = [&](CLI::App* subcommand) {
236 return subcommand
237 ->add_option("--verifier_target, -t",
238 flags.verifier_target,
239 "Target verification environment. Determines hash function and ZK settings.\n"
240 "\n"
241 "Options:\n"
242 " evm Ethereum/Solidity (keccak, ZK)\n"
243 " evm-no-zk Ethereum/Solidity without ZK\n"
244 " noir-recursive Noir circuits (poseidon2, ZK)\n"
245 " noir-recursive-no-zk Noir circuits without ZK\n"
246 " noir-rollup Rollup with IPA (poseidon2, ZK)\n"
247 " noir-rollup-no-zk Rollup without ZK\n"
248 " starknet Starknet via Garaga (ZK)\n"
249 " starknet-no-zk Starknet without ZK")
250 ->envname("BB_VERIFIER_TARGET")
251 ->check(CLI::IsMember({ "evm",
252 "evm-no-zk",
253 "noir-recursive",
254 "noir-recursive-no-zk",
255 "noir-rollup",
256 "noir-rollup-no-zk",
257 "starknet",
258 "starknet-no-zk" }));
259 };
260
261 const auto add_write_vk_flag = [&](CLI::App* subcommand) {
262 return subcommand->add_flag("--write_vk", flags.write_vk, "Write the provided circuit's verification key");
263 };
264
265 const auto remove_zk_option = [&](CLI::App* subcommand) {
266 return subcommand
267 ->add_flag("--disable_zk",
268 flags.disable_zk,
269 "Use a non-zk version of --scheme. Prefer using --verifier_target *-no-zk variants instead.")
270 ->group(advanced_group);
271 };
272
273 const auto add_bytecode_path_option = [&](CLI::App* subcommand) {
274 subcommand->add_option("--bytecode_path, -b", bytecode_path, "Path to ACIR bytecode generated by Noir.")
275 /* ->check(CLI::ExistingFile) OR stdin indicator - */;
276 };
277
278 const auto add_witness_path_option = [&](CLI::App* subcommand) {
279 subcommand->add_option("--witness_path, -w", witness_path, "Path to partial witness generated by Noir.")
280 /* ->check(CLI::ExistingFile) OR stdin indicator - */;
281 };
282
283 const auto add_ivc_inputs_path_options = [&](CLI::App* subcommand) {
284 subcommand
285 ->add_option(
286 "--ivc_inputs_path", ivc_inputs_path, "For IVC, path to input stack with bytecode and witnesses.")
287 ->group(advanced_group);
288 };
289
290 const auto add_public_inputs_path_option = [&](CLI::App* subcommand) {
291 return subcommand->add_option(
292 "--public_inputs_path, -i", public_inputs_path, "Path to public inputs.") /* ->check(CLI::ExistingFile) */;
293 };
294
295 const auto add_proof_path_option = [&](CLI::App* subcommand) {
296 return subcommand->add_option(
297 "--proof_path, -p", proof_path, "Path to a proof.") /* ->check(CLI::ExistingFile) */;
298 };
299
300 const auto add_vk_path_option = [&](CLI::App* subcommand) {
301 return subcommand->add_option("--vk_path, -k", vk_path, "Path to a verification key.")
302 /* ->check(CLI::ExistingFile) */;
303 };
304
305 const auto add_verbose_flag = [&](CLI::App* subcommand) {
306 return subcommand->add_flag("--verbose, --verbose_logging, -v", flags.verbose, "Output all logs to stderr.")
307 ->group(advanced_group);
308 };
309
310 const auto add_debug_flag = [&](CLI::App* subcommand) {
311 return subcommand->add_flag("--debug_logging, -d", flags.debug, "Output debug logs to stderr.")
312 ->group(advanced_group);
313 };
314
315 bool disable_asserts = false;
316 const auto add_disable_asserts_flag = [&](CLI::App* subcommand) {
317 return subcommand
318 ->add_flag("--disable_asserts",
319 disable_asserts,
320 "Disable BB assertions (asserts become warnings). Not for production use.")
321 ->group(advanced_group);
322 };
323
324 const auto add_include_gates_per_opcode_flag = [&](CLI::App* subcommand) {
325 return subcommand->add_flag("--include_gates_per_opcode",
326 flags.include_gates_per_opcode,
327 "Include gates_per_opcode in the output of the gates command.");
328 };
329
330 const auto add_slow_low_memory_flag = [&](CLI::App* subcommand) {
331 return subcommand
332 ->add_flag("--slow_low_memory", flags.slow_low_memory, "Enable low memory mode (can be 2x slower or more).")
333 ->group(advanced_group);
334 };
335
336 const auto add_storage_budget_option = [&](CLI::App* subcommand) {
337 return subcommand
338 ->add_option("--storage_budget",
339 flags.storage_budget,
340 "Storage budget for FileBackedMemory (e.g. '500m', '2g'). When exceeded, falls "
341 "back to RAM (requires --slow_low_memory).")
342 ->group(advanced_group);
343 };
344
345 const auto add_vk_policy_option = [&](CLI::App* subcommand) {
346 return subcommand
347 ->add_option("--vk_policy",
348 flags.vk_policy,
349 "Policy for handling verification keys. 'default' uses the provided VK as-is, 'check' "
350 "verifies the provided VK matches the computed VK (throws error on mismatch), 'recompute' "
351 "always ignores the provided VK and treats it as nullptr, 'rewrite' checks the VK and "
352 "rewrites the input file with the correct VK if there's a mismatch (for check command).")
353 ->check(CLI::IsMember({ "default", "check", "recompute", "rewrite" }).name("is_member"))
354 ->group(advanced_group);
355 };
356
357 const auto add_use_zk_flavor_flag = [&](CLI::App* subcommand) {
358 return subcommand
359 ->add_flag("--use_zk_flavor",
360 flags.use_zk_flavor,
361 "Chonk-only: derive the VK against MegaZKFlavor rather than MegaFlavor. "
362 "Set this for the IVC hiding kernel (the only Chonk circuit proven as MegaZK).")
363 ->group(advanced_group);
364 };
365
366 const auto add_optimized_solidity_verifier_flag = [&](CLI::App* subcommand) {
367 return subcommand->add_flag(
368 "--optimized", flags.optimized_solidity_verifier, "Use the optimized Solidity verifier.");
369 };
370
371 const auto add_output_format_option = [&](CLI::App* subcommand) {
372 return subcommand
373 ->add_option("--output_format",
374 flags.output_format,
375 "Output format for proofs and verification keys: 'binary' (default) or 'json'.\n"
376 "JSON format includes metadata like bb_version, scheme, and verifier_target.")
377 ->check(CLI::IsMember({ "binary", "json" }).name("is_member"));
378 };
379
380 bool print_bench = false;
381 const auto add_print_bench_flag = [&](CLI::App* subcommand) {
382 return subcommand
383 ->add_flag(
384 "--print_bench", print_bench, "Pretty print op counts to standard error in a human-readable format.")
385 ->group(advanced_group);
386 };
387
388 std::string bench_out;
389 const auto add_bench_out_option = [&](CLI::App* subcommand) {
390 return subcommand->add_option("--bench_out", bench_out, "Path to write the op counts in a json.")
391 ->group(advanced_group);
392 };
393 std::string bench_out_hierarchical;
394 const auto add_bench_out_hierarchical_option = [&](CLI::App* subcommand) {
395 return subcommand
396 ->add_option("--bench_out_hierarchical",
397 bench_out_hierarchical,
398 "Path to write the hierarchical benchmark data (op counts and timings with "
399 "parent-child relationships) as json.")
400 ->group(advanced_group);
401 };
402 std::string memory_profile_out;
403 const auto add_memory_profile_out_option = [&](CLI::App* subcommand) {
404 return subcommand
405 ->add_option("--memory_profile_out",
406 memory_profile_out,
407 "Path to write memory profile data (polynomial breakdown by category, RSS "
408 "checkpoints, CRS size) as json.")
409 ->group(advanced_group);
410 };
411
412 std::string trace_out_perfetto;
413 const auto add_trace_out_perfetto_option = [&](CLI::App* subcommand) {
414 return subcommand
415 ->add_option("--trace_out_perfetto",
416 trace_out_perfetto,
417 "Path to write a Chrome Trace Event Format JSON of every instrumented "
418 "BB_BENCH scope (per-call timeline). Drop the file into ui.perfetto.dev "
419 "or chrome://tracing.")
420 ->group(advanced_group);
421 };
422 std::string trace_out_perfetto_aggregate;
423 const auto add_trace_out_perfetto_aggregate_option = [&](CLI::App* subcommand) {
424 return subcommand
425 ->add_option("--trace_out_perfetto_aggregate",
426 trace_out_perfetto_aggregate,
427 "Path to write a synthesized Chrome Trace Event Format JSON derived from the "
428 "aggregate stats. Smaller than --trace_out_perfetto but lossy about individual "
429 "call timing.")
430 ->group(advanced_group);
431 };
432
433 /***************************************************************************************************************
434 * Top-level flags
435 ***************************************************************************************************************/
436 add_verbose_flag(&app);
437 add_debug_flag(&app);
438 add_crs_path_option(&app);
439
440 /***************************************************************************************************************
441 * Builtin flag: --version
442 ***************************************************************************************************************/
443 app.set_version_flag("--version", BB_VERSION, "Print the version string.");
444
445 /***************************************************************************************************************
446 * Flag: --help-extended (register with CLI11)
447 ***************************************************************************************************************/
448 app.add_flag("--help-extended", "Show all options including advanced and Aztec-specific commands.");
449
450 /***************************************************************************************************************
451 * Subcommand: acir_roundtrip
452 ***************************************************************************************************************/
453 std::filesystem::path acir_roundtrip_output_path;
454 CLI::App* acir_roundtrip_cmd =
455 app.add_subcommand("acir_roundtrip",
456 "[Internal testing] Deserialize an ACIR program from bytecode (msgpack), "
457 "re-serialize it back to msgpack, and write it to an output JSON file "
458 "in nargo-compatible format. Functional equivalence should then be verified "
459 "externally (e.g. by proving with the roundtripped bytecode).");
460
461 acir_roundtrip_cmd->group(aztec_internal_group);
462 add_bytecode_path_option(acir_roundtrip_cmd);
463 acir_roundtrip_cmd
464 ->add_option("--output_path,-o", acir_roundtrip_output_path, "Output path for the roundtripped bytecode JSON.")
465 ->required();
466
467 /***************************************************************************************************************
468 * Subcommand: check
469 ***************************************************************************************************************/
470 CLI::App* check = app.add_subcommand(
471 "check",
472 "A debugging tool to quickly check whether a witness satisfies a circuit The "
473 "function constructs the execution trace and iterates through it row by row, applying the "
474 "polynomial relations defining the gate types. For Chonk, we check the VKs in the folding stack.");
475
476 add_help_extended_flag(check);
477 add_scheme_option(check);
478 add_bytecode_path_option(check);
479 add_witness_path_option(check);
480 add_ivc_inputs_path_options(check);
481 add_vk_policy_option(check);
482 add_disable_asserts_flag(check);
483
484 /***************************************************************************************************************
485 * Subcommand: gates
486 ***************************************************************************************************************/
487 CLI::App* gates = app.add_subcommand("gates",
488 "Construct a circuit from the given bytecode (in particular, expand black box "
489 "functions) and return the gate count information.");
490
491 add_help_extended_flag(gates);
492 add_scheme_option(gates);
493 add_verbose_flag(gates);
494 add_bytecode_path_option(gates);
495 add_include_gates_per_opcode_flag(gates);
496 add_verifier_target_option(gates);
497 add_oracle_hash_option(gates);
498 add_ipa_accumulation_flag(gates);
499
500 /***************************************************************************************************************
501 * Subcommand: prove
502 ***************************************************************************************************************/
503 CLI::App* prove = app.add_subcommand("prove", "Generate a proof.");
504
505 add_help_extended_flag(prove);
506 add_scheme_option(prove);
507 add_bytecode_path_option(prove);
508 add_witness_path_option(prove);
509 add_output_path_option(prove, output_path);
510 add_ivc_inputs_path_options(prove);
511 add_vk_path_option(prove);
512 add_vk_policy_option(prove);
513 add_verbose_flag(prove);
514 add_debug_flag(prove);
515 add_crs_path_option(prove);
516 add_verifier_target_option(prove);
517 add_oracle_hash_option(prove);
518 add_write_vk_flag(prove);
519 add_ipa_accumulation_flag(prove);
520 remove_zk_option(prove);
521 add_slow_low_memory_flag(prove);
522 add_print_bench_flag(prove);
523 add_bench_out_option(prove);
524 add_bench_out_hierarchical_option(prove);
525 add_memory_profile_out_option(prove);
526 add_trace_out_perfetto_option(prove);
527 add_trace_out_perfetto_aggregate_option(prove);
528 add_storage_budget_option(prove);
529 add_output_format_option(prove);
530
531 prove->add_flag("--verify", "Verify the proof natively, resulting in a boolean output. Useful for testing.");
532
533 /***************************************************************************************************************
534 * Subcommand: write_vk
535 ***************************************************************************************************************/
536 CLI::App* write_vk =
537 app.add_subcommand("write_vk",
538 "Write the verification key of a circuit. The circuit is constructed using "
539 "quickly generated but invalid witnesses (which must be supplied in Barretenberg in order "
540 "to expand ACIR black box opcodes), and no proof is constructed.");
541
542 add_help_extended_flag(write_vk);
543 add_scheme_option(write_vk);
544 add_bytecode_path_option(write_vk);
545 add_output_path_option(write_vk, output_path);
546 add_ivc_inputs_path_options(write_vk);
547
548 add_verbose_flag(write_vk);
549 add_debug_flag(write_vk);
550 add_crs_path_option(write_vk);
551 add_verifier_target_option(write_vk);
552 add_oracle_hash_option(write_vk);
553 add_ipa_accumulation_flag(write_vk);
554 remove_zk_option(write_vk);
555 add_output_format_option(write_vk);
556 add_use_zk_flavor_flag(write_vk);
557
558 /***************************************************************************************************************
559 * Subcommand: verify
560 ***************************************************************************************************************/
561 CLI::App* verify = app.add_subcommand("verify", "Verify a proof.");
562
563 add_help_extended_flag(verify);
564 add_public_inputs_path_option(verify);
565 add_proof_path_option(verify);
566 add_vk_path_option(verify);
567
568 add_verbose_flag(verify);
569 add_debug_flag(verify);
570 add_scheme_option(verify);
571 add_crs_path_option(verify);
572 add_verifier_target_option(verify);
573 add_oracle_hash_option(verify);
574 remove_zk_option(verify);
575 add_ipa_accumulation_flag(verify);
576
577 /***************************************************************************************************************
578 * Subcommand: batch_verify
579 ***************************************************************************************************************/
580 std::filesystem::path batch_verify_proofs_dir{ "./proofs" };
581 CLI::App* batch_verify =
582 app.add_subcommand("batch_verify", "Batch-verify multiple Chonk proofs with a single IPA SRS MSM.");
583
584 add_help_extended_flag(batch_verify);
585 add_scheme_option(batch_verify);
586 batch_verify->add_option("--proofs_dir", batch_verify_proofs_dir, "Directory containing proof_N/vk_N pairs.");
587 add_verbose_flag(batch_verify);
588 add_debug_flag(batch_verify);
589 add_crs_path_option(batch_verify);
590
591 /***************************************************************************************************************
592 * Subcommand: proof_stats
593 ***************************************************************************************************************/
594 CLI::App* proof_stats =
595 app.add_subcommand("proof_stats", "Output proof statistics (compressed size, number of public inputs).");
596
597 add_help_extended_flag(proof_stats);
598 add_scheme_option(proof_stats);
599 add_proof_path_option(proof_stats);
600 add_output_path_option(proof_stats, output_path);
601 add_verbose_flag(proof_stats);
602
603 /***************************************************************************************************************
604 * Subcommand: write_solidity_verifier
605 ***************************************************************************************************************/
606 CLI::App* write_solidity_verifier =
607 app.add_subcommand("write_solidity_verifier",
608 "Write a Solidity smart contract suitable for verifying proofs of circuit "
609 "satisfiability for the circuit with verification key at vk_path. Not all "
610 "hash types are implemented due to efficiency concerns.");
611
612 add_help_extended_flag(write_solidity_verifier);
613 add_scheme_option(write_solidity_verifier);
614 add_vk_path_option(write_solidity_verifier);
615 add_output_path_option(write_solidity_verifier, output_path);
616
617 add_verbose_flag(write_solidity_verifier);
618 add_verifier_target_option(write_solidity_verifier);
619 remove_zk_option(write_solidity_verifier);
620 add_crs_path_option(write_solidity_verifier);
621 add_optimized_solidity_verifier_flag(write_solidity_verifier);
622
623 std::filesystem::path avm_inputs_path{ "./target/avm_inputs.bin" };
624 const auto add_avm_inputs_option = [&](CLI::App* subcommand) {
625 return subcommand->add_option("--avm-inputs", avm_inputs_path, "");
626 };
627 std::filesystem::path avm_public_inputs_path{ "./target/avm_public_inputs.bin" };
628 const auto add_avm_public_inputs_option = [&](CLI::App* subcommand) {
629 return subcommand->add_option("--avm-public-inputs", avm_public_inputs_path, "");
630 };
631
632 /***************************************************************************************************************
633 * Subcommand: avm_simulate
634 ***************************************************************************************************************/
635 CLI::App* avm_simulate_command = app.add_subcommand("avm_simulate", "Simulate AVM execution.");
636 avm_simulate_command->group(aztec_internal_group);
637 add_verbose_flag(avm_simulate_command);
638 add_debug_flag(avm_simulate_command);
639 add_avm_inputs_option(avm_simulate_command);
640
641 /***************************************************************************************************************
642 * Subcommand: avm_prove
643 ***************************************************************************************************************/
644 CLI::App* avm_prove_command = app.add_subcommand("avm_prove", "Generate an AVM proof.");
645 avm_prove_command->group(aztec_internal_group);
646 add_verbose_flag(avm_prove_command);
647 add_debug_flag(avm_prove_command);
648 add_crs_path_option(avm_prove_command);
649 std::filesystem::path avm_prove_output_path{ "./proofs" };
650 add_output_path_option(avm_prove_command, avm_prove_output_path);
651 add_avm_inputs_option(avm_prove_command);
652
653 /***************************************************************************************************************
654 * Subcommand: avm_write_vk
655 ***************************************************************************************************************/
656 CLI::App* avm_write_vk_command = app.add_subcommand("avm_write_vk", "Write AVM verification key.");
657 avm_write_vk_command->group(aztec_internal_group);
658 add_verbose_flag(avm_write_vk_command);
659 add_debug_flag(avm_write_vk_command);
660 add_crs_path_option(avm_write_vk_command);
661 std::filesystem::path avm_write_vk_output_path{ "./keys" };
662 add_output_path_option(avm_write_vk_command, avm_write_vk_output_path);
663
664 /***************************************************************************************************************
665 * Subcommand: avm_check_circuit
666 ***************************************************************************************************************/
667 CLI::App* avm_check_circuit_command = app.add_subcommand("avm_check_circuit", "Check AVM circuit satisfiability.");
668 avm_check_circuit_command->group(aztec_internal_group);
669 add_verbose_flag(avm_check_circuit_command);
670 add_debug_flag(avm_check_circuit_command);
671 add_crs_path_option(avm_check_circuit_command);
672 add_avm_inputs_option(avm_check_circuit_command);
673
674 /***************************************************************************************************************
675 * Subcommand: avm_verify
676 ***************************************************************************************************************/
677 CLI::App* avm_verify_command = app.add_subcommand("avm_verify", "Verify an AVM proof.");
678 avm_verify_command->group(aztec_internal_group);
679 add_verbose_flag(avm_verify_command);
680 add_debug_flag(avm_verify_command);
681 add_crs_path_option(avm_verify_command);
682 add_avm_public_inputs_option(avm_verify_command);
683 add_proof_path_option(avm_verify_command);
684
685 /***************************************************************************************************************
686 * Subcommand: aztec_process_artifact
687 ***************************************************************************************************************/
688 CLI::App* aztec_process = app.add_subcommand(
689 "aztec_process",
690 "Process Aztec contract artifacts: transpile and generate verification keys for all private functions.\n"
691 "If input is a directory (and no output specified), recursively processes all artifacts found in the "
692 "directory.\n"
693 "Multiple -i flags can be specified when no -o flag is present for parallel processing.");
694 aztec_process->group(aztec_internal_group);
695
696 std::vector<std::string> artifact_input_paths;
697 std::string artifact_output_path;
698 bool force_regenerate = false;
699
700 aztec_process->add_option("-i,--input",
701 artifact_input_paths,
702 "Input artifact JSON path or directory to search (optional, defaults to current "
703 "directory). Can be specified multiple times when no -o flag is present.");
704 aztec_process->add_option(
705 "-o,--output",
706 artifact_output_path,
707 "Output artifact JSON path (optional, same as input if not specified). Cannot be used with multiple -i flags.");
708 aztec_process->add_flag("-f,--force", force_regenerate, "Force regeneration of verification keys");
709 add_verbose_flag(aztec_process);
710 add_debug_flag(aztec_process);
711
712 /***************************************************************************************************************
713 * Subcommand: aztec_process cache_paths
714 ***************************************************************************************************************/
715 CLI::App* cache_paths_command =
716 aztec_process->add_subcommand("cache_paths",
717 "Output cache paths for verification keys in an artifact.\n"
718 "Format: <hash>:<cache_path>:<function_name> (one per line).");
719
720 std::string cache_paths_input;
721 cache_paths_command->add_option("input", cache_paths_input, "Input artifact JSON path (required).")->required();
722 add_verbose_flag(cache_paths_command);
723 add_debug_flag(cache_paths_command);
724
725 /***************************************************************************************************************
726 * Subcommand: msgpack
727 ***************************************************************************************************************/
728 CLI::App* msgpack_command = app.add_subcommand("msgpack", "Msgpack API interface.");
729
730 // Subcommand: msgpack schema
731 CLI::App* msgpack_schema_command =
732 msgpack_command->add_subcommand("schema", "Output a msgpack schema encoded as JSON to stdout.");
733 add_verbose_flag(msgpack_schema_command);
734
735 // Subcommand: msgpack curve_constants
736 CLI::App* msgpack_curve_constants_command =
737 msgpack_command->add_subcommand("curve_constants", "Output curve constants as msgpack to stdout.");
738 add_verbose_flag(msgpack_curve_constants_command);
739
740 // Subcommand: msgpack run
741 CLI::App* msgpack_run_command =
742 msgpack_command->add_subcommand("run", "Execute msgpack API commands from stdin or file.");
743 add_verbose_flag(msgpack_run_command);
744 std::string msgpack_input_file;
745 msgpack_run_command->add_option(
746 "-i,--input", msgpack_input_file, "Input file containing msgpack buffers (defaults to stdin)");
747 size_t request_ring_size = 1024 * 1024; // 1MB default
748 msgpack_run_command
749 ->add_option(
750 "--request-ring-size", request_ring_size, "Request ring buffer size for shared memory IPC (default: 1MB)")
751 ->check(CLI::PositiveNumber);
752 size_t response_ring_size = 1024 * 1024; // 1MB default
753 msgpack_run_command
754 ->add_option("--response-ring-size",
755 response_ring_size,
756 "Response ring buffer size for shared memory IPC (default: 1MB)")
757 ->check(CLI::PositiveNumber);
758 int max_clients = 1;
759 msgpack_run_command
760 ->add_option("--max-clients",
761 max_clients,
762 "Maximum concurrent clients for socket IPC servers (default: 1, only used for .sock files)")
763 ->check(CLI::PositiveNumber);
764
765 /***************************************************************************************************************
766 * Build the CLI11 App
767 ***************************************************************************************************************/
768
769 CLI11_PARSE(app, argc, argv);
770
771 // Handle --help-extended: print help and exit
772 if (show_extended_help) {
773 std::cout << app.help() << '\n';
774 return 0;
775 }
776
777 // Apply verifier_target to derive oracle_hash_type, disable_zk, and ipa_accumulation
778 // This only applies when verifier_target is explicitly set
779 if (!flags.verifier_target.empty()) {
780 // Check for conflicting flags - verifier_target should not be combined with low-level flags
781 // We need to check the active subcommand for these options
782 CLI::App* active_sub = find_deepest_subcommand(&app);
783 if (active_sub != nullptr) {
784 // Helper to safely get option count (returns 0 if option doesn't exist)
785 auto get_option_count = [](CLI::App* sub, const std::string& name) -> size_t {
786 try {
787 return sub->get_option(name)->count();
788 } catch (const CLI::OptionNotFound&) {
789 return 0;
790 }
791 };
792
793 if (get_option_count(active_sub, "--oracle_hash") > 0) {
794 throw_or_abort("Cannot use --verifier_target with --oracle_hash. "
795 "The --verifier_target flag sets oracle_hash automatically.");
796 }
797 if (get_option_count(active_sub, "--disable_zk") > 0) {
798 throw_or_abort("Cannot use --verifier_target with --disable_zk. "
799 "Use a '-no-zk' variant of --verifier_target instead (e.g., 'evm-no-zk').");
800 }
801 if (get_option_count(active_sub, "--ipa_accumulation") > 0) {
802 throw_or_abort("Cannot use --verifier_target with --ipa_accumulation. "
803 "Use '--verifier_target noir-rollup' for IPA accumulation.");
804 }
805 }
806
807 // Map verifier_target to underlying flags
808 if (flags.verifier_target == "evm") {
809 flags.oracle_hash_type = "keccak";
810 } else if (flags.verifier_target == "evm-no-zk") {
811 flags.oracle_hash_type = "keccak";
812 flags.disable_zk = true;
813 } else if (flags.verifier_target == "noir-recursive") {
814 flags.oracle_hash_type = "poseidon2";
815 } else if (flags.verifier_target == "noir-recursive-no-zk") {
816 flags.oracle_hash_type = "poseidon2";
817 flags.disable_zk = true;
818 } else if (flags.verifier_target == "noir-rollup") {
819 flags.oracle_hash_type = "poseidon2";
820 flags.ipa_accumulation = true;
821 } else if (flags.verifier_target == "noir-rollup-no-zk") {
822 flags.oracle_hash_type = "poseidon2";
823 flags.ipa_accumulation = true;
824 flags.disable_zk = true;
825 } else if (flags.verifier_target == "starknet") {
826 flags.oracle_hash_type = "starknet";
827 } else if (flags.verifier_target == "starknet-no-zk") {
828 flags.oracle_hash_type = "starknet";
829 flags.disable_zk = true;
830 }
831 vinfo("verifier_target '",
832 flags.verifier_target,
833 "' -> oracle_hash_type='",
834 flags.oracle_hash_type,
835 "', disable_zk=",
836 flags.disable_zk,
837 ", ipa_accumulation=",
838 flags.ipa_accumulation);
839 }
840
841 // Immediately after parsing, we can init the global CRS factory. Note this does not yet read or download any
842 // points; that is done on-demand.
843 srs::init_net_crs_factory(flags.crs_path);
844 if ((prove->parsed() || write_vk->parsed()) && output_path != "-") {
845 // If writing to an output folder, make sure it exists.
846 std::filesystem::create_directories(output_path);
847 }
848 if (flags.debug) {
850 } else if (flags.verbose) {
852 }
853 slow_low_memory = flags.slow_low_memory;
854#if !defined(__wasm__) || defined(ENABLE_WASM_BENCH)
855 if (!flags.storage_budget.empty()) {
856 storage_budget = parse_size_string(flags.storage_budget);
857 }
858 if (!memory_profile_out.empty()) {
860 vinfo("Memory profiling enabled via --memory_profile_out");
861 }
862 if (print_bench || !bench_out.empty() || !bench_out_hierarchical.empty() || !trace_out_perfetto.empty() ||
863 !trace_out_perfetto_aggregate.empty()) {
865 vinfo("BB_BENCH enabled via --print_bench / --bench_out / --trace_out_perfetto");
866 }
867 if (!trace_out_perfetto.empty()) {
869 vinfo("Per-call BB_BENCH event capture enabled via --trace_out_perfetto");
870 }
871#endif
872
874 info("Scheme is: ", flags.scheme, ", num threads: ", get_num_cpus());
875 if (CLI::App* deepest = find_deepest_subcommand(&app)) {
877 }
878
879 // TODO(AD): it is inflexible that Chonk shares an API command (prove) with UH this way. The base API class is a
880 // poor fit. It would be better to have a separate handling for each scheme with subcommands to prove.
881 const auto execute_non_prove_command = [&](API& api) {
882 if (check->parsed()) {
883 api.check(flags, bytecode_path, witness_path);
884 return 0;
885 }
886 if (gates->parsed()) {
887 api.gates(flags, bytecode_path);
888 return 0;
889 }
890 if (write_vk->parsed()) {
891 api.write_vk(flags, bytecode_path, output_path);
892 return 0;
893 }
894 if (verify->parsed()) {
895 const bool verified = api.verify(flags, public_inputs_path, proof_path, vk_path);
896 vinfo("verified: ", verified);
897 return verified ? 0 : 1;
898 }
899 if (write_solidity_verifier->parsed()) {
900 // Validate that verifier_target is compatible with Solidity verifier
901 if (!flags.verifier_target.empty() && flags.verifier_target != "evm" &&
902 flags.verifier_target != "evm-no-zk") {
903 throw_or_abort("write_solidity_verifier requires --verifier_target to be 'evm' or 'evm-no-zk', got '" +
904 flags.verifier_target + "'");
905 }
906 api.write_solidity_verifier(flags, output_path, vk_path);
907 return 0;
908 }
909 auto subcommands = app.get_subcommands();
910 const std::string message = std::string("No handler for subcommand ") + subcommands[0]->get_name();
911 throw_or_abort(message);
912 return 1;
913 };
914
915 try {
916 // ACIR roundtrip (internal testing)
917 if (acir_roundtrip_cmd->parsed()) {
918 acir_roundtrip(bytecode_path, acir_roundtrip_output_path);
919 return 0;
920 }
921
922 // MSGPACK
923 if (msgpack_schema_command->parsed()) {
925 return 0;
926 }
927 if (msgpack_curve_constants_command->parsed()) {
929 return 0;
930 }
931 if (msgpack_run_command->parsed()) {
932 return execute_msgpack_run(msgpack_input_file, max_clients, request_ring_size, response_ring_size);
933 }
934 if (aztec_process->parsed()) {
935#ifdef __wasm__
936 throw_or_abort("Aztec artifact processing is not supported in WASM builds.");
937#else
938 // Handle cache_paths subcommand
939 if (cache_paths_command->parsed()) {
940 return get_cache_paths(cache_paths_input) ? 0 : 1;
941 }
942
943 // Check for invalid combination of multiple inputs with output path
944 if (!artifact_output_path.empty() && artifact_input_paths.size() > 1) {
945 throw_or_abort("Cannot specify --output when multiple --input flags are provided.");
946 }
947
948 // Default to current directory if no inputs specified
949 if (artifact_input_paths.empty()) {
950 artifact_input_paths.push_back(".");
951 }
952
953 // Handle multiple inputs (process in parallel)
954 if (artifact_input_paths.size() > 1) {
955 // Validate all inputs are files, not directories
956 for (const auto& input : artifact_input_paths) {
957 if (std::filesystem::is_directory(input)) {
958 throw_or_abort("When using multiple --input flags, all inputs must be files, not directories.");
959 }
960 }
961
962 // Process all artifacts in parallel
963 std::atomic<bool> all_success = true;
964 std::vector<std::string> failures;
965 std::mutex failures_mutex;
966
967 parallel_for(artifact_input_paths.size(), [&](size_t i) {
968 const auto& input = artifact_input_paths[i];
969 if (!process_aztec_artifact(input, input, force_regenerate)) {
970 all_success = false;
971 std::lock_guard<std::mutex> lock(failures_mutex);
972 failures.push_back(input);
973 }
974 });
975
976 if (!all_success) {
977 info("Failed to process ", failures.size(), " artifact(s)");
978 return 1;
979 }
980 info("Successfully processed ", artifact_input_paths.size(), " artifact(s)");
981 return 0;
982 }
983
984 // Single input case
985 std::string input = artifact_input_paths[0];
986
987 // Check if input is a directory
988 if (std::filesystem::is_directory(input)) {
989 // If output specified for directory input, that's an error
990 if (!artifact_output_path.empty()) {
992 "Cannot specify --output when input is a directory. Artifacts are updated in-place.");
993 }
994 // Recursively process all artifacts in directory
995 return process_all_artifacts(input, force_regenerate) ? 0 : 1;
996 }
997
998 // Input is a file, process single artifact
999 std::string output = artifact_output_path.empty() ? input : artifact_output_path;
1000 return process_aztec_artifact(input, output, force_regenerate) ? 0 : 1;
1001#endif
1002 }
1003 // AVM - functions will throw at runtime if not supported (via stub module)
1004 else if (avm_prove_command->parsed()) {
1005 // This outputs both files: proof and vk, under the given directory.
1006 avm_prove(avm_inputs_path, avm_prove_output_path);
1007 } else if (avm_check_circuit_command->parsed()) {
1008 avm_check_circuit(avm_inputs_path);
1009 } else if (avm_verify_command->parsed()) {
1010 return avm_verify(proof_path, avm_public_inputs_path) ? 0 : 1;
1011 } else if (avm_simulate_command->parsed()) {
1012 avm_simulate(avm_inputs_path);
1013 } else if (avm_write_vk_command->parsed()) {
1014 avm_write_verification_key(avm_write_vk_output_path);
1015 } else if (flags.scheme == "chonk") {
1016 ChonkAPI api;
1017 if (prove->parsed()) {
1018 if (!std::filesystem::exists(ivc_inputs_path)) {
1019 throw_or_abort("The prove command for Chonk expect a valid file passed with --ivc_inputs_path "
1020 "<ivc-inputs.msgpack> (default ./ivc-inputs.msgpack)");
1021 }
1022 api.prove(flags, ivc_inputs_path, output_path);
1023#if !defined(__wasm__) || defined(ENABLE_WASM_BENCH)
1024 if (print_bench) {
1025 vinfo("Printing BB_BENCH results...");
1028 }
1029 if (!bench_out.empty()) {
1030 std::ofstream file(bench_out);
1032 }
1033 if (!bench_out_hierarchical.empty()) {
1034 std::ofstream file(bench_out_hierarchical);
1036 }
1037 if (!trace_out_perfetto.empty()) {
1038 std::ofstream file(trace_out_perfetto);
1040 vinfo("Perfetto per-call trace written to ", trace_out_perfetto);
1041 }
1042 if (!trace_out_perfetto_aggregate.empty()) {
1043 std::ofstream file(trace_out_perfetto_aggregate);
1045 vinfo("Perfetto aggregate trace written to ", trace_out_perfetto_aggregate);
1046 }
1047#endif
1048 if (!memory_profile_out.empty()) {
1049 std::ofstream file(memory_profile_out);
1051 vinfo("Memory profile written to ", memory_profile_out);
1052 }
1053 return 0;
1054 }
1055 if (check->parsed()) {
1056 if (!std::filesystem::exists(ivc_inputs_path)) {
1057 throw_or_abort("The check command for Chonk expect a valid file passed with --ivc_inputs_path "
1058 "<ivc-inputs.msgpack> (default ./ivc-inputs.msgpack)");
1059 }
1060 if (disable_asserts) {
1062 return api.check_precomputed_vks(flags, ivc_inputs_path) ? 0 : 1;
1063 }
1064 return api.check_precomputed_vks(flags, ivc_inputs_path) ? 0 : 1;
1065 }
1066 if (batch_verify->parsed()) {
1067 const bool verified = api.batch_verify(flags, batch_verify_proofs_dir);
1068 vinfo("batch verified: ", verified);
1069 return verified ? 0 : 1;
1070 }
1071 if (proof_stats->parsed()) {
1072 api.proof_stats(proof_path, output_path);
1073 return 0;
1074 }
1075 return execute_non_prove_command(api);
1076 } else if (flags.scheme == "ultra_honk") {
1077 UltraHonkAPI api;
1078 if (prove->parsed()) {
1079 api.prove(flags, bytecode_path, witness_path, vk_path, output_path);
1080#if !defined(__wasm__) || defined(ENABLE_WASM_BENCH)
1081 if (print_bench) {
1083 }
1084 if (!bench_out.empty()) {
1085 std::ofstream file(bench_out);
1087 }
1088 if (!bench_out_hierarchical.empty()) {
1089 std::ofstream file(bench_out_hierarchical);
1091 }
1092 if (!trace_out_perfetto.empty()) {
1093 std::ofstream file(trace_out_perfetto);
1095 vinfo("Perfetto per-call trace written to ", trace_out_perfetto);
1096 }
1097 if (!trace_out_perfetto_aggregate.empty()) {
1098 std::ofstream file(trace_out_perfetto_aggregate);
1100 vinfo("Perfetto aggregate trace written to ", trace_out_perfetto_aggregate);
1101 }
1102#endif
1103 return 0;
1104 }
1105 return execute_non_prove_command(api);
1106 } else {
1107 throw_or_abort("No match for API command");
1108 return 1;
1109 }
1110 } catch (std::runtime_error const& err) {
1111#ifndef BB_NO_EXCEPTIONS
1112 std::cerr << err.what() << std::endl;
1113 return 1;
1114#endif
1115 }
1116 return 0;
1117}
1118} // namespace bb
#define BB_DISABLE_ASSERTS()
Definition assert.hpp:33
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
CLI API for Chonk (Aztec's client-side proving).
Definition api_chonk.hpp:33
void proof_stats(const std::filesystem::path &proof_path, const std::filesystem::path &output_path)
Output proof statistics: compressed proof and its size.
bool batch_verify(const Flags &flags, const std::filesystem::path &proofs_dir)
Batch-verify multiple Chonk proofs from a directory of proof_N/vk_N pairs.
void prove(const Flags &flags, const std::filesystem::path &input_path, const std::filesystem::path &output_dir)
Main production entry point: generate a Chonk proof from private execution steps.
Definition api_chonk.cpp:54
bool check_precomputed_vks(const Flags &flags, const std::filesystem::path &input_path)
Validate that precomputed VKs in ivc-inputs.msgpack match computed VKs.
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)
group class. Represents an elliptic curve group element. Group is parametrised by Fq and Fr
Definition group.hpp:38
#define CLI11_PARSE(app,...)
#define info(...)
Definition log.hpp:93
#define vinfo(...)
Definition log.hpp:94
Programmatic interface for generating msgpack-encoded curve constants.
LogLevel bb_log_level
Definition log.cpp:9
std::string get_msgpack_schema_as_json()
bool use_memory_profile
MemoryProfile GLOBAL_MEMORY_PROFILE
GlobalBenchStatsContainer GLOBAL_BENCH_STATS
Definition bb_bench.cpp:822
std::atomic< bool > capture_per_call_events
Definition bb_bench.cpp:177
bool use_bb_bench
Definition bb_bench.cpp:175
void init_net_crs_factory(const std::filesystem::path &path)
std::filesystem::path bb_crs_path()
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
void print_subcommand_options(const CLI::App *sub)
Definition cli.cpp:79
void avm_simulate(const std::filesystem::path &inputs_path)
Simulates an public transaction.
Definition api_avm.cpp:78
int execute_msgpack_run(const std::string &msgpack_input_file, int max_clients, size_t request_ring_size, size_t response_ring_size)
Execute msgpack run command.
int parse_and_run_cli_command(int argc, char *argv[])
Parse command line arguments and run the corresponding command.
Definition cli.cpp:110
bool process_all_artifacts(const std::string &search_path, bool force)
Process all discovered contract artifacts in a directory tree.
bool get_cache_paths(const std::string &input_path)
Get cache paths for all verification keys in an artifact.
void write_curve_constants_msgpack_to_stdout()
Write msgpack-encoded curve constants to stdout.
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
void acir_roundtrip(const std::filesystem::path &bytecode_path, const std::filesystem::path &output_path)
Deserialize an ACIR program from bytecode (msgpack), re-serialize it, and write the result to an outp...
Definition api_acir.cpp:14
bool avm_verify(const std::filesystem::path &proof_path, const std::filesystem::path &public_inputs_path)
Verifies an avm proof and writes the result to stdout.
Definition api_avm.cpp:65
void print_active_subcommands(const CLI::App &app, const std::string &prefix="bb command: ")
Definition cli.cpp:50
void avm_write_verification_key(const std::filesystem::path &output_path)
Writes an avm (incomplete) verification key to a file.
Definition api_avm.cpp:90
void avm_prove(const std::filesystem::path &inputs_path, const std::filesystem::path &output_path)
Writes an avm proof to a file.
Definition api_avm.cpp:31
const char * BB_VERSION
Definition version.hpp:14
void avm_check_circuit(const std::filesystem::path &inputs_path)
Stub - throws runtime error if called.
Definition api_avm.cpp:53
const bool avm_enabled
Definition api_avm.cpp:15
CLI::App * find_deepest_subcommand(CLI::App *app)
Definition cli.cpp:64
void parallel_for(size_t num_iterations, const std::function< void(size_t)> &func)
Definition thread.cpp:111
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:548
void serialize_trace_events_json(std::ostream &) const
Definition bb_bench.cpp:406
void print_aggregate_counts(std::ostream &, size_t) const
Definition bb_bench.cpp:303
void serialize_aggregate_data_json(std::ostream &) const
Definition bb_bench.cpp:342
void serialize_aggregate_trace_json(std::ostream &) const
Definition bb_bench.cpp:474
void serialize_json(std::ostream &os) const
void throw_or_abort(std::string const &err)