zksecurity / noname

Noname: a programming language to write zkapps
https://zksecurity.github.io/noname/
193 stars 50 forks source link

Error reporting in programs without constraints #233

Open bufferhe4d opened 5 days ago

bufferhe4d commented 5 days ago

I was writing the following example (an example where there are no constraints with a public input):

fn main(pub aa: Field) {
    let mut xx = aa + 1;
}

After running cargo run test --path examples/no_cons.no --public-inputs '{"aa": "3"}', I hit the following error:

Error:   × Looks like something went wrong in constraint-finalization
   ╭─[<BUILTIN>:1:1]
 1 │ <SEE NONAME CODE>
   · ▲
   · ╰── here
   ╰────
  help: Unexpected error: there's a bug in the circuit_writer, some cellvar does not end up being a cellvar in the circuit!.

If I try the same example with a private input, the error is more descriptive:

Error:   × Looks like something went wrong in constraint-finalization
   ╭─[examples/no_cons.no:1:1]
 1 │ fn main(aa: Field) {
   ·         ─┬
   ·          ╰── here
 2 │     let mut xx = aa + 1;
   ╰────
  help: private input not used in the circuit

I thought it could help to give the same error in those cases as help: public input not used in the circuit

katat commented 5 days ago

Yes, great discovery. I agreed it will be helpful to display where the error originate from as you said above. Feel free to create a PR if you want :)