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

Builtins to_bits and to_bytes only work for u128 #1311

Closed
1 task
shuklaayush opened this issue May 7, 2023 · 0 comments · Fixed by #1312
Closed
1 task

Builtins to_bits and to_bytes only work for u128 #1311

shuklaayush opened this issue May 7, 2023 · 0 comments · Fixed by #1312
Labels
bug Something isn't working

Comments

@shuklaayush
Copy link
Contributor

Aim

Opcodes ToBits and ToRadix cast the input field element to u128 so they don't work for larger field elements

let args = args.iter().map(|arg| {
NodeEval::from_id(ctx, *arg).into_const_value().map(|f| f.to_u128())
});

Expected behavior

The functions should work for all field elements (i.e. up-to 254 bits)

Bug

Casting should be avoided

To reproduce

use dep::std;

fn main() {
    let x1 = 0xffffffffffffffffffffffffffffffff;
    let x2 = 0xffffffffffffffffffffffffffffffffff;

    let x1_bytes = x1.to_le_bytes(32);
    let x2_bytes = x2.to_le_bytes(32);
    std::println(x1_bytes);
    std::println(x2_bytes);

    // This should fail
    assert(x1_bytes[16] == x2_bytes[16]);
}

#[test]
fn test_main() {
    main();
}

Installation method

Compiled from source

Nargo version

nargo 0.5.1 (git version hash: 545340c, is dirty: false)

@noir-lang/noir_wasm version

No response

@noir-lang/barretenberg version

No response

@noir-lang/aztec_backend version

No response

Additional context

No response

Submission Checklist

  • Once I hit submit, I will assign this issue to the Project Board with the appropriate tags.
@shuklaayush shuklaayush added the bug Something isn't working label May 7, 2023
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir May 7, 2023
@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Noir May 11, 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.

1 participant