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

Handling globals() in Cairo0 hints #455

Open
MaksymMalicki opened this issue Jun 12, 2024 · 1 comment
Open

Handling globals() in Cairo0 hints #455

MaksymMalicki opened this issue Jun 12, 2024 · 1 comment
Labels
cairo zero Exclusively targets cairo zero needs discussion Discuss solution before start implementing it

Comments

@MaksymMalicki
Copy link
Contributor

This issue is only a writeup, on how other VMs handle fetching values from globals() in the Cairo0 hints.

In the Python VM, the initialize_vm method in cairo_runner provides a possibility to pass an optional argument, called static_locals. It is described as:
static_locals - dictionary holding static values for execution. They are available in all scopes., meaning that when the value is passed inside of that object, they will be present in each hint execution scope and used.
static_values are always updated in the constructor of the VirtualMachine, by these values and the ones provided in the constructor. static_locals are then always included in each step during, in the hint execution as globals.

My concern with this solution, is that there is no flag/possibility to pass the static_locals dynamically. They are loaded programatically for example here, which is in the entirely different package, called business logic on a wrapper class which extends from the basic CairoRunner.

What is also concerning, is that is can't find a place, where those static values are loaded into the scopes of rust and even go VMs. During hint execution, lambda VMs fetch constants like __usort_max_size from the current scope, but I don't see any entrypoint where those values are loaded, so that will always result in an error - ValueNotInScope.

After checking both solutions, there are a couple ways of handling this. We could either skip it entirely, since in other implementations there is no way of passing those values dynamically. We could load them from JSON and store them in some separate struct, maybe a field in hintrunner. We could also hardcode the values from the business logic package, but I'm not confident about that solution, since those values are passed externally and clearly are picked for some specific usecase.

@MaksymMalicki MaksymMalicki added cairo zero Exclusively targets cairo zero needs discussion Discuss solution before start implementing it labels Jun 12, 2024
@TAdev0
Copy link
Member

TAdev0 commented Jun 22, 2024

@MaksymMalicki i took some times to check all other cairo VM implementations. Agree with all you said.

globals() is used to fetch some values in 5 hints:

Just sent a message to one of the lead of the lambda rust cairo vm to know how they inject these variables in their exec_scopes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cairo zero Exclusively targets cairo zero needs discussion Discuss solution before start implementing it
Projects
None yet
Development

No branches or pull requests

2 participants