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

Constant folding doesn't update result value references #1618

Closed
joss-aztec opened this issue Jun 9, 2023 · 2 comments · Fixed by #1674
Closed

Constant folding doesn't update result value references #1618

joss-aztec opened this issue Jun 9, 2023 · 2 comments · Fixed by #1674
Labels
bug Something isn't working refactor ssa

Comments

@joss-aztec
Copy link
Contributor

joss-aztec commented Jun 9, 2023

Aim

To compile the test named sha256

use dep::std;

fn main(x: Field, result: [u8; 32]) {
    let digest = std::hash::sha256([x as u8]);
    assert(digest == result);
}

Expected Behavior

It compiles

Bug

Compile crashes with output (I've modified the printer to include instruction ids):

After Mem2Reg:
fn main f1 {
  b0(v0: Field, v1: [u8; 32]):
    v2 = (Id(0))cast v0 as u8
    v5 = (Id(1))call sha256([v2])
    v6 = (Id(2))eq v5, v1
    constrain v6
    return unit 0
}

After Constant Folding:
fn main f1 {
  b0(v0: Field, v1: [u8; 32]):
    v8 = (Id(4))cast v0 as u8
    v9 = (Id(5))call sha256([v2])
    v10 = (Id(6))eq v9, v1
    constrain v10
    return unit 0
}

The application panicked (crashed).
Message:  internal error: entered unreachable code: ICE: Should have been in cache Instruction { instruction: Id(0), position: 0, typ: Numeric(Unsigned { bit_size: 8 }) }
Location: crates/noirc_evaluator/src/ssa_refactor/acir_gen/mod.rs:345

Notice that during constant folding instruction Id(0) doesn't exist, but it did in mem2reg.

To Reproduce

Installation Method

None

Nargo Version

No response

Additional Context

No response

Would you like to submit a PR for this Issue?

No

Support Needs

No response

@joss-aztec joss-aztec added bug Something isn't working refactor ssa labels Jun 9, 2023
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Jun 9, 2023
@joss-aztec
Copy link
Contributor Author

Tests that are likely failing because of this:

  • simple_shield
  • sha256

@joss-aztec
Copy link
Contributor Author

Test named keccak256 also affected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working refactor ssa
Projects
Archived in project
1 participant