diff --git a/.github/workflows/test-bridge.yml b/.github/workflows/test-bridge.yml index 50d8e55..8bd0944 100644 --- a/.github/workflows/test-bridge.yml +++ b/.github/workflows/test-bridge.yml @@ -45,10 +45,7 @@ jobs: run: | sudo apt-get update sudo apt-get install -y clang llvm libudev-dev protobuf-compiler - - uses: rui314/setup-mold@v1 - - uses: software-mansion/setup-scarb@v1 - with: - scarb-version: "2.8.2" + - uses: foundry-rs/foundry-toolchain@v1 with: version: nightly @@ -74,7 +71,7 @@ jobs: uses: actions/checkout@v4 with: repository: madara-alliance/madara - ref: "d188aa91efa78bcc54f92aa1035295fd50e068d2" + ref: "34d629c460a99c731eb71cb4c0603d760dc30a62" path: madara - name: Run anvil @@ -99,9 +96,3 @@ jobs: with: files: lcov.info debug: true - - - name: Upload coverage report to Coveralls - uses: coverallsapp/github-action@v2 - with: - files: lcov.info - debug: true diff --git a/Cargo.lock b/Cargo.lock index d53e657..adb236b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2453,57 +2453,6 @@ dependencies = [ "signature", ] -[[package]] -name = "karnot-bridge-deploy" -version = "0.1.0" -dependencies = [ - "anyhow", - "assert_matches", - "async-trait", - "bytes", - "clap", - "color-eyre", - "dotenv", - "env_logger", - "ethereum-instance", - "ethers", - "flate2", - "hex", - "indexmap 2.2.6", - "inline_colorization", - "lazy_static", - "log", - "num-bigint", - "parity-scale-codec", - "reqwest", - "rstest", - "scale-info", - "serde", - "serde_json", - "serde_with 2.3.3", - "starkgate-manager-client", - "starkgate-registry-client", - "starknet", - "starknet-accounts 0.11.0", - "starknet-core 0.11.1", - "starknet-core-contract-client", - "starknet-crypto 0.7.2", - "starknet-erc20-client", - "starknet-eth-bridge-client", - "starknet-providers 0.11.0", - "starknet-proxy-client", - "starknet-signers 0.9.0", - "starknet-token-bridge-client", - "starknet-types-core", - "starknet_api", - "subxt-lightclient", - "tempfile", - "thiserror", - "tokio", - "url", - "utils", -] - [[package]] name = "keccak" version = "0.1.5" @@ -2676,6 +2625,57 @@ dependencies = [ "hashbrown 0.14.5", ] +[[package]] +name = "madara-bootstrapper" +version = "0.1.0" +dependencies = [ + "anyhow", + "assert_matches", + "async-trait", + "bytes", + "clap", + "color-eyre", + "dotenv", + "env_logger", + "ethereum-instance", + "ethers", + "flate2", + "hex", + "indexmap 2.2.6", + "inline_colorization", + "lazy_static", + "log", + "num-bigint", + "parity-scale-codec", + "reqwest", + "rstest", + "scale-info", + "serde", + "serde_json", + "serde_with 2.3.3", + "starkgate-manager-client", + "starkgate-registry-client", + "starknet", + "starknet-accounts 0.11.0", + "starknet-core 0.11.1", + "starknet-core-contract-client", + "starknet-crypto 0.7.2", + "starknet-erc20-client", + "starknet-eth-bridge-client", + "starknet-providers 0.11.0", + "starknet-proxy-client", + "starknet-signers 0.9.0", + "starknet-token-bridge-client", + "starknet-types-core", + "starknet_api", + "subxt-lightclient", + "tempfile", + "thiserror", + "tokio", + "url", + "utils", +] + [[package]] name = "matrixmultiply" version = "0.2.4" diff --git a/Cargo.toml b/Cargo.toml index 35b3e9d..dc1b648 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "karnot-bridge-deploy" +name = "madara-bootstrapper" version = "0.1.0" edition = "2021" diff --git a/Dockerfile b/Dockerfile index 5901738..6bdeed2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,73 +1,211 @@ # ============================================== # Karnot Bootstrapper # ============================================== -FROM rustlang/rust:nightly-slim as builder -LABEL authors="karnot.xyz" - -# Arguments : -ARG APP_CHAIN_ID -ARG ETH_CHAIN_ID -ARG ETH_PRIV_KEY -ARG ETH_RPC -ARG FEE_TOKEN_ADDRESS -ARG L1_DEPLOYER_ADDRESS -ARG L1_WAIT_TIME -ARG ROLLUP_PRIV_KEY -ARG ROLLUP_SEQ_URL -ARG SN_OS_CONFIG_HASH_VERSION -ARG SN_OS_PROGRAM_HASH -ARG CROSS_CHAIN_WAIT_TIME -ARG LOG_LEVEL -ARG L1_MULTISIG_ADDRESS -ARG L2_MULTISIG_ADDRESS -ARG VERIFIER_ADDRESS -ARG OPERATOR_ADDRESS - -# Assigning the env vars -ENV APP_CHAIN_ID=${APP_CHAIN_ID} \ - ETH_CHAIN_ID=${ETH_CHAIN_ID} \ - ETH_PRIV_KEY=${ETH_PRIV_KEY} \ - ETH_RPC=${ETH_RPC} \ - FEE_TOKEN_ADDRESS=${FEE_TOKEN_ADDRESS} \ - L1_DEPLOYER_ADDRESS=${L1_DEPLOYER_ADDRESS} \ - L1_WAIT_TIME=${L1_WAIT_TIME} \ - ROLLUP_PRIV_KEY=${ROLLUP_PRIV_KEY} \ - SN_OS_CONFIG_HASH_VERSION=${SN_OS_CONFIG_HASH_VERSION} \ - SN_OS_PROGRAM_HASH=${SN_OS_PROGRAM_HASH} \ - CROSS_CHAIN_WAIT_TIME=${CROSS_CHAIN_WAIT_TIME} \ - LOG_LEVEL=${LOG_LEVEL} \ - L1_MULTISIG_ADDRESS=${L1_MULTISIG_ADDRESS} \ - L2_MULTISIG_ADDRESS=${L2_MULTISIG_ADDRESS} \ - VERIFIER_ADDRESS=${VERIFIER_ADDRESS} \ - OPERATOR_ADDRESS=${OPERATOR_ADDRESS} \ - -# adding musl (build failing fix) -ENV RUST_TARGET=x86_64-unknown-linux-musl -ENV PKG_CONFIG_ALLOW_CROSS=1 -RUN apt-get update && apt-get install -y musl-tools -RUN rustup target add x86_64-unknown-linux-musl - -RUN USER=root cargo new --bin karnot-bridge-deploy && chmod -R 777 /karnot-bridge-deploy - -WORKDIR /karnot-bridge-deploy - -# Copy your manifests -COPY ./Cargo.lock ./Cargo.lock -COPY ./Cargo.toml ./Cargo.toml - -# Cache dependencies -RUN cargo build --target x86_64-unknown-linux-musl --release -RUN rm src/*.rs - -# Copy source tree -COPY ./src ./src - -# Build for release -RUN rm -rf ./target/x86_64-unknown-linux-musl/release/deps/karnot_bridge_deploy* -RUN cargo build --target x86_64-unknown-linux-musl --release -RUN mkdir data && touch data/addresses.json - -ENV RUST_LOG=${LOG_LEVEL} - -# Running the program -ENTRYPOINT ["cargo", "run"] \ No newline at end of file +FROM ubuntu:22.04 AS builder + +# Install basic dependencies +RUN apt-get update && apt-get install -y \ + curl \ + build-essential \ + pkg-config \ + libssl-dev \ + git \ + python3 \ + python3-pip \ + python3-venv \ + python3-dev \ + python3-cffi \ + libffi-dev \ + nodejs \ + npm \ + make \ + libgmp-dev \ + g++ \ + unzip \ + cmake \ + software-properties-common \ + && rm -rf /var/lib/apt/lists/* + +# Install Python 3.7 +RUN apt-get update && apt-get install -y software-properties-common && \ + add-apt-repository ppa:deadsnakes/ppa && \ + apt-get update && \ + apt-get install -y \ + python3.7 \ + python3.7-dev \ + python3.7-venv \ + python3.7-distutils \ + && rm -rf /var/lib/apt/lists/* + +# Install pip for Python 3.7 +RUN curl https://bootstrap.pypa.io/pip/3.7/get-pip.py -o get-pip.py && \ + python3.7 get-pip.py && \ + rm get-pip.py + +# Install Python dependencies for legacy build +RUN python3.7 -m pip install --upgrade pip && \ + python3.7 -m pip install cmake==3.22 + +# Install specific solc version for legacy build +RUN curl https://binaries.soliditylang.org/linux-amd64/solc-linux-amd64-v0.6.12+commit.27d51765 -o /usr/local/bin/solc-0.6.12 && \ + echo 'f6cb519b01dabc61cab4c184a3db11aa591d18151e362fcae850e42cffdfb09a /usr/local/bin/solc-0.6.12' | sha256sum --check && \ + chmod +x /usr/local/bin/solc-0.6.12 + +# Setup Python virtual environment for main build +ENV VIRTUAL_ENV=/opt/venv +RUN python3 -m venv $VIRTUAL_ENV +ENV PATH="$VIRTUAL_ENV/bin:$PATH" + +# Upgrade pip and install required Python packages +RUN python3 -m pip install --upgrade pip && \ + python3 -m pip install cffi && \ + python3 -m pip install solc-select && \ + solc-select install 0.8.19 && \ + solc-select use 0.8.19 + +# Install Foundry +SHELL ["/bin/bash", "-c"] +RUN curl -L https://foundry.paradigm.xyz | bash +ENV PATH="/root/.foundry/bin:${PATH}" +RUN source /root/.bashrc && foundryup + +# Install Rust +RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y +ENV PATH="/root/.cargo/bin:${PATH}" + +# Install asdf and scarb +RUN git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.13.1 && \ + echo '. "$HOME/.asdf/asdf.sh"' >> ~/.bashrc && \ + echo '. "$HOME/.asdf/completions/asdf.bash"' >> ~/.bashrc && \ + . "$HOME/.asdf/asdf.sh" && \ + asdf plugin add scarb && \ + asdf install scarb 2.8.4 && \ + asdf global scarb 2.8.4 + +# Set working directory +WORKDIR /app + +# Copy the entire project +COPY . . + +# Initialize and update submodules +RUN git submodule update --init --recursive + +RUN apt-get update && apt-get install -y \ + wget + +RUN curl https://binaries.soliditylang.org/linux-amd64/solc-linux-amd64-v0.6.12+commit.27d51765 -o /usr/local/bin/solc-0.6.12 +RUN echo 'f6cb519b01dabc61cab4c184a3db11aa591d18151e362fcae850e42cffdfb09a /usr/local/bin/solc-0.6.12' | sha256sum --check +RUN chmod +x /usr/local/bin/solc-0.6.12 +RUN npm install -g --unsafe-perm ganache-cli@6.12.2 + +# First run setup-linux +RUN make setup-linux + +# Build legacy starkgate contracts +# Note: This section implements the build steps for old starkgate contracts, +# replacing 'make starkgate-contracts-legacy' from the Makefile. We include these steps +# directly here because running the Makefile command would create a nested +# Docker container inside this build. + +RUN cd lib/starkgate-contracts-old && \ + # First verify ganache-cli installation + which ganache-cli && \ + ganache-cli --version && \ + # Start ganache-cli in background with specific host and port + nohup ganache-cli \ + --host 0.0.0.0 \ + --port 8545 \ + --networkId 1234 \ + --accounts 10 \ + --defaultBalanceEther 1000 \ + --mnemonic "test test test test test test test test test test test junk" \ + --db /tmp/ganache_db \ + > ganache.log 2>&1 & \ + # Store PID and wait + GANACHE_PID=$! && \ + echo "Started Ganache with PID: $GANACHE_PID" && \ + sleep 15 && \ + # Debug: show ganache logs + echo "Ganache logs:" && \ + cat ganache.log && \ + # Debug: check if process is running + ps aux | grep ganache && \ + # Verify ganache is running + curl -v http://localhost:8545 && \ + # Continue with build + rm -rf build && \ + ./build.sh && \ + mkdir -p build/Release && \ + mkdir -p starkgate-artifacts && \ + cp -r build/Release/src/* starkgate-artifacts/ && \ + # Kill ganache after build + kill $GANACHE_PID || true + +# Remove existing Node.js and related packages +RUN apt-get purge -y nodejs nodejs-doc node-gyp libnode-dev && \ + apt-get autoremove -y && \ + rm -rf /etc/apt/sources.list.d/nodesource.list && \ + rm -rf /var/lib/apt/lists/* + +# Install Node.js 18.x +RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && \ + apt-get update && \ + apt-get install -y nodejs && \ + # Install a specific compatible version of npm + npm install -g npm@9.8.1 + +# Install and verify ganache with explicit path and shell +RUN npm install -g --unsafe-perm ganache@7.9.0 && \ + # Verify ganache installation and keep trying if it fails + (for i in {1..5}; do \ + if which ganache && ganache --version; then \ + echo "Ganache installation verified" && \ + break; \ + else \ + echo "Attempt $i: Ganache not found, trying again..." && \ + echo "Searching for ganache in PATH..." && \ + find / -name ganache 2>/dev/null && \ + # Clear npm cache and reinstall + npm cache clean --force && \ + npm install -g --unsafe-perm ganache@7.9.0 && \ + # Add environment variables + export PATH="/usr/local/lib/node_modules/.bin:$PATH" && \ + # Add a small delay to let npm finish + sleep 5; \ + fi; \ + if [ $i -eq 5 ]; then \ + echo "Failed to install ganache after 5 attempts" && \ + exit 1; \ + fi \ + done) + +# Generate other artifacts +RUN . "$HOME/.asdf/asdf.sh" && \ + ls -la /app/.cairo && \ + ls -la /app/.cairo/cairo/bin && \ + export PATH="/app/.cairo/cairo/bin:$PATH" && \ + echo $PATH && \ + which starknet-compile && \ + make starkgate-contracts-latest && \ + make braavos-account-cairo && \ + make argent-contracts-starknet + +# Build the Rust project with specific binary name +RUN cargo build --release --workspace --bin madara-bootstrapper + +# Runtime stage +FROM debian:buster-slim + +# Copy only the compiled binary and artifacts +COPY --from=builder /app/target/release/madara-bootstrapper /usr/local/bin/ +COPY --from=builder /app/artifacts /app/artifacts + +# Set working directory +WORKDIR /app + +# Environment variables +ENV RUST_LOG=info + +# Run the binary +ENTRYPOINT ["/usr/local/bin/madara-bootstrapper"] \ No newline at end of file diff --git a/Makefile b/Makefile index 23283f5..fbe4509 100644 --- a/Makefile +++ b/Makefile @@ -1,21 +1,110 @@ -.PHONY: setup setup-linux starkgate-contracts-latest braavos-account-cairo argent-contracts-starknet artifacts starkgate-contracts-legacy +# ============================================================================= +# Starknet Contract Build System +# ============================================================================= +# This Makefile manages the build process for various Starknet contracts including +# StarkGate, Braavos, and Argent. It handles both legacy and latest versions, +# supporting multiple architectures (amd64/arm64). +.PHONY: setup setup-linux ensure-asdf starkgate-contracts-latest braavos-account-cairo argent-contracts-starknet artifacts starkgate-contracts-legacy + +# ============================================================================= +# Configuration Variables +# ============================================================================= + +# Contract version tags and commit hashes STARKGATE_CONTRACTS_VERSION_TAG="v2.0.1" ARGENT_CONTRACTS_COMMIT_HASH="1352198956f36fb35fa544c4e46a3507a3ec20e3" BRAAVOS_CONTRACTS_COMMIT_HASH="12b82a87b93ba9bfdf2cbbde2566437df2e0c6c8" -# Setup cairo for mac os +# Environment setup +SHELL := /bin/bash +HOME_DIR := $(HOME) + +# Virtual environment paths +VENV_DIR := $(PWD)/venv +VENV_BIN := $(VENV_DIR)/bin +PYTHON := $(VENV_BIN)/python +PIP := $(VENV_BIN)/pip +SOLC_SELECT := $(VENV_BIN)/solc-select +SOLC := $(VENV_BIN)/solc + +# ============================================================================= +# Virtual Environment Setup +# ============================================================================= + +# Target: setup-venv +# Creates and configures Python virtual environment with required dependencies +setup-venv: + python3 -m venv $(VENV_DIR) + $(PIP) install --upgrade pip + $(PIP) install solc-select + $(SOLC_SELECT) install 0.8.24 + $(SOLC_SELECT) use 0.8.24 + $(VENV_BIN)/solc --version + +# ============================================================================= +# ASDF Version Manager Setup +# ============================================================================= + +# Target: ensure-asdf +# Installs and configures ASDF version manager for Scarb +# Handles both macOS (via Homebrew) and Linux installations +ensure-asdf: + @if [ "$$(uname)" = "Darwin" ] && command -v brew >/dev/null 2>&1; then \ + BREW_ASDF_PATH="$$(brew --prefix asdf)/libexec/asdf.sh"; \ + if [ ! -f "$$BREW_ASDF_PATH" ]; then \ + echo "Installing ASDF via Homebrew on macOS..."; \ + brew install asdf; \ + fi; \ + . "$$BREW_ASDF_PATH" && \ + if ! asdf plugin list | grep -q scarb; then \ + asdf plugin add scarb https://github.com/software-mansion/asdf-scarb.git; \ + fi; \ + else \ + if [ ! -f "$(HOME_DIR)/.asdf/asdf.sh" ]; then \ + echo "Cleaning up existing ASDF installation..."; \ + rm -rf $(HOME_DIR)/.asdf; \ + echo "Installing ASDF..."; \ + git clone https://github.com/asdf-vm/asdf.git $(HOME_DIR)/.asdf --branch v0.14.1; \ + echo '. "$(HOME_DIR)/.asdf/asdf.sh"' >> $(HOME_DIR)/.bashrc; \ + fi; \ + if [ -f "$(HOME_DIR)/.asdf/asdf.sh" ]; then \ + . "$(HOME_DIR)/.asdf/asdf.sh" && \ + if ! asdf plugin list | grep -q scarb; then \ + asdf plugin add scarb https://github.com/software-mansion/asdf-scarb.git; \ + fi; \ + else \ + echo "Failed to install ASDF properly"; \ + exit 1; \ + fi; \ + fi + +# ============================================================================= +# Cairo Environment Setup +# ============================================================================= + +# Target: setup +# Sets up Cairo environment for macOS (arm64/amd64) setup: mkdir -p .cairo cd .cairo && \ wget -c https://github.com/starkware-libs/cairo/releases/download/v2.3.0/release-aarch64-apple-darwin.tar -O - | tar -xz +# Target: setup-linux +# Sets up Cairo environment for Linux (x86_64) setup-linux: mkdir -p .cairo cd .cairo && \ - wget -c https://github.com/starkware-libs/cairo/releases/download/v2.3.0/release-x86_64-unknown-linux-musl.tar.gz -O - | tar -xz + wget -c https://github.com/starkware-libs/cairo/releases/download/v2.3.0/release-x86_64-unknown-linux-musl.tar.gz -O - | tar -xz + +# ============================================================================= +# Contract Building Targets +# ============================================================================= -starkgate-contracts-latest: +# Target: starkgate-contracts-latest +# Builds the latest version of StarkGate contracts +# Prerequisites: setup-venv +starkgate-contracts-latest: setup-venv # Building L2 contracts # ===================== cd lib/starkgate-contracts-latest && \ @@ -49,18 +138,19 @@ starkgate-contracts-latest: # Building L1 contracts # ===================== # Configure solidity version - solc-select install 0.8.24 && solc-select use 0.8.24 - # Building + $(SOLC_SELECT) install 0.8.24 && $(SOLC_SELECT) use 0.8.24 && \ cd lib/starkgate-contracts-latest && \ ./scripts/setup.sh && \ FILES=$$(cat src/solidity/files_to_compile.txt) && \ - solc $$FILES --allow-paths .=., --optimize --optimize-runs 200 --overwrite --combined-json abi,bin -o artifacts && \ - ./scripts/extract_artifacts.py + $(SOLC) $$FILES --allow-paths .=., --optimize --optimize-runs 200 --overwrite --combined-json abi,bin -o artifacts && \ + ./scripts/extract_artifacts.py # Copying Contracts mkdir -p artifacts/upgrade-contracts cp lib/starkgate-contracts-latest/artifacts/StarknetEthBridge.json artifacts/upgrade-contracts/eth_bridge_upgraded.json cp lib/starkgate-contracts-latest/artifacts/StarkgateUpgradeAssistExternalInitializer.json artifacts/upgrade-contracts/eic_eth_bridge.json +# Target: starkgate-contracts-legacy +# Builds legacy StarkGate contracts using Docker starkgate-contracts-legacy: # Building Contracts rm -rf lib/starkgate-contracts-old/Dockerfile @@ -75,38 +165,62 @@ starkgate-contracts-legacy: cp ./lib/starkgate-contracts-old/starkgate-artifacts/starkware/starknet/std_contracts/upgradability_proxy/proxy.json ./artifacts/proxy_starkgate.json cp ./lib/starkgate-contracts-old/starkgate-artifacts/starkware/starknet/std_contracts/ERC20/ERC20.json ./artifacts/ERC20.json -braavos-account-cairo: +# Helper function for Scarb-based builds +define scarb_build + @if [ "$$(uname)" = "Darwin" ] && command -v brew >/dev/null 2>&1; then \ + . "$$(brew --prefix asdf)/libexec/asdf.sh"; \ + else \ + . "$(HOME_DIR)/.asdf/asdf.sh"; \ + fi && \ + cd $(1) && \ + git checkout $(2) && \ + asdf install scarb $(3) && \ + asdf local scarb $(3) && \ + scarb build +endef + +# Target: braavos-account-cairo +# Builds Braavos account contracts +# Prerequisites: ensure-asdf +braavos-account-cairo: ensure-asdf # Building - asdf install scarb 2.8.4 && asdf global scarb 2.8.4 - cd ./lib/braavos-account-cairo && \ - git checkout $(BRAAVOS_CONTRACTS_COMMIT_HASH) && \ - ~/.asdf/installs/scarb/2.8.4/bin/scarb build + $(call scarb_build,./lib/braavos-account-cairo,$(BRAAVOS_CONTRACTS_COMMIT_HASH),2.8.4) # Copying Contracts cp ./lib/braavos-account-cairo/target/dev/braavos_account_BraavosAccount.contract_class.json ./artifacts/BraavosAccount.sierra.json cp ./lib/braavos-account-cairo/target/dev/braavos_account_BraavosAccount.compiled_contract_class.json ./artifacts/BraavosAccount.casm.json cp ./lib/braavos-account-cairo/target/dev/braavos_account_BraavosBaseAccount.contract_class.json ./artifacts/BraavosBaseAccount.sierra.json cp ./lib/braavos-account-cairo/target/dev/braavos_account_BraavosBaseAccount.compiled_contract_class.json ./artifacts/BraavosBaseAccount.casm.json -argent-contracts-starknet: +# Target: argent-contracts-starknet +# Builds Argent account contracts +# Prerequisites: ensure-asdf +argent-contracts-starknet: ensure-asdf # Building - asdf install scarb 2.6.3 && asdf global scarb 2.6.3 - cd ./lib/argent-contracts-starknet && \ - git checkout $(ARGENT_CONTRACTS_COMMIT_HASH) && \ - ~/.asdf/installs/scarb/2.6.3/bin/scarb build + $(call scarb_build,./lib/argent-contracts-starknet,$(ARGENT_CONTRACTS_COMMIT_HASH),2.6.3) # Copying Contracts cp ./lib/argent-contracts-starknet/target/dev/argent_ArgentAccount.contract_class.json ./artifacts/ArgentAccount.sierra.json cp ./lib/argent-contracts-starknet/target/dev/argent_ArgentAccount.compiled_contract_class.json ./artifacts/ArgentAccount.casm.json -make build-contracts: +# ============================================================================= +# Main Build Targets +# ============================================================================= + +# Target: build-contracts +# Builds all contracts (legacy and latest versions) +build-contracts: make starkgate-contracts-legacy make starkgate-contracts-latest make braavos-account-cairo make argent-contracts-starknet -make artifacts-linux: +# Target: artifacts-linux +# Builds all artifacts for Linux environment +artifacts-linux: make setup-linux make build-contracts -make artifacts: +# Target: artifacts +# Builds all artifacts for macOS environment +artifacts: make setup make build-contracts \ No newline at end of file diff --git a/Readme.md b/Readme.md index fdf5d1f..f024177 100644 --- a/Readme.md +++ b/Readme.md @@ -1,39 +1,38 @@ -# Madara Bootstrapper 👾 +# Madara Bootstrapper [![Coverage Status](https://coveralls.io/repos/github/madara-alliance/madara-bootstrapper/badge.svg?branch=main)](https://coveralls.io/github/madara-alliance/madara-bootstrapper?branch=main) Madara Bootstrapper is a tool that helps to deploy the **Token Bridge** & **Eth Bridge** contract between a madara/katana Appchain and another L2 or L1 network. It will also declare wallet contracts from **OpenZappelin**, **Argent** and **Braavos**. You can find the full list of contracts -in [Info](#info-ℹ) +in the [Information](#information) section. -## Index 📇 +## Index -- [Madara Bootstrap 👾](#madara-bootstrap-) - - [Index 📇](#index-) - - [Testing 🛠ī¸](#testing-) - - [IMP 🚨](#imp-) - - [Run 🚀](#run-) - - [Local đŸ’ģ](#local-) - - [Docker đŸŗ](#docker-) - - [Info ℹī¸](#info-ℹ) - - [Contract Descriptions 🗒ī¸](#contract-descriptions-) - - [Generate Subxt Artifacts 🔨](#to-generate-the-madara-subxt-artifacts-) +- [Madara Bootstrapper](#madara-bootstrapper) + - [Index](#index) + - [Testing](#testing) + - [Important Notes](#important-notes) + - [Run](#run) + - [Local](#local) + - [Docker](#docker) + - [Information](#information) + - [Contract Descriptions](#contract-descriptions) -**Currently Supported :** +**Currently Supported:** - Madara App Chain <----> Ethereum / EVM based chains -- 👷đŸŧ more coming soon...... +- More coming soon... -## Testing 🛠ī¸ +## Testing -There are three test in the repository : +There are three test in the repository: - bridge deployment e2e - eth bridge deposit and claim - erc20 token bridge deposit and claim -### IMP 🚨 +### Important Notes - You need to comment/remove the #[ignore] tags in [src/tests/mod.rs](src/tests/mod.rs) file - Only one test can be run at one time as all the tests are e2e tests. @@ -54,9 +53,9 @@ There are three test in the repository : RUST_LOG=debug cargo test -- --nocapture ``` -## Run 🚀 +## Run -### Local đŸ’ģ +### Local You can provide the env variables as arguments also, or you can also provide them in .env file. @@ -76,7 +75,7 @@ RUST_LOG=info cargo run -- --dev **IMP 🚨** : It will store all the addresses in [data/addresses.json](data/addresses.json) -### Docker đŸŗ +### Docker 1. You need to set up the .env file first. Fill all the variables in .env file @@ -101,9 +100,107 @@ RUST_LOG=info cargo run -- --dev **IMP 🚨** : It will store all the addresses in [data/addresses.json](data/addresses.json) -## Info ℹī¸ +### Ubuntu Setup 🐧 -### Contract Descriptions 🗒ī¸ +To run the Madara Bootstrapper on an Ubuntu machine with AMD architecture, please follow these steps: + +1. **Clone the Repository**: Start by cloning the Madara Bootstrapper repository. + + ```shell + git clone https://github.com/madara-alliance/madara-bootstrapper.git + cd madara-bootstrapper + ``` + +2. **Install Build Essentials**: Ensure you have the necessary build tools. + + ```shell + sudo apt update + sudo apt install build-essential + ``` + +3. **Install Docker**: Docker should be installed and running. + + ```shell + sudo apt install docker.io + sudo systemctl start docker + sudo systemctl enable docker + ``` + +4. **Install Python**: Python3 and its virtual environment package are required. + + ```shell + sudo apt install python3 python3-venv + ``` + +5. **Install Node.js and npm**: These are required for JavaScript dependencies. + + ```shell + sudo apt install nodejs npm + ``` + +6. **Install asdf**: Use asdf for managing runtime versions. + + ```shell + git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.14.1 + ``` + +7. **Install Rust**: Use rustup to install Rust. + + ```shell + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh + rustup show + ``` + +8. **Create a Python Virtual Environment**: Set up a virtual environment for Python dependencies. + + ```shell + python3 -m venv venv + source venv/bin/activate + ``` + +9. **Build Artifacts**: Use the `make` command to build the necessary artifacts within the Madara Bootstrapper repository. + + ```shell + make artifacts-linux # For Linux + make artifacts # For macOS + ``` + + > **Note**: In case you get an error related to permission, try running the command with `sudo` + +10. **Build the Rust Binary**: Compile the Rust project. + + ```shell + cargo build --release + ``` + +11. **Run the Setup Command for L1**: Execute the following command to set up the L1 environment. Make sure to update the `devnet.json` file as per your needs. + + ```shell + RUST_LOG=debug cargo run --release -- --mode setup-l1 --config src/configs/devnet.json + ``` + + > **Note**: The default configuration file is located at `src/configs/devnet.json`. Please update it according to your requirements. + +12. **Update Configuration**: After running the `setup-l1` command, you will receive a response similar to the following: + + ```json + { + "starknet_contract_address": "STARKNET_CONTRACT_ADDRESS", + "starknet_contract_implementation_address": "STARKNET_CONTRACT_IMPLEMENTATION_ADDRESS" + } + ``` + + Update these values in your `devnet.json` or your specific configuration file before proceeding. + +13. **Run the Setup Command for L2**: Now, execute the following command to set up the L2 environment. + + ```shell + RUST_LOG=debug cargo run --release -- --mode setup-l2 --config src/configs/devnet.json + ``` + +## Information + +### Contract Descriptions | Contract | Source Link | Local Path | | --------------------------------------------- | ------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- | diff --git a/src/configs/devnet.json b/src/configs/devnet.json index 1a2b2f0..50331f3 100644 --- a/src/configs/devnet.json +++ b/src/configs/devnet.json @@ -2,6 +2,7 @@ "eth_rpc": "http://127.0.0.1:8545", "eth_priv_key": "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80", "rollup_seq_url": "http://127.0.0.1:9944", + "rollup_declare_v0_seq_url": "http://127.0.0.1:9943", "rollup_priv_key": "0xabcd", "eth_chain_id": 31337, "l1_deployer_address": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", @@ -18,5 +19,6 @@ "operator_address": "0x000000000000000000000000000000000000abcd", "dev": false, "core_contract_address": "0xe7f1725e7734ce288f8367e1bb143e90bb3f0512", - "core_contract_implementation_address": "0x5fbdb2315678afecb367f032d93f642f64180aa3" + "core_contract_implementation_address": "0x5fbdb2315678afecb367f032d93f642f64180aa3", + "core_contract_mode": "Dev" } diff --git a/src/main.rs b/src/main.rs index 96fd15b..000b345 100644 --- a/src/main.rs +++ b/src/main.rs @@ -78,6 +78,7 @@ pub struct ConfigFile { pub eth_rpc: String, pub eth_priv_key: String, pub rollup_seq_url: String, + pub rollup_declare_v0_seq_url: String, pub rollup_priv_key: String, pub eth_chain_id: u64, pub l1_deployer_address: String, @@ -109,6 +110,7 @@ impl Default for ConfigFile { eth_rpc: "http://127.0.0.1:8545".to_string(), eth_priv_key: "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80".to_string(), rollup_seq_url: "http://127.0.0.1:19944".to_string(), + rollup_declare_v0_seq_url: "http://127.0.0.1:19943".to_string(), rollup_priv_key: "0xabcd".to_string(), eth_chain_id: 31337, l1_deployer_address: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266".to_string(), diff --git a/src/setup_scripts/account_setup.rs b/src/setup_scripts/account_setup.rs index 9bb9bfd..e408292 100644 --- a/src/setup_scripts/account_setup.rs +++ b/src/setup_scripts/account_setup.rs @@ -16,7 +16,7 @@ pub async fn account_init<'a>(clients: &'a Clients, arg_config: &'a ConfigFile) // Making temp account for declaration of OZ account Cairo 1 contract let oz_account_class_hash = declare_contract(DeclarationInput::LegacyDeclarationInputs( String::from(OZ_ACCOUNT_PATH), - arg_config.rollup_seq_url.clone(), + arg_config.rollup_declare_v0_seq_url.clone(), clients.provider_l2(), )) .await; diff --git a/src/setup_scripts/braavos.rs b/src/setup_scripts/braavos.rs index 5ed9758..8240f19 100644 --- a/src/setup_scripts/braavos.rs +++ b/src/setup_scripts/braavos.rs @@ -59,7 +59,7 @@ impl<'a> BraavosSetup<'a> { let braavos_aggregator_class_hash = declare_contract(DeclarationInput::LegacyDeclarationInputs( String::from(BRAAVOS_AGGREGATOR_PATH), - self.arg_config.rollup_seq_url.clone(), + self.arg_config.rollup_declare_v0_seq_url.clone(), self.clients.provider_l2(), )) .await; diff --git a/src/setup_scripts/eth_bridge.rs b/src/setup_scripts/eth_bridge.rs index 3f0366f..29f5afa 100644 --- a/src/setup_scripts/eth_bridge.rs +++ b/src/setup_scripts/eth_bridge.rs @@ -56,7 +56,7 @@ impl<'a> EthBridge<'a> { pub async fn setup(&self) -> EthBridgeSetupOutput { let legacy_proxy_class_hash = declare_contract(DeclarationInput::LegacyDeclarationInputs( String::from(PROXY_LEGACY_PATH), - self.arg_config.rollup_seq_url.clone(), + self.arg_config.rollup_declare_v0_seq_url.clone(), self.clients.provider_l2(), )) .await; @@ -67,7 +67,7 @@ impl<'a> EthBridge<'a> { let starkgate_proxy_class_hash = declare_contract(DeclarationInput::LegacyDeclarationInputs( String::from(STARKGATE_PROXY_PATH), - self.arg_config.rollup_seq_url.clone(), + self.arg_config.rollup_declare_v0_seq_url.clone(), self.clients.provider_l2(), )) .await; @@ -78,7 +78,7 @@ impl<'a> EthBridge<'a> { let erc20_legacy_class_hash = declare_contract(DeclarationInput::LegacyDeclarationInputs( String::from(ERC20_LEGACY_PATH), - self.arg_config.rollup_seq_url.clone(), + self.arg_config.rollup_declare_v0_seq_url.clone(), self.clients.provider_l2(), )) .await; @@ -89,7 +89,7 @@ impl<'a> EthBridge<'a> { let legacy_eth_bridge_class_hash = declare_contract(DeclarationInput::LegacyDeclarationInputs( String::from(LEGACY_BRIDGE_PATH), - self.arg_config.rollup_seq_url.clone(), + self.arg_config.rollup_declare_v0_seq_url.clone(), self.clients.provider_l2(), )) .await; diff --git a/src/setup_scripts/udc.rs b/src/setup_scripts/udc.rs index 0773c9a..2d2852e 100644 --- a/src/setup_scripts/udc.rs +++ b/src/setup_scripts/udc.rs @@ -38,7 +38,7 @@ impl<'a> UdcSetup<'a> { pub async fn setup(&self) -> UdcSetupOutput { let udc_class_hash = declare_contract(DeclarationInput::LegacyDeclarationInputs( String::from(UDC_PATH), - self.arg_config.rollup_seq_url.clone(), + self.arg_config.rollup_declare_v0_seq_url.clone(), self.clients.provider_l2(), )) .await; diff --git a/src/tests/constants.rs b/src/tests/constants.rs index f55b97a..bae2fe1 100644 --- a/src/tests/constants.rs +++ b/src/tests/constants.rs @@ -1,6 +1,7 @@ pub const ETH_RPC: &str = "http://127.0.0.1:8545"; pub const ETH_PRIV_KEY: &str = "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"; pub const ROLLUP_SEQ_URL: &str = "http://127.0.0.1:19944"; +pub const ROLLUP_DECLARE_V0_SEQ_URL: &str = "http://127.0.0.1:19943"; pub const ROLLUP_PRIV_KEY: &str = "0xabcd"; pub const ETH_CHAIN_ID: &str = "31337"; pub const L1_DEPLOYER_ADDRESS: &str = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"; diff --git a/src/tests/mod.rs b/src/tests/mod.rs index 2bfbff6..ff145f5 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -181,8 +181,9 @@ async fn wait_for_madara() -> color_eyre::Result<()> { .arg("0") .arg("--blob-gas-price") .arg("0") - .arg("--rpc-methods") - .arg("unsafe") + .arg("--rpc-admin") + .arg("--rpc-admin-port") + .arg("19943") .arg("--l1-endpoint") .arg("http://localhost:8545") .spawn()?;