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

Inconsistent behavior on unused unsigned integer and field inputs #1346

Closed gwdjkspnado closed 11 months ago

gwdjkspnado commented 11 months ago

Description

Zokrates would throw an error if a field input is not used. However, when an unsigned integer input is not used, no error message would be thrown. This kind of behavior is inconsistent and causes confusion. It would be better if Zokrates can make the behavior consistent.

Environment

Steps to Reproduce

Save the following code as unconstrained.zok and check that the compiler would complain about the unused field input:

def main(private field a) {
}

Compile with zokrates compile -i unconstrained.zok, you would get the following error:

Compiling unconstrained.zok

Error: Found 1 unconstrained variable(s)

However, if you change the type of a to u32, the compiler would not complain about the unused input:

def main(private u32 a) {
}

Compile with zokrates compile -i unconstrained.zok, the compilation succeeds without any error message:

Compiling unconstrained.zok

Compiled code written to 'out'
Number of constraints: 33
dark64 commented 11 months ago

In the case of a u32 input, there is a bit decomposition and sum check happening which is the reason why it's considered constrained. Basically, the input is checked to be in the u32 range.

gwdjkspnado commented 11 months ago

Thanks for your reply! Closing this issue for now.