Skip to content

Commit

Permalink
chore: rename cairo-rs-py to cairo-vm-py (lambdaclass#1296)
Browse files Browse the repository at this point in the history
* Rename cairo-rs-py to cairo-vm-py

* Update changelog

* Run debian install as default user

* Revert "Run debian install as default user"

This reverts commit 64925ac.

---------

Co-authored-by: Pedro Fontana <fontana.pedro93@gmail.com>
  • Loading branch information
2 people authored and kariy committed Jul 25, 2023
1 parent 076859d commit 03150cf
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,8 @@

#### Upcoming Changes

* chore: change mentions of *cairo-rs-py* to *cairo-vm-py* [#1296](https://github.com/lambdaclass/cairo-vm/pull/1296)

* rename github repo from https://github.com/lambdaclass/cairo-rs to https://github.com/lambdaclass/cairo-vm [#1289](https://github.com/lambdaclass/cairo-vm/pull/1289)

* fix(security): avoid OOM crashes when programs jump to very high invalid addresses.
Expand Down
45 changes: 24 additions & 21 deletions docs/python_rust_integration_specs.md
Expand Up @@ -3,37 +3,40 @@ LambdaClass - StarkWare
#### 20th September 2022

### OVERVIEW
In order to allow cairo-vm to execute any Python code embedded into a Cairo program and to allow a Python context to call cairo-vm, we are adding support to provide communication of the VM state between Rust and Python via FFI bindings using PyO3, as an external crate.

In order to allow cairo-vm to execute any Python code embedded into a Cairo program and to allow a Python context to call cairo-vm, we are adding support to provide communication of the VM state between Rust and Python via FFI bindings using PyO3, as an external crate.

### GOAL
* Be able to efficiently and conveniently allow interactions between Python and cairo-vm.

* Be able to efficiently and conveniently allow interactions between Python and cairo-vm.
* Have an external crate which encapsulates the Python hint execution, and which is able to both run cairo-vm, and be imported as a Python module so that the VM can be ran from a Python process.

### SPECIFICATION

* FFI integration and functionality will be encapsulated in a crate external to cairo-vm. This crate will be called cairo-vm-py.
* The crate cairo-vm-py will behave as a cairo-vm VM wrapper, which can also be imported as a Python module.
* The crate cairo-vm-py will behave as a cairo-vm VM wrapper, which can also be imported as a Python module.
* The cairo-vm-py VM can be run for a set number of steps.
* The cairo-vm-py VM can be run for a set number of steps, paused, and then continue its execution.
* Variables defined by a hint can only be accessed by hints implemented in the same language, i.e., Rust hints are aware only of variables defined by Rust hints and Python hints are aware only of variables defined by Python hints. By Rust hints we refer to those implemented by the built-in hint processor.
* The cairo-vm-py VM can be instantiated by a Python interpreter as a regular object.
* Variables defined by a hint can only be accessed by hints implemented in the same language, i.e., Rust hints are aware only of variables defined by Rust hints and Python hints are aware only of variables defined by Python hints. By Rust hints we refer to those implemented by the built-in hint processor.
* The cairo-vm-py VM can be instantiated by a Python interpreter as a regular object.
* A Rust or Python program can instantiate one or more independent cairo-vm-py VMs, allowing for multiple coexisting VMs.
* When instantiated by a Python interpreter, that same interpreter will be used to execute Python hints.
* When instantiated by a Python interpreter, that same interpreter will be used to execute Python hints.
* Python hints have limited access to the running context (code paths, modules, scopes created by previous hints).
* The syscall handler will be instantiated before the VM run and should be available on the hint locals.
* An instance of a cairo-vm-py VM will be running either a cairo program interpretation loop or a Python hint, but not both at the same time.
* i.e. hints do not run concurrently
* The VM state shared with hints can only be accessed by a single hint at a time.
* The VM memory is private to a VM instance and cannot be shared across different VM instances.
* An instance of a VM will always run on the same thread.
* Multiple instances of a VM can run on the same thread.
* i.e. hints do not run concurrently
* The VM state shared with hints can only be accessed by a single hint at a time.
* The VM memory is private to a VM instance and cannot be shared across different VM instances.
* An instance of a VM will always run on the same thread.
* Multiple instances of a VM can run on the same thread.
* Hint interaction with the VM will be restricted to:
* read-write access to memory (with the methods __setitem__ and __getitem__),
* segments manager (with the methods add, write_arg, get_segments_used_sizes, add_temporary_segments),
* ids (with the methods __setattr__ and __getattr__),
* hint execution scopes,
* read-only access to ap and fp registers.
* Nice to have:
* Drop the GIL during Rust operation to allow to parallelism when using multi-threads instead of process.
* The cairo-vm-py VM can be instantiated by a Rust program, still allowing Python hints in Cairo programs.
* Python hints are supported when running the cairo-vm-py standalone binary (as opposed to importing it from Python) only with the CPython interpreter.
* read-write access to memory (with the methods __setitem__ and __getitem__),
* segments manager (with the methods add, write_arg, get_segments_used_sizes, add_temporary_segments),
* ids (with the methods __setattr__ and __getattr__),
* hint execution scopes,
* read-only access to ap and fp registers.

* Nice to have:
* Drop the GIL during Rust operation to allow to parallelism when using multi-threads instead of process.
* The cairo-vm-py VM can be instantiated by a Rust program, still allowing Python hints in Cairo programs.
* Python hints are supported when running the cairo-vm-py standalone binary (as opposed to importing it from Python) only with the CPython interpreter.
2 changes: 1 addition & 1 deletion vm/src/vm/runners/cairo_runner.rs
Expand Up @@ -1076,7 +1076,7 @@ impl CairoRunner {
}

// Iterates over the program builtins in reverse, calling BuiltinRunner::final_stack on each of them and returns the final pointer
// This method is used by cairo_rs_py to replace starknet functionality
// This method is used by cairo-vm-py to replace starknet functionality
pub fn get_builtins_final_stack(
&self,
vm: &mut VirtualMachine,
Expand Down

0 comments on commit 03150cf

Please sign in to comment.