2 *****************************************************************************
4 Implementation of functionality that runs the RAM ppzkSNARK for
7 See run_ram_ppzksnark.hpp .
9 *****************************************************************************
10 * @author This file is part of libsnark, developed by SCIPR Lab
11 * and contributors (see AUTHORS).
12 * @copyright MIT license (see LICENSE file)
13 *****************************************************************************/
15 #ifndef RUN_RAM_PPZKSNARK_TCC_
16 #define RUN_RAM_PPZKSNARK_TCC_
18 #include <libff/common/profiling.hpp>
19 #include <libsnark/zk_proof_systems/ppzksnark/ram_ppzksnark/ram_ppzksnark.hpp>
26 * The code below provides an example of all stages of running a RAM ppzkSNARK.
28 * Of course, in a real-life scenario, we would have three distinct entities,
29 * mangled into one in the demonstration below. The three entities are as
30 * follows. (1) The "generator", which runs the ppzkSNARK generator on input a
31 * given architecture and bounds on the computation. (2) The "prover", which
32 * runs the ppzkSNARK prover on input the proving key, a boot trace, and an
33 * auxiliary input. (3) The "verifier", which runs the ppzkSNARK verifier on
34 * input the verification key, a boot trace, and a proof.
36 template<typename ram_ppzksnark_ppT>
37 bool run_ram_ppzksnark(
38 const ram_example<ram_ppzksnark_machine_pp<ram_ppzksnark_ppT>> &example,
39 const bool test_serialization)
41 libff::enter_block("Call to run_ram_ppzksnark");
43 printf("This run uses an example with the following parameters:\n");
46 "* Primary input size bound (L): %zu\n", example.boot_trace_size_bound);
47 printf("* Time bound (T): %zu\n", example.time_bound);
49 "Hence, libff::log2(L+2*T) equals %zu\n",
50 libff::log2(example.boot_trace_size_bound + 2 * example.time_bound));
52 libff::print_header("RAM ppzkSNARK Generator");
53 ram_ppzksnark_keypair<ram_ppzksnark_ppT> keypair =
54 ram_ppzksnark_generator<ram_ppzksnark_ppT>(
55 example.ap, example.boot_trace_size_bound, example.time_bound);
57 libff::print_indent();
58 libff::print_mem("after generator");
60 if (test_serialization) {
61 libff::enter_block("Test serialization of keys");
63 libff::reserialize<ram_ppzksnark_proving_key<ram_ppzksnark_ppT>>(
65 keypair.vk = libff::reserialize<
66 ram_ppzksnark_verification_key<ram_ppzksnark_ppT>>(keypair.vk);
67 libff::leave_block("Test serialization of keys");
70 libff::print_header("RAM ppzkSNARK Prover");
71 ram_ppzksnark_proof<ram_ppzksnark_ppT> proof =
72 ram_ppzksnark_prover<ram_ppzksnark_ppT>(
73 keypair.pk, example.boot_trace, example.auxiliary_input);
75 libff::print_indent();
76 libff::print_mem("after prover");
78 if (test_serialization) {
79 libff::enter_block("Test serialization of proof");
81 libff::reserialize<ram_ppzksnark_proof<ram_ppzksnark_ppT>>(proof);
82 libff::leave_block("Test serialization of proof");
85 libff::print_header("RAM ppzkSNARK Verifier");
86 bool ans = ram_ppzksnark_verifier<ram_ppzksnark_ppT>(
87 keypair.vk, example.boot_trace, proof);
89 libff::print_indent();
90 libff::print_mem("after verifier");
91 printf("* The verification result is: %s\n", (ans ? "PASS" : "FAIL"));
93 libff::leave_block("Call to run_ram_ppzksnark");
98 } // namespace libsnark
100 #endif // RUN_RAM_PPZKSNARK_TCC_