From fb5da46af15fe7bf3cad6ec142c8f6e6ed543d06 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Thu, 13 Feb 2025 16:54:34 +0000 Subject: [PATCH] use shift in op relation so tables can index from 0 --- .../relations/ecc_op_queue_relation.hpp | 25 ++++++++++--------- .../trace_to_polynomials.cpp | 10 ++++---- .../ultra_honk/decider_proving_key.cpp | 5 ++-- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/relations/ecc_op_queue_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/ecc_op_queue_relation.hpp index 535f7ca6722b..b237e6227e34 100644 --- a/barretenberg/cpp/src/barretenberg/relations/ecc_op_queue_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/ecc_op_queue_relation.hpp @@ -20,16 +20,15 @@ template class EccOpQueueRelationImpl { template inline static bool skip([[maybe_unused]] const AllEntities& in) { - // The prover can skip execution of this relation altogether since an honest input will lead to a zero - // contribution at every row, even when the selector lagrange_ecc_op is on - return true; + // The prover can skip execution of this relation if the ecc op selector is identically zero + return in.lagrange_ecc_op.is_zero(); } /** * @brief Expression for the generalized permutation sort gate. * @details The relation is defined as C(in(X)...) = * \alpha_{base} * - * ( \Sum_{i=0}^3 \alpha^i * (w_i - w_{op,i}) * \chi_{ecc_op} + + * ( \Sum_{i=0}^3 \alpha^i * (w_i_shift - w_{op,i}) * \chi_{ecc_op} + * \Sum_{i=0}^3 \alpha^{i+4} w_{op,i} * \bar{\chi}_{ecc_op} ) * * where w_{op,i} are the ecc op gate wires, \chi_{ecc_op} is the indicator for the portion of the domain @@ -38,6 +37,8 @@ template class EccOpQueueRelationImpl { * The first four sub-relations check that the values in the conventional wires are identical to the values in the * ecc op wires over the portion of the execution trace representing ECC op queue gates. The next four check * that the op wire polynomials are identically zero everywhere else. + * @note This relation utilizes the shifted wires so that the ecc op wires can store the data begining at index 0, + * unlike the wires which contain an initial zero row to facilitate the left-shift-by-1 needed by other relations. * * @param evals transformed to `evals + C(in(X)...)*scaling_factor` * @param in an std::array containing the fully extended Univariate edges. @@ -57,10 +58,10 @@ template class EccOpQueueRelationImpl { // 3). To do a degree-1 multiplication in the coefficient basis requires 3 Fp muls and 4 Fp adds (karatsuba // multiplication). But a multiplication of a degree-3 Univariate only requires 3 Fp muls. // We still cast to CoefficientAccumulator so that the degree is extended to degree-3 from degree-1 - auto w_1 = Accumulator(CoefficientAccumulator(in.w_l)); - auto w_2 = Accumulator(CoefficientAccumulator(in.w_r)); - auto w_3 = Accumulator(CoefficientAccumulator(in.w_o)); - auto w_4 = Accumulator(CoefficientAccumulator(in.w_4)); + auto w_1_shift = Accumulator(CoefficientAccumulator(in.w_l_shift)); + auto w_2_shift = Accumulator(CoefficientAccumulator(in.w_r_shift)); + auto w_3_shift = Accumulator(CoefficientAccumulator(in.w_o_shift)); + auto w_4_shift = Accumulator(CoefficientAccumulator(in.w_4_shift)); auto op_wire_1 = Accumulator(CoefficientAccumulator(in.ecc_op_wire_1)); auto op_wire_2 = Accumulator(CoefficientAccumulator(in.ecc_op_wire_2)); auto op_wire_3 = Accumulator(CoefficientAccumulator(in.ecc_op_wire_3)); @@ -72,22 +73,22 @@ template class EccOpQueueRelationImpl { auto complement_ecc_op_by_scaling = -lagrange_by_scaling + scaling_factor; // Contribution (1) - auto tmp = op_wire_1 - w_1; + auto tmp = op_wire_1 - w_1_shift; tmp *= lagrange_by_scaling; std::get<0>(accumulators) += tmp; // Contribution (2) - tmp = op_wire_2 - w_2; + tmp = op_wire_2 - w_2_shift; tmp *= lagrange_by_scaling; std::get<1>(accumulators) += tmp; // Contribution (3) - tmp = op_wire_3 - w_3; + tmp = op_wire_3 - w_3_shift; tmp *= lagrange_by_scaling; std::get<2>(accumulators) += tmp; // Contribution (4) - tmp = op_wire_4 - w_4; + tmp = op_wire_4 - w_4_shift; tmp *= lagrange_by_scaling; std::get<3>(accumulators) += tmp; diff --git a/barretenberg/cpp/src/barretenberg/trace_to_polynomials/trace_to_polynomials.cpp b/barretenberg/cpp/src/barretenberg/trace_to_polynomials/trace_to_polynomials.cpp index 4023fcedc123..6fd27f276baa 100644 --- a/barretenberg/cpp/src/barretenberg/trace_to_polynomials/trace_to_polynomials.cpp +++ b/barretenberg/cpp/src/barretenberg/trace_to_polynomials/trace_to_polynomials.cpp @@ -140,16 +140,16 @@ void TraceToPolynomials::add_ecc_op_wires_to_proving_key(Builder& builde requires IsMegaFlavor { auto& ecc_op_selector = proving_key.polynomials.lagrange_ecc_op; - const size_t op_wire_offset = Flavor::has_zero_row ? 1 : 0; + const size_t wire_idx_offset = Flavor::has_zero_row ? 1 : 0; - // Copy the ecc op data from the conventional wires into the op wires over the range of ecc op gates + // Copy the ecc op data from the conventional wires into the op wires over the range of ecc op gates. The data is + // stored in the ecc op wires starting from index 0, whereas the wires contain the data offset by a zero row. const size_t num_ecc_ops = builder.blocks.ecc_op.size(); for (auto [ecc_op_wire, wire] : zip_view(proving_key.polynomials.get_ecc_op_wires(), proving_key.polynomials.get_wires())) { for (size_t i = 0; i < num_ecc_ops; ++i) { - size_t idx = i + op_wire_offset; - ecc_op_wire.at(idx) = wire[idx]; - ecc_op_selector.at(idx) = 1; // construct selector as the indicator on the ecc op block + ecc_op_wire.at(i) = wire[i + wire_idx_offset]; + ecc_op_selector.at(i) = 1; // construct selector as the indicator on the ecc op block } } } diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/decider_proving_key.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/decider_proving_key.cpp index ecc5dc5038b7..51d2c3bbd7ea 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/decider_proving_key.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/decider_proving_key.cpp @@ -131,12 +131,11 @@ void DeciderProvingKey_::allocate_ecc_op_polynomials(const Circuit& circ PROFILE_THIS_NAME("allocate_ecc_op_polynomials"); // Allocate the ecc op wires and selector - const size_t op_wire_offset = circuit.blocks.ecc_op.trace_offset; const size_t ecc_op_block_size = circuit.blocks.ecc_op.get_fixed_size(is_structured); for (auto& wire : proving_key.polynomials.get_ecc_op_wires()) { - wire = Polynomial(ecc_op_block_size, proving_key.circuit_size, op_wire_offset); + wire = Polynomial(ecc_op_block_size, proving_key.circuit_size); } - proving_key.polynomials.lagrange_ecc_op = Polynomial(ecc_op_block_size, proving_key.circuit_size, op_wire_offset); + proving_key.polynomials.lagrange_ecc_op = Polynomial(ecc_op_block_size, proving_key.circuit_size); } template