Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
poseidon2_transition_entry_relation.hpp
Go to the documentation of this file.
1#pragma once
4#include "relation_types.hpp"
5
6namespace bb {
7
48template <typename FF_> class Poseidon2TransitionEntryRelationImpl {
49 public:
50 using FF = FF_;
52
53 static constexpr std::array<size_t, 3> SUBRELATION_PARTIAL_LENGTHS{
54 7, // A_0: w_r_shift check (state[0] at round 1)
55 7, // A_1: w_o_shift check (state[0] at round 2)
56 7, // A_2: w_4_shift check (state[0] at round 3)
57 };
58
59 static constexpr fr D1 = QuadParams::D1;
60
61 // Linear round-propagation vectors shared with the closed-form interior relation:
62 // A_one[j] = D_{j+1} + 2 — wire coefs in A_1 (state[0] at round 2)
63 // A2_one[j] = D_{j+1}^2 + D_{j+1} + Σ + 4 — wire coefs in A_2 (state[0] at round 3)
64 // sum_A_one = Σ + 6 — u_0 coefficient in A_2
65 static constexpr auto& A_one = QuadParams::A_one;
66 static constexpr auto& A2_one = QuadParams::A2_one;
68
69 template <typename AllEntities> inline static bool skip(const AllEntities& in)
70 {
71 return in.q_poseidon2_transition_entry.is_zero();
72 }
73
74 template <typename ContainerOverSubrelations, typename AllEntities, typename Parameters>
75 void static accumulate(ContainerOverSubrelations& evals,
76 const AllEntities& in,
77 const Parameters& /*params*/,
78 const FF& scaling_factor)
79 {
81 using CoeffAcc = typename Accumulator::CoefficientAccumulator;
82
83 const auto w_l = CoeffAcc(in.w_l);
84 const auto w_r = CoeffAcc(in.w_r);
85 const auto w_o = CoeffAcc(in.w_o);
86 const auto w_4 = CoeffAcc(in.w_4);
87
88 const auto w_r_shift = CoeffAcc(in.w_r_shift);
89 const auto w_o_shift = CoeffAcc(in.w_o_shift);
90 const auto w_4_shift = CoeffAcc(in.w_4_shift);
91
92 const auto q_l = CoeffAcc(in.q_l);
93 const auto q_r = CoeffAcc(in.q_r);
94 const auto q_o = CoeffAcc(in.q_o);
95 const auto q_sel = CoeffAcc(in.q_poseidon2_transition_entry);
96
97 auto pow5 = [](const Accumulator& x) -> Accumulator {
98 auto sq = x.sqr();
99 auto quart = sq.sqr();
100 return quart * x;
101 };
102
103 // u_0 = (w_l + q_l)^5
104 auto u_0 = pow5(Accumulator(w_l + q_l));
105 // u_1 = (w_r_shift + q_r)^5
106 auto u_1 = pow5(Accumulator(w_r_shift + q_r));
107 // u_2 = (w_o_shift + q_o)^5
108 auto u_2 = pow5(Accumulator(w_o_shift + q_o));
109
110 const auto q_by_scaling_m = q_sel * scaling_factor;
111 const auto q_by_scaling = Accumulator(q_by_scaling_m);
112
113 // Wire parts of the three subrelations, including shifted-row targets.
114 auto wp_0 = w_r + w_o + w_4 - w_r_shift;
115 auto wp_1 = w_r * A_one[0] + w_o * A_one[1] + w_4 * A_one[2] - w_o_shift;
116 auto wp_2 = w_r * A2_one[0] + w_o * A2_one[1] + w_4 * A2_one[2] - w_4_shift;
117
118 // A_0: D_1 u_0 + (w_r + w_o + w_4) - w_r_shift = 0.
119 auto a0_body = u_0 * D1 + Accumulator(wp_0);
120 std::get<0>(evals) += q_by_scaling * a0_body;
121
122 // A_1: D_1 u_1 + 3 u_0 + (A·1)_j-weighted wire combo - w_o_shift = 0.
123 auto a1_body = u_1 * D1 + u_0 * fr(3) + Accumulator(wp_1);
124 std::get<1>(evals) += q_by_scaling * a1_body;
125
126 // A_2: D_1 u_2 + 3 u_1 + (Σ+6) u_0 + (A^2·1)_j-weighted wire combo - w_4_shift = 0.
127 auto a2_body = u_2 * D1 + u_1 * fr(3) + u_0 * sum_A_one + Accumulator(wp_2);
128 std::get<2>(evals) += q_by_scaling * a2_body;
129 }
130};
131
133
134} // namespace bb
Entry transition relation for the K=4 compressed Poseidon2 internal block.
static constexpr std::array< size_t, 3 > SUBRELATION_PARTIAL_LENGTHS
static bool skip(const AllEntities &in)
FF_ FF
static void accumulate(ContainerOverSubrelations &evals, const AllEntities &in, const Parameters &, const FF &scaling_factor)
static constexpr auto & A_one
static constexpr fr D1
static constexpr fr sum_A_one
static constexpr auto & A2_one
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
field< Bn254FrParams > fr
Definition fr.hpp:155
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
static constexpr std::array< FF, VANDERMONDE_SIZE > A_one
static constexpr std::array< FF, VANDERMONDE_SIZE > A2_one