Skip to content

chore: enable _GLIBCXX_DEBUG in debug build presets#22218

Merged
ludamad merged 2 commits into
merge-train/barretenbergfrom
claudebox/barretenberg-debug-config
Apr 1, 2026
Merged

chore: enable _GLIBCXX_DEBUG in debug build presets#22218
ludamad merged 2 commits into
merge-train/barretenbergfrom
claudebox/barretenberg-debug-config

Conversation

@AztecBot

@AztecBot AztecBot commented Apr 1, 2026

Copy link
Copy Markdown
Collaborator

Summary

Enables libstdc++ debug mode (_GLIBCXX_DEBUG) in the debug and debug-fast CMake presets.

Motivation

From the BB audit: _GLIBCXX_DEBUG catches logical container UB that ASAN misses. For example, operator[] on a reserve()d-but-empty vector is UB that ASAN cannot detect (because reserve() allocates the backing memory — the UB is logical, not a heap overflow). With _GLIBCXX_DEBUG, libstdc++ immediately aborts with a clear diagnostic:

attempt to subscript container with out-of-bounds index 0, but container only holds 0 elements

Changes

  • Added -D_GLIBCXX_DEBUG to CXXFLAGS in the debug preset
  • Added -D_GLIBCXX_DEBUG to CXXFLAGS in the debug-fast preset
  • ASAN presets inherit from debug, so they also benefit

ClaudeBox log: https://claudebox.work/s/638c6b632d5cd8af?run=2

Enable libstdc++ debug mode in the debug and debug-fast CMake presets.
This catches logical container UB (e.g. operator[] on a reserved-but-empty
vector) that ASAN cannot detect because the backing memory is allocated.
@AztecBot AztecBot added ci-draft Run CI on draft PRs. claudebox Owned by claudebox. it can push to this PR. labels Apr 1, 2026
@ludamad ludamad marked this pull request as ready for review April 1, 2026 12:24
@ludamad ludamad enabled auto-merge (squash) April 1, 2026 12:24
@ludamad ludamad merged commit aca4506 into merge-train/barretenberg Apr 1, 2026
12 checks passed
@ludamad ludamad deleted the claudebox/barretenberg-debug-config branch April 1, 2026 14:16
AztecBot added a commit that referenced this pull request Apr 1, 2026
…X_DEBUG ASAN build

hash_to_curve and ECCVMHardcodedVKAndHash::get_all() use std::vector
which is not a literal type under _GLIBCXX_DEBUG (added by PR #22218).
These functions are never evaluated at compile time, so constexpr is
unnecessary.
AztecBot added a commit that referenced this pull request Apr 1, 2026
…EBUG compat

hash_to_curve and ECCVMHardcodedVKAndHash::get_all() use std::vector
which is not a literal type under _GLIBCXX_DEBUG (added by PR #22218).
These functions are never evaluated at compile time, so constexpr is
unnecessary.
johnathan79717 pushed a commit that referenced this pull request Apr 2, 2026
…EBUG compat (#22239)

## Summary
Fixes ASAN and debug build failures introduced by PR #22218 which added
`_GLIBCXX_DEBUG` to debug/ASAN build presets.

Under `_GLIBCXX_DEBUG`, `std::vector` is not a literal type (the debug
wrapper lacks constexpr constructors), causing compilation errors in any
`constexpr` function that uses `std::vector`.

Two functions affected:
- `affine_element::hash_to_curve()` — uses `std::vector<uint8_t>`
internally
- `ECCVMHardcodedVKAndHash::get_all()` — returns
`std::vector<Commitment>`

Neither function is ever evaluated at compile time, so removing
`constexpr` is safe.

## Test plan
- [x] ASAN preset (`asan-fast`) builds clean from scratch (1103/1103
targets, 0 failures)
- [x] Debug preset builds clean from scratch (1111/1111 targets, 0
failures)
- [x] Format check passes
AztecBot added a commit that referenced this pull request Apr 2, 2026
Two write() overloads in serialize.hpp used `&*buf.end()` to get a
pointer to the newly-appended region after resize(). Under
_GLIBCXX_DEBUG (enabled in asan-fast and debug presets since #22218),
dereferencing end() triggers a debug assertion abort.

Replace with `buf.data() + buf.size()` which achieves the same
pointer arithmetic without dereferencing any iterator.
AztecBot added a commit that referenced this pull request Apr 2, 2026
… pointer arithmetic

Two write() overloads in serialize.hpp used `&*buf.end()` to get a pointer
to newly appended space. Dereferencing end() is undefined behavior, now
caught by _GLIBCXX_DEBUG (enabled in asan-fast builds via #22218).

Replace with `buf.data() + buf.size()` which is well-defined.
johnathan79717 pushed a commit that referenced this pull request Apr 2, 2026
…pp (#22261)

## Summary
Two `write()` overloads in `serialize.hpp` used `&*buf.end()` to obtain
a raw pointer into the newly-resized region. Under `_GLIBCXX_DEBUG`
(enabled in asan-fast and debug presets since #22218), dereferencing
`end()` is a debug assertion abort — even though the subtracted pointer
was in-bounds.

Replaced with `buf.data() + buf.size()` which yields the same pointer
without touching any iterator.

## Failure
`ChonkTests.Basic` in the asan-fast build aborted with:
```
Error: attempt to dereference a past-the-end iterator.
```

## Fix
- `serialize.hpp:166`: `&*buf.end() - sizeof(value)` → `buf.data() +
buf.size() - sizeof(value)`
- `serialize.hpp:251`: `&*buf.end() - N` → `buf.data() + buf.size() - N`

## Test plan
- [x] `ChonkTests.Basic` passes with debug-fast preset (`_GLIBCXX_DEBUG`
enabled)

ClaudeBox log: https://claudebox.work/s/4aef0cbe07a366e4?run=1
iakovenkos pushed a commit that referenced this pull request Apr 2, 2026
## Summary
Two `write()` overloads in `serialize.hpp` used `&*buf.end()` to get a
pointer to newly appended space. Dereferencing `end()` is UB, now caught
by `_GLIBCXX_DEBUG` (enabled in asan-fast builds via #22218). This
caused `ChonkTests.Basic` to abort in CI.

## Fix
Replace `&*buf.end() - offset` with `buf.data() + buf.size() - offset`
(well-defined pointer arithmetic).

## Verification
- `ChonkTests.Basic` under asan-fast: PASSED
- Full `barretenberg/cpp/bootstrap.sh ci`: All 6148 tests passed

Detailed analysis:
https://gist.github.com/AztecBot/76c4c49c772843199db95099062ffeb3"

ClaudeBox log: https://claudebox.work/s/1aa27334b5d24bba?run=1
github-merge-queue Bot pushed a commit that referenced this pull request Apr 2, 2026
BEGIN_COMMIT_OVERRIDE
fix: verify accumulated pairing points in native ChonkVerifier (#22224)
chore: enable _GLIBCXX_DEBUG in debug build presets (#22218)
feat: add --memory_profile_out flag for Chonk memory profiling (#22145)
fix: disable max capacity test in debug + tiny gate separator
improvements (#22215)
fix: WASM build for memory_profile.cpp (#22231)
fix: translator audit fixes (#22242)
fix: remove constexpr from functions using std::vector for
_GLIBCXX_DEBUG compat (#22239)
fix: pippenger edge case (#22256)
fix: avoid dereferencing past-the-end vector iterators in serialize.hpp
(#22261)
chore: crypto primitives external audit response 0 (#22263)
feat: switch memory profiling from peak RSS to live heap usage (#22266)
fix: replace UB end-iterator dereference in serialize.hpp (#22262)
fix: catch exceptions in ChonkBatchVerifier::batch_check (#22270)
END_COMMIT_OVERRIDE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-draft Run CI on draft PRs. claudebox Owned by claudebox. it can push to this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants