diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/logderivative_library.hpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/logderivative_library.hpp index 9e124684c3e..4790791bbc9 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/logderivative_library.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/logderivative_library.hpp @@ -34,6 +34,7 @@ void compute_logderivative_inverse(Polynomials& polynomials, auto& relation_para auto& inverse_polynomial = lookup_relation.template get_inverse_polynomial(polynomials); for (size_t i = 0; i < circuit_size; ++i) { + // TODO(https://github.com/AztecProtocol/barretenberg/issues/940): avoid get_row if possible. auto row = polynomials.get_row(i); bool has_inverse = lookup_relation.operation_exists_at_row(row); if (!has_inverse) { diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp index 34dd0ff6cad..470d8f110b5 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp @@ -155,6 +155,7 @@ template class ProtoGalaxyProver_ { run_loop_in_parallel(instance_size, [&](size_t start_row, size_t end_row) { auto thread_accumulator = FF(0); for (size_t row = start_row; row < end_row; row++) { + // TODO(https://github.com/AztecProtocol/barretenberg/issues/940): avoid get_row if possible. auto row_evaluations = instance_polynomials.get_row(row); RelationEvaluations relation_evaluations; Utils::zero_elements(relation_evaluations); diff --git a/barretenberg/cpp/src/barretenberg/relations/databus_lookup_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/databus_lookup_relation.hpp index d919738a928..7a68d156b38 100644 --- a/barretenberg/cpp/src/barretenberg/relations/databus_lookup_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/databus_lookup_relation.hpp @@ -177,7 +177,8 @@ template class DatabusLookupRelationImpl { * @brief Construct the polynomial I whose components are the inverse of the product of the read and write terms * @details If the denominators of log derivative lookup relation are read_term and write_term, then I_i = * (read_term_i*write_term_i)^{-1}. - * @note Importantly, I_i = 0 for rows i at which there is no read or write. + * @note Importantly, I_i = 0 for rows i at which there is no read or write, so the cost of this method is + * proportional to the actual databus usage. * */ template @@ -186,11 +187,22 @@ template class DatabusLookupRelationImpl { const size_t circuit_size) { auto& inverse_polynomial = BusData::inverses(polynomials); - // Compute the product of the read and write terms for each row + bool is_read = false; + bool nonzero_read_count = false; for (size_t i = 0; i < circuit_size; ++i) { - auto row = polynomials.get_row(i); + // Determine if the present row contains a databus operation + auto& q_busread = polynomials.q_busread[i]; + if constexpr (bus_idx == 0) { // calldata + is_read = q_busread == 1 && polynomials.q_l[i] == 1; + nonzero_read_count = polynomials.calldata_read_counts[i] > 0; + } + if constexpr (bus_idx == 1) { // return data + is_read = q_busread == 1 && polynomials.q_r[i] == 1; + nonzero_read_count = polynomials.return_data_read_counts[i] > 0; + } // We only compute the inverse if this row contains a read gate or data that has been read - if (operation_exists_at_row(row)) { + if (is_read || nonzero_read_count) { + auto row = polynomials.get_row(i); // Note: this is a copy. use sparingly! inverse_polynomial[i] = compute_read_term(row, relation_parameters) * compute_write_term(row, relation_parameters); }