Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
ecc_wnaf_relation_impl.hpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: not started, auditors: [], date: YYYY-MM-DD }
3// external_1: { status: not started, auditors: [], date: YYYY-MM-DD }
4// external_2: { status: not started, auditors: [], date: YYYY-MM-DD }
5// =====================
6
8
9namespace bb {
10
41template <typename FF>
42template <typename ContainerOverSubrelations, typename AllEntities, typename Parameters>
43void ECCVMWnafRelationImpl<FF>::accumulate(ContainerOverSubrelations& accumulator,
44 const AllEntities& in,
45 const Parameters& /*unused*/,
46 const FF& scaling_factor)
47{
49 using View = typename Accumulator::View;
50
51 auto scalar_sum = View(in.precompute_scalar_sum);
52 auto scalar_sum_new = View(in.precompute_scalar_sum_shift);
53 auto q_transition = View(in.precompute_point_transition);
54 auto round = View(in.precompute_round);
55 auto round_shift = View(in.precompute_round_shift);
56 auto pc = View(in.precompute_pc);
57 auto pc_shift = View(in.precompute_pc_shift);
58 // precompute_select is a boolean column. We only evaluate the ecc_wnaf_relation and the ecc_point_table_relation if
59 // `precompute_select=1`
60 auto precompute_select = View(in.precompute_select);
61 auto precompute_select_shift = View(in.precompute_select_shift);
62
63 const auto& precompute_skew = View(in.precompute_skew);
64
65 const std::array<View, 8> slices{
66 View(in.precompute_s1hi), View(in.precompute_s1lo), View(in.precompute_s2hi), View(in.precompute_s2lo),
67 View(in.precompute_s3hi), View(in.precompute_s3lo), View(in.precompute_s4hi), View(in.precompute_s4lo),
68 };
69
70 const auto range_constraint_slice_to_2_bits = [&scaling_factor](const View& s, auto& acc) {
71 acc += ((s - 1).sqr() - 1) * ((s - 2).sqr() - 1) * scaling_factor;
72 };
73
74 const auto convert_to_wnaf = [](const View& s0, const View& s1) {
75 auto t = s0 + s0;
76 t += t;
77 t += s1;
78 auto naf = t + t - 15;
79 return naf;
80 };
81
82 const auto scaled_transition = q_transition * scaling_factor;
83 const auto scaled_transition_is_zero = -scaled_transition + scaling_factor;
89 range_constraint_slice_to_2_bits(slices[0], std::get<0>(accumulator));
90 range_constraint_slice_to_2_bits(slices[1], std::get<1>(accumulator));
91 range_constraint_slice_to_2_bits(slices[2], std::get<2>(accumulator));
92 range_constraint_slice_to_2_bits(slices[3], std::get<3>(accumulator));
93 range_constraint_slice_to_2_bits(slices[4], std::get<4>(accumulator));
94 range_constraint_slice_to_2_bits(slices[5], std::get<5>(accumulator));
95 range_constraint_slice_to_2_bits(slices[6], std::get<6>(accumulator));
96 range_constraint_slice_to_2_bits(slices[7], std::get<7>(accumulator));
97
106 const auto s1_shift = View(in.precompute_s1hi_shift);
107 const auto s1_shift_msb_set = (s1_shift - 2) * (s1_shift - 3);
108 std::get<20>(accumulator) += scaled_transition * precompute_select_shift * s1_shift_msb_set;
109
116 const auto w0 = convert_to_wnaf(slices[0], slices[1]);
117 const auto w1 = convert_to_wnaf(slices[2], slices[3]);
118 const auto w2 = convert_to_wnaf(slices[4], slices[5]);
119 const auto w3 = convert_to_wnaf(slices[6], slices[7]);
120
130 auto row_slice = w0;
131 row_slice += row_slice;
132 row_slice += row_slice;
133 row_slice += row_slice;
134 row_slice += row_slice;
135 row_slice += w1;
136 row_slice += row_slice;
137 row_slice += row_slice;
138 row_slice += row_slice;
139 row_slice += row_slice;
140 row_slice += w2;
141 row_slice += row_slice;
142 row_slice += row_slice;
143 row_slice += row_slice;
144 row_slice += row_slice;
145 row_slice += w3;
146 auto sum_delta = scalar_sum * FF(1ULL << 16) + row_slice;
147 const auto check_sum = scalar_sum_new - sum_delta;
148 std::get<8>(accumulator) += precompute_select * check_sum * scaled_transition_is_zero;
149
171 // We combine checks 0, 1 into a single relation
172 // q_transition * (round - 7) + (-q_transition + 1) * (round_shift - round - 1)
173 // => q_transition * (round - 7 - round_shift + round + 1) + (round_shift - round - 1)
174 // => q_transition * (2 * round - round_shift - 6) + (round_shift - round - 1)
175 const auto round_check = round_shift - round - 1;
176 std::get<9>(accumulator) += precompute_select * scaled_transition * ((round - round_check - 7) + round_check);
177 std::get<10>(accumulator) += precompute_select * scaled_transition * round_shift;
178
186 std::get<11>(accumulator) += precompute_select * scalar_sum_new * scaled_transition;
187 // (2, 3 combined): q_transition * (pc - pc_shift - 1) + (-q_transition + 1) * (pc_shift - pc)
188 // => q_transition * (-2 * (pc_shift - pc) - 1) + (pc_shift - pc)
189 const auto pc_delta = pc_shift - pc;
190 std::get<12>(accumulator) +=
191 precompute_select * (scaled_transition * ((-pc_delta - pc_delta - 1)) + pc_delta * scaling_factor);
192
202 std::get<13>(accumulator) += precompute_select * (precompute_skew * (precompute_skew - 7)) * scaling_factor;
203
204 const auto precompute_select_zero = (-precompute_select + 1) * scaling_factor;
205 std::get<14>(accumulator) += precompute_select_zero * (w0 + 15);
206 std::get<15>(accumulator) += precompute_select_zero * (w1 + 15);
207 std::get<16>(accumulator) += precompute_select_zero * (w2 + 15);
208 std::get<17>(accumulator) += precompute_select_zero * (w3 + 15);
209
210 std::get<18>(accumulator) += precompute_select_zero * round;
211 std::get<19>(accumulator) += precompute_select_zero * pc;
212
213 // TODO(@zac-williamson #2226)
214 // if precompute_select = 0, validate pc, round, slice values are all zero
215 // If we do this we can reduce the degree of the set equivalence relations
216 // (currently when checking pc/round/wnaf tuples from WNAF columns match those from MSM columns,
217 // we conditionally include tuples depending on if precompute_select = 1 (for WNAF columns) or if q_add1/2/3/4 = 1
218 // (for MSM columns).
219 // If we KNOW that the wnaf tuple values are 0 when precompute_select = 0, we can remove the conditional checks in
220 // the set equivalence relation
221}
222} // namespace bb
static void accumulate(ContainerOverSubrelations &accumulator, const AllEntities &in, const Parameters &, const FF &scaling_factor)
ECCVMWnafRelationImpl evaluates relations that convert scalar multipliers into 4-bit WNAF slices.
Entry point for Barretenberg command-line interface.
typename Flavor::FF FF
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13