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

Compiler Panic when using nested Ternary Expressions #263

Open
MarkCampbell90 opened this issue May 8, 2024 · 0 comments
Open

Compiler Panic when using nested Ternary Expressions #263

MarkCampbell90 opened this issue May 8, 2024 · 0 comments

Comments

@MarkCampbell90
Copy link

MarkCampbell90 commented May 8, 2024

I was playing around with ternary expressions and found following unreachable code error during the c and wasm witness code generation. I am using circom 2.1.8.

Commands
circom --wasm circuit.circom or circom --c circuit.circom

Circom File

// circuit.circom

pragma circom 2.1.8;

template main_template() {
    signal input in;
    signal output out;
    out <-- (((in ? 1 : 0) ? 1 : 0));
}

component main = main_template();

For both circuit targets (c and wasm) I get following error:

thread 'main' panicked at compiler/src/intermediate_representation/translate.rs:687:9:
internal error: entered unreachable code: This expression is syntactic sugar
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

What I find particularly interesting is that when I create a temporary variable everything compiles as expected:

pragma circom 2.1.8;

template main_template() {
    signal input in;
    signal output out;
    var tmp = (in ? 1 : 0);
    out <-- (tmp ? 1 : 0);
    // out <-- (((in ? 1 : 0) ? 1 : 0));
}

component main = main_template();

Is it not possible to have multiple nested ternary expressions in the condition part?
Or is this simply not implemented yet?

Personally, I find the triggered unreachable!("This expression is syntactic sugar") error confusing. The code is clearly reachable and I am unsure what the message This expression is syntactic sugar is referring to.

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

1 participant