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)
57 {
58 return in[AllEntities::EntityId::q_arith].is_zero();
59 }
60
67 template <typename ContainerOverSubrelations, typename AllEntities, typename Parameters>
68 inline static void accumulate(ContainerOverSubrelations& evals,
69 const AllEntities& in,
70 BB_UNUSED const Parameters& params,
71 const FF& scaling_factor)
72 {
74 using CoefficientAccumulator = typename Accumulator::CoefficientAccumulator;
75
76 auto w_l_m = CoefficientAccumulator(in[AllEntities::EntityId::w_l]);
77 auto w_4_m = CoefficientAccumulator(in[AllEntities::EntityId::w_4]);
78 auto q_arith_m = CoefficientAccumulator(in[AllEntities::EntityId::q_arith]);
79 auto q_m_m = CoefficientAccumulator(in[AllEntities::EntityId::q_m]);
80
81 auto q_arith_sub_1 = q_arith_m - FF(1);
82 auto scaled_q_arith = q_arith_m * scaling_factor;
83 // Subrelation 1
84 {
86
87 auto w_4_shift_m = CoefficientAccumulator(in[AllEntities::EntityId::w_4_shift]);
88 auto w_r_m = CoefficientAccumulator(in[AllEntities::EntityId::w_r]);
89 auto w_o_m = CoefficientAccumulator(in[AllEntities::EntityId::w_o]);
90 auto q_l_m = CoefficientAccumulator(in[AllEntities::EntityId::q_l]);
91 auto q_r_m = CoefficientAccumulator(in[AllEntities::EntityId::q_r]);
92 auto q_o_m = CoefficientAccumulator(in[AllEntities::EntityId::q_o]);
93 auto q_4_m = CoefficientAccumulator(in[AllEntities::EntityId::q_4]);
94 auto q_c_m = CoefficientAccumulator(in[AllEntities::EntityId::q_c]);
95
96 static const FF neg_half = FF(-2).invert();
97
98 auto tmp0 = Accumulator(w_r_m * w_l_m * neg_half) * Accumulator((q_arith_m - 3) * q_m_m);
99 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;
100 tmp1 += q_arith_sub_1 * w_4_shift_m;
101
102 std::get<0>(evals) += (tmp0 + Accumulator(tmp1)) * Accumulator(scaled_q_arith);
103 }
104 // Subrelation 2
105 {
107
108 auto w_l_shift_m = CoefficientAccumulator(in[AllEntities::EntityId::w_l_shift]);
109
110 auto tmp_0 = w_l_m + w_4_m - w_l_shift_m + q_m_m;
111 auto tmp_1 = tmp_0 * (q_arith_m - FF(2));
112 auto tmp_2 = q_arith_sub_1 * scaled_q_arith;
113 std::get<1>(evals) += ShortAccumulator(tmp_1) * ShortAccumulator(tmp_2);
114 };
115 };
116};
117
119} // 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