NethermindEth / cairo-vm-go

A virtual machine for Cairo written in Go
MIT License
82 stars 50 forks source link

Investigate error in proof_mode when executing the specified code #202

Closed quasilyte closed 8 months ago

quasilyte commented 9 months ago

Just a reminder that this case could be worth investigating.

Our VM executed the given code without an error with and without a proof mode. cairo-run doesn't want to execute it in proof mode. It could be either an error on our side, or maybe an implementation issue on cairo0 side; or perhaps the code itself is invalid (it still needs an explanation).

Tested on:

quasilyte@lispbook2:~/CODE/cairo-vm-go2$ cairo-compile --version
cairo-compile 0.12.2

quasilyte@lispbook2:~/CODE/cairo-vm-go2$ cat test.cairo 
%builtins range_check

from starkware.cairo.common.math import assert_le_felt

func main{range_check_ptr}() {
    alloc_locals;
    local v1 = 543;
    local v2 = 657;

    assert_le_felt(v1, v2);

    ret;
}

quasilyte@lispbook2:~/CODE/cairo-vm-go2$ cairo-compile test.cairo --no_debug_info --proof_mode --output ./test_compiled.json

quasilyte@lispbook2:~/CODE/cairo-vm-go2$ cairo-run --version
cairo-run 0.12.2

quasilyte@lispbook2:~/CODE/cairo-vm-go2$ cairo-run --proof_mode --program test_compiled.json
Traceback (most recent call last):
  File "/home/quasilyte/.local/bin/cairo-run", line 10, in <module>
    sys.exit(main())
  File "/home/quasilyte/.local/lib/python3.10/site-packages/starkware/cairo/lang/vm/cairo_run.py", line 199, in main
    res = cairo_run(args)
  File "/home/quasilyte/.local/lib/python3.10/site-packages/starkware/cairo/lang/vm/cairo_run.py", line 326, in cairo_run
    runner.end_run(disable_trace_padding=disable_trace_padding)
  File "/home/quasilyte/.local/lib/python3.10/site-packages/starkware/cairo/lang/vm/cairo_runner.py", line 382, in end_run
    self.segments.compute_effective_sizes(allow_tmp_segments=allow_tmp_segments)
  File "/home/quasilyte/.local/lib/python3.10/site-packages/starkware/cairo/lang/vm/memory_segments.py", line 91, in compute_effective_sizes
    raise SecurityError(
starkware.cairo.lang.vm.vm_exceptions.SecurityError: Expected memory address to be relocatable value. Found: 1.
quasilyte commented 9 months ago

This program fails too:

%builtins range_check

from starkware.cairo.common.math import assert_le_felt

func main{range_check_ptr}() {
    ret;
}
Error: The stop pointer of the missing builtin "range_check" must be 0.
JorikSchellekens commented 9 months ago

Reach out to the SW team about this.

quasilyte commented 9 months ago

Two things are making this code not working as we expected it to work.

  1. The default cairo-run layout doesn't have the range_check builtin loaded (this is why it's "missing builtin")
  2. Implicit args are implicit returns as well, so ret is not going to work here: return must be used instead.

From the docs:

The plain layout, which is the default layout, has no builtins.