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
32template <typename FF_> class EccOpQueueRelationImpl {
33 public:
34 using FF = FF_;
35
36 static constexpr std::array<size_t, 8> SUBRELATION_PARTIAL_LENGTHS{
37 3, // wire - op-queue-wire consistency sub-relation 1
38 3, // wire - op-queue-wire consistency sub-relation 2
39 3, // wire - op-queue-wire consistency sub-relation 3
40 3, // wire - op-queue-wire consistency sub-relation 4
41 3, // op-queue-wire vanishes sub-relation 1
42 3, // op-queue-wire vanishes sub-relation 2
43 3, // op-queue-wire vanishes sub-relation 3
44 3 // op-queue-wire vanishes sub-relation 4
45 };
46
47 template <typename AllEntities> inline static bool skip([[maybe_unused]] const AllEntities& in)
48 {
49 // The prover can skip execution of this relation if the ecc op selector is identically zero
50 return in[AllEntities::EntityId::lagrange_ecc_op].is_zero();
51 }
52
59 template <typename ContainerOverSubrelations, typename AllEntities, typename Parameters>
60 inline static void accumulate(ContainerOverSubrelations& accumulators,
61 const AllEntities& in,
62 const Parameters&,
63 const FF& scaling_factor)
64 {
66 using CoefficientAccumulator = typename Accumulator::CoefficientAccumulator;
67 // We skip using the CoefficientAccumulator type in this relation, as the overall relation degree is low (deg
68 // 3). To do a degree-1 multiplication in the coefficient basis requires 3 Fp muls and 4 Fp adds (karatsuba
69 // multiplication). But a multiplication of a degree-3 Univariate only requires 3 Fp muls.
70 // We still cast to CoefficientAccumulator so that the degree is extended to degree-3 from degree-1
71 auto w_1_shift = Accumulator(CoefficientAccumulator(in[AllEntities::EntityId::w_l_shift]));
72 auto w_2_shift = Accumulator(CoefficientAccumulator(in[AllEntities::EntityId::w_r_shift]));
73 auto w_3_shift = Accumulator(CoefficientAccumulator(in[AllEntities::EntityId::w_o_shift]));
74 auto w_4_shift = Accumulator(CoefficientAccumulator(in[AllEntities::EntityId::w_4_shift]));
75 auto op_wire_1 = Accumulator(CoefficientAccumulator(in[AllEntities::EntityId::ecc_op_wire_1]));
76 auto op_wire_2 = Accumulator(CoefficientAccumulator(in[AllEntities::EntityId::ecc_op_wire_2]));
77 auto op_wire_3 = Accumulator(CoefficientAccumulator(in[AllEntities::EntityId::ecc_op_wire_3]));
78 auto op_wire_4 = Accumulator(CoefficientAccumulator(in[AllEntities::EntityId::ecc_op_wire_4]));
79 auto lagrange_ecc_op =
80 Accumulator(CoefficientAccumulator(in[AllEntities::EntityId::lagrange_ecc_op])); // precomputed selector
81
82 // If lagrange_ecc_op is the indicator for ecc_op_gates, complement_ecc_op_by_scaling is the indicator for the
83 // complement times the scaling factor
84 auto lagrange_by_scaling = lagrange_ecc_op * scaling_factor;
85 auto complement_ecc_op_by_scaling = -lagrange_by_scaling + scaling_factor;
86
87 // Contribution (1)
88 auto tmp = op_wire_1 - w_1_shift;
89 tmp *= lagrange_by_scaling;
90 std::get<0>(accumulators) += tmp;
91
92 // Contribution (2)
93 tmp = op_wire_2 - w_2_shift;
94 tmp *= lagrange_by_scaling;
95 std::get<1>(accumulators) += tmp;
96
97 // Contribution (3)
98 tmp = op_wire_3 - w_3_shift;
99 tmp *= lagrange_by_scaling;
100 std::get<2>(accumulators) += tmp;
101
102 // Contribution (4)
103 tmp = op_wire_4 - w_4_shift;
104 tmp *= lagrange_by_scaling;
105 std::get<3>(accumulators) += tmp;
106
107 // Contribution (5)
108 tmp = op_wire_1 * complement_ecc_op_by_scaling;
109 std::get<4>(accumulators) += tmp;
110
111 // Contribution (6)
112 tmp = op_wire_2 * complement_ecc_op_by_scaling;
113 std::get<5>(accumulators) += tmp;
114
115 // Contribution (7)
116 tmp = op_wire_3 * complement_ecc_op_by_scaling;
117 std::get<6>(accumulators) += tmp;
118
119 // Contribution (8)
120 tmp = op_wire_4 * complement_ecc_op_by_scaling;
121 std::get<7>(accumulators) += tmp;
122 };
123};
124
126
131template <typename FF_> class MegaEccOpBoundaryRelationImpl {
132 public:
133 using FF = FF_;
134
135 static constexpr bool IS_OFFSET_ONLY = true;
136
137 // Four subrelations `ecc_op_wire_j = 0`, each degree 1 (partial length 2).
138 static constexpr std::array<size_t, 4> SUBRELATION_PARTIAL_LENGTHS{ 2, 2, 2, 2 };
139
140 template <typename ContainerOverSubrelations, typename AllEntities, typename Parameters>
141 inline static void accumulate(ContainerOverSubrelations& evals,
142 const AllEntities& in,
143 const Parameters& /*params*/,
144 const FF& scaling_factor)
145 {
147 using CoefficientAccumulator = typename Accumulator::CoefficientAccumulator;
148
149 std::get<0>(evals) +=
150 Accumulator(CoefficientAccumulator(in[AllEntities::EntityId::ecc_op_wire_1])) * scaling_factor;
151 std::get<1>(evals) +=
152 Accumulator(CoefficientAccumulator(in[AllEntities::EntityId::ecc_op_wire_2])) * scaling_factor;
153 std::get<2>(evals) +=
154 Accumulator(CoefficientAccumulator(in[AllEntities::EntityId::ecc_op_wire_3])) * scaling_factor;
155 std::get<3>(evals) +=
156 Accumulator(CoefficientAccumulator(in[AllEntities::EntityId::ecc_op_wire_4])) * scaling_factor;
157 }
158};
159
161
162} // 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)
Enforces that MegaZK's ecc op wires start with four zeros: ecc_op_wire_j(x) = 0 for j = 1....
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