Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
poseidon2_internal_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#include "relation_types.hpp"
10
11namespace bb {
12
65template <typename FF_> class Poseidon2InternalRelationImpl {
66 public:
67 using FF = FF_;
68
69 static constexpr std::array<size_t, 4> SUBRELATION_PARTIAL_LENGTHS{
70 7, // internal poseidon2 round sub-relation for first value
71 7, // internal poseidon2 round sub-relation for second value
72 7, // internal poseidon2 round sub-relation for third value
73 7, // internal poseidon2 round sub-relation for fourth value
74 };
75
80 static constexpr fr D1_plus_1 = fr{ 1 } + D1;
85 template <typename AllEntities> inline static bool skip(const AllEntities& in)
86 {
87 return (in.q_poseidon2_internal.is_zero());
88 }
89
99 template <typename ContainerOverSubrelations, typename AllEntities, typename Parameters>
100 void static accumulate(ContainerOverSubrelations& evals,
101 const AllEntities& in,
102 const Parameters&,
103 const FF& scaling_factor)
104 {
105 // Univariates of degree 6 represented in Lagrange basis
107 // Low-degree univariates represented in monomial basis
108 using CoefficientAccumulator = typename Accumulator::CoefficientAccumulator;
109
110 // Current state
111 const auto w_1 = CoefficientAccumulator(in.w_l);
112 const auto w_2 = CoefficientAccumulator(in.w_r);
113 const auto w_3 = CoefficientAccumulator(in.w_o);
114 const auto w_4 = CoefficientAccumulator(in.w_4);
115 // Expected state, contained in the next row
116 const auto w_1_shift = CoefficientAccumulator(in.w_l_shift);
117 const auto w_2_shift = CoefficientAccumulator(in.w_r_shift);
118 const auto w_3_shift = CoefficientAccumulator(in.w_o_shift);
119 const auto w_4_shift = CoefficientAccumulator(in.w_4_shift);
120 // Poseidon2 internal relation selector
121 const auto q_poseidon2_internal_m = CoefficientAccumulator(in.q_poseidon2_internal);
122 // ĉ₀⁽ⁱ⁾ - the round constant in `i`-th internal round
123 const auto c_0_int = CoefficientAccumulator(in.q_l);
124
125 Accumulator barycentric_term;
126
127 // Add ĉ₀⁽ⁱ⁾ stored in the selector and convert to Lagrange basis
128 auto s1 = Accumulator(w_1 + c_0_int);
129
130 // Apply S-box. Note that the multiplication is performed point-wise
131 auto u1 = s1.sqr();
132 u1 = u1.sqr();
133 u1 *= s1;
134
135 const auto q_pos_by_scaling_m = (q_poseidon2_internal_m * scaling_factor);
136 const auto q_pos_by_scaling = Accumulator(q_pos_by_scaling_m);
137 // Common terms
138 const auto partial_sum = w_2 + w_3 + w_4;
139 const auto scaled_u1 = u1 * q_pos_by_scaling;
140
141 // Row 1:
142 barycentric_term = scaled_u1 * D1_plus_1;
143 auto monomial_term = partial_sum - w_1_shift;
144 barycentric_term += Accumulator(monomial_term * q_pos_by_scaling_m);
145 std::get<0>(evals) += barycentric_term;
146
147 // Row 2:
148 auto v2_m = w_2 * D2 + partial_sum - w_2_shift;
149 barycentric_term = Accumulator(v2_m * q_pos_by_scaling_m);
150 barycentric_term += scaled_u1;
151 std::get<1>(evals) += barycentric_term;
152
153 // Row 3:
154 auto v3_m = w_3 * D3 + partial_sum - w_3_shift;
155 barycentric_term = Accumulator(v3_m * q_pos_by_scaling_m);
156 barycentric_term += scaled_u1;
157 std::get<2>(evals) += barycentric_term;
158
159 // Row 4:
160 auto v4_m = w_4 * D4 + partial_sum - w_4_shift;
161 barycentric_term = Accumulator(v4_m * q_pos_by_scaling_m);
162 barycentric_term += scaled_u1;
163 std::get<3>(evals) += barycentric_term;
164 };
165}; // namespace bb
166
168} // namespace bb
Expression for the Poseidon2 internal round relation, based on I_i in Section 6 of https://eprint....
static bool skip(const AllEntities &in)
Returns true if the contribution from all subrelations for the provided inputs is identically zero.
static constexpr std::array< size_t, 4 > SUBRELATION_PARTIAL_LENGTHS
static void accumulate(ContainerOverSubrelations &evals, const AllEntities &in, const Parameters &, const FF &scaling_factor)
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.
Definition api.hpp:5
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
static constexpr std::array< FF, t > internal_matrix_diagonal