Commit 1c8e940
committed
fix: zero padding/length region in digest_var
`digest_var` copied the BoundedVec's entire backing store (`for i in 0..N`)
into the padded message, then only overwrote the 0x80 marker and the length
bytes. Bytes in the backing store beyond `len()` are unconstrained witness
data, so any non-zero value there landed in the SHA padding region and
silently altered the digest — the padding region was only ever zero by
convention, never by constraint.
Gate the copy on `i < msg_length` so the padding/length region is forced to
zero regardless of the witness, matching noir-lang/sha256 v0.3.0 which already
ignores input bytes past the message length.
Adds a regression test (`test_dirty_padding_ignored`) that hashes "abc" from a
BoundedVec whose tail is filled with 0xff via `from_parts_unchecked`; it fails
on the old code and passes with the fix.1 parent e92ffb4 commit 1c8e940
1 file changed
Lines changed: 20 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
140 | 140 | | |
141 | 141 | | |
142 | 142 | | |
| 143 | + | |
| 144 | + | |
143 | 145 | | |
144 | 146 | | |
145 | | - | |
| 147 | + | |
146 | 148 | | |
147 | 149 | | |
148 | | - | |
149 | | - | |
150 | 150 | | |
151 | 151 | | |
152 | 152 | | |
| |||
285 | 285 | | |
286 | 286 | | |
287 | 287 | | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
288 | 305 | | |
289 | 306 | | |
290 | 307 | | |
| |||
0 commit comments