noir-lang / noir

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

Wrong Failed Constraint Error #5463

Closed LukiMueller closed 1 month ago

LukiMueller commented 1 month ago

Aim

I experimented with the language and found a weird behavior. When executing the following code with nargo execute:

main.nr:

pub fn main(x : Field) -> pub Field {
    let mut y : Field = 0;
    if (!(6.lt(x)) | !(6.lt(x)))
    {
        y = x;
    }
    else
    {
        y = 1;
    }
    assert(((x == y) | true), "assertion");
    y
}

Prover.toml:

x = "10"

I receive a failed constraint error for the expression inside of the assert statement. I am unsure why I receive this error in this particular case. if I remove one of the !(6.lt(x)) expressions of the condition everything executes as expected, which seems even weirder to me.

Expected Behavior

I expect to run nargo execute without receiving an error and to receive following expected output:

[playground] Circuit witness successfully solved
[playground] Circuit output: Field(1)

Bug

This is the error message I receive from executing nargo execute:

error: Failed constraint
   ┌─ /app/src/main.nr:11:14
   │
11 │     assert(((x == y) | true), "assertion");
   │              -----------
   │
   = Call stack:
     1. /app/src/main.nr:11:14

To Reproduce

  1. create a project with the provided main.nr and Prover.toml
  2. nargo execute

Project Impact

None

Impact Context

No response

Workaround

None

Workaround Description

No response

Additional Context

No response

Installation Method

Binary (noirup default)

Nargo Version

No response

NoirJS Version

No response

Would you like to submit a PR for this Issue?

None

Support Needs

No response

jfecher commented 1 month ago

What compiler version are you using?

I can't reproduce this on latest master (c47242ab)

LukiMueller commented 1 month ago

Hey, thank you for the quick reply.

> nargo --version
nargo version = 0.30.0
noirc version = 0.30.0+af57471035e4fa7eaffa71693219df6d029dbcde
(git version hash: af57471035e4fa7eaffa71693219df6d029dbcde, is dirty: false)

I am using the default install when executing noirup.

jfecher commented 1 month ago

I've confirmed it's failing on your commit and not failing on master - so this bug has been fixed. You should see the fix in a future update. Alternatively, if this is blocking you can download nargo nightly via noirup as well to see this fix today.

LukiMueller commented 1 month ago

Seems like this was the fixing commit: