395 po::options_description options(
"");
396 options.add_options()(
398 po::value<boost::filesystem::path>(),
399 "file to load keypair from");
401 options.add_options()(
403 po::value<boost::filesystem::path>(),
404 "file in which to export the r1cs in json format");
408 std::cout <<
"Usage:"
410 <<
" " << argv[0] <<
" [<options>]\n"
412 std::cout << options;
413 std::cout << std::endl;
416 boost::filesystem::path keypair_file;
417 boost::filesystem::path r1cs_file;
419 po::variables_map vm;
421 po::command_line_parser(argc, argv).options(options).run(), vm);
422 if (vm.count(
"help")) {
426 if (vm.count(
"keypair")) {
427 keypair_file = vm[
"keypair"].as<boost::filesystem::path>();
429 if (vm.count(
"r1cs")) {
430 r1cs_file = vm[
"r1cs"].as<boost::filesystem::path>();
432 }
catch (po::error &error) {
433 std::cerr <<
" ERROR: " << error.what() << std::endl;
439 if (keypair_file.empty()) {
440 boost::filesystem::path setup_dir =
441 libzeth::get_path_to_setup_directory();
442 if (!setup_dir.empty()) {
443 boost::filesystem::create_directories(setup_dir);
445 keypair_file = setup_dir /
"zecale_keypair.bin";
449 std::cout <<
"[INFO] Init params of both curves" << std::endl;
450 npp::init_public_params();
451 wpp::init_public_params();
457 wsnark::keypair keypair = [&keypair_file, &aggregator]() {
458 if (boost::filesystem::exists(keypair_file)) {
459 std::cout <<
"[INFO] Loading keypair: " << keypair_file <<
"\n";
460 wsnark::keypair keypair;
462 libtool::open_binary_input_file(keypair_file.c_str());
463 wsnark::keypair_read_bytes(keypair, in_s);
466 if (keypair.vk.ABC_g1.size() != aggregator.num_primary_inputs()) {
467 throw std::invalid_argument(
"invalid VK");
473 std::cout <<
"[INFO] No keypair file " << keypair_file
474 <<
". Generating.\n";
475 const wsnark::keypair keypair = aggregator.generate_trusted_setup();
478 if (keypair.vk.ABC_g1.size() != aggregator.num_primary_inputs()) {
479 throw std::invalid_argument(
"invalid VK");
482 const size_t num_constraints =
483 aggregator.get_constraint_system().num_constraints();
484 std::cout <<
"[INFO] Circuit has " << std::to_string(num_constraints)
487 std::cout <<
"[INFO] Writing new keypair to " << keypair_file <<
"\n";
488 std::ofstream out_s =
489 libtool::open_binary_output_file(keypair_file.c_str());
490 wsnark::keypair_write_bytes(keypair, out_s);
496 if (!r1cs_file.empty()) {
497 std::cout <<
"[INFO] Writing R1CS to " << std::endl;
498 std::ofstream r1cs_stream(r1cs_file.c_str());
499 libzeth::r1cs_write_json(
500 aggregator.get_constraint_system(), r1cs_stream);
504 std::cout <<
"[INFO] Setup successful, starting the server..." << std::endl;
505 RunServer(aggregator, keypair);