11 #include <boost/program_options.hpp>
17 namespace po = boost::program_options;
32 std::string powersoftau_file;
33 std::string lagrange_file;
34 size_t powersoftau_degree;
39 mpc_linear_combination()
41 "linear-combination",
"Create linear combination for our circuit")
44 , powersoftau_degree(0)
51 void initialize_suboptions(
52 po::options_description &options,
53 po::options_description &all_options,
54 po::positional_options_description &pos)
override
56 options.add_options()(
59 "powersoftau degree (assumed equal to lagrange file)")(
60 "verify",
"Skip computation. Load and verify input data");
61 all_options.add(options).add_options()(
62 "powersoftau_file", po::value<std::string>(),
"powersoftau file")(
63 "lagrange_file", po::value<std::string>(),
"lagrange file")(
65 po::value<std::string>(),
66 "linear combination output");
67 pos.add(
"powersoftau_file", 1)
68 .add(
"lagrange_file", 1)
69 .add(
"linear_comb_file", 1);
72 void parse_suboptions(
const po::variables_map &vm)
override
74 if (0 == vm.count(
"powersoftau_file")) {
75 throw po::error(
"powersoftau_file not specified");
77 if (0 == vm.count(
"lagrange_file")) {
78 throw po::error(
"lagrange_file not specified");
80 if (0 == vm.count(
"linear_comb_file")) {
81 throw po::error(
"linear_comb_file not specified");
84 powersoftau_file = vm[
"powersoftau_file"].as<std::string>();
85 lagrange_file = vm[
"lagrange_file"].as<std::string>();
86 out_file = vm[
"linear_comb_file"].as<std::string>();
88 vm.count(
"pot-degree") ? vm[
"pot-degree"].as<
size_t>() : 0;
89 verify = (bool)vm.count(
"verify");
92 void subcommand_usage(
const char *argv0)
override
94 std::cout <<
"Usage:\n " << argv0 <<
" " << subcommand_name
95 <<
" [<options>] <powersoftau file> <lagrange file> "
96 "<linear_comb_file>\n";
102 std::cout <<
"powersoftau_file: " << powersoftau_file <<
"\n"
103 <<
"lagrange_file: " << lagrange_file <<
"\n"
104 <<
"powersoftau_degree: " << powersoftau_degree <<
"\n"
105 <<
"out_file: " << out_file <<
"\n"
106 <<
"verify: " << std::to_string(
verify) << std::endl;
112 libff::enter_block(
"Load Lagrange data");
113 libff::print_indent();
114 std::cout << lagrange_file << std::endl;
116 read_from_file<srs_lagrange_evaluations<pp>>(lagrange_file);
117 libff::leave_block(
"Load Lagrange data");
119 libff::enter_block(
"Load powers of tau");
120 libff::print_indent();
121 std::cout << powersoftau_file << std::endl;
124 powersoftau_file, std::ios_base::binary | std::ios_base::in);
125 const size_t pot_degree =
126 powersoftau_degree ? powersoftau_degree : lagrange.
degree;
127 return powersoftau_load<pp>(in, pot_degree);
129 libff::leave_block(
"Load powers of tau");
132 libff::enter_block(
"Generate QAP");
133 libsnark::protoboard<Field> pb;
135 const libsnark::r1cs_constraint_system<Field> cs =
136 pb.get_constraint_system();
137 const libsnark::qap_instance<Field> qap =
138 libsnark::r1cs_to_qap_instance_map(cs,
true);
139 libff::leave_block(
"Generate QAP");
143 std::cout <<
"verify: skipping computation and write.)"
149 if (qap.degree() != lagrange.
degree) {
150 throw std::invalid_argument(
151 "Degree of qap " + std::to_string(qap.degree()) +
" does not " +
152 "match degree of lagrange evaluations. Regenerate with "
159 mpc_compute_linearcombination<pp>(pot, lagrange, qap);
161 libff::enter_block(
"Writing linear combination file");
162 libff::print_indent();
163 std::cout << out_file << std::endl;
166 out_file, std::ios_base::binary | std::ios_base::out);
169 libff::leave_block(
"Writing linear combination file");