Skip to content

Commit 46d1d71

Browse files
committed
fix: guard debug-only pairing point validation and logderivative span OOB
Two fixes for the nightly barretenberg debug build: 1. PairingPoints: Add on_curve() checks before constructing native PairingPoints in debug blocks. Zero-initialized witness values during VK generation are not valid curve points, causing reduced_ate_pairing_batch_precomputed to abort. 2. logderivative_library: Clamp batch_invert range to the polynomial's actual (non-virtual) data size. When multithreaded chunks exceed the polynomial's real size, _GLIBCXX_DEBUG span bounds checking catches the OOB access.
1 parent cf1a239 commit 46d1d71

2 files changed

Lines changed: 28 additions & 9 deletions

File tree

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) {

barretenberg/cpp/src/barretenberg/stdlib/primitives/pairing_points.hpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,14 @@ template <typename Curve> struct PairingPoints {
5454
}
5555

5656
#ifndef NDEBUG
57-
bb::PairingPoints<typename Curve::NativeCurve> native_pp(P0().get_value(), P1().get_value());
58-
info("Are Pairing Points with tag ", tag_index, " valid? ", native_pp.check() ? "true" : "false");
57+
auto p0_val = P0().get_value();
58+
auto p1_val = P1().get_value();
59+
if (p0_val.on_curve() && p1_val.on_curve()) {
60+
bb::PairingPoints<typename Curve::NativeCurve> native_pp(p0_val, p1_val);
61+
info("Are Pairing Points with tag ", tag_index, " valid? ", native_pp.check() ? "true" : "false");
62+
} else {
63+
info("Are Pairing Points with tag ", tag_index, " valid? false (point not on curve)");
64+
}
5965
#endif
6066
}
6167

@@ -210,8 +216,15 @@ template <typename Curve> struct PairingPoints {
210216
}
211217

212218
#ifndef NDEBUG
213-
bb::PairingPoints<typename Curve::NativeCurve> native_pp(P0().get_value(), P1().get_value());
214-
info("Are aggregated Pairing Points with tag ", tag_index, " valid? ", native_pp.check() ? "true" : "false");
219+
auto p0_val = P0().get_value();
220+
auto p1_val = P1().get_value();
221+
if (p0_val.on_curve() && p1_val.on_curve()) {
222+
bb::PairingPoints<typename Curve::NativeCurve> native_pp(p0_val, p1_val);
223+
info(
224+
"Are aggregated Pairing Points with tag ", tag_index, " valid? ", native_pp.check() ? "true" : "false");
225+
} else {
226+
info("Are aggregated Pairing Points with tag ", tag_index, " valid? false (point not on curve)");
227+
}
215228
#endif
216229
}
217230

0 commit comments

Comments
 (0)