Clearmatics Libsnark  0.1
C++ library for zkSNARK proofs
ram_universal_gadget.hpp
Go to the documentation of this file.
1 
44 #ifndef RAM_UNIVERSAL_GADGET_HPP_
45 #define RAM_UNIVERSAL_GADGET_HPP_
46 
51 
52 namespace libsnark
53 {
54 
55 /*
56  Memory layout for our reduction is as follows:
57 
58  (1) An initial execution line carrying the initial state (set
59  to all zeros)
60  (2) program_size_bound + primary_input_size_bound memory lines for
61  storing input and program (boot)
62  (3) time_bound pairs for (fetch instruction memory line, execute
63  instruction execution line)
64 
65  Memory line stores address, previous value and the next value of the
66  memory cell specified by the address. An execution line additionally
67  carries the CPU state.
68 
69  Our memory handling technique has a technical requirement that
70  address 0 must be accessed. We fulfill this by requiring the initial
71  execution line to act as "store 0 to address 0".
72 
73  ---
74 
75  As an implementation detail if less than program_size_bound +
76  primary_input_size_bound are used in the initial memory map, then we
77  pre-pend (!) them with "store 0 to address 0" lines. This
78  pre-pending means that memory maps that have non-zero value at
79  address 0 will still be handled correctly.
80 
81  The R1CS input packs the memory map starting from the last entry to
82  the first. This way, the prepended zeros arrive at the end of R1CS
83  input and thus can be ignored by the "weak" input consistency R1CS
84  verifier.
85 */
86 
87 template<typename ramT>
89 {
90 public:
92 
94 
95  std::vector<memory_line_variable_gadget<ramT>> boot_lines;
96  std::vector<pb_variable_array<FieldT>> boot_line_bits;
97  std::vector<multipacking_gadget<FieldT>> unpack_boot_lines;
98 
99  std::vector<memory_line_variable_gadget<ramT>> load_instruction_lines;
100  std::vector<execution_line_variable_gadget<ramT>>
101  execution_lines; /* including the initial execution line */
102 
103  std::vector<memory_line_variable_gadget<ramT> *> unrouted_memory_lines;
104  std::vector<memory_line_variable_gadget<ramT>> routed_memory_lines;
105 
106  std::vector<ram_cpu_checker<ramT>> execution_checkers;
107  std::vector<memory_checker_gadget<ramT>> memory_checkers;
108 
109  std::vector<pb_variable_array<FieldT>> routing_inputs;
110  std::vector<pb_variable_array<FieldT>> routing_outputs;
111 
112  std::shared_ptr<as_waksman_routing_gadget<FieldT>> routing_network;
113 
114 public:
116  size_t time_bound;
118 
121  const size_t boot_trace_size_bound,
122  const size_t time_bound,
124  const std::string &annotation_prefix = "");
125 
128  const ram_boot_trace<ramT> &boot_trace,
129  const ram_input_tape<ramT> &auxiliary_input);
130 
131  /* both methods assume that generate_r1cs_witness has been called */
132  void print_execution_trace() const;
133  void print_memory_trace() const;
134 
135  static size_t packed_input_element_size(
137  static size_t packed_input_size(
139  const size_t boot_trace_size_bound);
140 };
141 
142 } // namespace libsnark
143 
145 
146 #endif // RAM_UNIVERSAL_GADGET_HPP_
libsnark::ram_universal_gadget::memory_checkers
std::vector< memory_checker_gadget< ramT > > memory_checkers
Definition: ram_universal_gadget.hpp:107
libsnark::ram_universal_gadget::ram_universal_gadget
ram_universal_gadget(ram_protoboard< ramT > &pb, const size_t boot_trace_size_bound, const size_t time_bound, const pb_variable_array< FieldT > &packed_input, const std::string &annotation_prefix="")
libsnark::ram_input_tape
std::vector< size_t > ram_input_tape
Definition: ram_params.hpp:55
libsnark::ram_architecture_params
typename ramT::architecture_params_type ram_architecture_params
Definition: ram_params.hpp:53
libsnark::ram_universal_gadget::num_memory_lines
size_t num_memory_lines
Definition: ram_universal_gadget.hpp:93
libsnark::ram_universal_gadget::print_memory_trace
void print_memory_trace() const
libsnark::ram_protoboard
typename ramT::protoboard_type ram_protoboard
Definition: ram_params.hpp:46
libsnark::ram_universal_gadget::print_execution_trace
void print_execution_trace() const
as_waksman_routing_gadget.hpp
libsnark
Definition: accumulation_vector.hpp:18
libsnark::ram_universal_gadget::unpack_boot_lines
std::vector< multipacking_gadget< FieldT > > unpack_boot_lines
Definition: ram_universal_gadget.hpp:97
libsnark::ram_base_field
typename ramT::base_field_type ram_base_field
Definition: ram_params.hpp:40
libsnark::ram_universal_gadget::generate_r1cs_witness
void generate_r1cs_witness(const ram_boot_trace< ramT > &boot_trace, const ram_input_tape< ramT > &auxiliary_input)
libsnark::ram_universal_gadget::unrouted_memory_lines
std::vector< memory_line_variable_gadget< ramT > * > unrouted_memory_lines
Definition: ram_universal_gadget.hpp:103
libsnark::ram_universal_gadget::execution_checkers
std::vector< ram_cpu_checker< ramT > > execution_checkers
Definition: ram_universal_gadget.hpp:106
libsnark::ram_universal_gadget::routed_memory_lines
std::vector< memory_line_variable_gadget< ramT > > routed_memory_lines
Definition: ram_universal_gadget.hpp:104
trace_lines.hpp
libsnark::ram_universal_gadget::boot_trace_size_bound
size_t boot_trace_size_bound
Definition: ram_universal_gadget.hpp:115
libsnark::ram_universal_gadget
Definition: ram_universal_gadget.hpp:88
libsnark::ram_universal_gadget::time_bound
size_t time_bound
Definition: ram_universal_gadget.hpp:116
libsnark::ram_universal_gadget::packed_input
pb_variable_array< FieldT > packed_input
Definition: ram_universal_gadget.hpp:117
libsnark::ram_universal_gadget::load_instruction_lines
std::vector< memory_line_variable_gadget< ramT > > load_instruction_lines
Definition: ram_universal_gadget.hpp:99
memory_checker_gadget.hpp
ram_universal_gadget.tcc
libsnark::ram_universal_gadget::routing_network
std::shared_ptr< as_waksman_routing_gadget< FieldT > > routing_network
Definition: ram_universal_gadget.hpp:112
libsnark::ram_universal_gadget::boot_line_bits
std::vector< pb_variable_array< FieldT > > boot_line_bits
Definition: ram_universal_gadget.hpp:96
libsnark::ram_universal_gadget::FieldT
ram_base_field< ramT > FieldT
Definition: ram_universal_gadget.hpp:91
libsnark::memory_store_trace
Definition: memory_store_trace.hpp:29
libsnark::ram_universal_gadget::packed_input_element_size
static size_t packed_input_element_size(const ram_architecture_params< ramT > &ap)
libsnark::ram_universal_gadget::routing_outputs
std::vector< pb_variable_array< FieldT > > routing_outputs
Definition: ram_universal_gadget.hpp:110
libsnark::ram_universal_gadget::boot_lines
std::vector< memory_line_variable_gadget< ramT > > boot_lines
Definition: ram_universal_gadget.hpp:95
libsnark::ram_universal_gadget::packed_input_size
static size_t packed_input_size(const ram_architecture_params< ramT > &ap, const size_t boot_trace_size_bound)
libsnark::pb_variable_array
Definition: pb_variable.hpp:44
libsnark::ram_gadget_base
typename ramT::gadget_base_type ram_gadget_base
Definition: ram_params.hpp:48
libsnark::ram_universal_gadget::execution_lines
std::vector< execution_line_variable_gadget< ramT > > execution_lines
Definition: ram_universal_gadget.hpp:101
libsnark::ram_universal_gadget::generate_r1cs_constraints
void generate_r1cs_constraints()
ram_params.hpp
libsnark::ram_universal_gadget::routing_inputs
std::vector< pb_variable_array< FieldT > > routing_inputs
Definition: ram_universal_gadget.hpp:109