From a36cc3939a5e5a00b776af7a54962d026fc2aae1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Gonz=C3=A1lez=20Calder=C3=B3n?= Date: Fri, 5 Jul 2024 18:04:14 -0300 Subject: [PATCH 1/6] Add env.sh --- env.sh | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 env.sh diff --git a/env.sh b/env.sh new file mode 100644 index 0000000..504c2cd --- /dev/null +++ b/env.sh @@ -0,0 +1,38 @@ +#!/bin/sh +# +# It sets the LLVM environment variables. +# +# You can copy this file to .envrc/.env and adapt it for your environment. + +case $(uname) in + Darwin) + # If installed with brew + MLIR_SYS_180_PREFIX="$(brew --prefix llvm@18)" + LLVM_SYS_180_PREFIX="$(brew --prefix llvm@18)" + TABLEGEN_180_PREFIX="$(brew --prefix llvm@18)" + + export MLIR_SYS_180_PREFIX + export LLVM_SYS_180_PREFIX + export TABLEGEN_180_PREFIX + ;; + Linux) + # If installed from Debian/Ubuntu repository: + MLIR_SYS_180_PREFIX=/usr/lib/llvm-18 + LLVM_SYS_180_PREFIX=/usr/lib/llvm-18 + TABLEGEN_180_PREFIX=/usr/lib/llvm-18 + + export MLIR_SYS_180_PREFIX + export LLVM_SYS_180_PREFIX + export TABLEGEN_180_PREFIX + ;; +esac + +# export CAIRO_NATIVE_RUNTIME_LIBRARY= +# export RPC_ENDPOINT_MAINNET= +# export RPC_ENDPOINT_TESTNET= + +echo "loaded LLVM environment variables" +echo "remember you must manually set:" +echo "- RPC_ENDPOINT_MAINNET=rpc.endpoint.mainnet.com" +echo "- RPC_ENDPOINT_TESTNET=rpc.endpoint.testnet.com" +echo "- CAIRO_NATIVE_RUNTIME_LIBRARY=path/to/cairo_native/target/release/libcairo_native_runtime.a" From af6a5cde8f0dd267f69f8d3a740bb73e7cb72446 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Gonz=C3=A1lez=20Calder=C3=B3n?= Date: Fri, 5 Jul 2024 18:04:33 -0300 Subject: [PATCH 2/6] Ignore .env/.envrc --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 8130c3a..1a01455 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ debug/ target/ + +.env +.envrc From c2125581105479d93b78b9f2add10aca5a7c6a13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Gonz=C3=A1lez=20Calder=C3=B3n?= Date: Fri, 5 Jul 2024 18:46:23 -0300 Subject: [PATCH 3/6] Add simple makefile --- Makefile | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..2d94132 --- /dev/null +++ b/Makefile @@ -0,0 +1,36 @@ +.PHONY: usage deps build check test clean + +UNAME := $(shell uname) + +usage: + @echo "Usage:" + @echo " deps: Installs the necesarry dependencies." + @echo " build: Builds the crate." + @echo " check: Checks format and lints." + @echo " test: Runs all tests." + @echo " clean: Cleans the built artifacts." + +build: + cargo build --release + # cargo build --release --all-features + +check: + cargo fmt --all -- --check + cargo clippy --all-targets -- -D warnings + # cargo clippy --all-targets --all-features -- -D warnings + +test: + cargo test + # cargo test --profile ci --all-features + +clean: + cargo clean + +deps: +ifeq ($(UNAME), Darwin) +deps: deps-macos +endif +deps: + +deps-macos: + -brew install llvm@18 --quiet From b2c22b7f522834c9f0b88d9aaa868e93cd2d5e52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Gonz=C3=A1lez=20Calder=C3=B3n?= Date: Mon, 8 Jul 2024 11:11:30 -0300 Subject: [PATCH 4/6] Update README.md --- README.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/README.md b/README.md index 28a0a25..19d60aa 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,43 @@ # starknet-replay Provides a way of reading a real Starknet State, so you can re-execute an existing transaction in any of the Starknet networks in an easy way +## Getting Started + +### Prerequisites + +- Linux or macOS (aarch64 included) only for now +- LLVM 18 with MLIR +- Rust 1.78.0 or later, since cairo-native makes use of the u128 abi change. +- Git + +### Setup + +Run the following make target to install dependencies: +```bash +make deps +``` +It will automatically install LLVM 18 with MLIR on macos, if you are using linux you must do it manually. On debian, you can use `apt.llvm.org`, or build it from source. + +This project is integrated with Cairo Native, see [Cairo Native Setup](#cairo-native-setup) to set it up correctly + +Some environment variable are needed, you can automatically set them by sourcing `env.sh`. If the script doesn't adjust to your specific environment you can `cp` it into `.env` or `.envrc` and modify it. +```bash +# Cairo Native +export MLIR_SYS_180_PREFIX=/path/to/llvm-18 +export LLVM_SYS_180_PREFIX=/path/to/llvm-18 +export TABLEGEN_180_PREFIX=/path/to/llvm-18 +export CAIRO_NATIVE_RUNTIME_LIBRARY=/path/to/cairo_native/target/release/libcairo_native_runtime.a +# RPC +export RPC_ENDPOINT_MAINNET=rpc.endpoint.mainnet.com +export RPC_ENDPOINT_TESTNET=rpc.endpoint.testnet.com +``` + +Once you have installed dependencies and set the needed environment variables, you can build the project and run the tests: +```bash +make build +make test +``` + ### Cairo Native Setup Starknet Replay is currenlty integrated with [Cairo Native](https://github.com/lambdaclass/cairo_native), which makes the execution of sierra programs possible through native machine code. To use it, the following needs to be setup: From 2551ca3646156426a466cd9c62ad09d82af4a591 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Gonz=C3=A1lez=20Calder=C3=B3n?= Date: Mon, 8 Jul 2024 11:49:06 -0300 Subject: [PATCH 5/6] Update Cairo Native Setup section --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 19d60aa..ccea3ac 100644 --- a/README.md +++ b/README.md @@ -42,11 +42,12 @@ make test Starknet Replay is currenlty integrated with [Cairo Native](https://github.com/lambdaclass/cairo_native), which makes the execution of sierra programs possible through native machine code. To use it, the following needs to be setup: -- LLVM `18` needs to be installed and the `MLIR_SYS_180_PREFIX` and `TABLEGEN_180_PREFIX` environment variable needs to point to said installation. In macOS, run +- On mac with brew, running `make deps` should have installed LLVM 18 with MLIR, otherwise, you must install it manually. On Debian, you can use `apt.llvm.org`, or build it from source. + +- The `LLVM_SYS_180_PREFIX`, `MLIR_SYS_180_PREFIX` and `TABLEGEN_180_PREFIX` environment variable needs to point to said installation. In macOS, run: ``` - brew install llvm@18 - export MLIR_SYS_180_PREFIX=/opt/homebrew/opt/llvm@18 export LLVM_SYS_180_PREFIX=/opt/homebrew/opt/llvm@18 + export MLIR_SYS_180_PREFIX=/opt/homebrew/opt/llvm@18 export TABLEGEN_180_PREFIX=/opt/homebrew/opt/llvm@18 ``` and you're set. From 955f12897f7133d27bb952e35737b4c04ccf41d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Gonz=C3=A1lez=20Calder=C3=B3n?= Date: Mon, 8 Jul 2024 11:54:11 -0300 Subject: [PATCH 6/6] Update to LLVM_SYS_181_PREFIX --- README.md | 6 +++--- env.sh | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index ccea3ac..ab925c4 100644 --- a/README.md +++ b/README.md @@ -23,8 +23,8 @@ This project is integrated with Cairo Native, see [Cairo Native Setup](#cairo-na Some environment variable are needed, you can automatically set them by sourcing `env.sh`. If the script doesn't adjust to your specific environment you can `cp` it into `.env` or `.envrc` and modify it. ```bash # Cairo Native +export LLVM_SYS_181_PREFIX=/path/to/llvm-18 export MLIR_SYS_180_PREFIX=/path/to/llvm-18 -export LLVM_SYS_180_PREFIX=/path/to/llvm-18 export TABLEGEN_180_PREFIX=/path/to/llvm-18 export CAIRO_NATIVE_RUNTIME_LIBRARY=/path/to/cairo_native/target/release/libcairo_native_runtime.a # RPC @@ -44,10 +44,10 @@ Starknet Replay is currenlty integrated with [Cairo Native](https://github.com/l - On mac with brew, running `make deps` should have installed LLVM 18 with MLIR, otherwise, you must install it manually. On Debian, you can use `apt.llvm.org`, or build it from source. -- The `LLVM_SYS_180_PREFIX`, `MLIR_SYS_180_PREFIX` and `TABLEGEN_180_PREFIX` environment variable needs to point to said installation. In macOS, run: +- The `LLVM_SYS_181_PREFIX`, `MLIR_SYS_180_PREFIX` and `TABLEGEN_180_PREFIX` environment variable needs to point to said installation. In macOS, run: ``` export LLVM_SYS_180_PREFIX=/opt/homebrew/opt/llvm@18 - export MLIR_SYS_180_PREFIX=/opt/homebrew/opt/llvm@18 + export MLIR_SYS_181_PREFIX=/opt/homebrew/opt/llvm@18 export TABLEGEN_180_PREFIX=/opt/homebrew/opt/llvm@18 ``` and you're set. diff --git a/env.sh b/env.sh index 504c2cd..2852364 100644 --- a/env.sh +++ b/env.sh @@ -7,22 +7,22 @@ case $(uname) in Darwin) # If installed with brew + LLVM_SYS_181_PREFIX="$(brew --prefix llvm@18)" MLIR_SYS_180_PREFIX="$(brew --prefix llvm@18)" - LLVM_SYS_180_PREFIX="$(brew --prefix llvm@18)" TABLEGEN_180_PREFIX="$(brew --prefix llvm@18)" + export LLVM_SYS_181_PREFIX export MLIR_SYS_180_PREFIX - export LLVM_SYS_180_PREFIX export TABLEGEN_180_PREFIX ;; Linux) # If installed from Debian/Ubuntu repository: + LLVM_SYS_181_PREFIX=/usr/lib/llvm-18 MLIR_SYS_180_PREFIX=/usr/lib/llvm-18 - LLVM_SYS_180_PREFIX=/usr/lib/llvm-18 TABLEGEN_180_PREFIX=/usr/lib/llvm-18 + export LLVM_SYS_181_PREFIX export MLIR_SYS_180_PREFIX - export LLVM_SYS_180_PREFIX export TABLEGEN_180_PREFIX ;; esac