ZoKrates icon indicating copy to clipboard operation
ZoKrates copied to clipboard

Out-of-bounds access crashes the static analyser

Open axic opened this issue 3 years ago • 2 comments

def main():
        u32[16] memory = [0; 16]
        memory[17] = 1
        return
Compiling bug1.zok

index out of bounds: the len is 16 but the index is 17 (/Users/alex/Projects/ZoKrates/zokrates_core/src/static_analysis/propagation.rs:85:77)
This is unexpected, please submit a full bug report at https://github.com/Zokrates/ZoKrates/issues

I was actually preparing a short example for a different bug and tried to simplify the code, so I found this issue too.

axic avatar May 05 '21 23:05 axic

Right, this needs to be handled more gracefully.

Schaeff avatar May 06 '21 09:05 Schaeff

Interestingly, static analysis handles the write case:

def main():
        u32[16] memory = [0; 16]
        u32 f = memory[17]
        return
$ zz compile -i bug.zok 
Compiling bug.zok

Compilation failed:

bug.zok:
        Out of bounds index (17 >= 16) found during static analysis

m1cm1c avatar Sep 13 '21 12:09 m1cm1c

This was fixed a while back, just didn't close this issue.

Schaeff avatar Sep 14 '22 08:09 Schaeff