Skip to content

fix: zero padding/length region in digest_var - #19

Open
saleel wants to merge 1 commit into
noir-lang:masterfrom
zkpassport:fix/zero-padding-region
Open

fix: zero padding/length region in digest_var#19
saleel wants to merge 1 commit into
noir-lang:masterfrom
zkpassport:fix/zero-padding-region

Conversation

@saleel

@saleel saleel commented Jun 18, 2026

Copy link
Copy Markdown
Member

No description provided.

`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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant