7 #include <boost/program_options.hpp>
8 #include <libff/common/profiling.hpp>
18 template<
typename FieldT>
21 const size_t input_size,
22 const size_t program_size)
24 const size_t num_addresses = 1ul << ap.
dwaddr_len();
25 const size_t value_size = 2 * ap.
w;
27 num_addresses, value_size, program_size + (input_size + 1) / 2);
29 libff::enter_block(
"Initialize random delegated memory");
31 num_addresses, value_size, init_random);
32 libff::leave_block(
"Initialize random delegated memory");
35 template<
typename ppT>
38 const size_t input_size,
39 const size_t program_size)
42 const size_t time_bound = 10;
44 const size_t boot_trace_size_bound = program_size + input_size;
46 ap, boot_trace_size_bound, time_bound,
true);
52 libff::enter_block(
"Verify fake proof");
53 ram_zksnark_verifier<ppT>(vk, example.
boot_trace, time_bound, pi);
54 libff::leave_block(
"Verify fake proof");
59 libff::inhibit_profiling_info =
true;
60 for (
size_t w : {16, 32}) {
63 for (
size_t input_size : {0, 10, 100}) {
64 for (
size_t program_size = 10; program_size <= 10000;
68 profile_ram_zksnark_verifier<ppT>(ap, input_size, program_size);
70 const double input_map =
71 libff::last_times[
"Call to ram_zksnark_verifier_input_map"];
72 const double preprocessing = libff::last_times
73 [
"Call to r1cs_ppzksnark_verifier_process_vk"];
74 const double accumulate = libff::last_times
75 [
"Call to r1cs_ppzksnark_IC_query::accumulate"];
76 const double pairings =
77 libff::last_times[
"Online pairing computations"];
79 libff::last_times[
"Call to ram_zksnark_verifier"];
81 total - (input_map + preprocessing + accumulate + pairings);
83 const double delegated_ra_memory_init = libff::last_times
84 [
"Construct delegated_ra_memory from memory map"];
86 libff::Fr<typename ppT::curve_A_pp>>(
87 ap, input_size, program_size);
88 const double delegated_ra_memory_init_random =
89 libff::last_times[
"Initialize random delegated memory"];
90 const double input_map_random = input_map -
91 delegated_ra_memory_init +
92 delegated_ra_memory_init_random;
93 const double total_random = total - delegated_ra_memory_init +
94 delegated_ra_memory_init_random;
97 "w = %zu, k = %zu, program_size = %zu, input_size = %zu, "
98 "input_map = %0.2fms, preprocessing = %0.2fms, accumulate "
99 "= %0.2fms, pairings = %0.2fms, rest = %0.2fms, total = "
100 "%0.2fms (input_map_random = %0.2fms, total_random = "
107 preprocessing * 1e-6,
112 input_map_random * 1e-6,
113 total_random * 1e-6);
119 template<
typename ppT>
122 const size_t program_size,
123 const size_t input_size,
124 const size_t time_bound)
128 const size_t boot_trace_size_bound = program_size + input_size;
130 ap, boot_trace_size_bound, time_bound,
true);
131 const bool test_serialization =
true;
132 const bool bit = run_ram_zksnark<ppT>(example, test_serialization);
136 namespace po = boost::program_options;
148 po::options_description desc(
"Usage");
149 desc.add_options()(
"help",
"print this help message")(
150 "profile_gp",
"profile generator and prover")(
151 "w", po::value<size_t>(&w)->default_value(16),
"word size")(
152 "k", po::value<size_t>(&k)->default_value(16),
"register count")(
153 "profile_v",
"profile verifier")(
"v",
"print version info")(
154 "l", po::value<size_t>(&l)->default_value(10),
"program length");
156 po::variables_map vm;
157 po::store(po::parse_command_line(argc, argv, desc), vm);
160 libff::print_compilation_info();
164 if (vm.count(
"help")) {
165 std::cout << desc <<
"\n";
169 profile_gp = vm.count(
"profile_gp");
170 profile_v = vm.count(
"profile_v");
172 if (!(vm.count(
"profile_gp") ^ vm.count(
"profile_v"))) {
173 std::cout <<
"Must choose between profiling generator/prover and "
174 "profiling verifier (see --help)\n";
179 }
catch (std::exception &e) {
180 std::cerr <<
"Error: " << e.what() <<
"\n";
187 int main(
int argc,
const char *argv[])
189 libff::start_profiling();
205 profile_ram_zksnark<default_ram_zksnark_pp>(
210 profile_ram_zksnark_verifier<default_ram_zksnark_pp>(ap, l / 2, l / 2);