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

Casting a felt to a felt pointer results in Int instead of Relocatable #1856

Closed
notlesh opened this issue Oct 18, 2024 · 2 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@notlesh
Copy link

notlesh commented Oct 18, 2024

Describe the bug

When casting a felt to a felt pointer in Cairo0 (such as cast(0, felt*)), cairo-vm writes an Integer to memory instead of a Relocatable.

The OS code does this in a number of cases like: this. This particular case is later used with add_relocation_rule() which always fails because it will only accept a Relocatable.

The following example Cairo code demonstrates the problem:

from starkware.cairo.common.alloc import alloc
func main() {
    alloc_locals;

    let ptr_from_alloc: felt* = alloc();
    let ptr_from_cast_0: felt* = cast(0, felt*);

    %{ breakpoint() %}

    ret;
}

This results in:

[0] "ptr_from_alloc": "RelocatableValue(Relocatable { segment_index: 4, offset: 0 })"
[1] "ptr_from_cast_0": "Int(0)"

To Reproduce

Reproducing this issue can be done by using the cairo0_run binary in this PR. Something like this:

  1. Save the cairo snippet above as test_cast.cairo.
  2. Compile it with cairo-compile, e.g. cairo-compile test_cast.cairo --output test_cast_compiled.json
  3. Run the SNOS cairo0_run binary with the output, e.g. cargo run -p cairo0_run -- --input test_cast_compiled.json
  4. The breakpoint hint will print ids_data, showing the values of the variables

Expected behavior

Based on the OS code in cairo-lang I believe the expectation is that cast in this case should return a Relocatable, but I'm not entirely clear on this.

What version/commit are you on?

58363ad8065ed891e3b14a8191b707677c7c7cb5b9d10030822506786d8d8108 (roughly v1.0.1)

Additional context

We have created a workaround in SNOS here.

@notlesh
Copy link
Author

notlesh commented Oct 29, 2024

Closing this issue as the problem is more intricate (described in #1860). To be clear: the problem described here seems to be "works as intended."

@pefontana
Copy link
Member

great! @notlesh !
let's continue in #1860

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants