Zecale - Reconciling Privacy and Scalability on Smart-Contract Chains  0.5
Reference implementation of the Zecale protocol by Clearmatics
verification_key_hash_gadget.tcc
Go to the documentation of this file.
1 // Copyright (c) 2015-2022 Clearmatics Technologies Ltd
2 //
3 // SPDX-License-Identifier: LGPL-3.0+
4 
5 #ifndef __ZECALE_CIRCUITS_VERIFICAION_KEY_HASH_GADGET_TCC__
6 #define __ZECALE_CIRCUITS_VERIFICAION_KEY_HASH_GADGET_TCC__
7 
8 #include "libzecale/circuits/verification_key_hash_gadget.hpp"
9 
10 namespace libzecale
11 {
12 
13 // verification_key_scalar_hash_gadget
14 
15 template<typename wppT, typename nverifierT>
16 verification_key_hash_gadget<wppT, nverifierT>::verification_key_hash_gadget(
17  libsnark::protoboard<libff::Fr<wppT>> &pb,
18  verification_key_variable &verification_key,
19  libsnark::pb_variable<libff::Fr<wppT>> &verification_key_hash,
20  const std::string &annotation_prefix)
21  : libsnark::gadget<FieldT>(pb, annotation_prefix)
22  , _hash_gadget(
23  pb,
24  verification_key.get_all_vars(),
25  verification_key_hash,
26  FMT(annotation_prefix, " _hash_gadget"))
27 {
28 }
29 
30 template<typename wppT, typename nverifierT>
31 void verification_key_hash_gadget<wppT, nverifierT>::generate_r1cs_constraints()
32 {
33  _hash_gadget.generate_r1cs_constraints();
34 }
35 
36 template<typename wppT, typename nverifierT>
37 void verification_key_hash_gadget<wppT, nverifierT>::generate_r1cs_witness()
38 {
39  _hash_gadget.generate_r1cs_witness();
40 }
41 
42 template<typename wppT, typename nverifierT>
43 libff::Fr<wppT> verification_key_hash_gadget<wppT, nverifierT>::compute_hash(
44  const typename nsnark::verification_key &vk, size_t num_inputs)
45 {
46  libsnark::protoboard<FieldT> pb;
47  libsnark::pb_variable<libff::Fr<wppT>> nvk_hash;
48  nvk_hash.allocate(pb, "nvk_hash");
49  verification_key_variable nvk(pb, num_inputs, "nvk");
50  libzecale::verification_key_hash_gadget<wppT, nverifierT> nvk_hash_gadget(
51  pb, nvk, nvk_hash, "nvk_hash_gadget");
52 
53  nvk_hash_gadget.generate_r1cs_constraints();
54 
55  nvk.generate_r1cs_witness(vk);
56  nvk_hash_gadget.generate_r1cs_witness();
57 
58  return pb.val(nvk_hash);
59 }
60 
61 } // namespace libzecale
62 
63 #endif // __ZECALE_CIRCUITS_VERIFICAION_KEY_HASH_GADGET_TCC__