2 *****************************************************************************
4 Implementation of functionality that runs the BACS ppzkSNARK for
7 See run_bacs_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_BACS_PPZKSNARK_TCC_
16 #define RUN_BACS_PPZKSNARK_TCC_
18 #include <libff/common/profiling.hpp>
19 #include <libsnark/zk_proof_systems/ppzksnark/bacs_ppzksnark/bacs_ppzksnark.hpp>
26 * The code below provides an example of all stages of running a BACS 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 circuit C to create a proving and a verification key for C. (2) The
32 * "prover", which runs the ppzkSNARK prover on input the proving key, a primary
33 * input for C, and an auxiliary input for C. (3) The "verifier", which runs the
34 * ppzkSNARK verifier on input the verification key, a primary input for C, and
37 template<typename ppT>
38 bool run_bacs_ppzksnark(
39 const bacs_example<libff::Fr<ppT>> &example, const bool test_serialization)
41 libff::enter_block("Call to run_bacs_ppzksnark");
43 libff::print_header("BACS ppzkSNARK Generator");
44 bacs_ppzksnark_keypair<ppT> keypair =
45 bacs_ppzksnark_generator<ppT>(example.circuit);
47 libff::print_indent();
48 libff::print_mem("after generator");
50 libff::print_header("Preprocess verification key");
51 bacs_ppzksnark_processed_verification_key<ppT> pvk =
52 bacs_ppzksnark_verifier_process_vk<ppT>(keypair.vk);
54 if (test_serialization) {
55 libff::enter_block("Test serialization of keys");
57 libff::reserialize<bacs_ppzksnark_proving_key<ppT>>(keypair.pk);
58 keypair.vk = libff::reserialize<bacs_ppzksnark_verification_key<ppT>>(
61 libff::reserialize<bacs_ppzksnark_processed_verification_key<ppT>>(
63 libff::leave_block("Test serialization of keys");
66 libff::print_header("BACS ppzkSNARK Prover");
67 bacs_ppzksnark_proof<ppT> proof = bacs_ppzksnark_prover<ppT>(
68 keypair.pk, example.primary_input, example.auxiliary_input);
70 libff::print_indent();
71 libff::print_mem("after prover");
73 if (test_serialization) {
74 libff::enter_block("Test serialization of proof");
75 proof = libff::reserialize<bacs_ppzksnark_proof<ppT>>(proof);
76 libff::leave_block("Test serialization of proof");
79 libff::print_header("BACS ppzkSNARK Verifier");
80 bool ans = bacs_ppzksnark_verifier_strong_IC<ppT>(
81 keypair.vk, example.primary_input, proof);
83 libff::print_indent();
84 libff::print_mem("after verifier");
85 printf("* The verification result is: %s\n", (ans ? "PASS" : "FAIL"));
87 libff::print_header("BACS ppzkSNARK Online Verifier");
88 bool ans2 = bacs_ppzksnark_online_verifier_strong_IC<ppT>(
89 pvk, example.primary_input, proof);
93 libff::leave_block("Call to run_bacs_ppzksnark");
98 } // namespace libsnark
100 #endif // RUN_BACS_PPZKSNARK_TCC_