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 {
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[AllEntities::EntityId::w_l]);
84 const auto w_r = CoeffAcc(in[AllEntities::EntityId::w_r]);
85 const auto w_o = CoeffAcc(in[AllEntities::EntityId::w_o]);
86 const auto w_4 = CoeffAcc(in[AllEntities::EntityId::w_4]);
87
88 const auto w_r_shift = CoeffAcc(in[AllEntities::EntityId::w_r_shift]);
89 const auto w_o_shift = CoeffAcc(in[AllEntities::EntityId::w_o_shift]);
90 const auto w_4_shift = CoeffAcc(in[AllEntities::EntityId::w_4_shift]);
91
92 const auto q_l = CoeffAcc(in[AllEntities::EntityId::q_l]);
93 const auto q_r = CoeffAcc(in[AllEntities::EntityId::q_r]);
94 const auto q_o = CoeffAcc(in[AllEntities::EntityId::q_o]);
95 const auto q_sel = CoeffAcc(in[AllEntities::EntityId::q_poseidon2_transition_entry]);
96
97 // Square the degree-1 pow5 input in the coefficient basis before promoting -- see
98 // UnivariateCoefficientBasis::sqr.
99 auto pow5 = [](const auto& x_m) -> Accumulator {
100 const Accumulator x(x_m);
101 const Accumulator sq(x_m.sqr());
102 return sq.sqr() * x;
103 };
104
105 // u_0 = (w_l + q_l)^5
106 auto u_0 = pow5(w_l + q_l);
107 // u_1 = (w_r_shift + q_r)^5
108 auto u_1 = pow5(w_r_shift + q_r);
109 // u_2 = (w_o_shift + q_o)^5
110 auto u_2 = pow5(w_o_shift + q_o);
111
112 const auto q_by_scaling_m = q_sel * scaling_factor;
113 const auto q_by_scaling = Accumulator(q_by_scaling_m);
114
115 // Wire parts of the three subrelations, including shifted-row targets.
116 auto wp_0 = w_r + w_o + w_4 - w_r_shift;
117 auto wp_1 = w_r * A_one[0] + w_o * A_one[1] + w_4 * A_one[2] - w_o_shift;
118 auto wp_2 = w_r * A2_one[0] + w_o * A2_one[1] + w_4 * A2_one[2] - w_4_shift;
119
120 // A_0: D_1 u_0 + (w_r + w_o + w_4) - w_r_shift = 0.
121 auto a0_body = u_0 * D1 + Accumulator(wp_0);
122 std::get<0>(evals) += q_by_scaling * a0_body;
123
124 // A_1: D_1 u_1 + 3 u_0 + (A·1)_j-weighted wire combo - w_o_shift = 0.
125 auto a1_body = u_1 * D1 + u_0 * fr(3) + Accumulator(wp_1);
126 std::get<1>(evals) += q_by_scaling * a1_body;
127
128 // A_2: D_1 u_2 + 3 u_1 + (Σ+6) u_0 + (A^2·1)_j-weighted wire combo - w_4_shift = 0.
129 auto a2_body = u_2 * D1 + u_1 * fr(3) + u_0 * sum_A_one + Accumulator(wp_2);
130 std::get<2>(evals) += q_by_scaling * a2_body;
131 }
132};
133
135
136} // 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