Clearmatics Libsnark  0.1
C++ library for zkSNARK proofs
Functions
profile_ram_zksnark.cpp File Reference
#include <boost/program_options.hpp>
#include <libff/common/profiling.hpp>
#include <libsnark/common/default_types/ram_zksnark_pp.hpp>
#include <libsnark/relations/ram_computations/memory/examples/memory_contents_examples.hpp>
#include <libsnark/relations/ram_computations/rams/examples/ram_examples.hpp>
#include <libsnark/relations/ram_computations/rams/tinyram/tinyram_params.hpp>
#include <libsnark/zk_proof_systems/zksnark/ram_zksnark/examples/run_ram_zksnark.hpp>
#include <libsnark/zk_proof_systems/zksnark/ram_zksnark/ram_zksnark.hpp>
Include dependency graph for profile_ram_zksnark.cpp:

Go to the source code of this file.

Functions

template<typename FieldT >
void simulate_random_memory_contents (const tinyram_architecture_params &ap, const size_t input_size, const size_t program_size)
 
template<typename ppT >
void profile_ram_zksnark_verifier (const tinyram_architecture_params &ap, const size_t input_size, const size_t program_size)
 
template<typename ppT >
void print_ram_zksnark_verifier_profiling ()
 
template<typename ppT >
void profile_ram_zksnark (const tinyram_architecture_params &ap, const size_t program_size, const size_t input_size, const size_t time_bound)
 
bool process_command_line (const int argc, const char **argv, bool &profile_gp, size_t &w, size_t &k, bool &profile_v, size_t &l)
 
int main (int argc, const char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
const char *  argv[] 
)

Definition at line 187 of file profile_ram_zksnark.cpp.

188 {
189  libff::start_profiling();
191 
192  bool profile_gp;
193  size_t w;
194  size_t k;
195  bool profile_v;
196  size_t l;
197 
198  if (!process_command_line(argc, argv, profile_gp, w, k, profile_v, l)) {
199  return 1;
200  }
201 
203 
204  if (profile_gp) {
205  profile_ram_zksnark<default_ram_zksnark_pp>(
206  ap, 100, 100, 10); // w, k, l, n, T
207  }
208 
209  if (profile_v) {
210  profile_ram_zksnark_verifier<default_ram_zksnark_pp>(ap, l / 2, l / 2);
211  }
212 }
Here is the call graph for this function:

◆ print_ram_zksnark_verifier_profiling()

template<typename ppT >
void print_ram_zksnark_verifier_profiling ( )

Definition at line 57 of file profile_ram_zksnark.cpp.

58 {
59  libff::inhibit_profiling_info = true;
60  for (size_t w : {16, 32}) {
61  const size_t k = 16;
62 
63  for (size_t input_size : {0, 10, 100}) {
64  for (size_t program_size = 10; program_size <= 10000;
65  program_size *= 10) {
66  const tinyram_architecture_params ap(w, k);
67 
68  profile_ram_zksnark_verifier<ppT>(ap, input_size, program_size);
69 
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"];
78  const double total =
79  libff::last_times["Call to ram_zksnark_verifier"];
80  const double rest =
81  total - (input_map + preprocessing + accumulate + pairings);
82 
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;
95 
96  printf(
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 = "
101  "%0.2fms)\n",
102  w,
103  k,
104  program_size,
105  input_size,
106  input_map * 1e-6,
107  preprocessing * 1e-6,
108  accumulate * 1e-6,
109  pairings * 1e-6,
110  rest * 1e-6,
111  total * 1e-6,
112  input_map_random * 1e-6,
113  total_random * 1e-6);
114  }
115  }
116  }
117 }
Here is the call graph for this function:

◆ process_command_line()

bool process_command_line ( const int  argc,
const char **  argv,
bool &  profile_gp,
size_t &  w,
size_t &  k,
bool &  profile_v,
size_t &  l 
)

Definition at line 138 of file profile_ram_zksnark.cpp.

146 {
147  try {
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");
155 
156  po::variables_map vm;
157  po::store(po::parse_command_line(argc, argv, desc), vm);
158 
159  if (vm.count("v")) {
160  libff::print_compilation_info();
161  exit(0);
162  }
163 
164  if (vm.count("help")) {
165  std::cout << desc << "\n";
166  return false;
167  }
168 
169  profile_gp = vm.count("profile_gp");
170  profile_v = vm.count("profile_v");
171 
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";
175  return false;
176  }
177 
178  po::notify(vm);
179  } catch (std::exception &e) {
180  std::cerr << "Error: " << e.what() << "\n";
181  return false;
182  }
183 
184  return true;
185 }
Here is the caller graph for this function:

◆ profile_ram_zksnark()

template<typename ppT >
void profile_ram_zksnark ( const tinyram_architecture_params ap,
const size_t  program_size,
const size_t  input_size,
const size_t  time_bound 
)

Definition at line 120 of file profile_ram_zksnark.cpp.

125 {
126  typedef ram_zksnark_machine_pp<ppT> ramT;
127 
128  const size_t boot_trace_size_bound = program_size + input_size;
129  const ram_example<ramT> example = gen_ram_example_complex<ramT>(
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);
133  assert(bit);
134 }

◆ profile_ram_zksnark_verifier()

template<typename ppT >
void profile_ram_zksnark_verifier ( const tinyram_architecture_params ap,
const size_t  input_size,
const size_t  program_size 
)

Definition at line 36 of file profile_ram_zksnark.cpp.

40 {
41  typedef ram_zksnark_machine_pp<ppT> ramT;
42  const size_t time_bound = 10;
43 
44  const size_t boot_trace_size_bound = program_size + input_size;
45  const ram_example<ramT> example = gen_ram_example_complex<ramT>(
46  ap, boot_trace_size_bound, time_bound, true);
47 
51 
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");
55 }
Here is the call graph for this function:

◆ simulate_random_memory_contents()

template<typename FieldT >
void simulate_random_memory_contents ( const tinyram_architecture_params ap,
const size_t  input_size,
const size_t  program_size 
)

Definition at line 19 of file profile_ram_zksnark.cpp.

23 {
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);
28 
29  libff::enter_block("Initialize random delegated memory");
31  num_addresses, value_size, init_random);
32  libff::leave_block("Initialize random delegated memory");
33 }
Here is the call graph for this function:
Here is the caller graph for this function:
libsnark::tinyram_architecture_params::dwaddr_len
size_t dwaddr_len() const
Definition: tinyram_aux.cpp:222
libsnark::ram_zksnark_machine_pp
typename ram_zksnark_ppT::machine_pp ram_zksnark_machine_pp
Definition: ram_zksnark_params.hpp:64
libsnark::tinyram_architecture_params
Definition: tinyram_aux.hpp:126
libsnark::memory_contents
std::map< size_t, size_t > memory_contents
Definition: memory_interface.hpp:25
process_command_line
bool process_command_line(const int argc, const char **argv, bool &profile_gp, size_t &w, size_t &k, bool &profile_v, size_t &l)
Definition: profile_ram_zksnark.cpp:138
libsnark::ram_example::boot_trace
ram_boot_trace< ramT > boot_trace
Definition: ram_examples.hpp:25
libsnark::tinyram_architecture_params::w
reg_width_t w
Definition: tinyram_aux.hpp:129
libsnark::ram_example
Definition: ram_examples.hpp:21
libsnark::delegated_ra_memory
Definition: delegated_ra_memory.hpp:24
libsnark::ram_zksnark_PCD_pp
typename ram_zksnark_ppT::PCD_pp ram_zksnark_PCD_pp
Definition: ram_zksnark_params.hpp:61
simulate_random_memory_contents
void simulate_random_memory_contents(const tinyram_architecture_params &ap, const size_t input_size, const size_t program_size)
Definition: profile_ram_zksnark.cpp:19
libsnark::random_memory_contents
memory_contents random_memory_contents(const size_t num_addresses, const size_t value_size, const size_t num_filled)
Definition: memory_contents_examples.cpp:43
libsnark::ram_zksnark_verification_key
Definition: ram_zksnark.hpp:96
libsnark::ram_zksnark_proof
Definition: ram_zksnark.hpp:163