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: 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
43template <typename FF_> class ArithmeticRelationImpl {
44 public:
45 using FF = FF_;
46
47 static constexpr std::array<size_t, 2> SUBRELATION_PARTIAL_LENGTHS{
48 6, // primary arithmetic sub-relation
49 5 // secondary arithmetic sub-relation
50 };
51
56 template <typename AllEntities> inline static bool skip(const AllEntities& in) { return in.q_arith.is_zero(); }
57
64 template <typename ContainerOverSubrelations, typename AllEntities, typename Parameters>
65 inline static void accumulate(ContainerOverSubrelations& evals,
66 const AllEntities& in,
67 BB_UNUSED const Parameters& params,
68 const FF& scaling_factor)
69 {
71 using CoefficientAccumulator = typename Accumulator::CoefficientAccumulator;
72
73 auto w_l_m = CoefficientAccumulator(in.w_l);
74 auto w_4_m = CoefficientAccumulator(in.w_4);
75 auto q_arith_m = CoefficientAccumulator(in.q_arith);
76 auto q_m_m = CoefficientAccumulator(in.q_m);
77
78 auto q_arith_sub_1 = q_arith_m - FF(1);
79 auto scaled_q_arith = q_arith_m * scaling_factor;
80 // Subrelation 1
81 {
83
84 auto w_4_shift_m = CoefficientAccumulator(in.w_4_shift);
85 auto w_r_m = CoefficientAccumulator(in.w_r);
86 auto w_o_m = CoefficientAccumulator(in.w_o);
87 auto q_l_m = CoefficientAccumulator(in.q_l);
88 auto q_r_m = CoefficientAccumulator(in.q_r);
89 auto q_o_m = CoefficientAccumulator(in.q_o);
90 auto q_4_m = CoefficientAccumulator(in.q_4);
91 auto q_c_m = CoefficientAccumulator(in.q_c);
92
93 static const FF neg_half = FF(-2).invert();
94
95 auto tmp0 = Accumulator(w_r_m * w_l_m * neg_half) * Accumulator((q_arith_m - 3) * q_m_m);
96 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;
97 tmp1 += q_arith_sub_1 * w_4_shift_m;
98
99 std::get<0>(evals) += (tmp0 + Accumulator(tmp1)) * Accumulator(scaled_q_arith);
100 }
101 // Subrelation 2
102 {
104
105 auto w_l_shift_m = CoefficientAccumulator(in.w_l_shift);
106
107 auto tmp_0 = w_l_m + w_4_m - w_l_shift_m + q_m_m;
108 auto tmp_1 = tmp_0 * (q_arith_m - FF(2));
109 auto tmp_2 = q_arith_sub_1 * scaled_q_arith;
110 std::get<1>(evals) += ShortAccumulator(tmp_1) * ShortAccumulator(tmp_2);
111 };
112 };
113};
114
116} // namespace bb
Expression for the Ultra (width-4) Arithmetic gate.
static void accumulate(ContainerOverSubrelations &evals, const AllEntities &in, BB_UNUSED const Parameters &params, const FF &scaling_factor)
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