From b0fc1138864ae46e40d5bf12e85b238f08f91695 Mon Sep 17 00:00:00 2001 From: Rumata888 Date: Thu, 8 Jun 2023 18:07:49 +0000 Subject: [PATCH 1/6] WIP --- .../ultra_circuit_constructor.cpp | 7 ++- .../proof_system/plookup_tables/filler.hpp | 56 +++++++++++++++++++ .../plookup_tables/plookup_tables.cpp | 1 + .../plookup_tables/plookup_tables.hpp | 7 +++ .../proof_system/plookup_tables/types.hpp | 4 ++ 5 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 cpp/src/barretenberg/proof_system/plookup_tables/filler.hpp diff --git a/cpp/src/barretenberg/proof_system/circuit_constructors/ultra_circuit_constructor.cpp b/cpp/src/barretenberg/proof_system/circuit_constructors/ultra_circuit_constructor.cpp index f8b3ddc02b..4299422e8b 100644 --- a/cpp/src/barretenberg/proof_system/circuit_constructors/ultra_circuit_constructor.cpp +++ b/cpp/src/barretenberg/proof_system/circuit_constructors/ultra_circuit_constructor.cpp @@ -100,18 +100,21 @@ void UltraCircuitConstructor::add_gates_to_ensure_all_polys_are_non_zero() // to get a non-zero value in table_4. I assume this index is arbitrary and could // start from 1 instead of 0? uint32_t left_value = 3; - uint32_t right_value = 5; + uint32_t right_value = 3; fr left_witness_value = fr{ left_value, 0, 0, 0 }.to_montgomery_form(); fr right_witness_value = fr{ right_value, 0, 0, 0 }.to_montgomery_form(); uint32_t left_witness_index = add_variable(left_witness_value); uint32_t right_witness_index = add_variable(right_witness_value); - + const auto filler_accumulators = plookup::get_lookup_accumulators( + plookup::MultiTableId::HONK_FILLER_MULTI, left_witness_value, right_witness_value, true); const auto and_accumulators = plookup::get_lookup_accumulators( plookup::MultiTableId::UINT32_AND, left_witness_value, right_witness_value, true); const auto xor_accumulators = plookup::get_lookup_accumulators( plookup::MultiTableId::UINT32_XOR, left_witness_value, right_witness_value, true); + create_gates_from_plookup_accumulators( + plookup::MultiTableId::HONK_FILLER_MULTI, filler_accumulators, left_witness_index, right_witness_index); create_gates_from_plookup_accumulators( plookup::MultiTableId::UINT32_AND, and_accumulators, left_witness_index, right_witness_index); diff --git a/cpp/src/barretenberg/proof_system/plookup_tables/filler.hpp b/cpp/src/barretenberg/proof_system/plookup_tables/filler.hpp new file mode 100644 index 0000000000..ab319a5784 --- /dev/null +++ b/cpp/src/barretenberg/proof_system/plookup_tables/filler.hpp @@ -0,0 +1,56 @@ +#pragma once + +#include "types.hpp" + +namespace plookup { +namespace filler_tables { + +inline std::array get_and_rotate_values_from_key(const std::array) +{ + return { 0x1337ULL, 0ULL }; +} +inline BasicTable generate_honk_filler_table(const BasicTableId id, const size_t table_index) +{ + + const size_t base = 1 << 1; // Probably has to be a power of 2 + BasicTable table; + table.id = id; + table.table_index = table_index; + table.size = base * base; + table.use_twin_keys = true; + for (uint64_t i = 0; i < base; ++i) { + for (uint64_t j = 0; j < base; ++j) { + table.column_1.emplace_back(i); + table.column_2.emplace_back(j); + table.column_3.emplace_back(0x1337ULL + i * 3 + j * 4 + id * 0x1337); + } + } + + table.get_values_from_key = &get_and_rotate_values_from_key; + + table.column_1_step_size = base; + table.column_2_step_size = base; + table.column_3_step_size = base; + + return table; +} +inline MultiTable get_honk_filler_multitable() +{ + const MultiTableId id = HONK_FILLER_MULTI; + const size_t number_of_elements_in_argument = 1 << 1; // Probably has to be a power of 2 + const size_t number_of_lookups = 2; + MultiTable table(number_of_elements_in_argument, + number_of_elements_in_argument, + number_of_elements_in_argument, + number_of_lookups); + table.id = id; + table.slice_sizes.emplace_back(number_of_elements_in_argument); + table.lookup_ids.emplace_back(HONK_FILLER_BASIC1); + table.get_table_values.emplace_back(&get_and_rotate_values_from_key); + table.slice_sizes.emplace_back(number_of_elements_in_argument); + table.lookup_ids.emplace_back(HONK_FILLER_BASIC2); + table.get_table_values.emplace_back(&get_and_rotate_values_from_key); + return table; +} +} // namespace filler_tables +} // namespace plookup \ No newline at end of file diff --git a/cpp/src/barretenberg/proof_system/plookup_tables/plookup_tables.cpp b/cpp/src/barretenberg/proof_system/plookup_tables/plookup_tables.cpp index b0f2528224..fa026ba376 100644 --- a/cpp/src/barretenberg/proof_system/plookup_tables/plookup_tables.cpp +++ b/cpp/src/barretenberg/proof_system/plookup_tables/plookup_tables.cpp @@ -96,6 +96,7 @@ void init_multi_tables() MULTI_TABLES[(size_t)MultiTableId::KECCAK_NORMALIZE_AND_ROTATE + i] = keccak_tables::Rho<8, i>::get_rho_output_table(MultiTableId::KECCAK_NORMALIZE_AND_ROTATE); }); + MULTI_TABLES[MultiTableId::HONK_FILLER_MULTI] = filler_tables::get_honk_filler_multitable(); } } // namespace diff --git a/cpp/src/barretenberg/proof_system/plookup_tables/plookup_tables.hpp b/cpp/src/barretenberg/proof_system/plookup_tables/plookup_tables.hpp index a6f46d3c49..ac988d9092 100644 --- a/cpp/src/barretenberg/proof_system/plookup_tables/plookup_tables.hpp +++ b/cpp/src/barretenberg/proof_system/plookup_tables/plookup_tables.hpp @@ -14,6 +14,7 @@ #include "keccak/keccak_output.hpp" #include "keccak/keccak_rho.hpp" #include "keccak/keccak_theta.hpp" +#include "filler.hpp" namespace plookup { @@ -242,6 +243,12 @@ inline BasicTable create_basic_table(const BasicTableId id, const size_t index) case PEDERSEN_IV_BASE: { return pedersen_tables::basic::generate_pedersen_iv_table(PEDERSEN_IV_BASE); } + case HONK_FILLER_BASIC1: { + return filler_tables::generate_honk_filler_table(HONK_FILLER_BASIC1, index); + } + case HONK_FILLER_BASIC2: { + return filler_tables::generate_honk_filler_table(HONK_FILLER_BASIC2, index); + } case KECCAK_INPUT: { return keccak_tables::KeccakInput::generate_keccak_input_table(KECCAK_INPUT, index); } diff --git a/cpp/src/barretenberg/proof_system/plookup_tables/types.hpp b/cpp/src/barretenberg/proof_system/plookup_tables/types.hpp index 0337e1553a..79b44294bf 100644 --- a/cpp/src/barretenberg/proof_system/plookup_tables/types.hpp +++ b/cpp/src/barretenberg/proof_system/plookup_tables/types.hpp @@ -83,6 +83,8 @@ enum BasicTableId { PEDERSEN_1, PEDERSEN_0, PEDERSEN_IV_BASE, + HONK_FILLER_BASIC1, + HONK_FILLER_BASIC2, KECCAK_INPUT, KECCAK_THETA, KECCAK_RHO, @@ -136,6 +138,7 @@ enum MultiTableId { BLAKE_XOR_ROTATE_8, BLAKE_XOR_ROTATE_7, PEDERSEN_IV, + HONK_FILLER_MULTI, KECCAK_THETA_OUTPUT, KECCAK_CHI_OUTPUT, KECCAK_FORMAT_INPUT, @@ -145,6 +148,7 @@ enum MultiTableId { }; struct MultiTable { + // Coefficients are accumulated products of corresponding step sizes until that point std::vector column_1_coefficients; std::vector column_2_coefficients; std::vector column_3_coefficients; From 26558e2d53072c24a7b59dd8bb14215831cc18fe Mon Sep 17 00:00:00 2001 From: Rumata888 Date: Wed, 14 Jun 2023 15:02:21 +0000 Subject: [PATCH 2/6] Fixed the s_randomness problem --- .../ultra_honk_composer_helper.cpp | 34 +++---------- .../ultra_honk_composer_helper.hpp | 6 --- .../composer/ultra_honk_composer.test.cpp | 3 +- .../ultra_circuit_constructor.cpp | 9 ---- .../proof_system/plookup_tables/filler.hpp | 51 ++++++++++++++++--- .../plookup_tables/plookup_tables.hpp | 4 +- 6 files changed, 56 insertions(+), 51 deletions(-) diff --git a/cpp/src/barretenberg/honk/composer/composer_helper/ultra_honk_composer_helper.cpp b/cpp/src/barretenberg/honk/composer/composer_helper/ultra_honk_composer_helper.cpp index f5c5da1594..6e307fdfe6 100644 --- a/cpp/src/barretenberg/honk/composer/composer_helper/ultra_honk_composer_helper.cpp +++ b/cpp/src/barretenberg/honk/composer/composer_helper/ultra_honk_composer_helper.cpp @@ -58,10 +58,11 @@ void UltraHonkComposerHelper::compute_witness(CircuitConstructor& circuit_constr // TODO(luke): The +1 size for z_lookup is not necessary and can lead to confusion. Resolve. polynomial z_lookup(subgroup_size + 1); // Only instantiated in this function; nothing assigned. - // Save space for adding random scalars in the s polynomial later. The subtracted 1 allows us to insert a `1` at the - // end, to ensure the evaluations (and hence coefficients) aren't all 0. See ComposerBase::compute_proving_key_base - // for further explanation, as a similar trick is done there. - size_t count = subgroup_size - tables_size - lookups_size - s_randomness - 1; + // TODO(kesha): Look at this once we figure out how we do ZK (previously we had roots cut out, so just added + // randomness) + // The size of empty space in sorted polynomials + size_t count = subgroup_size - tables_size - lookups_size; + ASSERT(count > 0); // We need at least 1 row of zeroes for the permutation argument for (size_t i = 0; i < count; ++i) { s_1[i] = 0; s_2[i] = 0; @@ -114,18 +115,7 @@ void UltraHonkComposerHelper::compute_witness(CircuitConstructor& circuit_constr } } - // Initialise the `s_randomness` positions in the s polynomials with 0. - // These will be the positions where we will be adding random scalars to add zero knowledge - // to plookup (search for `Blinding` in plonk/proof_system/widgets/random_widgets/plookup_widget_impl.hpp - // ProverPlookupWidget::compute_sorted_list_polynomial()) - for (size_t i = 0; i < s_randomness; ++i) { - s_1[count] = 0; - s_2[count] = 0; - s_3[count] = 0; - s_4[count] = 0; - ++count; - } - + // Polynomial memory is zeroed out when constructed with size hint, so we don't have to initialize trailing space proving_key->sorted_1 = s_1; proving_key->sorted_2 = s_2; proving_key->sorted_3 = s_3; @@ -209,7 +199,7 @@ std::shared_ptr UltraHonkComposerHe polynomial poly_q_table_column_3(subgroup_size); polynomial poly_q_table_column_4(subgroup_size); - size_t offset = subgroup_size - tables_size - s_randomness - 1; + size_t offset = subgroup_size - tables_size; // Create lookup selector polynomials which interpolate each table column. // Our selector polys always need to interpolate the full subgroup size, so here we offset so as to @@ -238,15 +228,7 @@ std::shared_ptr UltraHonkComposerHe } } - // Initialise the last `s_randomness` positions in table polynomials with 0. We don't need to actually randomise - // the table polynomials. - for (size_t i = 0; i < s_randomness; ++i) { - poly_q_table_column_1[offset] = 0; - poly_q_table_column_2[offset] = 0; - poly_q_table_column_3[offset] = 0; - poly_q_table_column_4[offset] = 0; - ++offset; - } + // Polynomial memory is zeroed out when constructed with size hint, so we don't have to initialize trailing space // // In the case of using UltraPlonkComposer for a circuit which does _not_ make use of any lookup tables, all // four diff --git a/cpp/src/barretenberg/honk/composer/composer_helper/ultra_honk_composer_helper.hpp b/cpp/src/barretenberg/honk/composer/composer_helper/ultra_honk_composer_helper.hpp index 5a13a92f33..b86ca23c36 100644 --- a/cpp/src/barretenberg/honk/composer/composer_helper/ultra_honk_composer_helper.hpp +++ b/cpp/src/barretenberg/honk/composer/composer_helper/ultra_honk_composer_helper.hpp @@ -36,12 +36,6 @@ class UltraHonkComposerHelper { bool contains_recursive_proof = false; bool computed_witness = false; - // This variable controls the amount with which the lookup table and witness values need to be shifted - // above to make room for adding randomness into the permutation and witness polynomials in the plookup widget. - // This must be (num_roots_cut_out_of_the_vanishing_polynomial - 1), since the variable num_roots_cut_out_of_ - // vanishing_polynomial cannot be trivially fetched here, I am directly setting this to 4 - 1 = 3. - static constexpr size_t s_randomness = 3; - explicit UltraHonkComposerHelper(std::shared_ptr crs_factory) : crs_factory_(std::move(crs_factory)) {} diff --git a/cpp/src/barretenberg/honk/composer/ultra_honk_composer.test.cpp b/cpp/src/barretenberg/honk/composer/ultra_honk_composer.test.cpp index 2eb23f820a..1609d42919 100644 --- a/cpp/src/barretenberg/honk/composer/ultra_honk_composer.test.cpp +++ b/cpp/src/barretenberg/honk/composer/ultra_honk_composer.test.cpp @@ -71,8 +71,7 @@ void ensure_non_zero(auto& polynomial) TEST(UltraHonkComposer, ANonZeroPolynomialIsAGoodPolynomial) { auto composer = UltraHonkComposer(); - - composer.add_gates_to_ensure_all_polys_are_non_zero(); + // The composer should call add_gates_to_ensure_all_polys_are_non_zero by default auto prover = composer.create_prover(); auto proof = prover.construct_proof(); diff --git a/cpp/src/barretenberg/proof_system/circuit_constructors/ultra_circuit_constructor.cpp b/cpp/src/barretenberg/proof_system/circuit_constructors/ultra_circuit_constructor.cpp index 4299422e8b..09f3d252af 100644 --- a/cpp/src/barretenberg/proof_system/circuit_constructors/ultra_circuit_constructor.cpp +++ b/cpp/src/barretenberg/proof_system/circuit_constructors/ultra_circuit_constructor.cpp @@ -109,17 +109,8 @@ void UltraCircuitConstructor::add_gates_to_ensure_all_polys_are_non_zero() uint32_t right_witness_index = add_variable(right_witness_value); const auto filler_accumulators = plookup::get_lookup_accumulators( plookup::MultiTableId::HONK_FILLER_MULTI, left_witness_value, right_witness_value, true); - const auto and_accumulators = plookup::get_lookup_accumulators( - plookup::MultiTableId::UINT32_AND, left_witness_value, right_witness_value, true); - const auto xor_accumulators = plookup::get_lookup_accumulators( - plookup::MultiTableId::UINT32_XOR, left_witness_value, right_witness_value, true); create_gates_from_plookup_accumulators( plookup::MultiTableId::HONK_FILLER_MULTI, filler_accumulators, left_witness_index, right_witness_index); - - create_gates_from_plookup_accumulators( - plookup::MultiTableId::UINT32_AND, and_accumulators, left_witness_index, right_witness_index); - create_gates_from_plookup_accumulators( - plookup::MultiTableId::UINT32_XOR, xor_accumulators, left_witness_index, right_witness_index); } /** diff --git a/cpp/src/barretenberg/proof_system/plookup_tables/filler.hpp b/cpp/src/barretenberg/proof_system/plookup_tables/filler.hpp index ab319a5784..d467e26cd6 100644 --- a/cpp/src/barretenberg/proof_system/plookup_tables/filler.hpp +++ b/cpp/src/barretenberg/proof_system/plookup_tables/filler.hpp @@ -1,17 +1,49 @@ #pragma once +/** + * @file filler.hpp + * @author Rumata888 + * @brief This file contains functions for the filler tables that we use in UltraHonk to make table, sorted and lookup + * selector polynomials non-zero. + * + */ #include "types.hpp" namespace plookup { namespace filler_tables { -inline std::array get_and_rotate_values_from_key(const std::array) +/** + * @brief Lookup the value corresponding to a sepcific key + * + * @details We need this function for when we are constructing the circuit and want to query the table. Since we need + * two basic tables to make the table polynomial have non-zero values, we instantiate two tables with the same function, + * but change it slightly through templating + * + * @tparam id The id of the basic table used to parametrize the values for 2 fake tables + * @param key The key that we are looking up + * @return std::array + */ +template inline std::array get_value_from_key(const std::array key) { - return { 0x1337ULL, 0ULL }; + return { key[0] * 3 + key[1] * 4 + id * 0x1337ULL, 0ULL }; } + +/** + * @brief Generate the whole table + * + * @details This function is used to generate the whole table for the table polynomial. It's templated with id, since we + * generate 2 slightly different fake tables. + * + * @tparam table_id The id of the table this function is instantiated for + * @param id Table id that is the same for all circuits + * @param table_index The index for this table that is used in this circuit. 0, 1, ... + * @return A table of values + */ +template inline BasicTable generate_honk_filler_table(const BasicTableId id, const size_t table_index) { + ASSERT(table_id == static_cast(id)); const size_t base = 1 << 1; // Probably has to be a power of 2 BasicTable table; table.id = id; @@ -22,11 +54,11 @@ inline BasicTable generate_honk_filler_table(const BasicTableId id, const size_t for (uint64_t j = 0; j < base; ++j) { table.column_1.emplace_back(i); table.column_2.emplace_back(j); - table.column_3.emplace_back(0x1337ULL + i * 3 + j * 4 + id * 0x1337); + table.column_3.emplace_back(i * 3 + j * 4 + id * 0x1337); } } - table.get_values_from_key = &get_and_rotate_values_from_key; + table.get_values_from_key = &get_value_from_key; table.column_1_step_size = base; table.column_2_step_size = base; @@ -34,6 +66,13 @@ inline BasicTable generate_honk_filler_table(const BasicTableId id, const size_t return table; } +/** + * @brief Create a multitable for filling UltraHonk polynomials with non-zero values + * + * @details Consists of 2 Basic tables that are almost identical. Each of those basic tables should only have 4 entries, + * so the overall overhead is just 8 + * + */ inline MultiTable get_honk_filler_multitable() { const MultiTableId id = HONK_FILLER_MULTI; @@ -46,10 +85,10 @@ inline MultiTable get_honk_filler_multitable() table.id = id; table.slice_sizes.emplace_back(number_of_elements_in_argument); table.lookup_ids.emplace_back(HONK_FILLER_BASIC1); - table.get_table_values.emplace_back(&get_and_rotate_values_from_key); + table.get_table_values.emplace_back(&get_value_from_key); table.slice_sizes.emplace_back(number_of_elements_in_argument); table.lookup_ids.emplace_back(HONK_FILLER_BASIC2); - table.get_table_values.emplace_back(&get_and_rotate_values_from_key); + table.get_table_values.emplace_back(&get_value_from_key); return table; } } // namespace filler_tables diff --git a/cpp/src/barretenberg/proof_system/plookup_tables/plookup_tables.hpp b/cpp/src/barretenberg/proof_system/plookup_tables/plookup_tables.hpp index ac988d9092..0d10613174 100644 --- a/cpp/src/barretenberg/proof_system/plookup_tables/plookup_tables.hpp +++ b/cpp/src/barretenberg/proof_system/plookup_tables/plookup_tables.hpp @@ -244,10 +244,10 @@ inline BasicTable create_basic_table(const BasicTableId id, const size_t index) return pedersen_tables::basic::generate_pedersen_iv_table(PEDERSEN_IV_BASE); } case HONK_FILLER_BASIC1: { - return filler_tables::generate_honk_filler_table(HONK_FILLER_BASIC1, index); + return filler_tables::generate_honk_filler_table(HONK_FILLER_BASIC1, index); } case HONK_FILLER_BASIC2: { - return filler_tables::generate_honk_filler_table(HONK_FILLER_BASIC2, index); + return filler_tables::generate_honk_filler_table(HONK_FILLER_BASIC2, index); } case KECCAK_INPUT: { return keccak_tables::KeccakInput::generate_keccak_input_table(KECCAK_INPUT, index); From ba926f351d0628acb83f568eb545433d67111d4c Mon Sep 17 00:00:00 2001 From: Rumata888 Date: Wed, 14 Jun 2023 15:11:56 +0000 Subject: [PATCH 3/6] WIP --- cpp/src/barretenberg/proof_system/plookup_tables/filler.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/src/barretenberg/proof_system/plookup_tables/filler.hpp b/cpp/src/barretenberg/proof_system/plookup_tables/filler.hpp index d467e26cd6..e57d7881f3 100644 --- a/cpp/src/barretenberg/proof_system/plookup_tables/filler.hpp +++ b/cpp/src/barretenberg/proof_system/plookup_tables/filler.hpp @@ -54,7 +54,7 @@ inline BasicTable generate_honk_filler_table(const BasicTableId id, const size_t for (uint64_t j = 0; j < base; ++j) { table.column_1.emplace_back(i); table.column_2.emplace_back(j); - table.column_3.emplace_back(i * 3 + j * 4 + id * 0x1337); + table.column_3.emplace_back(i * 3 + j * 4 + id * 0x1337ULL); } } From d50a50e8c716a28069d430e6ec1d4380f21f6449 Mon Sep 17 00:00:00 2001 From: Rumata888 Date: Wed, 14 Jun 2023 15:16:14 +0000 Subject: [PATCH 4/6] WIP --- cpp/src/barretenberg/proof_system/plookup_tables/filler.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/src/barretenberg/proof_system/plookup_tables/filler.hpp b/cpp/src/barretenberg/proof_system/plookup_tables/filler.hpp index e57d7881f3..11e7b08837 100644 --- a/cpp/src/barretenberg/proof_system/plookup_tables/filler.hpp +++ b/cpp/src/barretenberg/proof_system/plookup_tables/filler.hpp @@ -54,7 +54,7 @@ inline BasicTable generate_honk_filler_table(const BasicTableId id, const size_t for (uint64_t j = 0; j < base; ++j) { table.column_1.emplace_back(i); table.column_2.emplace_back(j); - table.column_3.emplace_back(i * 3 + j * 4 + id * 0x1337ULL); + table.column_3.emplace_back(i * 3 + j * 4 + static_cast(id) * 0x1337ULL); } } From 4760c436ae8912b65445a2a78250ecd72949ab10 Mon Sep 17 00:00:00 2001 From: Rumata888 Date: Wed, 14 Jun 2023 16:17:31 +0000 Subject: [PATCH 5/6] Renamed to dummy --- .../ultra_circuit_constructor.cpp | 6 ++--- .../plookup_tables/{filler.hpp => dummy.hpp} | 22 +++++++++---------- .../plookup_tables/plookup_tables.cpp | 2 +- .../plookup_tables/plookup_tables.hpp | 10 ++++----- .../proof_system/plookup_tables/types.hpp | 6 ++--- 5 files changed, 23 insertions(+), 23 deletions(-) rename cpp/src/barretenberg/proof_system/plookup_tables/{filler.hpp => dummy.hpp} (85%) diff --git a/cpp/src/barretenberg/proof_system/circuit_constructors/ultra_circuit_constructor.cpp b/cpp/src/barretenberg/proof_system/circuit_constructors/ultra_circuit_constructor.cpp index c5b8dfbb6b..69ece73304 100644 --- a/cpp/src/barretenberg/proof_system/circuit_constructors/ultra_circuit_constructor.cpp +++ b/cpp/src/barretenberg/proof_system/circuit_constructors/ultra_circuit_constructor.cpp @@ -107,10 +107,10 @@ void UltraCircuitConstructor::add_gates_to_ensure_all_polys_are_non_zero() uint32_t left_witness_index = add_variable(left_witness_value); uint32_t right_witness_index = add_variable(right_witness_value); - const auto filler_accumulators = plookup::get_lookup_accumulators( - plookup::MultiTableId::HONK_FILLER_MULTI, left_witness_value, right_witness_value, true); + const auto dummy_accumulators = plookup::get_lookup_accumulators( + plookup::MultiTableId::HONK_DUMMY_MULTI, left_witness_value, right_witness_value, true); create_gates_from_plookup_accumulators( - plookup::MultiTableId::HONK_FILLER_MULTI, filler_accumulators, left_witness_index, right_witness_index); + plookup::MultiTableId::HONK_DUMMY_MULTI, dummy_accumulators, left_witness_index, right_witness_index); } /** diff --git a/cpp/src/barretenberg/proof_system/plookup_tables/filler.hpp b/cpp/src/barretenberg/proof_system/plookup_tables/dummy.hpp similarity index 85% rename from cpp/src/barretenberg/proof_system/plookup_tables/filler.hpp rename to cpp/src/barretenberg/proof_system/plookup_tables/dummy.hpp index 11e7b08837..9231a759b0 100644 --- a/cpp/src/barretenberg/proof_system/plookup_tables/filler.hpp +++ b/cpp/src/barretenberg/proof_system/plookup_tables/dummy.hpp @@ -1,8 +1,8 @@ #pragma once /** - * @file filler.hpp + * @file dummy.hpp * @author Rumata888 - * @brief This file contains functions for the filler tables that we use in UltraHonk to make table, sorted and lookup + * @brief This file contains functions for the dummy tables that we use in UltraHonk to make table, sorted and lookup * selector polynomials non-zero. * */ @@ -10,7 +10,7 @@ #include "types.hpp" namespace plookup { -namespace filler_tables { +namespace dummy_tables { /** * @brief Lookup the value corresponding to a sepcific key @@ -40,7 +40,7 @@ template inline std::array get_value_from_key * @return A table of values */ template -inline BasicTable generate_honk_filler_table(const BasicTableId id, const size_t table_index) +inline BasicTable generate_honk_dummy_table(const BasicTableId id, const size_t table_index) { ASSERT(table_id == static_cast(id)); @@ -73,9 +73,9 @@ inline BasicTable generate_honk_filler_table(const BasicTableId id, const size_t * so the overall overhead is just 8 * */ -inline MultiTable get_honk_filler_multitable() +inline MultiTable get_honk_dummy_multitable() { - const MultiTableId id = HONK_FILLER_MULTI; + const MultiTableId id = HONK_DUMMY_MULTI; const size_t number_of_elements_in_argument = 1 << 1; // Probably has to be a power of 2 const size_t number_of_lookups = 2; MultiTable table(number_of_elements_in_argument, @@ -84,12 +84,12 @@ inline MultiTable get_honk_filler_multitable() number_of_lookups); table.id = id; table.slice_sizes.emplace_back(number_of_elements_in_argument); - table.lookup_ids.emplace_back(HONK_FILLER_BASIC1); - table.get_table_values.emplace_back(&get_value_from_key); + table.lookup_ids.emplace_back(HONK_DUMMY_BASIC1); + table.get_table_values.emplace_back(&get_value_from_key); table.slice_sizes.emplace_back(number_of_elements_in_argument); - table.lookup_ids.emplace_back(HONK_FILLER_BASIC2); - table.get_table_values.emplace_back(&get_value_from_key); + table.lookup_ids.emplace_back(HONK_DUMMY_BASIC2); + table.get_table_values.emplace_back(&get_value_from_key); return table; } -} // namespace filler_tables +} // namespace dummy_tables } // namespace plookup \ No newline at end of file diff --git a/cpp/src/barretenberg/proof_system/plookup_tables/plookup_tables.cpp b/cpp/src/barretenberg/proof_system/plookup_tables/plookup_tables.cpp index fa026ba376..6580a47e8e 100644 --- a/cpp/src/barretenberg/proof_system/plookup_tables/plookup_tables.cpp +++ b/cpp/src/barretenberg/proof_system/plookup_tables/plookup_tables.cpp @@ -96,7 +96,7 @@ void init_multi_tables() MULTI_TABLES[(size_t)MultiTableId::KECCAK_NORMALIZE_AND_ROTATE + i] = keccak_tables::Rho<8, i>::get_rho_output_table(MultiTableId::KECCAK_NORMALIZE_AND_ROTATE); }); - MULTI_TABLES[MultiTableId::HONK_FILLER_MULTI] = filler_tables::get_honk_filler_multitable(); + MULTI_TABLES[MultiTableId::HONK_DUMMY_MULTI] = dummy_tables::get_honk_dummy_multitable(); } } // namespace diff --git a/cpp/src/barretenberg/proof_system/plookup_tables/plookup_tables.hpp b/cpp/src/barretenberg/proof_system/plookup_tables/plookup_tables.hpp index 0d10613174..2e674befa2 100644 --- a/cpp/src/barretenberg/proof_system/plookup_tables/plookup_tables.hpp +++ b/cpp/src/barretenberg/proof_system/plookup_tables/plookup_tables.hpp @@ -14,7 +14,7 @@ #include "keccak/keccak_output.hpp" #include "keccak/keccak_rho.hpp" #include "keccak/keccak_theta.hpp" -#include "filler.hpp" +#include "dummy.hpp" namespace plookup { @@ -243,11 +243,11 @@ inline BasicTable create_basic_table(const BasicTableId id, const size_t index) case PEDERSEN_IV_BASE: { return pedersen_tables::basic::generate_pedersen_iv_table(PEDERSEN_IV_BASE); } - case HONK_FILLER_BASIC1: { - return filler_tables::generate_honk_filler_table(HONK_FILLER_BASIC1, index); + case HONK_DUMMY_BASIC1: { + return dummy_tables::generate_honk_dummy_table(HONK_DUMMY_BASIC1, index); } - case HONK_FILLER_BASIC2: { - return filler_tables::generate_honk_filler_table(HONK_FILLER_BASIC2, index); + case HONK_DUMMY_BASIC2: { + return dummy_tables::generate_honk_dummy_table(HONK_DUMMY_BASIC2, index); } case KECCAK_INPUT: { return keccak_tables::KeccakInput::generate_keccak_input_table(KECCAK_INPUT, index); diff --git a/cpp/src/barretenberg/proof_system/plookup_tables/types.hpp b/cpp/src/barretenberg/proof_system/plookup_tables/types.hpp index 79b44294bf..f6c7c0f6df 100644 --- a/cpp/src/barretenberg/proof_system/plookup_tables/types.hpp +++ b/cpp/src/barretenberg/proof_system/plookup_tables/types.hpp @@ -83,8 +83,8 @@ enum BasicTableId { PEDERSEN_1, PEDERSEN_0, PEDERSEN_IV_BASE, - HONK_FILLER_BASIC1, - HONK_FILLER_BASIC2, + HONK_DUMMY_BASIC1, + HONK_DUMMY_BASIC2, KECCAK_INPUT, KECCAK_THETA, KECCAK_RHO, @@ -138,7 +138,7 @@ enum MultiTableId { BLAKE_XOR_ROTATE_8, BLAKE_XOR_ROTATE_7, PEDERSEN_IV, - HONK_FILLER_MULTI, + HONK_DUMMY_MULTI, KECCAK_THETA_OUTPUT, KECCAK_CHI_OUTPUT, KECCAK_FORMAT_INPUT, From 30fe0eb08c8d0cce324257560308630bb0d5adcb Mon Sep 17 00:00:00 2001 From: Rumata888 Date: Thu, 15 Jun 2023 14:28:58 +0000 Subject: [PATCH 6/6] Addressed Mara's comments --- .../circuit_constructors/ultra_circuit_constructor.cpp | 8 ++++---- .../barretenberg/proof_system/plookup_tables/dummy.hpp | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/cpp/src/barretenberg/proof_system/circuit_constructors/ultra_circuit_constructor.cpp b/cpp/src/barretenberg/proof_system/circuit_constructors/ultra_circuit_constructor.cpp index 69ece73304..8edd5c7104 100644 --- a/cpp/src/barretenberg/proof_system/circuit_constructors/ultra_circuit_constructor.cpp +++ b/cpp/src/barretenberg/proof_system/circuit_constructors/ultra_circuit_constructor.cpp @@ -93,12 +93,12 @@ void UltraCircuitConstructor::add_gates_to_ensure_all_polys_are_non_zero() create_big_add_gate({ zero_idx, zero_idx, zero_idx, one_idx, 0, 0, 0, 1, -1 }); // Take care of all polys related to lookups (q_lookup, tables, sorted, etc) - // by doing an arbitrary xor and an "and" lookup. + // by doing a dummy lookup with a special table. // Note: the 4th table poly is the table index: this is not the value of the table // type enum but rather the index of the table in the list of all tables utilized - // in the circuit. Therefore we naively need two different tables (indices 0, 1) - // to get a non-zero value in table_4. I assume this index is arbitrary and could - // start from 1 instead of 0? + // in the circuit. Therefore we naively need two different basic tables (indices 0, 1) + // to get a non-zero value in table_4. + // The multitable operates on 2-bit values, so the maximum is 3 uint32_t left_value = 3; uint32_t right_value = 3; diff --git a/cpp/src/barretenberg/proof_system/plookup_tables/dummy.hpp b/cpp/src/barretenberg/proof_system/plookup_tables/dummy.hpp index 9231a759b0..e44ea72e8f 100644 --- a/cpp/src/barretenberg/proof_system/plookup_tables/dummy.hpp +++ b/cpp/src/barretenberg/proof_system/plookup_tables/dummy.hpp @@ -13,7 +13,7 @@ namespace plookup { namespace dummy_tables { /** - * @brief Lookup the value corresponding to a sepcific key + * @brief Lookup the value corresponding to a specific key * * @details We need this function for when we are constructing the circuit and want to query the table. Since we need * two basic tables to make the table polynomial have non-zero values, we instantiate two tables with the same function, @@ -43,6 +43,8 @@ template inline BasicTable generate_honk_dummy_table(const BasicTableId id, const size_t table_index) { + // We do the assertion, since this function is templated, but the general API for these functions contains the id, + // too. This helps us ensure that the correct instantion is used for a particular BasicTableId ASSERT(table_id == static_cast(id)); const size_t base = 1 << 1; // Probably has to be a power of 2 BasicTable table;