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

Test named sha2_byte crashes during compliation #1629

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

Test named sha2_byte crashes during compliation #1629

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

Comments

@joss-aztec
Copy link
Contributor

Aim

Test named sha2_byte should compile

Expected Behavior

^

Bug

It appears to hang during the cfg flatten pass.

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
@TomAFrench
Copy link
Member

Duplicate of #1259

@TomAFrench TomAFrench marked this as a duplicate of #1259 Jun 10, 2023
@TomAFrench TomAFrench closed this as not planned Won't fix, can't repro, duplicate, stale Jun 10, 2023
@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Noir Jun 10, 2023
@joss-aztec
Copy link
Contributor Author

This issue is specifically tracking a bug in the SSA refactor. The new SSA hangs. The old SSA throws.

@joss-aztec joss-aztec reopened this Jun 14, 2023
@joss-aztec
Copy link
Contributor Author

Sorry, I tell a lie. It doesn't hang. But the error feedback definitely needs improving:

The application panicked (crashed).
Message:  assertion failed: index < array.len()
Location: crates/noirc_evaluator/src/ssa_refactor/ir/instruction.rs:294

@joss-aztec
Copy link
Contributor Author

Also affects test named sha2_blocks

@kevaundray kevaundray added the e2e label Jun 20, 2023
@ludamad ludamad changed the title Test named sha2_byte hangs during compliation Test named sha2_byte crashes during compliation Jun 21, 2023
@ludamad
Copy link
Collaborator

ludamad commented Jun 21, 2023

This turns out to be related to #1756. This can be seen by removing the top half of the called sha function:


// SHA-256 hash function
fn digest<N>(msg: [u8; N]) -> [u8; 32] {
    let mut msg_block: [u8; 64] = [0; 64];
    let mut h: [u32; 8] = [1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]; // Intermediate hash, starting with the canonical initial value
    let mut c: [u32; 8] = [0; 8]; // Compression of current message block as sequence of u32
    let mut out_h: [u8; 32] = [0; 32]; // Digest as sequence of bytes
    let mut i = 0; // Message byte pointer

    for k in 0 .. msg.len() {
        // Populate msg_block
        msg_block[i] = msg[k];
        i = i + 1;
        if i == 64 { // Enough to hash block
            c = sha_c(msg_u8_to_u32(msg_block), h);
            for j in 0..8 {
                h[j] = c[j] + h[j];
            }
            
            i = 0;
        }
    }

    // Pad the rest such that we have a [u32; 2] block at the end representing the length
    // of the message, and a block of 1 0 ... 0 following the message (i.e. [1 << 7, 0, ..., 0]).
    msg_block[i] = 1 << 7;
    i = i + 1;


    out_h
}

Which gets the

Message:  internal error: entered unreachable code: Expected all allocate instructions to be removed before acir_gen
Location: crates/noirc_evaluator/src/ssa_refactor/acir_gen/mod.rs:258

error

@jfecher
Copy link
Contributor

jfecher commented Jun 22, 2023

The original error is gone now but sha2_byte now crashes with:

The application panicked (crashed).
Message:  Vector::index_mut: index out of bounds
Location: /Users/.../.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/im-15.1.0/./src/vector/mod.rs:838

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