13 #include <boost/program_options.hpp>
16 #include <libff/common/profiling.hpp>
23 namespace po = boost::program_options;
28 std::string &assembly_fn,
29 std::string &processed_assembly_fn,
30 std::string &architecture_params_fn,
31 std::string &computation_bounds_fn,
32 std::string &primary_input_fn,
33 std::string &auxiliary_input_fn)
36 po::options_description desc(
"Usage");
37 desc.add_options()(
"help",
"print this help message")(
38 "assembly", po::value<std::string>(&assembly_fn)->required())(
40 po::value<std::string>(&processed_assembly_fn)->required())(
41 "architecture_params",
42 po::value<std::string>(&architecture_params_fn)->required())(
44 po::value<std::string>(&computation_bounds_fn)->required())(
46 po::value<std::string>(&primary_input_fn)->required())(
48 po::value<std::string>(&auxiliary_input_fn)->required());
51 po::store(po::parse_command_line(argc, argv, desc), vm);
53 if (vm.count(
"help")) {
54 std::cout << desc <<
"\n";
59 }
catch (std::exception &e) {
60 std::cerr <<
"Error: " << e.what() <<
"\n";
70 int main(
int argc,
const char *argv[])
74 std::string assembly_fn =
"assembly.s";
75 std::string processed_assembly_fn =
"processed.txt";
76 std::string architecture_params_fn =
"architecture_params.txt";
77 std::string computation_bounds_fn =
"computation_bounds.txt";
78 std::string primary_input_fn =
"primary_input.txt";
79 std::string auxiliary_input_fn =
"auxiliary_input.txt";
81 std::string assembly_fn;
82 std::string processed_assembly_fn;
83 std::string architecture_params_fn;
84 std::string computation_bounds_fn;
85 std::string primary_input_fn;
86 std::string auxiliary_input_fn;
92 processed_assembly_fn,
93 architecture_params_fn,
94 computation_bounds_fn,
96 auxiliary_input_fn)) {
100 libff::start_profiling();
102 printf(
"==================================================================="
104 printf(
"TinyRAM example loader\n");
105 printf(
"==================================================================="
106 "=============\n\n");
110 std::ifstream f_ap(architecture_params_fn);
113 printf(
"Will run on %zu register machine (word size = %zu)\n", ap.k, ap.w);
115 std::ifstream f_rp(computation_bounds_fn);
116 size_t tinyram_input_size_bound, tinyram_program_size_bound, time_bound;
117 f_rp >> tinyram_input_size_bound >> tinyram_program_size_bound >>
120 std::ifstream processed(processed_assembly_fn);
121 std::ifstream raw(assembly_fn);
127 (std::istreambuf_iterator<char>(raw)),
128 std::istreambuf_iterator<char>())
131 std::ifstream f_primary_input(primary_input_fn);
132 std::ifstream f_auxiliary_input(auxiliary_input_fn);
134 libff::enter_block(
"Loading primary input");
136 libff::leave_block(
"Loading primary input");
138 libff::enter_block(
"Loading auxiliary input");
140 libff::leave_block(
"Loading auxiliary input");
142 printf(
"\nPress enter to continue.\n");
145 const size_t boot_trace_size_bound =
146 tinyram_program_size_bound + tinyram_input_size_bound;
149 ap, boot_trace_size_bound, program, primary_input);
151 printf(
"==================================================================="
153 printf(
"TinyRAM arithmetization test for T = %zu time steps\n", time_bound);
154 printf(
"==================================================================="
155 "=============\n\n");
165 ap, boot_trace_size_bound, boot_trace);
175 printf(
"\nPress enter to continue.\n");
178 printf(
"==================================================================="
180 printf(
"TinyRAM ppzkSNARK Key Pair Generator\n");
181 printf(
"==================================================================="
182 "=============\n\n");
184 ram_ppzksnark_generator<default_tinyram_ppzksnark_pp>(
185 ap, boot_trace_size_bound, time_bound);
187 printf(
"\nPress enter to continue.\n");
190 printf(
"==================================================================="
192 printf(
"TinyRAM ppzkSNARK Prover\n");
193 printf(
"==================================================================="
194 "=============\n\n");
196 ram_ppzksnark_prover<default_tinyram_ppzksnark_pp>(
197 keypair.
pk, boot_trace, auxiliary_input);
199 printf(
"\nPress enter to continue.\n");
202 printf(
"==================================================================="
204 printf(
"TinyRAM ppzkSNARK Verifier\n");
205 printf(
"==================================================================="
206 "=============\n\n");
207 bool bit = ram_ppzksnark_verifier<default_tinyram_ppzksnark_pp>(
208 keypair.
vk, boot_trace, proof);
210 printf(
"==================================================================="
212 printf(
"The verification result is: %s\n", (bit ?
"PASS" :
"FAIL"));
213 printf(
"==================================================================="
216 printf(
"==================================================================="