diff --git a/barretenberg/cpp/CMakePresets.json b/barretenberg/cpp/CMakePresets.json index 0174d8b873b..a231a712a46 100644 --- a/barretenberg/cpp/CMakePresets.json +++ b/barretenberg/cpp/CMakePresets.json @@ -46,8 +46,12 @@ "displayName": "Debugging build with Clang-16", "description": "Build with globally installed Clang-16 in debug mode", "inherits": "clang16", + "binaryDir": "build-debug", "environment": { - "CMAKE_BUILD_TYPE": "Debug" + "CMAKE_BUILD_TYPE": "Debug", + "CFLAGS": "-gdwarf-4", + "CXXFLAGS": "-gdwarf-4", + "LDFLAGS": "-gdwarf-4" }, "cacheVariables": { "ENABLE_ASAN": "OFF", diff --git a/barretenberg/cpp/src/barretenberg/common/zip_view.hpp b/barretenberg/cpp/src/barretenberg/common/zip_view.hpp new file mode 100644 index 00000000000..a055d82dada --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/common/zip_view.hpp @@ -0,0 +1,190 @@ +#pragma once +/* ********************************* FILE ************************************/ +/** \file mzip.hpp + * + * \brief This header contains the zip iterator class. + * + * WARNING this is a zip view, not a zip copy! + * + * \remark + * - c++17 + * - no dependencies + * - header only + * - tested by test_zip_iterator.cpp + * - not thread safe + * - view ! + * - extends lifetime of rvalue inputs untill the end of the for loop + * + * \todo + * - add algorithm tests, probably does not work at all... + * + * + * \example + * std::vector as{1,2},bs{1,2,3}; + * for(auto [index, a,b]: zip(as,bs)){ + * a++; + * } + * cout<= 201703L, + " must be c++17 or greater"); // could be rewritten in c++11, but the features you must use will be buggy + // in an older compiler anyways. +#include +#include +#include +#include +#include +#include +#include + +template +/** + * @brief The zip_iterator class + * + * Provides a zip iterator which is at end when any is at end + */ +class zip_iterator { + public: + // speeds up compilation a little bit... + using tuple_indexes = std::make_index_sequence>>; + + zip_iterator(T iter, T iter_end) + : iter(iter) + , iter_end(iter_end) + {} + // prefix, inc first, then return + zip_iterator& operator++() + { + for_each_in_tuple([](auto&& x) { return x++; }, iter); + // then if any hit end, update all to point to end. + auto end = apply2([](auto x, auto y) { return x == y; }, iter, iter_end); + if (if_any_in(end)) { + apply2([](auto& x, auto y) { return x = y; }, iter, iter_end); + } + index++; + return *this; + } + // sufficient because ++ keeps track and sets all to end when any is + bool operator!=(const zip_iterator& other) const { return other.iter != iter; } + auto operator*() const + { + return std::forward(get_refs(iter, tuple_indexes{})); + } + + private: + T iter, iter_end; + std::size_t index = 0; + + template auto get_refs(T t, std::index_sequence) const + { + return std::make_tuple(std::ref(*std::get(t))...); + } + + template auto apply2_impl(F&& f, A&& a, A&& b, std::index_sequence) + { + return std::make_tuple(f(std::get(a), std::get(b))...); + } + template auto apply2(F&& f, A&& a, A&& b) + { + return apply2_impl(std::forward(f), std::forward(a), std::forward(b), tuple_indexes{}); + } + template bool if_any_impl(const A& t, std::index_sequence) const + { + return (... || std::get(t)); // c++17 + } + + // in general context we must enforce that these are tuples + template bool if_any_in(A&& t) const { return if_any_impl(std::forward(t), tuple_indexes{}); } + + template + auto for_each_in_impl(F&& f, Tuple&& t, std::index_sequence) const + { + return std::make_tuple(f(std::get(t))...); + } + + template void for_each_in_tuple(F&& f, A&& t) const + { + for_each_in_impl(std::forward(f), std::forward(t), tuple_indexes{}); + } +}; + +template class zip_view { + using arg_indexes = std::make_index_sequence; + + public: + zip_view(S... args) + : args(std::forward(args)...) + {} + auto begin() const { return get_begins(arg_indexes{}); } + auto end() const { return get_ends(arg_indexes{}); } + [[nodiscard]] std::size_t size() const { return size_impl(arg_indexes{}); } + + private: + std::tuple args; + template auto get_begins(std::index_sequence) const + { + return zip_iterator(std::make_tuple(std::get(args).begin()...), std::make_tuple(std::get(args).end()...)); + } + template auto get_ends(std::index_sequence) const + { + return zip_iterator(std::make_tuple(std::get(args).end()...), std::make_tuple(std::get(args).end()...)); + } + template auto size_impl(std::index_sequence) const + { + return std::max({ std::size_t(std::get(args).size())... }); + } + + template bool if_any_impl(const A& t, std::index_sequence) const + { + return (... || std::get(t)); // c++17 + } +}; + +// deduction guide, +template zip_view(S&&...) -> zip_view; diff --git a/barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp b/barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp index 47cec70b76f..366616e9322 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp @@ -394,6 +394,113 @@ template class ECCVMBa } // clang-format on + // defines a method pointer_view that returns the following, with const and non-const variants + DEFINE_POINTER_VIEW(NUM_ALL_ENTITIES, + &lagrange_first, + &lagrange_second, + &lagrange_last, + &transcript_add, + &transcript_mul, + &transcript_eq, + &transcript_collision_check, + &transcript_msm_transition, + &transcript_pc, + &transcript_msm_count, + &transcript_x, + &transcript_y, + &transcript_z1, + &transcript_z2, + &transcript_z1zero, + &transcript_z2zero, + &transcript_op, + &transcript_accumulator_x, + &transcript_accumulator_y, + &transcript_msm_x, + &transcript_msm_y, + &precompute_pc, + &precompute_point_transition, + &precompute_round, + &precompute_scalar_sum, + &precompute_s1hi, + &precompute_s1lo, + &precompute_s2hi, + &precompute_s2lo, + &precompute_s3hi, + &precompute_s3lo, + &precompute_s4hi, + &precompute_s4lo, + &precompute_skew, + &precompute_dx, + &precompute_dy, + &precompute_tx, + &precompute_ty, + &msm_transition, + &msm_add, + &msm_double, + &msm_skew, + &msm_accumulator_x, + &msm_accumulator_y, + &msm_pc, + &msm_size_of_msm, + &msm_count, + &msm_round, + &msm_add1, + &msm_add2, + &msm_add3, + &msm_add4, + &msm_x1, + &msm_y1, + &msm_x2, + &msm_y2, + &msm_x3, + &msm_y3, + &msm_x4, + &msm_y4, + &msm_collision_x1, + &msm_collision_x2, + &msm_collision_x3, + &msm_collision_x4, + &msm_lambda1, + &msm_lambda2, + &msm_lambda3, + &msm_lambda4, + &msm_slice1, + &msm_slice2, + &msm_slice3, + &msm_slice4, + &transcript_accumulator_empty, + &transcript_reset_accumulator, + &precompute_select, + &lookup_read_counts_0, + &lookup_read_counts_1, + &z_perm, + &lookup_inverses, + &transcript_mul_shift, + &transcript_msm_count_shift, + &transcript_accumulator_x_shift, + &transcript_accumulator_y_shift, + &precompute_scalar_sum_shift, + &precompute_s1hi_shift, + &precompute_dx_shift, + &precompute_dy_shift, + &precompute_tx_shift, + &precompute_ty_shift, + &msm_transition_shift, + &msm_add_shift, + &msm_double_shift, + &msm_skew_shift, + &msm_accumulator_x_shift, + &msm_accumulator_y_shift, + &msm_count_shift, + &msm_round_shift, + &msm_add1_shift, + &msm_pc_shift, + &precompute_pc_shift, + &transcript_pc_shift, + &precompute_round_shift, + &transcript_accumulator_empty_shift, + &precompute_select_shift, + &z_perm_shift) std::vector get_wires() override { return { @@ -680,13 +787,12 @@ template class ECCVMBa */ class AllPolynomials : public AllEntities { public: + [[nodiscard]] size_t get_polynomial_size() const { return this->lagrange_first.size(); } AllValues get_row(const size_t row_idx) const { AllValues result; - size_t column_idx = 0; // // TODO(https://github.com/AztecProtocol/barretenberg/issues/391) zip - for (auto& column : this->_data) { - result[column_idx] = column[row_idx]; - column_idx++; + for (auto [result_field, polynomial] : zip_view(result.pointer_view(), this->pointer_view())) { + *result_field = (*polynomial)[row_idx]; } return result; } @@ -736,10 +842,8 @@ template class ECCVMBa AllValues get_row(const size_t row_idx) { AllValues result; - size_t column_idx = 0; // TODO(https://github.com/AztecProtocol/barretenberg/issues/391) zip - for (auto& column : this->_data) { - result[column_idx] = column[row_idx]; - column_idx++; + for (auto [result_field, polynomial] : zip_view(result.pointer_view(), this->pointer_view())) { + *result_field = (*polynomial)[row_idx]; } return result; } diff --git a/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp b/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp index 7b8bc126206..7a37e57d6c1 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp @@ -64,6 +64,7 @@ */ #pragma once +#include "barretenberg/common/zip_view.hpp" #include "barretenberg/polynomials/barycentric.hpp" #include "barretenberg/polynomials/evaluation_domain.hpp" #include "barretenberg/polynomials/univariate.hpp" @@ -74,6 +75,23 @@ namespace proof_system::honk::flavor { +template static auto _assert_array_size(std::array&& array) +{ + static_assert(N == ExpectedSize, + "Expected array size to match given size (first parameter) in DEFINE_POINTER_VIEW"); + return array; +} + +#define DEFINE_POINTER_VIEW(ExpectedSize, ...) \ + [[nodiscard]] auto pointer_view() \ + { \ + return _assert_array_size(std::array{ __VA_ARGS__ }); \ + } \ + [[nodiscard]] auto pointer_view() const \ + { \ + return _assert_array_size(std::array{ __VA_ARGS__ }); \ + } + /** * @brief Base data class template, a wrapper for std::array, from which every flavor class ultimately derives. * @@ -87,8 +105,7 @@ template class Ent ArrayType _data; virtual ~Entities_() = default; - - DataType& operator[](size_t idx) { return _data[idx]; }; + // TODO(AD): remove these with the backing array typename ArrayType::iterator begin() { return _data.begin(); }; typename ArrayType::iterator end() { return _data.end(); }; diff --git a/barretenberg/cpp/src/barretenberg/flavor/goblin_translator.hpp b/barretenberg/cpp/src/barretenberg/flavor/goblin_translator.hpp index e08eead4e42..136d60e6cc5 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/goblin_translator.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/goblin_translator.hpp @@ -835,6 +835,193 @@ template class GoblinTranslator_ { DataType& lagrange_second_to_last_in_minicircuit = std::get<182>(this->_data); DataType& ordered_extra_range_constraints_numerator = std::get<183>(this->_data); + // defines a method pointer_view that returns the following, with const and non-const variants + DEFINE_POINTER_VIEW(NUM_ALL_ENTITIES, + &op, + &x_lo_y_hi, + &x_hi_z_1, + &y_lo_z_2, + &p_x_low_limbs, + &p_x_low_limbs_range_constraint_0, + &p_x_low_limbs_range_constraint_1, + &p_x_low_limbs_range_constraint_2, + &p_x_low_limbs_range_constraint_3, + &p_x_low_limbs_range_constraint_4, + &p_x_low_limbs_range_constraint_tail, + &p_x_high_limbs, + &p_x_high_limbs_range_constraint_0, + &p_x_high_limbs_range_constraint_1, + &p_x_high_limbs_range_constraint_2, + &p_x_high_limbs_range_constraint_3, + &p_x_high_limbs_range_constraint_4, + &p_x_high_limbs_range_constraint_tail, + &p_y_low_limbs, + &p_y_low_limbs_range_constraint_0, + &p_y_low_limbs_range_constraint_1, + &p_y_low_limbs_range_constraint_2, + &p_y_low_limbs_range_constraint_3, + &p_y_low_limbs_range_constraint_4, + &p_y_low_limbs_range_constraint_tail, + &p_y_high_limbs, + &p_y_high_limbs_range_constraint_0, + &p_y_high_limbs_range_constraint_1, + &p_y_high_limbs_range_constraint_2, + &p_y_high_limbs_range_constraint_3, + &p_y_high_limbs_range_constraint_4, + &p_y_high_limbs_range_constraint_tail, + &z_low_limbs, + &z_low_limbs_range_constraint_0, + &z_low_limbs_range_constraint_1, + &z_low_limbs_range_constraint_2, + &z_low_limbs_range_constraint_3, + &z_low_limbs_range_constraint_4, + &z_low_limbs_range_constraint_tail, + &z_high_limbs, + &z_high_limbs_range_constraint_0, + &z_high_limbs_range_constraint_1, + &z_high_limbs_range_constraint_2, + &z_high_limbs_range_constraint_3, + &z_high_limbs_range_constraint_4, + &z_high_limbs_range_constraint_tail, + &accumulators_binary_limbs_0, + &accumulators_binary_limbs_1, + &accumulators_binary_limbs_2, + &accumulators_binary_limbs_3, + &accumulator_low_limbs_range_constraint_0, + &accumulator_low_limbs_range_constraint_1, + &accumulator_low_limbs_range_constraint_2, + &accumulator_low_limbs_range_constraint_3, + &accumulator_low_limbs_range_constraint_4, + &accumulator_low_limbs_range_constraint_tail, + &accumulator_high_limbs_range_constraint_0, + &accumulator_high_limbs_range_constraint_1, + &accumulator_high_limbs_range_constraint_2, + &accumulator_high_limbs_range_constraint_3, + &accumulator_high_limbs_range_constraint_4, + &accumulator_high_limbs_range_constraint_tail, + "ient_low_binary_limbs, + "ient_high_binary_limbs, + "ient_low_limbs_range_constraint_0, + "ient_low_limbs_range_constraint_1, + "ient_low_limbs_range_constraint_2, + "ient_low_limbs_range_constraint_3, + "ient_low_limbs_range_constraint_4, + "ient_low_limbs_range_constraint_tail, + "ient_high_limbs_range_constraint_0, + "ient_high_limbs_range_constraint_1, + "ient_high_limbs_range_constraint_2, + "ient_high_limbs_range_constraint_3, + "ient_high_limbs_range_constraint_4, + "ient_high_limbs_range_constraint_tail, + &relation_wide_limbs, + &relation_wide_limbs_range_constraint_0, + &relation_wide_limbs_range_constraint_1, + &relation_wide_limbs_range_constraint_2, + &relation_wide_limbs_range_constraint_3, + &concatenated_range_constraints_0, + &concatenated_range_constraints_1, + &concatenated_range_constraints_2, + &concatenated_range_constraints_3, + &ordered_range_constraints_0, + &ordered_range_constraints_1, + &ordered_range_constraints_2, + &ordered_range_constraints_3, + &ordered_range_constraints_4, + &z_perm, + &x_lo_y_hi_shift, + &x_hi_z_1_shift, + &y_lo_z_2_shift, + &p_x_low_limbs_shift, + &p_x_low_limbs_range_constraint_0_shift, + &p_x_low_limbs_range_constraint_1_shift, + &p_x_low_limbs_range_constraint_2_shift, + &p_x_low_limbs_range_constraint_3_shift, + &p_x_low_limbs_range_constraint_4_shift, + &p_x_low_limbs_range_constraint_tail_shift, + &p_x_high_limbs_shift, + &p_x_high_limbs_range_constraint_0_shift, + &p_x_high_limbs_range_constraint_1_shift, + &p_x_high_limbs_range_constraint_2_shift, + &p_x_high_limbs_range_constraint_3_shift, + &p_x_high_limbs_range_constraint_4_shift, + &p_x_high_limbs_range_constraint_tail_shift, + &p_y_low_limbs_shift, + &p_y_low_limbs_range_constraint_0_shift, + &p_y_low_limbs_range_constraint_1_shift, + &p_y_low_limbs_range_constraint_2_shift, + &p_y_low_limbs_range_constraint_3_shift, + &p_y_low_limbs_range_constraint_4_shift, + &p_y_low_limbs_range_constraint_tail_shift, + &p_y_high_limbs_shift, + &p_y_high_limbs_range_constraint_0_shift, + &p_y_high_limbs_range_constraint_1_shift, + &p_y_high_limbs_range_constraint_2_shift, + &p_y_high_limbs_range_constraint_3_shift, + &p_y_high_limbs_range_constraint_4_shift, + &p_y_high_limbs_range_constraint_tail_shift, + &z_low_limbs_shift, + &z_low_limbs_range_constraint_0_shift, + &z_low_limbs_range_constraint_1_shift, + &z_low_limbs_range_constraint_2_shift, + &z_low_limbs_range_constraint_3_shift, + &z_low_limbs_range_constraint_4_shift, + &z_low_limbs_range_constraint_tail_shift, + &z_high_limbs_shift, + &z_high_limbs_range_constraint_0_shift, + &z_high_limbs_range_constraint_1_shift, + &z_high_limbs_range_constraint_2_shift, + &z_high_limbs_range_constraint_3_shift, + &z_high_limbs_range_constraint_4_shift, + &z_high_limbs_range_constraint_tail_shift, + &accumulators_binary_limbs_0_shift, + &accumulators_binary_limbs_1_shift, + &accumulators_binary_limbs_2_shift, + &accumulators_binary_limbs_3_shift, + &accumulator_low_limbs_range_constraint_0_shift, + &accumulator_low_limbs_range_constraint_1_shift, + &accumulator_low_limbs_range_constraint_2_shift, + &accumulator_low_limbs_range_constraint_3_shift, + &accumulator_low_limbs_range_constraint_4_shift, + &accumulator_low_limbs_range_constraint_tail_shift, + &accumulator_high_limbs_range_constraint_0_shift, + &accumulator_high_limbs_range_constraint_1_shift, + &accumulator_high_limbs_range_constraint_2_shift, + &accumulator_high_limbs_range_constraint_3_shift, + &accumulator_high_limbs_range_constraint_4_shift, + &accumulator_high_limbs_range_constraint_tail_shift, + "ient_low_binary_limbs_shift, + "ient_high_binary_limbs_shift, + "ient_low_limbs_range_constraint_0_shift, + "ient_low_limbs_range_constraint_1_shift, + "ient_low_limbs_range_constraint_2_shift, + "ient_low_limbs_range_constraint_3_shift, + "ient_low_limbs_range_constraint_4_shift, + "ient_low_limbs_range_constraint_tail_shift, + "ient_high_limbs_range_constraint_0_shift, + "ient_high_limbs_range_constraint_1_shift, + "ient_high_limbs_range_constraint_2_shift, + "ient_high_limbs_range_constraint_3_shift, + "ient_high_limbs_range_constraint_4_shift, + "ient_high_limbs_range_constraint_tail_shift, + &relation_wide_limbs_shift, + &relation_wide_limbs_range_constraint_0_shift, + &relation_wide_limbs_range_constraint_1_shift, + &relation_wide_limbs_range_constraint_2_shift, + &relation_wide_limbs_range_constraint_3_shift, + &ordered_range_constraints_0_shift, + &ordered_range_constraints_1_shift, + &ordered_range_constraints_2_shift, + &ordered_range_constraints_3_shift, + &ordered_range_constraints_4_shift, + &z_perm_shift, + &lagrange_first, + &lagrange_last, + &lagrange_odd_in_minicircuit, + &lagrange_even_in_minicircuit, + &lagrange_second, + &lagrange_second_to_last_in_minicircuit, + &ordered_extra_range_constraints_numerator) + std::vector get_wires() override { @@ -1431,17 +1618,16 @@ template class GoblinTranslator_ { */ class ProverPolynomials : public AllEntities { public: + [[nodiscard]] size_t get_polynomial_size() const { return this->op.size(); } /** * @brief Returns the evaluations of all prover polynomials at one point on the boolean hypercube, which * represents one row in the execution trace. */ - AllValues get_row(const size_t row_idx) + [[nodiscard]] AllValues get_row(size_t row_idx) const { AllValues result; - size_t column_idx = 0; // TODO(https://github.com/AztecProtocol/barretenberg/issues/391) zip - for (auto& column : this->_data) { - result[column_idx] = column[row_idx]; - column_idx++; + for (auto [result_field, polynomial] : zip_view(result.pointer_view(), this->pointer_view())) { + *result_field = (*polynomial)[row_idx]; } return result; } diff --git a/barretenberg/cpp/src/barretenberg/flavor/goblin_ultra.hpp b/barretenberg/cpp/src/barretenberg/flavor/goblin_ultra.hpp index bf94b36b65d..120ff0badfc 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/goblin_ultra.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/goblin_ultra.hpp @@ -217,6 +217,60 @@ class GoblinUltra { DataType& z_perm_shift = std::get<49>(this->_data); DataType& z_lookup_shift = std::get<50>(this->_data); + // defines a method pointer_view that returns the following, with const and non-const variants + DEFINE_POINTER_VIEW(NUM_ALL_ENTITIES, + &q_c, + &q_l, + &q_r, + &q_o, + &q_4, + &q_m, + &q_arith, + &q_sort, + &q_elliptic, + &q_aux, + &q_lookup, + &q_busread, + &sigma_1, + &sigma_2, + &sigma_3, + &sigma_4, + &id_1, + &id_2, + &id_3, + &id_4, + &table_1, + &table_2, + &table_3, + &table_4, + &lagrange_first, + &lagrange_last, + &lagrange_ecc_op, + &w_l, + &w_r, + &w_o, + &w_4, + &sorted_accum, + &z_perm, + &z_lookup, + &ecc_op_wire_1, + &ecc_op_wire_2, + &ecc_op_wire_3, + &ecc_op_wire_4, + &calldata, + &calldata_read_counts, + &table_1_shift, + &table_2_shift, + &table_3_shift, + &table_4_shift, + &w_l_shift, + &w_r_shift, + &w_o_shift, + &w_4_shift, + &sorted_accum_shift, + &z_perm_shift, + &z_lookup_shift); + std::vector get_wires() override { return { w_l, w_r, w_o, w_4 }; }; std::vector get_ecc_op_wires() { @@ -379,13 +433,12 @@ class GoblinUltra { */ class ProverPolynomials : public AllEntities { public: - AllValues get_row(const size_t row_idx) const + [[nodiscard]] size_t get_polynomial_size() const { return q_c.size(); } + [[nodiscard]] AllValues get_row(size_t row_idx) const { AllValues result; - size_t column_idx = 0; // TODO(https://github.com/AztecProtocol/barretenberg/issues/391) zip - for (auto& column : this->_data) { - result[column_idx] = column[row_idx]; - column_idx++; + for (auto [result_field, polynomial] : zip_view(result.pointer_view(), pointer_view())) { + *result_field = (*polynomial)[row_idx]; } return result; } diff --git a/barretenberg/cpp/src/barretenberg/flavor/ultra.hpp b/barretenberg/cpp/src/barretenberg/flavor/ultra.hpp index 28feb0c2a17..f596b20d890 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/ultra.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/ultra.hpp @@ -199,6 +199,51 @@ class Ultra { DataType& z_perm_shift = std::get<41>(this->_data); DataType& z_lookup_shift = std::get<42>(this->_data); + // defines a method pointer_view that returns the following, with const and non-const variants + DEFINE_POINTER_VIEW(NUM_ALL_ENTITIES, + &q_c, + &q_l, + &q_r, + &q_o, + &q_4, + &q_m, + &q_arith, + &q_sort, + &q_elliptic, + &q_aux, + &q_lookup, + &sigma_1, + &sigma_2, + &sigma_3, + &sigma_4, + &id_1, + &id_2, + &id_3, + &id_4, + &table_1, + &table_2, + &table_3, + &table_4, + &lagrange_first, + &lagrange_last, + &w_l, + &w_r, + &w_o, + &w_4, + &sorted_accum, + &z_perm, + &z_lookup, + &table_1_shift, + &table_2_shift, + &table_3_shift, + &table_4_shift, + &w_l_shift, + &w_r_shift, + &w_o_shift, + &w_4_shift, + &sorted_accum_shift, + &z_perm_shift, + &z_lookup_shift); std::vector get_wires() override { return { w_l, w_r, w_o, w_4 }; }; // Gemini-specific getters. std::vector get_unshifted() override @@ -293,13 +338,12 @@ class Ultra { */ class ProverPolynomials : public AllEntities { public: - AllValues get_row(const size_t row_idx) const + [[nodiscard]] size_t get_polynomial_size() const { return q_c.size(); } + [[nodiscard]] AllValues get_row(const size_t row_idx) const { AllValues result; - size_t column_idx = 0; // TODO(https://github.com/AztecProtocol/barretenberg/issues/391) zip - for (auto& column : this->_data) { - result[column_idx] = column[row_idx]; - column_idx++; + for (auto [result_field, polynomial] : zip_view(result.pointer_view(), pointer_view())) { + *result_field = (*polynomial)[row_idx]; } return result; } diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/permutation_library.hpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/permutation_library.hpp index 54402dc93bf..0471f818ca6 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/permutation_library.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/permutation_library.hpp @@ -70,8 +70,8 @@ void compute_permutation_grand_product(const size_t circuit_size, for (size_t i = start; i < end; ++i) { typename Flavor::AllValues evaluations; - for (size_t k = 0; k < Flavor::NUM_ALL_ENTITIES; ++k) { - evaluations[k] = full_polynomials[k].size() > i ? full_polynomials[k][i] : 0; + for (auto [eval, poly] : zip_view(evaluations.pointer_view(), full_polynomials.pointer_view())) { + *eval = poly->size() > i ? (*poly)[i] : 0; } numerator[i] = GrandProdRelation::template compute_permutation_numerator(evaluations, relation_parameters); diff --git a/barretenberg/cpp/src/barretenberg/honk/utils/testing.hpp b/barretenberg/cpp/src/barretenberg/honk/utils/testing.hpp index 07275e9327d..fa7c124a843 100644 --- a/barretenberg/cpp/src/barretenberg/honk/utils/testing.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/utils/testing.hpp @@ -27,9 +27,10 @@ get_sequential_prover_polynomials(const size_t log_circuit_size, const size_t st } ProverPolynomials prover_polynomials; + auto prover_polynomials_pointers = prover_polynomials.pointer_view(); size_t poly_idx = 0; for (auto& polynomial : storage) { - prover_polynomials[poly_idx] = polynomial; + *prover_polynomials_pointers[poly_idx] = polynomial; poly_idx++; } @@ -56,8 +57,9 @@ get_zero_prover_polynomials(const size_t log_circuit_size) ProverPolynomials prover_polynomials; size_t poly_idx = 0; + auto prover_polynomial_pointers = prover_polynomials.pointer_view(); for (auto& polynomial : storage) { - prover_polynomials[poly_idx] = polynomial; + *prover_polynomial_pointers[poly_idx] = polynomial; poly_idx++; } diff --git a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/eccvm/eccvm_circuit_builder.hpp b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/eccvm/eccvm_circuit_builder.hpp index 507e5b42c70..07175f9df70 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/eccvm/eccvm_circuit_builder.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/eccvm/eccvm_circuit_builder.hpp @@ -338,8 +338,8 @@ template class ECCVMCircuitBuilder { size_t num_rows_pow2 = 1UL << (num_rows_log2 + (1UL << num_rows_log2 == num_rows ? 0 : 1)); AllPolynomials polys; - for (size_t j = 0; j < NUM_POLYNOMIALS; ++j) { - polys[j] = Polynomial(num_rows_pow2); + for (auto* poly : polys.pointer_view()) { + *poly = Polynomial(num_rows_pow2); } polys.lagrange_first[0] = 1; @@ -502,7 +502,7 @@ template class ECCVMCircuitBuilder { }; auto polynomials = compute_polynomials(); - const size_t num_rows = polynomials[0].size(); + const size_t num_rows = polynomials.get_polynomial_size(); proof_system::honk::lookup_library::compute_logderivative_inverse>( polynomials, params, num_rows); diff --git a/barretenberg/cpp/src/barretenberg/proof_system/library/grand_product_library.hpp b/barretenberg/cpp/src/barretenberg/proof_system/library/grand_product_library.hpp index b23bcdd5ae5..e20214639f8 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/library/grand_product_library.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/library/grand_product_library.hpp @@ -64,13 +64,16 @@ void compute_grand_product(const size_t circuit_size, // Populate `numerator` and `denominator` with the algebra described by Relation const size_t num_threads = circuit_size >= get_num_cpus_pow2() ? get_num_cpus_pow2() : 1; const size_t block_size = circuit_size / num_threads; + auto full_polynomial_pointers = full_polynomials.pointer_view(); parallel_for(num_threads, [&](size_t thread_idx) { const size_t start = thread_idx * block_size; const size_t end = (thread_idx + 1) * block_size; for (size_t i = start; i < end; ++i) { typename Flavor::AllValues evaluations; + auto evaluations_pointer = evaluations.pointer_view(); for (size_t k = 0; k < Flavor::NUM_ALL_ENTITIES; ++k) { - evaluations[k] = full_polynomials[k].size() > i ? full_polynomials[k][i] : 0; + *evaluations_pointer[k] = + (*full_polynomial_pointers[k]).size() > i ? (*full_polynomial_pointers[k])[i] : 0; } numerator[i] = GrandProdRelation::template compute_grand_product_numerator( evaluations, relation_parameters); diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp index de74529838f..f9c3f839867 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp @@ -44,7 +44,7 @@ ProverFoldingResult ProtoGalaxyProver_prover_polynomials[0].size(); + auto instance_size = accumulator->prover_polynomials.get_polynomial_size(); auto log_instance_size = static_cast(numeric::get_msb(instance_size)); auto deltas = compute_round_challenge_pows(log_instance_size, delta); auto perturbator = compute_perturbator(accumulator, deltas, alpha); diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp index cbddd5cbaeb..69329e6b82b 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp @@ -190,9 +190,11 @@ template class ProtoGalaxyProver_ { const ProverInstances& instances, const size_t row_idx) { - for (size_t poly_idx = 0; poly_idx < Flavor::NUM_ALL_ENTITIES; poly_idx++) { + size_t poly_idx = 0; + for (auto* extended_univariate : extended_univariates.pointer_view()) { auto base_univariate = instances.row_to_univariate(poly_idx, row_idx); - extended_univariates[poly_idx] = base_univariate.template extend_to(); + *extended_univariate = base_univariate.template extend_to(); + poly_idx++; } } diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp b/barretenberg/cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp index c887882ab75..52c92c707ec 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp @@ -66,14 +66,15 @@ TYPED_TEST(PartialEvaluationTests, TwoRoundsSpecial) sumcheck.partially_evaluate(full_polynomials, multivariate_n, round_challenge_0); - EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], round_challenge_0); - EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][1], FF(0)); + auto& first_polynomial = *sumcheck.partially_evaluated_polynomials.pointer_view()[0]; + EXPECT_EQ(first_polynomial[0], round_challenge_0); + EXPECT_EQ(first_polynomial[1], FF(0)); FF round_challenge_1 = 2; FF expected_val = expected_lo * (FF(1) - round_challenge_1) + expected_hi * round_challenge_1; sumcheck.partially_evaluate(sumcheck.partially_evaluated_polynomials, multivariate_n >> 1, round_challenge_1); - EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_val); + EXPECT_EQ(first_polynomial[0], expected_val); } TYPED_TEST(PartialEvaluationTests, TwoRoundsGeneric) @@ -101,14 +102,15 @@ TYPED_TEST(PartialEvaluationTests, TwoRoundsGeneric) FF expected_hi = v01 * (FF(1) - round_challenge_0) + v11 * round_challenge_0; sumcheck.partially_evaluate(full_polynomials, multivariate_n, round_challenge_0); + auto& first_polynomial = *sumcheck.partially_evaluated_polynomials.pointer_view()[0]; - EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_lo); - EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][1], expected_hi); + EXPECT_EQ(first_polynomial[0], expected_lo); + EXPECT_EQ(first_polynomial[1], expected_hi); FF round_challenge_1 = FF::random_element(); FF expected_val = expected_lo * (FF(1) - round_challenge_1) + expected_hi * round_challenge_1; sumcheck.partially_evaluate(sumcheck.partially_evaluated_polynomials, multivariate_n >> 1, round_challenge_1); - EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_val); + EXPECT_EQ(first_polynomial[0], expected_val); } /* @@ -165,23 +167,24 @@ TYPED_TEST(PartialEvaluationTests, ThreeRoundsSpecial) sumcheck.partially_evaluate(full_polynomials, multivariate_n, round_challenge_0); - EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_q1); - EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][1], expected_q2); - EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][2], expected_q3); - EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][3], expected_q4); + auto& first_polynomial = *sumcheck.partially_evaluated_polynomials.pointer_view()[0]; + EXPECT_EQ(first_polynomial[0], expected_q1); + EXPECT_EQ(first_polynomial[1], expected_q2); + EXPECT_EQ(first_polynomial[2], expected_q3); + EXPECT_EQ(first_polynomial[3], expected_q4); FF round_challenge_1 = 2; FF expected_lo = expected_q1 * (FF(1) - round_challenge_1) + expected_q2 * round_challenge_1; // 6 FF expected_hi = expected_q3 * (FF(1) - round_challenge_1) + expected_q4 * round_challenge_1; // 10 sumcheck.partially_evaluate(sumcheck.partially_evaluated_polynomials, multivariate_n >> 1, round_challenge_1); - EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_lo); - EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][1], expected_hi); + EXPECT_EQ(first_polynomial[0], expected_lo); + EXPECT_EQ(first_polynomial[1], expected_hi); FF round_challenge_2 = 3; FF expected_val = expected_lo * (FF(1) - round_challenge_2) + expected_hi * round_challenge_2; // 18 sumcheck.partially_evaluate(sumcheck.partially_evaluated_polynomials, multivariate_n >> 2, round_challenge_2); - EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_val); + EXPECT_EQ(first_polynomial[0], expected_val); } TYPED_TEST(PartialEvaluationTests, ThreeRoundsGeneric) @@ -214,25 +217,26 @@ TYPED_TEST(PartialEvaluationTests, ThreeRoundsGeneric) FF expected_q3 = v001 * (FF(1) - round_challenge_0) + v101 * round_challenge_0; FF expected_q4 = v011 * (FF(1) - round_challenge_0) + v111 * round_challenge_0; + auto& first_polynomial = *sumcheck.partially_evaluated_polynomials.pointer_view()[0]; sumcheck.partially_evaluate(full_polynomials, multivariate_n, round_challenge_0); - EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_q1); - EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][1], expected_q2); - EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][2], expected_q3); - EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][3], expected_q4); + EXPECT_EQ(first_polynomial[0], expected_q1); + EXPECT_EQ(first_polynomial[1], expected_q2); + EXPECT_EQ(first_polynomial[2], expected_q3); + EXPECT_EQ(first_polynomial[3], expected_q4); FF round_challenge_1 = FF::random_element(); FF expected_lo = expected_q1 * (FF(1) - round_challenge_1) + expected_q2 * round_challenge_1; FF expected_hi = expected_q3 * (FF(1) - round_challenge_1) + expected_q4 * round_challenge_1; sumcheck.partially_evaluate(sumcheck.partially_evaluated_polynomials, multivariate_n >> 1, round_challenge_1); - EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_lo); - EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][1], expected_hi); + EXPECT_EQ(first_polynomial[0], expected_lo); + EXPECT_EQ(first_polynomial[1], expected_hi); FF round_challenge_2 = FF::random_element(); FF expected_val = expected_lo * (FF(1) - round_challenge_2) + expected_hi * round_challenge_2; sumcheck.partially_evaluate(sumcheck.partially_evaluated_polynomials, multivariate_n >> 2, round_challenge_2); - EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_val); + EXPECT_EQ(first_polynomial[0], expected_val); } TYPED_TEST(PartialEvaluationTests, ThreeRoundsGenericMultiplePolys) @@ -283,11 +287,12 @@ TYPED_TEST(PartialEvaluationTests, ThreeRoundsGenericMultiplePolys) } sumcheck.partially_evaluate(full_polynomials, multivariate_n, round_challenge_0); + auto polynomial_pointer_view = sumcheck.partially_evaluated_polynomials.pointer_view(); for (size_t i = 0; i < 3; i++) { - EXPECT_EQ(sumcheck.partially_evaluated_polynomials[i][0], expected_q1[i]); - EXPECT_EQ(sumcheck.partially_evaluated_polynomials[i][1], expected_q2[i]); - EXPECT_EQ(sumcheck.partially_evaluated_polynomials[i][2], expected_q3[i]); - EXPECT_EQ(sumcheck.partially_evaluated_polynomials[i][3], expected_q4[i]); + EXPECT_EQ((*polynomial_pointer_view[i])[0], expected_q1[i]); + EXPECT_EQ((*polynomial_pointer_view[i])[1], expected_q2[i]); + EXPECT_EQ((*polynomial_pointer_view[i])[2], expected_q3[i]); + EXPECT_EQ((*polynomial_pointer_view[i])[3], expected_q4[i]); } FF round_challenge_1 = FF::random_element(); @@ -299,8 +304,8 @@ TYPED_TEST(PartialEvaluationTests, ThreeRoundsGenericMultiplePolys) } sumcheck.partially_evaluate(sumcheck.partially_evaluated_polynomials, multivariate_n >> 1, round_challenge_1); for (size_t i = 0; i < 3; i++) { - EXPECT_EQ(sumcheck.partially_evaluated_polynomials[i][0], expected_lo[i]); - EXPECT_EQ(sumcheck.partially_evaluated_polynomials[i][1], expected_hi[i]); + EXPECT_EQ((*polynomial_pointer_view[i])[0], expected_lo[i]); + EXPECT_EQ((*polynomial_pointer_view[i])[1], expected_hi[i]); } FF round_challenge_2 = FF::random_element(); std::array expected_val; @@ -309,7 +314,7 @@ TYPED_TEST(PartialEvaluationTests, ThreeRoundsGenericMultiplePolys) } sumcheck.partially_evaluate(sumcheck.partially_evaluated_polynomials, multivariate_n >> 2, round_challenge_2); for (size_t i = 0; i < 3; i++) { - EXPECT_EQ(sumcheck.partially_evaluated_polynomials[i][0], expected_val[i]); + EXPECT_EQ((*polynomial_pointer_view[i])[0], expected_val[i]); } } diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.hpp b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.hpp index 29a82b4f556..4bfc6d8f5f5 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.hpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.hpp @@ -111,11 +111,9 @@ template class SumcheckProver { // Final round: Extract multivariate evaluations from partially_evaluated_polynomials and add to transcript ClaimedEvaluations multivariate_evaluations; - size_t evaluation_idx = 0; - // TODO(https://github.com/AztecProtocol/barretenberg/issues/391) zip - for (auto& polynomial : partially_evaluated_polynomials) { - multivariate_evaluations[evaluation_idx] = polynomial[0]; - ++evaluation_idx; + for (auto [eval, poly] : + zip_view(multivariate_evaluations.pointer_view(), partially_evaluated_polynomials.pointer_view())) { + *eval = (*poly)[0]; } transcript.send_to_verifier("Sumcheck:evaluations", multivariate_evaluations._data); @@ -145,15 +143,31 @@ template class SumcheckProver { * \- v5 X0 (1-X1) X2 --/ / * g3 -- v6 (1-X0) X1 X2 --- (v6(1-X0) + v7 X0) X1 X2 -/ * \- v7 X0 X1 X2 --/ - * - * @param challenge */ void partially_evaluate(auto& polynomials, size_t round_size, FF round_challenge) { + auto pep_view = partially_evaluated_polynomials.pointer_view(); + auto poly_view = polynomials.pointer_view(); + // after the first round, operate in place on partially_evaluated_polynomials + parallel_for(polynomials.size(), [&](size_t j) { + for (size_t i = 0; i < round_size; i += 2) { + (*pep_view[j])[i >> 1] = + (*poly_view[j])[i] + round_challenge * ((*poly_view[j])[i + 1] - (*poly_view[j])[i]); + } + }); + }; + /** + * @brief Evaluate at the round challenge and prepare class for next round. + * Specialization for array, see generic version above. + */ + template + void partially_evaluate(std::array& polynomials, size_t round_size, FF round_challenge) + { + auto pep_view = partially_evaluated_polynomials.pointer_view(); // after the first round, operate in place on partially_evaluated_polynomials parallel_for(polynomials.size(), [&](size_t j) { for (size_t i = 0; i < round_size; i += 2) { - partially_evaluated_polynomials[j][i >> 1] = + (*pep_view[j])[i >> 1] = polynomials[j][i] + round_challenge * (polynomials[j][i + 1] - polynomials[j][i]); } }); diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.test.cpp b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.test.cpp index f175bdf7361..a641599f5fb 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.test.cpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.test.cpp @@ -136,23 +136,26 @@ TEST_F(SumcheckTests, PolynomialNormalization) FF l_7 = ( u_0) * ( u_1) * ( u_2); // clang-format on FF hand_computed_value; - for (size_t i = 0; i < NUM_POLYNOMIALS; i++) { + auto partially_evaluated_polynomials_array = sumcheck.partially_evaluated_polynomials.pointer_view(); + size_t i = 0; + for (auto* full_polynomial_pointer : full_polynomials.pointer_view()) { // full_polynomials[0][0] = w_l[0], full_polynomials[1][1] = w_r[1], and so on. - hand_computed_value = l_0 * full_polynomials[i][0] + l_1 * full_polynomials[i][1] + - l_2 * full_polynomials[i][2] + l_3 * full_polynomials[i][3] + - l_4 * full_polynomials[i][4] + l_5 * full_polynomials[i][5] + - l_6 * full_polynomials[i][6] + l_7 * full_polynomials[i][7]; - EXPECT_EQ(hand_computed_value, sumcheck.partially_evaluated_polynomials[i][0]); + hand_computed_value = l_0 * (*full_polynomial_pointer)[0] + l_1 * (*full_polynomial_pointer)[1] + + l_2 * (*full_polynomial_pointer)[2] + l_3 * (*full_polynomial_pointer)[3] + + l_4 * (*full_polynomial_pointer)[4] + l_5 * (*full_polynomial_pointer)[5] + + l_6 * (*full_polynomial_pointer)[6] + l_7 * (*full_polynomial_pointer)[7]; + EXPECT_EQ(hand_computed_value, (*partially_evaluated_polynomials_array[i])[0]); + i++; } // We can also check the correctness of the multilinear evaluations produced by Sumcheck by directly evaluating the // full polynomials at challenge u via the evaluate_mle() function std::vector u_challenge = { u_0, u_1, u_2 }; - for (size_t i = 0; i < NUM_POLYNOMIALS; i++) { - barretenberg::Polynomial poly(full_polynomials[i]); + for (auto [full_poly, claimed_eval] : + zip_view(full_polynomials.pointer_view(), output.claimed_evaluations.pointer_view())) { + barretenberg::Polynomial poly(*full_poly); auto v_expected = poly.evaluate_mle(u_challenge); - auto v_result = output.claimed_evaluations[i]; - EXPECT_EQ(v_expected, v_result); + EXPECT_EQ(v_expected, *claimed_eval); } } @@ -186,8 +189,8 @@ TEST_F(SumcheckTests, Prover) expected_values.emplace_back(expected_lo + expected_hi); } - for (size_t poly_idx = 0; poly_idx < NUM_POLYNOMIALS; poly_idx++) { - EXPECT_EQ(output.claimed_evaluations[poly_idx], expected_values[poly_idx]); + for (auto [eval, expected] : zip_view(output.claimed_evaluations.pointer_view(), expected_values)) { + *eval = expected; } } diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp index f2927c6ae46..5aafd72a24c 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp @@ -87,14 +87,13 @@ template class SumcheckProverRound { */ template void extend_edges(ExtendedEdges& extended_edges, - /* const */ ProverPolynomialsOrPartiallyEvaluatedMultivariates& multivariates, + const ProverPolynomialsOrPartiallyEvaluatedMultivariates& multivariates, size_t edge_idx) { - size_t univariate_idx = 0; // TODO(https://github.com/AztecProtocol/barretenberg/issues/391) zip - for (auto& poly : multivariates) { - auto edge = barretenberg::Univariate({ poly[edge_idx], poly[edge_idx + 1] }); - extended_edges[univariate_idx] = edge.template extend_to(); - ++univariate_idx; + for (auto [extended_edge, multivariate] : + zip_view(extended_edges.pointer_view(), multivariates.pointer_view())) { + auto edge = barretenberg::Univariate({ (*multivariate)[edge_idx], (*multivariate)[edge_idx + 1] }); + *extended_edge = edge.template extend_to(); } } diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/relation_correctness.test.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/relation_correctness.test.cpp index 7e515a42823..812982026f4 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/relation_correctness.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/relation_correctness.test.cpp @@ -38,10 +38,8 @@ template void check_relation(auto circuit_s // Extract an array containing all the polynomial evaluations at a given row i AllValues evaluations_at_index_i; - size_t poly_idx = 0; - for (auto& poly : polynomials) { - evaluations_at_index_i[poly_idx] = poly[i]; - ++poly_idx; + for (auto [eval, poly] : zip_view(evaluations_at_index_i.pointer_view(), polynomials.pointer_view())) { + *eval = (*poly)[i]; } // Define the appropriate SumcheckArrayOfValuesOverSubrelations type for this relation and initialize to zero @@ -345,10 +343,11 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorPermutationRelationCorrectness) // Create storage for polynomials ProverPolynomials prover_polynomials; std::vector polynomial_container; + auto polynomial_pointer_view = prover_polynomials.pointer_view(); for (size_t i = 0; i < prover_polynomials.size(); i++) { Polynomial temporary_polynomial(circuit_size); polynomial_container.push_back(temporary_polynomial); - prover_polynomials[i] = polynomial_container[i]; + *polynomial_pointer_view[i] = polynomial_container[i]; } // Fill in lagrange polynomials used in the permutation relation @@ -464,11 +463,12 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorGenPermSortRelationCorrectness) ProverPolynomials prover_polynomials; std::vector polynomial_container; + auto polynomial_pointer_view = prover_polynomials.pointer_view(); // Allocate polynomials for (size_t i = 0; i < prover_polynomials.size(); i++) { Polynomial temporary_polynomial(circuit_size); polynomial_container.push_back(temporary_polynomial); - prover_polynomials[i] = polynomial_container[i]; + *polynomial_pointer_view[i] = polynomial_container[i]; } // Construct lagrange polynomials that are needed for Goblin Translator's GenPermSort Relation @@ -558,6 +558,7 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorExtraRelationsCorrectness) ProverPolynomials prover_polynomials; // We use polynomial ids to make shifting the polynomials easier ProverPolynomialIds prover_polynomial_ids; + auto polynomial_id_pointer_view = prover_polynomial_ids.pointer_view(); std::vector polynomial_container; std::vector polynomial_ids; for (size_t i = 0; i < prover_polynomials.size(); i++) { @@ -566,7 +567,7 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorExtraRelationsCorrectness) polynomial_container.push_back(temporary_polynomial); // Push sequential ids to polynomial ids polynomial_ids.push_back(i); - prover_polynomial_ids[i] = polynomial_ids[i]; + *polynomial_id_pointer_view[i] = polynomial_ids[i]; } // Get ids of shifted polynomials and put them in a set auto shifted_ids = prover_polynomial_ids.get_shifted(); @@ -575,9 +576,10 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorExtraRelationsCorrectness) shifted_id_set.emplace(id); } // Assign spans to non-shifted prover polynomials + auto polynomial_pointer_view = prover_polynomials.pointer_view(); for (size_t i = 0; i < prover_polynomials.size(); i++) { if (!shifted_id_set.contains(i)) { - prover_polynomials[i] = polynomial_container[i]; + *polynomial_pointer_view[i] = polynomial_container[i]; } } @@ -585,7 +587,7 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorExtraRelationsCorrectness) for (size_t i = 0; i < shifted_ids.size(); i++) { auto shifted_id = shifted_ids[i]; auto to_be_shifted_id = prover_polynomial_ids.get_to_be_shifted()[i]; - prover_polynomials[shifted_id] = polynomial_container[to_be_shifted_id].shifted(); + *polynomial_pointer_view[shifted_id] = polynomial_container[to_be_shifted_id].shifted(); } // Fill in lagrange even polynomial @@ -656,13 +658,15 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorDecompositionRelationCorrectnes ProverPolynomialIds prover_polynomial_ids; std::vector polynomial_container; std::vector polynomial_ids; + auto polynomial_id_pointer_view = prover_polynomial_ids.pointer_view(); + auto polynomial_pointer_view = prover_polynomials.pointer_view(); for (size_t i = 0; i < prover_polynomials.size(); i++) { Polynomial temporary_polynomial(circuit_size); // Allocate polynomials polynomial_container.push_back(temporary_polynomial); // Push sequential ids to polynomial ids polynomial_ids.push_back(i); - prover_polynomial_ids[i] = polynomial_ids[i]; + *polynomial_id_pointer_view[i] = polynomial_ids[i]; } // Get ids of shifted polynomials and put them in a set auto shifted_ids = prover_polynomial_ids.get_shifted(); @@ -673,7 +677,7 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorDecompositionRelationCorrectnes // Assign spans to non-shifted prover polynomials for (size_t i = 0; i < prover_polynomials.size(); i++) { if (!shifted_id_set.contains(i)) { - prover_polynomials[i] = polynomial_container[i]; + *polynomial_pointer_view[i] = polynomial_container[i]; } } @@ -681,7 +685,7 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorDecompositionRelationCorrectnes for (size_t i = 0; i < shifted_ids.size(); i++) { auto shifted_id = shifted_ids[i]; auto to_be_shifted_id = prover_polynomial_ids.get_to_be_shifted()[i]; - prover_polynomials[shifted_id] = polynomial_container[to_be_shifted_id].shifted(); + *polynomial_pointer_view[shifted_id] = polynomial_container[to_be_shifted_id].shifted(); } // Fill in lagrange odd polynomial (the only non-witness one we are using) @@ -1073,13 +1077,15 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorNonNativeRelationCorrectness) ProverPolynomialIds prover_polynomial_ids; std::vector polynomial_container; std::vector polynomial_ids; + auto polynomial_pointer_view = prover_polynomials.pointer_view(); + auto polynomial_id_pointer_view = prover_polynomial_ids.pointer_view(); for (size_t i = 0; i < prover_polynomials.size(); i++) { Polynomial temporary_polynomial(circuit_size); // Allocate polynomials polynomial_container.push_back(temporary_polynomial); // Push sequential ids to polynomial ids polynomial_ids.push_back(i); - prover_polynomial_ids[i] = polynomial_ids[i]; + *polynomial_id_pointer_view[i] = polynomial_ids[i]; } // Get ids of shifted polynomials and put them in a set auto shifted_ids = prover_polynomial_ids.get_shifted(); @@ -1090,7 +1096,7 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorNonNativeRelationCorrectness) // Assign spans to non-shifted prover polynomials for (size_t i = 0; i < prover_polynomials.size(); i++) { if (!shifted_id_set.contains(i)) { - prover_polynomials[i] = polynomial_container[i]; + *polynomial_pointer_view[i] = polynomial_container[i]; } } @@ -1098,7 +1104,7 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorNonNativeRelationCorrectness) for (size_t i = 0; i < shifted_ids.size(); i++) { auto shifted_id = shifted_ids[i]; auto to_be_shifted_id = prover_polynomial_ids.get_to_be_shifted()[i]; - prover_polynomials[shifted_id] = polynomial_container[to_be_shifted_id].shifted(); + *polynomial_pointer_view[shifted_id] = polynomial_container[to_be_shifted_id].shifted(); } // Copy values of wires used in the non-native field relation from the circuit builder