Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
translator_delta_range_constraint_short_relation_impl.hpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: Planned, auditors: [], commit: }
3// external_1: { status: not started, auditors: [], commit: }
4// external_2: { status: not started, auditors: [], commit: }
5// =====================
6
7#pragma once
9
10namespace bb {
11
26template <typename FF>
27template <typename ContainerOverSubrelations, typename AllEntities, typename Parameters>
28void TranslatorDeltaRangeConstraintShortRelationImpl<FF>::accumulate(ContainerOverSubrelations& accumulators,
29 const AllEntities& in,
30 const Parameters& /*unused*/,
31 const FF& scaling_factor)
32{
33 static const FF minus_one = FF(-1);
34 static const FF minus_two = FF(-2);
35 static const FF minus_three = FF(-3);
36 static const size_t micro_limb_bits = 14;
37 static const auto maximum_sort_value = -FF((1 << micro_limb_bits) - 1);
38
39 [&]() {
42 auto ordered_range_constraints_0 = View(in.ordered_range_constraints_0);
43 auto ordered_range_constraints_1 = View(in.ordered_range_constraints_1);
44 auto ordered_range_constraints_2 = View(in.ordered_range_constraints_2);
45 auto ordered_range_constraints_3 = View(in.ordered_range_constraints_3);
46 auto ordered_range_constraints_4 = View(in.ordered_range_constraints_4);
47 auto ordered_range_constraints_0_shift = View(in.ordered_range_constraints_0_shift);
48 auto ordered_range_constraints_1_shift = View(in.ordered_range_constraints_1_shift);
49 auto ordered_range_constraints_2_shift = View(in.ordered_range_constraints_2_shift);
50 auto ordered_range_constraints_3_shift = View(in.ordered_range_constraints_3_shift);
51 auto ordered_range_constraints_4_shift = View(in.ordered_range_constraints_4_shift);
52
53 const auto lagrange_real_last = View(in.lagrange_real_last);
54 const auto lagrange_ordered_masking = View(in.lagrange_ordered_masking);
55
56 // 0 at real_last and ordered masking rows (where delta checks are skipped), nonzero elsewhere.
57 // lagrange_real_last and lagrange_ordered_masking have disjoint support, so the sum is 0/1.
58 const auto not_last_or_masking_scaled =
59 Accumulator((lagrange_real_last + lagrange_ordered_masking + minus_one) * scaling_factor);
60
61 // Compute wire differences
62 auto delta_1 = ordered_range_constraints_0_shift - ordered_range_constraints_0;
63 auto delta_2 = ordered_range_constraints_1_shift - ordered_range_constraints_1;
64 auto delta_3 = ordered_range_constraints_2_shift - ordered_range_constraints_2;
65 auto delta_4 = ordered_range_constraints_3_shift - ordered_range_constraints_3;
66 auto delta_5 = ordered_range_constraints_4_shift - ordered_range_constraints_4;
67
68 auto accumulate_delta_check = [&](auto& accumulator, const auto& delta) {
69 auto tmp =
70 Accumulator(delta * (delta + minus_one)) * Accumulator((delta + minus_two) * (delta + minus_three));
71 tmp *= not_last_or_masking_scaled;
72 accumulator += tmp;
73 };
74
75 // The ordered_range_constraints wires are sorted ascending, so each is constant over long runs. On an edge
76 // where ordered_i is locally constant, delta_i is the zero edge polynomial and P(delta_i) =
77 // delta(delta-1)(delta-2) (delta-3) vanishes identically, so this subrelation adds nothing. Skipping the
78 // degree-4 product there checks the actual delta value (not a selector), so it is sound in every sumcheck
79 // round. Test zero-ness on the raw length-2 edge entities, since the coefficient-basis view has no is_zero().
80 // Contributions (1-5) ensure that sequential values have a difference of {0,1,2,3}.
81 if (!(in.ordered_range_constraints_0_shift - in.ordered_range_constraints_0).is_zero()) {
82 accumulate_delta_check(std::get<0>(accumulators), delta_1);
83 }
84 if (!(in.ordered_range_constraints_1_shift - in.ordered_range_constraints_1).is_zero()) {
85 accumulate_delta_check(std::get<1>(accumulators), delta_2);
86 }
87 if (!(in.ordered_range_constraints_2_shift - in.ordered_range_constraints_2).is_zero()) {
88 accumulate_delta_check(std::get<2>(accumulators), delta_3);
89 }
90 if (!(in.ordered_range_constraints_3_shift - in.ordered_range_constraints_3).is_zero()) {
91 accumulate_delta_check(std::get<3>(accumulators), delta_4);
92 }
93 if (!(in.ordered_range_constraints_4_shift - in.ordered_range_constraints_4).is_zero()) {
94 accumulate_delta_check(std::get<4>(accumulators), delta_5);
95 }
96 }();
97
98 [&]() {
101 auto ordered_range_constraints_0 = View(in.ordered_range_constraints_0);
102 auto ordered_range_constraints_1 = View(in.ordered_range_constraints_1);
103 auto ordered_range_constraints_2 = View(in.ordered_range_constraints_2);
104 auto ordered_range_constraints_3 = View(in.ordered_range_constraints_3);
105 auto ordered_range_constraints_4 = View(in.ordered_range_constraints_4);
106 // Every max-value subrelation carries a lagrange_real_last factor, so on any edge where lagrange_real_last is
107 // identically zero all five contributions are the zero polynomial. lagrange_real_last is nonzero at a single
108 // index, so this skips the degree-2 products on essentially every edge.
109 if (!in.lagrange_real_last.is_zero()) {
110 const auto lagrange_real_last = View(in.lagrange_real_last);
111 const auto lagrange_real_last_scaled = lagrange_real_last * scaling_factor;
112
113 // Contribution (6) (Contributions 6-10 ensure that the last value is the designated maximum value. We don't
114 // need to constrain the first value to be 0, because the shift mechanic does this for us)
115 std::get<5>(accumulators) +=
116 Accumulator(lagrange_real_last_scaled * (ordered_range_constraints_0 + maximum_sort_value));
117 // Contribution (7)
118 std::get<6>(accumulators) +=
119 Accumulator(lagrange_real_last_scaled * (ordered_range_constraints_1 + maximum_sort_value));
120 // Contribution (8)
121 std::get<7>(accumulators) +=
122 Accumulator(lagrange_real_last_scaled * (ordered_range_constraints_2 + maximum_sort_value));
123 // Contribution (9)
124 std::get<8>(accumulators) +=
125 Accumulator(lagrange_real_last_scaled * (ordered_range_constraints_3 + maximum_sort_value));
126 // Contribution (10)
127 std::get<9>(accumulators) +=
128 Accumulator(lagrange_real_last_scaled * (ordered_range_constraints_4 + maximum_sort_value));
129 }
130 }();
131};
132} // namespace bb
bb::field< bb::Bn254FrParams > FF
Definition field.cpp:24
static void accumulate(ContainerOverSubrelations &accumulators, const AllEntities &in, const Parameters &, const FF &scaling_factor)
Expression for the generalized permutation sort relation.
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
typename Accumulator::CoefficientAccumulator TranslatorShortMonomialView
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13