Skip to content

bug: OS addition results in Int(0) for dest_ptr #424

@notlesh

Description

@notlesh

We previously created a workaround for an issue where dest_ptr is not a relocatable in #371. This PR works around the issue, but doesn’t understand or fix it.

I spent some more time looking at this recently and wanted to summarize my findings. I was not able to reproduce the issue with a standalone cairo0 program. It seems the compiler is good about preventing pointers-to-structs from being cast as integers in the way we see in the original issue.

The issue seems to happen when we add 1 to the pointer, that is (from segment_arena.cairo):

  • let dest_ptr = infos[0].end + 1; ⇒ dest_ptr is Int(0)
  • let end_ptr = infos[0].end;
    let dest_ptr = end_ptr + 1;
    ⇒ end_ptr is a proper relocatable, dest_ptr is Int(0)
  • While experimenting with cairo0 code, I found that a ptr to a struct gets a special Python treatment; specifically, it is represented as an instance of starkware.cairo.lang.vm.vm_consts.VmConstsReference. This may impact the way hints are executed (for example, it may have special treatment for the + operator).
  • There are no relocation rules present at the time this code is executed.

Given the above, I think there is something unexpected happening during the addition.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions