2 *****************************************************************************
4 Implementation of functionality that runs the R1CS SEppzkSNARK for
7 See run_r1cs_se_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_R1CS_SE_PPZKSNARK_TCC_
16 #define RUN_R1CS_SE_PPZKSNARK_TCC_
18 #include <libff/common/profiling.hpp>
19 #include <libsnark/zk_proof_systems/ppzksnark/r1cs_se_ppzksnark/r1cs_se_ppzksnark.hpp>
21 #include <type_traits>
27 * The code below provides an example of all stages of running a R1CS
30 * Of course, in a real-life scenario, we would have three distinct entities,
31 * mangled into one in the demonstration below. The three entities are as
32 * follows. (1) The "generator", which runs the SEppzkSNARK generator on input a
33 * given constraint system CS to create a proving and a verification key for CS.
34 * (2) The "prover", which runs the SEppzkSNARK prover on input the proving key,
35 * a primary input for CS, and an auxiliary input for CS.
36 * (3) The "verifier", which runs the SEppzkSNARK verifier on input the
37 * verification key, a primary input for CS, and a proof.
39 template<typename ppT>
40 bool run_r1cs_se_ppzksnark(
41 const r1cs_example<libff::Fr<ppT>> &example, const bool test_serialization)
43 libff::enter_block("Call to run_r1cs_se_ppzksnark");
45 libff::print_header("R1CS SEppzkSNARK Generator");
46 r1cs_se_ppzksnark_keypair<ppT> keypair =
47 r1cs_se_ppzksnark_generator<ppT>(example.constraint_system);
49 libff::print_indent();
50 libff::print_mem("after generator");
52 libff::print_header("Preprocess verification key");
53 r1cs_se_ppzksnark_processed_verification_key<ppT> pvk =
54 r1cs_se_ppzksnark_verifier_process_vk<ppT>(keypair.vk);
56 if (test_serialization) {
57 libff::enter_block("Test serialization of keys");
59 libff::reserialize<r1cs_se_ppzksnark_proving_key<ppT>>(keypair.pk);
61 libff::reserialize<r1cs_se_ppzksnark_verification_key<ppT>>(
63 pvk = libff::reserialize<
64 r1cs_se_ppzksnark_processed_verification_key<ppT>>(pvk);
65 libff::leave_block("Test serialization of keys");
68 libff::print_header("R1CS SEppzkSNARK Prover");
69 r1cs_se_ppzksnark_proof<ppT> proof = r1cs_se_ppzksnark_prover<ppT>(
70 keypair.pk, example.primary_input, example.auxiliary_input);
72 libff::print_indent();
73 libff::print_mem("after prover");
75 if (test_serialization) {
76 libff::enter_block("Test serialization of proof");
77 proof = libff::reserialize<r1cs_se_ppzksnark_proof<ppT>>(proof);
78 libff::leave_block("Test serialization of proof");
81 libff::print_header("R1CS SEppzkSNARK Verifier");
82 const bool ans = r1cs_se_ppzksnark_verifier_strong_IC<ppT>(
83 keypair.vk, example.primary_input, proof);
85 libff::print_indent();
86 libff::print_mem("after verifier");
87 printf("* The verification result is: %s\n", (ans ? "PASS" : "FAIL"));
89 libff::print_header("R1CS SEppzkSNARK Online Verifier");
90 const bool ans2 = r1cs_se_ppzksnark_online_verifier_strong_IC<ppT>(
91 pvk, example.primary_input, proof);
95 libff::leave_block("Call to run_r1cs_se_ppzksnark");
100 } // namespace libsnark
102 #endif // RUN_R1CS_SE_PPZKSNARK_TCC_