Skip to content

Commit fc319eb

Browse files
committed
fix: clamp logderivative inverse range to fix nightly debug build OOB
In compute_logderivative_inverse(), the multithreaded path partitions work by circuit_size but inverse_polynomial.coeffs() can be smaller than circuit_size (virtual zero elements). When a thread chunk's start exceeds the polynomial's actual data size, coeffs()[start] is out of bounds -- caught by _GLIBCXX_DEBUG's span bounds checking in the debug build. Fix: clamp start/end to the polynomial's actual data range before calling batch_invert. Virtual zero elements need no inversion.
1 parent 9a72466 commit fc319eb

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

barretenberg/cpp/src/barretenberg/honk/proof_system/logderivative_library.hpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,17 @@ void compute_logderivative_inverse(Polynomials& polynomials, auto& relation_para
5959
});
6060
inverse_polynomial.at(i) = denominator;
6161
}
62-
FF* ffstart = &inverse_polynomial.coeffs()[start];
63-
std::span<FF> to_invert(ffstart, end - start);
64-
// Compute inverse polynomial I in place by inverting the product at each row
65-
// Note: zeroes are ignored as they are not used anyway
66-
FF::batch_invert(to_invert);
62+
// Clamp to the polynomial's actual (non-virtual) data range; virtual zero elements need no inversion.
63+
const size_t actual_size = inverse_polynomial.size();
64+
const size_t clamped_start = std::min(start, actual_size);
65+
const size_t clamped_end = std::min(end, actual_size);
66+
if (clamped_start < clamped_end) {
67+
FF* ffstart = &inverse_polynomial.coeffs()[clamped_start];
68+
std::span<FF> to_invert(ffstart, clamped_end - clamped_start);
69+
// Compute inverse polynomial I in place by inverting the product at each row
70+
// Note: zeroes are ignored as they are not used anyway
71+
FF::batch_invert(to_invert);
72+
}
6773
};
6874
if constexpr (UseMultithreading) {
6975
parallel_for([&](const ThreadChunk& chunk) {

0 commit comments

Comments
 (0)