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: 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
7#pragma once
9
10namespace bb {
11
12template <typename FF_> class DeltaRangeConstraintRelationImpl {
13 public:
14 using FF = FF_;
15
16 static constexpr std::array<size_t, 4> SUBRELATION_PARTIAL_LENGTHS{
17 6, // range constrain sub-relation 1
18 6, // range constrain sub-relation 2
19 6, // range constrain sub-relation 3
20 6 // range constrain sub-relation 4
21 };
22
27 template <typename AllEntities> inline static bool skip(const AllEntities& in)
28 {
29 return in.q_delta_range.is_zero();
30 }
31
47 template <typename ContainerOverSubrelations, typename AllEntities, typename Parameters>
48 inline static void accumulate(ContainerOverSubrelations& accumulators,
49 const AllEntities& in,
50 const Parameters&,
51 const FF& scaling_factor)
52 {
54 using CoefficientAccumulator = typename Accumulator::CoefficientAccumulator;
55
56 auto w_1 = CoefficientAccumulator(in.w_l);
57 auto w_2 = CoefficientAccumulator(in.w_r);
58 auto w_3 = CoefficientAccumulator(in.w_o);
59 auto w_4 = CoefficientAccumulator(in.w_4);
60 auto w_1_shift = CoefficientAccumulator(in.w_l_shift);
61 auto q_delta_range_m = CoefficientAccumulator(in.q_delta_range);
62
63 auto q_delta_range_scaled_m = q_delta_range_m * scaling_factor;
64 Accumulator q_delta_range_scaled(q_delta_range_scaled_m);
65
66 // Compute wire differences
67 auto delta_1 = Accumulator(w_2 - w_1);
68 auto delta_2 = Accumulator(w_3 - w_2);
69 auto delta_3 = Accumulator(w_4 - w_3);
70 auto delta_4 = Accumulator(w_1_shift - w_4);
71
72 // Contribution (1)
73 auto tmp_1 = (delta_1 - FF(3)) * delta_1;
74 tmp_1 *= (tmp_1 + FF(2));
75 tmp_1 *= q_delta_range_scaled;
76 std::get<0>(accumulators) += tmp_1;
77
78 // Contribution (2)
79 auto tmp_2 = (delta_2 - FF(3)) * delta_2;
80 tmp_2 *= (tmp_2 + FF(2));
81 tmp_2 *= q_delta_range_scaled;
82 std::get<1>(accumulators) += tmp_2;
83
84 // Contribution (3)
85 auto tmp_3 = (delta_3 - FF(3)) * delta_3;
86 tmp_3 *= (tmp_3 + FF(2));
87 tmp_3 *= q_delta_range_scaled;
88 std::get<2>(accumulators) += tmp_3;
89
90 // Contribution (4)
91 auto tmp_4 = (delta_4 - FF(3)) * delta_4;
92 tmp_4 *= (tmp_4 + FF(2));
93 tmp_4 *= q_delta_range_scaled;
94 std::get<3>(accumulators) += tmp_4;
95 };
96};
97
99
100} // namespace bb
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.
static void accumulate(ContainerOverSubrelations &accumulators, const AllEntities &in, const Parameters &, const FF &scaling_factor)
Expression for the generalized permutation sort gate.
A wrapper for Relations to expose methods used by the Sumcheck prover or verifier to add the contribu...
Entry point for Barretenberg command-line interface.
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13