Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
ultra_arithmetic_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 ArithmeticRelationImpl {
13 public:
14 using FF = FF_;
15
16 static constexpr std::array<size_t, 2> SUBRELATION_PARTIAL_LENGTHS{
17 6, // primary arithmetic sub-relation
18 5 // secondary arithmetic sub-relation
19 };
20
25 template <typename AllEntities> inline static bool skip(const AllEntities& in) { return in.q_arith.is_zero(); }
26
63 template <typename ContainerOverSubrelations, typename AllEntities, typename Parameters>
64 inline static void accumulate(ContainerOverSubrelations& evals,
65 const AllEntities& in,
66 BB_UNUSED const Parameters& params,
67 const FF& scaling_factor)
68 {
70 using CoefficientAccumulator = typename Accumulator::CoefficientAccumulator;
71
72 auto w_l_m = CoefficientAccumulator(in.w_l);
73 auto w_4_m = CoefficientAccumulator(in.w_4);
74 auto q_arith_m = CoefficientAccumulator(in.q_arith);
75 auto q_m_m = CoefficientAccumulator(in.q_m);
76
77 auto q_arith_sub_1 = q_arith_m - FF(1);
78 auto scaled_q_arith = q_arith_m * scaling_factor;
79 // Subrelation 1
80 {
82
83 auto w_4_shift_m = CoefficientAccumulator(in.w_4_shift);
84 auto w_r_m = CoefficientAccumulator(in.w_r);
85 auto w_o_m = CoefficientAccumulator(in.w_o);
86 auto q_l_m = CoefficientAccumulator(in.q_l);
87 auto q_r_m = CoefficientAccumulator(in.q_r);
88 auto q_o_m = CoefficientAccumulator(in.q_o);
89 auto q_4_m = CoefficientAccumulator(in.q_4);
90 auto q_c_m = CoefficientAccumulator(in.q_c);
91
92 static const FF neg_half = FF(-2).invert();
93
94 auto tmp0 = Accumulator(w_r_m * w_l_m * neg_half) * Accumulator((q_arith_m - 3) * q_m_m);
95 auto tmp1 = (q_l_m * w_l_m) + (q_r_m * w_r_m) + (q_o_m * w_o_m) + (q_4_m * w_4_m) + q_c_m;
96 tmp1 += q_arith_sub_1 * w_4_shift_m;
97
98 std::get<0>(evals) += (tmp0 + Accumulator(tmp1)) * Accumulator(scaled_q_arith);
99 }
100 // Subrelation 2
101 {
103
104 auto w_l_shift_m = CoefficientAccumulator(in.w_l_shift);
105
106 auto tmp_0 = w_l_m + w_4_m - w_l_shift_m + q_m_m;
107 auto tmp_1 = tmp_0 * (q_arith_m - FF(2));
108 auto tmp_2 = q_arith_sub_1 * scaled_q_arith;
109 std::get<1>(evals) += ShortAccumulator(tmp_1) * ShortAccumulator(tmp_2);
110 };
111 };
112};
113
115} // namespace bb
static void accumulate(ContainerOverSubrelations &evals, const AllEntities &in, BB_UNUSED const Parameters &params, const FF &scaling_factor)
Expression for the Ultra (width-4) Arithmetic gate.
static constexpr std::array< size_t, 2 > 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