ZoKrates
ZoKrates copied to clipboard
Return statement in for-loop causes compiler panic
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: c7e4e29ad0e916cf2e1a6629a839f83db55a6447
- 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
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.