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
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
57 template <typename ContainerOverSubrelations, typename AllEntities, typename Parameters>
58 inline static void accumulate(ContainerOverSubrelations& accumulators,
59 const AllEntities& in,
60 const Parameters&,
61 const FF& scaling_factor)
62 {
64 using CoefficientAccumulator = typename Accumulator::CoefficientAccumulator;
65 // We skip using the CoefficientAccumulator type in this relation, as the overall relation degree is low (deg
66 // 3). To do a degree-1 multiplication in the coefficient basis requires 3 Fp muls and 4 Fp adds (karatsuba
67 // multiplication). But a multiplication of a degree-3 Univariate only requires 3 Fp muls.
68 // We still cast to CoefficientAccumulator so that the degree is extended to degree-3 from degree-1
69 auto w_1_shift = Accumulator(CoefficientAccumulator(in.w_l_shift));
70 auto w_2_shift = Accumulator(CoefficientAccumulator(in.w_r_shift));
71 auto w_3_shift = Accumulator(CoefficientAccumulator(in.w_o_shift));
72 auto w_4_shift = Accumulator(CoefficientAccumulator(in.w_4_shift));
73 auto op_wire_1 = Accumulator(CoefficientAccumulator(in.ecc_op_wire_1));
74 auto op_wire_2 = Accumulator(CoefficientAccumulator(in.ecc_op_wire_2));
75 auto op_wire_3 = Accumulator(CoefficientAccumulator(in.ecc_op_wire_3));
76 auto op_wire_4 = Accumulator(CoefficientAccumulator(in.ecc_op_wire_4));
77 auto lagrange_ecc_op = Accumulator(CoefficientAccumulator(in.lagrange_ecc_op)); // precomputed selector
78
79 // If lagrange_ecc_op is the indicator for ecc_op_gates, complement_ecc_op_by_scaling is the indicator for the
80 // complement times the scaling factor
81 auto lagrange_by_scaling = lagrange_ecc_op * scaling_factor;
82 auto complement_ecc_op_by_scaling = -lagrange_by_scaling + scaling_factor;
83
84 // Contribution (1)
85 auto tmp = op_wire_1 - w_1_shift;
86 tmp *= lagrange_by_scaling;
87 std::get<0>(accumulators) += tmp;
88
89 // Contribution (2)
90 tmp = op_wire_2 - w_2_shift;
91 tmp *= lagrange_by_scaling;
92 std::get<1>(accumulators) += tmp;
93
94 // Contribution (3)
95 tmp = op_wire_3 - w_3_shift;
96 tmp *= lagrange_by_scaling;
97 std::get<2>(accumulators) += tmp;
98
99 // Contribution (4)
100 tmp = op_wire_4 - w_4_shift;
101 tmp *= lagrange_by_scaling;
102 std::get<3>(accumulators) += tmp;
103
104 // Contribution (5)
105 tmp = op_wire_1 * complement_ecc_op_by_scaling;
106 std::get<4>(accumulators) += tmp;
107
108 // Contribution (6)
109 tmp = op_wire_2 * complement_ecc_op_by_scaling;
110 std::get<5>(accumulators) += tmp;
111
112 // Contribution (7)
113 tmp = op_wire_3 * complement_ecc_op_by_scaling;
114 std::get<6>(accumulators) += tmp;
115
116 // Contribution (8)
117 tmp = op_wire_4 * complement_ecc_op_by_scaling;
118 std::get<7>(accumulators) += tmp;
119 };
120};
121
123
124} // 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)
Constrains ecc_op_wire polynomials to equal shifted wires on the ECC op domain, and zero elsewhere.
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