Commit fa17227
committed
fix(bb): size Pippenger MSM arena for the non-GLV mid-band
## Problem
UltraHonk `bb prove` intermittently aborts in CI with:
```
libc++abi: terminating due to uncaught exception of type std::runtime_error:
Assertion failed: (aligned_local + bytes <= bound)
Left : 4123456
Right : 3699643
```
The assertion is `MsmArena::bump_alloc`'s `BB_ASSERT_LTE(aligned_local + bytes, bound)` in `scalar_multiplication_fast.cpp`. It is **not** OOM — the per-MSM scratch arena was sized smaller than the live allocator consumes.
## Root cause
`compute_arena_bytes_for_msm` sizes the arena from the conservative full-bit schedule (`NUM_BITS = FULL_NUM_BITS = 254` for non-GLV). The live path (`pippenger_round_parallel`) then shrinks the budget to `effective_num_bits` = the observed max scalar MSB, which can make `choose_window_bits` pick a *smaller* `window_bits` ⇒ *more* windows ⇒ a larger Zone S than the full-bit pre-size.
The sizer already has a defensive sweep that takes the max arena footprint across every bit budget, but it was gated `if (use_glv || n_input >= 2^17)`. That left the **non-GLV mid-band** (`GLV_SMALL_N_THRESHOLD < n_input < 2^17`, i.e. `8192 < n < 131072` natively) sized for the full-bit schedule only. `simple_shield`'s commitment MSM is ~28,696 points — non-GLV, squarely in that gap — so a witness whose scalars drive a smaller `effective_num_bits` overflows the arena.
It's intermittent because it needs both a runner core-count that yields the heavier schedule (this run reported 8 threads) and witness data whose max scalar MSB lands in the trigger band (~224–250). Both vary per run/PR, so it isn't tied to any particular PR.
## Fix
Make the defensive bit-budget sweep unconditional. `use_glv || n_input > GLV_SMALL_N_THRESHOLD` is true for every MSM that reaches this point, so the sweep now covers GLV and all non-GLV sizes. It only ever grows the arena when a shrunk-bit layout genuinely needs more, so the common full-bit-dominated case stays tight. Arena sizing is scratch memory only — no effect on VKs or proof output.
## Test
Added `MidBandArenaSizerCoversAllEffectiveNumBits`, which drives the module's own arena-fit simulator across the non-GLV mid-band × every `effective_num_bits` at 8 threads. It fails on the pre-fix sizer (under-counts at n=28,696 for `effective_num_bits` 224–248, among others) and passes with the fix. Full `ScalarMultiplication*` suite (110 tests, incl. real-MSM correctness and the small-scalar band test) passes.1 parent 0355ef8 commit fa17227
3 files changed
Lines changed: 58 additions & 16 deletions
File tree
- barretenberg/cpp/src/barretenberg/ecc/scalar_multiplication
Lines changed: 4 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
62 | | - | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
63 | 65 | | |
64 | 66 | | |
65 | 67 | | |
| |||
130 | 132 | | |
131 | 133 | | |
132 | 134 | | |
133 | | - | |
| 135 | + | |
134 | 136 | | |
135 | 137 | | |
136 | 138 | | |
| |||
Lines changed: 30 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1738 | 1738 | | |
1739 | 1739 | | |
1740 | 1740 | | |
| 1741 | + | |
| 1742 | + | |
| 1743 | + | |
| 1744 | + | |
| 1745 | + | |
| 1746 | + | |
| 1747 | + | |
| 1748 | + | |
| 1749 | + | |
| 1750 | + | |
| 1751 | + | |
| 1752 | + | |
| 1753 | + | |
| 1754 | + | |
| 1755 | + | |
| 1756 | + | |
| 1757 | + | |
| 1758 | + | |
| 1759 | + | |
| 1760 | + | |
| 1761 | + | |
| 1762 | + | |
| 1763 | + | |
| 1764 | + | |
| 1765 | + | |
| 1766 | + | |
| 1767 | + | |
| 1768 | + | |
| 1769 | + | |
| 1770 | + | |
1741 | 1771 | | |
1742 | 1772 | | |
1743 | 1773 | | |
| |||
Lines changed: 24 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1211 | 1211 | | |
1212 | 1212 | | |
1213 | 1213 | | |
1214 | | - | |
1215 | | - | |
| 1214 | + | |
1216 | 1215 | | |
1217 | | - | |
1218 | | - | |
1219 | | - | |
1220 | | - | |
| 1216 | + | |
| 1217 | + | |
1221 | 1218 | | |
1222 | 1219 | | |
1223 | 1220 | | |
| |||
1238 | 1235 | | |
1239 | 1236 | | |
1240 | 1237 | | |
1241 | | - | |
1242 | | - | |
1243 | | - | |
1244 | | - | |
1245 | | - | |
1246 | | - | |
1247 | | - | |
1248 | | - | |
| 1238 | + | |
| 1239 | + | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + | |
| 1243 | + | |
| 1244 | + | |
| 1245 | + | |
| 1246 | + | |
| 1247 | + | |
| 1248 | + | |
| 1249 | + | |
| 1250 | + | |
| 1251 | + | |
| 1252 | + | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
| 1258 | + | |
1249 | 1259 | | |
1250 | 1260 | | |
1251 | 1261 | | |
| |||
0 commit comments