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;
}
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.
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:
Environment
How to reproduce
Save the above code as
for_return.zok
and run the following command:The compiler would throw an error message on the last step: