Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
delta_range_constraint_relation.hpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: Complete, auditors: [Luke, Raju], 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
20template <typename FF_> class DeltaRangeConstraintRelationImpl {
21 public:
22 using FF = FF_;
23
24 static constexpr std::array<size_t, 4> SUBRELATION_PARTIAL_LENGTHS{
25 6, // sub-relation 1: D_0 = w_2 - w_1
26 6, // sub-relation 2: D_1 = w_3 - w_2
27 6, // sub-relation 3: D_2 = w_4 - w_3
28 6 // sub-relation 4: D_3 = w_1_shifst - w_4
29 };
30
35 template <typename AllEntities> inline static bool skip(const AllEntities& in)
36 {
37 return in.q_delta_range.is_zero();
38 }
39
55 template <typename ContainerOverSubrelations, typename AllEntities, typename Parameters>
56 inline static void accumulate(ContainerOverSubrelations& accumulators,
57 const AllEntities& in,
58 BB_UNUSED const Parameters&,
59 const FF& scaling_factor)
60 {
62 using CoefficientAccumulator = typename Accumulator::CoefficientAccumulator;
63
64 auto w_1 = CoefficientAccumulator(in.w_l);
65 auto w_2 = CoefficientAccumulator(in.w_r);
66 auto w_3 = CoefficientAccumulator(in.w_o);
67 auto w_4 = CoefficientAccumulator(in.w_4);
68 auto w_1_shift = CoefficientAccumulator(in.w_l_shift);
69 auto q_delta_range_m = CoefficientAccumulator(in.q_delta_range);
70
71 auto q_delta_range_scaled_m = q_delta_range_m * scaling_factor;
72 Accumulator q_delta_range_scaled(q_delta_range_scaled_m);
73
74 // Compute wire differences
75 auto delta_1 = Accumulator(w_2 - w_1);
76 auto delta_2 = Accumulator(w_3 - w_2);
77 auto delta_3 = Accumulator(w_4 - w_3);
78 auto delta_4 = Accumulator(w_1_shift - w_4);
79
80 // Polynomial trick: if T = (D - 3) * D, then T * (T + 2) == D * (D - 1) * (D - 2) * (D - 3)
81
82 // Contribution (1)
83 auto tmp_1 = (delta_1 - FF(3)) * delta_1;
84 tmp_1 *= (tmp_1 + FF(2));
85 tmp_1 *= q_delta_range_scaled;
86 std::get<0>(accumulators) += tmp_1;
87
88 // Contribution (2)
89 auto tmp_2 = (delta_2 - FF(3)) * delta_2;
90 tmp_2 *= (tmp_2 + FF(2));
91 tmp_2 *= q_delta_range_scaled;
92 std::get<1>(accumulators) += tmp_2;
93
94 // Contribution (3)
95 auto tmp_3 = (delta_3 - FF(3)) * delta_3;
96 tmp_3 *= (tmp_3 + FF(2));
97 tmp_3 *= q_delta_range_scaled;
98 std::get<2>(accumulators) += tmp_3;
99
100 // Contribution (4)
101 auto tmp_4 = (delta_4 - FF(3)) * delta_4;
102 tmp_4 *= (tmp_4 + FF(2));
103 tmp_4 *= q_delta_range_scaled;
104 std::get<3>(accumulators) += tmp_4;
105 };
106};
107
109
110} // namespace bb
Delta Range Constraint Relation for efficient range checks.
static void accumulate(ContainerOverSubrelations &accumulators, const AllEntities &in, BB_UNUSED const Parameters &, const FF &scaling_factor)
Expression for the generalized permutation sort gate.
static constexpr std::array< size_t, 4 > SUBRELATION_PARTIAL_LENGTHS
static bool skip(const AllEntities &in)
Returns true if the contribution from all subrelations for the provided inputs is identically zero.
A wrapper for Relations to expose methods used by the Sumcheck prover or verifier to add the contribu...
#define BB_UNUSED
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13