Clearmatics Libsnark  0.1
C++ library for zkSNARK proofs
demo_ram_ppzksnark_prover.cpp
Go to the documentation of this file.
1 
7 #include <fstream>
8 #include <iostream>
9 #ifndef MINDEPS
10 #include <boost/program_options.hpp>
11 #endif
12 
16 
17 #ifndef MINDEPS
18 namespace po = boost::program_options;
19 
21  const int argc,
22  const char **argv,
23  std::string &processed_assembly_fn,
24  std::string &proving_key_fn,
25  std::string &primary_input_fn,
26  std::string &auxiliary_input_fn,
27  std::string &proof_fn)
28 {
29  try {
30  po::options_description desc("Usage");
31  desc.add_options()("help", "print this help message")(
32  "processed_assembly",
33  po::value<std::string>(&processed_assembly_fn)->required())(
34  "proving_key", po::value<std::string>(&proving_key_fn)->required())(
35  "primary_input",
36  po::value<std::string>(&primary_input_fn)->required())(
37  "auxiliary_input",
38  po::value<std::string>(&auxiliary_input_fn)->required())(
39  "proof", po::value<std::string>(&proof_fn)->required());
40 
41  po::variables_map vm;
42  po::store(po::parse_command_line(argc, argv, desc), vm);
43 
44  if (vm.count("help")) {
45  std::cout << desc << "\n";
46  return false;
47  }
48 
49  po::notify(vm);
50  } catch (std::exception &e) {
51  std::cerr << "Error: " << e.what() << "\n";
52  return false;
53  }
54 
55  return true;
56 }
57 #endif
58 
59 using namespace libsnark;
60 
61 int main(int argc, const char *argv[])
62 {
64 
65 #ifdef MINDEPS
66  std::string processed_assembly_fn = "processed.txt";
67  std::string proving_key_fn = "proving_key.txt";
68  std::string primary_input_fn = "primary_input.txt";
69  std::string auxiliary_input_fn = "auxiliary_input.txt";
70  std::string proof_fn = "proof.txt";
71 #else
72  std::string processed_assembly_fn;
73  std::string proving_key_fn;
74  std::string primary_input_fn;
75  std::string auxiliary_input_fn;
76  std::string proof_fn;
77 
79  argc,
80  argv,
81  processed_assembly_fn,
82  proving_key_fn,
83  primary_input_fn,
84  auxiliary_input_fn,
85  proof_fn)) {
86  return 1;
87  }
88 #endif
89  libff::start_profiling();
90 
91  /* load everything */
93  std::ifstream pk_file(proving_key_fn);
94  pk_file >> pk;
95  pk_file.close();
96 
97  std::ifstream processed(processed_assembly_fn);
98  tinyram_program program = load_preprocessed_program(pk.ap, processed);
99 
100  std::ifstream f_primary_input(primary_input_fn);
101  std::ifstream f_auxiliary_input(auxiliary_input_fn);
102  tinyram_input_tape primary_input = load_tape(f_primary_input);
103  tinyram_input_tape auxiliary_input = load_tape(f_auxiliary_input);
104 
107  pk.ap, pk.primary_input_size_bound, program, primary_input);
109  ram_ppzksnark_prover<default_tinyram_ppzksnark_pp>(
110  pk, boot_trace, auxiliary_input);
111 
112  std::ofstream proof_file(proof_fn);
113  proof_file << proof;
114  proof_file.close();
115 }
tinyram_params.hpp
tinyram_ppzksnark_pp.hpp
libsnark
Definition: accumulation_vector.hpp:18
main
int main(int argc, const char *argv[])
Definition: demo_ram_ppzksnark_prover.cpp:61
libsnark::default_tinyram_ppzksnark_pp::init_public_params
static void init_public_params()
Definition: tinyram_ppzksnark_pp.cpp:18
libsnark::load_preprocessed_program
tinyram_program load_preprocessed_program(const tinyram_architecture_params &ap, std::istream &preprocessed)
Definition: tinyram_aux.cpp:312
libsnark::tinyram_input_tape
std::vector< size_t > tinyram_input_tape
Definition: tinyram_aux.hpp:122
libsnark::r1cs_ppzksnark_proof
Definition: r1cs_ppzksnark.hpp:298
libsnark::memory_store_trace
Definition: memory_store_trace.hpp:29
process_prover_command_line
bool process_prover_command_line(const int argc, const char **argv, std::string &processed_assembly_fn, std::string &proving_key_fn, std::string &primary_input_fn, std::string &auxiliary_input_fn, std::string &proof_fn)
Definition: demo_ram_ppzksnark_prover.cpp:20
libsnark::ram_ppzksnark_proving_key
Definition: ram_ppzksnark.hpp:60
libsnark::load_tape
tinyram_input_tape load_tape(std::istream &tape)
Definition: tinyram_aux.cpp:369
libsnark::tinyram_boot_trace_from_program_and_input
memory_store_trace tinyram_boot_trace_from_program_and_input(const tinyram_architecture_params &ap, const size_t boot_trace_size_bound, const tinyram_program &program, const tinyram_input_tape &primary_input)
Definition: tinyram_aux.cpp:338
ram_ppzksnark.hpp
libsnark::tinyram_program
Definition: tinyram_aux.hpp:200