fix: zero padding/length region in digest_var - #19
Open
saleel wants to merge 1 commit into
Open
Conversation
`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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.