Skip to content

Commit a1cf282

Browse files
42Pupusasclaude
andcommitted
k256: debug_assert wNAF digit index stays in bounds
`wnaf_128` writes into a fixed 130-entry buffer; the bound holds for the current `WNAF_WIDTH = 5` and the ≤128-bit GLV sub-scalars, but it's implicit. Add a `debug_assert!` in the loop so that any future change to `WNAF_WIDTH` that invalidates the bound is caught at test time rather than silently writing out of bounds in worst-case inputs. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 4785280 commit a1cf282

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

k256/src/arithmetic/mul.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ fn wnaf_128(k: &Scalar) -> [i8; WNAF_DIGITS] {
343343
let mut out = [0i8; WNAF_DIGITS];
344344
let mut i = 0;
345345
while (lo | hi) != 0 {
346+
debug_assert!(i < WNAF_DIGITS);
346347
if (lo & 1) == 1 {
347348
// d = k mod 2^W, recentered into [-2^(W-1) + 1, 2^(W-1) - 1]
348349
let mut d = (lo & width_mask) as i64;

0 commit comments

Comments
 (0)