2#include "barretenberg/numeric/uint256/uint256.hpp"
3#include "barretenberg/relations/relation_types.hpp"
5namespace proof_system {
34 static constexpr std::array<size_t, 6> SUBRELATION_PARTIAL_LENGTHS{
43 static constexpr std::array<size_t, 6> TOTAL_LENGTH_ADJUSTMENTS{
86 template <
typename ContainerOverSubrelations,
typename AllEntities,
typename Parameters>
87 inline static void accumulate(ContainerOverSubrelations& accumulators,
88 const AllEntities& in,
89 const Parameters& params,
90 const FF& scaling_factor)
94 using Accumulator =
typename std::tuple_element_t<0, ContainerOverSubrelations>;
95 using View =
typename Accumulator::View;
96 using ParameterView = GetParameterView<Parameters, View>;
98 const auto& eta = ParameterView(params.eta);
100 auto w_1 = View(in.w_l);
101 auto w_2 = View(in.w_r);
102 auto w_3 = View(in.w_o);
103 auto w_4 = View(in.w_4);
104 auto w_1_shift = View(in.w_l_shift);
105 auto w_2_shift = View(in.w_r_shift);
106 auto w_3_shift = View(in.w_o_shift);
107 auto w_4_shift = View(in.w_4_shift);
109 auto q_1 = View(in.q_l);
110 auto q_2 = View(in.q_r);
111 auto q_3 = View(in.q_o);
112 auto q_4 = View(in.q_4);
113 auto q_m = View(in.q_m);
114 auto q_c = View(in.q_c);
115 auto q_arith = View(in.q_arith);
116 auto q_aux = View(in.q_aux);
119 const FF SUBLIMB_SHIFT(
uint256_t(1) << 14);
131 auto limb_subproduct = w_1 * w_2_shift + w_1_shift * w_2;
132 auto non_native_field_gate_2 = (w_1 * w_4 + w_2 * w_3 - w_3_shift);
133 non_native_field_gate_2 *= LIMB_SIZE;
134 non_native_field_gate_2 -= w_4_shift;
135 non_native_field_gate_2 += limb_subproduct;
136 non_native_field_gate_2 *= q_4;
138 limb_subproduct *= LIMB_SIZE;
139 limb_subproduct += (w_1_shift * w_2_shift);
140 auto non_native_field_gate_1 = limb_subproduct;
141 non_native_field_gate_1 -= (w_3 + w_4);
142 non_native_field_gate_1 *= q_3;
144 auto non_native_field_gate_3 = limb_subproduct;
145 non_native_field_gate_3 += w_4;
146 non_native_field_gate_3 -= (w_3_shift + w_4_shift);
147 non_native_field_gate_3 *= q_m;
149 auto non_native_field_identity = non_native_field_gate_1 + non_native_field_gate_2 + non_native_field_gate_3;
150 non_native_field_identity *= q_2;
154 auto limb_accumulator_1 = w_2_shift * SUBLIMB_SHIFT;
155 limb_accumulator_1 += w_1_shift;
156 limb_accumulator_1 *= SUBLIMB_SHIFT;
157 limb_accumulator_1 += w_3;
158 limb_accumulator_1 *= SUBLIMB_SHIFT;
159 limb_accumulator_1 += w_2;
160 limb_accumulator_1 *= SUBLIMB_SHIFT;
161 limb_accumulator_1 += w_1;
162 limb_accumulator_1 -= w_4;
163 limb_accumulator_1 *= q_4;
167 auto limb_accumulator_2 = w_3_shift * SUBLIMB_SHIFT;
168 limb_accumulator_2 += w_2_shift;
169 limb_accumulator_2 *= SUBLIMB_SHIFT;
170 limb_accumulator_2 += w_1_shift;
171 limb_accumulator_2 *= SUBLIMB_SHIFT;
172 limb_accumulator_2 += w_4;
173 limb_accumulator_2 *= SUBLIMB_SHIFT;
174 limb_accumulator_2 += w_3;
175 limb_accumulator_2 -= w_4_shift;
176 limb_accumulator_2 *= q_m;
178 auto limb_accumulator_identity = limb_accumulator_1 + limb_accumulator_2;
179 limb_accumulator_identity *= q_3;
221 auto memory_record_check = w_3 * eta;
222 memory_record_check += w_2;
223 memory_record_check *= eta;
224 memory_record_check += w_1;
225 memory_record_check *= eta;
226 memory_record_check += q_c;
227 auto partial_record_check = memory_record_check;
228 memory_record_check = memory_record_check - w_4;
245 auto index_delta = w_1_shift - w_1;
246 auto record_delta = w_4_shift - w_4;
248 auto index_is_monotonically_increasing = index_delta * index_delta - index_delta;
250 auto adjacent_values_match_if_adjacent_indices_match = (index_delta * FF(-1) + FF(1)) * record_delta;
252 std::get<1>(accumulators) +=
253 adjacent_values_match_if_adjacent_indices_match * (q_1 * q_2) * (q_aux * scaling_factor);
254 std::get<2>(accumulators) +=
255 index_is_monotonically_increasing * (q_1 * q_2) * (q_aux * scaling_factor);
256 auto ROM_consistency_check_identity = memory_record_check * (q_1 * q_2);
276 auto access_type = (w_4 - partial_record_check);
277 auto access_check = access_type * access_type - access_type;
282 auto next_gate_access_type = w_3_shift * eta;
283 next_gate_access_type += w_2_shift;
284 next_gate_access_type *= eta;
285 next_gate_access_type += w_1_shift;
286 next_gate_access_type *= eta;
287 next_gate_access_type = w_4_shift - next_gate_access_type;
289 auto value_delta = w_3_shift - w_3;
290 auto adjacent_values_match_if_adjacent_indices_match_and_next_access_is_a_read_operation =
291 (index_delta * FF(-1) + FF(1)) * value_delta * (next_gate_access_type * FF(-1) + FF(1));
298 auto next_gate_access_type_is_boolean = next_gate_access_type * next_gate_access_type - next_gate_access_type;
301 std::get<3>(accumulators) +=
302 adjacent_values_match_if_adjacent_indices_match_and_next_access_is_a_read_operation * (q_arith) *
303 (q_aux * scaling_factor);
304 std::get<4>(accumulators) += index_is_monotonically_increasing * (q_arith) * (q_aux * scaling_factor);
305 std::get<5>(accumulators) +=
306 next_gate_access_type_is_boolean * (q_arith) * (q_aux * scaling_factor);
307 auto RAM_consistency_check_identity = access_check * (q_arith);
320 auto timestamp_delta = w_2_shift - w_2;
321 auto RAM_timestamp_check_identity = (index_delta * FF(-1) + FF(1)) * timestamp_delta - w_3;
327 auto memory_identity = ROM_consistency_check_identity;
328 memory_identity += RAM_timestamp_check_identity * (q_4 * q_1);
329 memory_identity += memory_record_check * (q_m * q_1);
330 memory_identity += RAM_consistency_check_identity;
333 auto auxiliary_identity = memory_identity + non_native_field_identity + limb_accumulator_identity;
334 auxiliary_identity *= (q_aux * scaling_factor);
335 std::get<0>(accumulators) += auxiliary_identity;
339template <
typename FF>
using AuxiliaryRelation = Relation<AuxiliaryRelationImpl<FF>>;
Definition: uint256.hpp:25
Definition: auxiliary_relation.hpp:7
static void accumulate(ContainerOverSubrelations &accumulators, const AllEntities &in, const Parameters ¶ms, const FF &scaling_factor)
Expression for the generalized permutation sort gate.
Definition: auxiliary_relation.hpp:87