Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
translator_delta_range_constraint_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 TranslatorDeltaRangeConstraintRelationImpl<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 [&]() {
41 using View = typename Accumulator::View;
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 = lagrange_real_last + lagrange_ordered_masking + minus_one;
59
60 // Compute wire differences
61 auto delta_1 = ordered_range_constraints_0_shift - ordered_range_constraints_0;
62 auto delta_2 = ordered_range_constraints_1_shift - ordered_range_constraints_1;
63 auto delta_3 = ordered_range_constraints_2_shift - ordered_range_constraints_2;
64 auto delta_4 = ordered_range_constraints_3_shift - ordered_range_constraints_3;
65 auto delta_5 = ordered_range_constraints_4_shift - ordered_range_constraints_4;
66
67 // Contribution (1) (contributions 1-5 ensure that the sequential values have a difference of {0,1,2,3})
68 auto tmp_1 = delta_1;
69 tmp_1 *= (delta_1 + minus_one);
70 tmp_1 *= (delta_1 + minus_two);
71 tmp_1 *= (delta_1 + minus_three);
72 tmp_1 *= not_last_or_masking;
73 tmp_1 *= scaling_factor;
74 std::get<0>(accumulators) += tmp_1;
75
76 // Contribution (2)
77 auto tmp_2 = delta_2;
78 tmp_2 *= (delta_2 + minus_one);
79 tmp_2 *= (delta_2 + minus_two);
80 tmp_2 *= (delta_2 + minus_three);
81 tmp_2 *= not_last_or_masking;
82 tmp_2 *= scaling_factor;
83
84 std::get<1>(accumulators) += tmp_2;
85
86 // Contribution (3)
87 auto tmp_3 = delta_3;
88 tmp_3 *= (delta_3 + minus_one);
89 tmp_3 *= (delta_3 + minus_two);
90 tmp_3 *= (delta_3 + minus_three);
91 tmp_3 *= not_last_or_masking;
92 tmp_3 *= scaling_factor;
93 std::get<2>(accumulators) += tmp_3;
94
95 // Contribution (4)
96 auto tmp_4 = delta_4;
97 tmp_4 *= (delta_4 + minus_one);
98 tmp_4 *= (delta_4 + minus_two);
99 tmp_4 *= (delta_4 + minus_three);
100 tmp_4 *= not_last_or_masking;
101 tmp_4 *= scaling_factor;
102 std::get<3>(accumulators) += tmp_4;
103
104 // Contribution (5)
105 auto tmp_5 = delta_5;
106 tmp_5 *= (delta_5 + minus_one);
107 tmp_5 *= (delta_5 + minus_two);
108 tmp_5 *= (delta_5 + minus_three);
109 tmp_5 *= not_last_or_masking;
110 tmp_5 *= scaling_factor;
111 std::get<4>(accumulators) += tmp_5;
112 }();
113
114 [&]() {
116 using View = typename Accumulator::View;
117 auto ordered_range_constraints_0 = View(in.ordered_range_constraints_0);
118 auto ordered_range_constraints_1 = View(in.ordered_range_constraints_1);
119 auto ordered_range_constraints_2 = View(in.ordered_range_constraints_2);
120 auto ordered_range_constraints_3 = View(in.ordered_range_constraints_3);
121 auto ordered_range_constraints_4 = View(in.ordered_range_constraints_4);
122 const auto lagrange_real_last = View(in.lagrange_real_last);
123
124 // Contribution (6) (Contributions 6-10 ensure that the last value is the designated maximum value. We don't
125 // need to constrain the first value to be 0, because the shift mechanic does this for us)
126 std::get<5>(accumulators) +=
127 lagrange_real_last * (ordered_range_constraints_0 + maximum_sort_value) * scaling_factor;
128 // Contribution (7)
129 std::get<6>(accumulators) +=
130 lagrange_real_last * (ordered_range_constraints_1 + maximum_sort_value) * scaling_factor;
131 // Contribution (8)
132 std::get<7>(accumulators) +=
133 lagrange_real_last * (ordered_range_constraints_2 + maximum_sort_value) * scaling_factor;
134 // Contribution (9)
135 std::get<8>(accumulators) +=
136 lagrange_real_last * (ordered_range_constraints_3 + maximum_sort_value) * scaling_factor;
137 // Contribution (10)
138 std::get<9>(accumulators) +=
139 lagrange_real_last * (ordered_range_constraints_4 + maximum_sort_value) * scaling_factor;
140 }();
141};
142} // 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
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13