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
25template <typename FF>
26template <typename ContainerOverSubrelations, typename AllEntities, typename Parameters>
27void TranslatorDeltaRangeConstraintRelationImpl<FF>::accumulate(ContainerOverSubrelations& accumulators,
28 const AllEntities& in,
29 const Parameters& /*unused*/,
30 const FF& scaling_factor)
31{
32 static const FF minus_one = FF(-1);
33 static const FF minus_two = FF(-2);
34 static const FF minus_three = FF(-3);
35 static const size_t micro_limb_bits = 14;
36 static const auto maximum_sort_value = -FF((1 << micro_limb_bits) - 1);
37
38 [&]() {
40 using View = typename Accumulator::View;
41 auto ordered_range_constraints_0 = View(in.ordered_range_constraints_0);
42 auto ordered_range_constraints_1 = View(in.ordered_range_constraints_1);
43 auto ordered_range_constraints_2 = View(in.ordered_range_constraints_2);
44 auto ordered_range_constraints_3 = View(in.ordered_range_constraints_3);
45 auto ordered_range_constraints_4 = View(in.ordered_range_constraints_4);
46 auto ordered_range_constraints_0_shift = View(in.ordered_range_constraints_0_shift);
47 auto ordered_range_constraints_1_shift = View(in.ordered_range_constraints_1_shift);
48 auto ordered_range_constraints_2_shift = View(in.ordered_range_constraints_2_shift);
49 auto ordered_range_constraints_3_shift = View(in.ordered_range_constraints_3_shift);
50 auto ordered_range_constraints_4_shift = View(in.ordered_range_constraints_4_shift);
51
52 // Represents the position of the final non-masked witness index
53 const auto lagrange_real_last = View(in.lagrange_real_last);
54 const auto lagrange_masking = View(in.lagrange_masking);
55
56 // This selector is 0 at the real_last row and in masking rows (where delta checks are skipped),
57 // and -1 at all other rows (where delta checks are enforced). The naming reflects that it is
58 // NOT at the last row or masking region when non-zero.
59 const auto not_last_or_masking = (lagrange_real_last + lagrange_masking + minus_one);
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 // Contribution (1) (contributions 1-5 ensure that the sequential values have a difference of {0,1,2,3})
69 auto tmp_1 = delta_1;
70 tmp_1 *= (delta_1 + minus_one);
71 tmp_1 *= (delta_1 + minus_two);
72 tmp_1 *= (delta_1 + minus_three);
73 tmp_1 *= not_last_or_masking;
74 tmp_1 *= scaling_factor;
75 std::get<0>(accumulators) += tmp_1;
76
77 // Contribution (2)
78 auto tmp_2 = delta_2;
79 tmp_2 *= (delta_2 + minus_one);
80 tmp_2 *= (delta_2 + minus_two);
81 tmp_2 *= (delta_2 + minus_three);
82 tmp_2 *= not_last_or_masking;
83 tmp_2 *= scaling_factor;
84
85 std::get<1>(accumulators) += tmp_2;
86
87 // Contribution (3)
88 auto tmp_3 = delta_3;
89 tmp_3 *= (delta_3 + minus_one);
90 tmp_3 *= (delta_3 + minus_two);
91 tmp_3 *= (delta_3 + minus_three);
92 tmp_3 *= not_last_or_masking;
93 tmp_3 *= scaling_factor;
94 std::get<2>(accumulators) += tmp_3;
95
96 // Contribution (4)
97 auto tmp_4 = delta_4;
98 tmp_4 *= (delta_4 + minus_one);
99 tmp_4 *= (delta_4 + minus_two);
100 tmp_4 *= (delta_4 + minus_three);
101 tmp_4 *= not_last_or_masking;
102 tmp_4 *= scaling_factor;
103 std::get<3>(accumulators) += tmp_4;
104
105 // Contribution (5)
106 auto tmp_5 = delta_5;
107 tmp_5 *= (delta_5 + minus_one);
108 tmp_5 *= (delta_5 + minus_two);
109 tmp_5 *= (delta_5 + minus_three);
110 tmp_5 *= not_last_or_masking;
111 tmp_5 *= scaling_factor;
112 std::get<4>(accumulators) += tmp_5;
113 }();
114
115 [&]() {
117 using View = typename Accumulator::View;
118 auto ordered_range_constraints_0 = View(in.ordered_range_constraints_0);
119 auto ordered_range_constraints_1 = View(in.ordered_range_constraints_1);
120 auto ordered_range_constraints_2 = View(in.ordered_range_constraints_2);
121 auto ordered_range_constraints_3 = View(in.ordered_range_constraints_3);
122 auto ordered_range_constraints_4 = View(in.ordered_range_constraints_4);
123 const auto lagrange_real_last = View(in.lagrange_real_last);
124
125 // Contribution (6) (Contributions 6-10 ensure that the last value is the designated maximum value. We don't
126 // need to constrain the first value to be 0, because the shift mechanic does this for us)
127 std::get<5>(accumulators) +=
128 lagrange_real_last * (ordered_range_constraints_0 + maximum_sort_value) * scaling_factor;
129 // Contribution (7)
130 std::get<6>(accumulators) +=
131 lagrange_real_last * (ordered_range_constraints_1 + maximum_sort_value) * scaling_factor;
132 // Contribution (8)
133 std::get<7>(accumulators) +=
134 lagrange_real_last * (ordered_range_constraints_2 + maximum_sort_value) * scaling_factor;
135 // Contribution (9)
136 std::get<8>(accumulators) +=
137 lagrange_real_last * (ordered_range_constraints_3 + maximum_sort_value) * scaling_factor;
138 // Contribution (10)
139 std::get<9>(accumulators) +=
140 lagrange_real_last * (ordered_range_constraints_4 + maximum_sort_value) * scaling_factor;
141 }();
142};
143} // 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