Clearmatics Libsnark  0.1
C++ library for zkSNARK proofs
knapsack_gadget.hpp
Go to the documentation of this file.
1 
45 #ifndef KNAPSACK_GADGET_HPP_
46 #define KNAPSACK_GADGET_HPP_
47 
51 
52 namespace libsnark
53 {
54 
55 /************************** Choice of dimension ******************************/
56 
57 template<typename FieldT> struct knapsack_dimension {
58  // the size of FieldT should be (approximately) at least 200 bits
59  static const size_t dimension = 1;
60 };
61 
62 /*********************** Knapsack with field output **************************/
63 
64 template<typename FieldT>
66 {
67 private:
68  static std::vector<FieldT> knapsack_coefficients;
69  static size_t num_cached_coefficients;
70 
71 public:
72  size_t input_len;
73  size_t dimension;
74 
77 
80  const size_t input_len,
83  const std::string &annotation_prefix);
85  void generate_r1cs_witness();
86 
87  static size_t get_digest_len();
88  // return 0 as block length, as the hash function is variable-input
89  static size_t get_block_len();
90  static std::vector<FieldT> get_hash(const libff::bit_vector &input);
91  static void sample_randomness(const size_t input_len);
92 
93  // for debugging
94  static size_t expected_constraints();
95 };
96 
97 /********************** Knapsack with binary output **************************/
98 
99 template<typename FieldT>
101 {
102 public:
103  typedef libff::bit_vector hash_value_type;
105 
106  size_t input_len;
107  size_t dimension;
108 
110 
111  std::shared_ptr<knapsack_CRH_with_field_out_gadget<FieldT>> hasher;
112 
115 
118  const size_t input_len,
121  const std::string &annotation_prefix);
122  void generate_r1cs_constraints(const bool enforce_bitness = true);
123  void generate_r1cs_witness();
124 
125  static size_t get_digest_len();
126  // return 0 as block length, as the hash function is variable-input
127  static size_t get_block_len();
128  static hash_value_type get_hash(const libff::bit_vector &input);
129  static void sample_randomness(const size_t input_len);
130 
131  // for debugging
132  static size_t expected_constraints(const bool enforce_bitness = true);
133 };
134 
135 template<typename FieldT> void test_knapsack_CRH_with_bit_out_gadget();
136 
137 } // namespace libsnark
138 
140 
141 #endif // KNAPSACK_GADGET_HPP_
libsnark::knapsack_CRH_with_bit_out_gadget
Definition: knapsack_gadget.hpp:100
libsnark::gadget::annotation_prefix
const std::string annotation_prefix
Definition: gadget.hpp:20
libsnark
Definition: accumulation_vector.hpp:18
libsnark::knapsack_CRH_with_field_out_gadget::generate_r1cs_witness
void generate_r1cs_witness()
libsnark::knapsack_CRH_with_bit_out_gadget::get_digest_len
static size_t get_digest_len()
libsnark::gadget::pb
protoboard< FieldT > & pb
Definition: gadget.hpp:19
libsnark::knapsack_dimension::dimension
static const size_t dimension
Definition: knapsack_gadget.hpp:59
libsnark::knapsack_CRH_with_bit_out_gadget::input_block
block_variable< FieldT > input_block
Definition: knapsack_gadget.hpp:113
libsnark::knapsack_CRH_with_bit_out_gadget::sample_randomness
static void sample_randomness(const size_t input_len)
libsnark::knapsack_CRH_with_bit_out_gadget::output_digest
digest_variable< FieldT > output_digest
Definition: knapsack_gadget.hpp:114
libsnark::knapsack_CRH_with_bit_out_gadget::knapsack_CRH_with_bit_out_gadget
knapsack_CRH_with_bit_out_gadget(protoboard< FieldT > &pb, const size_t input_len, const block_variable< FieldT > &input_block, const digest_variable< FieldT > &output_digest, const std::string &annotation_prefix)
libsnark::knapsack_CRH_with_field_out_gadget::sample_randomness
static void sample_randomness(const size_t input_len)
libsnark::knapsack_CRH_with_bit_out_gadget::input_len
size_t input_len
Definition: knapsack_gadget.hpp:106
libsnark::gadget
Definition: gadget.hpp:16
hash_io.hpp
libsnark::knapsack_CRH_with_field_out_gadget::knapsack_CRH_with_field_out_gadget
knapsack_CRH_with_field_out_gadget(protoboard< FieldT > &pb, const size_t input_len, const block_variable< FieldT > &input_block, const pb_linear_combination_array< FieldT > &output, const std::string &annotation_prefix)
libsnark::knapsack_CRH_with_field_out_gadget::output
pb_linear_combination_array< FieldT > output
Definition: knapsack_gadget.hpp:76
libsnark::knapsack_CRH_with_field_out_gadget::expected_constraints
static size_t expected_constraints()
libsnark::knapsack_CRH_with_bit_out_gadget::dimension
size_t dimension
Definition: knapsack_gadget.hpp:107
libsnark::test_knapsack_CRH_with_bit_out_gadget
void test_knapsack_CRH_with_bit_out_gadget()
merkle_tree.hpp
libsnark::knapsack_CRH_with_bit_out_gadget::output
pb_linear_combination_array< FieldT > output
Definition: knapsack_gadget.hpp:109
libsnark::knapsack_CRH_with_field_out_gadget::input_block
block_variable< FieldT > input_block
Definition: knapsack_gadget.hpp:75
libsnark::knapsack_CRH_with_bit_out_gadget::hasher
std::shared_ptr< knapsack_CRH_with_field_out_gadget< FieldT > > hasher
Definition: knapsack_gadget.hpp:111
libsnark::knapsack_CRH_with_bit_out_gadget::hash_value_type
libff::bit_vector hash_value_type
Definition: knapsack_gadget.hpp:103
libsnark::knapsack_dimension
Definition: knapsack_gadget.hpp:57
libsnark::pb_linear_combination_array
Definition: pb_variable.hpp:118
libsnark::knapsack_CRH_with_field_out_gadget::dimension
size_t dimension
Definition: knapsack_gadget.hpp:73
libsnark::block_variable
Definition: hash_io.hpp:39
libsnark::knapsack_CRH_with_field_out_gadget::get_hash
static std::vector< FieldT > get_hash(const libff::bit_vector &input)
libsnark::digest_variable
Definition: hash_io.hpp:16
libsnark::knapsack_CRH_with_bit_out_gadget::generate_r1cs_witness
void generate_r1cs_witness()
libsnark::knapsack_CRH_with_bit_out_gadget::get_block_len
static size_t get_block_len()
libsnark::knapsack_CRH_with_field_out_gadget
Definition: knapsack_gadget.hpp:65
basic_gadgets.hpp
libsnark::knapsack_CRH_with_bit_out_gadget::merkle_authentication_path_type
merkle_authentication_path merkle_authentication_path_type
Definition: knapsack_gadget.hpp:104
libsnark::knapsack_CRH_with_field_out_gadget::get_block_len
static size_t get_block_len()
libsnark::knapsack_CRH_with_field_out_gadget::generate_r1cs_constraints
void generate_r1cs_constraints()
knapsack_gadget.tcc
libsnark::knapsack_CRH_with_bit_out_gadget::get_hash
static hash_value_type get_hash(const libff::bit_vector &input)
libsnark::merkle_authentication_path
std::vector< merkle_authentication_node > merkle_authentication_path
Definition: merkle_tree.hpp:36
libsnark::knapsack_CRH_with_bit_out_gadget::generate_r1cs_constraints
void generate_r1cs_constraints(const bool enforce_bitness=true)
libsnark::knapsack_CRH_with_field_out_gadget::get_digest_len
static size_t get_digest_len()
libsnark::knapsack_CRH_with_bit_out_gadget::expected_constraints
static size_t expected_constraints(const bool enforce_bitness=true)
libsnark::knapsack_CRH_with_field_out_gadget::input_len
size_t input_len
Definition: knapsack_gadget.hpp:72
libsnark::protoboard
Definition: pb_variable.hpp:22