kkrt-labs / cairo-vm-ts

A typescript implementation of the Cairo VM
Apache License 2.0
20 stars 13 forks source link

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

Open Eikix opened 11 months ago

Eikix commented 11 months ago

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

ClementWalter commented 5 months ago

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

Eikix commented 5 months ago

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

zmalatrax commented 5 months ago

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;
    ^****************************^

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
  }
},