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

Incorrect result of shift right operation for value from as_bytes array #3635

Closed
akonior opened this issue Nov 29, 2023 · 0 comments · Fixed by #3682
Closed

Incorrect result of shift right operation for value from as_bytes array #3635

akonior opened this issue Nov 29, 2023 · 0 comments · Fixed by #3682
Assignees
Labels
bug Something isn't working

Comments

@akonior
Copy link
Contributor

akonior commented Nov 29, 2023

Aim

Convert string to u8 array and perform right shift >> on this u8 value.

Expected Behavior

Using String as_bytes method should return array of u8 values.

Bug

After

let y: u8 = "a".as_bytes()[0];

y is equal to 0x61 and is of type u8. So expression y >> 1 should be 0x30 but is some large number that looks like Field

To Reproduce

Run

#[test]
fn test_string_as_bytes() {
    let x: u8 = 0x61;
    let y: u8 = "a".as_bytes()[0];
    std::println(x); // => "0x61"
    std::println(y); // => "0x61"
    assert_eq(x, y);

    std::println(x >> 1); // => "0x30"
    std::println(y >> 1); // => "0x183227397098d014dc2822db40c0ac2e9419f4243cdcb848a1f0fac9f8000031"
    
    assert_eq(x >> 1, y >> 1); // error: Failed constraint
}

Example code https://github.com/akonior/noir_example/pull/2/files
CI failed logs: https://github.com/akonior/noir_example/actions/runs/7031006112/job/19131738391?pr=2

Installation Method

Binary

Nargo Version

0.19.2

Additional Context

No response

Would you like to submit a PR for this Issue?

Maybe

Support Needs

No response

@akonior akonior added the bug Something isn't working label Nov 29, 2023
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Nov 29, 2023
github-merge-queue bot pushed a commit that referenced this issue Dec 5, 2023
# Description

## Problem\*

Resolves #3635 

## Summary\*

String literals were initialised as field array instead of array of u8.

## Additional Context



## Documentation\*

Check one:
- [X] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[Exceptional Case]** 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 Dec 5, 2023
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
Development

Successfully merging a pull request may close this issue.

2 participants