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

Better error handling for conditional(unknown) #42

Closed
0xSage opened this issue Apr 3, 2022 · 2 comments
Closed

Better error handling for conditional(unknown) #42

0xSage opened this issue Apr 3, 2022 · 2 comments

Comments

@0xSage
Copy link

0xSage commented Apr 3, 2022

The following circuit fails with an error on a seemingly unrelated line:

template ItFails() {
    signal output out1;
    signal output out2;
    out1 <== 1;

    if ( out1 ) {
        out2 <-- 1;
    } else {
        out2 <-- 1; // ERROR HERE: Exception caused by invalid assignment
    }
}

Strangely, compiler doesn't complain at:

template ItFails() {
    signal output out1;
    signal output out2;
    out1 <== 1;

    if ( out1 ) {
        out2 <-- 1;
    }
}

It's unclear whether:

  1. compiler doesn't allow conditionals on unknowns PERIOD... OR
  2. compiler doesn't allow conditionals on unknowns iff its inner scope sets a constraint.
@alrubio
Copy link
Collaborator

alrubio commented Apr 20, 2022

This error has nothing to do with the unknowns as you are not adding constraints in the conditional. Remember that <-- is only an assignment without introducing the constraint. Yo have to use <== to introduce constraints and then you'll get an error talking about unknown conditions.
In your case, the error is due to the fact that we don't have a path analysis yet to check the single assignment condition on signals, so the "invalid assignment" means that you have two assignment instructions on out2 (which is not true in any real execution path, but the compiler does not detect it yet). That's the reason why the second example compiles.
The way to avoid such errors is by using a var:
template ItWorks() {
signal output out1;
signal output out2;
out1 <== 1;
var aux;
if ( out1 ) {
aux = 1;
} else {
aux = 1;
}
out2 <-- aux;
}
compiles without error.
If you replace <-- by <== you will get a compilation error in the constraint generation since aux is non quadratic as it is defined by a conditional with an unknown condition.

@0xSage
Copy link
Author

0xSage commented Apr 20, 2022

neat, thanks for the clarification.
closing this as the path inference work seems already on your radar

@0xSage 0xSage closed this as completed Apr 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants