2 *****************************************************************************
4 Implementation of functionality that runs the RAM zkSNARK for
7 See run_ram_zksnark.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_ZKSNARK_TCC_
16 #define RUN_RAM_ZKSNARK_TCC_
18 #include <libff/common/profiling.hpp>
19 #include <libsnark/zk_proof_systems/zksnark/ram_zksnark/ram_zksnark.hpp>
26 * The code below provides an example of all stages of running a RAM zkSNARK.
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 zkSNARK generator on input a
31 * given architecture. (2) The "prover", which runs the zkSNARK prover on input
32 * the proving key, a boot trace, and an auxiliary input. (3) The "verifier",
33 * which runs the zkSNARK verifier on input the verification key, a boot trace,
34 * a time bound, and a proof.
36 template<typename ram_zksnark_ppT>
38 const ram_example<ram_zksnark_machine_pp<ram_zksnark_ppT>> &example,
39 const bool test_serialization)
41 libff::enter_block("Call to run_ram_zksnark");
43 printf("This run uses an example with the following parameters:\n");
45 printf("* Time bound (T): %zu\n", example.time_bound);
47 libff::print_header("RAM zkSNARK Generator");
48 ram_zksnark_keypair<ram_zksnark_ppT> keypair =
49 ram_zksnark_generator<ram_zksnark_ppT>(example.ap);
51 libff::print_indent();
52 libff::print_mem("after generator");
54 if (test_serialization) {
55 libff::enter_block("Test serialization of keys");
57 libff::reserialize<ram_zksnark_proving_key<ram_zksnark_ppT>>(
60 libff::reserialize<ram_zksnark_verification_key<ram_zksnark_ppT>>(
62 libff::leave_block("Test serialization of keys");
65 libff::print_header("RAM zkSNARK Prover");
66 ram_zksnark_proof<ram_zksnark_ppT> proof =
67 ram_zksnark_prover<ram_zksnark_ppT>(
71 example.auxiliary_input);
73 libff::print_indent();
74 libff::print_mem("after prover");
76 if (test_serialization) {
77 libff::enter_block("Test serialization of proof");
78 proof = libff::reserialize<ram_zksnark_proof<ram_zksnark_ppT>>(proof);
79 libff::leave_block("Test serialization of proof");
82 libff::print_header("RAM zkSNARK Verifier");
83 bool ans = ram_zksnark_verifier<ram_zksnark_ppT>(
84 keypair.vk, example.boot_trace, example.time_bound, proof);
86 libff::print_indent();
87 libff::print_mem("after verifier");
88 printf("* The verification result is: %s\n", (ans ? "PASS" : "FAIL"));
90 libff::leave_block("Call to run_ram_zksnark");
95 } // namespace libsnark
97 #endif // RUN_RAM_ZKSNARK_TCC_