Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
poseidon2_quad_internal_terminal_relation.hpp
Go to the documentation of this file.
1#pragma once
4#include "relation_types.hpp"
5
6namespace bb {
7
23template <typename FF_> class Poseidon2QuadInternalTerminalRelationImpl {
24 public:
25 using FF = FF_;
27
28 static constexpr std::array<size_t, 4> SUBRELATION_PARTIAL_LENGTHS{ 7, 7, 7, 7 };
29
30 template <typename AllEntities> inline static bool skip(const AllEntities& in)
31 {
32 return in.q_poseidon2_quad_internal_terminal.is_zero();
33 }
34
35 template <typename ContainerOverSubrelations, typename AllEntities, typename Parameters>
36 void static accumulate(ContainerOverSubrelations& evals,
37 const AllEntities& in,
38 const Parameters& /*params*/,
39 const FF& scaling_factor)
40 {
42 using CoeffAcc = typename Accumulator::CoefficientAccumulator;
43
44 const auto w_l = CoeffAcc(in.w_l);
45 const auto w_r = CoeffAcc(in.w_r);
46 const auto w_o = CoeffAcc(in.w_o);
47 const auto w_4 = CoeffAcc(in.w_4);
48
49 const auto w_l_shift = CoeffAcc(in.w_l_shift);
50 const auto w_r_shift = CoeffAcc(in.w_r_shift);
51 const auto w_o_shift = CoeffAcc(in.w_o_shift);
52 const auto w_4_shift = CoeffAcc(in.w_4_shift);
53
54 const auto q_l = CoeffAcc(in.q_l);
55 const auto q_r = CoeffAcc(in.q_r);
56 const auto q_o = CoeffAcc(in.q_o);
57 const auto q_4 = CoeffAcc(in.q_4);
58
59 const auto q_sel = CoeffAcc(in.q_poseidon2_quad_internal_terminal);
60
61 auto pow5 = [](const Accumulator& x) -> Accumulator {
62 auto sq = x.sqr();
63 auto quart = sq.sqr();
64 return quart * x;
65 };
66
67 // S-boxes for the four rounds.
68 auto u_0 = pow5(Accumulator(w_l + q_l));
69 auto u_1 = pow5(Accumulator(w_r + q_r));
70 auto u_2 = pow5(Accumulator(w_o + q_o));
71 auto u_3 = pow5(Accumulator(w_4 + q_4));
72
73 // Closed-form output rows, with shifted bridge-row terms folded into the wire part.
74 const auto& C = QuadParams::tables.closed_form;
75 auto wp_0 = w_r * C[0][0] + w_o * C[0][1] + w_4 * C[0][2] - w_l_shift;
76 auto wp_1 = w_r * C[1][0] + w_o * C[1][1] + w_4 * C[1][2] - w_r_shift;
77 auto wp_2 = w_r * C[2][0] + w_o * C[2][1] + w_4 * C[2][2] - w_o_shift;
78 auto wp_3 = w_r * C[3][0] + w_o * C[3][1] + w_4 * C[3][2] - w_4_shift;
79
80 const auto q_by_scaling_m = q_sel * scaling_factor;
81 const auto q_by_scaling = Accumulator(q_by_scaling_m);
82
83 // Subrelation bodies: out_k - w_*_shift = 0.
84 auto a0_body = u_0 * C[0][3] + u_1 * C[0][4] + u_2 * C[0][5] + u_3 * C[0][6] + Accumulator(wp_0);
85 auto a1_body = u_0 * C[1][3] + u_1 * C[1][4] + u_2 * C[1][5] + u_3 + Accumulator(wp_1);
86 auto a2_body = u_0 * C[2][3] + u_1 * C[2][4] + u_2 * C[2][5] + u_3 + Accumulator(wp_2);
87 auto a3_body = u_0 * C[3][3] + u_1 * C[3][4] + u_2 * C[3][5] + u_3 + Accumulator(wp_3);
88
89 std::get<0>(evals) += q_by_scaling * a0_body;
90 std::get<1>(evals) += q_by_scaling * a1_body;
91 std::get<2>(evals) += q_by_scaling * a2_body;
92 std::get<3>(evals) += q_by_scaling * a3_body;
93 }
94};
95
96template <typename FF>
98
99} // namespace bb
Terminal variant of the K=4 compressed internal-round relation.
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