Skip to content

Commit 5f080e9

Browse files
authored
fix: clamp logderivative inverse range to fix nightly debug build OOB (#22312)
## Summary Fixes nightly barretenberg debug build which crashes with SIGABRT (exit code 134) in test `AvmRecursiveTests.TwoLayerAvmRecursionFailsWithWrongPIs`. **Root cause:** In `compute_logderivative_inverse()`, the multi-threaded path splits work by `circuit_size`, but `inverse_polynomial.coeffs()` only covers the actual (non-virtual) data. When a thread chunk's `start` exceeds the polynomial's actual size, `coeffs()[start]` is out of bounds — caught by `_GLIBCXX_DEBUG`'s span bounds checking in the debug build preset. **Fix:** Clamp `start`/`end` to the polynomial's actual data range before `batch_invert`. Virtual zero elements need no inversion. Note: The `batch_invert` reserve→resize fix from the original PR #22312 is no longer needed as it was already applied on `next`. PR #22314 can be closed as duplicate.
2 parents 11028cf + fc319eb commit 5f080e9

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)