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 template <typename AllEntities> inline static bool skip(const AllEntities& in)
29 {
30 return in.q_poseidon2_internal.is_zero();
31 }
32
52 template <typename ContainerOverSubrelations, typename AllEntities, typename Parameters>
53 void static accumulate(ContainerOverSubrelations& evals,
54 const AllEntities& in,
55 const Parameters&,
56 const FF& scaling_factor)
57 {
59 using CoefficientAccumulator = typename Accumulator::CoefficientAccumulator;
60
61 auto w_l_m = CoefficientAccumulator(in.w_l);
62 auto w_l_shift_m = CoefficientAccumulator(in.w_l_shift);
63 auto w_r_shift_m = CoefficientAccumulator(in.w_r_shift);
64 auto w_o_shift_m = CoefficientAccumulator(in.w_o_shift);
65 auto w_4_shift_m = CoefficientAccumulator(in.w_4_shift);
66 auto q_l_m = CoefficientAccumulator(in.q_l);
67 auto q_poseidon2_internal_m = CoefficientAccumulator(in.q_poseidon2_internal);
68
69 // add round constants
70 auto s1 = Accumulator(w_l_m + q_l_m);
71
72 // apply s-box round
73 auto u1 = s1.sqr();
74 u1 = u1.sqr();
75 u1 *= s1;
76 auto u2_m = CoefficientAccumulator(in.w_r);
77 auto u3_m = CoefficientAccumulator(in.w_o);
78 auto u4_m = CoefficientAccumulator(in.w_4);
79
80 auto q_pos_by_scaling_m = (q_poseidon2_internal_m * scaling_factor);
81 auto q_pos_by_scaling = Accumulator(q_pos_by_scaling_m);
82 // matrix mul with v = M_I * u 4 muls and 7 additions
83 auto partial_sum = u2_m + u3_m + u4_m;
84 auto scaled_u1 = u1 * q_pos_by_scaling;
85
86 static const auto diagonal_term = FF(1) + crypto::Poseidon2Bn254ScalarFieldParams::internal_matrix_diagonal[0];
87 auto barycentric_term = scaled_u1 * (diagonal_term);
88 auto monomial_term = partial_sum;
89 monomial_term -= w_l_shift_m;
90 barycentric_term += Accumulator(monomial_term * q_pos_by_scaling_m);
91 std::get<0>(evals) += barycentric_term;
92
94 v2_m += partial_sum;
95 v2_m -= w_r_shift_m;
96 barycentric_term = Accumulator(v2_m * q_pos_by_scaling_m);
97 barycentric_term += scaled_u1;
98 std::get<1>(evals) += barycentric_term;
99
101 v3_m += partial_sum;
102 v3_m -= w_o_shift_m;
103 barycentric_term = Accumulator(v3_m * q_pos_by_scaling_m);
104 barycentric_term += scaled_u1;
105 std::get<2>(evals) += barycentric_term;
106
108 v4_m += partial_sum;
109 v4_m -= w_4_shift_m;
110
111 barycentric_term = Accumulator(v4_m * q_pos_by_scaling_m);
112 barycentric_term += scaled_u1;
113 std::get<3>(evals) += barycentric_term;
114 };
115}; // namespace bb
116
118} // 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