cairo-rs VM keeps growing 😎 We are currently adding support for the VM to be used by and interact with existing #StarkNet code and execute user-defined Python hints. github.com/lambdaclass/ca…
To achieve this we are using the PyO3 crate which provides Rust bindings for Python, allowing us to share structures and functions between our VM and a Python context. pyo3.rs/v0.17.1/
Our main use cases for PyO3 are to allow us to run hints written in Python by sharing our VM state with a Python context during our Rust VM execution, and also to be able to instantiate and run our VM from Python, by importing it as a Python module.
PyO3 requires the Python context to own the objects that are being passed through it. This presented a problem for us, as we needed to share ownership of the VM between Rust and Python, which goes against Rust's compile-time ownership rules.
In order to solve this, we used a specific pattern that allows ownership rules to be enforced during runtime as opposed to compile time, providing a reference which can both be owned and modified by the Rust and Python contexts. doc.rust-lang.org/book/ch15-05-i…