Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sha256_var crashes in runtime #5836

Closed
olehmisar opened this issue Aug 27, 2024 · 2 comments · Fixed by #5838
Closed

sha256_var crashes in runtime #5836

olehmisar opened this issue Aug 27, 2024 · 2 comments · Fixed by #5838
Labels
bug Something isn't working

Comments

@olehmisar
Copy link

Aim

Getting a sha256 hash of some data. I am using a new version of sha256_var from #5760.

Expected Behavior

I got a hash

Bug

I got a runtime error:

Running 1 test function
Testing test_hash... FAIL
Failed to solve program: 'Cannot satisfy constraint'

error: Failed constraint
   ┌─ std/hash/sha256.nr:65:13
   │
65 │             assert_eq(msg_block[msg_byte_ptr], msg[k]);
   │             ------------------------------------------
   │
   = Call stack:
     1. src/lib.nr:71:5
     2. std/hash/sha256.nr:112:28
     3. std/hash/sha256.nr:65:13

1 test failed

To Reproduce

  1. noirup -C c52dc1c
  2. Run this test:
    #[test]
    fn test_hash() {
        let headers = [
            102, 114, 111, 109, 58, 114, 117, 110, 110, 105, 101, 114, 46, 108, 101, 97, 103, 117, 101, 115, 46, 48, 106, 64, 105, 99, 108, 111, 117, 100, 46, 99, 111, 109, 13, 10, 99, 111, 110, 116, 101, 110, 116, 45, 116, 121, 112, 101, 58, 116, 101, 120, 116, 47, 112, 108, 97, 105, 110, 59, 32, 99, 104, 97, 114, 115, 101, 116, 61, 117, 115, 45, 97, 115, 99, 105, 105, 13, 10, 109, 105, 109, 101, 45, 118, 101, 114, 115, 105, 111, 110, 58, 49, 46, 48, 32, 40, 77, 97, 99, 32, 79, 83, 32, 88, 32, 77, 97, 105, 108, 32, 49, 54, 46, 48, 32, 92, 40, 51, 55, 51, 49, 46, 53, 48, 48, 46, 50, 51, 49, 92, 41, 41, 13, 10, 115, 117, 98, 106, 101, 99, 116, 58, 72, 101, 108, 108, 111, 13, 10, 109, 101, 115, 115, 97, 103, 101, 45, 105, 100, 58, 60, 56, 70, 56, 49, 57, 68, 51, 50, 45, 66, 54, 65, 67, 45, 52, 56, 57, 68, 45, 57, 55, 55, 70, 45, 52, 51, 56, 66, 66, 67, 52, 67, 65, 66, 50, 55, 64, 109, 101, 46, 99, 111, 109, 62, 13, 10, 100, 97, 116, 101, 58, 83, 97, 116, 44, 32, 50, 54, 32, 65, 117, 103, 32, 50, 48, 50, 51, 32, 49, 50, 58, 50, 53, 58, 50, 50, 32, 43, 48, 52, 48, 48, 13, 10, 116, 111, 58, 122, 107, 101, 119, 116, 101, 115, 116, 64, 103, 109, 97, 105, 108, 46, 99, 111, 109, 13, 10, 100, 107, 105, 109, 45, 115, 105, 103, 110, 97, 116, 117, 114, 101, 58, 118, 61, 49, 59, 32, 97, 61, 114, 115, 97, 45, 115, 104, 97, 50, 53, 54, 59, 32, 99, 61, 114, 101, 108, 97, 120, 101, 100, 47, 114, 101, 108, 97, 120, 101, 100, 59, 32, 100, 61, 105, 99, 108, 111, 117, 100, 46, 99, 111, 109, 59, 32, 115, 61, 49, 97, 49, 104, 97, 105, 59, 32, 116, 61, 49, 54, 57, 51, 48, 51, 56, 51, 51, 55, 59, 32, 98, 104, 61, 55, 120, 81, 77, 68, 117, 111, 86, 86, 85, 52, 109, 48, 87, 48, 87, 82, 86, 83, 114, 86, 88, 77, 101, 71, 83, 73, 65, 83, 115, 110, 117, 99, 75, 57, 100, 74, 115, 114, 99, 43, 118, 85, 61, 59, 32, 104, 61, 102, 114, 111, 109, 58, 67, 111, 110, 116, 101, 110, 116, 45, 84, 121, 112, 101, 58, 77, 105, 109, 101, 45, 86, 101, 114, 115, 105, 111, 110, 58, 83, 117, 98, 106, 101, 99, 116, 58, 77, 101, 115, 115, 97, 103, 101, 45, 73, 100, 58, 68, 97, 116, 101, 58, 116, 111, 59, 32, 98, 61
        ];
        std::hash::sha256_var(headers, headers.len() as u64);
    }

Workaround

None

Workaround Description

No response

Additional Context

Caused by #5760

Project Impact

Blocker

Blocker Context

No response

Nargo Version

No response

NoirJS Version

No response

Proving Backend Tooling & Version

No response

Would you like to submit a PR for this Issue?

None

Support Needs

No response

@olehmisar olehmisar added the bug Something isn't working label Aug 27, 2024
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Aug 27, 2024
@TomAFrench
Copy link
Member

cc @vezenovm

@vezenovm
Copy link
Contributor

vezenovm commented Aug 27, 2024

Ah I think I know what this is, will push something in a moment.

EDIT: I have a fix

github-merge-queue bot pushed a commit that referenced this issue Aug 28, 2024
…block compression under certain cases (#5838)

# Description

## Problem\*

Resolves #5836 

## Summary\*

We accept a start index based upon the current block when parsing a
message. We should accurately base the upper bound to be based upon this
start index.

We also have special handling for building a message block but not
compressing it when the message is less than the block size. We need to
also do this handling for the last message block when we have a message
that is larger than the block size.

## Additional Context

~~sha256_var is currently getting warnings from the under constrained
check. It looks to only be happening on the new regression test added as
part of this PR that uses a larger message. The old sha256 tests do not
look to trigger these warnings which is strange. I am a bit unsure why I
am getting these warnings as msg block and msg block pointer are being
verified on each iteration of the loop.~~

<img width="965" alt="Screenshot 2024-08-27 at 12 04 58 PM"
src="https://github.com/user-attachments/assets/c71bff9d-bfea-4765-a134-91eca92c7806">

EDIT: This was only happening as my test was hashing constant values,
thus it was a dumb circuit. e.g the following:
```rust
fn main(result: pub [u8; 32]) {
    let headers = [102, 114, 111, 109, 58, 114, 117, 110, 110, 105, 101, 114, 46, 108, 101, 97, 103, 117, 101, 115, 46, 48, 106, 64, 105, 99, 108, 111, 117, 100, 46, 99, 111, 109, 13, 10, 99, 111, 110, 116, 101, 110, 116, 45, 116, 121, 112, 101, 58, 116, 101, 120, 116, 47, 112, 108, 97, 105, 110, 59, 32, 99, 104, 97, 114, 115, 101, 116];
    let hash = std::hash::sha256_var(headers, headers.len() as u64);
    assert_eq(hash, result);
}
```
The message needs to come from the inputs and the under-constrained
warnings go away.

## Documentation\*

Check one:
- [X] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[For Experimental Features]** Documentation to be submitted in a
separate PR.

# PR Checklist\*

- [X] I have tested the changes locally.
- [X] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.
@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Noir Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
3 participants