Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Debug scripts #1839

Merged
merged 6 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#### Upcoming Changes

* docs: Add debugging scripts and documentation [#1839](https://github.com/lambdaclass/cairo-vm/pull/1839)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation and this kind of scripts that don't modify the VM doesn't need a line in the changelog
Remove it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I added "documentation" label to ignore the changelog check.


* chore: bump pip `cairo-lang` 0.13.2 [#1827](https://github.com/lambdaclass/cairo-vm/pull/1827)

* chore: bump `cairo-lang-` dependencies to 2.8.0 [#1833](https://github.com/lambdaclass/cairo-vm/pull/1833/files)
Expand Down
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
* [How to run a cairo program with custom hints](./hint_processor/builtin_hint_processor)
* [References parsing](./references_parsing/)
* [Tracer](./tracer/)
* [Debugging](./debugging.md)
31 changes: 31 additions & 0 deletions docs/debugging.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Debugging

## Comparing with Cairo-Lang

If you executed a Cairo0 proof program with both Rust and Python VM, you can use the following scripts to compare their output. They all require `delta` (modern diff) to be installed. If you don't have you can locally change it.

No output when running a differ script implies that there are no differences.

To compare the public inputs, run:
```bash
scripts/air_public_inputs_differ.bash file1 file2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you be a little clearer here.
Instead of file do <AIR-PUBLIC-INPUT-1> <AIR-PUBLIC-INPUT-2>

Try to do the same to the other commands

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

```

To compare the private inputs, run:
```bash
scripts/air_private_inputs_differ.bash file1 file2
```

If you just want to visualize the memory, run:
```bash
scripts/memory_viewer.bash file
```
It will output the memory in two columns: address and value


To compare the memory, run:
```bash
scripts/memory_differ.bash file1 file2
```


6 changes: 6 additions & 0 deletions scripts/air_private_inputs_differ.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

delta \
<(jq -S 'del(.memory_path,.trace_path)' "$1") \
<(jq -S 'del(.memory_path,.trace_path)' "$2") \
-s
6 changes: 6 additions & 0 deletions scripts/air_public_inputs_differ.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

delta \
<(jq -S . "$1") \
<(jq -S . "$2") \
-s
6 changes: 6 additions & 0 deletions scripts/memory_differ.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

delta \
<(hexdump -e '1/8 "%u " 4/8 "%x " "\n"' "$1" | sort -n) \
<(hexdump -e '1/8 "%u " 4/8 "%x " "\n"' "$2" | sort -n) \
-s
5 changes: 5 additions & 0 deletions scripts/memory_viewer.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
#
# outputs memory file in "ADDR VALUE" format, on cell per line

hexdump -e '1/8 "%10u " 4/8 "%x " "\n"' "$1" | sort -n
Loading