Starknet transaction execution library in Rust, featuring ⚡cairo-vm⚡
- Table of Contents
⚠️ Disclaimer- 📖 About
- 🌅 Getting Started
- 🚀 Usage
- 🛠 Contributing
- 🌞 Related Projects
- 📚 Documentation
- ⚖️ License
🚧 This project is a work-in-progress and is not ready for production yet. Use at your own risk. 🚧
starknet_in_rust
is an implementation of Starknet in Rust.
It makes use of cairo-vm, the Rust implementation of the Cairo virtual machine.
- Rust 1.70
- A working installation of cairo-lang 0.12 (for compiling the cairo files)
- [Optional, for testing purposes] Heaptrack
Run the following make targets to have a working environment (if in Mac or if you encounter an error, see the subsection below):
$ make deps
$ make build
$ make deps-macos
$ make build
Check the Makefile for additional targets.
In order to use the RPC state reader add an Infura API key in a .env
file at root:
INFURA_API_KEY={some_key}
cairo-lang
requires the gmp
library to build.
You can install it on Debian-based GNU/Linux distributions with:
sudo apt install -y libgmp3-dev
In Mac you can use Homebrew:
brew install gmp
In Mac you'll also need to tell the script where to find the gmp lib:
export CFLAGS=-I/opt/homebrew/opt/gmp/include LDFLAGS=-L/opt/homebrew/opt/gmp/lib
Starknet in Rust can be integrated with Cairo Native, which makes the execution of sierra programs possible through native machine code. To use it, the following needs to be setup:
- LLVM
17
needs to be installed and theMLIR_SYS_170_PREFIX
andTABLEGEN_170_PREFIX
environment variable needs to point to said installation. In macOS, runand you're set.brew install llvm@17 export MLIR_SYS_170_PREFIX=/opt/homebrew/opt/llvm@17 export TABLEGEN_170_PREFIX=/opt/homebrew/opt/llvm@17
Afterwards, compiling with the feature flag cairo-native
will enable native execution. You can check out some example test code that uses it under tests/cairo_native.rs
.
You can find a tutorial on running contracts here.
You can find an example on how to use the CLI here
This project uses the tracing
crate as a library. Check out
its documentation for more information.
Run the following command:
$ make test
Run the following command:
$ make flamegraph
to generate a flamegraph with info of the execution of the main operations.
Read the 'bench_integration.py' file to identify which lines need to be commented out for accurate results. Comment out those lines and then run the following command:
$ make benchmark
The open source community is a fantastic place for learning, inspiration, and creation, and this is all thanks to contributions from people like you. Your contributions are greatly appreciated.
If you have any suggestions for how to improve the project, please feel free to fork the repo and create a pull request, or open an issue with the tag 'enhancement'.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
And don't forget to give the project a star! ⭐ Thank you again for your support.
- cairo-vm: A fast implementation of the Cairo VM in Rust.
- cairo-vm-py: Bindings for using cairo-vm from Python code.
This project is licensed under the Apache 2.0 license.
See LICENSE for more information.