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.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.w_l_shift));
72 auto w_2_shift = Accumulator(CoefficientAccumulator(in.w_r_shift));
73 auto w_3_shift = Accumulator(CoefficientAccumulator(in.w_o_shift));
74 auto w_4_shift = Accumulator(CoefficientAccumulator(in.w_4_shift));
75 auto op_wire_1 = Accumulator(CoefficientAccumulator(in.ecc_op_wire_1));
76 auto op_wire_2 = Accumulator(CoefficientAccumulator(in.ecc_op_wire_2));
77 auto op_wire_3 = Accumulator(CoefficientAccumulator(in.ecc_op_wire_3));
78 auto op_wire_4 = Accumulator(CoefficientAccumulator(in.ecc_op_wire_4));
79 auto lagrange_ecc_op = Accumulator(CoefficientAccumulator(in.lagrange_ecc_op)); // precomputed selector
80
81 // If lagrange_ecc_op is the indicator for ecc_op_gates, complement_ecc_op_by_scaling is the indicator for the
82 // complement times the scaling factor
83 auto lagrange_by_scaling = lagrange_ecc_op * scaling_factor;
84 auto complement_ecc_op_by_scaling = -lagrange_by_scaling + scaling_factor;
85
86 // Contribution (1)
87 auto tmp = op_wire_1 - w_1_shift;
88 tmp *= lagrange_by_scaling;
89 std::get<0>(accumulators) += tmp;
90
91 // Contribution (2)
92 tmp = op_wire_2 - w_2_shift;
93 tmp *= lagrange_by_scaling;
94 std::get<1>(accumulators) += tmp;
95
96 // Contribution (3)
97 tmp = op_wire_3 - w_3_shift;
98 tmp *= lagrange_by_scaling;
99 std::get<2>(accumulators) += tmp;
100
101 // Contribution (4)
102 tmp = op_wire_4 - w_4_shift;
103 tmp *= lagrange_by_scaling;
104 std::get<3>(accumulators) += tmp;
105
106 // Contribution (5)
107 tmp = op_wire_1 * complement_ecc_op_by_scaling;
108 std::get<4>(accumulators) += tmp;
109
110 // Contribution (6)
111 tmp = op_wire_2 * complement_ecc_op_by_scaling;
112 std::get<5>(accumulators) += tmp;
113
114 // Contribution (7)
115 tmp = op_wire_3 * complement_ecc_op_by_scaling;
116 std::get<6>(accumulators) += tmp;
117
118 // Contribution (8)
119 tmp = op_wire_4 * complement_ecc_op_by_scaling;
120 std::get<7>(accumulators) += tmp;
121 };
122};
123
125
126} // 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