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: Complete, auditors: [Luke, Raju], commit: }
3// external_1: { status: not started, auditors: [], commit: }
4// external_2: { status: not started, auditors: [], commit: }
5// =====================
6
7#pragma once
9
10namespace bb {
11
31template <typename FF_> class EccOpQueueRelationImpl {
32 public:
33 using FF = FF_;
34
35 static constexpr std::array<size_t, 8> SUBRELATION_PARTIAL_LENGTHS{
36 3, // wire - op-queue-wire consistency sub-relation 1
37 3, // wire - op-queue-wire consistency sub-relation 2
38 3, // wire - op-queue-wire consistency sub-relation 3
39 3, // wire - op-queue-wire consistency sub-relation 4
40 3, // op-queue-wire vanishes sub-relation 1
41 3, // op-queue-wire vanishes sub-relation 2
42 3, // op-queue-wire vanishes sub-relation 3
43 3 // op-queue-wire vanishes sub-relation 4
44 };
45
46 template <typename AllEntities> inline static bool skip([[maybe_unused]] const AllEntities& in)
47 {
48 // The prover can skip execution of this relation if the ecc op selector is identically zero
49 return in.lagrange_ecc_op.is_zero();
50 }
51
58 template <typename ContainerOverSubrelations, typename AllEntities, typename Parameters>
59 inline static void accumulate(ContainerOverSubrelations& accumulators,
60 const AllEntities& in,
61 const Parameters&,
62 const FF& scaling_factor)
63 {
65 using CoefficientAccumulator = typename Accumulator::CoefficientAccumulator;
66 // We skip using the CoefficientAccumulator type in this relation, as the overall relation degree is low (deg
67 // 3). To do a degree-1 multiplication in the coefficient basis requires 3 Fp muls and 4 Fp adds (karatsuba
68 // multiplication). But a multiplication of a degree-3 Univariate only requires 3 Fp muls.
69 // We still cast to CoefficientAccumulator so that the degree is extended to degree-3 from degree-1
70 auto w_1_shift = Accumulator(CoefficientAccumulator(in.w_l_shift));
71 auto w_2_shift = Accumulator(CoefficientAccumulator(in.w_r_shift));
72 auto w_3_shift = Accumulator(CoefficientAccumulator(in.w_o_shift));
73 auto w_4_shift = Accumulator(CoefficientAccumulator(in.w_4_shift));
74 auto op_wire_1 = Accumulator(CoefficientAccumulator(in.ecc_op_wire_1));
75 auto op_wire_2 = Accumulator(CoefficientAccumulator(in.ecc_op_wire_2));
76 auto op_wire_3 = Accumulator(CoefficientAccumulator(in.ecc_op_wire_3));
77 auto op_wire_4 = Accumulator(CoefficientAccumulator(in.ecc_op_wire_4));
78 auto lagrange_ecc_op = Accumulator(CoefficientAccumulator(in.lagrange_ecc_op)); // precomputed selector
79
80 // If lagrange_ecc_op is the indicator for ecc_op_gates, complement_ecc_op_by_scaling is the indicator for the
81 // complement times the scaling factor
82 auto lagrange_by_scaling = lagrange_ecc_op * scaling_factor;
83 auto complement_ecc_op_by_scaling = -lagrange_by_scaling + scaling_factor;
84
85 // Contribution (1)
86 auto tmp = op_wire_1 - w_1_shift;
87 tmp *= lagrange_by_scaling;
88 std::get<0>(accumulators) += tmp;
89
90 // Contribution (2)
91 tmp = op_wire_2 - w_2_shift;
92 tmp *= lagrange_by_scaling;
93 std::get<1>(accumulators) += tmp;
94
95 // Contribution (3)
96 tmp = op_wire_3 - w_3_shift;
97 tmp *= lagrange_by_scaling;
98 std::get<2>(accumulators) += tmp;
99
100 // Contribution (4)
101 tmp = op_wire_4 - w_4_shift;
102 tmp *= lagrange_by_scaling;
103 std::get<3>(accumulators) += tmp;
104
105 // Contribution (5)
106 tmp = op_wire_1 * complement_ecc_op_by_scaling;
107 std::get<4>(accumulators) += tmp;
108
109 // Contribution (6)
110 tmp = op_wire_2 * complement_ecc_op_by_scaling;
111 std::get<5>(accumulators) += tmp;
112
113 // Contribution (7)
114 tmp = op_wire_3 * complement_ecc_op_by_scaling;
115 std::get<6>(accumulators) += tmp;
116
117 // Contribution (8)
118 tmp = op_wire_4 * complement_ecc_op_by_scaling;
119 std::get<7>(accumulators) += tmp;
120 };
121};
122
124
125} // namespace bb
Constrains ecc_op_wire polynomials to equal shifted wires on the ECC op domain, and zero elsewhere.
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)
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