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

Divide-by-zero is a constraint failure for integers but not for Field #2149

Closed
Jurarpereurs opened this issue Aug 3, 2023 · 1 comment · Fixed by #2475
Closed

Divide-by-zero is a constraint failure for integers but not for Field #2149

Jurarpereurs opened this issue Aug 3, 2023 · 1 comment · Fixed by #2475
Assignees
Labels
bug Something isn't working

Comments

@Jurarpereurs
Copy link

Aim

The proving phase would complain that constraints are unsatisfiable when dividing an unsigned integer by zero:

let a: u8 = 3 / 0;

However, when changing the variable type to Field, the proving phase would not complain:

let a: Field = 3 / 0;

It would be better to make the behavior consistent. Also, the compiler should explicitly detect and give more informative error messages for divide-by-zero.

Expected Behavior

The compiler should explicitly issue an error message for divide-by-zero.

Bug

Please see steps to reproduce.

To Reproduce

Save the following code into src/main.nr:

use dep::std;

fn main() {
    let a: u8 = 3 / 0;
    std::println(a);
}

Run the following command:

nargo prove

You would see the following error message:

error: Unsatisfied constraint
  ┌─ /home/Jurarpereurs/src/main.nr:4:17
  │
4 │     let a: u8 = 3 / 0;
  │                 ----- Constraint failed

Error: could not satisfy all constraints

Location:
    crates/nargo_cli/src/cli/mod.rs:74:5

Then change the variable type to Field:

use dep::std;

fn main() {
    let a: Field = 3 / 0;
    std::println(a);
}

Run the following command:

nargo prove

The proving phase would succeed and you would see the following output:

"0x00"

Installation Method

Binary

Nargo Version

nargo 0.9.0 (git version hash: 35404ba, is dirty: false)

Additional Context

No response

Would you like to submit a PR for this Issue?

No

Support Needs

No response

@Jurarpereurs Jurarpereurs added the bug Something isn't working label Aug 3, 2023
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Aug 3, 2023
@jfecher jfecher changed the title Constraint failure in the case of divide-by-zero Divide-by-zero is a constraint failure for integers but not for Field Aug 4, 2023
@kevaundray
Copy link
Contributor

Since its a constraint failed error, this can likely be replicated with nargo execute

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

Successfully merging a pull request may close this issue.

4 participants