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

Rename cairo-rs to cairo-vm #1289

Merged
merged 6 commits into from Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/rust.yml
Expand Up @@ -331,7 +331,7 @@ jobs:
- program-target: cairo_test_programs
programs-dir: cairo_programs
extra-args: ''
name: Compute memory and execution traces with cairo-rs
name: Compute memory and execution traces with cairo-vm
needs: [ build-programs, build-release ]
runs-on: ubuntu-22.04
steps:
Expand Down Expand Up @@ -402,7 +402,7 @@ jobs:
strategy:
matrix:
program-target: [ cairo_proof_programs, cairo_test_programs ]
name: Compare memory and execution traces from cairo-lang and cairo-rs
name: Compare memory and execution traces from cairo-lang and cairo-vm
needs: [ run-cairo-reference, run-cairo-release ]
runs-on: ubuntu-22.04
steps:
Expand All @@ -418,7 +418,7 @@ jobs:
key: ${{ matrix.program-target }}-reference-trace-cache-${{ hashFiles( 'cairo_programs/**/*.cairo' ) }}
fail-on-cache-miss: true

- name: Fetch traces for cairo-rs
- name: Fetch traces for cairo-vm
uses: actions/cache/restore@v3
with:
path: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test_install.yml
@@ -1,4 +1,4 @@
name: Test dependencies and cairo-rs install
name: Test dependencies and cairo-vm install

on:
merge_group:
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Expand Up @@ -11,8 +11,8 @@
**/*.swp
bench/results
.python-version
cairo-rs-env/*
cairo-rs-pypy-env/*
cairo-vm-env/*
cairo-vm-pypy-env/*
cairo/

ensure-no_std/Cargo.lock
360 changes: 181 additions & 179 deletions CHANGELOG.md

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions CONTRIBUTING.md
Expand Up @@ -29,11 +29,11 @@ All types of contributions are encouraged and valued. See the [Table of Contents

> If you want to ask a question, we assume that you have read the available [Documentation](docs/).

Before you ask a question, it is best to search for existing [Issues](https://github.com/lambdaclass/cairo-rs/issues) that might help you. In case you have found a suitable issue and still need clarification, you can write your question in this issue. It is also advisable to search the internet for answers first.
Before you ask a question, it is best to search for existing [Issues](https://github.com/lambdaclass/cairo-vm/issues) that might help you. In case you have found a suitable issue and still need clarification, you can write your question in this issue. It is also advisable to search the internet for answers first.

If you then still feel the need to ask a question and need clarification, we recommend the following:

- Open an [Issue](https://github.com/lambdaclass/cairo-rs/issues/new).
- Open an [Issue](https://github.com/lambdaclass/cairo-vm/issues/new).
- Provide as much context as you can about what you're running into.
- Provide project and platform versions (cairo language, rust compiler, Python, etc), depending on what seems relevant.

Expand Down Expand Up @@ -73,7 +73,7 @@ A good bug report shouldn't leave others needing to chase you up for more inform

We use GitHub issues to track bugs and errors. If you run into an issue with the project:

- Open an [Issue](https://github.com/lambdaclass/cairo-rs/issues/new). (Since we can't be sure at this point whether it is a bug or not, we ask you not to talk about a bug yet and not to label the issue.)
- Open an [Issue](https://github.com/lambdaclass/cairo-vm/issues/new). (Since we can't be sure at this point whether it is a bug or not, we ask you not to talk about a bug yet and not to label the issue.)
- Explain the behavior you would expect and the actual behavior.
- Please provide as much context as possible and describe the *reproduction steps* that someone else can follow to recreate the issue on their own. This usually includes your code. For good bug reports you should isolate the problem and create a reduced test case.
- Provide the information you collected in the previous section.
Expand All @@ -96,19 +96,19 @@ This section guides you through submitting an enhancement suggestion for CONTRIB

- Make sure that you are using the latest version.
- Read the [documentation](docs/) carefully and find out if the functionality is already covered, maybe by an individual configuration.
- Perform a [search](https://github.com/lambdaclass/cairo-rs/issues) to see if the enhancement has already been suggested. If it has, add a comment to the existing issue instead of opening a new one.
- Perform a [search](https://github.com/lambdaclass/cairo-vm/issues) to see if the enhancement has already been suggested. If it has, add a comment to the existing issue instead of opening a new one.
- Find out whether your idea fits with the scope and aims of the project. It's up to you to make a strong case to convince the project's developers of the merits of this feature. Keep in mind that we want features that will be useful to the majority of our users and not just a small subset. If you're just targeting a minority of users, consider writing an add-on/plugin library.


#### How Do I Submit a Good Enhancement Suggestion?

Enhancement suggestions are tracked as [GitHub issues](https://github.com/lambdaclass/cairo-rs/issues).
Enhancement suggestions are tracked as [GitHub issues](https://github.com/lambdaclass/cairo-vm/issues).

- Use a **clear and descriptive title** for the issue to identify the suggestion.
- Provide a **step-by-step description of the suggested enhancement** in as many details as possible.
- **Describe the current behavior** and **explain which behavior you expected to see instead** and why. At this point you can also tell which alternatives do not work for you.
- You may want to **include screenshots and animated GIFs** which help you demonstrate the steps or point out the part which the suggestion is related to. You can use [this tool](https://www.cockos.com/licecap/) to record GIFs on macOS and Windows, and [this tool](https://github.com/colinkeenan/silentcast) or [this tool](https://github.com/GNOME/byzanz) on Linux.
- **Explain why this enhancement would be useful** to most cairo-rs users. You may also want to point out the other projects that solved it better and which could serve as inspiration.
- **Explain why this enhancement would be useful** to most cairo-vm users. You may also want to point out the other projects that solved it better and which could serve as inspiration.


<!-- TODO
Expand Down
30 changes: 15 additions & 15 deletions Makefile
@@ -1,5 +1,5 @@
RELBIN:=target/release/cairo-rs-run
DBGBIN:=target/debug/cairo-rs-run
RELBIN:=target/release/cairo-vm-run
DBGBIN:=target/debug/cairo-vm-run
STARKNET_COMPILE:=cairo/target/release/starknet-compile
STARKNET_SIERRA_COMPILE:=cairo/target/release/starknet-sierra-compile

Expand All @@ -8,7 +8,7 @@ STARKNET_SIERRA_COMPILE:=cairo/target/release/starknet-sierra-compile
compare_vm_output compare_trace_memory compare_trace compare_memory \
compare_trace_memory_proof compare_trace_proof compare_memory_proof \
cairo_bench_programs cairo_proof_programs cairo_test_programs \
cairo_trace cairo-rs_trace cairo_proof_trace cairo-rs_proof_trace \
cairo_trace cairo-vm_trace cairo_proof_trace cairo-vm_proof_trace \
$(RELBIN) $(DBGBIN) $(STARKNET_COMPILE) $(STARKNET_SIERRA_COMPILE)

# Proof mode consumes too much memory with cairo-lang to execute
Expand Down Expand Up @@ -125,23 +125,23 @@ cargo-deps:

deps: cargo-deps build-cairo-1-compiler
pyenv install -s pypy3.9-7.3.9
PYENV_VERSION=pypy3.9-7.3.9 python -m venv cairo-rs-pypy-env
. cairo-rs-pypy-env/bin/activate ; \
PYENV_VERSION=pypy3.9-7.3.9 python -m venv cairo-vm-pypy-env
. cairo-vm-pypy-env/bin/activate ; \
pip install -r requirements.txt ; \
pyenv install -s 3.9.15
PYENV_VERSION=3.9.15 python -m venv cairo-rs-env
. cairo-rs-env/bin/activate ; \
PYENV_VERSION=3.9.15 python -m venv cairo-vm-env
. cairo-vm-env/bin/activate ; \
pip install -r requirements.txt ; \

deps-macos: cargo-deps build-cairo-1-compiler
brew install gmp
arch -x86_64 pyenv install -s pypy3.9-7.3.9
PYENV_VERSION=pypy3.9-7.3.9 python -m venv cairo-rs-pypy-env
. cairo-rs-pypy-env/bin/activate ; \
PYENV_VERSION=pypy3.9-7.3.9 python -m venv cairo-vm-pypy-env
. cairo-vm-pypy-env/bin/activate ; \
CFLAGS=-I/opt/homebrew/opt/gmp/include LDFLAGS=-L/opt/homebrew/opt/gmp/lib pip install -r requirements.txt ; \
pyenv install -s 3.9.15
PYENV_VERSION=3.9.15 python -m venv cairo-rs-env
. cairo-rs-env/bin/activate ; \
PYENV_VERSION=3.9.15 python -m venv cairo-vm-env
. cairo-vm-env/bin/activate ; \
CFLAGS=-I/opt/homebrew/opt/gmp/include LDFLAGS=-L/opt/homebrew/opt/gmp/lib pip install -r requirements.txt ; \

$(RELBIN):
Expand All @@ -161,10 +161,10 @@ cairo_bench_programs: $(COMPILED_BENCHES)
cairo_1_test_contracts: $(COMPILED_CASM_CONTRACTS)

cairo_proof_trace: $(CAIRO_TRACE_PROOF) $(CAIRO_MEM_PROOF)
cairo-rs_proof_trace: $(CAIRO_RS_TRACE_PROOF) $(CAIRO_RS_MEM_PROOF)
cairo-vm_proof_trace: $(CAIRO_RS_TRACE_PROOF) $(CAIRO_RS_MEM_PROOF)

cairo_trace: $(CAIRO_TRACE) $(CAIRO_MEM)
cairo-rs_trace: $(CAIRO_RS_TRACE) $(CAIRO_RS_MEM)
cairo-vm_trace: $(CAIRO_RS_TRACE) $(CAIRO_RS_MEM)

test: $(COMPILED_PROOF_TESTS) $(COMPILED_TESTS) $(COMPILED_BAD_TESTS) $(COMPILED_NORETROCOMPAT_TESTS) $(COMPILED_CASM_CONTRACTS)
cargo llvm-cov nextest --no-report --workspace --features "test_utils, cairo-1-hints"
Expand Down Expand Up @@ -232,6 +232,6 @@ clean:
rm -f $(TEST_PROOF_DIR)/*.json
rm -f $(TEST_PROOF_DIR)/*.memory
rm -f $(TEST_PROOF_DIR)/*.trace
rm -rf cairo-rs-env
rm -rf cairo-rs-pypy-env
rm -rf cairo-vm-env
rm -rf cairo-vm-pypy-env
rm -rf cairo
42 changes: 21 additions & 21 deletions README.md
@@ -1,15 +1,15 @@
<div align="center">
<img src="./bonaparte.webp" height="150">

### ⚡ Cairo-rs
### ⚡ Cairo-vm

A faster and safer implementation of the Cairo VM in Rust

[Report Bug](https://github.com/lambdaclass/cairo-rs/issues/new?labels=bug&title=bug%3A+) · [Request Feature](https://github.com/lambdaclass/cairo-rs/issues/new?labels=enhancement&title=feat%3A+)
[Report Bug](https://github.com/lambdaclass/cairo-vm/issues/new?assignees=&labels=bug&projects=&template=bug_report.md&title=bug%3A+) · [Request Feature](https://github.com/lambdaclass/cairo-vm/issues/new?labels=enhancement&title=feat%3A+)

[![rust](https://github.com/lambdaclass/cairo-rs/actions/workflows/rust.yml/badge.svg)](https://github.com/lambdaclass/cairo-rs/actions/workflows/rust.yml)
[![codecov](https://img.shields.io/codecov/c/github/lambdaclass/cairo-rs)](https://codecov.io/gh/lambdaclass/cairo-rs)
[![license](https://img.shields.io/github/license/lambdaclass/cairo-rs)](/LICENSE)
[![rust](https://github.com/lambdaclass/cairo-vm/actions/workflows/rust.yml/badge.svg)](https://github.com/lambdaclass/cairo-vm/actions/workflows/rust.yml)
[![codecov](https://img.shields.io/codecov/c/github/lambdaclass/cairo-vm)](https://codecov.io/gh/lambdaclass/cairo-vm)
[![license](https://img.shields.io/github/license/lambdaclass/cairo-vm)](/LICENSE)
[![pr-welcome]](#-contributing)
[![Telegram Chat][tg-badge]][tg-url]

Expand All @@ -27,7 +27,7 @@ A faster and safer implementation of the Cairo VM in Rust
- [Getting Started](#-getting-started)
- [Dependencies](#dependencies)
- [Usage](#-usage)
- [Running cairo-rs](#running-cairo-rs)
- [Running cairo-vm](#running-cairo-vm)
- [Using hints](#using-hints)
- [Running a function in a Cairo program with arguments](#running-a-function-in-a-cairo-program-with-arguments)
- [WebAssembly Demo](#webassembly-demo)
Expand All @@ -46,7 +46,7 @@ A faster and safer implementation of the Cairo VM in Rust

## ⚠️ Disclaimer

🚧 `cairo-rs` is still being built therefore breaking changes might happen often so use it at your own risk. 🚧
🚧 `cairo-vm` is still being built therefore breaking changes might happen often so use it at your own risk. 🚧
Cargo doesn't comply with [semver](https://semver.org/), so we advise to pin the version to 0.1.0. This can be done adding `cairo-vm = "0.1.0"` to your Cargo.toml

## 📖 About
Expand Down Expand Up @@ -81,7 +81,7 @@ These dependencies are only necessary in order to run the original VM, compile C

## 🚀 Usage

### Adding cairo-rs as a dependency
### Adding cairo-vm as a dependency

You can add the following to your rust project's `Cargo.toml`:

Expand All @@ -91,7 +91,7 @@ cairo-vm = { version = '0.7.0', features = ["lambdaworks-felt"] }

The `features = ["lambdaworks-felt"]` part adds usage of [`lambdaworks-math`](https://github.com/lambdaclass/lambdaworks) as the backend for `Felt252`. This improves performance by more than 20%, and will be the default in the future.

### Running cairo-rs from CLI
### Running cairo-vm from CLI

To run programs from the command line, first compile the repository from the cairo-vm-cli folder:

Expand Down Expand Up @@ -120,15 +120,15 @@ The flag `--layout` determines which builtins can be used. More info about layou
To sum up, the following code will get you from zero to running a Cairo program:

```bash
git clone https://github.com/lambdaclass/cairo-rs.git
git clone https://github.com/lambdaclass/cairo-vm.git

cd cairo-rs
cd cairo-vm

cargo build --release

cairo-compile cairo_programs/abs_value_array.cairo --output cairo_programs/abs_value_array_compiled.json

target/release/cairo-rs-run cairo_programs/abs_value_array_compiled.json --layout all_cairo
target/release/cairo-vm-run cairo_programs/abs_value_array_compiled.json --layout all_cairo
```

### Using hints
Expand All @@ -137,12 +137,12 @@ Currently, as this VM is under construction, it's missing some of the features o

There are two ways to use non-standard hints in this VM:

- Extend the cairo-rs code and build your own binary using the interface [HintProcessor](docs/hint_processor/README.md).
- Use [cairo-rs-py](https://github.com/lambdaclass/cairo-rs-py) which supports running any hint in a Python interpreter.
- Extend the cairo-vm code and build your own binary using the interface [HintProcessor](docs/hint_processor/README.md).
- Use [cairo-vm-py](https://github.com/lambdaclass/cairo-vm-py) which supports running any hint in a Python interpreter.

### Running a function in a Cairo program with arguments

When running a Cairo program directly using the Cairo-rs repository you would first need to prepare a couple of things.
When running a Cairo program directly using the Cairo-vm repository you would first need to prepare a couple of things.

1. Specify the Cairo program you want to run

Expand Down Expand Up @@ -173,7 +173,7 @@ When running a Cairo program directly using the Cairo-rs repository you would fi
cairo_runner.initialize_segments(&mut vm, None);
```

When using cairo-rs with the Starknet devnet there are additional parameters that are part of the OS context passed on to the `run_from_entrypoint` method that we do not have here when using it directly. These parameters are, for example, initial stacks of the builtins, which are the base of each of them and are needed as they are the implicit arguments of the function.
When using cairo-vm with the Starknet devnet there are additional parameters that are part of the OS context passed on to the `run_from_entrypoint` method that we do not have here when using it directly. These parameters are, for example, initial stacks of the builtins, which are the base of each of them and are needed as they are the implicit arguments of the function.

```rust
let _var = cairo_runner.run_from_entrypoint(
Expand All @@ -190,7 +190,7 @@ When using cairo-rs with the Starknet devnet there are additional parameters tha

### WebAssembly Demo

A demo on how to use `cairo-rs` with WebAssembly can be found
A demo on how to use `cairo-vm` with WebAssembly can be found
[here](https://github.com/lambdaclass/cairo-rs-wasm).

### Testing
Expand All @@ -213,9 +213,9 @@ Running a [Cairo program](./cairo_programs/benchmarks/fibonacci_1000_multirun.ca

- Execution time with [Criterion](./docs/benchmarks/criterion_benchmark.pdf)
- [Flamegraph](./docs/benchmarks/flamegraph.svg)
- Github action [results](https://lambdaclass.github.io/cairo-rs/)
- Github action [results](https://lambdaclass.github.io/cairo-vm/)

Note before running the benchmark suite: the benchmark named [iai_benchmark](https://github.com/lambdaclass/cairo-rs/blob/8dba86dbec935fa04a255e2edf3d5d184950fa22/Cargo.toml#L59) depends on Valgrind. Please make sure it is installed prior to running the `iai_benchmark` benchmark.
Note before running the benchmark suite: the benchmark named [iai_benchmark](https://github.com/lambdaclass/cairo-vm/blob/8dba86dbec935fa04a255e2edf3d5d184950fa22/Cargo.toml#L59) depends on Valgrind. Please make sure it is installed prior to running the `iai_benchmark` benchmark.

Run the complete benchmark suite with cargo:

Expand Down Expand Up @@ -257,8 +257,8 @@ You can find more detailed instructions in the [CONTRIBUTING.md](CONTRIBUTING.md

## 🌞 Related Projects

- [starknet_in_rust](https://github.com/lambdaclass/starknet_in_rust): implementation of Starknet in Rust, powered by the cairo-rs VM.
- [cairo-rs-py](https://github.com/lambdaclass/cairo-rs-py): Bindings for using cairo-rs from Python code.
- [starknet_in_rust](https://github.com/lambdaclass/starknet_in_rust): implementation of Starknet in Rust, powered by the cairo-vm.
- [cairo-vm-py](https://github.com/lambdaclass/cairo-vm-py): Bindings for using cairo-vm from Python code.

## 📚 Documentation

Expand Down
2 changes: 1 addition & 1 deletion bench/run_benchmarks.sh
Expand Up @@ -11,5 +11,5 @@ for file in $(ls $tests_path | grep .cairo | sed -E 's/\.cairo//'); do
hyperfine \
-n "Cairo VM (CPython)" "PYENV_VERSION=3.9.15 cairo-run --proof_mode --memory_file /dev/null --trace_file /dev/null --layout starknet_with_keccak --program $tests_path/$file.json" \
-n "Cairo VM (PyPy)" "PYENV_VERSION=pypy3.9-7.3.9 cairo-run --proof_mode --memory_file /dev/null --trace_file /dev/null --layout starknet_with_keccak --program $tests_path/$file.json" \
-n "cairo-rs (Rust)" "../target/release/cairo-vm-cli $tests_path/$file.json --proof_mode --memory_file /dev/null --trace_file /dev/null --layout starknet_with_keccak"
-n "cairo-vm (Rust)" "../target/release/cairo-vm-cli $tests_path/$file.json --proof_mode --memory_file /dev/null --trace_file /dev/null --layout starknet_with_keccak"
done
12 changes: 6 additions & 6 deletions docs/hint_processor/builtin_hint_processor/README.md
Expand Up @@ -3,20 +3,20 @@ How to run a cairo program with custom hints

### Step by Step Guide:

#### Step 1: Add cairo-rs to your project as a crate
Add cairo-rs as a dependency to your Cargo.toml
#### Step 1: Add cairo-vm to your project as a crate
Add cairo-vm as a dependency to your Cargo.toml

By using either path:

```rust
[dependencies]
cairo-rs = {path = "[path to cairo-rs directory"}
cairo-vm = {path = "[path to cairo-vm directory"}
```

Or by github link:
```rust
[dependencies]
cairo-rs = {git = "https://github.com/lambdaclass/cairo-rs.git"}
cairo-vm = {git = "https://github.com/lambdaclass/cairo-vm.git"}
```

#### Step 2: Code the implementation of your custom hint (Using the helpers and structures described in the sections below)
Expand Down Expand Up @@ -58,7 +58,7 @@ let hint = HintFunc(Box::new(print_a_hint));
```

#### Step 3: Instantiate the BuiltinHintProcessor and add your custom hint implementation
Import the BuiltinHintProcessor from cairo-rs, instantiate it using the `new_empty()` method and the add your custom hint implementation using the method `add_hint`
Import the BuiltinHintProcessor from cairo-vm, instantiate it using the `new_empty()` method and the add your custom hint implementation using the method `add_hint`
```rust
use cairo_vm::hint_processor::builtin_hint_processor::builtin_hint_processor_definition::BuiltinHintProcessor

Expand All @@ -68,7 +68,7 @@ hint_processor.add_hint(String::from("print(ids.a)"), hint);
You can also create a dictionary of HintFunc and use the method `new()` to create a BuiltinHintProcessor with a preset dictionary of functions instead of using `add_hint()` for each custom hint.

#### Step 4: Run your cairo program using BuiltinHintProcessor extended with your hint
Import the function cairo_run from cairo-rs, and run your compiled program
Import the function cairo_run from cairo-vm, and run your compiled program

```rust
use cairo_vm::cairo_run::cairo_run;
Expand Down