kkrt-labs/cairo-vm-ts

epic: investigate and design a tracing API for the cairo vm ts

Opened this issue · 3 comments

  • look at VMs, i.e. EVMs,
  • NPM packages for tracing and error tracing

This is not linked to the VM trace (prover mode)

@Eikix can you give more context ? or we close this?

Ah yes, I wonder how we can replicate the concept of Cairo trace for Cairo VM TS

The fact that you get a precise error trace when hitting a CairoVM error in Python. Moreover, I wonder if it can come directly decoded

Ah yes, I wonder how we can replicate the concept of Cairo trace for Cairo VM TS

The fact that you get a precise error trace when hitting a CairoVM error in Python. Moreover, I wonder if it can come directly decoded

Are you talking about what the --show_trace flag outputs in the python VM cli? If so, the JS error already display the call stack leading to the error

But if we're talking about where it failed on the Cairo program, such as

cairo_programs/cairo_0/bad_programs/bad_range_check_builtin.cairo:4:5: Error at pc=0:2:
Value 3618502788666131213697322783095070105623107215331596699973092056135872020480, in range check builtin 0, is out of range [0, 340282366920938463463374607431768211456).
    assert [range_check_ptr] = -1;
    ^****************************^
  • For Error at pc=0:2, we can add a try catch clause in the vm step() to log at which PC it failed and then throw
  • A meaningful error message is doable by adding an error message to the super('') constructor of each error class (e.g. error: Value ${value} in range_check builtin is out of range [0, ${bound}])
  • For the link to the Cairo program, is it done through the debug_info of the compilation artifacts, instruction_locations maps the (relative) PC (0:2 => "2") to the instruction location. The inst field gives the path to the cairo program + start/end lines and columns of the instruction.

Assuming the Cairo file is available in the context of execution, adding a debug attribute to the VM (optional in the config ?) would allow to show which Cairo statement induced the error. Don't know if something changes with more complex cases (w/ hints, nested call to imported libraries) but as is, it can be implemented without too much hassle imo

"2": {
  "accessible_scopes": [
    "__main__",
    "__main__.main"
  ],
  "flow_tracking_data": {
    "ap_tracking": {
      "group": 0,
      "offset": 1
    },
    "reference_ids": {
      "__main__.main.__temp0": 1,
      "__main__.main.range_check_ptr": 0
    }
  },
  "hints": [],
  "inst": {
    "end_col": 35,
    "end_line": 4,
    "input_file": {
      "filename": "cairo_programs/cairo_0/bad_programs/bad_range_check_builtin.cairo"
    },
    "start_col": 5,
    "start_line": 4
  }
},