Skip to content

Commit d27d98d

Browse files
committed
fix: resolve _GLIBCXX_DEBUG assertion failures in debug build
Three latent bugs exposed by _GLIBCXX_DEBUG bounds checking: 1. batched_affine_addition.cpp: subspan(total_num_pairs, 2*total_num_pairs) requested 2*total_num_pairs elements but only total_num_pairs are used. Fixed count argument to total_num_pairs. 2. scalar_multiplication.hpp: MSMData::from_work_unit accessed empty vector via &v[0] when all scalars are zero. Changed to v.data() + offset. 3. gemini_impl.hpp: compute_fold_polynomials accessed multilinear_challenge out of bounds when polynomial degree > 2^(challenge size). Added bounds check to fall back to u=0 for rounds beyond the challenge array.
1 parent 4598628 commit d27d98d

3 files changed

Lines changed: 6 additions & 5 deletions

File tree

barretenberg/cpp/src/barretenberg/commitment_schemes/gemini/gemini_impl.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,9 @@ std::vector<typename GeminiProver_<Curve>::Polynomial> GeminiProver_<Curve>::com
137137
// size of the previous polynomial/2
138138
const size_t n_l = 1 << (log_n - l - 1);
139139

140-
// Opening point is the same for all
141-
const Fr u_l = multilinear_challenge[l];
140+
// Use the challenge value when available; otherwise fold with u=0 (take even part only).
141+
// This handles the edge case where the polynomial degree exceeds 2^virtual_log_n.
142+
const Fr u_l = (l < virtual_log_n) ? multilinear_challenge[l] : Fr(0);
142143

143144
// A_l_fold = Aₗ₊₁(X) = (1-uₗ)⋅even(Aₗ)(X) + uₗ⋅odd(Aₗ)(X)
144145
auto A_l_fold = fold_polynomials[l].data();
@@ -161,7 +162,7 @@ std::vector<typename GeminiProver_<Curve>::Polynomial> GeminiProver_<Curve>::com
161162
// value at every point, (f(X) - f(x)) / (X - x) = 0, so these contribute nothing to the Shplonk quotient Q(X).
162163
// On the verifier side, padding_indicator_array zeros their contributions independently.
163164
const auto& last = fold_polynomials.back();
164-
const Fr u_last = multilinear_challenge[log_n - 1];
165+
const Fr u_last = (log_n - 1 < virtual_log_n) ? multilinear_challenge[log_n - 1] : Fr(0);
165166
const Fr final_eval = last.at(0) + u_last * (last.at(1) - last.at(0));
166167
Polynomial const_fold(1);
167168
const_fold.at(0) = final_eval;

barretenberg/cpp/src/barretenberg/ecc/batched_affine_addition/batched_affine_addition.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ std::span<typename BatchedAffineAddition<Curve>::Fq> BatchedAffineAddition<
143143
// Define scratch space for batched inverse computations and eventual storage of denominators
144144
BB_ASSERT_GTE(add_sequences.scratch_space.size(), 2 * total_num_pairs);
145145
std::span<Fq> denominators = add_sequences.scratch_space.subspan(0, total_num_pairs);
146-
std::span<Fq> differences = add_sequences.scratch_space.subspan(total_num_pairs, 2 * total_num_pairs);
146+
std::span<Fq> differences = add_sequences.scratch_space.subspan(total_num_pairs, total_num_pairs);
147147

148148
// Compute and store successive products of differences (x_2 - x_1)
149149
Fq accumulator = 1;

barretenberg/cpp/src/barretenberg/ecc/scalar_multiplication/scalar_multiplication.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ template <typename Curve> class MSM {
122122
.scalars = all_scalars[work_unit.batch_msm_index],
123123
.points = all_points[work_unit.batch_msm_index],
124124
.scalar_indices =
125-
std::span<const uint32_t>{ &all_indices[work_unit.batch_msm_index][work_unit.start_index],
125+
std::span<const uint32_t>{ all_indices[work_unit.batch_msm_index].data() + work_unit.start_index,
126126
work_unit.size },
127127
.point_schedule = point_schedule_buffer,
128128
};

0 commit comments

Comments
 (0)