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: 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#include "relation_types.hpp"
10
11namespace bb {
12
13template <typename FF_> class Poseidon2InternalRelationImpl {
14 public:
15 using FF = FF_;
16
17 static constexpr std::array<size_t, 4> SUBRELATION_PARTIAL_LENGTHS{
18 7, // internal poseidon2 round sub-relation for first value
19 7, // internal poseidon2 round sub-relation for second value
20 7, // internal poseidon2 round sub-relation for third value
21 7, // internal poseidon2 round sub-relation for fourth value
22 };
23
28 static constexpr fr D1_plus_1 = fr{ 1 } + D1;
33 template <typename AllEntities> inline static bool skip(const AllEntities& in)
34 {
35 return (in.q_poseidon2_internal.is_zero());
36 }
37
97 template <typename ContainerOverSubrelations, typename AllEntities, typename Parameters>
98 void static accumulate(ContainerOverSubrelations& evals,
99 const AllEntities& in,
100 const Parameters&,
101 const FF& scaling_factor)
102 {
103 // Univariates of degree 6 represented in Lagrange basis
105 // Low-degree univariates represented in monomial basis
106 using CoefficientAccumulator = typename Accumulator::CoefficientAccumulator;
107
108 // Current state
109 const auto w_1 = CoefficientAccumulator(in.w_l);
110 const auto w_2 = CoefficientAccumulator(in.w_r);
111 const auto w_3 = CoefficientAccumulator(in.w_o);
112 const auto w_4 = CoefficientAccumulator(in.w_4);
113 // Expected state, contained in the next row
114 const auto w_1_shift = CoefficientAccumulator(in.w_l_shift);
115 const auto w_2_shift = CoefficientAccumulator(in.w_r_shift);
116 const auto w_3_shift = CoefficientAccumulator(in.w_o_shift);
117 const auto w_4_shift = CoefficientAccumulator(in.w_4_shift);
118 // Poseidon2 internal relation selector
119 const auto q_poseidon2_internal_m = CoefficientAccumulator(in.q_poseidon2_internal);
120 // ĉ₀⁽ⁱ⁾ - the round constant in `i`-th internal round
121 const auto c_0_int = CoefficientAccumulator(in.q_l);
122
123 Accumulator barycentric_term;
124
125 // Add ĉ₀⁽ⁱ⁾ stored in the selector and convert to Lagrange basis
126 auto s1 = Accumulator(w_1 + c_0_int);
127
128 // Apply S-box. Note that the multiplication is performed point-wise
129 auto u1 = s1.sqr();
130 u1 = u1.sqr();
131 u1 *= s1;
132
133 const auto q_pos_by_scaling_m = (q_poseidon2_internal_m * scaling_factor);
134 const auto q_pos_by_scaling = Accumulator(q_pos_by_scaling_m);
135 // Common terms
136 const auto partial_sum = w_2 + w_3 + w_4;
137 const auto scaled_u1 = u1 * q_pos_by_scaling;
138
139 // Row 1:
140 barycentric_term = scaled_u1 * D1_plus_1;
141 auto monomial_term = partial_sum - w_1_shift;
142 barycentric_term += Accumulator(monomial_term * q_pos_by_scaling_m);
143 std::get<0>(evals) += barycentric_term;
144
145 // Row 2:
146 auto v2_m = w_2 * D2 + partial_sum - w_2_shift;
147 barycentric_term = Accumulator(v2_m * q_pos_by_scaling_m);
148 barycentric_term += scaled_u1;
149 std::get<1>(evals) += barycentric_term;
150
151 // Row 3:
152 auto v3_m = w_3 * D3 + partial_sum - w_3_shift;
153 barycentric_term = Accumulator(v3_m * q_pos_by_scaling_m);
154 barycentric_term += scaled_u1;
155 std::get<2>(evals) += barycentric_term;
156
157 // Row 4:
158 auto v4_m = w_4 * D4 + partial_sum - w_4_shift;
159 barycentric_term = Accumulator(v4_m * q_pos_by_scaling_m);
160 barycentric_term += scaled_u1;
161 std::get<3>(evals) += barycentric_term;
162 };
163}; // namespace bb
164
166} // namespace bb
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)
Expression for the Poseidon2 internal round relation, based on I_i in Section 6 of https://eprint....
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
static constexpr std::array< FF, t > internal_matrix_diagonal