ZoKrates icon indicating copy to clipboard operation
ZoKrates copied to clipboard

Compiler crashes if arguments are too large

Open m1cm1c opened this issue 3 years ago • 6 comments

Description

The compiler crashes during witness computation if (at least) one of the arguments presented is too large.

Environment

  • Compiler version: branch develop (commit b18ea015)
  • Operating system: Manjaro

Steps to Reproduce

def main(u64 x):
	return
$ zz compile -i bug.zok
Compiling bug.zok

Compiled code written to 'out'
Number of constraints: 65
$ zz compute-witness -a 340282366920938463426481119284349108225
Computing witness...
Execution failed: Sum check failed
The default ZoKrates interpreter should not yield this error. Please open an issue: expected 18446744073709551615 to equal 340282366920938463426481119284349108225

m1cm1c avatar Sep 13 '21 09:09 m1cm1c

Hi @m1cm1c, it is expected for this to fail, but the last message should not be displayed like that. We'll have a look into it, thanks!

dark64 avatar Sep 13 '21 14:09 dark64

@dark64 Yes, it makes sense for compilation to fail. However, in my recent call with @Schaeff, he said that you guys are trying to get rid of compiler crashes and want to replace them with user error messages. That's why today I decided to file lots of bug reports about the compiler crashing.

m1cm1c avatar Sep 13 '21 15:09 m1cm1c

We should have a separate sum check error that we use for arguments and which is not marked malicious.

Schaeff avatar Oct 11 '21 09:10 Schaeff

A similar bug appears in zokrates-js. I run following code in npm RunKit:

var zokratesJs = require("zokrates-js/node")
var zok = await zokratesJs.initialize()
var code = zok.compile(`def main(private u64 original_val) -> u64:
  return original_val
`)
var {output} = zok.computeWitness(code, ['50000000000'])
var out = JSON.parse(output)

And, the result given is ["0x00000000a43b7400"], which in decimal is 2755359744, and it's not equal to 50000000000, which is less than 2**64. So I belive it's a bug

felinae98 avatar Feb 08 '22 13:02 felinae98

A similar bug appears in zokrates-js. I run following code in npm RunKit:

var zokratesJs = require("zokrates-js/node")
var zok = await zokratesJs.initialize()
var code = zok.compile(`def main(private u64 original_val) -> u64:
  return original_val
`)
var {output} = zok.computeWitness(code, ['50000000000'])
var out = JSON.parse(output)

And, the result given is ["0x00000000a43b7400"], which in decimal is 2755359744, and it's not equal to 50000000000, which is less than 2**64. So I belive it's a bug

Ah yes, we are aware of this, the issue is explained here https://github.com/Zokrates/ZoKrates/issues/1096

dark64 avatar Feb 08 '22 14:02 dark64

If it is correct ,I will Iove it from now on

Danyalkasiri avatar Mar 25 '24 04:03 Danyalkasiri