Commit 5c2e6d9
authored
chore: crypto primitives external audit response 0 (#22263)
### Audit Context
Addresses findings from the "Aztec - Cryptographic Primitives" external
audit. This is response 0, covering the findings that have
straightforward fixes.
### Changes Made
**Finding 1: Off-Curve Proof Commitment Crashes WASM Verifier**
Replace `BB_ASSERT(val.on_curve())` with explicit `throw_or_abort` in
both FrCodec and U256Codec deserialization paths
(`field_conversion.hpp`). This routes the error through the standard
error path that is catchable by bbapi's try-catch in native builds,
rather than going through `assert_failure`.
**Finding 2: WASM Process DOS via Oversized Polynomial in Prover Commit
Path**
No changes in this PR. Requires a WASM-compatible recovery boundary
(setjmp/longjmp or extending try_catch_shim.hpp). Will be addressed in a
follow-up.
**Finding 3: SRS Downloaded Using HTTP**
No changes in this PR. Already mitigated by SHA-256 chunk hash
verification (PR #21113). Switching to HTTPS requires resolving the
OpenSSL cross-compilation dependency. Deferred.
**Finding 4: bbapi Unix Socket Accepts Unauthenticated SRS Replacement**
- Add `chmod(socket_path, 0600)` after `bind()` on both macOS and Linux
socket paths, matching the 0600 mode already used for the SHM transport.
- Add null-guard to `init_bn254_mem_crs_factory()` to prevent replacing
an already-initialized SRS, matching the existing guards on
`init_bn254_net_crs_factory` and `init_bn254_file_crs_factory`.
**Finding 5: Latent Shift-UB in get_scalar_slice**
Add `static_assert(MAX_SLICE_BITS < 64, ...)` to encode the invariant
that the shift in `get_scalar_slice` remains well-defined.
**Finding 6: batch_commit() Subspan Constructed Before Bounds Check**
Move the SRS bounds check before the `subspan()` call in
`batch_commit()`. `std::span::subspan()` has UB when offset > size().
This brings `batch_commit` in line with `commit()` which already
validates first.
**Finding 7: Witness Polynomial Coefficients Vulnerable to Leakage**
No changes. Threat model does not support this being a real vector: PXE
in an extension runs in a separate origin, and for embedded wallets
there is no trust boundary. Not prioritized.
**Finding 8: BitVector::set() Non-Atomic RMW Has No Thread-Safety
Guard**
Add NOT THREAD-SAFE documentation to `BitVector` class noting that
concurrent `set()` calls on indices in the same 64-bit word will race.
Current usage is safe due to per-thread `BucketAccumulators` ownership.
**Finding 9: batch_mul Mutates Scalars Through const Interface**
Change `batch_mul`'s public interface from `std::span<const Fr>` to
`std::span<Fr>`, making the mutation contract explicit. The MSM
internally converts scalars from/to Montgomery form, so callers must
provide mutable scalars. Updated HyperNova prover/verifier wrappers
(drop const) and IPA `reduce_batch_opening_claim` (mutable copy).
### Checklist
- [x] Confirmed and documented security issues found
- [x] Verified that tests cover all critical paths
- [x] Verified build passes (`ninja` clean build)
- [x] Ran ecc_tests (830 passed), srs_tests (29 passed),
commitment_schemes_tests (88 passed), hypernova_tests (9 passed)1 parent fccec82 commit 5c2e6d9
14 files changed
Lines changed: 32 additions & 13 deletions
File tree
- barretenberg/cpp/src/barretenberg
- commitment_schemes
- ipa
- ecc
- fields
- groups
- scalar_multiplication
- hypernova
- ipc
- srs
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
114 | | - | |
115 | 114 | | |
116 | 115 | | |
117 | 116 | | |
118 | 117 | | |
119 | 118 | | |
120 | 119 | | |
121 | 120 | | |
| 121 | + | |
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
832 | 832 | | |
833 | 833 | | |
834 | 834 | | |
835 | | - | |
| 835 | + | |
836 | 836 | | |
837 | 837 | | |
838 | 838 | | |
| |||
Lines changed: 6 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
133 | 133 | | |
134 | 134 | | |
135 | 135 | | |
136 | | - | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
137 | 139 | | |
138 | 140 | | |
139 | 141 | | |
| |||
268 | 270 | | |
269 | 271 | | |
270 | 272 | | |
271 | | - | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
272 | 276 | | |
273 | 277 | | |
274 | 278 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
199 | 199 | | |
200 | 200 | | |
201 | 201 | | |
202 | | - | |
| 202 | + | |
203 | 203 | | |
204 | 204 | | |
205 | 205 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
110 | | - | |
| 110 | + | |
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
| |||
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
| 45 | + | |
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
| 52 | + | |
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
| |||
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
42 | 45 | | |
43 | 46 | | |
44 | 47 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
116 | | - | |
| 116 | + | |
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
0 commit comments