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

feat: add initializeSegments method logic #3

Closed
ClementWalter opened this issue Mar 18, 2024 · 5 comments · Fixed by #12
Closed

feat: add initializeSegments method logic #3

ClementWalter opened this issue Mar 18, 2024 · 5 comments · Fixed by #12
Assignees
Labels
hard Requires a good understanding of the whole stack ODHack

Comments

@ClementWalter
Copy link
Owner

ClementWalter commented Mar 18, 2024

Why

The Cairo VM uses memory segments to track values. In short and almost true, a memory segment is just a list of values, ie. here a list of felt (felt is the only native type of cairo, think of felt as uint252).

A run of the VM actually consists in filling values in memory segments; allocating a segment just means creating an empty list at index i in the segments manager of the VM, much like

{
    0: [],
    1: [],
    42: [],
}

could be a memory with 3 initialized segments (with indexes 0, 1 and 42).

Segments can be allocated during the run (when the dev uses the alloc() function) or by the VM itself at the beginning of a run for given builtins. In cairo0, these builtins are declared at the tile level using the % builtin directive, and at the function level using corresponding implicit arguments.

The list of builtins actually available is:

[
  "output",
  "pedersen",
  "range_check",
  "ecdsa",
  "bitwise",
  "ec_op",
  "keccak",
  "poseidon",
]

Each builtin requires its own memory segment as these builtins actually enforces some rules over the segment. For example, the range_check segment will enforce that every values contained in this segment are actually no greater than 2**128.

Consequently, when initializing the VM for running a program, one needs to create as much memory segments as required.

What

The Cairo VM gs uses native sheet columns as memory segments.
The function should add the corresponding column with their header as names next to the Execution column

How

Follow the python VM https://github.com/starkware-libs/cairo-lang/blob/efa9648f57568aad8f8a13fbf027d2de7c63c2c0/src/starkware/cairo/lang/vm/cairo_runner.py#L216
Note that program_base is always the first segment, and Execution the second.

Add a menu in the UI to actually trigger the call

The CairoVM will for now only run the main entrypoint, so the final fp and pc segments should be added last, and their reference be added in the execution segment.

@ClementWalter ClementWalter added the hard Requires a good understanding of the whole stack label Mar 18, 2024
@jaipaljadeja
Copy link

jaipaljadeja commented Mar 18, 2024

i am going through it. can you assign me this?

@KeneePatel
Copy link
Contributor

Hey @jaipaljadeja, I went through this issue and found it to be doable. If you are not working on this, can I pick this up?

@jaipaljadeja
Copy link

jaipaljadeja commented Mar 25, 2024

@ClementWalter can you assign this to kennee please?

@KeneePatel
Copy link
Contributor

Thank you jaipaal. Appreciate it!

@ClementWalter
Copy link
Owner Author

@KeneePatel it's yours now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hard Requires a good understanding of the whole stack ODHack
Projects
None yet
3 participants