noir-lang / noir

Noir is a domain specific language for zero knowledge proofs
https://noir-lang.org
Apache License 2.0
824 stars 178 forks source link

Entered unreachable code on 128x128 matrix multiplication #1132

Open nojansheybani opened 1 year ago

nojansheybani commented 1 year ago

Aim

I am trying to implement 128x128 matrix multiplication, but I've had to modify it to be flattened due to Noir not supporting multi-dimensional arrays. My code works on smaller inputs, but once I move to 128x128 it breaks.

Expected behavior

I expect it to work as at does on smaller inputs, such as 10x10

Bug

Message: internal error: entered unreachable code: failed on standard_example__get_exact_circuit_size call Location: /home/runner/.cargo/git/checkouts/aztec_backend-a697fb631cbad807/2cb523d/barretenberg_wasm/src/composer.rs:114

To reproduce

  1. on local system, do nargo new matmult
  2. Put the following in main.nr

    fn main(a : [Field; 16384], b : [Field; 16384], c : pub [Field; 16384]) {
    let mut temp_field = [0; 16384];
    for i in 0..128 {
        for j in 0..128 {
            for k in 0..128 {
                temp_field[i*128 + j] = temp_field[i*128 + j] + a[i * 128 + k] * b[k * 128 + j];
            }
        }
    }
    
    for i in 0..16384 {
        constrain c[i] == temp_field[i];
    }
    }
  3. Set Prover.toml to the following: PasteBin
  4. Use the following dockerfile:
    
    FROM ubuntu:22.04 as base

RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install \ -y build-essential cmake git libgmp3-dev libprocps-dev libboost-all-dev libssl-dev libsodium-dev nano wget clang lld libomp-dev curl bash

RUN curl https://sh.rustup.rs -sSf | bash -s -- -y ENV PATH="/root/.cargo/bin:${PATH}"

RUN git clone https://github.com/noir-lang/noir.git

WORKDIR noir

RUN curl -L https://raw.githubusercontent.com/noir-lang/noirup/main/install | bash

RUN cd /root/.nargo/bin/ && rm noirup && wget https://raw.githubusercontent.com/noir-lang/noirup/main/noirup && chmod +x noirup

ENV PATH="${PATH}:/root/.nargo/bin"

RUN noirup

RUN nargo new hello_world

COPY matmult/ matmult/

WORKDIR matmult

RUN nargo check

RUN nargo prove p

RUN nargo verify p



### Installation method

Binary

### Nargo version

nargo 0.3.2 (git version hash: 29b1f7df4d563849a62e64c533cb62932188135b, 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.
kevaundray commented 11 months ago

@f01dab1e can you check if this is an issue error occurs in our newer code, ie with --experimental-ssa enabled?

kevaundray commented 11 months ago

Assigning myself as I cannot assign f01dab1e

ghost commented 11 months ago

Operating system kills the process :]

❯ nargo prove --experimental-ssa
Killed
jfecher commented 11 months ago

The triple loop here would mean loop unrolling would have to unroll 2,097,152 times. Plus an extra 16384 times for the second loop. We can look at memory usage but I'm not sure if this would even prove and verify in a reasonable time if that is fixed.