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

if-else loops are short-circuiting when using variables #1277

Closed
1 task
harshnambiar opened this issue May 2, 2023 · 2 comments
Closed
1 task

if-else loops are short-circuiting when using variables #1277

harshnambiar opened this issue May 2, 2023 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@harshnambiar
Copy link

Aim

in fn main(x: u32, y: pub u32), doing (x == 2), (x < 2) and (x > 2) all yield true. This is leading to every if, else part getting executed.

Expected behavior

This should clearly not be the case. However, constraints are working since constraint (x <= 2) seems to work just fine.

Bug

Each comparison with x is leading to a true case, which effectively short circuits the conditional statements.

To reproduce

  1. Fork https://github.com/resurgencelabs/rock_paper_scissors_game
  2. nargo check
  3. nargo prove p --show-output
  4. The program prints every scenario possible, which should not happen.

Installation method

Binary

Nargo version

nargo 0.5.0

@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.
@harshnambiar harshnambiar added the bug Something isn't working label May 2, 2023
@kevaundray kevaundray assigned vezenovm and unassigned guipublic Jul 25, 2023
@kevaundray
Copy link
Collaborator

@vezenovm is checking if this is fixed

@vezenovm
Copy link
Contributor

Using the repo provided in the issue I added printlns inside each conditional:

    if (p == 0){
        if (q == 1){
            std::println("Player 2 wins!");
            res = 2;
        }
        if (q == 2){
            std::println("Player 1 wins!");
            res = 1;
        }
    }
    if (p == 1){
        if (q == 0){
            std::println("Player 1 wins!");
            res = 1;  
        }
        if (q == 2){
            std::println("Player 2 wins!");
            res = 2;
        }
    }
    if (p == 2){
        if (q == 0){
            std::println("Player 2 wins!");
            res = 2;
        }
        if (q == 1){
            std::println("It's a draw!");
            res = 1; 
        }
    }

When using the new experimental ssa (nargo prove p --experimental-ssa) this is only now printing

"Player 2 wins!"
"0x02"

versus every case being printed with just nargo prove p --show-output.

Marking this issue as resolved

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

No branches or pull requests

4 participants