Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
ecc_op_queue_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
10namespace bb {
11
12template <typename FF_> class EccOpQueueRelationImpl {
13 public:
14 using FF = FF_;
15
16 static constexpr std::array<size_t, 8> SUBRELATION_PARTIAL_LENGTHS{
17 3, // wire - op-queue-wire consistency sub-relation 1
18 3, // wire - op-queue-wire consistency sub-relation 2
19 3, // wire - op-queue-wire consistency sub-relation 3
20 3, // wire - op-queue-wire consistency sub-relation 4
21 3, // op-queue-wire vanishes sub-relation 1
22 3, // op-queue-wire vanishes sub-relation 2
23 3, // op-queue-wire vanishes sub-relation 3
24 3 // op-queue-wire vanishes sub-relation 4
25 };
26
27 template <typename AllEntities> inline static bool skip([[maybe_unused]] const AllEntities& in)
28 {
29 // The prover can skip execution of this relation if the ecc op selector is identically zero
30 return in.lagrange_ecc_op.is_zero();
31 }
32
54 template <typename ContainerOverSubrelations, typename AllEntities, typename Parameters>
55 inline static void accumulate(ContainerOverSubrelations& accumulators,
56 const AllEntities& in,
57 const Parameters&,
58 const FF& scaling_factor)
59 {
61 using CoefficientAccumulator = typename Accumulator::CoefficientAccumulator;
62 // We skip using the CoefficientAccumulator type in this relation, as the overall relation degree is low (deg
63 // 3). To do a degree-1 multiplication in the coefficient basis requires 3 Fp muls and 4 Fp adds (karatsuba
64 // multiplication). But a multiplication of a degree-3 Univariate only requires 3 Fp muls.
65 // We still cast to CoefficientAccumulator so that the degree is extended to degree-3 from degree-1
66 auto w_1_shift = Accumulator(CoefficientAccumulator(in.w_l_shift));
67 auto w_2_shift = Accumulator(CoefficientAccumulator(in.w_r_shift));
68 auto w_3_shift = Accumulator(CoefficientAccumulator(in.w_o_shift));
69 auto w_4_shift = Accumulator(CoefficientAccumulator(in.w_4_shift));
70 auto op_wire_1 = Accumulator(CoefficientAccumulator(in.ecc_op_wire_1));
71 auto op_wire_2 = Accumulator(CoefficientAccumulator(in.ecc_op_wire_2));
72 auto op_wire_3 = Accumulator(CoefficientAccumulator(in.ecc_op_wire_3));
73 auto op_wire_4 = Accumulator(CoefficientAccumulator(in.ecc_op_wire_4));
74 auto lagrange_ecc_op = Accumulator(CoefficientAccumulator(in.lagrange_ecc_op));
75
76 // If lagrange_ecc_op is the indicator for ecc_op_gates, this is the indicator for the complement
77 auto lagrange_by_scaling = lagrange_ecc_op * scaling_factor;
78 auto complement_ecc_op_by_scaling = -lagrange_by_scaling + scaling_factor;
79
80 // Contribution (1)
81 auto tmp = op_wire_1 - w_1_shift;
82 tmp *= lagrange_by_scaling;
83 std::get<0>(accumulators) += tmp;
84
85 // Contribution (2)
86 tmp = op_wire_2 - w_2_shift;
87 tmp *= lagrange_by_scaling;
88 std::get<1>(accumulators) += tmp;
89
90 // Contribution (3)
91 tmp = op_wire_3 - w_3_shift;
92 tmp *= lagrange_by_scaling;
93 std::get<2>(accumulators) += tmp;
94
95 // Contribution (4)
96 tmp = op_wire_4 - w_4_shift;
97 tmp *= lagrange_by_scaling;
98 std::get<3>(accumulators) += tmp;
99
100 // Contribution (5)
101 tmp = op_wire_1 * complement_ecc_op_by_scaling;
102 std::get<4>(accumulators) += tmp;
103
104 // Contribution (6)
105 tmp = op_wire_2 * complement_ecc_op_by_scaling;
106 std::get<5>(accumulators) += tmp;
107
108 // Contribution (7)
109 tmp = op_wire_3 * complement_ecc_op_by_scaling;
110 std::get<6>(accumulators) += tmp;
111
112 // Contribution (8)
113 tmp = op_wire_4 * complement_ecc_op_by_scaling;
114 std::get<7>(accumulators) += tmp;
115 };
116};
117
119
120} // namespace bb
static bool skip(const AllEntities &in)
static constexpr std::array< size_t, 8 > SUBRELATION_PARTIAL_LENGTHS
static void accumulate(ContainerOverSubrelations &accumulators, const AllEntities &in, const Parameters &, const FF &scaling_factor)
Expression for the generalized permutation sort gate.
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