Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
poseidon2_initial_external_relation.hpp
Go to the documentation of this file.
1#pragma once
3
4namespace bb {
5
22template <typename FF_> class Poseidon2InitialExternalRelationImpl {
23 public:
24 using FF = FF_;
25
26 static constexpr std::array<size_t, 4> SUBRELATION_PARTIAL_LENGTHS{
27 3, // A_0
28 3, // A_1
29 3, // A_2
30 3, // A_3
31 };
32
33 template <typename AllEntities> inline static bool skip(const AllEntities& in)
34 {
35 return in.q_poseidon2_external_initial.is_zero();
36 }
37
38 template <typename ContainerOverSubrelations, typename AllEntities, typename Parameters>
39 void static accumulate(ContainerOverSubrelations& evals,
40 const AllEntities& in,
41 const Parameters&,
42 const FF& scaling_factor)
43 {
45 using CoeffAcc = typename Accumulator::CoefficientAccumulator;
46
47 const auto x_0 = CoeffAcc(in.w_l);
48 const auto x_1 = CoeffAcc(in.w_r);
49 const auto x_2 = CoeffAcc(in.w_o);
50 const auto x_3 = CoeffAcc(in.w_4);
51 const auto y_0 = CoeffAcc(in.w_l_shift);
52 const auto y_1 = CoeffAcc(in.w_r_shift);
53 const auto y_2 = CoeffAcc(in.w_o_shift);
54 const auto y_3 = CoeffAcc(in.w_4_shift);
55
56 const auto q_sel = CoeffAcc(in.q_poseidon2_external_initial);
57 const auto q_by_scaling = Accumulator(q_sel * scaling_factor);
58
59 // Shared partial sums for M_E:
60 // y0 = 5x0 + 7x1 + x2 + 3x3 = (4x0 + 6x1 + x2 + x3) + (x0 + x1 + 2x3)
61 // y1 = 4x0 + 6x1 + x2 + x3 = (2x0 + 2x1) + (2x0 + 2x1) + (2x1 + x2 + x3)
62 // y2 = x0 + 3x1 + 5x2 + 7x3 = (2x1 + x2 + x3) + (x0 + x1 + 4x2 + 6x3)
63 // y3 = x0 + x1 + 4x2 + 6x3
64 auto t0 = x_0 + x_1; // x0 + x1
65 auto t1 = x_2 + x_3; // x2 + x3
66 auto t2 = x_1 + x_1 + t1; // 2x1 + x2 + x3
67 auto t3 = x_3 + x_3 + t0; // x0 + x1 + 2x3
68
69 auto y3_calc = t1 + t1;
70 y3_calc = y3_calc + y3_calc + t3; // 4x2 + 4x3 + (x0 + x1 + 2x3) = x0 + x1 + 4x2 + 6x3
71 auto y1_calc = t0 + t0;
72 y1_calc = y1_calc + y1_calc + t2; // 4x0 + 4x1 + (2x1 + x2 + x3) = 4x0 + 6x1 + x2 + x3
73 auto y0_calc = t3 + y1_calc; // (x0 + x1 + 2x3) + (4x0 + 6x1 + x2 + x3) = 5x0 + 7x1 + x2 + 3x3
74 auto y2_calc = t2 + y3_calc; // (2x1 + x2 + x3) + (x0 + x1 + 4x2 + 6x3) = x0 + 3x1 + 5x2 + 7x3
75
76 // Each subrelation: q_sel ยท (y_k_calc - y_k) = 0.
77 std::get<0>(evals) += q_by_scaling * Accumulator(y0_calc - y_0);
78 std::get<1>(evals) += q_by_scaling * Accumulator(y1_calc - y_1);
79 std::get<2>(evals) += q_by_scaling * Accumulator(y2_calc - y_2);
80 std::get<3>(evals) += q_by_scaling * Accumulator(y3_calc - y_3);
81 }
82};
83
85
86} // namespace bb
Initial-linear-layer relation for Poseidon2 (Mega).
static void accumulate(ContainerOverSubrelations &evals, const AllEntities &in, const Parameters &, const FF &scaling_factor)
static constexpr std::array< size_t, 4 > SUBRELATION_PARTIAL_LENGTHS
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