Zeth - Zerocash on Ethereum  0.8
Reference implementation of the Zeth protocol by Clearmatics
merkle_path_compute.hpp
Go to the documentation of this file.
1 // DISCLAIMER:
2 // Content taken and adapted from:
3 // https://github.com/HarryR/ethsnarks/blob/master/src/gadgets/merkle_tree.hpp
4 // https://github.com/HarryR/ethsnarks/blob/master/src/gadgets/merkle_tree.cpp
5 
6 #ifndef __ZETH_CIRCUITS_MERKLE_PATH_COMPUTE_HPP__
7 #define __ZETH_CIRCUITS_MERKLE_PATH_COMPUTE_HPP__
8 
10 
11 namespace libzeth
12 {
13 
14 template<typename FieldT, typename HashTreeT>
15 class merkle_path_compute : public libsnark::gadget<FieldT>
16 {
17 public:
18  const size_t depth;
19  // Address of the leaf to authenticate
20  const libsnark::pb_variable_array<FieldT> address_bits;
21  // Leaf to authenticate
22  const libsnark::pb_variable<FieldT> leaf;
23  // Merkle Authentication path
24  const libsnark::pb_variable_array<FieldT> path;
25 
26  // Digests
27  libsnark::pb_variable_array<FieldT> digests;
28  // Gadget informing the position in the three of the computed
29  // hash and authentication node
30  std::vector<merkle_path_selector<FieldT>> selectors;
31  // Vector of hash gadgets to compute the intermediary digests
32  std::vector<HashTreeT> hashers;
33 
35  libsnark::protoboard<FieldT> &pb,
36  // Depth of the tree
37  const size_t depth,
38  // Address of the leaf to authenticate
39  const libsnark::pb_variable_array<FieldT> &address_bits,
40  // Leaf to authenticate
41  const libsnark::pb_variable<FieldT> leaf,
42  // Merkle Authentication path
43  const libsnark::pb_variable_array<FieldT> &path,
44  const std::string &annotation_prefix);
45 
47  void generate_r1cs_witness();
48 
49  // Returns the computed root
50  const libsnark::pb_variable<FieldT> result();
51 };
52 
53 } // namespace libzeth
54 
56 
57 #endif // __ZETH_CIRCUITS_MERKLE_PATH_COMPUTE_HPP__
libzeth::merkle_path_compute::digests
libsnark::pb_variable_array< FieldT > digests
Definition: merkle_path_compute.hpp:27
libzeth::merkle_path_compute::path
const libsnark::pb_variable_array< FieldT > path
Definition: merkle_path_compute.hpp:24
libzeth::merkle_path_compute::leaf
const libsnark::pb_variable< FieldT > leaf
Definition: merkle_path_compute.hpp:22
libzeth::merkle_path_compute::hashers
std::vector< HashTreeT > hashers
Definition: merkle_path_compute.hpp:32
libzeth
Definition: binary_operation.hpp:15
libzeth::merkle_path_compute::generate_r1cs_constraints
void generate_r1cs_constraints()
libzeth::merkle_path_compute::generate_r1cs_witness
void generate_r1cs_witness()
merkle_path_compute.tcc
libzeth::merkle_path_compute
Definition: merkle_path_compute.hpp:15
libzeth::merkle_path_compute::result
const libsnark::pb_variable< FieldT > result()
libzeth::merkle_path_compute::merkle_path_compute
merkle_path_compute(libsnark::protoboard< FieldT > &pb, const size_t depth, const libsnark::pb_variable_array< FieldT > &address_bits, const libsnark::pb_variable< FieldT > leaf, const libsnark::pb_variable_array< FieldT > &path, const std::string &annotation_prefix)
merkle_path_selector.hpp
libzeth::merkle_path_compute::selectors
std::vector< merkle_path_selector< FieldT > > selectors
Definition: merkle_path_compute.hpp:30
libzeth::merkle_path_compute::address_bits
const libsnark::pb_variable_array< FieldT > address_bits
Definition: merkle_path_compute.hpp:20
libzeth::merkle_path_compute::depth
const size_t depth
Definition: merkle_path_compute.hpp:18