10 namespace po = boost::program_options;
24 std::string challenge_file;
25 std::string response_file;
26 std::string transcript_file;
27 std::string new_challenge_file;
30 mpc_phase2_verify_contribution()
32 "mpc_phase2_verify_contribution",
33 "Verify contribution and optionally output next challenge")
37 , new_challenge_file()
42 void initialize_suboptions(
43 po::options_description &options,
44 po::options_description &all_options,
45 po::positional_options_description &pos)
override
47 options.add_options()(
49 po::value<std::string>(),
50 "Append contribution, if it is valid")(
52 po::value<std::string>(),
53 "Write new challenge, if contribution is valid");
54 all_options.add(options).add_options()(
55 "challenge_file", po::value<std::string>(),
"challenge file")(
56 "response_file", po::value<std::string>(),
"response file");
57 pos.add(
"challenge_file", 1).add(
"response_file", 1);
60 void parse_suboptions(
const po::variables_map &vm)
override
62 if (!vm.count(
"challenge_file")) {
63 throw po::error(
"challenge_file not specified");
65 if (!vm.count(
"response_file")) {
66 throw po::error(
"response_file not specified");
68 challenge_file = vm[
"challenge_file"].as<std::string>();
69 response_file = vm[
"response_file"].as<std::string>();
71 vm.count(
"transcript") ? vm[
"transcript"].as<std::string>() :
"";
72 new_challenge_file = vm.count(
"new-challenge")
73 ? vm[
"new-challenge"].as<std::string>()
77 void subcommand_usage(
const char *argv0)
override
79 std::cout <<
"Usage:\n " << argv0 <<
" " << subcommand_name
80 <<
" [<options>] <challenge_file> <response_file>\n\n";
86 std::cout <<
"challenge: " << challenge_file <<
"\n"
87 <<
"response: " << response_file <<
"\n"
88 <<
"transcript: " << transcript_file <<
"\n"
89 <<
"new_challenge: " << new_challenge_file << std::endl;
92 libff::enter_block(
"Load challenge file");
94 read_from_file<srs_mpc_phase2_challenge<pp>>(challenge_file);
95 libff::leave_block(
"Load challenge file");
97 libff::enter_block(
"Load response file");
99 read_from_file<srs_mpc_phase2_response<pp>>(response_file);
100 libff::leave_block(
"Load response file");
102 libff::enter_block(
"Verifying response");
103 const bool response_is_valid =
105 libff::leave_block(
"Verifying response");
106 if (!response_is_valid) {
107 std::cerr <<
"Response is invalid" << std::endl;
114 if (!transcript_file.empty()) {
115 libff::enter_block(
"appending contribution to transcript");
118 std::ios_base::binary | std::ios_base::out |
121 libff::leave_block(
"appending contribution to transcript");
126 if (!new_challenge_file.empty()) {
127 libff::enter_block(
"computing and writing new challenge");
131 new_challenge_file, std::ios_base::binary | std::ios_base::out);
132 new_challenge.
write(out);
133 libff::leave_block(
"computing and writing new challenge");
143 new mpc_phase2_verify_contribution();