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

Compiler error hashing a field #1842

Closed
mikeshultz opened this issue Jun 30, 2023 · 4 comments · Fixed by #2070
Closed

Compiler error hashing a field #1842

mikeshultz opened this issue Jun 30, 2023 · 4 comments · Fixed by #2070
Assignees
Labels
bug Something isn't working

Comments

@mikeshultz
Copy link

Aim

I'm new to Noir and trying to learn more about how it works. My first example was just to attempt to hash a Field. nargo check succeeds just fine, but if I attempt to actually run the test or prove, I get the below compiler error.

Expected Behavior

The test would run and field would be hashed (or show me the error of my ways)

Bug

$ nargo test
Running 1 test functions...
Testing test_main...
The application panicked (crashed).
Message:  invalid input
Location: crates/noirc_evaluator/src/ssa/acir_gen/operations/intrinsics.rs:184

This is a bug. We may have already fixed this in newer versions of Nargo so try searching for similar issues at https://github.com/noir-lang/noir/issues/.
If there isn't an open issue for this bug, consider opening one at https://github.com/noir-lang/noir/issues/new?labels=bug&template=bug_report.yml

To Reproduce

Try to run nargo test on the following circuit:

use dep::std::hash;

fn main(thing : Field) {
    let chash = hash::keccak256(thing.to_le_bytes(8));
    assert(chash[0] > 0 | chash[1] > 0);
}

#[test]
fn test_main() {
    let thing = 123;
    main(thing);
}

Installation Method

Binary

Nargo Version

nargo 0.6.0 (git version hash: 0181813, is dirty: false)

Additional Context

No response

Would you like to submit a PR for this Issue?

No

Support Needs

No response

@mikeshultz mikeshultz added the bug Something isn't working label Jun 30, 2023
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Jun 30, 2023
@kevaundray
Copy link
Contributor

@vezenovm can you verify if this is an issue with the new SSA code?

@vezenovm
Copy link
Contributor

@kevaundray Yeah I'll look into it

@vezenovm
Copy link
Contributor

vezenovm commented Jul 24, 2023

With the addition of slices this brings a new, but easily solvable bug. to_le_bytes returns a u8 slice. While keccak currently still has this method signature: fn keccak256<N>(_input : [u8; N], _message_size: u32) -> [u8; 32] {} but will be fixed if we switched to fn keccak256(_input : [u8], _message_size: u32) -> [u8; 32] {}. For the old SSA this is also a case of mismatched input and can be solved with this:

use dep::std::hash;

fn main(thing : Field) {
    let x = thing.to_le_bytes(8);
    let chash = hash::keccak256(x, 8);
    assert(chash[0] > 0 | chash[1] > 0);
}

#[test]
fn test_main() {
    let thing = 123;
    main(thing);
}

For the new SSA this bug will can fixed in Noir by converting the output of to_le_bytes to an array until we switch over the keccak method signature. @jfecher I was thinking we should hold off on converting any method signatures until the full switch to the new SSA.

@jfecher
Copy link
Contributor

jfecher commented Jul 24, 2023

@vezenovm we should probably wait, yes. There are slice related changes I'd like to merge as well that would be breaking changes or would require changing method signatures to fix old bugs. For example the to_bits family of functions claim to return an array of any length N but in reality return a specific length depending on the size of the input. We either need to change these to return slices or put a maximum bound on them and fill the rest with zeroes. Since their type is unsound currently.

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
4 participants