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

Return statement in for-loop causes compiler panic #1350

Open
gasilano opened this issue Sep 30, 2023 · 1 comment
Open

Return statement in for-loop causes compiler panic #1350

gasilano opened this issue Sep 30, 2023 · 1 comment

Comments

@gasilano
Copy link

Description

When a return statement is used in a for-loop, the compiler would panic during the witness generation phase. It would be better if the compiler can throw an error message instead of panicking.

A minimal example is shown below:

def main() -> u32 {
    u32 mut res = 0;
    for u32 i in 0..2 {
        res = res + i;
        return res;
    }
    return res;
}

Environment

  • Zokrates Compiler commit: c7e4e29
  • Operating system: Ubuntu 22.04.2 LTS

How to reproduce

Save the above code as for_return.zok and run the following command:

zokrates compile -i for_return.zok
zokrates setup
zokrates compute-witness

The compiler would throw an error message on the last step:

Compiling for_return.zok

Compiled code written to 'out'
Number of constraints: 2
Performing setup...
Verification key written to 'verification.key'
Proving key written to 'proving.key'
Setup completed
Computing witness...
The compiler unexpectedly panicked
panicked at 'Found an unsatisfied constraint without an attached error.', zokrates_interpreter/src/lib.rs:390:26
This is unexpected, please submit a full bug report at https://github.com/Zokrates/ZoKrates/issues
@dark64
Copy link
Member

dark64 commented Jan 18, 2024

Hey, it seems like our semantic checker missed this one – using return statements in the for-loop block shouldn't be allowed. That's causing some funky undefined behavior in the other steps.

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