Zokrates / ZoKrates

A toolbox for zkSNARKs on Ethereum
https://zokrates.github.io
GNU Lesser General Public License v3.0
1.8k stars 360 forks source link

Compiler crash with large constant #1329

Open Safarah4783 opened 1 year ago

Safarah4783 commented 1 year ago

Description

I encountered a compiler crash when compiling a program with a large constant.

Environment

Steps to Reproduce

Save the following code as src.zok:

def main(private field a) {
    assert(a > 8000000000000000000000000000000000000000000000000000000000000000000000000000 && a > 1);
}

The compile the code with:

zokrates compile -i src.zok

The compiler will crash with the following error:

Compiling src.zok

The compiler unexpectedly panicked
panicked at 'assertion failed: res.len() <= to', /home/Safarah4783/ZoKrates/zokrates_codegen/src/lib.rs:2020:21
This is unexpected, please submit a full bug report at https://github.com/Zokrates/ZoKrates/issues

However, if you remove the assertion condition that a > 1, the compiler will compile the code successfully.

def main(private field a) {
    // Remove the `&& a > 1` part
    assert(a > 8000000000000000000000000000000000000000000000000000000000000000000000000000);
}
dark64 commented 1 year ago

Thanks for the report, this seems to be fixed in #1309