From 60f2b1b3b85dfc84d6d14a870281e1936d0daeb4 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Fri, 7 Jun 2024 22:04:17 +0000 Subject: [PATCH 01/42] some initial comments and cleanup --- .../stdlib/primitives/plookup/plookup.cpp | 2 +- .../plookup_tables/plookup_tables.cpp | 67 +++++++++++-------- .../plookup_tables/types.hpp | 27 ++++++-- 3 files changed, 61 insertions(+), 35 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/plookup/plookup.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/plookup/plookup.cpp index 94d8bf089fd..375211e12a0 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/plookup/plookup.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/plookup/plookup.cpp @@ -77,7 +77,7 @@ field_t plookup_read::read_from_2_to_1_table(const MultiTableI const field_t& key_a, const field_t& key_b) { - const auto lookup = get_lookup_accumulators(id, key_a, key_b, true); + const auto lookup = get_lookup_accumulators(id, key_a, key_b, /*is_2_to_1_lookup=*/true); return lookup[ColumnIdx::C3][0]; } diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/plookup_tables.cpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/plookup_tables.cpp index 73e3814cba5..9e5276b6873 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/plookup_tables.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/plookup_tables.cpp @@ -132,6 +132,23 @@ const MultiTable& create_table(const MultiTableId id) return MULTI_TABLES[id]; } +/** + * @brief Given a table ID and the key(s) for a key-value lookup, return the lookup accumulators + * @details In general the number of bits in key/value is greater than what can be efficiently supported in lookup + * tables. For this reason we actually perform lookups on the corresponding limbs. However, since we're interested in + * the full values and not the limbs, its convenient to structure the witnesses of lookup gates to store the former. + * This way we don't have to waste gates reaccumulating the limbs to compute the actual value of interest. The way to do + * this is to populate the wires with 'accumulator' values such that the first gate in the series contains the full + * accumulated values, and successive gates contain prior stages of the accumulator such that wire_i - r*wire_{i-1} = + * v_i, where r = num limb bits and v_i is a limb that explicitly appears in one of the lookup tables. See the detailed + * comment block below for more explanation. + * + * @param id + * @param key_a + * @param key_b + * @param is_2_to_1_lookup + * @return ReadData + */ ReadData get_lookup_accumulators(const MultiTableId id, const fr& key_a, const fr& key_b, @@ -157,14 +174,14 @@ ReadData get_lookup_accumulators(const MultiTableId id, column_2_raw_values.emplace_back(is_2_to_1_lookup ? key_b_slices[i] : values[0]); column_3_raw_values.emplace_back(is_2_to_1_lookup ? values[0] : values[1]); - // Question: why are we storing the key slices twice? - const BasicTable::KeyEntry key_entry{ { key_a_slices[i], key_b_slices[i] }, values }; + // Question: why are we storing the key slices twice? // WORKTODO: resolve question? + const BasicTable::LookupEntry key_entry{ { key_a_slices[i], key_b_slices[i] }, values }; lookup.key_entries.emplace_back(key_entry); } - lookup[ColumnIdx::C1].resize(num_lookups); - lookup[ColumnIdx::C2].resize(num_lookups); - lookup[ColumnIdx::C3].resize(num_lookups); + lookup[C1].resize(num_lookups); + lookup[C2].resize(num_lookups); + lookup[C3].resize(num_lookups); /** * A multi-table consists of multiple basic tables (say L = 6). @@ -178,8 +195,9 @@ ReadData get_lookup_accumulators(const MultiTableId id, * s1 s2 s3 s4 s5 s6 * * Note that different basic tables can be of different sizes. Every lookup query generates L output slices (one for - * each basic table, here, s1, s2, ..., s6). In other words, every lookup query add L lookup gates to the program. - * Let the input slices/keys be (a1, b1), (a2, b2), ..., (a6, b6). The lookup gate structure is as follows: + * each basic table, here, s1, s2, ..., s6). In other words, every lookup query adds L lookup gates to the program. + * For example, to look up the XOR of 32-bit inputs, we actually perform 6 individual lookups on the 6-bit XOR basic + * table. Let the input slices/keys be (a1, b1), (a2, b2), ..., (a6, b6). The lookup gate structure is as follows: * * +---+-----------------------------------+----------------------------------+-----------------------------------+ * | s | key_a | key_b | output | @@ -193,34 +211,25 @@ ReadData get_lookup_accumulators(const MultiTableId id, * +---+-----------------------------------+----------------------------------+-----------------------------------+ * * Note that we compute the accumulating sums of the slices so as to avoid using additonal gates for the purpose of - * reconstructing inputs/outputs. Here, (p, q, r) are referred to as column coefficients/step sizes. - * In the next few lines, we compute these accumulating sums from raw column values (a1, ..., a6), (b1, ..., b6), - * (s1, ..., s6) and column coefficients (p, q, r). + * reconstructing the original inputs/outputs. I.e. the output value at the 0th index in the above table is the + * actual value we were interested in computing in the first place. Importantly, the structure of the remaining rows + * is such that row_i - r*row_{i+1} produces an entry {a_j, b_j, s_j} that exactly corresponds to an entry in a + * BasicTable. This is what gives rise to the wire_i - scalar*wire_i_shift structure in the lookup relation. Here, + * (p, q, r) are referred to as column coefficients/step sizes. In the next few lines, we compute these accumulating + * sums from raw column values (a1, ..., a6), (b1, ..., b6), (s1, ..., s6) and column coefficients (p, q, r). * * For more details: see * https://app.gitbook.com/o/-LgCgJ8TCO7eGlBr34fj/s/-MEwtqp3H6YhHUTQ_pVJ/plookup-gates-for-ultraplonk/lookup-table-structures * */ - lookup[ColumnIdx::C1][num_lookups - 1] = column_1_raw_values[num_lookups - 1]; - lookup[ColumnIdx::C2][num_lookups - 1] = column_2_raw_values[num_lookups - 1]; - lookup[ColumnIdx::C3][num_lookups - 1] = column_3_raw_values[num_lookups - 1]; + lookup[C1][num_lookups - 1] = column_1_raw_values[num_lookups - 1]; + lookup[C2][num_lookups - 1] = column_2_raw_values[num_lookups - 1]; + lookup[C3][num_lookups - 1] = column_3_raw_values[num_lookups - 1]; - for (size_t i = 1; i < num_lookups; ++i) { - const auto& previous_1 = lookup[ColumnIdx::C1][num_lookups - i]; - const auto& previous_2 = lookup[ColumnIdx::C2][num_lookups - i]; - const auto& previous_3 = lookup[ColumnIdx::C3][num_lookups - i]; - - auto& current_1 = lookup[ColumnIdx::C1][num_lookups - 1 - i]; - auto& current_2 = lookup[ColumnIdx::C2][num_lookups - 1 - i]; - auto& current_3 = lookup[ColumnIdx::C3][num_lookups - 1 - i]; - - const auto& raw_1 = column_1_raw_values[num_lookups - 1 - i]; - const auto& raw_2 = column_2_raw_values[num_lookups - 1 - i]; - const auto& raw_3 = column_3_raw_values[num_lookups - 1 - i]; - - current_1 = raw_1 + previous_1 * multi_table.column_1_step_sizes[num_lookups - i]; - current_2 = raw_2 + previous_2 * multi_table.column_2_step_sizes[num_lookups - i]; - current_3 = raw_3 + previous_3 * multi_table.column_3_step_sizes[num_lookups - i]; + for (size_t i = num_lookups - 1; i > 0; --i) { + lookup[C1][i - 1] = column_1_raw_values[i - 1] + lookup[C1][i] * multi_table.column_1_step_sizes[i]; + lookup[C2][i - 1] = column_2_raw_values[i - 1] + lookup[C2][i] * multi_table.column_2_step_sizes[i]; + lookup[C3][i - 1] = column_3_raw_values[i - 1] + lookup[C3][i] * multi_table.column_3_step_sizes[i]; } return lookup; } diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/types.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/types.hpp index 0dfcaa916d3..2c1f6ff92d4 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/types.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/types.hpp @@ -121,6 +121,19 @@ enum MultiTableId { NUM_MULTI_TABLES = KECCAK_NORMALIZE_AND_ROTATE + 25, }; +/** + * @brief Container for managing multiple BasicTables plus the data needed to combine basic table outputs (limbs) into + * accumulators + * @details As a simple example, consider using lookups to compute XOR on uint32_t inputs. To do this we decompose the + * inputs into 6 limbs and use a BasicTable for 6-bit XOR lookups. In this case the MultiTable simply manages 6 basic + * tables, all of which are the XOR BasicTable. (In many cases all of the BasicTables managed by a MultiTable are + * identical, however there are some cases where more than 1 type is required, e.g. if a certain limb has to be handled + * differently). This class also stores the scalars needed to reconstruct full values from the limbs that are contained + * in the basic lookup tables. + * @note Note that a MultiTable does not actually *store* any table data. Rather it stores a set of basic table IDs, the + * methods used to compute the basic table entries, plus some metadata. + * + */ struct MultiTable { // Coefficients are accumulated products of corresponding step sizes until that point std::vector column_1_coefficients; @@ -150,6 +163,8 @@ struct MultiTable { bb::fr::batch_invert(&coefficient_inverses[0], num_lookups * 3); + // WORKTODO: in simple cases like XOR, I think every one of these values is 1 << 6. Confirm this. If so, is it + // worth adding logic to not do all this computation? Probably not but it might at least make the code clearer. for (size_t i = 1; i < num_lookups; ++i) { column_1_step_sizes.emplace_back(column_1_coefficients[i] * coefficient_inverses[i - 1]); column_2_step_sizes.emplace_back(column_2_coefficients[i] * coefficient_inverses[num_lookups + i - 1]); @@ -262,12 +277,14 @@ struct MultiTable { * */ struct BasicTable { - struct KeyEntry { - bool operator==(const KeyEntry& other) const = default; + struct LookupEntry { + bool operator==(const LookupEntry& other) const = default; + // Storage for two key values and two result values to support different lookup formats, i.e. 1:1, 1:2, and 2:1 std::array key{ 0, 0 }; std::array value{ bb::fr(0), bb::fr(0) }; - bool operator<(const KeyEntry& other) const + // Comparison operator required for sorting; Used to construct sorted-concatenated table/lookup polynomial + bool operator<(const LookupEntry& other) const { return key[0] < other.key[0] || ((key[0] == other.key[0]) && key[1] < other.key[1]); } @@ -296,7 +313,7 @@ struct BasicTable { std::vector column_1; std::vector column_3; std::vector column_2; - std::vector lookup_gates; + std::vector lookup_gates; std::array (*get_values_from_key)(const std::array); @@ -324,7 +341,7 @@ template class ReadData { std::vector& operator[](ColumnIdx idx) { return columns[static_cast(idx)]; }; const std::vector& operator[](ColumnIdx idx) const { return columns[static_cast(idx)]; }; - std::vector key_entries; + std::vector key_entries; private: std::array, 3> columns; From 760a9fbb20f9bb62984861e07678144edb4d16b5 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Mon, 10 Jun 2024 17:07:56 +0000 Subject: [PATCH 02/42] some naming updates and comments --- .../stdlib/hash/keccak/keccak.cpp | 2 +- .../plookup_tables/aes128.hpp | 6 +++--- .../plookup_tables/blake2s.hpp | 16 +++++++------- .../plookup_tables/dummy.hpp | 4 ++-- .../plookup_tables/fixed_base/fixed_base.cpp | 4 ++-- .../plookup_tables/keccak/keccak_chi.hpp | 2 +- .../plookup_tables/keccak/keccak_input.hpp | 2 +- .../plookup_tables/keccak/keccak_output.hpp | 2 +- .../plookup_tables/keccak/keccak_rho.hpp | 4 ++-- .../plookup_tables/keccak/keccak_theta.hpp | 2 +- .../non_native_group_generator.cpp | 16 +++++++------- .../plookup_tables/plookup_tables.cpp | 21 +++++++++++++------ .../plookup_tables/plookup_tables.hpp | 2 +- .../plookup_tables/sha256.hpp | 18 ++++++++-------- .../plookup_tables/types.hpp | 6 +++--- .../plookup_tables/uint.hpp | 4 ++-- .../ultra_circuit_builder.cpp | 7 ++++--- .../ultra_circuit_builder.hpp | 2 +- 18 files changed, 65 insertions(+), 55 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/stdlib/hash/keccak/keccak.cpp b/barretenberg/cpp/src/barretenberg/stdlib/hash/keccak/keccak.cpp index 5ac843e6b8d..ab653fadfb7 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/hash/keccak/keccak.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/hash/keccak/keccak.cpp @@ -126,7 +126,7 @@ field_t keccak::normalize_and_rotate(const field_ct& limb, fie // We need to provide a key/value object for this lookup in order for the Builder // to compute the plookup sorted list commitment const auto [input_quotient, input_slice] = input.divmod(divisor); - lookup.key_entries.push_back( + lookup.lookup_entries.push_back( { { static_cast(input_slice), 0 }, { normalized_slice, normalized_msb } }); // reduce the input and output by 11^{bit_slice} diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/aes128.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/aes128.hpp index f3102bbfd18..be3d5783695 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/aes128.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/aes128.hpp @@ -102,7 +102,7 @@ inline MultiTable get_aes_normalization_table(const MultiTableId id = AES_NORMAL table.id = id; for (size_t i = 0; i < num_entries; ++i) { table.slice_sizes.emplace_back(AES_BASE * AES_BASE * AES_BASE * AES_BASE); - table.lookup_ids.emplace_back(AES_SPARSE_NORMALIZE); + table.basic_table_ids.emplace_back(AES_SPARSE_NORMALIZE); table.get_table_values.emplace_back(&get_aes_sparse_normalization_values_from_key); } return table; @@ -117,7 +117,7 @@ inline MultiTable get_aes_input_table(const MultiTableId id = AES_INPUT) table.id = id; for (size_t i = 0; i < num_entries; ++i) { table.slice_sizes.emplace_back(256); - table.lookup_ids.emplace_back(AES_SPARSE_MAP); + table.basic_table_ids.emplace_back(AES_SPARSE_MAP); table.get_table_values.emplace_back(&sparse_tables::get_sparse_table_with_rotation_values); } return table; @@ -167,7 +167,7 @@ inline MultiTable get_aes_sbox_table(const MultiTableId id = AES_SBOX) table.id = id; for (size_t i = 0; i < num_entries; ++i) { table.slice_sizes.emplace_back(numeric::pow64(AES_BASE, 8)); - table.lookup_ids.emplace_back(AES_SBOX_MAP); + table.basic_table_ids.emplace_back(AES_SBOX_MAP); table.get_table_values.emplace_back(&get_aes_sbox_values_from_key); } return table; diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/blake2s.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/blake2s.hpp index 10a56396e6b..3f55bf2fc50 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/blake2s.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/blake2s.hpp @@ -95,12 +95,12 @@ inline MultiTable get_blake2s_xor_table(const MultiTableId id = BLAKE_XOR) table.id = id; for (size_t i = 0; i < num_entries - 1; ++i) { table.slice_sizes.emplace_back(base); - table.lookup_ids.emplace_back(BLAKE_XOR_ROTATE0); + table.basic_table_ids.emplace_back(BLAKE_XOR_ROTATE0); table.get_table_values.emplace_back(&get_xor_rotate_values_from_key<6, 0>); } table.slice_sizes.emplace_back(SIZE_OF_LAST_SLICE); - table.lookup_ids.emplace_back(BLAKE_XOR_ROTATE0_SLICE5_MOD4); + table.basic_table_ids.emplace_back(BLAKE_XOR_ROTATE0_SLICE5_MOD4); table.get_table_values.emplace_back(&get_xor_rotate_values_from_key); return table; @@ -128,8 +128,8 @@ inline MultiTable get_blake2s_xor_rotate_16_table(const MultiTableId id = BLAKE_ table.id = id; table.slice_sizes = { base, base, base, base, base, SIZE_OF_LAST_SLICE }; - table.lookup_ids = { BLAKE_XOR_ROTATE0, BLAKE_XOR_ROTATE0, BLAKE_XOR_ROTATE4, - BLAKE_XOR_ROTATE0, BLAKE_XOR_ROTATE0, BLAKE_XOR_ROTATE0_SLICE5_MOD4 }; + table.basic_table_ids = { BLAKE_XOR_ROTATE0, BLAKE_XOR_ROTATE0, BLAKE_XOR_ROTATE4, + BLAKE_XOR_ROTATE0, BLAKE_XOR_ROTATE0, BLAKE_XOR_ROTATE0_SLICE5_MOD4 }; table.get_table_values.emplace_back(&get_xor_rotate_values_from_key<6, 0>); table.get_table_values.emplace_back(&get_xor_rotate_values_from_key<6, 0>); @@ -163,8 +163,8 @@ inline MultiTable get_blake2s_xor_rotate_8_table(const MultiTableId id = BLAKE_X table.id = id; table.slice_sizes = { base, base, base, base, base, SIZE_OF_LAST_SLICE }; - table.lookup_ids = { BLAKE_XOR_ROTATE0, BLAKE_XOR_ROTATE2, BLAKE_XOR_ROTATE0, - BLAKE_XOR_ROTATE0, BLAKE_XOR_ROTATE0, BLAKE_XOR_ROTATE0_SLICE5_MOD4 }; + table.basic_table_ids = { BLAKE_XOR_ROTATE0, BLAKE_XOR_ROTATE2, BLAKE_XOR_ROTATE0, + BLAKE_XOR_ROTATE0, BLAKE_XOR_ROTATE0, BLAKE_XOR_ROTATE0_SLICE5_MOD4 }; table.get_table_values.emplace_back(&get_xor_rotate_values_from_key<6, 0>); table.get_table_values.emplace_back(&get_xor_rotate_values_from_key<6, 2>); @@ -198,8 +198,8 @@ inline MultiTable get_blake2s_xor_rotate_7_table(const MultiTableId id = BLAKE_X table.id = id; table.slice_sizes = { base, base, base, base, base, SIZE_OF_LAST_SLICE }; - table.lookup_ids = { BLAKE_XOR_ROTATE0, BLAKE_XOR_ROTATE1, BLAKE_XOR_ROTATE0, - BLAKE_XOR_ROTATE0, BLAKE_XOR_ROTATE0, BLAKE_XOR_ROTATE0_SLICE5_MOD4 }; + table.basic_table_ids = { BLAKE_XOR_ROTATE0, BLAKE_XOR_ROTATE1, BLAKE_XOR_ROTATE0, + BLAKE_XOR_ROTATE0, BLAKE_XOR_ROTATE0, BLAKE_XOR_ROTATE0_SLICE5_MOD4 }; table.get_table_values.emplace_back(&get_xor_rotate_values_from_key<6, 0>); table.get_table_values.emplace_back(&get_xor_rotate_values_from_key<6, 1>); diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/dummy.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/dummy.hpp index f49409c9bbc..3488fbb90b6 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/dummy.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/dummy.hpp @@ -85,10 +85,10 @@ inline MultiTable get_honk_dummy_multitable() number_of_lookups); table.id = id; table.slice_sizes.emplace_back(number_of_elements_in_argument); - table.lookup_ids.emplace_back(HONK_DUMMY_BASIC1); + table.basic_table_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_DUMMY_BASIC2); + table.basic_table_ids.emplace_back(HONK_DUMMY_BASIC2); table.get_table_values.emplace_back(&get_value_from_key); return table; } diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/fixed_base/fixed_base.cpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/fixed_base/fixed_base.cpp index 6a470eb835c..05f54b068e4 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/fixed_base/fixed_base.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/fixed_base/fixed_base.cpp @@ -243,13 +243,13 @@ template MultiTable table::get_fixed_ MultiTable table(MAX_TABLE_SIZE, 0, 0, NUM_TABLES); table.id = id; table.get_table_values.resize(NUM_TABLES); - table.lookup_ids.resize(NUM_TABLES); + table.basic_table_ids.resize(NUM_TABLES); for (size_t i = 0; i < NUM_TABLES; ++i) { table.slice_sizes.emplace_back(MAX_TABLE_SIZE); table.get_table_values[i] = get_values_from_key_table[multitable_index][i]; static_assert(multitable_index < NUM_FIXED_BASE_MULTI_TABLES); size_t idx = i + static_cast(basic_table_ids[multitable_index]); - table.lookup_ids[i] = static_cast(idx); + table.basic_table_ids[i] = static_cast(idx); } return table; } diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/keccak/keccak_chi.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/keccak/keccak_chi.hpp index 0e5b4a8a5c3..b38b6520b29 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/keccak/keccak_chi.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/keccak/keccak_chi.hpp @@ -242,7 +242,7 @@ class Chi { table.id = id; for (size_t i = 0; i < num_tables_per_multitable; ++i) { table.slice_sizes.emplace_back(numeric::pow64(BASE, TABLE_BITS)); - table.lookup_ids.emplace_back(KECCAK_CHI); + table.basic_table_ids.emplace_back(KECCAK_CHI); table.get_table_values.emplace_back(&get_chi_renormalization_values); } return table; diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/keccak/keccak_input.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/keccak/keccak_input.hpp index c3b6d20ae98..e9898c987af 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/keccak/keccak_input.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/keccak/keccak_input.hpp @@ -132,7 +132,7 @@ class KeccakInput { table.id = id; for (size_t i = 0; i < num_entries; ++i) { table.slice_sizes.emplace_back(1 << 8); - table.lookup_ids.emplace_back(KECCAK_INPUT); + table.basic_table_ids.emplace_back(KECCAK_INPUT); table.get_table_values.emplace_back(&get_keccak_input_values); } return table; diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/keccak/keccak_output.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/keccak/keccak_output.hpp index 53f2fc9a53f..6da411892e8 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/keccak/keccak_output.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/keccak/keccak_output.hpp @@ -162,7 +162,7 @@ class KeccakOutput { table.id = id; for (size_t i = 0; i < num_tables_per_multitable; ++i) { table.slice_sizes.emplace_back(numeric::pow64(BASE, TABLE_BITS)); - table.lookup_ids.emplace_back(KECCAK_OUTPUT); + table.basic_table_ids.emplace_back(KECCAK_OUTPUT); table.get_table_values.emplace_back( &sparse_tables::get_sparse_normalization_values); } diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/keccak/keccak_rho.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/keccak/keccak_rho.hpp index c16085aca8a..ef3ddbda46d 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/keccak/keccak_rho.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/keccak/keccak_rho.hpp @@ -264,7 +264,7 @@ template class Rho { table.slice_sizes.push_back(scaled_base); table.get_table_values.emplace_back(&get_rho_renormalization_values); - table.lookup_ids.push_back((BasicTableId)((size_t)KECCAK_RHO_1 + (bit_slice - 1))); + table.basic_table_ids.push_back((BasicTableId)((size_t)KECCAK_RHO_1 + (bit_slice - 1))); }); // generate table selector values for the 'left' slice @@ -284,7 +284,7 @@ template class Rho { table.slice_sizes.push_back(scaled_base); table.get_table_values.emplace_back(&get_rho_renormalization_values); - table.lookup_ids.push_back((BasicTableId)((size_t)KECCAK_RHO_1 + (bit_slice - 1))); + table.basic_table_ids.push_back((BasicTableId)((size_t)KECCAK_RHO_1 + (bit_slice - 1))); }); return table; diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/keccak/keccak_theta.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/keccak/keccak_theta.hpp index 9f05cf94267..7664a0f246c 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/keccak/keccak_theta.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/keccak/keccak_theta.hpp @@ -244,7 +244,7 @@ class Theta { table.id = id; for (size_t i = 0; i < num_tables_per_multitable; ++i) { table.slice_sizes.emplace_back(numeric::pow64(BASE, TABLE_BITS)); - table.lookup_ids.emplace_back(KECCAK_THETA); + table.basic_table_ids.emplace_back(KECCAK_THETA); table.get_table_values.emplace_back(&get_theta_renormalization_values); } return table; diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/non_native_group_generator.cpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/non_native_group_generator.cpp index ed172573e24..9d09ceefedb 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/non_native_group_generator.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/non_native_group_generator.cpp @@ -374,7 +374,7 @@ MultiTable ecc_generator_table::get_xlo_table(const MultiTableId id, const B table.id = id; for (size_t i = 0; i < num_entries; ++i) { table.slice_sizes.emplace_back(512); - table.lookup_ids.emplace_back(basic_id); + table.basic_table_ids.emplace_back(basic_id); table.get_table_values.emplace_back(&get_xlo_values); } return table; @@ -389,7 +389,7 @@ MultiTable ecc_generator_table::get_xhi_table(const MultiTableId id, const B table.id = id; for (size_t i = 0; i < num_entries; ++i) { table.slice_sizes.emplace_back(512); - table.lookup_ids.emplace_back(basic_id); + table.basic_table_ids.emplace_back(basic_id); table.get_table_values.emplace_back(&get_xhi_values); } return table; @@ -404,7 +404,7 @@ MultiTable ecc_generator_table::get_xlo_endo_table(const MultiTableId id, co table.id = id; for (size_t i = 0; i < num_entries; ++i) { table.slice_sizes.emplace_back(512); - table.lookup_ids.emplace_back(basic_id); + table.basic_table_ids.emplace_back(basic_id); table.get_table_values.emplace_back(&get_xlo_endo_values); } return table; @@ -419,7 +419,7 @@ MultiTable ecc_generator_table::get_xhi_endo_table(const MultiTableId id, co table.id = id; for (size_t i = 0; i < num_entries; ++i) { table.slice_sizes.emplace_back(512); - table.lookup_ids.emplace_back(basic_id); + table.basic_table_ids.emplace_back(basic_id); table.get_table_values.emplace_back(&get_xhi_endo_values); } return table; @@ -434,7 +434,7 @@ MultiTable ecc_generator_table::get_ylo_table(const MultiTableId id, const B table.id = id; for (size_t i = 0; i < num_entries; ++i) { table.slice_sizes.emplace_back(512); - table.lookup_ids.emplace_back(basic_id); + table.basic_table_ids.emplace_back(basic_id); table.get_table_values.emplace_back(&get_ylo_values); } return table; @@ -449,7 +449,7 @@ MultiTable ecc_generator_table::get_yhi_table(const MultiTableId id, const B table.id = id; for (size_t i = 0; i < num_entries; ++i) { table.slice_sizes.emplace_back(512); - table.lookup_ids.emplace_back(basic_id); + table.basic_table_ids.emplace_back(basic_id); table.get_table_values.emplace_back(&get_yhi_values); } return table; @@ -464,7 +464,7 @@ MultiTable ecc_generator_table::get_xyprime_table(const MultiTableId id, con table.id = id; for (size_t i = 0; i < num_entries; ++i) { table.slice_sizes.emplace_back(512); - table.lookup_ids.emplace_back(basic_id); + table.basic_table_ids.emplace_back(basic_id); table.get_table_values.emplace_back(&get_xyprime_values); } return table; @@ -479,7 +479,7 @@ MultiTable ecc_generator_table::get_xyprime_endo_table(const MultiTableId id table.id = id; for (size_t i = 0; i < num_entries; ++i) { table.slice_sizes.emplace_back(512); - table.lookup_ids.emplace_back(basic_id); + table.basic_table_ids.emplace_back(basic_id); table.get_table_values.emplace_back(&get_xyprime_endo_values); } return table; diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/plookup_tables.cpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/plookup_tables.cpp index 9e5276b6873..edc67c2e1b3 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/plookup_tables.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/plookup_tables.cpp @@ -26,7 +26,7 @@ std::array MULTI_TABLES; bool initialised = false; #ifndef NO_MULTITHREADING -// The multitables initialisation procedure is not thread-sage, so we need to make sure only 1 thread gets to initialize +// The multitables initialisation procedure is not thread-safe, so we need to make sure only 1 thread gets to initialize // them. std::mutex multi_table_mutex; #endif @@ -123,7 +123,16 @@ void init_multi_tables() initialised = true; } } // namespace -const MultiTable& create_table(const MultiTableId id) +/** + * @brief Return the multitable with the provided ID; construct all MultiTables if not constructed already + * @details The multitables are relatively light objects (they do not themselves store raw table data) so the first time + * we use one of them we simply construct all of them (regardless of which of them will actually be used) and store in + * MULTI_TABLES array. + * + * @param id The index of a MultiTable in the MULTI_TABLES array + * @return const MultiTable& + */ +const MultiTable& get_multitable(const MultiTableId id) { if (!initialised) { init_multi_tables(); @@ -155,8 +164,8 @@ ReadData get_lookup_accumulators(const MultiTableId id, const bool is_2_to_1_lookup) { // return multi-table, populating global array of all multi-tables if need be - const auto& multi_table = create_table(id); - const size_t num_lookups = multi_table.lookup_ids.size(); + const auto& multi_table = get_multitable(id); + const size_t num_lookups = multi_table.basic_table_ids.size(); ReadData lookup; const auto key_a_slices = numeric::slice_input_using_variable_bases(key_a, multi_table.slice_sizes); @@ -175,8 +184,8 @@ ReadData get_lookup_accumulators(const MultiTableId id, column_3_raw_values.emplace_back(is_2_to_1_lookup ? values[0] : values[1]); // Question: why are we storing the key slices twice? // WORKTODO: resolve question? - const BasicTable::LookupEntry key_entry{ { key_a_slices[i], key_b_slices[i] }, values }; - lookup.key_entries.emplace_back(key_entry); + const BasicTable::LookupEntry lookup_entry{ { key_a_slices[i], key_b_slices[i] }, values }; + lookup.lookup_entries.emplace_back(lookup_entry); } lookup[C1].resize(num_lookups); diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/plookup_tables.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/plookup_tables.hpp index 504a4ba97b8..5b598f10a1f 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/plookup_tables.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/plookup_tables.hpp @@ -4,7 +4,7 @@ namespace bb::plookup { -const MultiTable& create_table(MultiTableId id); +const MultiTable& get_multitable(MultiTableId id); ReadData get_lookup_accumulators(MultiTableId id, const bb::fr& key_a, diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/sha256.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/sha256.hpp index a63b94cd20d..d702c5c24c9 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/sha256.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/sha256.hpp @@ -116,7 +116,7 @@ inline MultiTable get_witness_extension_output_table(const MultiTableId id = SHA table.id = id; for (size_t i = 0; i < num_entries; ++i) { table.slice_sizes.emplace_back(numeric::pow64(16, 3)); - table.lookup_ids.emplace_back(SHA256_WITNESS_NORMALIZE); + table.basic_table_ids.emplace_back(SHA256_WITNESS_NORMALIZE); table.get_table_values.emplace_back( &sparse_tables::get_sparse_normalization_values<16, witness_extension_normalization_table>); } @@ -132,7 +132,7 @@ inline MultiTable get_choose_output_table(const MultiTableId id = SHA256_CH_OUTP table.id = id; for (size_t i = 0; i < num_entries; ++i) { table.slice_sizes.emplace_back(numeric::pow64(28, 2)); - table.lookup_ids.emplace_back(SHA256_CH_NORMALIZE); + table.basic_table_ids.emplace_back(SHA256_CH_NORMALIZE); table.get_table_values.emplace_back( &sparse_tables::get_sparse_normalization_values<28, choose_normalization_table>); } @@ -148,7 +148,7 @@ inline MultiTable get_majority_output_table(const MultiTableId id = SHA256_MAJ_O table.id = id; for (size_t i = 0; i < num_entries; ++i) { table.slice_sizes.emplace_back(numeric::pow64(16, 3)); - table.lookup_ids.emplace_back(SHA256_MAJ_NORMALIZE); + table.basic_table_ids.emplace_back(SHA256_MAJ_NORMALIZE); table.get_table_values.emplace_back( &sparse_tables::get_sparse_normalization_values<16, majority_normalization_table>); } @@ -223,10 +223,10 @@ inline MultiTable get_witness_extension_input_table(const MultiTableId id = SHA2 MultiTable table(column_1_coefficients, column_2_coefficients, column_3_coefficients); table.id = id; table.slice_sizes = { (1 << 3), (1 << 7), (1 << 8), (1 << 18) }; - table.lookup_ids = { SHA256_WITNESS_SLICE_3, - SHA256_WITNESS_SLICE_7_ROTATE_4, - SHA256_WITNESS_SLICE_8_ROTATE_7, - SHA256_WITNESS_SLICE_14_ROTATE_1 }; + table.basic_table_ids = { SHA256_WITNESS_SLICE_3, + SHA256_WITNESS_SLICE_7_ROTATE_4, + SHA256_WITNESS_SLICE_8_ROTATE_7, + SHA256_WITNESS_SLICE_14_ROTATE_1 }; table.get_table_values = { &sparse_tables::get_sparse_table_with_rotation_values<16, 0>, @@ -321,7 +321,7 @@ inline MultiTable get_choose_input_table(const MultiTableId id = SHA256_CH_INPUT MultiTable table(column_1_coefficients, column_2_coefficients, column_3_coefficients); table.id = id; table.slice_sizes = { (1 << 11), (1 << 11), (1 << 10) }; - table.lookup_ids = { SHA256_BASE28_ROTATE6, SHA256_BASE28, SHA256_BASE28_ROTATE3 }; + table.basic_table_ids = { SHA256_BASE28_ROTATE6, SHA256_BASE28, SHA256_BASE28_ROTATE3 }; table.get_table_values.push_back(&sparse_tables::get_sparse_table_with_rotation_values<28, 6>); table.get_table_values.push_back(&sparse_tables::get_sparse_table_with_rotation_values<28, 0>); @@ -380,7 +380,7 @@ inline MultiTable get_majority_input_table(const MultiTableId id = SHA256_MAJ_IN MultiTable table(column_1_coefficients, column_2_coefficients, column_3_coefficients); table.id = id; table.slice_sizes = { (1 << 11), (1 << 11), (1 << 10) }; - table.lookup_ids = { SHA256_BASE16_ROTATE2, SHA256_BASE16_ROTATE2, SHA256_BASE16 }; + table.basic_table_ids = { SHA256_BASE16_ROTATE2, SHA256_BASE16_ROTATE2, SHA256_BASE16 }; table.get_table_values = { &sparse_tables::get_sparse_table_with_rotation_values<16, 2>, &sparse_tables::get_sparse_table_with_rotation_values<16, 2>, diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/types.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/types.hpp index 2c1f6ff92d4..17dbe132ccb 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/types.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/types.hpp @@ -123,7 +123,7 @@ enum MultiTableId { /** * @brief Container for managing multiple BasicTables plus the data needed to combine basic table outputs (limbs) into - * accumulators + * accumulators. Does not store actual raw table data. * @details As a simple example, consider using lookups to compute XOR on uint32_t inputs. To do this we decompose the * inputs into 6 limbs and use a BasicTable for 6-bit XOR lookups. In this case the MultiTable simply manages 6 basic * tables, all of which are the XOR BasicTable. (In many cases all of the BasicTables managed by a MultiTable are @@ -140,7 +140,7 @@ struct MultiTable { std::vector column_2_coefficients; std::vector column_3_coefficients; MultiTableId id; - std::vector lookup_ids; + std::vector basic_table_ids; std::vector slice_sizes; std::vector column_1_step_sizes; std::vector column_2_step_sizes; @@ -341,7 +341,7 @@ template class ReadData { std::vector& operator[](ColumnIdx idx) { return columns[static_cast(idx)]; }; const std::vector& operator[](ColumnIdx idx) const { return columns[static_cast(idx)]; }; - std::vector key_entries; + std::vector lookup_entries; private: std::array, 3> columns; diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/uint.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/uint.hpp index 1ccfecdd2a5..2117eb3b0f9 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/uint.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/uint.hpp @@ -81,7 +81,7 @@ inline MultiTable get_uint32_xor_table(const MultiTableId id = UINT32_XOR) table.id = id; for (size_t i = 0; i < num_entries; ++i) { table.slice_sizes.emplace_back(base); - table.lookup_ids.emplace_back(UINT_XOR_ROTATE0); + table.basic_table_ids.emplace_back(UINT_XOR_ROTATE0); table.get_table_values.emplace_back(&get_xor_rotate_values_from_key<6, 0>); } return table; @@ -96,7 +96,7 @@ inline MultiTable get_uint32_and_table(const MultiTableId id = UINT32_AND) table.id = id; for (size_t i = 0; i < num_entries; ++i) { table.slice_sizes.emplace_back(base); - table.lookup_ids.emplace_back(UINT_AND_ROTATE0); + table.basic_table_ids.emplace_back(UINT_AND_ROTATE0); table.get_table_values.emplace_back(&get_and_rotate_values_from_key<6, 0>); } return table; diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.cpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.cpp index e96c234c5ab..a8054621616 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.cpp @@ -633,13 +633,14 @@ plookup::ReadData UltraCircuitBuilder_::create_gates_ const uint32_t key_a_index, std::optional key_b_index) { - const auto& multi_table = plookup::create_table(id); + const auto& multi_table = plookup::get_multitable(id); const size_t num_lookups = read_values[plookup::ColumnIdx::C1].size(); plookup::ReadData read_data; for (size_t i = 0; i < num_lookups; ++i) { - auto& table = get_table(multi_table.lookup_ids[i]); + // get basic lookup table; construct and add to builder.lookup_tables if not already present + auto& table = get_table(multi_table.basic_table_ids[i]); - table.lookup_gates.emplace_back(read_values.key_entries[i]); + table.lookup_gates.emplace_back(read_values.lookup_entries[i]); const auto first_idx = (i == 0) ? key_a_index : this->add_variable(read_values[plookup::ColumnIdx::C1][i]); const auto second_idx = (i == 0 && (key_b_index.has_value())) diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp index 10317b7a009..7c9c64e7e3c 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp @@ -702,7 +702,7 @@ class UltraCircuitBuilder_ : public CircuitBuilderBase (*get_values_from_key)(const std::array)); plookup::BasicTable& get_table(const plookup::BasicTableId id); - plookup::MultiTable& create_table(const plookup::MultiTableId id); + plookup::MultiTable& get_multitable(const plookup::MultiTableId id); plookup::ReadData create_gates_from_plookup_accumulators( const plookup::MultiTableId& id, From 5005403cb1c07f92d66ff7f0991df5bb69d594ca Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Mon, 10 Jun 2024 18:42:10 +0000 Subject: [PATCH 03/42] more comments --- .../plookup_tables/types.hpp | 15 ++++++++------- .../ultra_circuit_builder.cpp | 10 +++++++++- .../ultra_circuit_builder.hpp | 5 ++--- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/types.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/types.hpp index 17dbe132ccb..542b7908a0f 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/types.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/types.hpp @@ -128,8 +128,8 @@ enum MultiTableId { * inputs into 6 limbs and use a BasicTable for 6-bit XOR lookups. In this case the MultiTable simply manages 6 basic * tables, all of which are the XOR BasicTable. (In many cases all of the BasicTables managed by a MultiTable are * identical, however there are some cases where more than 1 type is required, e.g. if a certain limb has to be handled - * differently). This class also stores the scalars needed to reconstruct full values from the limbs that are contained - * in the basic lookup tables. + * differently etc.). This class also stores the scalars needed to reconstruct full values from the components that are + * contained in the basic lookup tables. * @note Note that a MultiTable does not actually *store* any table data. Rather it stores a set of basic table IDs, the * methods used to compute the basic table entries, plus some metadata. * @@ -147,6 +147,7 @@ struct MultiTable { std::vector column_3_step_sizes; typedef std::array table_out; typedef std::array table_in; + // Methods for computing the value from a key for each basic table std::vector get_table_values; private: @@ -163,8 +164,6 @@ struct MultiTable { bb::fr::batch_invert(&coefficient_inverses[0], num_lookups * 3); - // WORKTODO: in simple cases like XOR, I think every one of these values is 1 << 6. Confirm this. If so, is it - // worth adding logic to not do all this computation? Probably not but it might at least make the code clearer. for (size_t i = 1; i < num_lookups; ++i) { column_1_step_sizes.emplace_back(column_1_coefficients[i] * coefficient_inverses[i - 1]); column_2_step_sizes.emplace_back(column_2_coefficients[i] * coefficient_inverses[num_lookups + i - 1]); @@ -270,7 +269,8 @@ struct MultiTable { // } /** - * @brief The structure contains the most basic table serving one function (for, example an xor table) + * @brief A basic table from which we can perform lookups (for example, an xor table) + * @details Also stores the lookup gate data for all lookups performed on this table * * @details You can find initialization example at * ../ultra_plonk_composer.cpp#UltraPlonkComposer::initialize_precomputed_table(..) @@ -311,9 +311,9 @@ struct BasicTable { bb::fr column_2_step_size = bb::fr(0); bb::fr column_3_step_size = bb::fr(0); std::vector column_1; - std::vector column_3; std::vector column_2; - std::vector lookup_gates; + std::vector column_3; + std::vector lookup_gates; // wire data for all lookup gates created for lookups on this table std::array (*get_values_from_key)(const std::array); @@ -344,6 +344,7 @@ template class ReadData { std::vector lookup_entries; private: + // Container for the lookup accumulators; 0th index of each column contains full accumulated value std::array, 3> columns; }; diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.cpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.cpp index a8054621616..d110aed642c 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.cpp @@ -609,6 +609,14 @@ uint32_t UltraCircuitBuilder_::put_constant_variable(const FF& } } +/** + * @brief Get the basic table with provided ID from the set of tables for the present circuit; create it if it doesnt + * yet exist + * + * @tparam Arithmetization + * @param id + * @return plookup::BasicTable& + */ template plookup::BasicTable& UltraCircuitBuilder_::get_table(const plookup::BasicTableId id) { @@ -619,7 +627,7 @@ plookup::BasicTable& UltraCircuitBuilder_::get_table(const ploo } // Table doesn't exist! So try to create it. lookup_tables.emplace_back(plookup::create_basic_table(id, lookup_tables.size())); - return lookup_tables[lookup_tables.size() - 1]; + return lookup_tables.back(); } /** diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp index 7c9c64e7e3c..5fd766f8626 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp @@ -281,8 +281,9 @@ class UltraCircuitBuilder_ : public CircuitBuilderBase constant_variable_indices; + // The set of lookup tables used by the circuit, plus the gate data for the lookups from each table std::vector lookup_tables; - std::vector lookup_multi_tables; + std::map range_lists; // DOCTODO: explain this. /** @@ -367,7 +368,6 @@ class UltraCircuitBuilder_ : public CircuitBuilderBase Date: Mon, 10 Jun 2024 18:49:02 +0000 Subject: [PATCH 04/42] another comment --- .../stdlib_circuit_builders/plookup_tables/plookup_tables.cpp | 4 ++-- .../stdlib_circuit_builders/ultra_circuit_builder.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/plookup_tables.cpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/plookup_tables.cpp index edc67c2e1b3..b897fc8c309 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/plookup_tables.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/plookup_tables.cpp @@ -176,14 +176,14 @@ ReadData get_lookup_accumulators(const MultiTableId id, std::vector column_3_raw_values; for (size_t i = 0; i < num_lookups; ++i) { - // get i-th table query function and then submit query + // compute the value(s) corresponding to the key(s) using on the i-th basic table query function const auto values = multi_table.get_table_values[i]({ key_a_slices[i], key_b_slices[i] }); // store all query data in raw columns and key entry column_1_raw_values.emplace_back(key_a_slices[i]); column_2_raw_values.emplace_back(is_2_to_1_lookup ? key_b_slices[i] : values[0]); column_3_raw_values.emplace_back(is_2_to_1_lookup ? values[0] : values[1]); - // Question: why are we storing the key slices twice? // WORKTODO: resolve question? + // Store the lookup entries for use in constructing the sorted table/lookup polynomials later on const BasicTable::LookupEntry lookup_entry{ { key_a_slices[i], key_b_slices[i] }, values }; lookup.lookup_entries.emplace_back(lookup_entry); } diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.cpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.cpp index d110aed642c..9f208ab9b50 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.cpp @@ -648,7 +648,7 @@ plookup::ReadData UltraCircuitBuilder_::create_gates_ // get basic lookup table; construct and add to builder.lookup_tables if not already present auto& table = get_table(multi_table.basic_table_ids[i]); - table.lookup_gates.emplace_back(read_values.lookup_entries[i]); + table.lookup_gates.emplace_back(read_values.lookup_entries[i]); // used for constructing sorted polynomials const auto first_idx = (i == 0) ? key_a_index : this->add_variable(read_values[plookup::ColumnIdx::C1][i]); const auto second_idx = (i == 0 && (key_b_index.has_value())) From 205a1e4f231bb76ad920264a41e982dccb742e5a Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Mon, 10 Jun 2024 22:56:28 +0000 Subject: [PATCH 05/42] table read counts seems to be working --- .../plonk_honk_shared/CMakeLists.txt | 2 +- .../composer/composer_lib.hpp | 37 +++++++++ .../composer/composer_lib.test.cpp | 79 +++++++++++++++++-- .../plookup_tables/plookup_tables.cpp | 18 ++--- .../plookup_tables/types.hpp | 43 +++++++++- 5 files changed, 159 insertions(+), 20 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/CMakeLists.txt b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/CMakeLists.txt index d3024bcdbb1..7603c0f6775 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/CMakeLists.txt +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/CMakeLists.txt @@ -1 +1 @@ -barretenberg_module(plonk_honk_shared polynomials) \ No newline at end of file +barretenberg_module(plonk_honk_shared polynomials ultra_honk) \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp index 06a901d7425..313c93f389f 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp @@ -2,6 +2,7 @@ #include "barretenberg/common/ref_array.hpp" #include "barretenberg/flavor/flavor.hpp" #include "barretenberg/polynomials/polynomial_store.hpp" +#include "barretenberg/stdlib_circuit_builders/plookup_tables/types.hpp" #include @@ -111,4 +112,40 @@ std::array construct_sorted_list_polynomials(typ return sorted_polynomials; } +/** + * @brief WORKTODO + * + */ +template +typename Flavor::Polynomial construct_lookup_read_counts(typename Flavor::CircuitBuilder& circuit, + const size_t dyadic_circuit_size) +{ + using Polynomial = typename Flavor::Polynomial; + using HashTable = plookup::LookupHashTable; + Polynomial read_counts{ dyadic_circuit_size }; + + size_t table_offset = 0; // offset of the present table in the table polynomials + for (auto& table : circuit.lookup_tables) { + HashTable index_map{ table.column_1, table.column_2, table.column_3 }; + + for (auto& entry : table.lookup_gates) { + info("entry"); + auto data = entry.to_sorted_list_components(table.use_twin_keys); + info("data[0] = ", data[0]); + info("data[1] = ", data[1]); + info("data[2] = ", data[2]); + + // find the index of the current lookup gate in the table + auto index_in_table = index_map.find(data); + + // increment the read count at the corresponding index in the full polynomial + size_t index_in_poly = table_offset + index_in_table; + read_counts[index_in_poly]++; + } + table_offset += table.size; + } + + return read_counts; +} + } // namespace bb diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.test.cpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.test.cpp index 94219c72a48..7b1e11cc16f 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.test.cpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.test.cpp @@ -1,21 +1,86 @@ #include "barretenberg/plonk_honk_shared/composer/composer_lib.hpp" +#include "barretenberg/circuit_checker/circuit_checker.hpp" #include "barretenberg/common/slab_allocator.hpp" #include "barretenberg/plonk_honk_shared/types/circuit_type.hpp" #include "barretenberg/srs/factories/crs_factory.hpp" +#include "barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp" #include "barretenberg/stdlib_circuit_builders/ultra_flavor.hpp" + +// #include "barretenberg/common/serialize.hpp" +// #include "barretenberg/ecc/curves/bn254/fr.hpp" +// #include "barretenberg/numeric/uint256/uint256.hpp" +// #include "barretenberg/plonk_honk_shared/library/grand_product_delta.hpp" +// #include "barretenberg/relations/permutation_relation.hpp" +// #include "barretenberg/relations/relation_parameters.hpp" +// #include "barretenberg/stdlib_circuit_builders/mock_circuits.hpp" +// #include "barretenberg/stdlib_circuit_builders/plookup_tables/fixed_base/fixed_base.hpp" +// #include "barretenberg/stdlib_circuit_builders/plookup_tables/types.hpp" +// #include "barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp" +// #include "barretenberg/sumcheck/sumcheck_round.hpp" +// #include "barretenberg/ultra_honk/ultra_prover.hpp" +// #include "barretenberg/ultra_honk/ultra_verifier.hpp" + #include #include using namespace bb; class ComposerLibTests : public ::testing::Test { + public: + using Flavor = UltraFlavor; + using FF = typename Flavor::FF; + // Flavor::CircuitBuilder circuit_constructor; + // Flavor::ProvingKey proving_key = []() { + // auto crs_factory = srs::factories::CrsFactory(); + // auto crs = crs_factory.get_prover_crs(4); + // return Flavor::ProvingKey(/*circuit_size=*/8, /*num_public_inputs=*/0); + // }(); protected: + static void SetUpTestSuite() { bb::srs::init_crs_factory("../srs_db/ignition"); } +}; + +TEST_F(ComposerLibTests, LookupReadCounts) +{ + using Builder = UltraCircuitBuilder; using Flavor = UltraFlavor; using FF = typename Flavor::FF; - Flavor::CircuitBuilder circuit_constructor; - Flavor::ProvingKey proving_key = []() { - auto crs_factory = srs::factories::CrsFactory(); - auto crs = crs_factory.get_prover_crs(4); - return Flavor::ProvingKey(/*circuit_size=*/8, /*num_public_inputs=*/0); - }(); -}; \ No newline at end of file + Builder builder; + + uint256_t left_val = 1 & 0xffffffffULL; + uint256_t right_val = 5 & 0xffffffffULL; + // uint256_t left_val = 25251 & 0xffffffffULL; + // uint256_t right_val = 2831092109228376 & 0xffffffffULL; + + FF left{ left_val }; + FF right{ right_val }; + auto left_idx = builder.add_variable(left); + auto right_idx = builder.add_variable(right); + + auto accumulators = + plookup::get_lookup_accumulators(plookup::MultiTableId::UINT32_XOR, left, right, /*is_2_to_1_lookup*/ true); + info("num accumulators = ", accumulators.columns[0].size()); + + builder.create_gates_from_plookup_accumulators( + plookup::MultiTableId::UINT32_XOR, accumulators, left_idx, right_idx); + + info("num tables = ", builder.lookup_tables.size()); + info("num lookups = ", builder.lookup_tables[0].lookup_gates.size()); + + size_t circuit_size = 8192; + + // UltraProver prover(builder); + auto read_counts = construct_lookup_read_counts(builder, circuit_size); + // info("circuit_size = ", prover.instance->proving_key.circuit_size); + + size_t idx = 0; + for (auto& val : read_counts) { + if (val != 0) { + info("idx = ", idx); + info(val); + } + ++idx; + } + + EXPECT_EQ(read_counts[0], 5); + EXPECT_EQ(read_counts[64 + 5], 1); +} \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/plookup_tables.cpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/plookup_tables.cpp index b897fc8c309..0440eb17b9c 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/plookup_tables.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/plookup_tables.cpp @@ -143,14 +143,14 @@ const MultiTable& get_multitable(const MultiTableId id) /** * @brief Given a table ID and the key(s) for a key-value lookup, return the lookup accumulators - * @details In general the number of bits in key/value is greater than what can be efficiently supported in lookup - * tables. For this reason we actually perform lookups on the corresponding limbs. However, since we're interested in - * the full values and not the limbs, its convenient to structure the witnesses of lookup gates to store the former. - * This way we don't have to waste gates reaccumulating the limbs to compute the actual value of interest. The way to do - * this is to populate the wires with 'accumulator' values such that the first gate in the series contains the full - * accumulated values, and successive gates contain prior stages of the accumulator such that wire_i - r*wire_{i-1} = - * v_i, where r = num limb bits and v_i is a limb that explicitly appears in one of the lookup tables. See the detailed - * comment block below for more explanation. + * @details In general the number of bits in original key/value is greater than what can be efficiently supported in + * lookup tables. For this reason we actually perform lookups on the corresponding limbs. However, since we're + * interested in the original values and not the limbs, its convenient to structure the witnesses of lookup gates to + * store the former. This way we don't have to waste gates reaccumulating the limbs to compute the actual value of + * interest. The way to do this is to populate the wires with 'accumulator' values such that the first gate in the + * series contains the full accumulated values, and successive gates contain prior stages of the accumulator such that + * wire_i - r*wire_{i-1} = v_i, where r = num limb bits and v_i is a limb that explicitly appears in one of the lookup + * tables. See the detailed comment block below for more explanation. * * @param id * @param key_a @@ -176,7 +176,7 @@ ReadData get_lookup_accumulators(const MultiTableId id, std::vector column_3_raw_values; for (size_t i = 0; i < num_lookups; ++i) { - // compute the value(s) corresponding to the key(s) using on the i-th basic table query function + // compute the value(s) corresponding to the key(s) using the i-th basic table query function const auto values = multi_table.get_table_values[i]({ key_a_slices[i], key_b_slices[i] }); // store all query data in raw columns and key entry column_1_raw_values.emplace_back(key_a_slices[i]); diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/types.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/types.hpp index 542b7908a0f..debf4eeff53 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/types.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/types.hpp @@ -122,8 +122,8 @@ enum MultiTableId { }; /** - * @brief Container for managing multiple BasicTables plus the data needed to combine basic table outputs (limbs) into - * accumulators. Does not store actual raw table data. + * @brief Container for managing multiple BasicTables plus the data needed to combine basic table outputs (e.g. limbs) + * into accumulators. Does not store actual raw table data. * @details As a simple example, consider using lookups to compute XOR on uint32_t inputs. To do this we decompose the * inputs into 6 limbs and use a BasicTable for 6-bit XOR lookups. In this case the MultiTable simply manages 6 basic * tables, all of which are the XOR BasicTable. (In many cases all of the BasicTables managed by a MultiTable are @@ -343,9 +343,46 @@ template class ReadData { std::vector lookup_entries; - private: + // private: // Container for the lookup accumulators; 0th index of each column contains full accumulated value std::array, 3> columns; }; +struct LookupHashTable { + using FF = bb::fr; + using Key = std::array; + using Value = size_t; + struct HashFunction { + static constexpr FF mult_const = FF(uint256_t(0x1337, 0x1336, 0x1335, 0x1334)); + static constexpr FF const_sqr = mult_const.sqr(); + + size_t operator()(const Key& entry) const + { + FF result = entry[0] + mult_const * entry[1] + const_sqr * entry[2]; + return static_cast(result.reduce_once().data[0]); + } + }; + + std::unordered_map index_map; + + LookupHashTable(std::vector& column_1, std::vector& column_2, std::vector& column_3) + { + for (size_t i = 0; i < column_1.size(); ++i) { + index_map[{ column_1[i], column_2[i], column_3[i] }] = i; + } + } + + // Value find(Key key) { return index_map[key]; } + Value find(const Key& key) const + { + auto it = index_map.find(key); + if (it != index_map.end()) { + return it->second; + } else { + info(" KEY NOT FOUND!"); + return 0; + } + } +}; + } // namespace bb::plookup From 5d2237d52a203b5199527eed1b4a284ed60cdc6f Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Tue, 11 Jun 2024 16:04:37 +0000 Subject: [PATCH 06/42] update and add read tags to method --- .../composer/composer_lib.hpp | 18 ++-- .../composer/composer_lib.test.cpp | 36 +++++--- .../plookup_tables/types.hpp | 88 +++++++++++-------- 3 files changed, 82 insertions(+), 60 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp index 313c93f389f..e5939e5df27 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp @@ -117,30 +117,24 @@ std::array construct_sorted_list_polynomials(typ * */ template -typename Flavor::Polynomial construct_lookup_read_counts(typename Flavor::CircuitBuilder& circuit, - const size_t dyadic_circuit_size) +typename Flavor::Polynomial construct_lookup_read_counts(typename Flavor::Polynomial& read_counts, + typename Flavor::Polynomial& read_tags, + typename Flavor::CircuitBuilder& circuit) { - using Polynomial = typename Flavor::Polynomial; - using HashTable = plookup::LookupHashTable; - Polynomial read_counts{ dyadic_circuit_size }; - size_t table_offset = 0; // offset of the present table in the table polynomials for (auto& table : circuit.lookup_tables) { - HashTable index_map{ table.column_1, table.column_2, table.column_3 }; + table.initialize_index_map(); for (auto& entry : table.lookup_gates) { - info("entry"); auto data = entry.to_sorted_list_components(table.use_twin_keys); - info("data[0] = ", data[0]); - info("data[1] = ", data[1]); - info("data[2] = ", data[2]); // find the index of the current lookup gate in the table - auto index_in_table = index_map.find(data); + auto index_in_table = table.index_map[data]; // increment the read count at the corresponding index in the full polynomial size_t index_in_poly = table_offset + index_in_table; read_counts[index_in_poly]++; + read_tags[index_in_poly] = 1; } table_offset += table.size; } diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.test.cpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.test.cpp index 7b1e11cc16f..60155a36890 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.test.cpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.test.cpp @@ -44,6 +44,7 @@ TEST_F(ComposerLibTests, LookupReadCounts) using Builder = UltraCircuitBuilder; using Flavor = UltraFlavor; using FF = typename Flavor::FF; + using Polynomial = typename Flavor::Polynomial; Builder builder; uint256_t left_val = 1 & 0xffffffffULL; @@ -68,19 +69,32 @@ TEST_F(ComposerLibTests, LookupReadCounts) size_t circuit_size = 8192; - // UltraProver prover(builder); - auto read_counts = construct_lookup_read_counts(builder, circuit_size); - // info("circuit_size = ", prover.instance->proving_key.circuit_size); + Polynomial read_counts{ circuit_size }; + Polynomial read_tags{ circuit_size }; + + construct_lookup_read_counts(read_counts, read_tags, builder); + + // size_t idx = 0; + // for (auto& val : read_counts) { + // if (val != 0) { + // info("idx = ", idx); + // info(val); + // } + // ++idx; + // } size_t idx = 0; - for (auto& val : read_counts) { - if (val != 0) { - info("idx = ", idx); - info(val); + for (auto [count, tag] : zip_view(read_counts, read_tags)) { + if (idx == 0) { + EXPECT_EQ(count, 5); + EXPECT_EQ(tag, 1); + } else if (idx == 69) { + EXPECT_EQ(count, 1); + EXPECT_EQ(tag, 1); + } else { + EXPECT_EQ(count, 0); + EXPECT_EQ(tag, 0); } - ++idx; + idx++; } - - EXPECT_EQ(read_counts[0], 5); - EXPECT_EQ(read_counts[64 + 5], 1); } \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/types.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/types.hpp index debf4eeff53..7ffe0969be1 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/types.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/types.hpp @@ -268,6 +268,53 @@ struct MultiTable { // } +struct LookupHashTable { + using FF = bb::fr; + using Key = std::array; + using Value = size_t; + struct HashFunction { + FF mult_const; + FF const_sqr; + + HashFunction() + : mult_const(FF(uint256_t(0x1337, 0x1336, 0x1335, 0x1334))) + , const_sqr(mult_const.sqr()) + {} + + size_t operator()(const Key& entry) const + { + FF result = entry[0] + mult_const * entry[1] + const_sqr * entry[2]; + return static_cast(result.reduce_once().data[0]); + } + }; + + std::unordered_map index_map; + + // Default constructor + LookupHashTable() = default; + + void initialize(std::vector& column_1, std::vector& column_2, std::vector& column_3) + { + for (size_t i = 0; i < column_1.size(); ++i) { + index_map[{ column_1[i], column_2[i], column_3[i] }] = i; + } + } + + Value operator[](const Key& key) const + { + auto it = index_map.find(key); + if (it != index_map.end()) { + return it->second; + } else { + info("LookupHashTable: Key not found!"); + ASSERT(false); + return 0; + } + } + + bool operator==(const LookupHashTable& other) const = default; +}; + /** * @brief A basic table from which we can perform lookups (for example, an xor table) * @details Also stores the lookup gate data for all lookups performed on this table @@ -315,6 +362,10 @@ struct BasicTable { std::vector column_3; std::vector lookup_gates; // wire data for all lookup gates created for lookups on this table + LookupHashTable index_map; + + void initialize_index_map() { index_map.initialize(column_1, column_2, column_3); } + std::array (*get_values_from_key)(const std::array); bool operator==(const BasicTable& other) const = default; @@ -348,41 +399,4 @@ template class ReadData { std::array, 3> columns; }; -struct LookupHashTable { - using FF = bb::fr; - using Key = std::array; - using Value = size_t; - struct HashFunction { - static constexpr FF mult_const = FF(uint256_t(0x1337, 0x1336, 0x1335, 0x1334)); - static constexpr FF const_sqr = mult_const.sqr(); - - size_t operator()(const Key& entry) const - { - FF result = entry[0] + mult_const * entry[1] + const_sqr * entry[2]; - return static_cast(result.reduce_once().data[0]); - } - }; - - std::unordered_map index_map; - - LookupHashTable(std::vector& column_1, std::vector& column_2, std::vector& column_3) - { - for (size_t i = 0; i < column_1.size(); ++i) { - index_map[{ column_1[i], column_2[i], column_3[i] }] = i; - } - } - - // Value find(Key key) { return index_map[key]; } - Value find(const Key& key) const - { - auto it = index_map.find(key); - if (it != index_map.end()) { - return it->second; - } else { - info(" KEY NOT FOUND!"); - return 0; - } - } -}; - } // namespace bb::plookup From 856fbfbb7b714057b686d60bf107781314c3a261 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Tue, 11 Jun 2024 17:06:31 +0000 Subject: [PATCH 07/42] add counts and tags to flavor and oink, tests pass --- .../composer/composer_lib.hpp | 2 + .../stdlib_circuit_builders/mega_flavor.hpp | 16 ++- .../stdlib_circuit_builders/ultra_flavor.hpp | 101 +++++++++++++----- .../sumcheck/instance/prover_instance.hpp | 3 + .../barretenberg/ultra_honk/oink_prover.cpp | 6 ++ .../barretenberg/ultra_honk/oink_verifier.cpp | 4 + 6 files changed, 104 insertions(+), 28 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp index e5939e5df27..543e62564f3 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp @@ -121,6 +121,8 @@ typename Flavor::Polynomial construct_lookup_read_counts(typename Flavor::Polyno typename Flavor::Polynomial& read_tags, typename Flavor::CircuitBuilder& circuit) { + // WORKTODO: this wont work; the counts need to reflect the sturcture of the actual table polys (which are shifted + // to the bottom of the trace) so we should just construct these at the same time as the table polys. size_t table_offset = 0; // offset of the present table in the table polynomials for (auto& table : circuit.lookup_tables) { table.initialize_index_map(); diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp index eabacc96c31..62a74307734 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp @@ -40,12 +40,12 @@ class MegaFlavor { // The number of multivariate polynomials on which a sumcheck prover sumcheck operates (including shifts). We often // need containers of this size to hold related data, so we choose a name more agnostic than `NUM_POLYNOMIALS`. // Note: this number does not include the individual sorted list polynomials. - static constexpr size_t NUM_ALL_ENTITIES = 58; + static constexpr size_t NUM_ALL_ENTITIES = 60; // The number of polynomials precomputed to describe a circuit and to aid a prover in constructing a satisfying // assignment of witnesses. We again choose a neutral name. static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 30; // The total number of witness entities not including shifts. - static constexpr size_t NUM_WITNESS_ENTITIES = 17; + static constexpr size_t NUM_WITNESS_ENTITIES = 19; // Total number of folded polynomials, which is just all polynomials except the shifts static constexpr size_t NUM_FOLDED_ENTITIES = NUM_PRECOMPUTED_ENTITIES + NUM_WITNESS_ENTITIES; @@ -182,6 +182,8 @@ class MegaFlavor { sorted_accum, // column 4 z_perm, // column 5 z_lookup, // column 6 + lookup_read_counts, // column 6 + lookup_read_tags, // column 6 ecc_op_wire_1, // column 7 ecc_op_wire_2, // column 8 ecc_op_wire_3, // column 9 @@ -657,6 +659,8 @@ class MegaFlavor { w_4 = "W_4"; z_perm = "Z_PERM"; z_lookup = "Z_LOOKUP"; + lookup_read_counts = "LOOKUP_READ_COUNTS"; + lookup_read_tags = "LOOKUP_READ_TAGS"; sorted_accum = "SORTED_ACCUM"; ecc_op_wire_1 = "ECC_OP_WIRE_1"; ecc_op_wire_2 = "ECC_OP_WIRE_2"; @@ -750,6 +754,8 @@ class MegaFlavor { this->sorted_accum = commitments.sorted_accum; this->z_perm = commitments.z_perm; this->z_lookup = commitments.z_lookup; + this->lookup_read_counts = commitments.lookup_read_counts; + this->lookup_read_tags = commitments.lookup_read_tags; this->ecc_op_wire_1 = commitments.ecc_op_wire_1; this->ecc_op_wire_2 = commitments.ecc_op_wire_2; this->ecc_op_wire_3 = commitments.ecc_op_wire_3; @@ -794,6 +800,8 @@ class MegaFlavor { Commitment w_4_comm; Commitment z_perm_comm; Commitment z_lookup_comm; + Commitment lookup_read_counts_comm; + Commitment lookup_read_tags_comm; std::vector> sumcheck_univariates; std::array sumcheck_evaluations; std::vector zm_cq_comms; @@ -847,6 +855,8 @@ class MegaFlavor { return_data_read_counts_comm = deserialize_from_buffer(proof_data, num_frs_read); return_data_inverses_comm = deserialize_from_buffer(proof_data, num_frs_read); sorted_accum_comm = deserialize_from_buffer(proof_data, num_frs_read); + lookup_read_counts_comm = deserialize_from_buffer(proof_data, num_frs_read); + lookup_read_tags_comm = deserialize_from_buffer(proof_data, num_frs_read); w_4_comm = deserialize_from_buffer(proof_data, num_frs_read); z_perm_comm = deserialize_from_buffer(proof_data, num_frs_read); z_lookup_comm = deserialize_from_buffer(proof_data, num_frs_read); @@ -888,6 +898,8 @@ class MegaFlavor { serialize_to_buffer(return_data_read_counts_comm, proof_data); serialize_to_buffer(return_data_inverses_comm, proof_data); serialize_to_buffer(sorted_accum_comm, proof_data); + serialize_to_buffer(lookup_read_counts_comm, proof_data); + serialize_to_buffer(lookup_read_tags_comm, proof_data); serialize_to_buffer(w_4_comm, proof_data); serialize_to_buffer(z_perm_comm, proof_data); serialize_to_buffer(z_lookup_comm, proof_data); diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp index 5422535e0d2..83867898ade 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp @@ -37,12 +37,12 @@ class UltraFlavor { // The number of multivariate polynomials on which a sumcheck prover sumcheck operates (including shifts). We often // need containers of this size to hold related data, so we choose a name more agnostic than `NUM_POLYNOMIALS`. // Note: this number does not include the individual sorted list polynomials. - static constexpr size_t NUM_ALL_ENTITIES = 43; + static constexpr size_t NUM_ALL_ENTITIES = 45; // The number of polynomials precomputed to describe a circuit and to aid a prover in constructing a satisfying // assignment of witnesses. We again choose a neutral name. static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 25; // The total number of witness entities not including shifts. - static constexpr size_t NUM_WITNESS_ENTITIES = 7; + static constexpr size_t NUM_WITNESS_ENTITIES = 9; // Total number of folded polynomials, which is just all polynomials except the shifts static constexpr size_t NUM_FOLDED_ENTITIES = NUM_PRECOMPUTED_ENTITIES + NUM_WITNESS_ENTITIES; @@ -142,13 +142,15 @@ class UltraFlavor { template class WitnessEntities { public: DEFINE_FLAVOR_MEMBERS(DataType, - w_l, // column 0 - w_r, // column 1 - w_o, // column 2 - w_4, // column 3 - sorted_accum, // column 4 - z_perm, // column 5 - z_lookup) // column 6 + w_l, // column 0 + w_r, // column 1 + w_o, // column 2 + w_4, // column 3 + sorted_accum, // column 4 + z_perm, // column 5 + z_lookup, // column 6 + lookup_read_counts, // column 6 + lookup_read_tags) // column 6 auto get_wires() { return RefArray{ w_l, w_r, w_o, w_4 }; }; }; @@ -222,6 +224,8 @@ class UltraFlavor { sorted_accum, // column 29 z_perm, // column 30 z_lookup, // column 31 + lookup_read_counts, // column 6 + lookup_read_tags, // column 6 table_1_shift, // column 32 table_2_shift, // column 33 table_3_shift, // column 34 @@ -245,12 +249,40 @@ class UltraFlavor { // Gemini-specific getters. auto get_unshifted() { - return RefArray{ q_m, q_c, q_l, q_r, q_o, q_4, q_arith, q_delta_range, - 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 - - }; + return RefArray{ q_m, + q_c, + q_l, + q_r, + q_o, + q_4, + q_arith, + q_delta_range, + 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, + lookup_read_counts, + lookup_read_tags }; }; auto get_precomputed() @@ -263,7 +295,10 @@ class UltraFlavor { }; } - auto get_witness() { return RefArray{ w_l, w_r, w_o, w_4, sorted_accum, z_perm, z_lookup }; }; + auto get_witness() + { + return RefArray{ w_l, w_r, w_o, w_4, sorted_accum, z_perm, z_lookup, lookup_read_counts, lookup_read_tags }; + }; auto get_to_be_shifted() { return RefArray{ table_1, table_2, table_3, table_4, w_l, w_r, w_o, w_4, sorted_accum, z_perm, z_lookup }; @@ -295,7 +330,8 @@ class UltraFlavor { // Define all operations as default, except copy construction/assignment ProverPolynomials() = default; ProverPolynomials(size_t circuit_size) - { // Initialize all unshifted polynomials to the zero polynomial and initialize the shifted polys + { // Initialize all unshifted polynomials to the zero polynomial and initialize the + // shifted polys for (auto& poly : get_unshifted()) { poly = Polynomial{ circuit_size }; } @@ -380,8 +416,8 @@ class UltraFlavor { /** * @brief Add plookup memory records to the fourth wire polynomial * - * @details This operation must be performed after the first three wires have been committed to, hence the - * dependence on the `eta` challenge. + * @details This operation must be performed after the first three wires have been + * committed to, hence the dependence on the `eta` challenge. * * @tparam Flavor * @param eta challenge produced after commitment to first three wire polynomials @@ -410,7 +446,8 @@ class UltraFlavor { } /** - * @brief Computes public_input_delta, lookup_grand_product_delta, the z_perm and z_lookup polynomials + * @brief Computes public_input_delta, lookup_grand_product_delta, the z_perm and z_lookup + * polynomials * * @param relation_parameters */ @@ -458,7 +495,8 @@ class UltraFlavor { commitment = proving_key.commitment_key->commit(polynomial); } } - // TODO(https://github.com/AztecProtocol/barretenberg/issues/964): Clean the boilerplate up. + // TODO(https://github.com/AztecProtocol/barretenberg/issues/964): Clean the boilerplate + // up. VerificationKey(const uint64_t circuit_size, const uint64_t num_public_inputs, const uint64_t pub_inputs_offset, @@ -582,7 +620,8 @@ class UltraFlavor { PartiallyEvaluatedMultivariates() = default; PartiallyEvaluatedMultivariates(const size_t circuit_size) { - // Storage is only needed after the first partial evaluation, hence polynomials of size (n / 2) + // Storage is only needed after the first partial evaluation, hence polynomials of + // size (n / 2) for (auto& poly : this->get_all()) { poly = Polynomial(circuit_size / 2); } @@ -628,6 +667,8 @@ class UltraFlavor { z_perm = "Z_PERM"; z_lookup = "Z_LOOKUP"; sorted_accum = "SORTED_ACCUM"; + lookup_read_counts = "LOOKUP_READ_COUNTS"; + lookup_read_tags = "LOOKUP_READ_TAGS"; q_c = "Q_C"; q_l = "Q_L"; @@ -721,6 +762,8 @@ class UltraFlavor { Commitment w_r_comm; Commitment w_o_comm; Commitment sorted_accum_comm; + Commitment lookup_read_counts_comm; + Commitment lookup_read_tags_comm; Commitment w_4_comm; Commitment z_perm_comm; Commitment z_lookup_comm; @@ -753,8 +796,9 @@ class UltraFlavor { }; /** - * @brief Takes a FULL Ultra proof and deserializes it into the public member variables that compose the - * structure. Must be called in order to access the structure of the proof. + * @brief Takes a FULL Ultra proof and deserializes it into the public member variables + * that compose the structure. Must be called in order to access the structure of the + * proof. * */ void deserialize_full_transcript() @@ -773,6 +817,8 @@ class UltraFlavor { w_r_comm = deserialize_from_buffer(proof_data, num_frs_read); w_o_comm = deserialize_from_buffer(proof_data, num_frs_read); sorted_accum_comm = deserialize_from_buffer(proof_data, num_frs_read); + lookup_read_counts_comm = deserialize_from_buffer(proof_data, num_frs_read); + lookup_read_tags_comm = deserialize_from_buffer(proof_data, num_frs_read); w_4_comm = deserialize_from_buffer(proof_data, num_frs_read); z_perm_comm = deserialize_from_buffer(proof_data, num_frs_read); z_lookup_comm = deserialize_from_buffer(proof_data, num_frs_read); @@ -789,8 +835,9 @@ class UltraFlavor { kzg_w_comm = deserialize_from_buffer(proof_data, num_frs_read); } /** - * @brief Serializes the structure variables into a FULL Ultra proof. Should be called only if - * deserialize_full_transcript() was called and some transcript variable was modified. + * @brief Serializes the structure variables into a FULL Ultra proof. Should be called + * only if deserialize_full_transcript() was called and some transcript variable was + * modified. * */ void serialize_full_transcript() @@ -808,6 +855,8 @@ class UltraFlavor { serialize_to_buffer(w_r_comm, proof_data); serialize_to_buffer(w_o_comm, proof_data); serialize_to_buffer(sorted_accum_comm, proof_data); + serialize_to_buffer(lookup_read_counts_comm, proof_data); + serialize_to_buffer(lookup_read_tags_comm, proof_data); serialize_to_buffer(w_4_comm, proof_data); serialize_to_buffer(z_perm_comm, proof_data); serialize_to_buffer(z_lookup_comm, proof_data); diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp b/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp index 3a5de3c3c5e..af2a7a26871 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp @@ -81,6 +81,9 @@ template class ProverInstance_ { construct_lookup_table_polynomials(proving_key.polynomials.get_tables(), circuit, dyadic_circuit_size); + construct_lookup_read_counts( + proving_key.polynomials.lookup_read_counts, proving_key.polynomials.lookup_read_tags, circuit); + proving_key.sorted_polynomials = construct_sorted_list_polynomials(circuit, dyadic_circuit_size); std::span public_wires_source = proving_key.polynomials.w_r; diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp index f0c15496c95..da33c01fd9c 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp @@ -121,9 +121,15 @@ template void OinkProver::execute_sorted_list_acc // Commit to the sorted witness-table accumulator and the finalized (i.e. with memory records) fourth wire // polynomial witness_commitments.sorted_accum = commitment_key->commit(proving_key.polynomials.sorted_accum); + witness_commitments.lookup_read_counts = commitment_key->commit(proving_key.polynomials.lookup_read_counts); + witness_commitments.lookup_read_tags = commitment_key->commit(proving_key.polynomials.lookup_read_tags); witness_commitments.w_4 = commitment_key->commit(proving_key.polynomials.w_4); transcript->send_to_verifier(domain_separator + commitment_labels.sorted_accum, witness_commitments.sorted_accum); + transcript->send_to_verifier(domain_separator + commitment_labels.lookup_read_counts, + witness_commitments.lookup_read_counts); + transcript->send_to_verifier(domain_separator + commitment_labels.lookup_read_tags, + witness_commitments.lookup_read_tags); transcript->send_to_verifier(domain_separator + commitment_labels.w_4, witness_commitments.w_4); } diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/oink_verifier.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/oink_verifier.cpp index 69a2b20a57b..2cc722c82fa 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/oink_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/oink_verifier.cpp @@ -96,6 +96,10 @@ template void OinkVerifier::execute_sorted_list_a // Get commitments to sorted list accumulator and fourth wire witness_comms.sorted_accum = transcript->template receive_from_prover(domain_separator + comm_labels.sorted_accum); + witness_comms.lookup_read_counts = + transcript->template receive_from_prover(domain_separator + comm_labels.lookup_read_counts); + witness_comms.lookup_read_tags = + transcript->template receive_from_prover(domain_separator + comm_labels.lookup_read_tags); witness_comms.w_4 = transcript->template receive_from_prover(domain_separator + comm_labels.w_4); } From f8cdcb9e674e56e15ea9b9d38bb9ab401006f428 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Tue, 11 Jun 2024 17:39:19 +0000 Subject: [PATCH 08/42] construct counts at bottom of trace to match tables --- .../plonk_honk_shared/composer/composer_lib.hpp | 11 +++++++---- .../plonk_honk_shared/composer/composer_lib.test.cpp | 9 ++++++--- .../sumcheck/instance/prover_instance.hpp | 6 ++++-- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp index 543e62564f3..3a00cd2272d 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp @@ -21,6 +21,7 @@ void construct_lookup_table_polynomials(RefArray // ^^^^^^^^^ ^^^^^^^^ ^^^^^^^ ^nonzero to ensure uniqueness and to avoid infinity commitments // | table randomness // ignored, as used for regular constraints and padding to the next power of 2. + // WORKTODO: eventually just construct the tables (and therefore the counts) at the top of the trace ASSERT(dyadic_circuit_size > circuit.get_tables_size() + additional_offset); size_t offset = dyadic_circuit_size - circuit.get_tables_size() - additional_offset; @@ -119,11 +120,13 @@ std::array construct_sorted_list_polynomials(typ template typename Flavor::Polynomial construct_lookup_read_counts(typename Flavor::Polynomial& read_counts, typename Flavor::Polynomial& read_tags, - typename Flavor::CircuitBuilder& circuit) + typename Flavor::CircuitBuilder& circuit, + size_t dyadic_circuit_size) { - // WORKTODO: this wont work; the counts need to reflect the sturcture of the actual table polys (which are shifted - // to the bottom of the trace) so we should just construct these at the same time as the table polys. - size_t table_offset = 0; // offset of the present table in the table polynomials + // WORKTODO: eventually just construct the tables (and therefore the counts) at the top of the trace + size_t offset = dyadic_circuit_size - circuit.get_tables_size(); + + size_t table_offset = offset; // offset of the present table in the table polynomials for (auto& table : circuit.lookup_tables) { table.initialize_index_map(); diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.test.cpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.test.cpp index 60155a36890..890013dc341 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.test.cpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.test.cpp @@ -72,7 +72,7 @@ TEST_F(ComposerLibTests, LookupReadCounts) Polynomial read_counts{ circuit_size }; Polynomial read_tags{ circuit_size }; - construct_lookup_read_counts(read_counts, read_tags, builder); + construct_lookup_read_counts(read_counts, read_tags, builder, circuit_size); // size_t idx = 0; // for (auto& val : read_counts) { @@ -83,12 +83,15 @@ TEST_F(ComposerLibTests, LookupReadCounts) // ++idx; // } + // The table polys are constructed at the bottom of the trace, thus so to are the counts/tags + size_t offset = circuit_size - builder.get_tables_size(); + size_t idx = 0; for (auto [count, tag] : zip_view(read_counts, read_tags)) { - if (idx == 0) { + if (idx == (0 + offset)) { EXPECT_EQ(count, 5); EXPECT_EQ(tag, 1); - } else if (idx == 69) { + } else if (idx == (69 + offset)) { EXPECT_EQ(count, 1); EXPECT_EQ(tag, 1); } else { diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp b/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp index af2a7a26871..e9ded4cecf1 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp @@ -81,8 +81,10 @@ template class ProverInstance_ { construct_lookup_table_polynomials(proving_key.polynomials.get_tables(), circuit, dyadic_circuit_size); - construct_lookup_read_counts( - proving_key.polynomials.lookup_read_counts, proving_key.polynomials.lookup_read_tags, circuit); + construct_lookup_read_counts(proving_key.polynomials.lookup_read_counts, + proving_key.polynomials.lookup_read_tags, + circuit, + dyadic_circuit_size); proving_key.sorted_polynomials = construct_sorted_list_polynomials(circuit, dyadic_circuit_size); From bcdc1a7f7ee2f4803d9aacfab5f9edf1114da00e Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Tue, 11 Jun 2024 19:23:01 +0000 Subject: [PATCH 09/42] relation code in place, not tested yet --- .../relations/logderiv_lookup_relation.hpp | 157 ++++++++++++++++++ .../ultra_honk/relation_correctness.test.cpp | 41 +++-- 2 files changed, 176 insertions(+), 22 deletions(-) create mode 100644 barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp diff --git a/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp new file mode 100644 index 00000000000..0c086823253 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp @@ -0,0 +1,157 @@ +#pragma once +#include +#include + +#include "barretenberg/common/constexpr_utils.hpp" +#include "barretenberg/honk/proof_system/logderivative_library.hpp" +#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/univariate.hpp" +#include "barretenberg/relations/relation_types.hpp" + +namespace bb { + +template class LogDerivLookupRelationImpl { + public: + using FF = FF_; + static constexpr size_t READ_TERMS = 1; + static constexpr size_t WRITE_TERMS = 1; + // 1 + polynomial degree of this relation + static constexpr size_t LENGTH = READ_TERMS + WRITE_TERMS + 3; // 5 + + static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ + LENGTH, // inverse construction sub-relation + LENGTH // log derivative lookup argument sub-relation + }; + + static constexpr std::array SUBRELATION_LINEARLY_INDEPENDENT = { true, false }; + + template static bool operation_exists_at_row(const AllValues& row) + { + return (row.q_lookup == 1) || (row.lookup_read_tags == 1); + } + + /** + * @brief Get the inverse lookup polynomial + * + * @tparam AllEntities + * @param in + * @return auto& + */ + template static auto& get_inverse_polynomial(AllEntities& in) { return in.lookup_inverses; } + + template + static Accumulator compute_inverse_exists(const AllEntities& in) + { + using View = typename Accumulator::View; + + const auto row_has_write = View(in.lookup_read_tags); + const auto row_has_read = View(in.q_lookup); + return row_has_write + row_has_read - (row_has_write * row_has_read); + } + + template + static Accumulator lookup_read_counts(const AllEntities& in) + { + using View = typename Accumulator::View; + + return Accumulator(View(in.lookup_read_counts)); + } + + template + static Accumulator compute_read_term_predicate(const AllEntities& in) + + { + using View = typename Accumulator::View; + + return Accumulator(View(in.q_lookup)); + } + + template + static Accumulator compute_write_term_predicate([[maybe_unused]] const AllEntities& in) + { + // using View = typename Accumulator::View; + return Accumulator(1); + } + + template + static Accumulator compute_write_term(const AllEntities& in, const Parameters& params) + { + using View = typename Accumulator::View; + + static_assert(write_index < WRITE_TERMS); + + const auto& gamma = params.gamma; + const auto& beta = params.beta; + const auto& beta_sqr = params.beta_sqr; + const auto& beta_cube = params.beta_cube; + + auto table_1 = View(in.table_1); + auto table_2 = View(in.table_2); + auto table_3 = View(in.table_3); + auto table_4 = View(in.table_4); + + return table_1 + gamma + table_2 * beta + table_3 * beta_sqr + table_4 * beta_cube; + } + + template + static Accumulator compute_read_term(const AllEntities& in, const Parameters& params) + { + using View = typename Accumulator::View; + + const auto& gamma = params.gamma; + const auto& beta = params.beta; + const auto& beta_sqr = params.beta_sqr; + const auto& beta_cube = params.beta_cube; + + auto w_1 = View(in.w_l); + auto w_2 = View(in.w_r); + auto w_3 = View(in.w_o); + + auto w_1_shift = View(in.w_l_shift); + auto w_2_shift = View(in.w_r_shift); + auto w_3_shift = View(in.w_o_shift); + + auto table_index = View(in.q_o); + auto negative_column_1_step_size = View(in.q_r); + auto negative_column_2_step_size = View(in.q_m); + auto negative_column_3_step_size = View(in.q_c); + + // The wire values for lookup gates are accumulators structured in such a way that the differences w_i - + // step_size*w_i_shift should result in a values that exists in table_i. + auto derived_table_entry_1 = w_1 + negative_column_1_step_size * w_1_shift; + auto derived_table_entry_2 = w_2 + negative_column_2_step_size * w_2_shift; + auto derived_table_entry_3 = w_3 + negative_column_3_step_size * w_3_shift; + + // (w_1 + q_2*w_1_shift) + η(w_2 + q_m*w_2_shift) + η₂(w_3 + q_c*w_3_shift) + η₃q_index. + // deg 2 or 3 + return derived_table_entry_1 + gamma + derived_table_entry_2 * beta + derived_table_entry_3 * beta_sqr + + table_index * beta_cube; + } + + /** + * @brief Expression for ECCVM lookup tables. + * @details We use log-derivative lookup tables for the following case: + * Table writes: ECCVMPointTable columns: we define Straus point table: + * { {0, -15[P]}, {1, -13[P]}, ..., {15, 15[P]} } + * write source: { precompute_round, precompute_tx, precompute_ty } + * Table reads: ECCVMMSM columns. Each row adds up to 4 points into MSM accumulator + * read source: { msm_slice1, msm_x1, msm_y1 }, ..., { msm_slice4, msm_x4, msm_y4 } + * @param accumulator transformed to `evals + C(in(X)...)*scaling_factor` + * @param in an std::array containing the fully extended Accumulator edges. + * @param relation_params contains beta, gamma, and public_input_delta, .... + * @param scaling_factor optional term to scale the evaluation before adding to evals. + */ + template + static void accumulate(ContainerOverSubrelations& accumulator, + const AllEntities& in, + const Parameters& params, + const FF& scaling_factor) + { + accumulate_logderivative_lookup_subrelation_contributions>( + accumulator, in, params, scaling_factor); + } +}; + +template using LogDerivLookupRelation = Relation>; + +} // namespace bb 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 b928a0bcd04..e28a0148688 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/relation_correctness.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/relation_correctness.test.cpp @@ -4,6 +4,7 @@ #include "barretenberg/relations/delta_range_constraint_relation.hpp" #include "barretenberg/relations/ecc_op_queue_relation.hpp" #include "barretenberg/relations/elliptic_relation.hpp" +#include "barretenberg/relations/logderiv_lookup_relation.hpp" #include "barretenberg/relations/lookup_relation.hpp" #include "barretenberg/relations/permutation_relation.hpp" #include "barretenberg/relations/relation_parameters.hpp" @@ -29,9 +30,8 @@ void ensure_non_zero(auto& polynomial) * @brief Check that a given relation is satified for a set of polynomials * * @tparam relation_idx Index into a tuple of provided relations - * @tparam Flavor */ -template void check_relation(auto circuit_size, auto& polynomials, auto params) +template void check_relation(auto circuit_size, auto& polynomials, auto params) { for (size_t i = 0; i < circuit_size; i++) { // Define the appropriate SumcheckArrayOfValuesOverSubrelations type for this relation and initialize to zero @@ -285,18 +285,16 @@ TEST_F(UltraRelationCorrectnessTests, Ultra) ensure_non_zero(proving_key.polynomials.q_elliptic); ensure_non_zero(proving_key.polynomials.q_aux); - // Construct the round for applying sumcheck relations and results for storing computed results - using Relations = typename Flavor::Relations; - auto& prover_polynomials = instance->proving_key.polynomials; auto params = instance->relation_parameters; // Check that each relation is satisfied across each row of the prover polynomials - check_relation>(circuit_size, prover_polynomials, params); - check_relation>(circuit_size, prover_polynomials, params); - check_relation>(circuit_size, prover_polynomials, params); - check_relation>(circuit_size, prover_polynomials, params); - check_relation>(circuit_size, prover_polynomials, params); - check_relation>(circuit_size, prover_polynomials, params); + check_relation>(circuit_size, prover_polynomials, params); + check_relation>(circuit_size, prover_polynomials, params); + check_relation>(circuit_size, prover_polynomials, params); + check_relation>(circuit_size, prover_polynomials, params); + check_relation>(circuit_size, prover_polynomials, params); + check_relation>(circuit_size, prover_polynomials, params); + // check_linearly_dependent_relation>(circuit_size, prover_polynomials, params); } TEST_F(UltraRelationCorrectnessTests, Mega) @@ -351,19 +349,18 @@ TEST_F(UltraRelationCorrectnessTests, Mega) ensure_non_zero(proving_key.polynomials.return_data_read_counts); ensure_non_zero(proving_key.polynomials.return_data_inverses); - // Construct the round for applying sumcheck relations and results for storing computed results - using Relations = typename Flavor::Relations; auto& prover_polynomials = instance->proving_key.polynomials; auto params = instance->relation_parameters; // Check that each relation is satisfied across each row of the prover polynomials - check_relation>(circuit_size, prover_polynomials, params); - check_relation>(circuit_size, prover_polynomials, params); - check_relation>(circuit_size, prover_polynomials, params); - check_relation>(circuit_size, prover_polynomials, params); - check_relation>(circuit_size, prover_polynomials, params); - check_relation>(circuit_size, prover_polynomials, params); - check_relation>(circuit_size, prover_polynomials, params); - check_linearly_dependent_relation>( - circuit_size, prover_polynomials, params); + check_relation>(circuit_size, prover_polynomials, params); + check_relation>(circuit_size, prover_polynomials, params); + check_relation>(circuit_size, prover_polynomials, params); + check_relation>(circuit_size, prover_polynomials, params); + check_relation>(circuit_size, prover_polynomials, params); + check_relation>(circuit_size, prover_polynomials, params); + check_relation>(circuit_size, prover_polynomials, params); + check_relation>(circuit_size, prover_polynomials, params); + check_relation>(circuit_size, prover_polynomials, params); + check_linearly_dependent_relation>(circuit_size, prover_polynomials, params); } \ No newline at end of file From e00d618776319974ee5346182b4094d7f1495181 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Tue, 11 Jun 2024 19:37:19 +0000 Subject: [PATCH 10/42] add (fake) lookup inverses to proof system, tests pass --- .../stdlib_circuit_builders/mega_flavor.hpp | 10 +++++++-- .../stdlib_circuit_builders/ultra_flavor.hpp | 22 ++++++++++++++++--- .../barretenberg/ultra_honk/oink_prover.cpp | 9 ++++++++ .../barretenberg/ultra_honk/oink_verifier.cpp | 4 ++++ 4 files changed, 40 insertions(+), 5 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp index 62a74307734..acdb46e2e48 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp @@ -40,12 +40,12 @@ class MegaFlavor { // The number of multivariate polynomials on which a sumcheck prover sumcheck operates (including shifts). We often // need containers of this size to hold related data, so we choose a name more agnostic than `NUM_POLYNOMIALS`. // Note: this number does not include the individual sorted list polynomials. - static constexpr size_t NUM_ALL_ENTITIES = 60; + static constexpr size_t NUM_ALL_ENTITIES = 61; // The number of polynomials precomputed to describe a circuit and to aid a prover in constructing a satisfying // assignment of witnesses. We again choose a neutral name. static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 30; // The total number of witness entities not including shifts. - static constexpr size_t NUM_WITNESS_ENTITIES = 19; + static constexpr size_t NUM_WITNESS_ENTITIES = 20; // Total number of folded polynomials, which is just all polynomials except the shifts static constexpr size_t NUM_FOLDED_ENTITIES = NUM_PRECOMPUTED_ENTITIES + NUM_WITNESS_ENTITIES; @@ -182,6 +182,7 @@ class MegaFlavor { sorted_accum, // column 4 z_perm, // column 5 z_lookup, // column 6 + lookup_inverses, // column 6 lookup_read_counts, // column 6 lookup_read_tags, // column 6 ecc_op_wire_1, // column 7 @@ -659,6 +660,7 @@ class MegaFlavor { w_4 = "W_4"; z_perm = "Z_PERM"; z_lookup = "Z_LOOKUP"; + lookup_inverses = "LOOKUP_INVERSES"; lookup_read_counts = "LOOKUP_READ_COUNTS"; lookup_read_tags = "LOOKUP_READ_TAGS"; sorted_accum = "SORTED_ACCUM"; @@ -754,6 +756,7 @@ class MegaFlavor { this->sorted_accum = commitments.sorted_accum; this->z_perm = commitments.z_perm; this->z_lookup = commitments.z_lookup; + this->lookup_inverses = commitments.lookup_inverses; this->lookup_read_counts = commitments.lookup_read_counts; this->lookup_read_tags = commitments.lookup_read_tags; this->ecc_op_wire_1 = commitments.ecc_op_wire_1; @@ -800,6 +803,7 @@ class MegaFlavor { Commitment w_4_comm; Commitment z_perm_comm; Commitment z_lookup_comm; + Commitment lookup_inverses_comm; Commitment lookup_read_counts_comm; Commitment lookup_read_tags_comm; std::vector> sumcheck_univariates; @@ -858,6 +862,7 @@ class MegaFlavor { lookup_read_counts_comm = deserialize_from_buffer(proof_data, num_frs_read); lookup_read_tags_comm = deserialize_from_buffer(proof_data, num_frs_read); w_4_comm = deserialize_from_buffer(proof_data, num_frs_read); + lookup_inverses_comm = deserialize_from_buffer(proof_data, num_frs_read); z_perm_comm = deserialize_from_buffer(proof_data, num_frs_read); z_lookup_comm = deserialize_from_buffer(proof_data, num_frs_read); for (size_t i = 0; i < log_n; ++i) { @@ -901,6 +906,7 @@ class MegaFlavor { serialize_to_buffer(lookup_read_counts_comm, proof_data); serialize_to_buffer(lookup_read_tags_comm, proof_data); serialize_to_buffer(w_4_comm, proof_data); + serialize_to_buffer(lookup_inverses_comm, proof_data); serialize_to_buffer(z_perm_comm, proof_data); serialize_to_buffer(z_lookup_comm, proof_data); for (size_t i = 0; i < log_n; ++i) { diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp index 83867898ade..c2cbd9ab122 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp @@ -37,12 +37,12 @@ class UltraFlavor { // The number of multivariate polynomials on which a sumcheck prover sumcheck operates (including shifts). We often // need containers of this size to hold related data, so we choose a name more agnostic than `NUM_POLYNOMIALS`. // Note: this number does not include the individual sorted list polynomials. - static constexpr size_t NUM_ALL_ENTITIES = 45; + static constexpr size_t NUM_ALL_ENTITIES = 46; // The number of polynomials precomputed to describe a circuit and to aid a prover in constructing a satisfying // assignment of witnesses. We again choose a neutral name. static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 25; // The total number of witness entities not including shifts. - static constexpr size_t NUM_WITNESS_ENTITIES = 9; + static constexpr size_t NUM_WITNESS_ENTITIES = 10; // Total number of folded polynomials, which is just all polynomials except the shifts static constexpr size_t NUM_FOLDED_ENTITIES = NUM_PRECOMPUTED_ENTITIES + NUM_WITNESS_ENTITIES; @@ -149,6 +149,7 @@ class UltraFlavor { sorted_accum, // column 4 z_perm, // column 5 z_lookup, // column 6 + lookup_inverses, // column 6 lookup_read_counts, // column 6 lookup_read_tags) // column 6 @@ -224,6 +225,7 @@ class UltraFlavor { sorted_accum, // column 29 z_perm, // column 30 z_lookup, // column 31 + lookup_inverses, // column 31 lookup_read_counts, // column 6 lookup_read_tags, // column 6 table_1_shift, // column 32 @@ -281,6 +283,7 @@ class UltraFlavor { sorted_accum, z_perm, z_lookup, + lookup_inverses, lookup_read_counts, lookup_read_tags }; }; @@ -297,7 +300,16 @@ class UltraFlavor { auto get_witness() { - return RefArray{ w_l, w_r, w_o, w_4, sorted_accum, z_perm, z_lookup, lookup_read_counts, lookup_read_tags }; + return RefArray{ w_l, + w_r, + w_o, + w_4, + sorted_accum, + z_perm, + z_lookup, + lookup_inverses, + lookup_read_counts, + lookup_read_tags }; }; auto get_to_be_shifted() { @@ -666,6 +678,7 @@ class UltraFlavor { w_4 = "W_4"; z_perm = "Z_PERM"; z_lookup = "Z_LOOKUP"; + lookup_inverses = "LOOKUP_INVERSES"; sorted_accum = "SORTED_ACCUM"; lookup_read_counts = "LOOKUP_READ_COUNTS"; lookup_read_tags = "LOOKUP_READ_TAGS"; @@ -767,6 +780,7 @@ class UltraFlavor { Commitment w_4_comm; Commitment z_perm_comm; Commitment z_lookup_comm; + Commitment lookup_inverses_comm; std::vector> sumcheck_univariates; std::array sumcheck_evaluations; std::vector zm_cq_comms; @@ -820,6 +834,7 @@ class UltraFlavor { lookup_read_counts_comm = deserialize_from_buffer(proof_data, num_frs_read); lookup_read_tags_comm = deserialize_from_buffer(proof_data, num_frs_read); w_4_comm = deserialize_from_buffer(proof_data, num_frs_read); + lookup_inverses_comm = deserialize_from_buffer(proof_data, num_frs_read); z_perm_comm = deserialize_from_buffer(proof_data, num_frs_read); z_lookup_comm = deserialize_from_buffer(proof_data, num_frs_read); for (size_t i = 0; i < log_n; ++i) { @@ -858,6 +873,7 @@ class UltraFlavor { serialize_to_buffer(lookup_read_counts_comm, proof_data); serialize_to_buffer(lookup_read_tags_comm, proof_data); serialize_to_buffer(w_4_comm, proof_data); + serialize_to_buffer(lookup_inverses_comm, proof_data); serialize_to_buffer(z_perm_comm, proof_data); serialize_to_buffer(z_lookup_comm, proof_data); for (size_t i = 0; i < log_n; ++i) { diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp index da33c01fd9c..dba32363476 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp @@ -142,6 +142,15 @@ template void OinkProver::execute_log_derivative_ auto [beta, gamma] = transcript->template get_challenges(domain_separator + "beta", domain_separator + "gamma"); relation_parameters.beta = beta; relation_parameters.gamma = gamma; + + // compute_logderivative_inverse( + // key->polynomials, relation_parameters, key->circuit_size); + + proving_key.polynomials.lookup_inverses[0] = 25; + witness_commitments.lookup_inverses = commitment_key->commit(proving_key.polynomials.lookup_inverses); + transcript->send_to_verifier(domain_separator + commitment_labels.lookup_inverses, + witness_commitments.lookup_inverses); + if constexpr (IsGoblinFlavor) { // Compute and commit to the logderivative inverse used in DataBus proving_key.compute_logderivative_inverse(relation_parameters); diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/oink_verifier.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/oink_verifier.cpp index 2cc722c82fa..4216dbad45f 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/oink_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/oink_verifier.cpp @@ -113,6 +113,10 @@ template void OinkVerifier::execute_log_derivativ auto [beta, gamma] = transcript->template get_challenges(domain_separator + "beta", domain_separator + "gamma"); relation_parameters.beta = beta; relation_parameters.gamma = gamma; + + witness_comms.lookup_inverses = + transcript->template receive_from_prover(domain_separator + comm_labels.lookup_inverses); + // If Goblin (i.e. using DataBus) receive commitments to log-deriv inverses polynomials if constexpr (IsGoblinFlavor) { witness_comms.calldata_inverses = From 8d76a3c385283d6a4169d1b7a4ced6275a7a52be Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Tue, 11 Jun 2024 20:02:21 +0000 Subject: [PATCH 11/42] compute genuine inverses; relation correctness fails though --- .../barretenberg/stdlib_circuit_builders/mega_flavor.hpp | 3 ++- .../barretenberg/stdlib_circuit_builders/ultra_flavor.hpp | 3 +++ .../cpp/src/barretenberg/ultra_honk/oink_prover.cpp | 6 +++--- .../barretenberg/ultra_honk/relation_correctness.test.cpp | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp index acdb46e2e48..7c53a1e72d0 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp @@ -13,6 +13,7 @@ #include "barretenberg/relations/delta_range_constraint_relation.hpp" #include "barretenberg/relations/ecc_op_queue_relation.hpp" #include "barretenberg/relations/elliptic_relation.hpp" +#include "barretenberg/relations/logderiv_lookup_relation.hpp" #include "barretenberg/relations/lookup_relation.hpp" #include "barretenberg/relations/permutation_relation.hpp" #include "barretenberg/relations/poseidon2_external_relation.hpp" @@ -66,7 +67,7 @@ class MegaFlavor { bb::Poseidon2InternalRelation>; using Relations = Relations_; - using LogDerivLookupRelation = bb::DatabusLookupRelation; + using LogDerivLookupRelation = LogDerivLookupRelation; static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = compute_max_partial_relation_length(); static constexpr size_t MAX_TOTAL_RELATION_LENGTH = compute_max_total_relation_length(); diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp index c2cbd9ab122..56e26251adb 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp @@ -12,6 +12,7 @@ #include "barretenberg/relations/auxiliary_relation.hpp" #include "barretenberg/relations/delta_range_constraint_relation.hpp" #include "barretenberg/relations/elliptic_relation.hpp" +#include "barretenberg/relations/logderiv_lookup_relation.hpp" #include "barretenberg/relations/lookup_relation.hpp" #include "barretenberg/relations/permutation_relation.hpp" #include "barretenberg/relations/relation_parameters.hpp" @@ -55,6 +56,8 @@ class UltraFlavor { bb::EllipticRelation, bb::AuxiliaryRelation>; + using LogDerivLookupRelation = bb::LogDerivLookupRelation; + static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = compute_max_partial_relation_length(); static_assert(MAX_PARTIAL_RELATION_LENGTH == 6); static constexpr size_t MAX_TOTAL_RELATION_LENGTH = compute_max_total_relation_length(); diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp index dba32363476..a22c951cc59 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp @@ -1,4 +1,5 @@ #include "barretenberg/ultra_honk/oink_prover.hpp" +#include "barretenberg/relations/logderiv_lookup_relation.hpp" namespace bb { @@ -143,10 +144,9 @@ template void OinkProver::execute_log_derivative_ relation_parameters.beta = beta; relation_parameters.gamma = gamma; - // compute_logderivative_inverse( - // key->polynomials, relation_parameters, key->circuit_size); + compute_logderivative_inverse( + proving_key.polynomials, relation_parameters, proving_key.circuit_size); - proving_key.polynomials.lookup_inverses[0] = 25; witness_commitments.lookup_inverses = commitment_key->commit(proving_key.polynomials.lookup_inverses); transcript->send_to_verifier(domain_separator + commitment_labels.lookup_inverses, witness_commitments.lookup_inverses); 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 e28a0148688..8eccc3a19e2 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/relation_correctness.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/relation_correctness.test.cpp @@ -294,7 +294,7 @@ TEST_F(UltraRelationCorrectnessTests, Ultra) check_relation>(circuit_size, prover_polynomials, params); check_relation>(circuit_size, prover_polynomials, params); check_relation>(circuit_size, prover_polynomials, params); - // check_linearly_dependent_relation>(circuit_size, prover_polynomials, params); + check_linearly_dependent_relation>(circuit_size, prover_polynomials, params); } TEST_F(UltraRelationCorrectnessTests, Mega) From 1a12f9d95048e0a48b70310c9d60cfd634d2823b Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Tue, 11 Jun 2024 20:41:38 +0000 Subject: [PATCH 12/42] relation correctness passes for ultra and Mega --- .../protogalaxy/protogalaxy.test.cpp | 4 +-- .../relations/logderiv_lookup_relation.hpp | 25 +++++++++++++++++-- .../stdlib_circuit_builders/mega_flavor.hpp | 6 ++++- .../stdlib_circuit_builders/ultra_flavor.hpp | 14 +++++++++++ .../barretenberg/ultra_honk/oink_prover.cpp | 8 +++--- .../ultra_honk/relation_correctness.test.cpp | 4 ++- 6 files changed, 49 insertions(+), 12 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp index e8cf235f4aa..1833659d8ef 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp @@ -139,9 +139,7 @@ template class ProtoGalaxyTests : public testing::Test { instance->proving_key.compute_sorted_accumulator_polynomials(instance->relation_parameters.eta, instance->relation_parameters.eta_two, instance->relation_parameters.eta_three); - if constexpr (IsGoblinFlavor) { - instance->proving_key.compute_logderivative_inverse(instance->relation_parameters); - } + instance->proving_key.compute_logderivative_inverses(instance->relation_parameters); instance->proving_key.compute_grand_product_polynomials(instance->relation_parameters); for (auto& alpha : instance->alphas) { diff --git a/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp index 0c086823253..b30f35f5317 100644 --- a/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp @@ -147,8 +147,29 @@ template class LogDerivLookupRelationImpl { const Parameters& params, const FF& scaling_factor) { - accumulate_logderivative_lookup_subrelation_contributions>( - accumulator, in, params, scaling_factor); + using Accumulator = typename std::tuple_element_t<0, ContainerOverSubrelations>; + using View = typename Accumulator::View; + + const auto inverses = View(in.lookup_inverses); // Degree 1 + const auto read_counts = View(in.lookup_read_counts); // Degree 1 + const auto read_selector = View(in.q_lookup); // Degree 1 + const auto inverse_exists = compute_inverse_exists(in); // Degree 1 + const auto read_term = compute_read_term(in, params); // Degree 1 + const auto write_term = compute_write_term(in, params); // Degree 1 + const auto write_inverse = inverses * read_term; // Degree 2 + const auto read_inverse = inverses * write_term; // Degree 2 + + // Establish the correctness of the polynomial of inverses I. Note: inverses is computed so that the value is 0 + // if !inverse_exists. Degree 3 + std::get<0>(accumulator) += (read_term * write_term * inverses - inverse_exists) * scaling_factor; + + // Establish validity of the read. Note: no scaling factor here since this constraint is enforced across the + // entire trace, not on a per-row basis + std::get<1>(accumulator) += read_selector * read_inverse - read_counts * write_inverse; // Degree 4 + + // ****************** + // accumulate_logderivative_lookup_subrelation_contributions>( + // accumulator, in, params, scaling_factor); } }; diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp index 7c53a1e72d0..472c9f4ca32 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp @@ -414,8 +414,12 @@ class MegaFlavor { * @param beta * @param gamma */ - void compute_logderivative_inverse(const RelationParameters& relation_parameters) + void compute_logderivative_inverses(const RelationParameters& relation_parameters) { + // Compute inverses for conventional lookups + compute_logderivative_inverse( + this->polynomials, relation_parameters, this->circuit_size); + // Compute inverses for calldata reads DatabusLookupRelation::compute_logderivative_inverse( this->polynomials, relation_parameters, this->circuit_size); diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp index 56e26251adb..c073eee516d 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp @@ -460,6 +460,20 @@ class UltraFlavor { } } + /** + * @brief Compute the inverse polynomial used in the log derivative lookup argument + * + * @tparam Flavor + * @param beta + * @param gamma + */ + void compute_logderivative_inverses(const RelationParameters& relation_parameters) + { + // Compute inverses for conventional lookups + compute_logderivative_inverse( + this->polynomials, relation_parameters, this->circuit_size); + } + /** * @brief Computes public_input_delta, lookup_grand_product_delta, the z_perm and z_lookup * polynomials diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp index a22c951cc59..582bf4f92ee 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp @@ -144,17 +144,15 @@ template void OinkProver::execute_log_derivative_ relation_parameters.beta = beta; relation_parameters.gamma = gamma; - compute_logderivative_inverse( - proving_key.polynomials, relation_parameters, proving_key.circuit_size); + // Compute the inverses used in log-derivative lookup relations + proving_key.compute_logderivative_inverses(relation_parameters); witness_commitments.lookup_inverses = commitment_key->commit(proving_key.polynomials.lookup_inverses); transcript->send_to_verifier(domain_separator + commitment_labels.lookup_inverses, witness_commitments.lookup_inverses); + // If Mega, commit to the databus inverse polynomials and send if constexpr (IsGoblinFlavor) { - // Compute and commit to the logderivative inverse used in DataBus - proving_key.compute_logderivative_inverse(relation_parameters); - witness_commitments.calldata_inverses = commitment_key->commit(proving_key.polynomials.calldata_inverses); witness_commitments.return_data_inverses = commitment_key->commit(proving_key.polynomials.return_data_inverses); transcript->send_to_verifier(domain_separator + commitment_labels.calldata_inverses, 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 8eccc3a19e2..707cf8736a4 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/relation_correctness.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/relation_correctness.test.cpp @@ -276,6 +276,7 @@ TEST_F(UltraRelationCorrectnessTests, Ultra) instance->proving_key.compute_sorted_accumulator_polynomials(instance->relation_parameters.eta, instance->relation_parameters.eta_two, instance->relation_parameters.eta_three); + instance->proving_key.compute_logderivative_inverses(instance->relation_parameters); instance->proving_key.compute_grand_product_polynomials(instance->relation_parameters); // Check that selectors are nonzero to ensure corresponding relation has nontrivial contribution @@ -329,7 +330,7 @@ TEST_F(UltraRelationCorrectnessTests, Mega) instance->proving_key.compute_sorted_accumulator_polynomials(instance->relation_parameters.eta, instance->relation_parameters.eta_two, instance->relation_parameters.eta_three); - instance->proving_key.compute_logderivative_inverse(instance->relation_parameters); + instance->proving_key.compute_logderivative_inverses(instance->relation_parameters); instance->proving_key.compute_grand_product_polynomials(instance->relation_parameters); // Check that selectors are nonzero to ensure corresponding relation has nontrivial contribution @@ -363,4 +364,5 @@ TEST_F(UltraRelationCorrectnessTests, Mega) check_relation>(circuit_size, prover_polynomials, params); check_relation>(circuit_size, prover_polynomials, params); check_linearly_dependent_relation>(circuit_size, prover_polynomials, params); + check_linearly_dependent_relation>(circuit_size, prover_polynomials, params); } \ No newline at end of file From a66e0c6cd21727dde9468dc57869f70106545480 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Mon, 17 Jun 2024 19:19:30 +0000 Subject: [PATCH 13/42] use inheritance for getters --- .../stdlib_circuit_builders/ultra_flavor.hpp | 135 +++--------------- 1 file changed, 16 insertions(+), 119 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp index c073eee516d..277c605ea10 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp @@ -193,136 +193,33 @@ class UltraFlavor { * Symbolically we have: AllEntities = PrecomputedEntities + WitnessEntities + "ShiftedEntities". It could be * implemented as such, but we have this now. */ - template class AllEntities { + template + class AllEntities : public PrecomputedEntities, + public WitnessEntities, + public ShiftedEntities { public: - DEFINE_FLAVOR_MEMBERS(DataType, - q_c, // column 0 - q_l, // column 1 - q_r, // column 2 - q_o, // column 3 - q_4, // column 4 - q_m, // column 5 - q_arith, // column 6 - q_delta_range, // column 7 - q_elliptic, // column 8 - q_aux, // column 9 - q_lookup, // column 10 - sigma_1, // column 11 - sigma_2, // column 12 - sigma_3, // column 13 - sigma_4, // column 14 - id_1, // column 15 - id_2, // column 16 - id_3, // column 17 - id_4, // column 18 - table_1, // column 19 - table_2, // column 20 - table_3, // column 21 - table_4, // column 22 - lagrange_first, // column 23 - lagrange_last, // column 24 - w_l, // column 25 - w_r, // column 26 - w_o, // column 27 - w_4, // column 28 - sorted_accum, // column 29 - z_perm, // column 30 - z_lookup, // column 31 - lookup_inverses, // column 31 - lookup_read_counts, // column 6 - lookup_read_tags, // column 6 - table_1_shift, // column 32 - table_2_shift, // column 33 - table_3_shift, // column 34 - table_4_shift, // column 35 - w_l_shift, // column 36 - w_r_shift, // column 37 - w_o_shift, // column 38 - w_4_shift, // column 39 - sorted_accum_shift, // column 40 - z_perm_shift, // column 41 - z_lookup_shift) // column 42 + DEFINE_COMPOUND_GET_ALL(PrecomputedEntities, WitnessEntities, ShiftedEntities) - auto get_wires() { return RefArray{ w_l, w_r, w_o, w_4 }; }; - auto get_selectors() - { - return RefArray{ q_m, q_c, q_l, q_r, q_o, q_4, q_arith, q_delta_range, q_elliptic, q_aux, q_lookup }; - } - auto get_sigmas() { return RefArray{ sigma_1, sigma_2, sigma_3, sigma_4 }; }; - auto get_ids() { return RefArray{ id_1, id_2, id_3, id_4 }; }; - auto get_tables() { return RefArray{ table_1, table_2, table_3, table_4 }; }; + auto get_wires() { return RefArray{ this->w_l, this->w_r, this->w_o, this->w_4 }; }; + auto get_selectors() { return PrecomputedEntities::get_selectors(); } + auto get_sigmas() { return RefArray{ this->sigma_1, this->sigma_2, this->sigma_3, this->sigma_4 }; }; + auto get_ids() { return RefArray{ this->id_1, this->id_2, this->id_3, this->id_4 }; }; + auto get_tables() { return RefArray{ this->table_1, this->table_2, this->table_3, this->table_4 }; }; // Gemini-specific getters. auto get_unshifted() { - return RefArray{ q_m, - q_c, - q_l, - q_r, - q_o, - q_4, - q_arith, - q_delta_range, - 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, - lookup_inverses, - lookup_read_counts, - lookup_read_tags }; + return concatenate(PrecomputedEntities::get_all(), WitnessEntities::get_all()); }; - auto get_precomputed() - { - return RefArray{ q_m, q_c, q_l, q_r, q_o, q_4, q_arith, q_delta_range, - 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 + auto get_precomputed() { return PrecomputedEntities::get_all(); } - }; - } - - auto get_witness() - { - return RefArray{ w_l, - w_r, - w_o, - w_4, - sorted_accum, - z_perm, - z_lookup, - lookup_inverses, - lookup_read_counts, - lookup_read_tags }; - }; + auto get_witness() { return WitnessEntities::get_all(); }; auto get_to_be_shifted() { - return RefArray{ table_1, table_2, table_3, table_4, w_l, w_r, w_o, w_4, sorted_accum, z_perm, z_lookup }; - }; - auto get_shifted() - { - return RefArray{ 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 }; + return RefArray{ this->table_1, this->table_2, this->table_3, this->table_4, this->w_l, this->w_r, + this->w_o, this->w_4, this->sorted_accum, this->z_perm, this->z_lookup }; }; + auto get_shifted() { return ShiftedEntities::get_all(); }; }; public: From ed7cdbee6ab6a65a48326fb1d3e84ad01b802266 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Mon, 17 Jun 2024 19:26:42 +0000 Subject: [PATCH 14/42] fix build --- .../barretenberg/plonk_honk_shared/composer/composer_lib.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp index a5c9bb0c969..5fb9814ddaa 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp @@ -141,7 +141,7 @@ typename Flavor::Polynomial construct_lookup_read_counts(typename Flavor::Polyno read_counts[index_in_poly]++; read_tags[index_in_poly] = 1; } - table_offset += table.size; + table_offset += table.size(); } return read_counts; From b90989ca475e1b4f0dd726fa554fc77b371abada Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Mon, 17 Jun 2024 19:31:39 +0000 Subject: [PATCH 15/42] fix bad template alias --- .../src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp | 4 ++-- .../src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp index 970c53ec780..4ef1c587d3c 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp @@ -67,7 +67,7 @@ class MegaFlavor { bb::Poseidon2InternalRelation>; using Relations = Relations_; - using LogDerivLookupRelation = LogDerivLookupRelation; + // using LogDerivLookupRelation = LogDerivLookupRelation; static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = compute_max_partial_relation_length(); static constexpr size_t MAX_TOTAL_RELATION_LENGTH = compute_max_total_relation_length(); @@ -435,7 +435,7 @@ class MegaFlavor { void compute_logderivative_inverses(const RelationParameters& relation_parameters) { // Compute inverses for conventional lookups - compute_logderivative_inverse( + compute_logderivative_inverse>( this->polynomials, relation_parameters, this->circuit_size); // Compute inverses for calldata reads diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp index 69c293e193c..153099631ec 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp @@ -56,7 +56,7 @@ class UltraFlavor { bb::EllipticRelation, bb::AuxiliaryRelation>; - using LogDerivLookupRelation = bb::LogDerivLookupRelation; + // using LogDerivLookupRelation = bb::LogDerivLookupRelation; static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = compute_max_partial_relation_length(); static_assert(MAX_PARTIAL_RELATION_LENGTH == 6); @@ -369,7 +369,7 @@ class UltraFlavor { void compute_logderivative_inverses(const RelationParameters& relation_parameters) { // Compute inverses for conventional lookups - compute_logderivative_inverse( + compute_logderivative_inverse>( this->polynomials, relation_parameters, this->circuit_size); } From 6da8c4d0482b1fcfb71b787e964f675766baefe8 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Mon, 17 Jun 2024 16:45:20 +0000 Subject: [PATCH 16/42] use ultra in ultra recursive --- .../stdlib_circuit_builders/ultra_flavor.hpp | 75 +++--- .../ultra_recursive_flavor.hpp | 224 +----------------- 2 files changed, 48 insertions(+), 251 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp index 153099631ec..083960f24a1 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp @@ -49,12 +49,15 @@ class UltraFlavor { using GrandProductRelations = std::tuple, bb::LookupRelation>; // define the tuple of Relations that comprise the Sumcheck relation - using Relations = std::tuple, - bb::UltraPermutationRelation, - bb::LookupRelation, - bb::DeltaRangeConstraintRelation, - bb::EllipticRelation, - bb::AuxiliaryRelation>; + // Note: made generic for use in MegaRecursive. + template + using Relations_ = std::tuple, + bb::UltraPermutationRelation, + bb::LookupRelation, + bb::DeltaRangeConstraintRelation, + bb::EllipticRelation, + bb::AuxiliaryRelation>; + using Relations = Relations_; // using LogDerivLookupRelation = bb::LogDerivLookupRelation; @@ -91,7 +94,6 @@ class UltraFlavor { static constexpr bool is_decider = true; - private: /** * @brief A base class labelling precomputed entities and (ordered) subsets of interest. * @details Used to build the proving key and verification key. @@ -635,36 +637,37 @@ class UltraFlavor { * witness polynomials). * */ - class VerifierCommitments : public AllEntities { + template + class VerifierCommitments_ : public AllEntities { public: - VerifierCommitments(const std::shared_ptr& verification_key, - const std::optional& witness_commitments = std::nullopt) + VerifierCommitments_(const std::shared_ptr& verification_key, + const std::optional& witness_commitments = std::nullopt) { - q_m = verification_key->q_m; - q_c = verification_key->q_c; - q_l = verification_key->q_l; - q_r = verification_key->q_r; - q_o = verification_key->q_o; - q_4 = verification_key->q_4; - q_arith = verification_key->q_arith; - q_delta_range = verification_key->q_delta_range; - q_elliptic = verification_key->q_elliptic; - q_aux = verification_key->q_aux; - q_lookup = verification_key->q_lookup; - sigma_1 = verification_key->sigma_1; - sigma_2 = verification_key->sigma_2; - sigma_3 = verification_key->sigma_3; - sigma_4 = verification_key->sigma_4; - id_1 = verification_key->id_1; - id_2 = verification_key->id_2; - id_3 = verification_key->id_3; - id_4 = verification_key->id_4; - table_1 = verification_key->table_1; - table_2 = verification_key->table_2; - table_3 = verification_key->table_3; - table_4 = verification_key->table_4; - lagrange_first = verification_key->lagrange_first; - lagrange_last = verification_key->lagrange_last; + this->q_m = verification_key->q_m; + this->q_c = verification_key->q_c; + this->q_l = verification_key->q_l; + this->q_r = verification_key->q_r; + this->q_o = verification_key->q_o; + this->q_4 = verification_key->q_4; + this->q_arith = verification_key->q_arith; + this->q_delta_range = verification_key->q_delta_range; + this->q_elliptic = verification_key->q_elliptic; + this->q_aux = verification_key->q_aux; + this->q_lookup = verification_key->q_lookup; + this->sigma_1 = verification_key->sigma_1; + this->sigma_2 = verification_key->sigma_2; + this->sigma_3 = verification_key->sigma_3; + this->sigma_4 = verification_key->sigma_4; + this->id_1 = verification_key->id_1; + this->id_2 = verification_key->id_2; + this->id_3 = verification_key->id_3; + this->id_4 = verification_key->id_4; + this->table_1 = verification_key->table_1; + this->table_2 = verification_key->table_2; + this->table_3 = verification_key->table_3; + this->table_4 = verification_key->table_4; + this->lagrange_first = verification_key->lagrange_first; + this->lagrange_last = verification_key->lagrange_last; if (witness_commitments.has_value()) { auto commitments = witness_commitments.value(); @@ -678,6 +681,8 @@ class UltraFlavor { } } }; + // Specialize for Ultra (general case used in UltraRecursive). + using VerifierCommitments = VerifierCommitments_; /** * @brief Derived class that defines proof structure for Ultra proofs, as well as supporting functions. diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_recursive_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_recursive_flavor.hpp index 2979b9ac0d0..a73509fe018 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_recursive_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_recursive_flavor.hpp @@ -71,12 +71,7 @@ template class UltraRecursiveFlavor_ { static constexpr size_t NUM_WITNESS_ENTITIES = 7; // define the tuple of Relations that comprise the Sumcheck relation - using Relations = std::tuple, - bb::UltraPermutationRelation, - bb::LookupRelation, - bb::DeltaRangeConstraintRelation, - bb::EllipticRelation, - bb::AuxiliaryRelation>; + using Relations = UltraFlavor::Relations_; static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = compute_max_partial_relation_length(); static_assert(MAX_PARTIAL_RELATION_LENGTH == 6); @@ -99,167 +94,6 @@ template class UltraRecursiveFlavor_ { // define the container for storing the univariate contribution from each relation in Sumcheck using TupleOfArraysOfValues = decltype(create_tuple_of_arrays_of_values()); - private: - template - /** - * @brief A base class labelling precomputed entities and (ordered) subsets of interest. - * @details Used to build the proving key and verification key. - */ - class PrecomputedEntities : public PrecomputedEntitiesBase { - public: - DEFINE_FLAVOR_MEMBERS(DataType, - q_m, // column 0 - q_c, // column 1 - q_l, // column 2 - q_r, // column 3 - q_o, // column 4 - q_4, // column 5 - q_arith, // column 6 - q_delta_range, // column 7 - q_elliptic, // column 8 - q_aux, // column 9 - q_lookup, // column 10 - sigma_1, // column 11 - sigma_2, // column 12 - sigma_3, // column 13 - sigma_4, // column 14 - id_1, // column 15 - id_2, // column 16 - id_3, // column 17 - id_4, // column 18 - table_1, // column 19 - table_2, // column 20 - table_3, // column 21 - table_4, // column 22 - lagrange_first, // column 23 - lagrange_last); // column 24 - - auto get_selectors() - { - return RefArray{ q_m, q_c, q_l, q_r, q_o, q_4, q_arith, q_delta_range, q_elliptic, q_aux, q_lookup }; - }; - auto get_sigma_polynomials() { return RefArray{ sigma_1, sigma_2, sigma_3, sigma_4 }; }; - auto get_id_polynomials() { return RefArray{ id_1, id_2, id_3, id_4 }; }; - - auto get_table_polynomials() { return RefArray{ table_1, table_2, table_3, table_4 }; }; - }; - - /** - * @brief Container for all witness polynomials used/constructed by the prover. - * @details Shifts are not included here since they do not occupy their own memory. - */ - template class WitnessEntities { - public: - DEFINE_FLAVOR_MEMBERS(DataType, - w_l, // column 0 - w_r, // column 1 - w_o, // column 2 - w_4, // column 3 - sorted_accum, // column 4 - z_perm, // column 5 - z_lookup // column 6 - - ); - - auto get_wires() { return RefArray{ w_l, w_r, w_o, w_4 }; }; - }; - - public: - /** - * @brief A container for the witness commitments. - */ - using WitnessCommitments = WitnessEntities; - - /** - * @brief A base class labelling all entities (for instance, all of the polynomials used by the prover during - * sumcheck) in this Honk variant along with particular subsets of interest - * @details Used to build containers for: the prover's polynomial during sumcheck; the sumcheck's folded - * polynomials; the univariates consturcted during during sumcheck; the evaluations produced by sumcheck. - * - * Symbolically we have: AllEntities = PrecomputedEntities + WitnessEntities + "ShiftedEntities". It could be - * implemented as such, but we have this now. - */ - template class AllEntities { - public: - DEFINE_FLAVOR_MEMBERS(DataType, - q_c, // column 0 - q_l, // column 1 - q_r, // column 2 - q_o, // column 3 - q_4, // column 4 - q_m, // column 5 - q_arith, // column 6 - q_delta_range, // column 7 - q_elliptic, // column 8 - q_aux, // column 9 - q_lookup, // column 10 - sigma_1, // column 11 - sigma_2, // column 12 - sigma_3, // column 13 - sigma_4, // column 14 - id_1, // column 15 - id_2, // column 16 - id_3, // column 17 - id_4, // column 18 - table_1, // column 19 - table_2, // column 20 - table_3, // column 21 - table_4, // column 22 - lagrange_first, // column 23 - lagrange_last, // column 24 - w_l, // column 25 - w_r, // column 26 - w_o, // column 27 - w_4, // column 28 - sorted_accum, // column 29 - z_perm, // column 30 - z_lookup, // column 31 - table_1_shift, // column 32 - table_2_shift, // column 33 - table_3_shift, // column 34 - table_4_shift, // column 35 - w_l_shift, // column 36 - w_r_shift, // column 37 - w_o_shift, // column 38 - w_4_shift, // column 39 - sorted_accum_shift, // column 40 - z_perm_shift, // column 41 - z_lookup_shift // column 42 - ); - - auto get_wires() { return RefArray{ w_l, w_r, w_o, w_4 }; }; - // Gemini-specific getters. - auto get_unshifted() - { - return RefArray{ q_m, q_c, q_l, q_r, q_o, q_4, q_arith, q_delta_range, - 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 - - }; - }; - auto get_precomputed() - { - return RefArray{ q_m, q_c, q_l, q_r, q_o, q_4, q_arith, q_delta_range, - 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 - - }; - } - - auto get_witness() { return RefArray{ w_l, w_r, w_o, w_4, sorted_accum, z_perm, z_lookup }; }; - auto get_to_be_shifted() - { - return RefArray{ table_1, table_2, table_3, table_4, w_l, w_r, w_o, w_4, sorted_accum, z_perm, z_lookup }; - }; - auto get_shifted() - { - return RefArray{ 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 }; - }; - }; - public: /** * @brief The verification key is responsible for storing the the commitments to the precomputed (non-witnessk) @@ -269,7 +103,8 @@ template class UltraRecursiveFlavor_ { * that, and split out separate PrecomputedPolynomials/Commitments data for clarity but also for portability of our * circuits. */ - class VerificationKey : public VerificationKey_, VerifierCommitmentKey> { + class VerificationKey + : public VerificationKey_, VerifierCommitmentKey> { public: VerificationKey(const size_t circuit_size, const size_t num_public_inputs) { @@ -357,60 +192,17 @@ template class UltraRecursiveFlavor_ { * @brief A field element for each entity of the flavor. These entities represent the prover polynomials * evaluated at one point. */ - class AllValues : public AllEntities { + class AllValues : public UltraFlavor::AllEntities { public: - using Base = AllEntities; + using Base = UltraFlavor::AllEntities; using Base::Base; - AllValues(std::array _data_in) { this->_data = _data_in; } }; - /** - * @brief A container for commitment labels. - * @note It's debatable whether this should inherit from AllEntities. since most entries are not strictly - * needed. It has, however, been useful during debugging to have these labels available. - * - */ - class CommitmentLabels : public AllEntities { - public: - CommitmentLabels() - { - this->w_l = "W_L"; - this->w_r = "W_R"; - this->w_o = "W_O"; - this->w_4 = "W_4"; - this->z_perm = "Z_PERM"; - this->z_lookup = "Z_LOOKUP"; - this->sorted_accum = "SORTED_ACCUM"; + using CommitmentLabels = UltraFlavor::CommitmentLabels; - this->q_c = "Q_C"; - this->q_l = "Q_L"; - this->q_r = "Q_R"; - this->q_o = "Q_O"; - this->q_4 = "Q_4"; - this->q_m = "Q_M"; - this->q_arith = "Q_ARITH"; - this->q_delta_range = "Q_SORT"; - this->q_elliptic = "Q_ELLIPTIC"; - this->q_aux = "Q_AUX"; - this->q_lookup = "Q_LOOKUP"; - this->sigma_1 = "SIGMA_1"; - this->sigma_2 = "SIGMA_2"; - this->sigma_3 = "SIGMA_3"; - this->sigma_4 = "SIGMA_4"; - this->id_1 = "ID_1"; - this->id_2 = "ID_2"; - this->id_3 = "ID_3"; - this->id_4 = "ID_4"; - this->table_1 = "TABLE_1"; - this->table_2 = "TABLE_2"; - this->table_3 = "TABLE_3"; - this->table_4 = "TABLE_4"; - this->lagrange_first = "LAGRANGE_FIRST"; - this->lagrange_last = "LAGRANGE_LAST"; - }; - }; + using WitnessCommitments = UltraFlavor::WitnessEntities; - class VerifierCommitments : public AllEntities { + class VerifierCommitments : public UltraFlavor::AllEntities { public: VerifierCommitments(const std::shared_ptr& verification_key, const std::optional& witness_commitments = std::nullopt) From bd8903a7125210d5916450ba00b819111b7d415c Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Mon, 17 Jun 2024 20:09:03 +0000 Subject: [PATCH 17/42] update transcript tests --- .../cpp/src/barretenberg/ultra_honk/mega_transcript.test.cpp | 3 +++ .../cpp/src/barretenberg/ultra_honk/ultra_transcript.test.cpp | 3 +++ 2 files changed, 6 insertions(+) diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/mega_transcript.test.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/mega_transcript.test.cpp index 4b9f122c966..308eb95fed0 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/mega_transcript.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/mega_transcript.test.cpp @@ -66,10 +66,13 @@ class MegaTranscriptTests : public ::testing::Test { round++; manifest_expected.add_entry(round, "SORTED_ACCUM", frs_per_G); + manifest_expected.add_entry(round, "LOOKUP_READ_COUNTS", frs_per_G); + manifest_expected.add_entry(round, "LOOKUP_READ_TAGS", frs_per_G); manifest_expected.add_entry(round, "W_4", frs_per_G); manifest_expected.add_challenge(round, "beta", "gamma"); round++; + manifest_expected.add_entry(round, "LOOKUP_INVERSES", frs_per_G); manifest_expected.add_entry(round, "CALLDATA_INVERSES", frs_per_G); manifest_expected.add_entry(round, "RETURN_DATA_INVERSES", frs_per_G); manifest_expected.add_entry(round, "Z_PERM", frs_per_G); diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_transcript.test.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_transcript.test.cpp index 952894e4a36..560211d6416 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_transcript.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_transcript.test.cpp @@ -59,10 +59,13 @@ class UltraTranscriptTests : public ::testing::Test { round++; manifest_expected.add_entry(round, "SORTED_ACCUM", frs_per_G); + manifest_expected.add_entry(round, "LOOKUP_READ_COUNTS", frs_per_G); + manifest_expected.add_entry(round, "LOOKUP_READ_TAGS", frs_per_G); manifest_expected.add_entry(round, "W_4", frs_per_G); manifest_expected.add_challenge(round, "beta", "gamma"); round++; + manifest_expected.add_entry(round, "LOOKUP_INVERSES", frs_per_G); manifest_expected.add_entry(round, "Z_PERM", frs_per_G); manifest_expected.add_entry(round, "Z_LOOKUP", frs_per_G); From 50b53b9ec92d65716eada6d41ec0584ad38566a9 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Mon, 17 Jun 2024 20:31:18 +0000 Subject: [PATCH 18/42] update pg and ultra rec verifiers --- .../verifier/protogalaxy_recursive_verifier.cpp | 7 +++++++ .../honk_recursion/verifier/ultra_recursive_verifier.cpp | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/barretenberg/cpp/src/barretenberg/stdlib/honk_recursion/verifier/protogalaxy_recursive_verifier.cpp b/barretenberg/cpp/src/barretenberg/stdlib/honk_recursion/verifier/protogalaxy_recursive_verifier.cpp index b605840a125..6653fd5f9d1 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/honk_recursion/verifier/protogalaxy_recursive_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/honk_recursion/verifier/protogalaxy_recursive_verifier.cpp @@ -58,12 +58,19 @@ void ProtoGalaxyRecursiveVerifier_::receive_and_finalise_inst domain_separator + "_eta", domain_separator + "_eta_two", domain_separator + "_eta_three"); witness_commitments.sorted_accum = transcript->template receive_from_prover(domain_separator + "_" + labels.sorted_accum); + witness_commitments.lookup_read_counts = + transcript->template receive_from_prover(domain_separator + "_" + labels.lookup_read_counts); + witness_commitments.lookup_read_tags = + transcript->template receive_from_prover(domain_separator + "_" + labels.lookup_read_tags); witness_commitments.w_4 = transcript->template receive_from_prover(domain_separator + "_" + labels.w_4); // Get permutation challenges and commitment to permutation and lookup grand products auto [beta, gamma] = transcript->template get_challenges(domain_separator + "_beta", domain_separator + "_gamma"); + witness_commitments.lookup_inverses = transcript->template receive_from_prover( + domain_separator + "_" + commitment_labels.lookup_inverses); + // If Goblin (i.e. using DataBus) receive commitments to log-deriv inverses polynomial if constexpr (IsGoblinFlavor) { witness_commitments.calldata_inverses = transcript->template receive_from_prover( diff --git a/barretenberg/cpp/src/barretenberg/stdlib/honk_recursion/verifier/ultra_recursive_verifier.cpp b/barretenberg/cpp/src/barretenberg/stdlib/honk_recursion/verifier/ultra_recursive_verifier.cpp index abb38ea241a..fa630c64fbb 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/honk_recursion/verifier/ultra_recursive_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/honk_recursion/verifier/ultra_recursive_verifier.cpp @@ -97,11 +97,18 @@ std::array UltraRecursiveVerifier_::ve // Get commitments to sorted list accumulator and fourth wire commitments.sorted_accum = transcript->template receive_from_prover(commitment_labels.sorted_accum); + commitments.lookup_read_counts = + transcript->template receive_from_prover(commitment_labels.lookup_read_counts); + commitments.lookup_read_tags = + transcript->template receive_from_prover(commitment_labels.lookup_read_tags); commitments.w_4 = transcript->template receive_from_prover(commitment_labels.w_4); // Get permutation challenges auto [beta, gamma] = transcript->template get_challenges("beta", "gamma"); + commitments.lookup_inverses = + transcript->template receive_from_prover(commitment_labels.lookup_inverses); + // If Goblin (i.e. using DataBus) receive commitments to log-deriv inverses polynomial if constexpr (IsGoblinFlavor) { commitments.calldata_inverses = From 97ecc4042a23ce5bb82c9e283c47f46b5b179bd7 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Mon, 17 Jun 2024 20:48:36 +0000 Subject: [PATCH 19/42] add lookup polys to verifier commitments for ultra --- .../barretenberg/stdlib_circuit_builders/mega_flavor.hpp | 3 +++ .../barretenberg/stdlib_circuit_builders/ultra_flavor.hpp | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp index 4ef1c587d3c..b2ccb23dade 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp @@ -221,6 +221,9 @@ class MegaFlavor { this->sorted_accum, this->z_perm, this->z_lookup, + this->lookup_inverses, + this->lookup_read_counts, + this->lookup_read_tags, this->ecc_op_wire_1, this->ecc_op_wire_2, this->ecc_op_wire_3, diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp index 083960f24a1..b09cc74fd7c 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp @@ -160,7 +160,8 @@ class UltraFlavor { auto get_wires() { return RefArray{ w_l, w_r, w_o, w_4 }; }; - MSGPACK_FIELDS(w_l, w_r, w_o, w_4, sorted_accum, z_perm, z_lookup); + MSGPACK_FIELDS( + w_l, w_r, w_o, w_4, sorted_accum, z_perm, z_lookup, lookup_inverses, lookup_read_counts, lookup_read_tags); }; /** @@ -675,6 +676,9 @@ class UltraFlavor { this->w_r = commitments.w_r; this->w_o = commitments.w_o; this->sorted_accum = commitments.sorted_accum; + this->lookup_inverses = commitments.lookup_inverses; + this->lookup_read_counts = commitments.lookup_read_counts; + this->lookup_read_tags = commitments.lookup_read_tags; this->w_4 = commitments.w_4; this->z_perm = commitments.z_perm; this->z_lookup = commitments.z_lookup; From 6d95dbe7127bab5cd150201b54e91b39eb96b1da Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Mon, 17 Jun 2024 21:05:31 +0000 Subject: [PATCH 20/42] fix ultra rec flavor --- .../stdlib_circuit_builders/ultra_recursive_flavor.hpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_recursive_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_recursive_flavor.hpp index a73509fe018..6ca21196e8b 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_recursive_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_recursive_flavor.hpp @@ -239,6 +239,9 @@ template class UltraRecursiveFlavor_ { this->w_r = commitments.w_r; this->w_o = commitments.w_o; this->sorted_accum = commitments.sorted_accum; + this->lookup_inverses = commitments.lookup_inverses; + this->lookup_read_counts = commitments.lookup_read_counts; + this->lookup_read_tags = commitments.lookup_read_tags; this->w_4 = commitments.w_4; this->z_perm = commitments.z_perm; this->z_lookup = commitments.z_lookup; From a84bb7584488ae6917548614b3779c0bc34cd395 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Mon, 17 Jun 2024 21:34:11 +0000 Subject: [PATCH 21/42] use ultra sizes in rec ultra flav --- .../stdlib_circuit_builders/ultra_recursive_flavor.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_recursive_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_recursive_flavor.hpp index 6ca21196e8b..444fe8670d9 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_recursive_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_recursive_flavor.hpp @@ -63,12 +63,12 @@ template class UltraRecursiveFlavor_ { // The number of multivariate polynomials on which a sumcheck prover sumcheck operates (including shifts). We often // need containers of this size to hold related data, so we choose a name more agnostic than `NUM_POLYNOMIALS`. // Note: this number does not include the individual sorted list polynomials. - static constexpr size_t NUM_ALL_ENTITIES = 43; + static constexpr size_t NUM_ALL_ENTITIES = UltraFlavor::NUM_ALL_ENTITIES; // The number of polynomials precomputed to describe a circuit and to aid a prover in constructing a satisfying // assignment of witnesses. We again choose a neutral name. - static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 25; + static constexpr size_t NUM_PRECOMPUTED_ENTITIES = UltraFlavor::NUM_PRECOMPUTED_ENTITIES; // The total number of witness entities not including shifts. - static constexpr size_t NUM_WITNESS_ENTITIES = 7; + static constexpr size_t NUM_WITNESS_ENTITIES = UltraFlavor::NUM_WITNESS_ENTITIES; // define the tuple of Relations that comprise the Sumcheck relation using Relations = UltraFlavor::Relations_; From 3aa43c653ab3012731eef54ae054cd08600fe95b Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Mon, 17 Jun 2024 21:57:19 +0000 Subject: [PATCH 22/42] turn on log deriv lookups in the flavors --- .../relations/logderiv_lookup_relation.hpp | 31 +++++++++---------- .../stdlib_circuit_builders/mega_flavor.hpp | 1 + .../stdlib_circuit_builders/ultra_flavor.hpp | 1 + 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp index b30f35f5317..b7e4870006a 100644 --- a/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp @@ -77,13 +77,14 @@ template class LogDerivLookupRelationImpl { static Accumulator compute_write_term(const AllEntities& in, const Parameters& params) { using View = typename Accumulator::View; + using ParameterView = GetParameterView; static_assert(write_index < WRITE_TERMS); - const auto& gamma = params.gamma; - const auto& beta = params.beta; - const auto& beta_sqr = params.beta_sqr; - const auto& beta_cube = params.beta_cube; + const auto& gamma = ParameterView(params.gamma); + const auto& beta = ParameterView(params.beta); + const auto& beta_sqr = ParameterView(params.beta_sqr); + const auto& beta_cube = ParameterView(params.beta_cube); auto table_1 = View(in.table_1); auto table_2 = View(in.table_2); @@ -97,11 +98,12 @@ template class LogDerivLookupRelationImpl { static Accumulator compute_read_term(const AllEntities& in, const Parameters& params) { using View = typename Accumulator::View; + using ParameterView = GetParameterView; - const auto& gamma = params.gamma; - const auto& beta = params.beta; - const auto& beta_sqr = params.beta_sqr; - const auto& beta_cube = params.beta_cube; + const auto& gamma = ParameterView(params.gamma); + const auto& beta = ParameterView(params.beta); + const auto& beta_sqr = ParameterView(params.beta_sqr); + const auto& beta_cube = ParameterView(params.beta_cube); auto w_1 = View(in.w_l); auto w_2 = View(in.w_r); @@ -118,24 +120,19 @@ template class LogDerivLookupRelationImpl { // The wire values for lookup gates are accumulators structured in such a way that the differences w_i - // step_size*w_i_shift should result in a values that exists in table_i. - auto derived_table_entry_1 = w_1 + negative_column_1_step_size * w_1_shift; + auto derived_table_entry_1 = w_1 + gamma + negative_column_1_step_size * w_1_shift; auto derived_table_entry_2 = w_2 + negative_column_2_step_size * w_2_shift; auto derived_table_entry_3 = w_3 + negative_column_3_step_size * w_3_shift; // (w_1 + q_2*w_1_shift) + η(w_2 + q_m*w_2_shift) + η₂(w_3 + q_c*w_3_shift) + η₃q_index. // deg 2 or 3 - return derived_table_entry_1 + gamma + derived_table_entry_2 * beta + derived_table_entry_3 * beta_sqr + + return derived_table_entry_1 + derived_table_entry_2 * beta + derived_table_entry_3 * beta_sqr + table_index * beta_cube; } /** - * @brief Expression for ECCVM lookup tables. - * @details We use log-derivative lookup tables for the following case: - * Table writes: ECCVMPointTable columns: we define Straus point table: - * { {0, -15[P]}, {1, -13[P]}, ..., {15, 15[P]} } - * write source: { precompute_round, precompute_tx, precompute_ty } - * Table reads: ECCVMMSM columns. Each row adds up to 4 points into MSM accumulator - * read source: { msm_slice1, msm_x1, msm_y1 }, ..., { msm_slice4, msm_x4, msm_y4 } + * @brief WORKTODO + * * @param accumulator transformed to `evals + C(in(X)...)*scaling_factor` * @param in an std::array containing the fully extended Accumulator edges. * @param relation_params contains beta, gamma, and public_input_delta, .... diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp index b2ccb23dade..14df8d32a5d 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp @@ -58,6 +58,7 @@ class MegaFlavor { using Relations_ = std::tuple, bb::UltraPermutationRelation, bb::LookupRelation, + bb::LogDerivLookupRelation, bb::DeltaRangeConstraintRelation, bb::EllipticRelation, bb::AuxiliaryRelation, diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp index b09cc74fd7c..1119a9a6036 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp @@ -54,6 +54,7 @@ class UltraFlavor { using Relations_ = std::tuple, bb::UltraPermutationRelation, bb::LookupRelation, + bb::LogDerivLookupRelation, bb::DeltaRangeConstraintRelation, bb::EllipticRelation, bb::AuxiliaryRelation>; From e728e8a70873652ce98d326aac11cd764684989f Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Tue, 18 Jun 2024 20:16:01 +0000 Subject: [PATCH 23/42] remove pi folding and add a test --- .../protogalaxy/protogalaxy.test.cpp | 33 +++++++++++++++++++ .../protogalaxy/protogalaxy_prover_impl.hpp | 16 --------- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp index 1833659d8ef..073995e3d73 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp @@ -308,6 +308,34 @@ template class ProtoGalaxyTests : public testing::Test { } } + /** + * @brief Testing one valid round of folding followed by the decider. + * @brief For additional robustness we give one of the circuits more public inputs than the other + * + */ + static void test_full_protogalaxy_simple() + { + // Construct a first circuit with some public inputs + Builder builder1; + construct_circuit(builder1); + bb::MockCircuits::add_arithmetic_gates_with_public_inputs(builder1, /*num_gates=*/4); + + // Construct a second circuit with no public inputs + Builder builder2; + construct_circuit(builder2); + + // Construct the prover/verifier instances for each + TupleOfInstances instances; + construct_prover_and_verifier_instance(instances, builder1); + construct_prover_and_verifier_instance(instances, builder2); + + // Perform prover and verifier folding + auto [prover_accumulator, verifier_accumulator] = fold_and_verify(get<0>(instances), get<1>(instances)); + check_accumulator_target_sum_manual(prover_accumulator, true); + + decide_and_verify(prover_accumulator, verifier_accumulator, true); + } + /** * @brief Testing two valid rounds of folding followed by the decider. * @@ -487,6 +515,11 @@ TYPED_TEST(ProtoGalaxyTests, CombineAlpha) TestFixture::test_combine_alpha(); } +TYPED_TEST(ProtoGalaxyTests, FullProtogalaxySimple) +{ + TestFixture::test_full_protogalaxy_simple(); +} + TYPED_TEST(ProtoGalaxyTests, FullProtogalaxyTest) { TestFixture::test_full_protogalaxy(); diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp index 02fbb08ff15..f38ff10b3e1 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp @@ -104,22 +104,6 @@ std::shared_ptr ProtoGalaxyProver_proving_key.public_inputs) { - el *= lagranges[0]; - size_t inst = 0; - for (size_t inst_idx = 1; inst_idx < ProverInstances::NUM; inst_idx++) { - auto& instance = instances[inst_idx]; - // TODO(https://github.com/AztecProtocol/barretenberg/issues/830) - if (instance->proving_key.num_public_inputs >= next_accumulator->proving_key.num_public_inputs) { - el += instance->proving_key.public_inputs[el_idx] * lagranges[inst]; - inst++; - }; - } - el_idx++; - } - // Evaluate the combined batching α_i univariate at challenge to obtain next α_i and send it to the // verifier, where i ∈ {0,...,NUM_SUBRELATIONS - 1} auto& folded_alphas = next_accumulator->alphas; From cf8e0a0c79d3df0b4e1896013cf6c61e6a55fd43 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Tue, 18 Jun 2024 20:23:21 +0000 Subject: [PATCH 24/42] remove pi folding from verifier as well --- .../protogalaxy/protogalaxy_verifier.cpp | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_verifier.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_verifier.cpp index a16bacd6e3d..9ffce227620 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_verifier.cpp @@ -115,19 +115,7 @@ std::shared_ptr ProtoGalaxyVerifier_verification_key->num_public_inputs = accumulator->verification_key->num_public_inputs; next_accumulator->public_inputs = std::vector(static_cast(next_accumulator->verification_key->num_public_inputs), 0); - size_t public_input_idx = 0; - for (auto& public_input : next_accumulator->public_inputs) { - size_t inst = 0; - for (auto& instance : instances) { - // TODO(https://github.com/AztecProtocol/barretenberg/issues/830) - if (instance->verification_key->num_public_inputs >= - next_accumulator->verification_key->num_public_inputs) { - public_input += instance->public_inputs[public_input_idx] * lagranges[inst]; - inst++; - } - } - public_input_idx++; - } + next_accumulator->is_accumulator = true; // Compute next folding parameters From 46b70ba1da62d38db1be30c8654c4cf683d69847 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Wed, 19 Jun 2024 13:56:14 +0000 Subject: [PATCH 25/42] test cleanup --- .../composer/composer_lib.test.cpp | 24 +------------------ 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.test.cpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.test.cpp index 890013dc341..c6c4eb24d4c 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.test.cpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.test.cpp @@ -1,25 +1,8 @@ #include "barretenberg/plonk_honk_shared/composer/composer_lib.hpp" -#include "barretenberg/circuit_checker/circuit_checker.hpp" -#include "barretenberg/common/slab_allocator.hpp" -#include "barretenberg/plonk_honk_shared/types/circuit_type.hpp" #include "barretenberg/srs/factories/crs_factory.hpp" #include "barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp" #include "barretenberg/stdlib_circuit_builders/ultra_flavor.hpp" -// #include "barretenberg/common/serialize.hpp" -// #include "barretenberg/ecc/curves/bn254/fr.hpp" -// #include "barretenberg/numeric/uint256/uint256.hpp" -// #include "barretenberg/plonk_honk_shared/library/grand_product_delta.hpp" -// #include "barretenberg/relations/permutation_relation.hpp" -// #include "barretenberg/relations/relation_parameters.hpp" -// #include "barretenberg/stdlib_circuit_builders/mock_circuits.hpp" -// #include "barretenberg/stdlib_circuit_builders/plookup_tables/fixed_base/fixed_base.hpp" -// #include "barretenberg/stdlib_circuit_builders/plookup_tables/types.hpp" -// #include "barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp" -// #include "barretenberg/sumcheck/sumcheck_round.hpp" -// #include "barretenberg/ultra_honk/ultra_prover.hpp" -// #include "barretenberg/ultra_honk/ultra_verifier.hpp" - #include #include @@ -29,12 +12,7 @@ class ComposerLibTests : public ::testing::Test { public: using Flavor = UltraFlavor; using FF = typename Flavor::FF; - // Flavor::CircuitBuilder circuit_constructor; - // Flavor::ProvingKey proving_key = []() { - // auto crs_factory = srs::factories::CrsFactory(); - // auto crs = crs_factory.get_prover_crs(4); - // return Flavor::ProvingKey(/*circuit_size=*/8, /*num_public_inputs=*/0); - // }(); + protected: static void SetUpTestSuite() { bb::srs::init_crs_factory("../srs_db/ignition"); } }; From 4dfd4156230c2e706bbad25d31d6b5ca6f7a9c1d Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Wed, 19 Jun 2024 14:59:31 +0000 Subject: [PATCH 26/42] remove lookup relation and all its paraphernalia --- .../relations_bench/relations.bench.cpp | 3 - .../src/barretenberg/eccvm/eccvm_prover.cpp | 1 - .../protogalaxy/protogalaxy.test.cpp | 6 +- .../relations/lookup_relation.hpp | 224 ------------------ .../ultra_relation_consistency.test.cpp | 79 ------ .../protogalaxy_recursive_verifier.cpp | 4 - .../verifier/ultra_recursive_verifier.cpp | 2 - .../honk_recursion/verifier/verifier.test.cpp | 2 +- .../grand_product_library.test.cpp | 133 ----------- .../stdlib_circuit_builders/mega_flavor.hpp | 86 ++----- .../stdlib_circuit_builders/ultra_flavor.hpp | 90 ++----- .../ultra_recursive_flavor.hpp | 3 - .../sumcheck/instance/prover_instance.hpp | 2 - .../instance/prover_instance.test.cpp | 53 +---- .../barretenberg/sumcheck/sumcheck.test.cpp | 1 - .../ultra_honk/mega_transcript.test.cpp | 6 +- .../barretenberg/ultra_honk/oink_prover.cpp | 6 +- .../barretenberg/ultra_honk/oink_verifier.cpp | 4 - .../ultra_honk/relation_correctness.test.cpp | 15 +- .../barretenberg/ultra_honk/sumcheck.test.cpp | 7 +- .../ultra_honk/ultra_transcript.test.cpp | 6 +- .../barretenberg/vm/generated/avm_prover.cpp | 1 - 22 files changed, 52 insertions(+), 682 deletions(-) delete mode 100644 barretenberg/cpp/src/barretenberg/relations/lookup_relation.hpp diff --git a/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp index 6e7069f08ae..00ec04a5521 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp @@ -65,7 +65,6 @@ BENCHMARK(execute_relation_for_pg_univariates>); BENCHMARK(execute_relation_for_pg_univariates>); BENCHMARK(execute_relation_for_pg_univariates>); -BENCHMARK(execute_relation_for_pg_univariates>); BENCHMARK(execute_relation_for_pg_univariates>); // Goblin-Ultra only relations (PG prover combiner work) @@ -79,7 +78,6 @@ BENCHMARK(execute_relation_for_univariates>); BENCHMARK(execute_relation_for_univariates>); BENCHMARK(execute_relation_for_univariates>); -BENCHMARK(execute_relation_for_univariates>); BENCHMARK(execute_relation_for_univariates>); // Goblin-Ultra only relations (Sumcheck prover work) @@ -93,7 +91,6 @@ BENCHMARK(execute_relation_for_values>) BENCHMARK(execute_relation_for_values>); BENCHMARK(execute_relation_for_values>); BENCHMARK(execute_relation_for_values>); -BENCHMARK(execute_relation_for_values>); BENCHMARK(execute_relation_for_values>); // Goblin-Ultra only relations (verifier work) diff --git a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_prover.cpp b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_prover.cpp index 43cd7248f11..ce55bef0af3 100644 --- a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_prover.cpp @@ -6,7 +6,6 @@ #include "barretenberg/honk/proof_system/permutation_library.hpp" #include "barretenberg/plonk_honk_shared/library/grand_product_library.hpp" #include "barretenberg/polynomials/polynomial.hpp" -#include "barretenberg/relations/lookup_relation.hpp" #include "barretenberg/relations/permutation_relation.hpp" #include "barretenberg/sumcheck/sumcheck.hpp" diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp index 073995e3d73..5eec42117d5 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp @@ -136,9 +136,9 @@ template class ProtoGalaxyTests : public testing::Test { instance->relation_parameters.beta = FF::random_element(); instance->relation_parameters.gamma = FF::random_element(); - instance->proving_key.compute_sorted_accumulator_polynomials(instance->relation_parameters.eta, - instance->relation_parameters.eta_two, - instance->relation_parameters.eta_three); + instance->proving_key.add_plookup_memory_records_to_wire_4(instance->relation_parameters.eta, + instance->relation_parameters.eta_two, + instance->relation_parameters.eta_three); instance->proving_key.compute_logderivative_inverses(instance->relation_parameters); instance->proving_key.compute_grand_product_polynomials(instance->relation_parameters); diff --git a/barretenberg/cpp/src/barretenberg/relations/lookup_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/lookup_relation.hpp deleted file mode 100644 index 46b70df7cab..00000000000 --- a/barretenberg/cpp/src/barretenberg/relations/lookup_relation.hpp +++ /dev/null @@ -1,224 +0,0 @@ -#pragma once -#include "barretenberg/relations/relation_types.hpp" - -namespace bb { - -/** - * @brief LookupRelationImpl defines the algebra for the lookup polynomial: - * - * ∏ (1 + β) ⋅ (q_lookup*f_k + γ) ⋅ (t_k + βt_{k+1} + γ(1 + β)) - * Z_lookup(g^j) = -------------------------------------------------------------------------- - * ∏ (s_k + βs_{k+1} + γ(1 + β)) - * - * - * The method `compute_numerator_term` computes polynomials f, t and incorporate them into terms that are ultimately - * needed to construct the grand product polynomial Z_lookup(X): Note 1: In the above, 't' is associated with table - * values (and is not to be confused with the quotient polynomial, also refered to as 't' elsewhere). Polynomial 's' is - * the sorted concatenation of the witnesses and the table values. - * - * @tparam FF parametrises the prime field class being used - */ -template class LookupRelationImpl { - public: - using FF = FF_; - - static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ - 6, // grand product construction sub-relation - 3 // left-shiftable polynomial sub-relation - }; - - static constexpr std::array TOTAL_LENGTH_ADJUSTMENTS{ - 4, // grand product construction sub-relation - 0 // left-shiftable polynomial sub-relation - }; - - /** - * @brief Returns true if the contribution from all subrelations for the provided inputs is identically zero - * - */ - template inline static bool skip([[maybe_unused]] const AllEntities& in) - { - // TODO(https://github.com/AztecProtocol/barretenberg/issues/952): figure out why skip condition described in - // issue causes failures in acir tests. - return false; - } - - /** - * @brief Get the grand product polynomial object (either from the proving key or AllEntities depending on context) - * - * @param input - * @return auto& either std::span or Flavor::Polynomial depending on context - */ - inline static auto& get_grand_product_polynomial(auto& input) { return input.z_lookup; } - - /** - * @brief Get the shifted grand product polynomial object (either from the proving key or AllEntities depending on - * context) - * - * @param input - * @return auto& either std::span or Flavor::Polynomial depending on context - */ - inline static auto& get_shifted_grand_product_polynomial(auto& input) { return input.z_lookup_shift; } - - /** - * @brief Compute numerator term of the lookup relation: - * - * N_{index} = (1 + β) ⋅ ∏ (q_lookup*f_k + γ) ⋅ (t_k + βt_{k+1} + γ(1 + β)) - * - * @tparam AccumulatorTypes - * @param in - * @param relation_parameters - * @param index If calling this method over vector inputs, index >= 0 - */ - template - inline static Accumulator compute_grand_product_numerator(const AllEntities& in, const Parameters& params) - { - using View = typename Accumulator::View; - using ParameterView = GetParameterView; - - const auto& beta = ParameterView(params.beta); - const auto& gamma = ParameterView(params.gamma); - const auto& eta = ParameterView(params.eta); - const auto& eta_two = ParameterView(params.eta_two); - const auto& eta_three = ParameterView(params.eta_three); - - const auto one_plus_beta = beta + FF(1); - const auto gamma_by_one_plus_beta = gamma * one_plus_beta; - - auto w_1 = View(in.w_l); - auto w_2 = View(in.w_r); - auto w_3 = View(in.w_o); - - auto w_1_shift = View(in.w_l_shift); - auto w_2_shift = View(in.w_r_shift); - auto w_3_shift = View(in.w_o_shift); - - auto table_1 = View(in.table_1); - auto table_2 = View(in.table_2); - auto table_3 = View(in.table_3); - auto table_4 = View(in.table_4); - - auto table_1_shift = View(in.table_1_shift); - auto table_2_shift = View(in.table_2_shift); - auto table_3_shift = View(in.table_3_shift); - auto table_4_shift = View(in.table_4_shift); - - auto table_index = View(in.q_o); - auto column_1_step_size = View(in.q_r); - auto column_2_step_size = View(in.q_m); - auto column_3_step_size = View(in.q_c); - auto q_lookup = View(in.q_lookup); - - // (w_1 + q_2*w_1_shift) + η(w_2 + q_m*w_2_shift) + η₂(w_3 + q_c*w_3_shift) + η₃q_index. - // deg 2 or 3 - auto wire_accum = (w_1 + column_1_step_size * w_1_shift) + (w_2 + column_2_step_size * w_2_shift) * eta + - (w_3 + column_3_step_size * w_3_shift) * eta_two + table_index * eta_three; - - // t_1 + ηt_2 + η₂t_3 + η₃t_4 - // deg 1 or 2 - auto table_accum = table_1 + table_2 * eta + table_3 * eta_two + table_4 * eta_three; - - // t_1_shift + ηt_2_shift + η₂t_3_shift + η₃t_4_shift - // deg 1 or 2 - auto table_accum_shift = - table_1_shift + table_2_shift * eta + table_3_shift * eta_two + table_4_shift * eta_three; - - auto tmp = (q_lookup * wire_accum + gamma); // deg 3 or 4 - tmp *= (table_accum + table_accum_shift * beta + gamma_by_one_plus_beta); // 1 or 3 - tmp *= one_plus_beta; // deg 0 or 1 - return tmp; // deg 4 or 8 - } - - /** - * @brief Compute denominator term of the lookup relation: - * - * (s_k + βs_{k+1} + γ(1 + β)) - * - * @tparam AccumulatorTypes - * @param in - * @param relation_parameters - * @param index - */ - template - inline static Accumulator compute_grand_product_denominator(const AllEntities& in, const Parameters& params) - { - - using View = typename Accumulator::View; - using ParameterView = GetParameterView; - - const auto& beta = ParameterView(params.beta); - const auto& gamma = ParameterView(params.gamma); - - const auto one_plus_beta = beta + FF(1); - const auto gamma_by_one_plus_beta = gamma * one_plus_beta; // deg 0 or 2 - - // Contribution (1) - auto s_accum = View(in.sorted_accum); - auto s_accum_shift = View(in.sorted_accum_shift); - - auto tmp = (s_accum + s_accum_shift * beta + gamma_by_one_plus_beta); // 1 or 2 - return tmp; - } - - /** - * @brief Compute contribution of the lookup grand prod relation for a given edge (internal function) - * - * @details This the relation confirms faithful calculation of the lookup grand - * product polynomial Z_lookup. The contribution is - * z_lookup * (1 + β) * [q_lookup * f + γ] * (t_accum_k + βt_accum_{k+1} + γ(1 + β)) - - * z_lookup_shift * (s_accum_k + βs_accum_{k+1} + γ(1 + β)) - * where - * f = (w_1 + q_2*w_1_shift) + η(w_2 + q_m*w_2_shift) + η²(w_3 + q_c*w_3_shift) + η³q_index, - * t_accum = table_1 + ηtable_2 + η²table_3 + η³table_4, and - * s_accum = s_1 + ηs_2 + η²s_3 + η³s_4. - * Note: Selectors q_2, q_m and q_c are repurposed as 'column step size' for lookup gates. - * - * @param evals transformed to `evals + C(in(X)...)*scaling_factor` - * @param in an std::array containing the fully extended Univariate edges. - * @param parameters contains beta, gamma, and public_input_delta, .... - * @param scaling_factor optional term to scale the evaluation before adding to evals. - */ - template - inline static void accumulate(ContainerOverSubrelations& accumulators, - const AllEntities& in, - const Parameters& params, - const FF& scaling_factor) - { - BB_OP_COUNT_TIME_NAME("Lookup::accumulate"); - { - using Accumulator = std::tuple_element_t<0, ContainerOverSubrelations>; - using View = typename Accumulator::View; - using ParameterView = GetParameterView; - - const auto& grand_product_delta = ParameterView(params.lookup_grand_product_delta); - - auto z_lookup = View(in.z_lookup); - auto z_lookup_shift = View(in.z_lookup_shift); - - auto lagrange_first = View(in.lagrange_first); - auto lagrange_last = View(in.lagrange_last); - - const auto lhs = compute_grand_product_numerator(in, params); // deg 4 or 8 - const auto rhs = compute_grand_product_denominator(in, params); // deg 1 or 2 - - // (deg 5 or 9) - (deg 3 or 5) - const auto tmp = - lhs * (z_lookup + lagrange_first) - rhs * (z_lookup_shift + lagrange_last * grand_product_delta); - std::get<0>(accumulators) += tmp * scaling_factor; - }; - - { - using Accumulator = std::tuple_element_t<1, ContainerOverSubrelations>; - using View = typename Accumulator::View; - auto z_lookup_shift = View(in.z_lookup_shift); - auto lagrange_last = View(in.lagrange_last); - - // Contribution (2) - std::get<1>(accumulators) += (lagrange_last * z_lookup_shift) * scaling_factor; - }; - }; -}; - -template using LookupRelation = Relation>; - -} // namespace bb \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/relations/ultra_relation_consistency.test.cpp b/barretenberg/cpp/src/barretenberg/relations/ultra_relation_consistency.test.cpp index 0406f82bcef..b40b45da3c6 100644 --- a/barretenberg/cpp/src/barretenberg/relations/ultra_relation_consistency.test.cpp +++ b/barretenberg/cpp/src/barretenberg/relations/ultra_relation_consistency.test.cpp @@ -16,7 +16,6 @@ #include "barretenberg/relations/auxiliary_relation.hpp" #include "barretenberg/relations/delta_range_constraint_relation.hpp" #include "barretenberg/relations/elliptic_relation.hpp" -#include "barretenberg/relations/lookup_relation.hpp" #include "barretenberg/relations/permutation_relation.hpp" #include "barretenberg/relations/poseidon2_external_relation.hpp" #include "barretenberg/relations/poseidon2_internal_relation.hpp" @@ -204,84 +203,6 @@ TEST_F(UltraRelationConsistency, UltraPermutationRelation) run_test(/*random_inputs=*/true); }; -TEST_F(UltraRelationConsistency, LookupRelation) -{ - const auto run_test = [](bool random_inputs) { - using Relation = LookupRelation; - using SumcheckArrayOfValuesOverSubrelations = typename Relation::SumcheckArrayOfValuesOverSubrelations; - - const InputElements input_elements = random_inputs ? InputElements::get_random() : InputElements::get_special(); - const auto& w_1 = input_elements.w_l; - const auto& w_2 = input_elements.w_r; - const auto& w_3 = input_elements.w_o; - - const auto& w_1_shift = input_elements.w_l_shift; - const auto& w_2_shift = input_elements.w_r_shift; - const auto& w_3_shift = input_elements.w_o_shift; - - const auto& table_1 = input_elements.table_1; - const auto& table_2 = input_elements.table_2; - const auto& table_3 = input_elements.table_3; - const auto& table_4 = input_elements.table_4; - - const auto& table_1_shift = input_elements.table_1_shift; - const auto& table_2_shift = input_elements.table_2_shift; - const auto& table_3_shift = input_elements.table_3_shift; - const auto& table_4_shift = input_elements.table_4_shift; - - const auto& s_accum = input_elements.sorted_accum; - const auto& s_accum_shift = input_elements.sorted_accum_shift; - const auto& z_lookup = input_elements.z_lookup; - const auto& z_lookup_shift = input_elements.z_lookup_shift; - - const auto& table_index = input_elements.q_o; - const auto& column_1_step_size = input_elements.q_r; - const auto& column_2_step_size = input_elements.q_m; - const auto& column_3_step_size = input_elements.q_c; - const auto& q_lookup = input_elements.q_lookup; - - const auto& lagrange_first = input_elements.lagrange_first; - const auto& lagrange_last = input_elements.lagrange_last; - - SumcheckArrayOfValuesOverSubrelations expected_values; - - const auto parameters = RelationParameters::get_random(); - - const auto eta = parameters.eta; - const auto eta_two = parameters.eta_two; - const auto eta_three = parameters.eta_three; - const auto beta = parameters.beta; - const auto gamma = parameters.gamma; - auto grand_product_delta = parameters.lookup_grand_product_delta; - - // Extract the extended edges for manual computation of relation contribution - auto one_plus_beta = FF::one() + beta; - auto gamma_by_one_plus_beta = gamma * one_plus_beta; - - auto wire_accum = (w_1 + column_1_step_size * w_1_shift) + (w_2 + column_2_step_size * w_2_shift) * eta + - (w_3 + column_3_step_size * w_3_shift) * eta_two + table_index * eta_three; - - auto table_accum = table_1 + table_2 * eta + table_3 * eta_two + table_4 * eta_three; - auto table_accum_shift = - table_1_shift + table_2_shift * eta + table_3_shift * eta_two + table_4_shift * eta_three; - - // Contribution 1 - auto contribution_1 = (z_lookup + lagrange_first) * (q_lookup * wire_accum + gamma) * - (table_accum + table_accum_shift * beta + gamma_by_one_plus_beta) * one_plus_beta; - contribution_1 -= (z_lookup_shift + lagrange_last * grand_product_delta) * - (s_accum + s_accum_shift * beta + gamma_by_one_plus_beta); - expected_values[0] = contribution_1; - - // Contribution 2 - auto contribution_2 = z_lookup_shift * lagrange_last; - expected_values[1] = contribution_2; - - validate_relation_execution(expected_values, input_elements, parameters); - }; - run_test(/*random_inputs=*/false); - run_test(/*random_inputs=*/true); -}; - TEST_F(UltraRelationConsistency, DeltaRangeConstraintRelation) { const auto run_test = [](bool random_inputs) { diff --git a/barretenberg/cpp/src/barretenberg/stdlib/honk_recursion/verifier/protogalaxy_recursive_verifier.cpp b/barretenberg/cpp/src/barretenberg/stdlib/honk_recursion/verifier/protogalaxy_recursive_verifier.cpp index 6653fd5f9d1..5c9910c05bb 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/honk_recursion/verifier/protogalaxy_recursive_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/honk_recursion/verifier/protogalaxy_recursive_verifier.cpp @@ -56,8 +56,6 @@ void ProtoGalaxyRecursiveVerifier_::receive_and_finalise_inst // Get challenge for sorted list batching and wire four memory records commitment auto [eta, eta_two, eta_three] = transcript->template get_challenges( domain_separator + "_eta", domain_separator + "_eta_two", domain_separator + "_eta_three"); - witness_commitments.sorted_accum = - transcript->template receive_from_prover(domain_separator + "_" + labels.sorted_accum); witness_commitments.lookup_read_counts = transcript->template receive_from_prover(domain_separator + "_" + labels.lookup_read_counts); witness_commitments.lookup_read_tags = @@ -81,8 +79,6 @@ void ProtoGalaxyRecursiveVerifier_::receive_and_finalise_inst witness_commitments.z_perm = transcript->template receive_from_prover(domain_separator + "_" + labels.z_perm); - witness_commitments.z_lookup = - transcript->template receive_from_prover(domain_separator + "_" + labels.z_lookup); // Compute correction terms for grand products const FF public_input_delta = diff --git a/barretenberg/cpp/src/barretenberg/stdlib/honk_recursion/verifier/ultra_recursive_verifier.cpp b/barretenberg/cpp/src/barretenberg/stdlib/honk_recursion/verifier/ultra_recursive_verifier.cpp index fa630c64fbb..952e38c7685 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/honk_recursion/verifier/ultra_recursive_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/honk_recursion/verifier/ultra_recursive_verifier.cpp @@ -96,7 +96,6 @@ std::array UltraRecursiveVerifier_::ve relation_parameters.eta_three = eta_three; // Get commitments to sorted list accumulator and fourth wire - commitments.sorted_accum = transcript->template receive_from_prover(commitment_labels.sorted_accum); commitments.lookup_read_counts = transcript->template receive_from_prover(commitment_labels.lookup_read_counts); commitments.lookup_read_tags = @@ -128,7 +127,6 @@ std::array UltraRecursiveVerifier_::ve // Get commitment to permutation and lookup grand products commitments.z_perm = transcript->template receive_from_prover(commitment_labels.z_perm); - commitments.z_lookup = transcript->template receive_from_prover(commitment_labels.z_lookup); // Execute Sumcheck Verifier and extract multivariate opening point u = (u_0, ..., u_{d-1}) and purported // multivariate evaluations at u diff --git a/barretenberg/cpp/src/barretenberg/stdlib/honk_recursion/verifier/verifier.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/honk_recursion/verifier/verifier.test.cpp index f8658a39fe3..605b44b702f 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/honk_recursion/verifier/verifier.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/honk_recursion/verifier/verifier.test.cpp @@ -227,7 +227,7 @@ template class RecursiveVerifierTest : public testing // Arbitrarily tamper with the proof to be verified inner_prover.transcript->deserialize_full_transcript(); - inner_prover.transcript->sorted_accum_comm = InnerCommitment::one() * InnerFF::random_element(); + inner_prover.transcript->z_perm_comm = InnerCommitment::one() * InnerFF::random_element(); inner_prover.transcript->serialize_full_transcript(); inner_proof = inner_prover.export_proof(); diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/grand_product_library.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/grand_product_library.test.cpp index 9ab7c789f67..0bf80a8db8c 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/grand_product_library.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/grand_product_library.test.cpp @@ -146,134 +146,6 @@ template class GrandProductTests : public testing::Test { // Check consistency between locally computed z_perm and the one computed by the prover library EXPECT_EQ(prover_polynomials.z_perm, z_permutation_expected); }; - - /** - * @brief Check consistency of the computation of the lookup grand product polynomial z_lookup. - * @details This test compares a simple, unoptimized, easily readable calculation of the grand product z_lookup - * to the optimized implementation used by the prover. It's purpose is to provide confidence that some optimization - * introduced into the calculation has not changed the result. - * @note This test does confirm the correctness of z_lookup, only that the two implementations yield an - * identical result. - */ - static void test_lookup_grand_product_construction() - { - using Flavor = UltraFlavor; - using ProverPolynomials = typename Flavor::ProverPolynomials; - - // Set a mock circuit size - static const size_t circuit_size = 8; - - // Construct a ProverPolynomials object with completely random polynomials - ProverPolynomials prover_polynomials; - for (auto& poly : prover_polynomials.get_unshifted()) { - poly = get_random_polynomial(circuit_size); - poly[0] = 0; // for shiftability - } - prover_polynomials.set_shifted(); - - // Get random challenges - auto beta = FF::random_element(); - auto gamma = FF::random_element(); - auto eta = FF::random_element(); - auto eta_two = FF::random_element(); - auto eta_three = FF::random_element(); - - RelationParameters params{ - .eta = eta, - .eta_two = eta_two, - .eta_three = eta_three, - .beta = beta, - .gamma = gamma, - .public_input_delta = 1, - .lookup_grand_product_delta = 1, - }; - - // Method 1: Compute z_lookup using the prover library method - constexpr size_t LOOKUP_RELATION_INDEX = 1; - using LHS = typename std::tuple_element::type; - using RHS = LookupRelation; - static_assert(std::same_as); - compute_grand_product(prover_polynomials, params); - - // Method 2: Compute the lookup grand product polynomial Z_lookup: - // - // ∏(1 + β) ⋅ ∏(q_lookup*f_k + γ) ⋅ ∏(t_k + βt_{k+1} + γ(1 + β)) - // Z_lookup(X_j) = ----------------------------------------------------------------- - // ∏(s_k + βs_{k+1} + γ(1 + β)) - // - // in a way that is simple to read (but inefficient). See prover library method for more details. - - std::array accumulators; - for (size_t i = 0; i < 4; ++i) { - accumulators[i] = Polynomial{ circuit_size }; - } - - // Step (1) - - auto wires = prover_polynomials.get_wires(); - auto tables = prover_polynomials.get_tables(); - auto sorted_batched = prover_polynomials.sorted_accum; - auto column_1_step_size = prover_polynomials.q_r; - auto column_2_step_size = prover_polynomials.q_m; - auto column_3_step_size = prover_polynomials.q_c; - auto lookup_index_selector = prover_polynomials.q_o; - auto lookup_selector = prover_polynomials.q_lookup; - - // Note: block_mask is used for efficient modulus, i.e. i % N := i & (N-1), for N = 2^k - const size_t block_mask = circuit_size - 1; - // Initialize 't(X)' to be used in an expression of the form t(X) + β*t(Xω) - FF table_i = tables[0][0] + tables[1][0] * eta + tables[2][0] * eta_two + tables[3][0] * eta_three; - for (size_t i = 0; i < circuit_size; ++i) { - size_t shift_idx = (i + 1) & block_mask; - - // f = (w_1 + q_2*w_1(Xω)) + η(w_2 + q_m*w_2(Xω)) + η²(w_3 + q_c*w_3(Xω)) + η³q_index. - FF f_i = (wires[0][i] + wires[0][shift_idx] * column_1_step_size[i]) + - (wires[1][i] + wires[1][shift_idx] * column_2_step_size[i]) * eta + - (wires[2][i] + wires[2][shift_idx] * column_3_step_size[i]) * eta_two + - eta_three * lookup_index_selector[i]; - - // q_lookup * f + γ - accumulators[0][i] = lookup_selector[i] * f_i + gamma; - - // t = t_1 + ηt_2 + η²t_3 + η³t_4 - FF table_i_plus_1 = tables[0][shift_idx] + eta * tables[1][shift_idx] + eta_two * tables[2][shift_idx] + - eta_three * tables[3][shift_idx]; - - // t + βt(Xω) + γ(1 + β) - accumulators[1][i] = table_i + table_i_plus_1 * beta + gamma * (FF::one() + beta); - - // (1 + β) - accumulators[2][i] = FF::one() + beta; - - // s + βs(Xω) + γ(1 + β) - accumulators[3][i] = sorted_batched[i] + beta * sorted_batched[shift_idx] + gamma * (FF::one() + beta); - - // Set t(X_i) for next iteration - table_i = table_i_plus_1; - } - - // Step (2) - for (auto& accum : accumulators) { - for (size_t i = 0; i < circuit_size - 1; ++i) { - accum[i + 1] *= accum[i]; - } - } - - // Step (3) - Polynomial z_lookup_expected(circuit_size); - z_lookup_expected[0] = FF::zero(); // Z_lookup_0 = 0 - - // Compute the numerator in accumulators[0]; The denominator is in accumulators[3] - for (size_t i = 0; i < circuit_size - 1; ++i) { - accumulators[0][i] *= accumulators[1][i] * accumulators[2][i]; - } - // Compute Z_lookup_i, i = [1, n-1] - for (size_t i = 0; i < circuit_size - 1; ++i) { - z_lookup_expected[i + 1] = accumulators[0][i] / accumulators[3][i]; - } - - EXPECT_EQ(prover_polynomials.z_lookup, z_lookup_expected); - }; }; using FieldTypes = testing::Types; @@ -283,8 +155,3 @@ TYPED_TEST(GrandProductTests, GrandProductPermutation) { TestFixture::template test_permutation_grand_product_construction(); } - -TYPED_TEST(GrandProductTests, GrandProductLookup) -{ - TestFixture::test_lookup_grand_product_construction(); -} diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp index 14df8d32a5d..0cbffeb559d 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp @@ -14,7 +14,6 @@ #include "barretenberg/relations/ecc_op_queue_relation.hpp" #include "barretenberg/relations/elliptic_relation.hpp" #include "barretenberg/relations/logderiv_lookup_relation.hpp" -#include "barretenberg/relations/lookup_relation.hpp" #include "barretenberg/relations/permutation_relation.hpp" #include "barretenberg/relations/poseidon2_external_relation.hpp" #include "barretenberg/relations/poseidon2_internal_relation.hpp" @@ -40,24 +39,22 @@ class MegaFlavor { static constexpr size_t NUM_WIRES = CircuitBuilder::NUM_WIRES; // The number of multivariate polynomials on which a sumcheck prover sumcheck operates (including shifts). We often // need containers of this size to hold related data, so we choose a name more agnostic than `NUM_POLYNOMIALS`. - // Note: this number does not include the individual sorted list polynomials. - static constexpr size_t NUM_ALL_ENTITIES = 61; + static constexpr size_t NUM_ALL_ENTITIES = 57; // The number of polynomials precomputed to describe a circuit and to aid a prover in constructing a satisfying // assignment of witnesses. We again choose a neutral name. static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 30; // The total number of witness entities not including shifts. - static constexpr size_t NUM_WITNESS_ENTITIES = 20; + static constexpr size_t NUM_WITNESS_ENTITIES = 18; // Total number of folded polynomials, which is just all polynomials except the shifts static constexpr size_t NUM_FOLDED_ENTITIES = NUM_PRECOMPUTED_ENTITIES + NUM_WITNESS_ENTITIES; - using GrandProductRelations = std::tuple, bb::LookupRelation>; + using GrandProductRelations = std::tuple>; // define the tuple of Relations that comprise the Sumcheck relation // Note: made generic for use in MegaRecursive. template using Relations_ = std::tuple, bb::UltraPermutationRelation, - bb::LookupRelation, bb::LogDerivLookupRelation, bb::DeltaRangeConstraintRelation, bb::EllipticRelation, @@ -181,9 +178,7 @@ class MegaFlavor { template class DerivedEntities { public: DEFINE_FLAVOR_MEMBERS(DataType, - sorted_accum, // column 4 z_perm, // column 5 - z_lookup, // column 6 lookup_inverses, // column 6 lookup_read_counts, // column 6 lookup_read_tags, // column 6 @@ -219,9 +214,7 @@ class MegaFlavor { this->w_r, this->w_o, this->w_4, - this->sorted_accum, this->z_perm, - this->z_lookup, this->lookup_inverses, this->lookup_read_counts, this->lookup_read_tags, @@ -240,18 +233,15 @@ class MegaFlavor { template class ShiftedEntities { public: DEFINE_FLAVOR_MEMBERS(DataType, - table_1_shift, // column 0 - table_2_shift, // column 1 - table_3_shift, // column 2 - table_4_shift, // column 3 - w_l_shift, // column 4 - w_r_shift, // column 5 - w_o_shift, // column 6 - w_4_shift, // column 7 - sorted_accum_shift, // column 8 - z_perm_shift, // column 9 - z_lookup_shift // column 10 - ) + table_1_shift, // column 0 + table_2_shift, // column 1 + table_3_shift, // column 2 + table_4_shift, // column 3 + w_l_shift, // column 4 + w_r_shift, // column 5 + w_o_shift, // column 6 + w_4_shift, // column 7 + z_perm_shift) }; public: @@ -289,8 +279,8 @@ class MegaFlavor { auto get_witness() { return WitnessEntities::get_all(); }; auto get_to_be_shifted() { - return RefArray{ this->table_1, this->table_2, this->table_3, this->table_4, this->w_l, this->w_r, - this->w_o, this->w_4, this->sorted_accum, this->z_perm, this->z_lookup }; + return RefArray{ this->table_1, this->table_2, this->table_3, this->table_4, this->w_l, + this->w_r, this->w_o, this->w_4, this->z_perm }; }; auto get_precomputed() { return PrecomputedEntities::get_all(); } auto get_shifted() { return ShiftedEntities::get_all(); }; @@ -359,44 +349,8 @@ class MegaFlavor { std::vector memory_read_records; std::vector memory_write_records; - std::array sorted_polynomials; ProverPolynomials polynomials; // storage for all polynomials evaluated by the prover - void compute_sorted_accumulator_polynomials(const FF& eta, const FF& eta_two, const FF& eta_three) - { - // Compute sorted witness-table accumulator - compute_sorted_list_accumulator(eta, eta_two, eta_three); - - // Finalize fourth wire polynomial by adding lookup memory records - add_plookup_memory_records_to_wire_4(eta, eta_two, eta_three); - } - - /** - * @brief Construct sorted list accumulator polynomial 's'. - * - * @details Compute s = s_1 + η*s_2 + η²*s_3 + η³*s_4 (via Horner) where s_i are the - * sorted concatenated witness/table polynomials - * - * @param key proving key - * @param sorted_list_polynomials sorted concatenated witness/table polynomials - * @param eta random challenge - * @return Polynomial - */ - void compute_sorted_list_accumulator(const FF& eta, const FF& eta_two, const FF& eta_three) - { - - auto& sorted_list_accumulator = polynomials.sorted_accum; - - // Construct s via Horner, i.e. s = s_1 + η(s_2 + η(s_3 + η*s_4)) - for (size_t i = 0; i < this->circuit_size; ++i) { - FF T0 = sorted_polynomials[3][i] * eta_three; - T0 += sorted_polynomials[2][i] * eta_two; - T0 += sorted_polynomials[1][i] * eta; - T0 += sorted_polynomials[0][i]; - sorted_list_accumulator[i] = T0; - } - } - /** * @brief Add plookup memory records to the fourth wire polynomial * @@ -452,7 +406,7 @@ class MegaFlavor { } /** - * @brief Computes public_input_delta, lookup_grand_product_delta, the z_perm and z_lookup polynomials + * @brief Computes public_input_delta, lookup_grand_product_delta, the z_perm polynomial * * @param relation_parameters */ @@ -689,11 +643,9 @@ class MegaFlavor { w_o = "W_O"; w_4 = "W_4"; z_perm = "Z_PERM"; - z_lookup = "Z_LOOKUP"; lookup_inverses = "LOOKUP_INVERSES"; lookup_read_counts = "LOOKUP_READ_COUNTS"; lookup_read_tags = "LOOKUP_READ_TAGS"; - sorted_accum = "SORTED_ACCUM"; ecc_op_wire_1 = "ECC_OP_WIRE_1"; ecc_op_wire_2 = "ECC_OP_WIRE_2"; ecc_op_wire_3 = "ECC_OP_WIRE_3"; @@ -783,9 +735,7 @@ class MegaFlavor { this->w_r = commitments.w_r; this->w_o = commitments.w_o; this->w_4 = commitments.w_4; - this->sorted_accum = commitments.sorted_accum; this->z_perm = commitments.z_perm; - this->z_lookup = commitments.z_lookup; this->lookup_inverses = commitments.lookup_inverses; this->lookup_read_counts = commitments.lookup_read_counts; this->lookup_read_tags = commitments.lookup_read_tags; @@ -829,10 +779,8 @@ class MegaFlavor { Commitment return_data_comm; Commitment return_data_read_counts_comm; Commitment return_data_inverses_comm; - Commitment sorted_accum_comm; Commitment w_4_comm; Commitment z_perm_comm; - Commitment z_lookup_comm; Commitment lookup_inverses_comm; Commitment lookup_read_counts_comm; Commitment lookup_read_tags_comm; @@ -888,13 +836,11 @@ class MegaFlavor { return_data_comm = deserialize_from_buffer(proof_data, num_frs_read); return_data_read_counts_comm = deserialize_from_buffer(proof_data, num_frs_read); return_data_inverses_comm = deserialize_from_buffer(proof_data, num_frs_read); - sorted_accum_comm = deserialize_from_buffer(proof_data, num_frs_read); lookup_read_counts_comm = deserialize_from_buffer(proof_data, num_frs_read); lookup_read_tags_comm = deserialize_from_buffer(proof_data, num_frs_read); w_4_comm = deserialize_from_buffer(proof_data, num_frs_read); lookup_inverses_comm = deserialize_from_buffer(proof_data, num_frs_read); z_perm_comm = deserialize_from_buffer(proof_data, num_frs_read); - z_lookup_comm = deserialize_from_buffer(proof_data, num_frs_read); for (size_t i = 0; i < log_n; ++i) { sumcheck_univariates.push_back( deserialize_from_buffer>(proof_data, @@ -932,13 +878,11 @@ class MegaFlavor { serialize_to_buffer(return_data_comm, proof_data); serialize_to_buffer(return_data_read_counts_comm, proof_data); serialize_to_buffer(return_data_inverses_comm, proof_data); - serialize_to_buffer(sorted_accum_comm, proof_data); serialize_to_buffer(lookup_read_counts_comm, proof_data); serialize_to_buffer(lookup_read_tags_comm, proof_data); serialize_to_buffer(w_4_comm, proof_data); serialize_to_buffer(lookup_inverses_comm, proof_data); serialize_to_buffer(z_perm_comm, proof_data); - serialize_to_buffer(z_lookup_comm, proof_data); for (size_t i = 0; i < log_n; ++i) { serialize_to_buffer(sumcheck_univariates[i], proof_data); } diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp index 1119a9a6036..6a71840fb92 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp @@ -13,7 +13,6 @@ #include "barretenberg/relations/delta_range_constraint_relation.hpp" #include "barretenberg/relations/elliptic_relation.hpp" #include "barretenberg/relations/logderiv_lookup_relation.hpp" -#include "barretenberg/relations/lookup_relation.hpp" #include "barretenberg/relations/permutation_relation.hpp" #include "barretenberg/relations/relation_parameters.hpp" #include "barretenberg/relations/ultra_arithmetic_relation.hpp" @@ -37,23 +36,21 @@ class UltraFlavor { static constexpr size_t NUM_WIRES = CircuitBuilder::NUM_WIRES; // The number of multivariate polynomials on which a sumcheck prover sumcheck operates (including shifts). We often // need containers of this size to hold related data, so we choose a name more agnostic than `NUM_POLYNOMIALS`. - // Note: this number does not include the individual sorted list polynomials. - static constexpr size_t NUM_ALL_ENTITIES = 46; + static constexpr size_t NUM_ALL_ENTITIES = 42; // The number of polynomials precomputed to describe a circuit and to aid a prover in constructing a satisfying // assignment of witnesses. We again choose a neutral name. static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 25; // The total number of witness entities not including shifts. - static constexpr size_t NUM_WITNESS_ENTITIES = 10; + static constexpr size_t NUM_WITNESS_ENTITIES = 8; // Total number of folded polynomials, which is just all polynomials except the shifts static constexpr size_t NUM_FOLDED_ENTITIES = NUM_PRECOMPUTED_ENTITIES + NUM_WITNESS_ENTITIES; - using GrandProductRelations = std::tuple, bb::LookupRelation>; + using GrandProductRelations = std::tuple>; // define the tuple of Relations that comprise the Sumcheck relation // Note: made generic for use in MegaRecursive. template using Relations_ = std::tuple, bb::UltraPermutationRelation, - bb::LookupRelation, bb::LogDerivLookupRelation, bb::DeltaRangeConstraintRelation, bb::EllipticRelation, @@ -152,17 +149,14 @@ class UltraFlavor { w_r, // column 1 w_o, // column 2 w_4, // column 3 - sorted_accum, // column 4 z_perm, // column 5 - z_lookup, // column 6 lookup_inverses, // column 6 lookup_read_counts, // column 6 lookup_read_tags) // column 6 auto get_wires() { return RefArray{ w_l, w_r, w_o, w_4 }; }; - MSGPACK_FIELDS( - w_l, w_r, w_o, w_4, sorted_accum, z_perm, z_lookup, lookup_inverses, lookup_read_counts, lookup_read_tags); + MSGPACK_FIELDS(w_l, w_r, w_o, w_4, z_perm, lookup_inverses, lookup_read_counts, lookup_read_tags); }; /** @@ -171,22 +165,20 @@ class UltraFlavor { template class ShiftedEntities { public: DEFINE_FLAVOR_MEMBERS(DataType, - table_1_shift, // column 0 - table_2_shift, // column 1 - table_3_shift, // column 2 - table_4_shift, // column 3 - w_l_shift, // column 4 - w_r_shift, // column 5 - w_o_shift, // column 6 - w_4_shift, // column 7 - sorted_accum_shift, // column 8 - z_perm_shift, // column 9 - z_lookup_shift) // column 10 + table_1_shift, // column 0 + table_2_shift, // column 1 + table_3_shift, // column 2 + table_4_shift, // column 3 + w_l_shift, // column 4 + w_r_shift, // column 5 + w_o_shift, // column 6 + w_4_shift, // column 7 + z_perm_shift) // column 10 auto get_shifted() { - return RefArray{ 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 }; + return RefArray{ table_1_shift, table_2_shift, table_3_shift, table_4_shift, w_l_shift, + w_r_shift, w_o_shift, w_4_shift, z_perm_shift }; }; }; @@ -222,8 +214,8 @@ class UltraFlavor { auto get_witness() { return WitnessEntities::get_all(); }; auto get_to_be_shifted() { - return RefArray{ this->table_1, this->table_2, this->table_3, this->table_4, this->w_l, this->w_r, - this->w_o, this->w_4, this->sorted_accum, this->z_perm, this->z_lookup }; + return RefArray{ this->table_1, this->table_2, this->table_3, this->table_4, this->w_l, + this->w_r, this->w_o, this->w_4, this->z_perm }; }; auto get_shifted() { return ShiftedEntities::get_all(); }; }; @@ -294,43 +286,8 @@ class UltraFlavor { std::vector memory_read_records; std::vector memory_write_records; - std::array sorted_polynomials; ProverPolynomials polynomials; // storage for all polynomials evaluated by the prover - void compute_sorted_accumulator_polynomials(const FF& eta, const FF& eta_two, const FF& eta_three) - { - // Compute sorted witness-table accumulator - compute_sorted_list_accumulator(eta, eta_two, eta_three); - - // Finalize fourth wire polynomial by adding lookup memory records - add_plookup_memory_records_to_wire_4(eta, eta_two, eta_three); - } - - /** - * @brief Construct sorted list accumulator polynomial 's'. - * - * @details Compute s = s_1 + η*s_2 + η²*s_3 + η³*s_4 (via Horner) where s_i are the - * sorted concatenated witness/table polynomials - * - * @param key proving key - * @param sorted_list_polynomials sorted concatenated witness/table polynomials - * @param eta random challenge - * @return Polynomial - */ - void compute_sorted_list_accumulator(const FF& eta, const FF& eta_two, const FF& eta_three) - { - auto& sorted_list_accumulator = polynomials.sorted_accum; - - // Construct s via Horner, i.e. s = s_1 + η(s_2 + η(s_3 + η*s_4)) - for (size_t i = 0; i < this->circuit_size; ++i) { - FF T0 = sorted_polynomials[3][i] * eta_three; - T0 += sorted_polynomials[2][i] * eta_two; - T0 += sorted_polynomials[1][i] * eta; - T0 += sorted_polynomials[0][i]; - sorted_list_accumulator[i] = T0; - } - } - /** * @brief Add plookup memory records to the fourth wire polynomial * @@ -378,8 +335,7 @@ class UltraFlavor { } /** - * @brief Computes public_input_delta, lookup_grand_product_delta, the z_perm and z_lookup - * polynomials + * @brief Computes public_input_delta, lookup_grand_product_delta, the z_perm polynomial * * @param relation_parameters */ @@ -600,9 +556,7 @@ class UltraFlavor { w_o = "W_O"; w_4 = "W_4"; z_perm = "Z_PERM"; - z_lookup = "Z_LOOKUP"; lookup_inverses = "LOOKUP_INVERSES"; - sorted_accum = "SORTED_ACCUM"; lookup_read_counts = "LOOKUP_READ_COUNTS"; lookup_read_tags = "LOOKUP_READ_TAGS"; @@ -676,13 +630,11 @@ class UltraFlavor { this->w_l = commitments.w_l; this->w_r = commitments.w_r; this->w_o = commitments.w_o; - this->sorted_accum = commitments.sorted_accum; this->lookup_inverses = commitments.lookup_inverses; this->lookup_read_counts = commitments.lookup_read_counts; this->lookup_read_tags = commitments.lookup_read_tags; this->w_4 = commitments.w_4; this->z_perm = commitments.z_perm; - this->z_lookup = commitments.z_lookup; } } }; @@ -703,12 +655,10 @@ class UltraFlavor { Commitment w_l_comm; Commitment w_r_comm; Commitment w_o_comm; - Commitment sorted_accum_comm; Commitment lookup_read_counts_comm; Commitment lookup_read_tags_comm; Commitment w_4_comm; Commitment z_perm_comm; - Commitment z_lookup_comm; Commitment lookup_inverses_comm; std::vector> sumcheck_univariates; std::array sumcheck_evaluations; @@ -759,13 +709,11 @@ class UltraFlavor { w_l_comm = deserialize_from_buffer(proof_data, num_frs_read); w_r_comm = deserialize_from_buffer(proof_data, num_frs_read); w_o_comm = deserialize_from_buffer(proof_data, num_frs_read); - sorted_accum_comm = deserialize_from_buffer(proof_data, num_frs_read); lookup_read_counts_comm = deserialize_from_buffer(proof_data, num_frs_read); lookup_read_tags_comm = deserialize_from_buffer(proof_data, num_frs_read); w_4_comm = deserialize_from_buffer(proof_data, num_frs_read); lookup_inverses_comm = deserialize_from_buffer(proof_data, num_frs_read); z_perm_comm = deserialize_from_buffer(proof_data, num_frs_read); - z_lookup_comm = deserialize_from_buffer(proof_data, num_frs_read); for (size_t i = 0; i < log_n; ++i) { sumcheck_univariates.push_back( deserialize_from_buffer>(proof_data, @@ -798,13 +746,11 @@ class UltraFlavor { serialize_to_buffer(w_l_comm, proof_data); serialize_to_buffer(w_r_comm, proof_data); serialize_to_buffer(w_o_comm, proof_data); - serialize_to_buffer(sorted_accum_comm, proof_data); serialize_to_buffer(lookup_read_counts_comm, proof_data); serialize_to_buffer(lookup_read_tags_comm, proof_data); serialize_to_buffer(w_4_comm, proof_data); serialize_to_buffer(lookup_inverses_comm, proof_data); serialize_to_buffer(z_perm_comm, proof_data); - serialize_to_buffer(z_lookup_comm, proof_data); for (size_t i = 0; i < log_n; ++i) { serialize_to_buffer(sumcheck_univariates[i], proof_data); } diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_recursive_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_recursive_flavor.hpp index 444fe8670d9..195097c2c7f 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_recursive_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_recursive_flavor.hpp @@ -11,7 +11,6 @@ #include "barretenberg/relations/auxiliary_relation.hpp" #include "barretenberg/relations/delta_range_constraint_relation.hpp" #include "barretenberg/relations/elliptic_relation.hpp" -#include "barretenberg/relations/lookup_relation.hpp" #include "barretenberg/relations/permutation_relation.hpp" #include "barretenberg/relations/ultra_arithmetic_relation.hpp" #include "barretenberg/srs/factories/crs_factory.hpp" @@ -238,13 +237,11 @@ template class UltraRecursiveFlavor_ { this->w_l = commitments.w_l; this->w_r = commitments.w_r; this->w_o = commitments.w_o; - this->sorted_accum = commitments.sorted_accum; this->lookup_inverses = commitments.lookup_inverses; this->lookup_read_counts = commitments.lookup_read_counts; this->lookup_read_tags = commitments.lookup_read_tags; this->w_4 = commitments.w_4; this->z_perm = commitments.z_perm; - this->z_lookup = commitments.z_lookup; } } }; diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp b/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp index e9ded4cecf1..d3a9d0bf8ee 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp @@ -86,8 +86,6 @@ template class ProverInstance_ { circuit, dyadic_circuit_size); - proving_key.sorted_polynomials = construct_sorted_list_polynomials(circuit, dyadic_circuit_size); - std::span public_wires_source = proving_key.polynomials.w_r; // Construct the public inputs array diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.test.cpp b/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.test.cpp index 4a8b5d36734..7b2c3738d76 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.test.cpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.test.cpp @@ -35,55 +35,4 @@ template class InstanceTests : public testing::Test { polynomial_view[idx] = polynomial[idx]; } }; - /** - * @brief Check consistency of the computation of the sorted list accumulator - * @details This test compares a simple, unoptimized, easily readable calculation of the sorted list accumulator - * to the optimized implementation used by the prover. It's purpose is to provide confidence that some optimization - * introduced into the calculation has not changed the result. - * @note This test does confirm the correctness of the sorted list accumulator, only that the two implementations - * yield an identical result. - */ - static void test_sorted_list_accumulator_construction() - { - srs::init_crs_factory("../srs_db/ignition"); - - // Construct a simple circuit of size n = 8 (i.e. the minimum circuit size) - Builder builder; - - auto a = 2; - builder.add_variable(a); - - builder.add_gates_to_ensure_all_polys_are_non_zero(); - builder.finalize_circuit(); - auto instance = ProverInstance_(builder); - - // Get random challenge eta - auto eta = FF::random_element(); - auto eta_two = FF::random_element(); - auto eta_three = FF::random_element(); - - auto sorted_list_polynomials = instance.proving_key.sorted_polynomials; - - // Method 1: computed sorted list accumulator polynomial using prover library method - instance.proving_key.compute_sorted_list_accumulator(eta, eta_two, eta_three); - auto sorted_list_accumulator = instance.proving_key.polynomials.sorted_accum; - - // Compute s = s_1 + η*s_2 + η²*s_3 + η³*s_4 - Polynomial sorted_list_accumulator_expected{ sorted_list_polynomials[0] }; - for (size_t i = 0; i < instance.proving_key.circuit_size; ++i) { - sorted_list_accumulator_expected[i] += sorted_list_polynomials[1][i] * eta + - sorted_list_polynomials[2][i] * eta_two + - sorted_list_polynomials[3][i] * eta_three; - } - - EXPECT_EQ(sorted_list_accumulator, sorted_list_accumulator_expected); - }; -}; - -using FlavorTypes = testing::Types; -TYPED_TEST_SUITE(InstanceTests, FlavorTypes); - -TYPED_TEST(InstanceTests, SortedListAccumulator) -{ - TestFixture::test_sorted_list_accumulator_construction(); -} +}; \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.test.cpp b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.test.cpp index 05c0938fa10..bfc9b0facac 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.test.cpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.test.cpp @@ -3,7 +3,6 @@ #include "barretenberg/relations/auxiliary_relation.hpp" #include "barretenberg/relations/delta_range_constraint_relation.hpp" #include "barretenberg/relations/elliptic_relation.hpp" -#include "barretenberg/relations/lookup_relation.hpp" #include "barretenberg/relations/permutation_relation.hpp" #include "barretenberg/relations/ultra_arithmetic_relation.hpp" #include "barretenberg/stdlib_circuit_builders/plookup_tables/fixed_base/fixed_base.hpp" diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/mega_transcript.test.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/mega_transcript.test.cpp index 308eb95fed0..8dfc816e01a 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/mega_transcript.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/mega_transcript.test.cpp @@ -65,7 +65,6 @@ class MegaTranscriptTests : public ::testing::Test { manifest_expected.add_challenge(round, "eta", "eta_two", "eta_three"); round++; - manifest_expected.add_entry(round, "SORTED_ACCUM", frs_per_G); manifest_expected.add_entry(round, "LOOKUP_READ_COUNTS", frs_per_G); manifest_expected.add_entry(round, "LOOKUP_READ_TAGS", frs_per_G); manifest_expected.add_entry(round, "W_4", frs_per_G); @@ -76,7 +75,6 @@ class MegaTranscriptTests : public ::testing::Test { manifest_expected.add_entry(round, "CALLDATA_INVERSES", frs_per_G); manifest_expected.add_entry(round, "RETURN_DATA_INVERSES", frs_per_G); manifest_expected.add_entry(round, "Z_PERM", frs_per_G); - manifest_expected.add_entry(round, "Z_LOOKUP", frs_per_G); for (size_t i = 0; i < NUM_SUBRELATIONS - 1; i++) { std::string label = "alpha_" + std::to_string(i); @@ -245,7 +243,7 @@ TEST_F(MegaTranscriptTests, StructureTest) Flavor::Commitment one_group_val = Flavor::Commitment::one(); FF rand_val = FF::random_element(); - prover.transcript->sorted_accum_comm = one_group_val * rand_val; // choose random object to modify + prover.transcript->z_perm_comm = one_group_val * rand_val; // choose random object to modify EXPECT_TRUE(verifier.verify_proof( prover.export_proof())); // we have not serialized it back to the proof so it should still be fine @@ -253,5 +251,5 @@ TEST_F(MegaTranscriptTests, StructureTest) EXPECT_FALSE(verifier.verify_proof(prover.export_proof())); // the proof is now wrong after serializing it prover.transcript->deserialize_full_transcript(); - EXPECT_EQ(static_cast(prover.transcript->sorted_accum_comm), one_group_val * rand_val); + EXPECT_EQ(static_cast(prover.transcript->z_perm_comm), one_group_val * rand_val); } diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp index 582bf4f92ee..e80f0c14a8f 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp @@ -117,16 +117,14 @@ template void OinkProver::execute_sorted_list_acc relation_parameters.eta_two = eta_two; relation_parameters.eta_three = eta_three; - proving_key.compute_sorted_accumulator_polynomials( + proving_key.add_plookup_memory_records_to_wire_4( relation_parameters.eta, relation_parameters.eta_two, relation_parameters.eta_three); // Commit to the sorted witness-table accumulator and the finalized (i.e. with memory records) fourth wire // polynomial - witness_commitments.sorted_accum = commitment_key->commit(proving_key.polynomials.sorted_accum); witness_commitments.lookup_read_counts = commitment_key->commit(proving_key.polynomials.lookup_read_counts); witness_commitments.lookup_read_tags = commitment_key->commit(proving_key.polynomials.lookup_read_tags); witness_commitments.w_4 = commitment_key->commit(proving_key.polynomials.w_4); - transcript->send_to_verifier(domain_separator + commitment_labels.sorted_accum, witness_commitments.sorted_accum); transcript->send_to_verifier(domain_separator + commitment_labels.lookup_read_counts, witness_commitments.lookup_read_counts); transcript->send_to_verifier(domain_separator + commitment_labels.lookup_read_tags, @@ -171,10 +169,8 @@ template void OinkProver::execute_grand_product_c proving_key.compute_grand_product_polynomials(relation_parameters); witness_commitments.z_perm = commitment_key->commit(proving_key.polynomials.z_perm); - witness_commitments.z_lookup = commitment_key->commit(proving_key.polynomials.z_lookup); transcript->send_to_verifier(domain_separator + commitment_labels.z_perm, witness_commitments.z_perm); - transcript->send_to_verifier(domain_separator + commitment_labels.z_lookup, witness_commitments.z_lookup); } template typename Flavor::RelationSeparator OinkProver::generate_alphas_round() diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/oink_verifier.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/oink_verifier.cpp index 4216dbad45f..22c888ad797 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/oink_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/oink_verifier.cpp @@ -94,8 +94,6 @@ template void OinkVerifier::execute_sorted_list_a relation_parameters.eta_two = eta_two; relation_parameters.eta_three = eta_three; // Get commitments to sorted list accumulator and fourth wire - witness_comms.sorted_accum = - transcript->template receive_from_prover(domain_separator + comm_labels.sorted_accum); witness_comms.lookup_read_counts = transcript->template receive_from_prover(domain_separator + comm_labels.lookup_read_counts); witness_comms.lookup_read_tags = @@ -145,8 +143,6 @@ template void OinkVerifier::execute_grand_product // Get commitment to permutation and lookup grand products witness_comms.z_perm = transcript->template receive_from_prover(domain_separator + comm_labels.z_perm); - witness_comms.z_lookup = - transcript->template receive_from_prover(domain_separator + comm_labels.z_lookup); } template typename Flavor::RelationSeparator OinkVerifier::generate_alphas_round() 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 707cf8736a4..3e50eeca4f4 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/relation_correctness.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/relation_correctness.test.cpp @@ -5,7 +5,6 @@ #include "barretenberg/relations/ecc_op_queue_relation.hpp" #include "barretenberg/relations/elliptic_relation.hpp" #include "barretenberg/relations/logderiv_lookup_relation.hpp" -#include "barretenberg/relations/lookup_relation.hpp" #include "barretenberg/relations/permutation_relation.hpp" #include "barretenberg/relations/relation_parameters.hpp" #include "barretenberg/relations/ultra_arithmetic_relation.hpp" @@ -273,9 +272,9 @@ TEST_F(UltraRelationCorrectnessTests, Ultra) instance->relation_parameters.beta = FF::random_element(); instance->relation_parameters.gamma = FF::random_element(); - instance->proving_key.compute_sorted_accumulator_polynomials(instance->relation_parameters.eta, - instance->relation_parameters.eta_two, - instance->relation_parameters.eta_three); + instance->proving_key.add_plookup_memory_records_to_wire_4(instance->relation_parameters.eta, + instance->relation_parameters.eta_two, + instance->relation_parameters.eta_three); instance->proving_key.compute_logderivative_inverses(instance->relation_parameters); instance->proving_key.compute_grand_product_polynomials(instance->relation_parameters); @@ -291,7 +290,6 @@ TEST_F(UltraRelationCorrectnessTests, Ultra) // Check that each relation is satisfied across each row of the prover polynomials check_relation>(circuit_size, prover_polynomials, params); check_relation>(circuit_size, prover_polynomials, params); - check_relation>(circuit_size, prover_polynomials, params); check_relation>(circuit_size, prover_polynomials, params); check_relation>(circuit_size, prover_polynomials, params); check_relation>(circuit_size, prover_polynomials, params); @@ -327,9 +325,9 @@ TEST_F(UltraRelationCorrectnessTests, Mega) instance->relation_parameters.beta = FF::random_element(); instance->relation_parameters.gamma = FF::random_element(); - instance->proving_key.compute_sorted_accumulator_polynomials(instance->relation_parameters.eta, - instance->relation_parameters.eta_two, - instance->relation_parameters.eta_three); + instance->proving_key.add_plookup_memory_records_to_wire_4(instance->relation_parameters.eta, + instance->relation_parameters.eta_two, + instance->relation_parameters.eta_three); instance->proving_key.compute_logderivative_inverses(instance->relation_parameters); instance->proving_key.compute_grand_product_polynomials(instance->relation_parameters); @@ -356,7 +354,6 @@ TEST_F(UltraRelationCorrectnessTests, Mega) // Check that each relation is satisfied across each row of the prover polynomials check_relation>(circuit_size, prover_polynomials, params); check_relation>(circuit_size, prover_polynomials, params); - check_relation>(circuit_size, prover_polynomials, params); check_relation>(circuit_size, prover_polynomials, params); check_relation>(circuit_size, prover_polynomials, params); check_relation>(circuit_size, prover_polynomials, params); diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/sumcheck.test.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/sumcheck.test.cpp index 5962b8ba212..99fe24309f1 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/sumcheck.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/sumcheck.test.cpp @@ -5,7 +5,6 @@ #include "barretenberg/relations/auxiliary_relation.hpp" #include "barretenberg/relations/delta_range_constraint_relation.hpp" #include "barretenberg/relations/elliptic_relation.hpp" -#include "barretenberg/relations/lookup_relation.hpp" #include "barretenberg/relations/permutation_relation.hpp" #include "barretenberg/relations/ultra_arithmetic_relation.hpp" #include "barretenberg/stdlib_circuit_builders/plookup_tables/fixed_base/fixed_base.hpp" @@ -157,9 +156,9 @@ TEST_F(SumcheckTestsRealCircuit, Ultra) instance->relation_parameters.beta = FF::random_element(); instance->relation_parameters.gamma = FF::random_element(); - instance->proving_key.compute_sorted_accumulator_polynomials(instance->relation_parameters.eta, - instance->relation_parameters.eta_two, - instance->relation_parameters.eta_three); + instance->proving_key.add_plookup_memory_records_to_wire_4(instance->relation_parameters.eta, + instance->relation_parameters.eta_two, + instance->relation_parameters.eta_three); instance->proving_key.compute_grand_product_polynomials(instance->relation_parameters); auto prover_transcript = Transcript::prover_init_empty(); diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_transcript.test.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_transcript.test.cpp index 560211d6416..df541aeb2df 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_transcript.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_transcript.test.cpp @@ -58,7 +58,6 @@ class UltraTranscriptTests : public ::testing::Test { manifest_expected.add_challenge(round, "eta", "eta_two", "eta_three"); round++; - manifest_expected.add_entry(round, "SORTED_ACCUM", frs_per_G); manifest_expected.add_entry(round, "LOOKUP_READ_COUNTS", frs_per_G); manifest_expected.add_entry(round, "LOOKUP_READ_TAGS", frs_per_G); manifest_expected.add_entry(round, "W_4", frs_per_G); @@ -67,7 +66,6 @@ class UltraTranscriptTests : public ::testing::Test { round++; manifest_expected.add_entry(round, "LOOKUP_INVERSES", frs_per_G); manifest_expected.add_entry(round, "Z_PERM", frs_per_G); - manifest_expected.add_entry(round, "Z_LOOKUP", frs_per_G); for (size_t i = 0; i < NUM_SUBRELATIONS - 1; i++) { std::string label = "alpha_" + std::to_string(i); @@ -229,7 +227,7 @@ TEST_F(UltraTranscriptTests, StructureTest) Flavor::Commitment one_group_val = Flavor::Commitment::one(); FF rand_val = FF::random_element(); - prover.transcript->sorted_accum_comm = one_group_val * rand_val; // choose random object to modify + prover.transcript->z_perm_comm = one_group_val * rand_val; // choose random object to modify EXPECT_TRUE(verifier.verify_proof( prover.export_proof())); // we have not serialized it back to the proof so it should still be fine @@ -237,5 +235,5 @@ TEST_F(UltraTranscriptTests, StructureTest) EXPECT_FALSE(verifier.verify_proof(prover.export_proof())); // the proof is now wrong after serializing it prover.transcript->deserialize_full_transcript(); - EXPECT_EQ(static_cast(prover.transcript->sorted_accum_comm), one_group_val * rand_val); + EXPECT_EQ(static_cast(prover.transcript->z_perm_comm), one_group_val * rand_val); } diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/avm_prover.cpp b/barretenberg/cpp/src/barretenberg/vm/generated/avm_prover.cpp index 57ee78efa8c..a4cfcae9eb5 100644 --- a/barretenberg/cpp/src/barretenberg/vm/generated/avm_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/generated/avm_prover.cpp @@ -7,7 +7,6 @@ #include "barretenberg/honk/proof_system/permutation_library.hpp" #include "barretenberg/plonk_honk_shared/library/grand_product_library.hpp" #include "barretenberg/polynomials/polynomial.hpp" -#include "barretenberg/relations/lookup_relation.hpp" #include "barretenberg/relations/permutation_relation.hpp" #include "barretenberg/sumcheck/sumcheck.hpp" From 7f93c261bb70eeb9b011580d98b594288841462b Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Wed, 19 Jun 2024 19:38:00 +0000 Subject: [PATCH 27/42] use etas instead of betas, add subrel additional offsets --- .../relations/databus_lookup_relation.hpp | 16 +++---- .../relations/logderiv_lookup_relation.hpp | 46 +++++++++++-------- 2 files changed, 35 insertions(+), 27 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/relations/databus_lookup_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/databus_lookup_relation.hpp index 3c897ce3909..c0ec529cdd7 100644 --- a/barretenberg/cpp/src/barretenberg/relations/databus_lookup_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/databus_lookup_relation.hpp @@ -243,24 +243,24 @@ template class DatabusLookupRelationImpl { const auto inverses = View(BusData::inverses(in)); // Degree 1 const auto read_counts = View(BusData::read_counts(in)); // Degree 1 - const auto read_term = compute_read_term(in, params); // Degree 1 - const auto write_term = compute_write_term(in, params); // Degree 1 - const auto inverse_exists = compute_inverse_exists(in); // Degree 1 + const auto read_term = compute_read_term(in, params); // Degree 1 (2) + const auto write_term = compute_write_term(in, params); // Degree 1 (2) + const auto inverse_exists = compute_inverse_exists(in); // Degree 2 const auto read_selector = get_read_selector(in); // Degree 2 - const auto write_inverse = inverses * read_term; // Degree 2 - const auto read_inverse = inverses * write_term; // Degree 2 + const auto write_inverse = inverses * read_term; // Degree 2 (3) + const auto read_inverse = inverses * write_term; // Degree 2 (3) // Determine which pair of subrelations to update based on which bus column is being read constexpr size_t subrel_idx_1 = 2 * bus_idx; constexpr size_t subrel_idx_2 = 2 * bus_idx + 1; // Establish the correctness of the polynomial of inverses I. Note: inverses is computed so that the value is 0 - // if !inverse_exists. Degree 3 + // if !inverse_exists. Degree 3 (5) std::get(accumulator) += (read_term * write_term * inverses - inverse_exists) * scaling_factor; // Establish validity of the read. Note: no scaling factor here since this constraint is enforced across the - // entire trace, not on a per-row basis - std::get(accumulator) += read_selector * read_inverse - read_counts * write_inverse; // Degree 4 + // entire trace, not on a per-row basis. + std::get(accumulator) += read_selector * read_inverse - read_counts * write_inverse; // Deg 4 (5) } /** diff --git a/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp index b7e4870006a..66019999fa7 100644 --- a/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp @@ -16,13 +16,19 @@ template class LogDerivLookupRelationImpl { static constexpr size_t READ_TERMS = 1; static constexpr size_t WRITE_TERMS = 1; // 1 + polynomial degree of this relation - static constexpr size_t LENGTH = READ_TERMS + WRITE_TERMS + 3; // 5 + static constexpr size_t LENGTH = 5; // both subrelations are degree 4 static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ LENGTH, // inverse construction sub-relation LENGTH // log derivative lookup argument sub-relation }; + // WORKTODO: shouldnt first one be 2? code doesnt compile that way + static constexpr std::array TOTAL_LENGTH_ADJUSTMENTS{ + 1, // inverse construction sub-relation + 1 // log derivative lookup argument sub-relation + }; + static constexpr std::array SUBRELATION_LINEARLY_INDEPENDENT = { true, false }; template static bool operation_exists_at_row(const AllValues& row) @@ -82,16 +88,16 @@ template class LogDerivLookupRelationImpl { static_assert(write_index < WRITE_TERMS); const auto& gamma = ParameterView(params.gamma); - const auto& beta = ParameterView(params.beta); - const auto& beta_sqr = ParameterView(params.beta_sqr); - const auto& beta_cube = ParameterView(params.beta_cube); + const auto& eta = ParameterView(params.eta); + const auto& eta_two = ParameterView(params.eta_two); + const auto& eta_three = ParameterView(params.eta_three); auto table_1 = View(in.table_1); auto table_2 = View(in.table_2); auto table_3 = View(in.table_3); auto table_4 = View(in.table_4); - return table_1 + gamma + table_2 * beta + table_3 * beta_sqr + table_4 * beta_cube; + return table_1 + gamma + table_2 * eta + table_3 * eta_two + table_4 * eta_three; } template @@ -101,9 +107,9 @@ template class LogDerivLookupRelationImpl { using ParameterView = GetParameterView; const auto& gamma = ParameterView(params.gamma); - const auto& beta = ParameterView(params.beta); - const auto& beta_sqr = ParameterView(params.beta_sqr); - const auto& beta_cube = ParameterView(params.beta_cube); + const auto& eta = ParameterView(params.eta); + const auto& eta_two = ParameterView(params.eta_two); + const auto& eta_three = ParameterView(params.eta_three); auto w_1 = View(in.w_l); auto w_2 = View(in.w_r); @@ -126,8 +132,8 @@ template class LogDerivLookupRelationImpl { // (w_1 + q_2*w_1_shift) + η(w_2 + q_m*w_2_shift) + η₂(w_3 + q_c*w_3_shift) + η₃q_index. // deg 2 or 3 - return derived_table_entry_1 + derived_table_entry_2 * beta + derived_table_entry_3 * beta_sqr + - table_index * beta_cube; + return derived_table_entry_1 + derived_table_entry_2 * eta + derived_table_entry_3 * eta_two + + table_index * eta_three; } /** @@ -150,19 +156,21 @@ template class LogDerivLookupRelationImpl { const auto inverses = View(in.lookup_inverses); // Degree 1 const auto read_counts = View(in.lookup_read_counts); // Degree 1 const auto read_selector = View(in.q_lookup); // Degree 1 - const auto inverse_exists = compute_inverse_exists(in); // Degree 1 - const auto read_term = compute_read_term(in, params); // Degree 1 - const auto write_term = compute_write_term(in, params); // Degree 1 - const auto write_inverse = inverses * read_term; // Degree 2 - const auto read_inverse = inverses * write_term; // Degree 2 + const auto inverse_exists = compute_inverse_exists(in); // Degree 2 + const auto read_term = compute_read_term(in, params); // Degree 2 (3) + const auto write_term = compute_write_term(in, params); // Degree 1 (2) + const auto write_inverse = inverses * read_term; // Degree 3 (4) + const auto read_inverse = inverses * write_term; // Degree 2 (3) // Establish the correctness of the polynomial of inverses I. Note: inverses is computed so that the value is 0 - // if !inverse_exists. Degree 3 - std::get<0>(accumulator) += (read_term * write_term * inverses - inverse_exists) * scaling_factor; + // if !inverse_exists. + // Degrees: 2 (3) 1 (2) 1 + std::get<0>(accumulator) += (read_term * write_term * inverses - inverse_exists) * scaling_factor; // Deg 4 (6) // Establish validity of the read. Note: no scaling factor here since this constraint is enforced across the - // entire trace, not on a per-row basis - std::get<1>(accumulator) += read_selector * read_inverse - read_counts * write_inverse; // Degree 4 + // entire trace, not on a per-row basis. Degree + // Degrees: 1 2 (3) 1 3 (4) + std::get<1>(accumulator) += read_selector * read_inverse - read_counts * write_inverse; // Deg 4 (5) // ****************** // accumulate_logderivative_lookup_subrelation_contributions>( From 019c268f897783be6df04bc9b4b865a02a636ac9 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Wed, 19 Jun 2024 22:18:24 +0000 Subject: [PATCH 28/42] fix sumcheck test --- barretenberg/cpp/src/barretenberg/ultra_honk/sumcheck.test.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/sumcheck.test.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/sumcheck.test.cpp index 99fe24309f1..6c0b24af539 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/sumcheck.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/sumcheck.test.cpp @@ -159,6 +159,7 @@ TEST_F(SumcheckTestsRealCircuit, Ultra) instance->proving_key.add_plookup_memory_records_to_wire_4(instance->relation_parameters.eta, instance->relation_parameters.eta_two, instance->relation_parameters.eta_three); + instance->proving_key.compute_logderivative_inverses(instance->relation_parameters); instance->proving_key.compute_grand_product_polynomials(instance->relation_parameters); auto prover_transcript = Transcript::prover_init_empty(); From a37fa4f095117c815841afa3022b94a6ba432feb Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Wed, 19 Jun 2024 22:28:24 +0000 Subject: [PATCH 29/42] move sorted poly method to plonk only lib --- .../relations_bench/relations.bench.cpp | 3 + .../plonk/composer/composer_lib.hpp | 75 +++++++++++++++++++ .../composer/composer_lib.hpp | 75 ------------------- 3 files changed, 78 insertions(+), 75 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp index 00ec04a5521..f735d2cfb19 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp @@ -65,6 +65,7 @@ BENCHMARK(execute_relation_for_pg_univariates>); BENCHMARK(execute_relation_for_pg_univariates>); BENCHMARK(execute_relation_for_pg_univariates>); +BENCHMARK(execute_relation_for_pg_univariates>); BENCHMARK(execute_relation_for_pg_univariates>); // Goblin-Ultra only relations (PG prover combiner work) @@ -78,6 +79,7 @@ BENCHMARK(execute_relation_for_univariates>); BENCHMARK(execute_relation_for_univariates>); BENCHMARK(execute_relation_for_univariates>); +BENCHMARK(execute_relation_for_univariates>); BENCHMARK(execute_relation_for_univariates>); // Goblin-Ultra only relations (Sumcheck prover work) @@ -91,6 +93,7 @@ BENCHMARK(execute_relation_for_values>) BENCHMARK(execute_relation_for_values>); BENCHMARK(execute_relation_for_values>); BENCHMARK(execute_relation_for_values>); +BENCHMARK(execute_relation_for_values>); BENCHMARK(execute_relation_for_values>); // Goblin-Ultra only relations (verifier work) diff --git a/barretenberg/cpp/src/barretenberg/plonk/composer/composer_lib.hpp b/barretenberg/cpp/src/barretenberg/plonk/composer/composer_lib.hpp index 0ca1c00e747..ee319334d73 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/composer/composer_lib.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk/composer/composer_lib.hpp @@ -48,4 +48,79 @@ std::shared_ptr compute_verification_key_common( // silencing for now but need to figure out where to extract type of VerifierCrs from :-/ std::shared_ptr> const& vrs); +/** + * @brief Construct polynomials containing the sorted concatenation of the lookups and the lookup tables + * + * @tparam Flavor + * @param circuit + * @param dyadic_circuit_size + * @param additional_offset Additional space needed in polynomials to add randomness for zk (Plonk only) + * @return std::array + */ +template +std::array construct_sorted_list_polynomials(typename Flavor::CircuitBuilder& circuit, + const size_t dyadic_circuit_size, + size_t additional_offset = 0) +{ + using Polynomial = typename Flavor::Polynomial; + std::array sorted_polynomials; + // Initialise the sorted concatenated list polynomials for the lookup argument + for (auto& s_i : sorted_polynomials) { + s_i = Polynomial(dyadic_circuit_size); + } + + // The sorted list polynomials have (tables_size + lookups_size) populated entries. We define the index below so + // that these entries are written into the last indices of the polynomials. The values on the first + // dyadic_circuit_size - (tables_size + lookups_size) indices are automatically initialized to zero via the + // polynomial constructor. + size_t s_index = dyadic_circuit_size - (circuit.get_tables_size() + circuit.get_lookups_size()) - additional_offset; + ASSERT(s_index > 0); // We need at least 1 row of zeroes for the permutation argument + + for (auto& table : circuit.lookup_tables) { + const fr table_index(table.table_index); + auto& lookup_gates = table.lookup_gates; + for (size_t i = 0; i < table.size(); ++i) { + if (table.use_twin_keys) { + lookup_gates.push_back({ + { + table.column_1[i].from_montgomery_form().data[0], + table.column_2[i].from_montgomery_form().data[0], + }, + { + table.column_3[i], + 0, + }, + }); + } else { + lookup_gates.push_back({ + { + table.column_1[i].from_montgomery_form().data[0], + 0, + }, + { + table.column_2[i], + table.column_3[i], + }, + }); + } + } + +#ifdef NO_TBB + std::sort(lookup_gates.begin(), lookup_gates.end()); +#else + std::sort(std::execution::par_unseq, lookup_gates.begin(), lookup_gates.end()); +#endif + + for (const auto& entry : lookup_gates) { + const auto components = entry.to_sorted_list_components(table.use_twin_keys); + sorted_polynomials[0][s_index] = components[0]; + sorted_polynomials[1][s_index] = components[1]; + sorted_polynomials[2][s_index] = components[2]; + sorted_polynomials[3][s_index] = table_index; + ++s_index; + } + } + return sorted_polynomials; +} + } // namespace bb::plonk diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp index 5fb9814ddaa..3e439c1d8a6 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp @@ -38,81 +38,6 @@ void construct_lookup_table_polynomials(RefArray } } -/** - * @brief Construct polynomials containing the sorted concatenation of the lookups and the lookup tables - * - * @tparam Flavor - * @param circuit - * @param dyadic_circuit_size - * @param additional_offset Additional space needed in polynomials to add randomness for zk (Plonk only) - * @return std::array - */ -template -std::array construct_sorted_list_polynomials(typename Flavor::CircuitBuilder& circuit, - const size_t dyadic_circuit_size, - size_t additional_offset = 0) -{ - using Polynomial = typename Flavor::Polynomial; - std::array sorted_polynomials; - // Initialise the sorted concatenated list polynomials for the lookup argument - for (auto& s_i : sorted_polynomials) { - s_i = Polynomial(dyadic_circuit_size); - } - - // The sorted list polynomials have (tables_size + lookups_size) populated entries. We define the index below so - // that these entries are written into the last indices of the polynomials. The values on the first - // dyadic_circuit_size - (tables_size + lookups_size) indices are automatically initialized to zero via the - // polynomial constructor. - size_t s_index = dyadic_circuit_size - (circuit.get_tables_size() + circuit.get_lookups_size()) - additional_offset; - ASSERT(s_index > 0); // We need at least 1 row of zeroes for the permutation argument - - for (auto& table : circuit.lookup_tables) { - const fr table_index(table.table_index); - auto& lookup_gates = table.lookup_gates; - for (size_t i = 0; i < table.size(); ++i) { - if (table.use_twin_keys) { - lookup_gates.push_back({ - { - table.column_1[i].from_montgomery_form().data[0], - table.column_2[i].from_montgomery_form().data[0], - }, - { - table.column_3[i], - 0, - }, - }); - } else { - lookup_gates.push_back({ - { - table.column_1[i].from_montgomery_form().data[0], - 0, - }, - { - table.column_2[i], - table.column_3[i], - }, - }); - } - } - -#ifdef NO_TBB - std::sort(lookup_gates.begin(), lookup_gates.end()); -#else - std::sort(std::execution::par_unseq, lookup_gates.begin(), lookup_gates.end()); -#endif - - for (const auto& entry : lookup_gates) { - const auto components = entry.to_sorted_list_components(table.use_twin_keys); - sorted_polynomials[0][s_index] = components[0]; - sorted_polynomials[1][s_index] = components[1]; - sorted_polynomials[2][s_index] = components[2]; - sorted_polynomials[3][s_index] = table_index; - ++s_index; - } - } - return sorted_polynomials; -} - /** * @brief WORKTODO * From 32ecdd38406c31589168fcb62f8cc11d1eb99f3d Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Thu, 20 Jun 2024 15:41:41 +0000 Subject: [PATCH 30/42] add skip condition --- .../src/barretenberg/relations/logderiv_lookup_relation.hpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp index 66019999fa7..1302e9bf6a7 100644 --- a/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp @@ -31,6 +31,12 @@ template class LogDerivLookupRelationImpl { static constexpr std::array SUBRELATION_LINEARLY_INDEPENDENT = { true, false }; + template inline static bool skip(const AllEntities& in) + { + // Ensure the input does not contain a lookup gate or data that is being read + return in.q_lookup.is_zero() && in.lookup_read_counts.is_zero(); + } + template static bool operation_exists_at_row(const AllValues& row) { return (row.q_lookup == 1) || (row.lookup_read_tags == 1); From 1f3fc15045b93133c38c1de932f7eb36dd2079de Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Thu, 20 Jun 2024 16:27:54 +0000 Subject: [PATCH 31/42] update honk proof data for acir recursion --- barretenberg/acir_tests/gen_inner_proof_inputs_ultra_honk.sh | 2 +- .../execution_success/verify_honk_proof/Prover.toml | 2 +- .../execution_success/verify_honk_proof/src/main.nr | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/barretenberg/acir_tests/gen_inner_proof_inputs_ultra_honk.sh b/barretenberg/acir_tests/gen_inner_proof_inputs_ultra_honk.sh index a013a7129b3..30548202ad3 100755 --- a/barretenberg/acir_tests/gen_inner_proof_inputs_ultra_honk.sh +++ b/barretenberg/acir_tests/gen_inner_proof_inputs_ultra_honk.sh @@ -3,7 +3,7 @@ # BIN: to specify a different binary to test with (e.g. bb.js or bb.js-dev). set -eu -BIN=${BIN:-../cpp/build-debug/bin/bb} +BIN=${BIN:-../cpp/build/bin/bb} CRS_PATH=~/.bb-crs BRANCH=master VERBOSE=${VERBOSE:-} diff --git a/noir/noir-repo/test_programs/execution_success/verify_honk_proof/Prover.toml b/noir/noir-repo/test_programs/execution_success/verify_honk_proof/Prover.toml index 1ebc77c5a5f..4619fd298dd 100644 --- a/noir/noir-repo/test_programs/execution_success/verify_honk_proof/Prover.toml +++ b/noir/noir-repo/test_programs/execution_success/verify_honk_proof/Prover.toml @@ -1,4 +1,4 @@ key_hash = "0x096129b1c6e108252fc5c829c4cc9b7e8f0d1fd9f29c2532b563d6396645e08f" -proof = ["0x0000000000000000000000000000000000000000000000000000000000000020","0x0000000000000000000000000000000000000000000000000000000000000011","0x0000000000000000000000000000000000000000000000000000000000000001","0x0000000000000000000000000000000000000000000000042ab5d6d1986846cf","0x00000000000000000000000000000000000000000000000b75c020998797da78","0x0000000000000000000000000000000000000000000000005a107acb64952eca","0x000000000000000000000000000000000000000000000000000031e97a575e9d","0x00000000000000000000000000000000000000000000000b5666547acf8bd5a4","0x00000000000000000000000000000000000000000000000c410db10a01750aeb","0x00000000000000000000000000000000000000000000000d722669117f9758a4","0x000000000000000000000000000000000000000000000000000178cbf4206471","0x000000000000000000000000000000000000000000000000e91b8a11e7842c38","0x000000000000000000000000000000000000000000000007fd51009034b3357f","0x000000000000000000000000000000000000000000000009889939f81e9c7402","0x0000000000000000000000000000000000000000000000000000f94656a2ca48","0x000000000000000000000000000000000000000000000006fb128b46c1ddb67f","0x0000000000000000000000000000000000000000000000093fe27776f50224bd","0x000000000000000000000000000000000000000000000004a0c80c0da527a081","0x0000000000000000000000000000000000000000000000000001b52c2020d746","0x0000000000000000000000000000005a9bae947e1e91af9e4033d8d6aa6ed632","0x000000000000000000000000000000000025e485e013446d4ac7981c88ba6ecc","0x000000000000000000000000000000ff1e0496e30ab24a63b32b2d1120b76e62","0x00000000000000000000000000000000001afe0a8a685d7cd85d1010e55d9d7c","0x000000000000000000000000000000b0804efd6573805f991458295f510a2004","0x00000000000000000000000000000000000c81a178016e2fe18605022d5a8b0e","0x000000000000000000000000000000eba51e76eb1cfff60a53a0092a3c3dea47","0x000000000000000000000000000000000022e7466247b533282f5936ac4e6c15","0x00000000000000000000000000000071b1d76edf770edff98f00ff4deec264cd","0x00000000000000000000000000000000001e48128e68794d8861fcbb2986a383","0x000000000000000000000000000000d3a2af4915ae6d86b097adc377fafda2d4","0x000000000000000000000000000000000006359de9ca452dab3a4f1f8d9c9d98","0x00000000000000000000000000000044d7ca77b464f03aa44f6f8d49a0d3ada5","0x00000000000000000000000000000000002a36959f550517d82d0af666bcd7dc","0x0000000000000000000000000000000566b28c19f0b1732b95e0381bc5d6dbdd","0x00000000000000000000000000000000002511360b7a8c6a823559f0ac9eb02b","0x000000000000000000000000000000f968b227a358a305607f3efc933823d288","0x00000000000000000000000000000000000eaf8adb390375a76d95e918b65e08","0x000000000000000000000000000000bb34b4b447aae56f5e24f81c3acd6d547f","0x00000000000000000000000000000000002175d012746260ebcfe339a91a81e1","0x00000000000000000000000000000058035b1ed115023f42bf4ee93d2dc29dcb","0x00000000000000000000000000000000002de4b004225be4e68938b0db546287","0x0000000000000000000000000000003d18d72585ef033ab3663d1944abb2054a","0x0000000000000000000000000000000000149a1974c0c2b5f0639970cda1af83","0x000000000000000000000000000000bb1eb2b1fc10b55295ed6c1ae54e8a40da","0x000000000000000000000000000000000026da80059472ac8c64e437d6fe6134","0x000000000000000000000000000000d1f101b72ee710423ca44548910676a4fe","0x00000000000000000000000000000000000323378ad6b5aec67af99e522095a0","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x2622384e4b4688a3ad115007c1c09de1a141aeca06c31925898cf746038a5897","0x2f743e893a3880004db1ff3492279d89c025b9815f16e129d15f7a3687b6f833","0x03e05487307f18e3afb90cc524e56809e478039d317a3757433bfc8e06a32b73","0x099ba7011747dd2d8b5ac03ed02b93c9803d51899677409931d5b1571c3041b5","0x189ef108e334c5173619eac1067b99526a5cc6e47cbffaa3c117f0c3eb8bebd4","0x0b5f77b69ac2955ecc44a73e18b2ea8403224cf769657d53acc9a5d302d0b86e","0x1b81353a160e985e8a1fb09d3a3827fe68d03585757530dcec1b8038ac829a21","0x175e75cef1b974011de38e6e631f42bffd4dcb6fad6680930388cffaa60d940e","0x1631945a2aa39032cfa8cf379d18a983d4b5a487adab67252c6514b35bc88095","0x181b639e465a6f9842c5d75f6f5b855a065f498595146df3bd2b9c0ef66042a1","0x0c6e5af7add3e12f610c13d8066896d08882a7c50cfe33676fda8a75e250e9b9","0x28f94cd060c45a2e6b423831302deb456d0964879db5008a2be0957a2c749e2a","0x1c81fb20cea508580aa962e5b4736a43382816e7abac7e478e6c080cf896798d","0x23dea53784aa14dcf7e1cce5ee480796e67b2dd69a8e20c5c09558001640edfa","0x149c2548f8b0d96fefecab53e31aa3902341c903fa0ef863ef64610315de993b","0x16ad81b3129ccebe1682d14b726bc9b86acd0f0be8c304594ce5a87e756add27","0x2c1ef938516edccc0cd1d4d812644d72b6ead3c85e1c8500fc54e77e5652b23f","0x0eecb7fba3395b21197cb24bb9b733b1985d81f35a1ee944714ffd781a7bd136","0x06e2a96ecf1e8419198eca10133954f3560102467f40a234cf071d23c6cf411a","0x1e6bfa2adcbdc50313408ef28a77b76dd915fa372c093c4484ba662695a3eadc","0x28ccaf4d4759c1f4bb49429b961a59cdefbc445017ffa807e90c54b27e1ee657","0x22803d537311e757a146ae7a2fc396d42d67f27e73efca82e3e324dc493da4de","0x196255f687cede05f326204bfaead7a54f8d48b67ce8522cb8af6a7fffaffcb6","0x147ea42988386b944f006be242ccc6b099fadd7f450955d252768667bbaee4f9","0x1f9ccb05e508b1d08c79c11acbc0677fdc18d5d40827e2e1eaae60fee51b940f","0x28ea76870d22eea72821da25f9b7a89341347afcd6c077387986a82dc8afa833","0x0e6ef82d3e5a318a9c6233dffbb00d130599f4ac979a89b034ce9d930b11165a","0x2e97fa9299a218c982504199ada3278270b9cb566bf46fe1ecc1d151e06b8745","0x1a41ac9b1032ac24c11720407c253a866e9c75a4ec233f15f968b206ea1e5d0e","0x0b31b541bb044c1bc2428c2a57ba29438f620050d1628389ff1fa90c494d7c58","0x050fec8d69f182768a9b34eca8c3f4695dad8bc20a10904090cfe18777d44d25","0x069283ac40daaafff76c3679f54a0aa773c8d71152fbb9c3219906113fc4f683","0x25c3ec4e8b90214aafe3b5416abf11a98bd34b8acb449df8424f159ddf858bc1","0x1a3884f3a922d0da758cb7ed9a5ddc3c3c2132dde8d913753fa3e6b766be5697","0x222d05a0fce0565bf9cc490f97bd4eff53858f2ca6afe9d91c5c8d7de8076f39","0x054698b045b439467a3067a8dc2b4d020b2bb44df3d98a19f9cfb04c9ee5ffd1","0x0e39d66cded0f3df40e04124e36c827bcaf15fbe9fb6e9bbc3af889f8bd1ebf0","0x145aea47dc97ec35ac67f135aac37f8bc6eaf149551a2f48901529d10e25c860","0x1894877b2769ae2c288738f8aa33acfc7ca9a7d1e26a76908ca2909bf25aa59a","0x27e8c702be67be467f052abd180464a468b7d5d5d8a4961e56e8561f7863c91a","0x0326d3e4607d54a30c7fa99d1609f386aeb8c8094cabd7397246074f634dcec8","0x17eb8f62b5ba2dad391e3f81d3a6b9d03ff723a7d6a4d77b98b18ddd0debf4fd","0x1a5d3e8a27c1f69d6e4558b3c89cd9347c62182ce90fb6e34392bc4e7b7c178c","0x2293034bed3d33d5ad0d150f64d493c9be554f640103621f9ae56034a7323d84","0x13d75ffbb9d2ceb2daa6d42f3618d4ea9775befa1cf5f9df141dfebf794abc35","0x2ec339c42fbb2d50221ec907779e72be3eab2960d110a90d36cc6c0afcf5857e","0x15e9c913fa84a2657571831d5d7a90f6534ca67a1617b4063fa5bf09f46cd7a2","0x10f56fbe9fefd59d2acd49fa641fedcfb65d96d54cf47207e2c8ab34f22bbabe","0x117fa3859a400040ebe8dee4a60ddcb04484ff5cfb5294c6530354c3c8cb35f3","0x123260b824df2f8bbe6a351ba2fa94c61aa754741eb198b768a699b2d1cc2b6f","0x1e51d9a653adc6b67287d35bb60584261f57363177c6b54a56dbd39834d851ba","0x18a9b2e2fce77bdb5e41215e2caeb7e77e946dbb2f381c8e7974709e03a6c216","0x2b2640870195a40e374cfa834e37ad9a5e17cb687bd2119a63ac02c3769b0f1e","0x2da73263fef362dfc79dd1066fd7ec294b765e2533f3ac4320e8d1540f2639a8","0x0cc9f299e5291bb1bc0951ce510a634c418af9f9802a291fe6d951768c0a1b2d","0x02a940acb788df42cc9219531776d45465be19087fc3f523fe92df771e5efc10","0x2d5976cc5540e761824bdacf69a2dddabe104fdbb235985ae9080b488f642fa9","0x284c18d1574d2cb7b4ee45b3ff30176eff2ab9c7b7f60cd8a87cef599379244d","0x12a38d659bf38da09af8f445505baa16bcb036d83173f6f45a7e46cac511e5a1","0x0852ef710b2396ba5b7fd69a95b336908d3a368262ec41e0d972564f784201a4","0x240c467a31ed3bb7c4cef09407750d2d89b3750e6cebb4aaa9d0f1f92be77249","0x04edf7595087745abc11fe7780afd4754c5013725653a4cec31f039b77e7b3c7","0x080d04b50ae3acd787f33f8f4a639a58677b5c04ef8a352fd4dd9236883f0e81","0x0cd745e7540fe230038f024ab1269177599ad94e8d8099a010eb7eebd3e41ec8","0x25e2394f90f5b3e3046b8876a6b3ef19a03ef9e9aeae4813fcb14907decc0393","0x03df12a6e39c606d70d3d470aff710d9daa86dece773a6f6f057725b57d6d115","0x0f744082aecf54f55db19dfbe56a81c17b3eb48417305c129beb6c97a22c705b","0x244a80d6d82e82fc416e8e4694deb4e08b81c32bb90cb2f96ff3f687298322d1","0x251eb4d8692f49523e3972096264ee770b295fb62a970fbfdd8aa1fff661ef50","0x0c4d9200120430618493a9151d632faa95c9ae842b7d97103a4afb3330cafbed","0x09e970a55dd7335db16a3823b6489c77cb7785f674cb7c924994ee121122e514","0x19e5bd1113959463be673ee72103bfe7559f423c632fbf9701ff099e165c429b","0x071eb2916ba30652a328c98353f69f239c41a4913c34931f18e91e5414b3270a","0x2a0cd2ebac904b7ebd82b6509dfcaf9ecf32175758c691d01f4fb32dad6371c4","0x1aa43a3009417d95904ebecd4189545e52ca7e9c7dfa3bde5f255ddefed5c754","0x29fd7a93212d60af81b810dad13a240bbbe16966a4977408b1d64c5d692b50b4","0x000000000000000000000000000000bef7cad70fa62891e6329cb7c17d0c5459","0x0000000000000000000000000000000000209177f2a04609421c1f23c04b454e","0x00000000000000000000000000000060dec389686170618e2490100f3fcf39e2","0x0000000000000000000000000000000000213368873145aad5f93798c31730af","0x000000000000000000000000000000c0f21a470488d9cbe53650d941c25cd569","0x000000000000000000000000000000000016d6f88e6b319553f5948886a6bd5e","0x000000000000000000000000000000d6dbb8a54a071e01c46d648c8c555ec352","0x0000000000000000000000000000000000130a7ce06ad74eb6c83f5565e2f821","0x00000000000000000000000000000058ca3aa788bd6ff37a5da3ecefdc896601","0x00000000000000000000000000000000001381bddcf8fb976cc52fee0d920598","0x00000000000000000000000000000082bdd94acd10edf22e09b1a42be500f8f8","0x00000000000000000000000000000000002f27815e28b2bc0699336893abdc0f","0x000000000000000000000000000000eb1d6973a54f8848f4c0630370d6181e49","0x000000000000000000000000000000000000129c1889d64ab66303bf17bfc864","0x000000000000000000000000000000155918aa9f6d352b847bf860a261266282","0x0000000000000000000000000000000000216e687d2f85a811f67573cbf311ba","0x0000000000000000000000000000002d2662f79a7ba21a95f44e67ed0b5abf3b","0x00000000000000000000000000000000001351870a81dc6edff235df110fe798","0x000000000000000000000000000000b113a55b86f59b21fe419ed8518dfddfc6","0x00000000000000000000000000000000002f26cd920f79b0d72a49897acc521c","0x0000000000000000000000000000002a4e1689c65dcae73ed1a33b03c611a7fe","0x00000000000000000000000000000000001c5093a8ae791c00fdd763c95800c5","0x0000000000000000000000000000006231d049ec3683c06ec6b00348e0669c61","0x0000000000000000000000000000000000237bfd7ec06c28f22ce84db9bb17ed","0x0000000000000000000000000000008afa7fa0842467bded20491950c3c1cde0","0x00000000000000000000000000000000000194ab5c71154605b8483cb40d00b8","0x00000000000000000000000000000066709af193591e93e8be3b833f63cb8597","0x000000000000000000000000000000000008ab9091bb9225b00ca0c011dff12f"] +proof = ["0x0000000000000000000000000000000000000000000000000000000000000020","0x0000000000000000000000000000000000000000000000000000000000000011","0x0000000000000000000000000000000000000000000000000000000000000001","0x0000000000000000000000000000000000000000000000042ab5d6d1986846cf","0x00000000000000000000000000000000000000000000000b75c020998797da78","0x0000000000000000000000000000000000000000000000005a107acb64952eca","0x000000000000000000000000000000000000000000000000000031e97a575e9d","0x00000000000000000000000000000000000000000000000b5666547acf8bd5a4","0x00000000000000000000000000000000000000000000000c410db10a01750aeb","0x00000000000000000000000000000000000000000000000d722669117f9758a4","0x000000000000000000000000000000000000000000000000000178cbf4206471","0x000000000000000000000000000000000000000000000000e91b8a11e7842c38","0x000000000000000000000000000000000000000000000007fd51009034b3357f","0x000000000000000000000000000000000000000000000009889939f81e9c7402","0x0000000000000000000000000000000000000000000000000000f94656a2ca48","0x000000000000000000000000000000000000000000000006fb128b46c1ddb67f","0x0000000000000000000000000000000000000000000000093fe27776f50224bd","0x000000000000000000000000000000000000000000000004a0c80c0da527a081","0x0000000000000000000000000000000000000000000000000001b52c2020d746","0x0000000000000000000000000000005a9bae947e1e91af9e4033d8d6aa6ed632","0x000000000000000000000000000000000025e485e013446d4ac7981c88ba6ecc","0x000000000000000000000000000000ff1e0496e30ab24a63b32b2d1120b76e62","0x00000000000000000000000000000000001afe0a8a685d7cd85d1010e55d9d7c","0x000000000000000000000000000000b0804efd6573805f991458295f510a2004","0x00000000000000000000000000000000000c81a178016e2fe18605022d5a8b0e","0x000000000000000000000000000000eba51e76eb1cfff60a53a0092a3c3dea47","0x000000000000000000000000000000000022e7466247b533282f5936ac4e6c15","0x00000000000000000000000000000071b1d76edf770edff98f00ff4deec264cd","0x00000000000000000000000000000000001e48128e68794d8861fcbb2986a383","0x000000000000000000000000000000d3a2af4915ae6d86b097adc377fafda2d4","0x000000000000000000000000000000000006359de9ca452dab3a4f1f8d9c9d98","0x0000000000000000000000000000000d9d719a8b9f020ad3642d60fe704e696f","0x00000000000000000000000000000000000ddfdbbdefc4ac1580ed38e12cfa49","0x0000000000000000000000000000008289fe9754ce48cd01b7be96a861b5e157","0x00000000000000000000000000000000000ff3e0896bdea021253b3d360fa678","0x0000000000000000000000000000000d9d719a8b9f020ad3642d60fe704e696f","0x00000000000000000000000000000000000ddfdbbdefc4ac1580ed38e12cfa49","0x0000000000000000000000000000008289fe9754ce48cd01b7be96a861b5e157","0x00000000000000000000000000000000000ff3e0896bdea021253b3d360fa678","0x000000000000000000000000000000f968b227a358a305607f3efc933823d288","0x00000000000000000000000000000000000eaf8adb390375a76d95e918b65e08","0x000000000000000000000000000000bb34b4b447aae56f5e24f81c3acd6d547f","0x00000000000000000000000000000000002175d012746260ebcfe339a91a81e1","0x0000000000000000000000000000005b739ed2075f2b046062b8fc6a2d1e9863","0x00000000000000000000000000000000001285cd1030d338c0e1603b4da2c838","0x00000000000000000000000000000027447d6c281eb38b2b937af4a516d60c04","0x000000000000000000000000000000000019bc3d980465fbb4a656a74296fc58","0x000000000000000000000000000000b484788ace8f7df86dd5e325d2e9b12599","0x00000000000000000000000000000000000a2ca0d10eb7b767114ae230b728d3","0x000000000000000000000000000000c6dfc7092f16f95795e437664498b88d53","0x0000000000000000000000000000000000131067b4e4d95a4f6f8cf5c9b5450a","0x0f413f22eec51f2a02800e0cafaeec1d92d744fbbaef213c687b9edabd6985f5","0x21230f4ff26c80ffb5d037a9d1d26c3f955ca34cbeca4f54db6656b932967a0c","0x0521f877fe35535767f99597cc50effbd283dcae6812ee0a7620d796ccbfd642","0x202b01350a9cc5c20ec0f3eaada338c0a3b793811bd539418ffa3cc4302615e2","0x2d1214d9b0d41058ad4a172d9c0aecc5bdabe95e687c3465050c6b5396509be4","0x1113b344a151b0af091cb28d728b752ebb4865da6cd7ee68471b961ca5cf69b9","0x2aa66d0954bb83e17bd5c9928d3aa7a7df75d741d409f7c15ba596804ba643fb","0x2e26bc7a530771ef7a95d5360d537e41cf94d8a0942764ff09881c107f91a106","0x0f14f32b921bb63ad1df00adab7c82af58ea8aa7f353f14b281208d8c5fab504","0x13429515c0c53b6502bbcdf545defb3cb69a986c9263e070fcbb397391aae1a3","0x1f21cac5e2f262afc1006a21454cc6bcb018c44e53ad8ab61cebbac99e539176","0x2a9886a6ddc8a61b097c668cd362fc8acdee8dde74f7b1af192c3e060bb2948f","0x2d718181e408ead2e9bcd30a84ad1fccbaf8d48ab6d1820bad4933d284b503c4","0x2634c1aafc902f14508f34d3d7e9d485f42d1a4c95b5a1ef73711ed0d3c68d77","0x092ede9777e6472ce5ffd8c963d466006189e960e2c591d338dc8d4af1a057fb","0x1cba45b17fd24f1cb1b4ab7b83eee741f6c77ba70a497dc4de259eceb7d5ea26","0x246e887c7bf2e17f919b2393b6e9b00b33e8822d862544a775aac05cb7bff710","0x04c3f539fe8689971948afcb437f1ecbd444a5bddaca1c8a450348dcd8480047","0x20c6a423ae4fd58e8951aa378d02d77baf90508ceb48856db2319d70938b186e","0x1bcf8786b554b3316d8ebdbc9d006a4e5d4865aad512ffd404b7f83550d3d030","0x09ab038260518f0970564afcd6bf22e2abf6b1fa5e12a327bbf195b6ca5edd78","0x1024e32554746f89c195286ba6ccfc9765e5d14bbe8064bc6fdf22d16ec6b495","0x17706656f8dbd7e47bb257a6428f0cb7278ea02fa9e6ce431d7bcc9133fba9c7","0x25a3e8a33c15ef2a4dd16313a6049bf1d468b4cdc141f238f2d51a1e8e1c22b3","0x1198863f08006edb27aee23164fb117a4ddec1bf1ed89807aa907e5cd24bf068","0x1862b4856b5b4d4a064f873e221703e4e2cd1ebfca1337dedca56485c38ed5a0","0x062214af1ea6dd6bf8895b92d394571c43970b6f967e1c794624d96071b25ad3","0x1e5be9428ddcf1f9b0cbafc28101e792ec5cf73852b0cd0b84fbff71b4490e09","0x2d4189bea5b1e30f63c64bd26df82f18bcaf885ec8887b54634b2557869ce87f","0x0f2e5d9a908850e9d44925e17d8b12d1adb1ed029799c9b5858598504242bbc0","0x3050dc85746a57931d99f3f35e77c2ba561fba0baa018b79ff1fd544026833ae","0x2a591a32437e5e0b875a137fd868bd1b6dbc003ff1b661f26e00627cc7c5cf47","0x27946841e1670ad9c65717016d0cedf524724217236e81b9fd0a264a36ebfb0e","0x0fc396e9d19d6e68e289602e292ee345542d0d28bf6de34fa62cc577cbdfb1df","0x08e7433a07a44c0c9c4dd4b273a2685bbd1a91fd5cf2b43409458fab42a23e1b","0x12bd9bfb029c3503a5c6deea87b0a0f11bb9f7ea584af2d48f3e48d7e09247ae","0x2ccc4810748c0a82dfc0f063d0b8c7999ffe9474653080e6ef92b3cb7a428784","0x08eb574d7fecadadb508c8bd35fdad06b99110609d679763c2e3645229b1b95a","0x0f1a65e747c8021ed7c454a4be1e89b1bce66ead9ed980fa98a7a050eafe98a1","0x1c8ff9e36684ec71614dee4c17859b06c742089f6029d3694a16e00dac9b57f1","0x0303101a8ba712aeca4da85b767ab8d3ecf489ec7d746f8ee20041717cc000e9","0x0aaf64c65e7088e5596108c9601467911fea809ca6540d79af77e6e66e36cd99","0x17caf164ce74ea7edfb1390e07763d2197797ec26661b92cde18a98d61d2fddc","0x18cb055c7ad6d01437725bb457681d81f3ecadc4f35d838a3c13daf25a44456a","0x2d78602b8bbcd32b36a99a6e2d248e7fe044ef1b50813133370412f9ef5299f0","0x2b139276ea86d426a115479e4154f72a6bd83a6253bf13e9670dc6b4664378f0","0x127c7837b384902c39a104036c09546728571c46c8166b1b9b13b3a615ebb781","0x05faa4816f83cf0189a482ad943c94b9ec6474002f2b327f8698763ad0ea0985","0x2f90359cc30ee693fb3aced96523cf7aebd152c22329eee56a398d9a4ac0628e","0x0a71beaf17a59c5a238f04c1f203848d87502c5057a78c13f0cfb0f9876e7714","0x2696c1e6d089556adaeb95c8a5e3065b00a393a38c2d69e9bd6ce8cdc49d87da","0x1f3d165a7dc6564a036e451eb9cb7f1e1cb1e6d29daa75e3f135ea3e58a79ccd","0x1473a660819bdd838d56122b72b32b267211e9f1103239480ec50fa85c9e1035","0x0a8ccaeb22451f391b3fc3467c8e6e900270a7afb7b510e8acf5a4f06f1c0888","0x03b3080afc0658cc87e307758cebc171921f43eca159b9dedf7f72aa8dd926bd","0x2dd7d6663fa0e1755dfafac352c361fcd64c7f4d53627e3646870ac169cc4a07","0x1ec54b883f5f35ccad0e75695af20790d9860104095bab34c9bf01628dd40cb9","0x193dff50f83c241f7a9e087a29ce72ecf3f6d8563593f786dcd04c32bcfd4ced","0x135122c0dae26cda8ca1c09de8225064ad86d10423ab0aaa53b481aa4626e1d6","0x08d5a56cbfab5aeed56d3cdd7fb6b30fc26b0c1a5b63fccd7fa44c53ba6fd35a","0x0d12f126dfa2daad3726d00ca339284cc22e36c6d81bb7a4b95c6f9598b60e7c","0x2e8b24bbdf2fd839d3c7cae1f0eeb96bfcfaeef30b27476f2fafcb17da78cd5e","0x2364acfe0cea39b7f749c5f303b99504977357925f810f684c60f35d16315211","0x06ca062eb70b8c51cfac35345e7b6b51f33a8ec9ebe204fb9b4911200bf508b7","0x266c0aa1ccb97186815bf69084f600d06ddd934e59a38dfe602ee5d6b9487f22","0x1d817537a49c6d0e3b4b65c6665334b91d7593142e60065048be9e55ceb5e7ab","0x05e9b7256a368df053c691952b59e9327a7c12ed322bbd6f72c669b9b9c26d49","0x05e9b7256a368df053c691952b59e9327a7c12ed322bbd6f72c669b9b9c26d49","0x25b77026673a1e613e50df0e88fb510973739d5f9064bd364079a9f884209632","0x25c9bc7a3f6aae3d43ff68b5614b34b5eaceff37157b37347995d231784ac1fd","0x085f69baef22680ae15f4801ef4361ebe9c7fc24a94b5bc2527dce8fb705439e","0x0d7c6b9ce31bfc32238a205455baf5ffe99cd30eb0f7bb5b504e1d4501e01382","0x1001a8cc4bc1221c814fba0eddcf3c40619b133373640c600de5bed0a0a05b10","0x20f5894be90e52977cb70f4f4cbd5101693db0360848939750db7e91109d54b6","0x22c09cb26db43f0599408b4daed0f4f496c66424e6affa41c14387d8e0af851b","0x24e5f41357798432426a9549d71e8cc681eaebacbe87f6e3bf38e85de5aa2f3d","0x06eb90100c736fbf2b87432d7821ecdc0b365024739bc36363d48b905973f5b9","0x0000000000000000000000000000007f36e0b4f59927ebbb2302e76cbe8bd44e","0x00000000000000000000000000000000001b95777c6c98640c80638c195909ca","0x0000000000000000000000000000006d4b1ad71244248cb2070fbbbb0ac9df88","0x00000000000000000000000000000000001abada4d5d816a67b6fc75746cb723","0x000000000000000000000000000000465811089df032ceb5269254547a101e57","0x000000000000000000000000000000000011a4a909c59776a6df9c7615e8e87d","0x000000000000000000000000000000311f6f724e7199351c9774225f15c25f20","0x00000000000000000000000000000000001ddba8eb0ab208ad3d96c70941fcbc","0x0000000000000000000000000000000dfa80bdf5be151b21ad89466b7201b63d","0x000000000000000000000000000000000015ca7dc258adab8ea406d94e00c56d","0x000000000000000000000000000000507ea3454165f92295b6e435c7d30d14f0","0x00000000000000000000000000000000002f522608db7b7d389d1df67eab104d","0x000000000000000000000000000000950102cce743fadb23965fc72e31efd36c","0x000000000000000000000000000000000018b4a7ec90df68dfe97d3c5367d1bf","0x000000000000000000000000000000118d90258b25dba8bc0f99d9f7547c6a62","0x000000000000000000000000000000000012d78638701da6322abbf325693b0f","0x000000000000000000000000000000144743e0d082f35295b51561af65f94c6b","0x00000000000000000000000000000000002322a615615e5405836374bb3c5336","0x000000000000000000000000000000e6f08dd5904ee42f826cde680919b41a96","0x00000000000000000000000000000000002d3f823ea255b68465e4b5360bf864","0x00000000000000000000000000000076d4db93683b6363ae92a5a20d8bb9922e","0x00000000000000000000000000000000002f8a7009cac72c9599b81cb9054308","0x00000000000000000000000000000085c12dd2be9f2b29e54c1a4bc3cbf9b6ce","0x000000000000000000000000000000000024e3688a1f4f50b0c6bd6c068f32b2","0x00000000000000000000000000000023a2015e7ea351e444c9405adfbd81e84d","0x00000000000000000000000000000000001fb3e4228c15dc4380db796925ec49","0x000000000000000000000000000000834ad9406b8ded7208b872373be7445e47","0x0000000000000000000000000000000000267544d6a9f5cc46d10555f2617c65"] public_inputs = ["0x0000000000000000000000000000000000000000000000000000000000000003"] verification_key = ["0x0000000000000000000000000000000000000000000000000000000000000020","0x0000000000000000000000000000000000000000000000000000000000000011","0x0000000000000000000000000000000000000000000000000000000000000001","0x00000000000000000000000000000060e430ad1c23bfcf3514323aae3f206e84","0x00000000000000000000000000000000001b5c3ff4c2458d8f481b1c068f27ae","0x000000000000000000000000000000bb510ab2112def34980e4fc6998ad9dd16","0x00000000000000000000000000000000000576e7c105b43e061e13cb877fefe1","0x000000000000000000000000000000ced074785d11857b065d8199e6669a601c","0x00000000000000000000000000000000000053b48a4098c1c0ae268f273952f7","0x000000000000000000000000000000d1d4b26e941db8168cee8f6de548ae0fd8","0x00000000000000000000000000000000001a9adf5a6dadc3d948bb61dfd63f4c","0x0000000000000000000000000000009ce1faac6f8de6ebb18f1db17372c82ad5","0x00000000000000000000000000000000002002681bb417184b2df070a16a3858","0x000000000000000000000000000000161baa651a8092e0e84725594de5aba511","0x00000000000000000000000000000000000be0064399c2a1efff9eb0cdcb2223","0x0000000000000000000000000000008673be6fd1bdbe980a29d8c1ded54381e7","0x000000000000000000000000000000000008a5158a7d9648cf1d234524c9fa0c","0x0000000000000000000000000000002b4fce6e4b1c72062b296d49bca2aa4130","0x00000000000000000000000000000000002e45a9eff4b6769e55fb710cded44f","0x00000000000000000000000000000072b85bf733758b76bcf97333efb85a23e3","0x000000000000000000000000000000000017da0ea508994fc82862715e4b5592","0x00000000000000000000000000000094fa74695cf058dba8ff35aec95456c6c3","0x0000000000000000000000000000000000211acddb851061c24b8f159e832bd1","0x000000000000000000000000000000303b5e5c531384b9a792e11702ad3bcab0","0x00000000000000000000000000000000000d336dff51a60b8833d5d7f6d4314c","0x0000000000000000000000000000009f825dde88092070747180d581c342444a","0x0000000000000000000000000000000000237fbd6511a03cca8cac01b555fe01","0x0000000000000000000000000000007c313205159495df6d8de292079a4844ff","0x000000000000000000000000000000000018facdfc468530dd45e8f7a1d38ce9","0x0000000000000000000000000000000d1ce33446fc3dc4ab40ca38d92dac74e1","0x00000000000000000000000000000000000852d8e3e0e8f4435af3e94222688b","0x0000000000000000000000000000006c04ee19ec1dfec87ed47d6d04aa158de2","0x000000000000000000000000000000000013240f97a584b45184c8ec31319b5f","0x000000000000000000000000000000cefb5d240b07ceb4be26ea429b6dc9d9e0","0x00000000000000000000000000000000002dad22022121d689f57fb38ca21349","0x000000000000000000000000000000c9f189f2a91aeb664ce376d8b157ba98f8","0x00000000000000000000000000000000002531a51ad54f124d58094b219818d2","0x000000000000000000000000000000ef1e6db71809307f677677e62b4163f556","0x0000000000000000000000000000000000272da4396fb2a7ee0638b9140e523d","0x0000000000000000000000000000002e54c0244a7732c87bc4712a76dd8c83fb","0x000000000000000000000000000000000007db77b3e04b7eba9643da57cbbe4d","0x000000000000000000000000000000e0dfe1ddd7f74ae0d636c910c3e85830d8","0x00000000000000000000000000000000000466fa9b57ec4664abd1505b490862","0x0000000000000000000000000000009ee55ae8a32fe5384c79907067cc27192e","0x00000000000000000000000000000000000799d0e465cec07ecb5238c854e830","0x0000000000000000000000000000001d5910ad361e76e1c241247a823733c39f","0x00000000000000000000000000000000002b03f2ccf7507564da2e6678bef8fe","0x000000000000000000000000000000231147211b3c75e1f47d150e4bbd2fb22e","0x00000000000000000000000000000000000d19ee104a10d3c701cfd87473cbbe","0x0000000000000000000000000000006705f3f382637d00f698e2c5c94ed05ae9","0x00000000000000000000000000000000000b9c792da28bb60601dd7ce4b74e68","0x000000000000000000000000000000ac5acc8cc21e4ddb225c510670f80c80b3","0x00000000000000000000000000000000002da9d3fa57343e6998aba19429b9fa","0x0000000000000000000000000000004bacbf54b7c17a560df0af18b6d0d527be","0x00000000000000000000000000000000000faea33aeca2025b22c288964b21eb","0x000000000000000000000000000000492e756298d68d6e95de096055cc0336c3","0x00000000000000000000000000000000001a12a12f004859e5a3675c7315121b","0x000000000000000000000000000000893d521d512f30e6d32afbbc0cecd8ee00","0x00000000000000000000000000000000001674b3c1ef12c6da690631e0d86c04","0x000000000000000000000000000000aa6cb02a52e7a613873d4ac9b411349945","0x00000000000000000000000000000000001ecb1fe9c493add46751f9940f73e1","0x00000000000000000000000000000045b3d362ca82cba69fb2b9c733a5b8c351","0x000000000000000000000000000000000019a683586af466e331945b732d2f8c","0x000000000000000000000000000000fc79b052dfdfe67c0ecfc06b4267ffd694","0x00000000000000000000000000000000001336a70c396393038d5e9913744ac2","0x0000000000000000000000000000005450d29af1e9438e91cd33ddeb2548226e","0x000000000000000000000000000000000000993a602891cfd0e6f6ecf7404933","0x000000000000000000000000000000498efddab90a32e9b2db729ed6e9b40192","0x00000000000000000000000000000000002425efebe9628c63ca6fc28bdb5901","0x000000000000000000000000000000d8488157f875a21ab5f93f1c2b641f3de9","0x0000000000000000000000000000000000290f95ada3936604dc4b14df7504e3","0x0000000000000000000000000000005d6902187f3ed60dcce06fca211b40329a","0x00000000000000000000000000000000002b5870a6ba0b20aaa0178e5adfbc36","0x000000000000000000000000000000e5c2519171fa0e548fc3c4966ffc1ce570","0x00000000000000000000000000000000001cb8d8f4793b7debbdc429389dbf2d","0x000000000000000000000000000000a3ee22dd60456277b86c32a18982dcb185","0x00000000000000000000000000000000002493c99a3d068b03f8f2b8d28b57ce","0x000000000000000000000000000000f6c3731486320082c20ec71bbdc92196c1","0x00000000000000000000000000000000001ded39c4c8366469843cd63f09ecac","0x000000000000000000000000000000494997477ab161763e46601d95844837ef","0x00000000000000000000000000000000002e0cddbc5712d79b59cb3b41ebbcdd","0x000000000000000000000000000000426db4c64531d350750df62dbbc41a1bd9","0x0000000000000000000000000000000000303126892f664d8d505964d14315ec","0x00000000000000000000000000000076a6b2c6040c0c62bd59acfe3e3e125672","0x000000000000000000000000000000000000874a5ad262eecc6b565e0b085074","0x000000000000000000000000000000ef082fb517183c9c6841c2b8ef2ca1df04","0x0000000000000000000000000000000000127b2a745a1b74968c3edc18982b9b","0x000000000000000000000000000000c9efd4f8c3d56e1eb23d789a8f710d5be6","0x000000000000000000000000000000000015a18748490ff4c2b1871081954e86","0x000000000000000000000000000000a0011ef987dc016ab110eacd554a1d8bbf","0x00000000000000000000000000000000002097c84955059442a95df075833071","0x000000000000000000000000000000d38e9426ad3085b68b00a93c17897c2877","0x00000000000000000000000000000000002aecd48089890ea0798eb952c66824","0x00000000000000000000000000000078d8a9ce405ce559f441f2e71477ff3ddb","0x00000000000000000000000000000000001216bdb2f0d961bb8a7a23331d2150","0x0000000000000000000000000000000000000000000000000000000000000001","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000002","0x0000000000000000000000000000000000000000000000000000000000000000","0x000000000000000000000000000000ee40d90bea71fba7a412dd61fcf34e8ceb","0x0000000000000000000000000000000000140b0936c323fd2471155617b6af56","0x0000000000000000000000000000002b90071823185c5ff8e440fd3d73b6fefc","0x00000000000000000000000000000000002b6c10790a5f6631c87d652e059df4"] \ No newline at end of file diff --git a/noir/noir-repo/test_programs/execution_success/verify_honk_proof/src/main.nr b/noir/noir-repo/test_programs/execution_success/verify_honk_proof/src/main.nr index d25fd804ce4..c534b07fc77 100644 --- a/noir/noir-repo/test_programs/execution_success/verify_honk_proof/src/main.nr +++ b/noir/noir-repo/test_programs/execution_success/verify_honk_proof/src/main.nr @@ -6,7 +6,7 @@ fn main( // This is the proof without public inputs attached. // // This means: the size of this does not change with the number of public inputs. - proof: [Field; 153], + proof: [Field; 156], public_inputs: pub [Field; 1], // This is currently not public. It is fine given that the vk is a part of the circuit definition. // I believe we want to eventually make it public too though. From 40191a75f22acbe5d3360582a147d0455addb26e Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Thu, 20 Jun 2024 18:51:59 +0000 Subject: [PATCH 32/42] comments and cleanup --- .../relations/logderiv_lookup_relation.hpp | 67 ++++++++++++------- .../stdlib_circuit_builders/mega_flavor.hpp | 32 +++++---- .../plookup_tables/types.hpp | 20 +++++- .../stdlib_circuit_builders/ultra_flavor.hpp | 10 ++- 4 files changed, 79 insertions(+), 50 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp index 1302e9bf6a7..9d65181aa29 100644 --- a/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp @@ -37,20 +37,17 @@ template class LogDerivLookupRelationImpl { return in.q_lookup.is_zero() && in.lookup_read_counts.is_zero(); } + // Used to determine whether the polynomial of inverses must be computed at a given row template static bool operation_exists_at_row(const AllValues& row) { + // is lookup gate or row contains data that has been read return (row.q_lookup == 1) || (row.lookup_read_tags == 1); } - /** - * @brief Get the inverse lookup polynomial - * - * @tparam AllEntities - * @param in - * @return auto& - */ + // Get the inverse lookup polynomial for this relation template static auto& get_inverse_polynomial(AllEntities& in) { return in.lookup_inverses; } + // Used to toggle the inverse correctness check in the inverse correctness subrelation template static Accumulator compute_inverse_exists(const AllEntities& in) { @@ -65,7 +62,6 @@ template class LogDerivLookupRelationImpl { static Accumulator lookup_read_counts(const AllEntities& in) { using View = typename Accumulator::View; - return Accumulator(View(in.lookup_read_counts)); } @@ -74,14 +70,12 @@ template class LogDerivLookupRelationImpl { { using View = typename Accumulator::View; - return Accumulator(View(in.q_lookup)); } template static Accumulator compute_write_term_predicate([[maybe_unused]] const AllEntities& in) { - // using View = typename Accumulator::View; return Accumulator(1); } @@ -131,7 +125,7 @@ template class LogDerivLookupRelationImpl { auto negative_column_3_step_size = View(in.q_c); // The wire values for lookup gates are accumulators structured in such a way that the differences w_i - - // step_size*w_i_shift should result in a values that exists in table_i. + // step_size*w_i_shift result in values present in column i of a corresponding table. auto derived_table_entry_1 = w_1 + gamma + negative_column_1_step_size * w_1_shift; auto derived_table_entry_2 = w_2 + negative_column_2_step_size * w_2_shift; auto derived_table_entry_3 = w_3 + negative_column_3_step_size * w_3_shift; @@ -143,12 +137,41 @@ template class LogDerivLookupRelationImpl { } /** - * @brief WORKTODO + * @brief Log-derivative style lookup argument for conventional lookups form tables with 3 or fewer columns + * @details The identity to be checked is of the form + * + * \sum{i=0}^{n-1} \frac{read_counts_i}{write_term_i} - \frac{q_lookup}{read_term_i} = 0 + * + * where write_term = table_col_1 + \gamma + table_col_2 * \eta_1 + table_col_3 * \eta_2 + table_index * \eta_3 + * and read_term = derived_table_entry_1 + \gamma + derived_table_entry_2 * \eta_1 + derived_table_entry_3 * \eta_2 + * + table_index * \eta_3, with derived_table_entry_i = w_i - col_step_size\cdot w_i_shift. (The table entries must + * be 'derived' from wire values in this way since the stored witnesses are actually successive accumulators, the + * differences of which are equal to entries in a table. This is an efficiency trick to avoid using additional gates + * to reconstruct full size values from the limbs contained in tables). + * + * In practice this identity is expressed in terms of polynomials by defining a polynomial of inverses I_i = + * \frac{1}{read_term_i\cdot write_term_i} then rewriting the above identity as + * + * (1) \sum{i=0}^{n-1} (read_counts_i\cdot I_i\cdot read_term_i) - (q_lookup\cdot I_i\cdot write_term_i) = 0 + * + * This requires a second subrelation to check that polynomial I was computed correctly. For all i, it must hold + * that + * + * (2) I_i\cdot read_term_i\cdot write_term_i - 1 = 0 + * + * Note that (1) is 'linearly dependent' in the sense that it holds only as a sum across the entire execution trace. + * (2) on the other hand holds independently at every row. Finally, note that to avoid unnecessary computation, we + * only compute I_i at indices where the relation is 'active', i.e. on rows which either contain a lookup gate or + * table data that has been read. For inactive rows i, we set I_i = 0. We can thus rewrite (2) as + * + * (2) I_i\cdot read_term_i\cdot write_term_i - is_active_i + * + * where is_active = q_lookup + read_tags - q_lookup\cdot read_tags + * + * and read_tags is a polynomial taking boolean values indicating whether the table entry at the corresponding row + * has been read or not. + * @note This relation utilizes functionality in the log-derivative library to compute the polynomial of inverses * - * @param accumulator transformed to `evals + C(in(X)...)*scaling_factor` - * @param in an std::array containing the fully extended Accumulator edges. - * @param relation_params contains beta, gamma, and public_input_delta, .... - * @param scaling_factor optional term to scale the evaluation before adding to evals. */ template static void accumulate(ContainerOverSubrelations& accumulator, @@ -170,17 +193,13 @@ template class LogDerivLookupRelationImpl { // Establish the correctness of the polynomial of inverses I. Note: inverses is computed so that the value is 0 // if !inverse_exists. - // Degrees: 2 (3) 1 (2) 1 + // Degrees: 2 (3) 1 (2) 1 1 std::get<0>(accumulator) += (read_term * write_term * inverses - inverse_exists) * scaling_factor; // Deg 4 (6) - // Establish validity of the read. Note: no scaling factor here since this constraint is enforced across the - // entire trace, not on a per-row basis. Degree - // Degrees: 1 2 (3) 1 3 (4) + // Establish validity of the read. Note: no scaling factor here since this constraint is 'linearly dependent, + // i.e. enforced across the entire trace, not on a per-row basis. Degree + // Degrees: 1 2 (3) 1 3 (4) std::get<1>(accumulator) += read_selector * read_inverse - read_counts * write_inverse; // Deg 4 (5) - - // ****************** - // accumulate_logderivative_lookup_subrelation_contributions>( - // accumulator, in, params, scaling_factor); } }; diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp index 0cbffeb559d..1f01843a625 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp @@ -65,8 +65,6 @@ class MegaFlavor { bb::Poseidon2InternalRelation>; using Relations = Relations_; - // using LogDerivLookupRelation = LogDerivLookupRelation; - static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = compute_max_partial_relation_length(); static constexpr size_t MAX_TOTAL_RELATION_LENGTH = compute_max_total_relation_length(); @@ -178,20 +176,20 @@ class MegaFlavor { template class DerivedEntities { public: DEFINE_FLAVOR_MEMBERS(DataType, - z_perm, // column 5 - lookup_inverses, // column 6 + z_perm, // column 4 + lookup_inverses, // column 5 lookup_read_counts, // column 6 - lookup_read_tags, // column 6 - ecc_op_wire_1, // column 7 - ecc_op_wire_2, // column 8 - ecc_op_wire_3, // column 9 - ecc_op_wire_4, // column 10 - calldata, // column 11 - calldata_read_counts, // column 12 - calldata_inverses, // column 13 - return_data, // column 14 - return_data_read_counts, // column 15 - return_data_inverses); // column 16 + lookup_read_tags, // column 7 + ecc_op_wire_1, // column 8 + ecc_op_wire_2, // column 9 + ecc_op_wire_3, // column 10 + ecc_op_wire_4, // column 11 + calldata, // column 12 + calldata_read_counts, // column 13 + calldata_inverses, // column 14 + return_data, // column 15 + return_data_read_counts, // column 16 + return_data_inverses); // column 17 }; /** @@ -241,7 +239,7 @@ class MegaFlavor { w_r_shift, // column 5 w_o_shift, // column 6 w_4_shift, // column 7 - z_perm_shift) + z_perm_shift) // column 8 }; public: @@ -406,7 +404,7 @@ class MegaFlavor { } /** - * @brief Computes public_input_delta, lookup_grand_product_delta, the z_perm polynomial + * @brief Computes public_input_delta and the permutation grand product polynomial * * @param relation_parameters */ diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/types.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/types.hpp index 40881c91e0b..a68da31b1b6 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/types.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/types.hpp @@ -268,10 +268,22 @@ struct MultiTable { // } +/** + * @brief A map from 'entry' to 'index' where entry is a row in a BasicTable and index is the row at which that entry + * exists in the table + * @details Such a map is needed to in order to construct read_counts (the polynomial containing the number of reads + * from each entry in a table) for the log-derivative lookup argument. A BasicTable essentially consists of 3 columns, + * and 'lookups' are recorded as rows in this table. The index at which this data exists in the table is not explicitly + * known at the time of lookup gate creation. This map can be used to construct read counts from the set of lookups that + * have been performed via an operation like read_counts[index_map[lookup_data]]++ + * + */ struct LookupHashTable { using FF = bb::fr; - using Key = std::array; - using Value = size_t; + using Key = std::array; // an entry in a lookup table + using Value = size_t; // the index of an entry in a lookup table + + // Define a simple hash on three field elements struct HashFunction { FF mult_const; FF const_sqr; @@ -290,9 +302,9 @@ struct LookupHashTable { std::unordered_map index_map; - // Default constructor LookupHashTable() = default; + // Initialize the entry-index map with the columns of a table void initialize(std::vector& column_1, std::vector& column_2, std::vector& column_3) { for (size_t i = 0; i < column_1.size(); ++i) { @@ -300,6 +312,7 @@ struct LookupHashTable { } } + // Given an entry in the table, return its index in the table Value operator[](const Key& key) const { auto it = index_map.find(key); @@ -360,6 +373,7 @@ struct BasicTable { std::vector column_3; std::vector lookup_gates; // wire data for all lookup gates created for lookups on this table + // Map from a table entry to its index in the table; used for constructing read counts LookupHashTable index_map; void initialize_index_map() { index_map.initialize(column_1, column_2, column_3); } diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp index 6a71840fb92..be9c9294a24 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp @@ -57,8 +57,6 @@ class UltraFlavor { bb::AuxiliaryRelation>; using Relations = Relations_; - // using LogDerivLookupRelation = bb::LogDerivLookupRelation; - static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = compute_max_partial_relation_length(); static_assert(MAX_PARTIAL_RELATION_LENGTH == 6); static constexpr size_t MAX_TOTAL_RELATION_LENGTH = compute_max_total_relation_length(); @@ -149,10 +147,10 @@ class UltraFlavor { w_r, // column 1 w_o, // column 2 w_4, // column 3 - z_perm, // column 5 - lookup_inverses, // column 6 + z_perm, // column 4 + lookup_inverses, // column 5 lookup_read_counts, // column 6 - lookup_read_tags) // column 6 + lookup_read_tags) // column 7 auto get_wires() { return RefArray{ w_l, w_r, w_o, w_4 }; }; @@ -335,7 +333,7 @@ class UltraFlavor { } /** - * @brief Computes public_input_delta, lookup_grand_product_delta, the z_perm polynomial + * @brief Computes public_input_delta and the permutation grand product polynomial * * @param relation_parameters */ From f706150ef1e4247d4ff21e1eda7fbb39bf212582 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Thu, 20 Jun 2024 19:32:22 +0000 Subject: [PATCH 33/42] clean up test and add todo --- .../composer/composer_lib.hpp | 19 +++++--- .../composer/composer_lib.test.cpp | 43 +++++++++---------- .../protogalaxy/protogalaxy_prover.hpp | 1 - 3 files changed, 32 insertions(+), 31 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp index 3e439c1d8a6..b71752d0735 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp @@ -21,7 +21,7 @@ void construct_lookup_table_polynomials(RefArray // ^^^^^^^^^ ^^^^^^^^ ^^^^^^^ ^nonzero to ensure uniqueness and to avoid infinity commitments // | table randomness // ignored, as used for regular constraints and padding to the next power of 2. - // WORKTODO: eventually just construct the tables (and therefore the counts) at the top of the trace + // TODO(https://github.com/AztecProtocol/barretenberg/issues/1033): construct tables and counts at top of trace ASSERT(dyadic_circuit_size > circuit.get_tables_size() + additional_offset); size_t offset = dyadic_circuit_size - circuit.get_tables_size() - additional_offset; @@ -39,8 +39,11 @@ void construct_lookup_table_polynomials(RefArray } /** - * @brief WORKTODO - * + * @brief Construct polynomial whose value at index i is the number of times the table entry at that index has been + * read. + * @details Read counts are needed for the log derivative lookup argument. The table polynomials are constructed as a + * concatenation of basic 3-column tables. Similarly, the read counts polynomial is constructed as the concatenation of + * read counts for the individual tables. */ template typename Flavor::Polynomial construct_lookup_read_counts(typename Flavor::Polynomial& read_counts, @@ -48,25 +51,27 @@ typename Flavor::Polynomial construct_lookup_read_counts(typename Flavor::Polyno typename Flavor::CircuitBuilder& circuit, size_t dyadic_circuit_size) { - // WORKTODO: eventually just construct the tables (and therefore the counts) at the top of the trace + // TODO(https://github.com/AztecProtocol/barretenberg/issues/1033): construct tables and counts at top of trace size_t offset = dyadic_circuit_size - circuit.get_tables_size(); size_t table_offset = offset; // offset of the present table in the table polynomials + // loop over all tables used in the circuit; each table contains data about the lookups made on it for (auto& table : circuit.lookup_tables) { table.initialize_index_map(); for (auto& entry : table.lookup_gates) { + // convert lookup entry to an array of three field elements, one for each of the 3 columns auto data = entry.to_sorted_list_components(table.use_twin_keys); - // find the index of the current lookup gate in the table + // find the index of the entry in the table auto index_in_table = table.index_map[data]; // increment the read count at the corresponding index in the full polynomial size_t index_in_poly = table_offset + index_in_table; read_counts[index_in_poly]++; - read_tags[index_in_poly] = 1; + read_tags[index_in_poly] = 1; // tag is 1 if entry has been read 1 or more times } - table_offset += table.size(); + table_offset += table.size(); // set the offset of the next table within the polynomials } return read_counts; diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.test.cpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.test.cpp index c6c4eb24d4c..33534bc958d 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.test.cpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.test.cpp @@ -17,33 +17,34 @@ class ComposerLibTests : public ::testing::Test { static void SetUpTestSuite() { bb::srs::init_crs_factory("../srs_db/ignition"); } }; +/** + * @brief A test to demonstrate that lookup read counts/tags are computed correctly for a simple 'hand-computable' case + * using the uint32 XOR table + * + */ TEST_F(ComposerLibTests, LookupReadCounts) { using Builder = UltraCircuitBuilder; using Flavor = UltraFlavor; using FF = typename Flavor::FF; using Polynomial = typename Flavor::Polynomial; + auto UINT32_XOR = plookup::MultiTableId::UINT32_XOR; + Builder builder; - uint256_t left_val = 1 & 0xffffffffULL; - uint256_t right_val = 5 & 0xffffffffULL; - // uint256_t left_val = 25251 & 0xffffffffULL; - // uint256_t right_val = 2831092109228376 & 0xffffffffULL; + // define some very simply inputs to XOR + FF left{ 1 }; + FF right{ 5 }; - FF left{ left_val }; - FF right{ right_val }; auto left_idx = builder.add_variable(left); auto right_idx = builder.add_variable(right); - auto accumulators = - plookup::get_lookup_accumulators(plookup::MultiTableId::UINT32_XOR, left, right, /*is_2_to_1_lookup*/ true); - info("num accumulators = ", accumulators.columns[0].size()); - - builder.create_gates_from_plookup_accumulators( - plookup::MultiTableId::UINT32_XOR, accumulators, left_idx, right_idx); + // create a single lookup from the uint32 XOR table + auto accumulators = plookup::get_lookup_accumulators(UINT32_XOR, left, right, /*is_2_to_1_lookup*/ true); + builder.create_gates_from_plookup_accumulators(UINT32_XOR, accumulators, left_idx, right_idx); - info("num tables = ", builder.lookup_tables.size()); - info("num lookups = ", builder.lookup_tables[0].lookup_gates.size()); + EXPECT_EQ(builder.lookup_tables.size(), 1); // we only used a single table + EXPECT_EQ(builder.lookup_tables[0].size(), 4096); // table has size 64*64 (6 bit operands) size_t circuit_size = 8192; @@ -52,18 +53,14 @@ TEST_F(ComposerLibTests, LookupReadCounts) construct_lookup_read_counts(read_counts, read_tags, builder, circuit_size); - // size_t idx = 0; - // for (auto& val : read_counts) { - // if (val != 0) { - // info("idx = ", idx); - // info(val); - // } - // ++idx; - // } - // The table polys are constructed at the bottom of the trace, thus so to are the counts/tags + // TODO(https://github.com/AztecProtocol/barretenberg/issues/1033): construct tables and counts at top of trace size_t offset = circuit_size - builder.get_tables_size(); + // The uint32 XOR lookup table is constructed for 6 bit operands via double for loop that iterates through the left + // operand externally (0 to 63) then the right operand internally (0 to 63). Computing (1 XOR 5) will thus result in + // 1 lookup from the (1*64 + 5)th index in the table and 5 lookups from the (0*64 + 0)th index (for the remaining 5 + // limbs that are all 0). The counts and tags at all other indices should be zero. size_t idx = 0; for (auto [count, tag] : zip_view(read_counts, read_tags)) { if (idx == (0 + offset)) { diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp index 3091c0259e2..cbfbe35cbda 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp @@ -364,7 +364,6 @@ template class ProtoGalaxyProver_ { const FF& scaling_factor) { using Relation = std::tuple_element_t; - // WORKTODO: disable skipping for the combiner for now.. // Check if the relation is skippable to speed up accumulation if constexpr (!isSkippable) { // If not, accumulate normally From 3a5c42ead78968b827e2b9389c379ff518f73ff9 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Thu, 20 Jun 2024 21:32:19 +0000 Subject: [PATCH 34/42] failure tests --- .../composer/composer_lib.hpp | 11 +-- .../ultra_honk/ultra_composer.test.cpp | 92 +++++++++++++++++++ 2 files changed, 97 insertions(+), 6 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp index b71752d0735..1bf7425ad89 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp @@ -46,10 +46,10 @@ void construct_lookup_table_polynomials(RefArray * read counts for the individual tables. */ template -typename Flavor::Polynomial construct_lookup_read_counts(typename Flavor::Polynomial& read_counts, - typename Flavor::Polynomial& read_tags, - typename Flavor::CircuitBuilder& circuit, - size_t dyadic_circuit_size) +void construct_lookup_read_counts(typename Flavor::Polynomial& read_counts, + typename Flavor::Polynomial& read_tags, + typename Flavor::CircuitBuilder& circuit, + size_t dyadic_circuit_size) { // TODO(https://github.com/AztecProtocol/barretenberg/issues/1033): construct tables and counts at top of trace size_t offset = dyadic_circuit_size - circuit.get_tables_size(); @@ -61,6 +61,7 @@ typename Flavor::Polynomial construct_lookup_read_counts(typename Flavor::Polyno for (auto& entry : table.lookup_gates) { // convert lookup entry to an array of three field elements, one for each of the 3 columns + // WORKTODO change name of this method auto data = entry.to_sorted_list_components(table.use_twin_keys); // find the index of the entry in the table @@ -73,8 +74,6 @@ typename Flavor::Polynomial construct_lookup_read_counts(typename Flavor::Polyno } table_offset += table.size(); // set the offset of the next table within the polynomials } - - return read_counts; } } // namespace bb diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.test.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.test.cpp index b04bd0b7fd1..697a74b3474 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.test.cpp @@ -207,6 +207,98 @@ TEST_F(UltraHonkComposerTests, create_gates_from_plookup_accumulators) prove_and_verify(circuit_builder, /*expected_result=*/true); } +/** + * @brief Test various failure modes for the lookup relation via bad input polynomials + * + */ +TEST_F(UltraHonkComposerTests, LookupFailure) +{ + auto construct_circuit_with_lookups = []() { + UltraCircuitBuilder builder; + auto UINT32_XOR = plookup::MultiTableId::UINT32_XOR; + + // define some arbitrary inputs to uint32 XOR + uint32_t left_value = engine.get_random_uint32(); + uint32_t right_value = engine.get_random_uint32(); + + fr left = fr{ left_value, 0, 0, 0 }.to_montgomery_form(); + fr right = fr{ right_value, 0, 0, 0 }.to_montgomery_form(); + + auto left_idx = builder.add_variable(left); + auto right_idx = builder.add_variable(right); + + // perform lookups from the uint32 XOR table + auto accumulators = plookup::get_lookup_accumulators(UINT32_XOR, left, right, /*is_2_to_1_lookup*/ true); + builder.create_gates_from_plookup_accumulators(UINT32_XOR, accumulators, left_idx, right_idx); + + return builder; + }; + + auto prove_and_verify = [](auto& instance) { + UltraProver prover(instance); + auto verification_key = std::make_shared(instance->proving_key); + UltraVerifier verifier(verification_key); + auto proof = prover.construct_proof(); + return verifier.verify_proof(proof); + }; + + // Ensure the unaltered test circuit is valid + { + auto builder = construct_circuit_with_lookups(); + + auto instance = std::make_shared(builder); + + EXPECT_TRUE(prove_and_verify(instance)); + } + + // Failure mode 1: bad read counts/tags + { + auto builder = construct_circuit_with_lookups(); + + auto instance = std::make_shared(builder); + + // Erroneously update the read counts/tags at an arbitrary index + instance->proving_key.polynomials.lookup_read_counts[25] = 1; + instance->proving_key.polynomials.lookup_read_tags[25] = 1; + + EXPECT_FALSE(prove_and_verify(instance)); + } + + // Failure mode 2: bad lookup gate wire value + { + auto builder = construct_circuit_with_lookups(); + + auto instance = std::make_shared(builder); + + auto& polynomials = instance->proving_key.polynomials; + + // Find a lookup gate and alter one of the wire values + for (auto [q_lookup, wire_3] : zip_view(polynomials.q_lookup, polynomials.w_o)) { + if (!q_lookup.is_zero()) { + wire_3 += 1; + break; + } + } + + EXPECT_FALSE(prove_and_verify(instance)); + } + + // Failure mode 3: erroneous lookup gate + { + auto builder = construct_circuit_with_lookups(); + + auto instance = std::make_shared(builder); + + auto& polynomials = instance->proving_key.polynomials; + + // Turn the lookup selector on for an arbitrary row where it is not already active + EXPECT_TRUE(polynomials.q_lookup[25] != 1); + instance->proving_key.polynomials.q_lookup[25] = 1; + + EXPECT_FALSE(prove_and_verify(instance)); + } +} + TEST_F(UltraHonkComposerTests, test_no_lookup_proof) { auto circuit_builder = UltraCircuitBuilder(); From cd2da7a333f138b5dd738046d8e1ba6d18f62cbb Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Fri, 21 Jun 2024 15:21:55 +0000 Subject: [PATCH 35/42] more failure tests and some cleanup --- .../protogalaxy/protogalaxy.test.cpp | 105 ++++++++++++++++-- .../protogalaxy/protogalaxy_prover_impl.hpp | 7 +- .../stdlib_circuit_builders/mock_circuits.hpp | 29 +++++ .../ultra_circuit_builder.hpp | 1 + .../ultra_honk/ultra_composer.test.cpp | 27 ++--- 5 files changed, 137 insertions(+), 32 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp index 5eec42117d5..cfb06a1d796 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp @@ -309,21 +309,96 @@ template class ProtoGalaxyTests : public testing::Test { } /** - * @brief Testing one valid round of folding followed by the decider. - * @brief For additional robustness we give one of the circuits more public inputs than the other + * @brief Testing one valid round of folding (plus decider) for two inhomogeneous circuits + * @details For robustness we fold circuits with different numbers/types of gates (but the same dyadic size) * */ - static void test_full_protogalaxy_simple() + static void test_protogalaxy_inhomogeneous() { - // Construct a first circuit with some public inputs - Builder builder1; - construct_circuit(builder1); - bb::MockCircuits::add_arithmetic_gates_with_public_inputs(builder1, /*num_gates=*/4); + auto check_fold_and_decide = [](Builder& circuit_1, Builder& circuit_2) { + // Construct the prover/verifier instances for each + TupleOfInstances instances; + construct_prover_and_verifier_instance(instances, circuit_1); + construct_prover_and_verifier_instance(instances, circuit_2); + + // Perform prover and verifier folding + auto [prover_accumulator, verifier_accumulator] = fold_and_verify(get<0>(instances), get<1>(instances)); + check_accumulator_target_sum_manual(prover_accumulator, true); + + // Run decider + decide_and_verify(prover_accumulator, verifier_accumulator, true); + }; + + // One circuit has more arithmetic gates + { + // Construct two equivalent circuits + Builder builder1; + Builder builder2; + construct_circuit(builder1); + construct_circuit(builder2); + + // Add some arithmetic gates + bb::MockCircuits::add_arithmetic_gates(builder1, /*num_gates=*/4); + + check_fold_and_decide(builder1, builder2); + } + + // One circuit has more arithmetic gates with public inputs + { + // Construct two equivalent circuits + Builder builder1; + Builder builder2; + construct_circuit(builder1); + construct_circuit(builder2); + + // Add some arithmetic gates with public inputs to the first circuit + bb::MockCircuits::add_arithmetic_gates_with_public_inputs(builder1, /*num_gates=*/4); + + check_fold_and_decide(builder1, builder2); + } - // Construct a second circuit with no public inputs + // One circuit has more lookup gates + { + // Construct two equivalent circuits + Builder builder1; + Builder builder2; + construct_circuit(builder1); + construct_circuit(builder2); + + // Add a different number of lookup gates to each circuit + bb::MockCircuits::add_lookup_gates(builder1, /*num_iterations=*/2); // 12 gates plus 4096 table + bb::MockCircuits::add_lookup_gates(builder2, /*num_iterations=*/1); // 6 gates plus 4096 table + + check_fold_and_decide(builder1, builder2); + } + } + + /** + * @brief Ensure failure for a bad lookup gate in one of the circuits being folded + * + */ + static void test_protogalaxy_bad_lookup_failure() + { + + // Failure case: tamper with one of the lookup gates + // Construct two equivalent circuits + Builder builder1; Builder builder2; + construct_circuit(builder1); construct_circuit(builder2); + // Add a different number of lookup gates to each circuit + bb::MockCircuits::add_lookup_gates(builder1, /*num_iterations=*/2); // 12 gates plus 4096 table + bb::MockCircuits::add_lookup_gates(builder2, /*num_iterations=*/1); // 6 gates plus 4096 table + + // Erroneously set a non-zero wire value to zero in one of the lookup gates + for (auto& wire_3_witness_idx : builder1.blocks.lookup.w_o()) { + if (wire_3_witness_idx != builder1.zero_idx) { + wire_3_witness_idx = builder1.zero_idx; + break; + } + } + // Construct the prover/verifier instances for each TupleOfInstances instances; construct_prover_and_verifier_instance(instances, builder1); @@ -331,9 +406,10 @@ template class ProtoGalaxyTests : public testing::Test { // Perform prover and verifier folding auto [prover_accumulator, verifier_accumulator] = fold_and_verify(get<0>(instances), get<1>(instances)); - check_accumulator_target_sum_manual(prover_accumulator, true); - decide_and_verify(prover_accumulator, verifier_accumulator, true); + // Expect failure in manual target sum check and decider + bool expected_result check_accumulator_target_sum_manual(prover_accumulator, false); + decide_and_verify(prover_accumulator, verifier_accumulator, false); } /** @@ -515,9 +591,9 @@ TYPED_TEST(ProtoGalaxyTests, CombineAlpha) TestFixture::test_combine_alpha(); } -TYPED_TEST(ProtoGalaxyTests, FullProtogalaxySimple) +TYPED_TEST(ProtoGalaxyTests, ProtogalaxyInhomogeneous) { - TestFixture::test_full_protogalaxy_simple(); + TestFixture::test_protogalaxy_inhomogeneous(); } TYPED_TEST(ProtoGalaxyTests, FullProtogalaxyTest) @@ -544,6 +620,11 @@ TYPED_TEST(ProtoGalaxyTests, TamperedAccumulatorPolynomial) TestFixture::test_tampered_accumulator_polynomial(); } +TYPED_TEST(ProtoGalaxyTests, BadLookupFailure) +{ + TestFixture::test_protogalaxy_bad_lookup_failure(); +} + // We only fold one instance currently due to significant compile time added by multiple instances TYPED_TEST(ProtoGalaxyTests, Fold1Instance) { diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp index f38ff10b3e1..36774b7c25f 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp @@ -187,7 +187,12 @@ FoldingResult ProtoGalaxyProver_proving_key.circuit_size == instances[idx + 1]->proving_key.circuit_size); + if (instances[idx]->proving_key.circuit_size != instances[idx + 1]->proving_key.circuit_size) { + info("ProtogalaxyProver: circuit size mismatch!"); + info("Instance ", idx, " size = ", instances[idx]->proving_key.circuit_size); + info("Instance ", idx + 1, " size = ", instances[idx + 1]->proving_key.circuit_size); + ASSERT(false); + } } preparation_round(); perturbator_round(); diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mock_circuits.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mock_circuits.hpp index 183d951f070..5c3b54d173a 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mock_circuits.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mock_circuits.hpp @@ -59,6 +59,35 @@ class MockCircuits { } } + /** + * @brief Add lookup gates using the uint32 XOR lookup table (table size 4096) + * @brief Each iteration adds 6 lookup gates + * + * @param builder + * @param num_gates + */ + template static void add_lookup_gates(Builder& builder, size_t num_iterations = 1) + { + auto UINT32_XOR = plookup::MultiTableId::UINT32_XOR; + + // Each iteration adds 6 lookup gates (due to six 6-bit limbs); the first adds a table of size 4096 + for (size_t i = 0; i < num_iterations; ++i) { + // define some arbitrary inputs to uint32 XOR + uint32_t left_value = engine.get_random_uint32(); + uint32_t right_value = engine.get_random_uint32(); + + fr left = fr{ left_value, 0, 0, 0 }.to_montgomery_form(); + fr right = fr{ right_value, 0, 0, 0 }.to_montgomery_form(); + + auto left_idx = builder.add_variable(left); + auto right_idx = builder.add_variable(right); + + // perform lookups from the uint32 XOR table + auto accumulators = plookup::get_lookup_accumulators(UINT32_XOR, left, right, /*is_2_to_1_lookup*/ true); + builder.create_gates_from_plookup_accumulators(UINT32_XOR, accumulators, left_idx, right_idx); + } + } + /** * @brief Populate a builder with a specified number of arithmetic gates; includes a PI * diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp index ce1a8b8aebf..7d3198dfc70 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp @@ -659,6 +659,7 @@ class UltraCircuitBuilder_ : public CircuitBuilderBasepublic_inputs.size(); return std::max(minimum_circuit_size, num_filled_gates) + NUM_RESERVED_GATES; diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.test.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.test.cpp index 697a74b3474..aad537c721d 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.test.cpp @@ -213,23 +213,12 @@ TEST_F(UltraHonkComposerTests, create_gates_from_plookup_accumulators) */ TEST_F(UltraHonkComposerTests, LookupFailure) { + // Construct a circuit with lookup and arithmetic gates auto construct_circuit_with_lookups = []() { UltraCircuitBuilder builder; - auto UINT32_XOR = plookup::MultiTableId::UINT32_XOR; - // define some arbitrary inputs to uint32 XOR - uint32_t left_value = engine.get_random_uint32(); - uint32_t right_value = engine.get_random_uint32(); - - fr left = fr{ left_value, 0, 0, 0 }.to_montgomery_form(); - fr right = fr{ right_value, 0, 0, 0 }.to_montgomery_form(); - - auto left_idx = builder.add_variable(left); - auto right_idx = builder.add_variable(right); - - // perform lookups from the uint32 XOR table - auto accumulators = plookup::get_lookup_accumulators(UINT32_XOR, left, right, /*is_2_to_1_lookup*/ true); - builder.create_gates_from_plookup_accumulators(UINT32_XOR, accumulators, left_idx, right_idx); + MockCircuits::add_lookup_gates(builder); + MockCircuits::add_arithmetic_gates(builder); return builder; }; @@ -256,10 +245,12 @@ TEST_F(UltraHonkComposerTests, LookupFailure) auto builder = construct_circuit_with_lookups(); auto instance = std::make_shared(builder); + auto& polynomials = instance->proving_key.polynomials; // Erroneously update the read counts/tags at an arbitrary index - instance->proving_key.polynomials.lookup_read_counts[25] = 1; - instance->proving_key.polynomials.lookup_read_tags[25] = 1; + // Note: updating only one or the other may not cause failure due to the relation algebra + polynomials.lookup_read_counts[25] = 1; + polynomials.lookup_read_tags[25] = 1; EXPECT_FALSE(prove_and_verify(instance)); } @@ -269,7 +260,6 @@ TEST_F(UltraHonkComposerTests, LookupFailure) auto builder = construct_circuit_with_lookups(); auto instance = std::make_shared(builder); - auto& polynomials = instance->proving_key.polynomials; // Find a lookup gate and alter one of the wire values @@ -288,12 +278,11 @@ TEST_F(UltraHonkComposerTests, LookupFailure) auto builder = construct_circuit_with_lookups(); auto instance = std::make_shared(builder); - auto& polynomials = instance->proving_key.polynomials; // Turn the lookup selector on for an arbitrary row where it is not already active EXPECT_TRUE(polynomials.q_lookup[25] != 1); - instance->proving_key.polynomials.q_lookup[25] = 1; + polynomials.q_lookup[25] = 1; EXPECT_FALSE(prove_and_verify(instance)); } From c36266c5ff11fd3cf897a29a34720df47ab468b8 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Fri, 21 Jun 2024 15:43:55 +0000 Subject: [PATCH 36/42] fix build and cleanup --- .../src/barretenberg/plonk/composer/composer_lib.hpp | 2 +- .../plonk_honk_shared/composer/composer_lib.hpp | 9 ++++----- .../src/barretenberg/protogalaxy/protogalaxy.test.cpp | 5 +++-- .../relations/logderiv_lookup_relation.hpp | 11 ++++++----- .../stdlib_circuit_builders/plookup_tables/types.hpp | 7 ++++--- .../stdlib_circuit_builders/ultra_circuit_builder.hpp | 1 - 6 files changed, 18 insertions(+), 17 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/plonk/composer/composer_lib.hpp b/barretenberg/cpp/src/barretenberg/plonk/composer/composer_lib.hpp index ee319334d73..88c518cb4b3 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/composer/composer_lib.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk/composer/composer_lib.hpp @@ -112,7 +112,7 @@ std::array construct_sorted_list_polynomials(typ #endif for (const auto& entry : lookup_gates) { - const auto components = entry.to_sorted_list_components(table.use_twin_keys); + const auto components = entry.to_table_components(table.use_twin_keys); sorted_polynomials[0][s_index] = components[0]; sorted_polynomials[1][s_index] = components[1]; sorted_polynomials[2][s_index] = components[2]; diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp index 1bf7425ad89..d4e75dc9e14 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp @@ -59,13 +59,12 @@ void construct_lookup_read_counts(typename Flavor::Polynomial& read_counts, for (auto& table : circuit.lookup_tables) { table.initialize_index_map(); - for (auto& entry : table.lookup_gates) { - // convert lookup entry to an array of three field elements, one for each of the 3 columns - // WORKTODO change name of this method - auto data = entry.to_sorted_list_components(table.use_twin_keys); + for (auto& gate_data : table.lookup_gates) { + // convert lookup gate data to an array of three field elements, one for each of the 3 columns + auto table_entry = gate_data.to_table_components(table.use_twin_keys); // find the index of the entry in the table - auto index_in_table = table.index_map[data]; + auto index_in_table = table.index_map[table_entry]; // increment the read count at the corresponding index in the full polynomial size_t index_in_poly = table_offset + index_in_table; diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp index cfb06a1d796..98b02eda176 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp @@ -408,8 +408,9 @@ template class ProtoGalaxyTests : public testing::Test { auto [prover_accumulator, verifier_accumulator] = fold_and_verify(get<0>(instances), get<1>(instances)); // Expect failure in manual target sum check and decider - bool expected_result check_accumulator_target_sum_manual(prover_accumulator, false); - decide_and_verify(prover_accumulator, verifier_accumulator, false); + bool expected_result = false; + check_accumulator_target_sum_manual(prover_accumulator, expected_result); + decide_and_verify(prover_accumulator, verifier_accumulator, expected_result); } /** diff --git a/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp index 9d65181aa29..0510b93fab2 100644 --- a/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp @@ -23,7 +23,8 @@ template class LogDerivLookupRelationImpl { LENGTH // log derivative lookup argument sub-relation }; - // WORKTODO: shouldnt first one be 2? code doesnt compile that way + // WORKTODO: shouldnt first one be 2? Why do tests pass with 1? (Note: if setting to 2, both need to be 2 due to + // structure of relation algebra) static constexpr std::array TOTAL_LENGTH_ADJUSTMENTS{ 1, // inverse construction sub-relation 1 // log derivative lookup argument sub-relation @@ -144,10 +145,10 @@ template class LogDerivLookupRelationImpl { * * where write_term = table_col_1 + \gamma + table_col_2 * \eta_1 + table_col_3 * \eta_2 + table_index * \eta_3 * and read_term = derived_table_entry_1 + \gamma + derived_table_entry_2 * \eta_1 + derived_table_entry_3 * \eta_2 - * + table_index * \eta_3, with derived_table_entry_i = w_i - col_step_size\cdot w_i_shift. (The table entries must - * be 'derived' from wire values in this way since the stored witnesses are actually successive accumulators, the - * differences of which are equal to entries in a table. This is an efficiency trick to avoid using additional gates - * to reconstruct full size values from the limbs contained in tables). + * + table_index * \eta_3, with derived_table_entry_i = w_i - col_step_size_i\cdot w_i_shift. (The table entries + * must be 'derived' from wire values in this way since the stored witnesses are actually successive accumulators, + * the differences of which are equal to entries in a table. This is an efficiency trick to avoid using additional + * gates to reconstruct full size values from the limbs contained in tables). * * In practice this identity is expressed in terms of polynomials by defining a polynomial of inverses I_i = * \frac{1}{read_term_i\cdot write_term_i} then rewriting the above identity as diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/types.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/types.hpp index a68da31b1b6..4111817ba7a 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/types.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/types.hpp @@ -213,7 +213,7 @@ struct MultiTable { // std::array value{ bb::fr(0), bb::fr(0) }; // bool operator<(const KeyEntry& other) const { return key < other.key; } -// std::array to_sorted_list_components(const bool use_two_keys) const +// std::array to_table_components(const bool use_two_keys) const // { // return { // key[0], @@ -248,7 +248,7 @@ struct MultiTable { // return (key.from_montgomery_form() < other.key.from_montgomery_form()); // } -// std::array to_sorted_list_components() const { return { key, values[0], values[0] }; } +// std::array to_table_components() const { return { key, values[0], values[0] }; } // } // BasicTableId id; @@ -349,7 +349,8 @@ struct BasicTable { return key[0] < other.key[0] || ((key[0] == other.key[0]) && key[1] < other.key[1]); } - std::array to_sorted_list_components(const bool use_two_keys) const + // Express the key-value pair as the entries of a 3-column row in a table + std::array to_table_components(const bool use_two_keys) const { return { bb::fr(key[0]), diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp index 7d3198dfc70..ce1a8b8aebf 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp @@ -659,7 +659,6 @@ class UltraCircuitBuilder_ : public CircuitBuilderBasepublic_inputs.size(); return std::max(minimum_circuit_size, num_filled_gates) + NUM_RESERVED_GATES; From f74ceff6d61eec2235abf46f9ef526e70aab2113 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Fri, 21 Jun 2024 15:59:12 +0000 Subject: [PATCH 37/42] min circuit size due to lookups is only based on tables now --- .../cpp/src/barretenberg/sumcheck/instance/prover_instance.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.cpp b/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.cpp index 2df2f34f158..350b9e414e4 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.cpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.cpp @@ -13,7 +13,7 @@ namespace bb { template size_t ProverInstance_::compute_dyadic_size(Circuit& circuit) { // minimum circuit size due to lookup argument - const size_t min_size_due_to_lookups = circuit.get_tables_size() + circuit.get_lookups_size(); + const size_t min_size_due_to_lookups = circuit.get_tables_size(); // minimum size of execution trace due to everything else size_t min_size_of_execution_trace = circuit.public_inputs.size() + circuit.num_gates; From dc883bbf4733cdee98421a2c99cf293cfe875892 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Fri, 21 Jun 2024 16:28:02 +0000 Subject: [PATCH 38/42] lots of cleanup --- .../protogalaxy/protogalaxy.test.cpp | 2 -- .../relations/logderiv_lookup_relation.hpp | 19 +++---------------- .../protogalaxy_recursive_verifier.cpp | 6 +++++- .../verifier/ultra_recursive_verifier.cpp | 4 ++-- .../stdlib_circuit_builders/mega_flavor.hpp | 2 +- .../stdlib_circuit_builders/mock_circuits.hpp | 2 +- .../plookup_tables/types.hpp | 2 +- .../barretenberg/ultra_honk/oink_prover.cpp | 6 +++--- .../barretenberg/ultra_honk/oink_verifier.cpp | 5 +++-- .../ultra_honk/ultra_composer.test.cpp | 2 +- 10 files changed, 20 insertions(+), 30 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp index 98b02eda176..08815605a34 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp @@ -379,8 +379,6 @@ template class ProtoGalaxyTests : public testing::Test { */ static void test_protogalaxy_bad_lookup_failure() { - - // Failure case: tamper with one of the lookup gates // Construct two equivalent circuits Builder builder1; Builder builder2; diff --git a/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp index 0510b93fab2..2d56a3e1dd6 100644 --- a/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp @@ -45,10 +45,10 @@ template class LogDerivLookupRelationImpl { return (row.q_lookup == 1) || (row.lookup_read_tags == 1); } - // Get the inverse lookup polynomial for this relation + // Get the inverse polynomial for this relation template static auto& get_inverse_polynomial(AllEntities& in) { return in.lookup_inverses; } - // Used to toggle the inverse correctness check in the inverse correctness subrelation + // Used in the inverse correctness subrelation; facilitates only computing inverses where necessary template static Accumulator compute_inverse_exists(const AllEntities& in) { @@ -66,20 +66,7 @@ template class LogDerivLookupRelationImpl { return Accumulator(View(in.lookup_read_counts)); } - template - static Accumulator compute_read_term_predicate(const AllEntities& in) - - { - using View = typename Accumulator::View; - return Accumulator(View(in.q_lookup)); - } - - template - static Accumulator compute_write_term_predicate([[maybe_unused]] const AllEntities& in) - { - return Accumulator(1); - } - + // Compute table_1 + gamma + table_2 * eta + table_3 * eta_2 + table_4 * eta_3 template static Accumulator compute_write_term(const AllEntities& in, const Parameters& params) { diff --git a/barretenberg/cpp/src/barretenberg/stdlib/honk_recursion/verifier/protogalaxy_recursive_verifier.cpp b/barretenberg/cpp/src/barretenberg/stdlib/honk_recursion/verifier/protogalaxy_recursive_verifier.cpp index e5633d78039..0a1b48068bd 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/honk_recursion/verifier/protogalaxy_recursive_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/honk_recursion/verifier/protogalaxy_recursive_verifier.cpp @@ -53,13 +53,17 @@ void ProtoGalaxyRecursiveVerifier_::receive_and_finalise_inst domain_separator + "_" + labels.return_data_read_counts); } - // Get challenge for sorted list batching and wire four memory records commitment + // Get eta challenges auto [eta, eta_two, eta_three] = transcript->template get_challenges( domain_separator + "_eta", domain_separator + "_eta_two", domain_separator + "_eta_three"); + + // Receive commitments to lookup argument polynomials witness_commitments.lookup_read_counts = transcript->template receive_from_prover(domain_separator + "_" + labels.lookup_read_counts); witness_commitments.lookup_read_tags = transcript->template receive_from_prover(domain_separator + "_" + labels.lookup_read_tags); + + // Receive commitments to wire 4 witness_commitments.w_4 = transcript->template receive_from_prover(domain_separator + "_" + labels.w_4); // Get permutation challenges and commitment to permutation and lookup grand products diff --git a/barretenberg/cpp/src/barretenberg/stdlib/honk_recursion/verifier/ultra_recursive_verifier.cpp b/barretenberg/cpp/src/barretenberg/stdlib/honk_recursion/verifier/ultra_recursive_verifier.cpp index 952e38c7685..0bc2de8d67f 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/honk_recursion/verifier/ultra_recursive_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/honk_recursion/verifier/ultra_recursive_verifier.cpp @@ -89,13 +89,13 @@ std::array UltraRecursiveVerifier_::ve transcript->template receive_from_prover(commitment_labels.return_data_read_counts); } - // Get challenge for sorted list batching and wire four memory records + // Get eta challenges auto [eta, eta_two, eta_three] = transcript->template get_challenges("eta", "eta_two", "eta_three"); relation_parameters.eta = eta; relation_parameters.eta_two = eta_two; relation_parameters.eta_three = eta_three; - // Get commitments to sorted list accumulator and fourth wire + // Get commitments to lookup argument polynomials and fourth wire commitments.lookup_read_counts = transcript->template receive_from_prover(commitment_labels.lookup_read_counts); commitments.lookup_read_tags = diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp index 1f01843a625..a8047946141 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp @@ -382,7 +382,7 @@ class MegaFlavor { } /** - * @brief Compute the inverse polynomial used in the databus log derivative lookup argument + * @brief Compute the inverse polynomials used in the log derivative lookup relations * * @tparam Flavor * @param beta diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mock_circuits.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mock_circuits.hpp index 5c3b54d173a..f52d7d3ab52 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mock_circuits.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mock_circuits.hpp @@ -61,7 +61,7 @@ class MockCircuits { /** * @brief Add lookup gates using the uint32 XOR lookup table (table size 4096) - * @brief Each iteration adds 6 lookup gates + * @brief Each iteration adds 6 lookup gates and results in a minimum circuit size of 4096 * * @param builder * @param num_gates diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/types.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/types.hpp index 4111817ba7a..259082820eb 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/types.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/types.hpp @@ -413,7 +413,7 @@ template class ReadData { std::vector lookup_entries; - // private: + private: // Container for the lookup accumulators; 0th index of each column contains full accumulated value std::array, 3> columns; }; diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp index e80f0c14a8f..4e21db889ae 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp @@ -110,7 +110,7 @@ template void OinkProver::execute_wire_commitment */ template void OinkProver::execute_sorted_list_accumulator_round() { - + // Get eta challenges auto [eta, eta_two, eta_three] = transcript->template get_challenges( domain_separator + "eta", domain_separator + "eta_two", domain_separator + "eta_three"); relation_parameters.eta = eta; @@ -119,8 +119,8 @@ template void OinkProver::execute_sorted_list_acc proving_key.add_plookup_memory_records_to_wire_4( relation_parameters.eta, relation_parameters.eta_two, relation_parameters.eta_three); - // Commit to the sorted witness-table accumulator and the finalized (i.e. with memory records) fourth wire - // polynomial + + // Commit to lookup argument polynomials and the finalized (i.e. with memory records) fourth wire polynomial witness_commitments.lookup_read_counts = commitment_key->commit(proving_key.polynomials.lookup_read_counts); witness_commitments.lookup_read_tags = commitment_key->commit(proving_key.polynomials.lookup_read_tags); witness_commitments.w_4 = commitment_key->commit(proving_key.polynomials.w_4); diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/oink_verifier.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/oink_verifier.cpp index 22c888ad797..0a5a1810e4c 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/oink_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/oink_verifier.cpp @@ -87,13 +87,14 @@ template void OinkVerifier::execute_wire_commitme */ template void OinkVerifier::execute_sorted_list_accumulator_round() { - // Get challenge for sorted list batching and wire four memory records + // Get eta challenges auto [eta, eta_two, eta_three] = transcript->template get_challenges( domain_separator + "eta", domain_separator + "eta_two", domain_separator + "eta_three"); relation_parameters.eta = eta; relation_parameters.eta_two = eta_two; relation_parameters.eta_three = eta_three; - // Get commitments to sorted list accumulator and fourth wire + + // Get commitments to lookup argument polynomials and fourth wire witness_comms.lookup_read_counts = transcript->template receive_from_prover(domain_separator + comm_labels.lookup_read_counts); witness_comms.lookup_read_tags = diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.test.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.test.cpp index aad537c721d..9daf1620fc3 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.test.cpp @@ -248,7 +248,7 @@ TEST_F(UltraHonkComposerTests, LookupFailure) auto& polynomials = instance->proving_key.polynomials; // Erroneously update the read counts/tags at an arbitrary index - // Note: updating only one or the other may not cause failure due to the relation algebra + // Note: updating only one or the other may not cause failure due to the design of the relation algebra polynomials.lookup_read_counts[25] = 1; polynomials.lookup_read_tags[25] = 1; From 0b8384844c75128c5b79a0abf1136c480671fc14 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Fri, 21 Jun 2024 17:03:56 +0000 Subject: [PATCH 39/42] add op count timer to new lookup relation --- .../cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp index 2d56a3e1dd6..41464d255f7 100644 --- a/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp @@ -167,6 +167,7 @@ template class LogDerivLookupRelationImpl { const Parameters& params, const FF& scaling_factor) { + BB_OP_COUNT_TIME_NAME("Lookup::accumulate"); using Accumulator = typename std::tuple_element_t<0, ContainerOverSubrelations>; using View = typename Accumulator::View; From 810a110d53228b4a7e19d0dc425d4d0b83ee652f Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Fri, 21 Jun 2024 17:29:31 +0000 Subject: [PATCH 40/42] revert lookups size change --- .../cpp/src/barretenberg/sumcheck/instance/prover_instance.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.cpp b/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.cpp index 350b9e414e4..2df2f34f158 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.cpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.cpp @@ -13,7 +13,7 @@ namespace bb { template size_t ProverInstance_::compute_dyadic_size(Circuit& circuit) { // minimum circuit size due to lookup argument - const size_t min_size_due_to_lookups = circuit.get_tables_size(); + const size_t min_size_due_to_lookups = circuit.get_tables_size() + circuit.get_lookups_size(); // minimum size of execution trace due to everything else size_t min_size_of_execution_trace = circuit.public_inputs.size() + circuit.num_gates; From 8c5fe0c609529cc5ecc7efeb5c231310f05f65a9 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Fri, 21 Jun 2024 21:18:27 +0000 Subject: [PATCH 41/42] circuit checker failure test --- .../ultra_circuit_builder.test.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/barretenberg/cpp/src/barretenberg/circuit_checker/ultra_circuit_builder.test.cpp b/barretenberg/cpp/src/barretenberg/circuit_checker/ultra_circuit_builder.test.cpp index 005a50ea156..5d1eec57741 100644 --- a/barretenberg/cpp/src/barretenberg/circuit_checker/ultra_circuit_builder.test.cpp +++ b/barretenberg/cpp/src/barretenberg/circuit_checker/ultra_circuit_builder.test.cpp @@ -1,6 +1,7 @@ #include "barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp" #include "barretenberg/circuit_checker/circuit_checker.hpp" #include "barretenberg/crypto/pedersen_commitment/pedersen.hpp" +#include "barretenberg/stdlib_circuit_builders/mock_circuits.hpp" #include "barretenberg/stdlib_circuit_builders/plookup_tables/fixed_base/fixed_base.hpp" #include @@ -104,6 +105,22 @@ TEST(ultra_circuit_constructor, create_gates_from_plookup_accumulators) EXPECT_EQ(result, true); } +TEST(ultra_circuit_constructor, bad_lookup_failure) +{ + UltraCircuitBuilder builder; + MockCircuits::add_lookup_gates(builder); + + // Erroneously set a non-zero wire value to zero in one of the lookup gates + for (auto& wire_3_witness_idx : builder.blocks.lookup.w_o()) { + if (wire_3_witness_idx != builder.zero_idx) { + wire_3_witness_idx = builder.zero_idx; + break; + } + } + + EXPECT_FALSE(CircuitChecker::check(builder)); +} + TEST(ultra_circuit_constructor, base_case) { UltraCircuitBuilder circuit_constructor = UltraCircuitBuilder(); From 0d4032d848fc3ceadb164cb1e8269460760c3776 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Mon, 24 Jun 2024 23:16:17 +0000 Subject: [PATCH 42/42] comments and cleanup based on review --- .../protogalaxy/protogalaxy.test.cpp | 2 +- .../relations/logderiv_lookup_relation.hpp | 22 ++++++-- .../verifier/ultra_recursive_verifier.cpp | 2 +- .../stdlib_circuit_builders/mega_flavor.hpp | 2 +- .../stdlib_circuit_builders/ultra_flavor.hpp | 8 +-- .../instance/prover_instance.test.cpp | 38 ------------- .../barretenberg/ultra_honk/oink_prover.cpp | 2 +- .../ultra_honk/relation_correctness.test.cpp | 4 +- .../barretenberg/ultra_honk/sumcheck.test.cpp | 2 +- ..._composer.test.cpp => ultra_honk.test.cpp} | 55 ++++++++++--------- 10 files changed, 56 insertions(+), 81 deletions(-) delete mode 100644 barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.test.cpp rename barretenberg/cpp/src/barretenberg/ultra_honk/{ultra_composer.test.cpp => ultra_honk.test.cpp} (95%) diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp index 08815605a34..da09210655f 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp @@ -136,7 +136,7 @@ template class ProtoGalaxyTests : public testing::Test { instance->relation_parameters.beta = FF::random_element(); instance->relation_parameters.gamma = FF::random_element(); - instance->proving_key.add_plookup_memory_records_to_wire_4(instance->relation_parameters.eta, + instance->proving_key.add_ram_rom_memory_records_to_wire_4(instance->relation_parameters.eta, instance->relation_parameters.eta_two, instance->relation_parameters.eta_three); instance->proving_key.compute_logderivative_inverses(instance->relation_parameters); diff --git a/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp index 41464d255f7..92078db8e85 100644 --- a/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp @@ -23,8 +23,8 @@ template class LogDerivLookupRelationImpl { LENGTH // log derivative lookup argument sub-relation }; - // WORKTODO: shouldnt first one be 2? Why do tests pass with 1? (Note: if setting to 2, both need to be 2 due to - // structure of relation algebra) + // TODO(https://github.com/AztecProtocol/barretenberg/issues/1036): Scrutinize these adjustment factors. Counting + // degrees suggests the first subrelation should require an adjustment of 2. static constexpr std::array TOTAL_LENGTH_ADJUSTMENTS{ 1, // inverse construction sub-relation 1 // log derivative lookup argument sub-relation @@ -38,10 +38,19 @@ template class LogDerivLookupRelationImpl { return in.q_lookup.is_zero() && in.lookup_read_counts.is_zero(); } - // Used to determine whether the polynomial of inverses must be computed at a given row + /** + * @brief Does the provided row contain data relevant to table lookups; Used to determine whether the polynomial of + * inverses must be computed at a given row + * @details In order to avoid unnecessary computation, the polynomial of inverses I is only computed for rows at + * which the lookup relation is "active". It is active if either (1) the present row contains a lookup gate (i.e. + * q_lookup == 1), or (2) the present row contains table data that has been looked up in this circuit + * (lookup_read_tags == 1, or equivalently, if the row in consideration has index i, the data in polynomials table_i + * has been utlized in the circuit). + * + */ template static bool operation_exists_at_row(const AllValues& row) { - // is lookup gate or row contains data that has been read + // is the row a lookup gate or does it contain table data that has been read at some point in this circuit return (row.q_lookup == 1) || (row.lookup_read_tags == 1); } @@ -113,7 +122,8 @@ template class LogDerivLookupRelationImpl { auto negative_column_3_step_size = View(in.q_c); // The wire values for lookup gates are accumulators structured in such a way that the differences w_i - - // step_size*w_i_shift result in values present in column i of a corresponding table. + // step_size*w_i_shift result in values present in column i of a corresponding table. See the documentation in + // method get_lookup_accumulators() in for a detailed explanation. auto derived_table_entry_1 = w_1 + gamma + negative_column_1_step_size * w_1_shift; auto derived_table_entry_2 = w_2 + negative_column_2_step_size * w_2_shift; auto derived_table_entry_3 = w_3 + negative_column_3_step_size * w_3_shift; @@ -186,7 +196,7 @@ template class LogDerivLookupRelationImpl { std::get<0>(accumulator) += (read_term * write_term * inverses - inverse_exists) * scaling_factor; // Deg 4 (6) // Establish validity of the read. Note: no scaling factor here since this constraint is 'linearly dependent, - // i.e. enforced across the entire trace, not on a per-row basis. Degree + // i.e. enforced across the entire trace, not on a per-row basis. // Degrees: 1 2 (3) 1 3 (4) std::get<1>(accumulator) += read_selector * read_inverse - read_counts * write_inverse; // Deg 4 (5) } diff --git a/barretenberg/cpp/src/barretenberg/stdlib/honk_recursion/verifier/ultra_recursive_verifier.cpp b/barretenberg/cpp/src/barretenberg/stdlib/honk_recursion/verifier/ultra_recursive_verifier.cpp index e1b08a436c7..f609464efec 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/honk_recursion/verifier/ultra_recursive_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/honk_recursion/verifier/ultra_recursive_verifier.cpp @@ -91,7 +91,7 @@ std::array UltraRecursiveVerifier_::ve transcript->template receive_from_prover(commitment_labels.return_data_read_counts); } - // Get eta challenges + // Get eta challenges; used in RAM/ROM memory records and log derivative lookup argument auto [eta, eta_two, eta_three] = transcript->template get_challenges("eta", "eta_two", "eta_three"); relation_parameters.eta = eta; relation_parameters.eta_two = eta_two; diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp index a8047946141..45467f78325 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp @@ -358,7 +358,7 @@ class MegaFlavor { * @tparam Flavor * @param eta challenge produced after commitment to first three wire polynomials */ - void add_plookup_memory_records_to_wire_4(const FF& eta, const FF& eta_two, const FF& eta_three) + void add_ram_rom_memory_records_to_wire_4(const FF& eta, const FF& eta_two, const FF& eta_three) { // The plookup memory record values are computed at the indicated indices as // w4 = w3 * eta^3 + w2 * eta^2 + w1 * eta + read_write_flag; diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp index 19958c14076..6ca68d7037e 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp @@ -286,7 +286,7 @@ class UltraFlavor { ProverPolynomials polynomials; // storage for all polynomials evaluated by the prover /** - * @brief Add plookup memory records to the fourth wire polynomial + * @brief Add RAM/ROM memory records to the fourth wire polynomial * * @details This operation must be performed after the first three wires have been * committed to, hence the dependence on the `eta` challenge. @@ -294,11 +294,11 @@ class UltraFlavor { * @tparam Flavor * @param eta challenge produced after commitment to first three wire polynomials */ - void add_plookup_memory_records_to_wire_4(const FF& eta, const FF& eta_two, const FF& eta_three) + void add_ram_rom_memory_records_to_wire_4(const FF& eta, const FF& eta_two, const FF& eta_three) { - // The plookup memory record values are computed at the indicated indices as + // The memory record values are computed at the indicated indices as // w4 = w3 * eta^3 + w2 * eta^2 + w1 * eta + read_write_flag; - // (See plookup_auxiliary_widget.hpp for details) + // (See the Auxiliary relation for details) auto wires = polynomials.get_wires(); // Compute read record values diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.test.cpp b/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.test.cpp deleted file mode 100644 index 7b2c3738d76..00000000000 --- a/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.test.cpp +++ /dev/null @@ -1,38 +0,0 @@ - -#include "prover_instance.hpp" -#include "barretenberg/ecc/curves/bn254/bn254.hpp" -#include "barretenberg/plonk_honk_shared/library/grand_product_library.hpp" -#include "barretenberg/polynomials/polynomial.hpp" -#include "barretenberg/srs/factories/file_crs_factory.hpp" -#include -using namespace bb; - -template class InstanceTests : public testing::Test { - using FF = typename Flavor::FF; - using Polynomial = bb::Polynomial; - using Builder = typename Flavor::CircuitBuilder; - - public: - /** - * @brief Get a random polynomial - * - * @param size - * @return Polynomial - */ - static constexpr Polynomial get_random_polynomial(size_t size) - { - Polynomial random_polynomial{ size }; - for (auto& coeff : random_polynomial) { - coeff = FF::random_element(); - } - return random_polynomial; - } - - static void populate_span(auto& polynomial_view, const auto& polynomial) - { - ASSERT(polynomial_view.size() <= polynomial.size()); - for (size_t idx = 0; idx < polynomial.size(); idx++) { - polynomial_view[idx] = polynomial[idx]; - } - }; -}; \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp index 4e21db889ae..6626b48623f 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp @@ -117,7 +117,7 @@ template void OinkProver::execute_sorted_list_acc relation_parameters.eta_two = eta_two; relation_parameters.eta_three = eta_three; - proving_key.add_plookup_memory_records_to_wire_4( + proving_key.add_ram_rom_memory_records_to_wire_4( relation_parameters.eta, relation_parameters.eta_two, relation_parameters.eta_three); // Commit to lookup argument polynomials and the finalized (i.e. with memory records) fourth wire polynomial 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 3e50eeca4f4..cedd1fd4bb2 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/relation_correctness.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/relation_correctness.test.cpp @@ -272,7 +272,7 @@ TEST_F(UltraRelationCorrectnessTests, Ultra) instance->relation_parameters.beta = FF::random_element(); instance->relation_parameters.gamma = FF::random_element(); - instance->proving_key.add_plookup_memory_records_to_wire_4(instance->relation_parameters.eta, + instance->proving_key.add_ram_rom_memory_records_to_wire_4(instance->relation_parameters.eta, instance->relation_parameters.eta_two, instance->relation_parameters.eta_three); instance->proving_key.compute_logderivative_inverses(instance->relation_parameters); @@ -325,7 +325,7 @@ TEST_F(UltraRelationCorrectnessTests, Mega) instance->relation_parameters.beta = FF::random_element(); instance->relation_parameters.gamma = FF::random_element(); - instance->proving_key.add_plookup_memory_records_to_wire_4(instance->relation_parameters.eta, + instance->proving_key.add_ram_rom_memory_records_to_wire_4(instance->relation_parameters.eta, instance->relation_parameters.eta_two, instance->relation_parameters.eta_three); instance->proving_key.compute_logderivative_inverses(instance->relation_parameters); diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/sumcheck.test.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/sumcheck.test.cpp index 6c0b24af539..665538278c1 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/sumcheck.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/sumcheck.test.cpp @@ -156,7 +156,7 @@ TEST_F(SumcheckTestsRealCircuit, Ultra) instance->relation_parameters.beta = FF::random_element(); instance->relation_parameters.gamma = FF::random_element(); - instance->proving_key.add_plookup_memory_records_to_wire_4(instance->relation_parameters.eta, + instance->proving_key.add_ram_rom_memory_records_to_wire_4(instance->relation_parameters.eta, instance->relation_parameters.eta_two, instance->relation_parameters.eta_three); instance->proving_key.compute_logderivative_inverses(instance->relation_parameters); diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.test.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_honk.test.cpp similarity index 95% rename from barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.test.cpp rename to barretenberg/cpp/src/barretenberg/ultra_honk/ultra_honk.test.cpp index 9daf1620fc3..31d0423fd99 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_composer.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_honk.test.cpp @@ -48,7 +48,7 @@ void ensure_non_zero(auto& polynomial) ASSERT_TRUE(has_non_zero_coefficient); } -class UltraHonkComposerTests : public ::testing::Test { +class UltraHonkTests : public ::testing::Test { protected: static void SetUpTestSuite() { bb::srs::init_crs_factory("../srs_db/ignition"); } }; @@ -60,7 +60,7 @@ class UltraHonkComposerTests : public ::testing::Test { * to achieve non-zero polynomials * */ -TEST_F(UltraHonkComposerTests, ANonZeroPolynomialIsAGoodPolynomial) +TEST_F(UltraHonkTests, ANonZeroPolynomialIsAGoodPolynomial) { auto circuit_builder = UltraCircuitBuilder(); @@ -86,7 +86,7 @@ TEST_F(UltraHonkComposerTests, ANonZeroPolynomialIsAGoodPolynomial) * @brief Test proof construction/verification for a structured execution trace * */ -TEST_F(UltraHonkComposerTests, StructuredTrace) +TEST_F(UltraHonkTests, StructuredTrace) { auto builder = UltraCircuitBuilder(); size_t num_gates = 3; @@ -109,7 +109,7 @@ TEST_F(UltraHonkComposerTests, StructuredTrace) * @brief Test simple circuit with public inputs * */ -TEST_F(UltraHonkComposerTests, PublicInputs) +TEST_F(UltraHonkTests, PublicInputs) { auto builder = UltraCircuitBuilder(); size_t num_gates = 10; @@ -120,7 +120,7 @@ TEST_F(UltraHonkComposerTests, PublicInputs) prove_and_verify(builder, /*expected_result=*/true); } -TEST_F(UltraHonkComposerTests, XorConstraint) +TEST_F(UltraHonkTests, XorConstraint) { auto circuit_builder = UltraCircuitBuilder(); @@ -147,7 +147,7 @@ TEST_F(UltraHonkComposerTests, XorConstraint) prove_and_verify(circuit_builder, /*expected_result=*/true); } -TEST_F(UltraHonkComposerTests, create_gates_from_plookup_accumulators) +TEST_F(UltraHonkTests, create_gates_from_plookup_accumulators) { auto circuit_builder = UltraCircuitBuilder(); @@ -211,7 +211,7 @@ TEST_F(UltraHonkComposerTests, create_gates_from_plookup_accumulators) * @brief Test various failure modes for the lookup relation via bad input polynomials * */ -TEST_F(UltraHonkComposerTests, LookupFailure) +TEST_F(UltraHonkTests, LookupFailure) { // Construct a circuit with lookup and arithmetic gates auto construct_circuit_with_lookups = []() { @@ -248,7 +248,10 @@ TEST_F(UltraHonkComposerTests, LookupFailure) auto& polynomials = instance->proving_key.polynomials; // Erroneously update the read counts/tags at an arbitrary index - // Note: updating only one or the other may not cause failure due to the design of the relation algebra + // Note: updating only one or the other may not cause failure due to the design of the relation algebra. For + // example, the inverse is only computed if read tags is non-zero, otherwise the inverse at the row in question + // will be zero. So if read counts is incremented at some arbitrary index but read tags is not, the inverse will + // be 0 and the erroneous read_counts value will get multiplied by 0 in the relation. This is expected behavior. polynomials.lookup_read_counts[25] = 1; polynomials.lookup_read_tags[25] = 1; @@ -288,7 +291,7 @@ TEST_F(UltraHonkComposerTests, LookupFailure) } } -TEST_F(UltraHonkComposerTests, test_no_lookup_proof) +TEST_F(UltraHonkTests, test_no_lookup_proof) { auto circuit_builder = UltraCircuitBuilder(); @@ -310,7 +313,7 @@ TEST_F(UltraHonkComposerTests, test_no_lookup_proof) prove_and_verify(circuit_builder, /*expected_result=*/true); } -TEST_F(UltraHonkComposerTests, test_elliptic_gate) +TEST_F(UltraHonkTests, test_elliptic_gate) { typedef grumpkin::g1::affine_element affine_element; typedef grumpkin::g1::element element; @@ -343,7 +346,7 @@ TEST_F(UltraHonkComposerTests, test_elliptic_gate) prove_and_verify(circuit_builder, /*expected_result=*/true); } -TEST_F(UltraHonkComposerTests, non_trivial_tag_permutation) +TEST_F(UltraHonkTests, non_trivial_tag_permutation) { auto circuit_builder = UltraCircuitBuilder(); fr a = fr::random_element(); @@ -370,7 +373,7 @@ TEST_F(UltraHonkComposerTests, non_trivial_tag_permutation) prove_and_verify(circuit_builder, /*expected_result=*/true); } -TEST_F(UltraHonkComposerTests, non_trivial_tag_permutation_and_cycles) +TEST_F(UltraHonkTests, non_trivial_tag_permutation_and_cycles) { auto circuit_builder = UltraCircuitBuilder(); fr a = fr::random_element(); @@ -407,7 +410,7 @@ TEST_F(UltraHonkComposerTests, non_trivial_tag_permutation_and_cycles) prove_and_verify(circuit_builder, /*expected_result=*/true); } -TEST_F(UltraHonkComposerTests, bad_tag_permutation) +TEST_F(UltraHonkTests, bad_tag_permutation) { { auto circuit_builder = UltraCircuitBuilder(); @@ -450,7 +453,7 @@ TEST_F(UltraHonkComposerTests, bad_tag_permutation) } } -TEST_F(UltraHonkComposerTests, sort_widget) +TEST_F(UltraHonkTests, sort_widget) { auto circuit_builder = UltraCircuitBuilder(); fr a = fr::one(); @@ -467,7 +470,7 @@ TEST_F(UltraHonkComposerTests, sort_widget) prove_and_verify(circuit_builder, /*expected_result=*/true); } -TEST_F(UltraHonkComposerTests, sort_with_edges_gate) +TEST_F(UltraHonkTests, sort_with_edges_gate) { fr a = fr::one(); fr b = fr(2); @@ -557,7 +560,7 @@ TEST_F(UltraHonkComposerTests, sort_with_edges_gate) } } -TEST_F(UltraHonkComposerTests, range_constraint) +TEST_F(UltraHonkTests, range_constraint) { { auto circuit_builder = UltraCircuitBuilder(); @@ -626,7 +629,7 @@ TEST_F(UltraHonkComposerTests, range_constraint) } } -TEST_F(UltraHonkComposerTests, range_with_gates) +TEST_F(UltraHonkTests, range_with_gates) { auto circuit_builder = UltraCircuitBuilder(); auto idx = add_variables(circuit_builder, { 1, 2, 3, 4, 5, 6, 7, 8 }); @@ -644,7 +647,7 @@ TEST_F(UltraHonkComposerTests, range_with_gates) prove_and_verify(circuit_builder, /*expected_result=*/true); } -TEST_F(UltraHonkComposerTests, range_with_gates_where_range_is_not_a_power_of_two) +TEST_F(UltraHonkTests, range_with_gates_where_range_is_not_a_power_of_two) { auto circuit_builder = UltraCircuitBuilder(); auto idx = add_variables(circuit_builder, { 1, 2, 3, 4, 5, 6, 7, 8 }); @@ -662,7 +665,7 @@ TEST_F(UltraHonkComposerTests, range_with_gates_where_range_is_not_a_power_of_tw prove_and_verify(circuit_builder, /*expected_result=*/true); } -TEST_F(UltraHonkComposerTests, sort_widget_complex) +TEST_F(UltraHonkTests, sort_widget_complex) { { @@ -688,7 +691,7 @@ TEST_F(UltraHonkComposerTests, sort_widget_complex) } } -TEST_F(UltraHonkComposerTests, sort_widget_neg) +TEST_F(UltraHonkTests, sort_widget_neg) { auto circuit_builder = UltraCircuitBuilder(); fr a = fr::one(); @@ -705,7 +708,7 @@ TEST_F(UltraHonkComposerTests, sort_widget_neg) prove_and_verify(circuit_builder, /*expected_result=*/false); } -TEST_F(UltraHonkComposerTests, composed_range_constraint) +TEST_F(UltraHonkTests, composed_range_constraint) { auto circuit_builder = UltraCircuitBuilder(); auto c = fr::random_element(); @@ -718,7 +721,7 @@ TEST_F(UltraHonkComposerTests, composed_range_constraint) prove_and_verify(circuit_builder, /*expected_result=*/true); } -TEST_F(UltraHonkComposerTests, non_native_field_multiplication) +TEST_F(UltraHonkTests, non_native_field_multiplication) { using fq = fq; auto circuit_builder = UltraCircuitBuilder(); @@ -774,7 +777,7 @@ TEST_F(UltraHonkComposerTests, non_native_field_multiplication) prove_and_verify(circuit_builder, /*expected_result=*/true); } -TEST_F(UltraHonkComposerTests, rom) +TEST_F(UltraHonkTests, rom) { auto circuit_builder = UltraCircuitBuilder(); @@ -815,7 +818,7 @@ TEST_F(UltraHonkComposerTests, rom) prove_and_verify(circuit_builder, /*expected_result=*/true); } -TEST_F(UltraHonkComposerTests, ram) +TEST_F(UltraHonkTests, ram) { auto circuit_builder = UltraCircuitBuilder(); @@ -878,7 +881,7 @@ TEST_F(UltraHonkComposerTests, ram) prove_and_verify(circuit_builder, /*expected_result=*/true); } -TEST_F(UltraHonkComposerTests, range_checks_on_duplicates) +TEST_F(UltraHonkTests, range_checks_on_duplicates) { auto circuit_builder = UltraCircuitBuilder(); @@ -917,7 +920,7 @@ TEST_F(UltraHonkComposerTests, range_checks_on_duplicates) // range constrained, do not break the set equivalence checks because of indices mismatch. // 2^14 is DEFAULT_PLOOKUP_RANGE_BITNUM i.e. the maximum size before a variable gets sliced // before range constraints are applied to it. -TEST_F(UltraHonkComposerTests, range_constraint_small_variable) +TEST_F(UltraHonkTests, range_constraint_small_variable) { auto circuit_builder = UltraCircuitBuilder();