From 041e87cbb2707aef677773ae091ce922f874e431 Mon Sep 17 00:00:00 2001 From: enitrat Date: Tue, 1 Oct 2024 18:53:54 +0200 Subject: [PATCH 01/11] bump: cairo native --- scripts/setup_cairo_native.sh | 187 ++++++++++++++++++++++++++++++++++ 1 file changed, 187 insertions(+) create mode 100755 scripts/setup_cairo_native.sh diff --git a/scripts/setup_cairo_native.sh b/scripts/setup_cairo_native.sh new file mode 100755 index 000000000..459dea491 --- /dev/null +++ b/scripts/setup_cairo_native.sh @@ -0,0 +1,187 @@ +#!/bin/bash + +install_essential_deps_linux() { + apt-get update -y + apt-get install -y \ + curl \ + jq \ + ripgrep \ + wget \ + ca-certificates \ + gnupg \ + git +} + +setup_llvm_deps() { + case "$(uname)" in + Darwin) + brew update + brew install llvm@19 + + LIBRARY_PATH=/opt/homebrew/lib + MLIR_SYS_190_PREFIX="$(brew --prefix llvm@19)" + LLVM_SYS_191_PREFIX="${MLIR_SYS_190_PREFIX}" + TABLEGEN_190_PREFIX="${MLIR_SYS_190_PREFIX}" + + export LIBRARY_PATH + export MLIR_SYS_190_PREFIX + export LLVM_SYS_191_PREFIX + export TABLEGEN_190_PREFIX + ;; + Linux) + export DEBIAN_FRONTEND=noninteractive + export TZ=America/New_York + + # shellcheck disable=SC2312 + CODENAME=$(grep VERSION_CODENAME /etc/os-release | cut -d= -f2) + if [[ -z ${CODENAME} ]]; then + echo "Error: Unable to determine OS codename" + exit 1 + fi + + # shellcheck disable=SC2312 + echo "deb http://apt.llvm.org/${CODENAME}/ llvm-toolchain-${CODENAME}-19 main" >/etc/apt/sources.list.d/llvm-19.list + echo "deb-src http://apt.llvm.org/${CODENAME}/ llvm-toolchain-${CODENAME}-19 main" >>/etc/apt/sources.list.d/llvm-19.list + # shellcheck disable=SC2312 + if ! wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -; then + echo "Error: Failed to add LLVM GPG key" + exit 1 + fi + + if ! apt-get update && apt-get upgrade -y; then + echo "Error: Failed to update and upgrade packages" + exit 1 + fi + if ! apt-get install -y llvm-19 llvm-19-dev llvm-19-runtime clang-19 clang-tools-19 lld-19 libpolly-19-dev libmlir-19-dev mlir-19-tools; then + echo "Error: Failed to install LLVM packages" + exit 1 + fi + + MLIR_SYS_190_PREFIX=/usr/lib/llvm-19/ + LLVM_SYS_191_PREFIX=/usr/lib/llvm-19/ + TABLEGEN_190_PREFIX=/usr/lib/llvm-19/ + + export MLIR_SYS_190_PREFIX + export LLVM_SYS_191_PREFIX + export TABLEGEN_190_PREFIX + + { + echo "MLIR_SYS_190_PREFIX=${MLIR_SYS_190_PREFIX}" + echo "LLVM_SYS_191_PREFIX=${LLVM_SYS_191_PREFIX}" + echo "TABLEGEN_190_PREFIX=${TABLEGEN_190_PREFIX}" + } >>"${GITHUB_ENV}" + ;; + *) + echo "Error: Unsupported operating system" + exit 1 + ;; + esac + + # GitHub Actions specific + [[ -n ${GITHUB_ACTIONS} ]] && { + { + echo "MLIR_SYS_190_PREFIX=${MLIR_SYS_190_PREFIX}" + echo "LLVM_SYS_191_PREFIX=${LLVM_SYS_191_PREFIX}" + echo "TABLEGEN_190_PREFIX=${TABLEGEN_190_PREFIX}" + } >>"${GITHUB_ENV}" + } +} + +install_rust() { + if command -v cargo >/dev/null 2>&1; then + echo "Rust is already installed with cargo available in PATH." + return 0 + fi + + echo "cargo not found. Installing Rust..." + # shellcheck disable=SC2312 + if ! curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain 1.81.0 --no-modify-path; then + echo >&2 "Failed to install Rust. Aborting." + return 1 + fi + + # shellcheck disable=SC1091 + if [[ -f "${HOME}/.cargo/env" ]]; then + . "${HOME}/.cargo/env" + else + echo >&2 "Failed to find Rust environment file. Aborting." + return 1 + fi + + echo "Rust installed successfully." +} + +install_cairo_native_runtime() { + install_rust || { + echo "Error: Failed to install Rust" + exit 1 + } + + git clone https://github.com/lambdaclass/cairo_native.git + pushd ./cairo_native || exit 1 + git fetch + git checkout fix-clone-drop-for-enum-structs + make deps + make runtime + cp libcairo_native_runtime.a ../libcairo_native_runtime.a + popd || exit 1 + + rm -rf ./cairo_native + + CAIRO_NATIVE_RUNTIME_LIBRARY=$(pwd)/libcairo_native_runtime.a + if [[ -z ${CAIRO_NATIVE_RUNTIME_LIBRARY} ]]; then + echo "Error: Failed to set CAIRO_NATIVE_RUNTIME_LIBRARY" + exit 1 + fi + export CAIRO_NATIVE_RUNTIME_LIBRARY + + echo "CAIRO_NATIVE_RUNTIME_LIBRARY=${CAIRO_NATIVE_RUNTIME_LIBRARY}" + + [[ -n ${GITHUB_ACTIONS} ]] && echo "CAIRO_NATIVE_RUNTIME_LIBRARY=${CAIRO_NATIVE_RUNTIME_LIBRARY}" >>"${GITHUB_ENV}" +} + +main() { + # New argument parsing + SKIP_RUNTIME=false + while getopts ":s" opt; do + case ${opt} in + s) + SKIP_RUNTIME=true + ;; + \?) + echo "Invalid option: ${OPTARG}" 1>&2 + exit 1 + ;; + *) + echo "Error: Unhandled option" 1>&2 + exit 1 + ;; + esac + done + shift $((OPTIND - 1)) + + # shellcheck disable=SC2312 + [[ "$(uname)" == "Linux" ]] && install_essential_deps_linux + + setup_llvm_deps + + if [[ ${SKIP_RUNTIME} == false ]]; then + install_cairo_native_runtime + else + echo "Skipping Cairo native runtime installation" + # Set the environment variable if the library file exists + # shellcheck disable=SC2312 + if [[ -f "$(pwd)/libcairo_native_runtime.a" ]]; then + CAIRO_NATIVE_RUNTIME_LIBRARY=$(pwd)/libcairo_native_runtime.a + export CAIRO_NATIVE_RUNTIME_LIBRARY + echo "CAIRO_NATIVE_RUNTIME_LIBRARY=${CAIRO_NATIVE_RUNTIME_LIBRARY}" + [[ -n ${GITHUB_ACTIONS} ]] && echo "CAIRO_NATIVE_RUNTIME_LIBRARY=${CAIRO_NATIVE_RUNTIME_LIBRARY}" >>"${GITHUB_ENV}" + else + echo "Warning: libcairo_native_runtime.a not found. CAIRO_NATIVE_RUNTIME_LIBRARY not set." + fi + fi + + echo "LLVM and Cairo native runtime dependencies setup completed." +} + +main "$@" From 53436247b2f0655bd5d0728418d1d8cfee6b4dfe Mon Sep 17 00:00:00 2001 From: enitrat Date: Thu, 3 Oct 2024 13:57:51 +0200 Subject: [PATCH 02/11] increase ulimit --- .github/workflows/ef-tests.yml | 130 +++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 .github/workflows/ef-tests.yml diff --git a/.github/workflows/ef-tests.yml b/.github/workflows/ef-tests.yml new file mode 100644 index 000000000..bbee20160 --- /dev/null +++ b/.github/workflows/ef-tests.yml @@ -0,0 +1,130 @@ +name: EF-Tests + +on: + workflow_call: + inputs: + artifact-name: + required: true + type: string + +permissions: read-all + +jobs: + ef-tests: + # trunk-ignore(actionlint/runner-label) + runs-on: ubuntu-latest-16-cores + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Cache cairo-native setup + id: cache-cairo-native + uses: actions/cache@v3 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + ./libcairo_native_runtime.a + key: + ${{ runner.os }}-cairo-native-${{ hashFiles('**/Cargo.lock', + 'scripts/setup_cairo_native.sh') }} + + - name: Make setup script executable + run: chmod +x ./scripts/setup_cairo_native.sh + + - name: Setup Cairo Native + run: | + if [[ "${{ steps.cache-cairo-native.outputs.cache-hit }}" == 'true' ]]; then + sudo ./scripts/setup_cairo_native.sh -s + else + sudo ./scripts/setup_cairo_native.sh + fi + + - name: Set Environment Variables + run: | + echo "MLIR_SYS_190_PREFIX=/usr/lib/llvm-19/" >> $GITHUB_ENV + echo "LLVM_SYS_191_PREFIX=/usr/lib/llvm-19/" >> $GITHUB_ENV + echo "TABLEGEN_190_PREFIX=/usr/lib/llvm-19/" >> $GITHUB_ENV + echo "CAIRO_NATIVE_RUNTIME_LIBRARY=$(pwd)/libcairo_native_runtime.a" >> $GITHUB_ENV + + - name: Checkout ef-tests + uses: actions/checkout@v4 + with: + repository: kkrt-labs/ef-tests + ref: feat/cairo-native + path: ef-tests # Check out to a subdirectory to avoid cleaning the kakarot-ssj directory + + - name: Checkout local skip file + uses: actions/checkout@v4 + with: + sparse-checkout: | + blockchain-tests-skip.yml + sparse-checkout-cone-mode: false + path: skip-file + + - name: Setup ef-tests + run: | + mv skip-file/blockchain-tests-skip.yml ef-tests/blockchain-tests-skip.yml + cd ef-tests + mkdir -p build/common + make setup setup-kakarot-v0 + + - name: Install nextest + uses: taiki-e/install-action@nextest + + - name: Download Kakarot-SSJ build artifacts in v1 + uses: actions/download-artifact@v3 + with: + name: ${{ inputs.artifact-name }} + path: ef-tests/build/v1 + + - name: Move Cairo1Helpers + run: | + mv ef-tests/build/v1/contracts_Cairo1Helpers.compiled_contract_class.json \ + ef-tests/build/common/cairo1_helpers.json + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: 3.10.14 + + # Add this step to verify the file exists + - name: Verify libcairo_native_runtime.a + run: | + echo $CAIRO_NATIVE_RUNTIME_LIBRARY + ls -l $CAIRO_NATIVE_RUNTIME_LIBRARY + + - name: Run tests + working-directory: ef-tests + run: | + set -o pipefail + ulimit -s 16384 + RUST_TEST_THREADS=4 RUST_MIN_STACK=16777216 make ef-test-v1-native | tee data.txt + set +o pipefail + + - name: Retrieve ef-tests execution resources + working-directory: ef-tests + run: python scripts/compute_resources.py + env: + KAKAROT_VERSION: v1 + + - name: Upload resources + uses: actions/upload-artifact@v3 + with: + path: ef-tests/resources + name: resources + + - name: Generate blockchain-tests-skip.yml file + if: github.event_name == 'workflow_dispatch' + working-directory: ef-tests + run: make generate-skip-file + + - name: Upload skip file + if: github.event_name == 'workflow_dispatch' + uses: actions/upload-artifact@v3 + with: + path: ef-tests/blockchain-tests-skip.yml + name: blockchain-tests-skip From 7a56f3b12d7474b8ad80ae77cad3c1278bc60693 Mon Sep 17 00:00:00 2001 From: enitrat Date: Thu, 3 Oct 2024 16:51:35 +0200 Subject: [PATCH 03/11] revert ulimit changes --- .github/workflows/ef-tests.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ef-tests.yml b/.github/workflows/ef-tests.yml index bbee20160..7ada11382 100644 --- a/.github/workflows/ef-tests.yml +++ b/.github/workflows/ef-tests.yml @@ -101,8 +101,7 @@ jobs: working-directory: ef-tests run: | set -o pipefail - ulimit -s 16384 - RUST_TEST_THREADS=4 RUST_MIN_STACK=16777216 make ef-test-v1-native | tee data.txt + RUST_MIN_STACK=16777216 make ef-test-v1-native | tee data.txt set +o pipefail - name: Retrieve ef-tests execution resources From 458615f7fd471bd69a1ec884d471b1156a9989fb Mon Sep 17 00:00:00 2001 From: enitrat Date: Thu, 3 Oct 2024 16:57:42 +0200 Subject: [PATCH 04/11] update native to main --- scripts/setup_cairo_native.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/scripts/setup_cairo_native.sh b/scripts/setup_cairo_native.sh index 459dea491..8b74c612c 100755 --- a/scripts/setup_cairo_native.sh +++ b/scripts/setup_cairo_native.sh @@ -119,8 +119,6 @@ install_cairo_native_runtime() { git clone https://github.com/lambdaclass/cairo_native.git pushd ./cairo_native || exit 1 - git fetch - git checkout fix-clone-drop-for-enum-structs make deps make runtime cp libcairo_native_runtime.a ../libcairo_native_runtime.a From 90aea1c765a40c61aed4b13b295e213c105121b3 Mon Sep 17 00:00:00 2001 From: enitrat Date: Fri, 4 Oct 2024 16:04:01 +0200 Subject: [PATCH 05/11] bump native --- .github/workflows/ef-tests.yml | 2 +- scripts/setup_cairo_native.sh | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ef-tests.yml b/.github/workflows/ef-tests.yml index 7ada11382..d52ad1c92 100644 --- a/.github/workflows/ef-tests.yml +++ b/.github/workflows/ef-tests.yml @@ -54,7 +54,7 @@ jobs: uses: actions/checkout@v4 with: repository: kkrt-labs/ef-tests - ref: feat/cairo-native + ref: dev/bump-native path: ef-tests # Check out to a subdirectory to avoid cleaning the kakarot-ssj directory - name: Checkout local skip file diff --git a/scripts/setup_cairo_native.sh b/scripts/setup_cairo_native.sh index 8b74c612c..ab116fd3c 100755 --- a/scripts/setup_cairo_native.sh +++ b/scripts/setup_cairo_native.sh @@ -119,6 +119,8 @@ install_cairo_native_runtime() { git clone https://github.com/lambdaclass/cairo_native.git pushd ./cairo_native || exit 1 + git fetch + git checkout fix-array-get-drop make deps make runtime cp libcairo_native_runtime.a ../libcairo_native_runtime.a From c8ee91298c34d5c771d0c2e063bf8818ee65d7a0 Mon Sep 17 00:00:00 2001 From: enitrat Date: Fri, 4 Oct 2024 17:18:56 +0200 Subject: [PATCH 06/11] increase stack size in ci runner --- .github/workflows/ef-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ef-tests.yml b/.github/workflows/ef-tests.yml index d52ad1c92..4bf8f2c2f 100644 --- a/.github/workflows/ef-tests.yml +++ b/.github/workflows/ef-tests.yml @@ -101,7 +101,7 @@ jobs: working-directory: ef-tests run: | set -o pipefail - RUST_MIN_STACK=16777216 make ef-test-v1-native | tee data.txt + RUST_MIN_STACK=1342177280 make ef-test-v1-native | tee data.txt set +o pipefail - name: Retrieve ef-tests execution resources From f25c4ce340f7aa3887fe73906a3528f2c5be5902 Mon Sep 17 00:00:00 2001 From: enitrat Date: Mon, 7 Oct 2024 21:46:46 +0200 Subject: [PATCH 07/11] up native --- scripts/setup_cairo_native.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/setup_cairo_native.sh b/scripts/setup_cairo_native.sh index ab116fd3c..b0bab56b6 100755 --- a/scripts/setup_cairo_native.sh +++ b/scripts/setup_cairo_native.sh @@ -120,7 +120,7 @@ install_cairo_native_runtime() { git clone https://github.com/lambdaclass/cairo_native.git pushd ./cairo_native || exit 1 git fetch - git checkout fix-array-get-drop + git checkout add-malloc-tracing make deps make runtime cp libcairo_native_runtime.a ../libcairo_native_runtime.a From b912f92b33121e122ddb0dd8a69093b7441684a3 Mon Sep 17 00:00:00 2001 From: enitrat Date: Thu, 10 Oct 2024 15:05:51 +0200 Subject: [PATCH 08/11] update setup native --- scripts/setup_cairo_native.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/setup_cairo_native.sh b/scripts/setup_cairo_native.sh index b0bab56b6..d64d3300d 100755 --- a/scripts/setup_cairo_native.sh +++ b/scripts/setup_cairo_native.sh @@ -120,7 +120,7 @@ install_cairo_native_runtime() { git clone https://github.com/lambdaclass/cairo_native.git pushd ./cairo_native || exit 1 git fetch - git checkout add-malloc-tracing + git checkout eee6d1981531c5a4466f83ecf8c851feaa91a1c6 make deps make runtime cp libcairo_native_runtime.a ../libcairo_native_runtime.a From cb23ef4d3546769c93d0cf61359fde69434d2ed4 Mon Sep 17 00:00:00 2001 From: enitrat Date: Thu, 21 Nov 2024 12:48:08 +0800 Subject: [PATCH 09/11] bump native to 2.9.0-dev.0 --- .github/workflows/ef-tests.yml | 2 +- scripts/setup_cairo_native.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ef-tests.yml b/.github/workflows/ef-tests.yml index 4bf8f2c2f..39492488a 100644 --- a/.github/workflows/ef-tests.yml +++ b/.github/workflows/ef-tests.yml @@ -101,7 +101,7 @@ jobs: working-directory: ef-tests run: | set -o pipefail - RUST_MIN_STACK=1342177280 make ef-test-v1-native | tee data.txt + RUST_MIN_STACK=1073741824 make ef-test-v1-native | tee data.txt set +o pipefail - name: Retrieve ef-tests execution resources diff --git a/scripts/setup_cairo_native.sh b/scripts/setup_cairo_native.sh index d64d3300d..f49e12b13 100755 --- a/scripts/setup_cairo_native.sh +++ b/scripts/setup_cairo_native.sh @@ -120,7 +120,7 @@ install_cairo_native_runtime() { git clone https://github.com/lambdaclass/cairo_native.git pushd ./cairo_native || exit 1 git fetch - git checkout eee6d1981531c5a4466f83ecf8c851feaa91a1c6 + git checkout 5e60089288c461eca98bf3dbe03cc882778ff677 make deps make runtime cp libcairo_native_runtime.a ../libcairo_native_runtime.a From c2e4ccbfcd8d6b8d79668f34daab97080d6769f9 Mon Sep 17 00:00:00 2001 From: Mathieu <60658558+enitrat@users.noreply.github.com> Date: Mon, 30 Sep 2024 13:24:22 +0200 Subject: [PATCH 10/11] dev: use native in ci (#992) * dev: use native in ci * remove outdated gas reports * fix fmt * fix runtime location * avoid clearing the ssj checkout * use correct working dir * update stack size when running rust ef-tests * update workflows * simplify workflows by avoiding re-building runtimes * rework workflow structure --- .github/workflows/build.yml | 32 ++++++++ .github/workflows/ci.yml | 116 +++-------------------------- .github/workflows/gas_reports.yml | 43 ----------- .github/workflows/gas_snapshot.yml | 34 --------- .github/workflows/test.yml | 25 ++++--- .github/workflows/tests-unit.yml | 26 +++++++ .gitignore | 2 + 7 files changed, 86 insertions(+), 192 deletions(-) create mode 100644 .github/workflows/build.yml delete mode 100644 .github/workflows/gas_reports.yml delete mode 100644 .github/workflows/gas_snapshot.yml create mode 100644 .github/workflows/tests-unit.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 000000000..7cca4d20d --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,32 @@ +name: Reusable Build Workflow + +on: + workflow_call: + inputs: + artifact-name: + required: true + type: string + +permissions: read-all + +jobs: + build: + runs-on: ubuntu-latest + env: + CI_COMMIT_MESSAGE: CI Formatting Auto Commit + CI_COMMIT_AUTHOR: ${{ github.event.repository.name }} CI + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Scarb + uses: software-mansion/setup-scarb@v1 + + - name: Build contracts + run: scarb build -p contracts + + - name: Upload artifacts + uses: actions/upload-artifact@v3 + with: + name: ${{ inputs.artifact-name }} + path: target/dev diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 92fd8de84..b99ecd358 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,118 +16,24 @@ permissions: read-all jobs: build: - runs-on: ubuntu-latest - env: - CI_COMMIT_MESSAGE: CI Formatting Auto Commit - CI_COMMIT_AUTHOR: ${{ github.event.repository.name }} CI - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up Scarb - uses: software-mansion/setup-scarb@v1 - - - name: Build contracts - run: scarb build -p contracts - - - name: Upload artifacts - uses: actions/upload-artifact@v3 - with: - name: kakarot-ssj-build - path: target/dev + uses: ./.github/workflows/build.yml + with: + artifact-name: kakarot-ssj-build tests-unit: - # trunk-ignore(actionlint/runner-label) - runs-on: ubuntu-latest-16-cores - steps: - - uses: actions/checkout@v3 - - uses: foundry-rs/setup-snfoundry@v3 - - uses: software-mansion/setup-scarb@v1 - - run: scarb fmt --check - - run: scarb build - - run: scarb test + uses: ./.github/workflows/tests-unit.yml + with: + run-fmt-check: false ef-tests: - # trunk-ignore(actionlint/runner-label) - runs-on: ubuntu-latest-32-cores - needs: build - steps: - - name: Checkout ef-tests - uses: actions/checkout@v4 - with: - repository: kkrt-labs/ef-tests - - - name: Checkout local skip file - uses: actions/checkout@v4 - with: - sparse-checkout: | - blockchain-tests-skip.yml - sparse-checkout-cone-mode: false - path: skip-file - - - name: Replace the skip files - run: mv skip-file/blockchain-tests-skip.yml blockchain-tests-skip.yml - - - name: Rust cache - uses: Swatinem/rust-cache@v2 - with: - cache-on-failure: "true" - - - name: Setup - run: | - mkdir -p build/common - make setup setup-kakarot-v0 - - - name: Install nextest - uses: taiki-e/install-action@nextest - - - name: Download Kakarot-SSJ build artifacts in v1 - uses: actions/download-artifact@v3 - with: - name: kakarot-ssj-build - path: ./build/v1 - - - name: Move Cairo1Helpers - run: - mv build/v1/contracts_Cairo1Helpers.compiled_contract_class.json - build/common/cairo1_helpers.json - - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: 3.10.14 - - - name: Run tests - run: | - set -o pipefail - make ef-test-v1 | tee data.txt - set +o pipefail - - - name: Retrieve ef-tests execution resources - run: python scripts/compute_resources.py - env: - KAKAROT_VERSION: v1 - - - name: Upload resources - uses: actions/upload-artifact@v3 - with: - path: resources - name: resources - - - name: Generate blockchain-tests-skip.yml file - if: github.event_name == 'workflow_dispatch' - run: make generate-skip-file - - - name: Upload skip file - if: github.event_name == 'workflow_dispatch' - uses: actions/upload-artifact@v3 - with: - path: blockchain-tests-skip.yml - name: blockchain-tests-skip + uses: ./.github/workflows/ef-tests.yml + needs: [build] + with: + artifact-name: kakarot-ssj-build resources: runs-on: ubuntu-latest - needs: ef-tests + needs: [ef-tests] steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/gas_reports.yml b/.github/workflows/gas_reports.yml deleted file mode 100644 index 6200d6329..000000000 --- a/.github/workflows/gas_reports.yml +++ /dev/null @@ -1,43 +0,0 @@ -name: Compare Snapshot - -on: pull_request - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -permissions: - pull-requests: write - -jobs: - compare-snapshot: - permissions: write-all - # trunk-ignore(actionlint/runner-label) - runs-on: ubuntu-latest-16-cores - - steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: 3.9 - - - name: Set up Scarb - uses: software-mansion/setup-scarb@v1 - - - name: Run compare_snapshot script - id: run-script - env: - GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} - continue-on-error: true - run: | - result=$(python scripts/compare_snapshot.py 2>&1) - status=$(echo "$result" | tail -n 1 | awk -F ':' '{print $1}') - echo "$result" >> "$GITHUB_STEP_SUMMARY" - echo "status=$status" >> "$GITHUB_OUTPUT" - - - name: Exit step based on status - if: steps.run-script.outputs.status == 'ERROR' - run: exit 1 diff --git a/.github/workflows/gas_snapshot.yml b/.github/workflows/gas_snapshot.yml deleted file mode 100644 index 3e8ffa6cf..000000000 --- a/.github/workflows/gas_snapshot.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: Generate and Upload Gas Snapshot - -permissions: read-all - -on: - push: - branches: - - main - workflow_dispatch: {} - -jobs: - build: - # trunk-ignore(actionlint/runner-label) - runs-on: ubuntu-latest-16-cores - - steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: 3.x - - name: Set up Scarb - uses: software-mansion/setup-scarb@v1 - - - name: Generate gas snapshot - run: python scripts/gen_snapshot.py - - - name: Upload gas snapshot to GitHub Artifacts - uses: actions/upload-artifact@v2 - with: - name: gas-snapshot - path: gas_snapshot.json diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 32c1a450a..cc095668a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,13 +9,18 @@ concurrency: cancel-in-progress: true jobs: - tests: - # trunk-ignore(actionlint/runner-label) - runs-on: ubuntu-latest-16-cores - steps: - - uses: actions/checkout@v3 - - uses: foundry-rs/setup-snfoundry@v3 - - uses: software-mansion/setup-scarb@v1 - - run: scarb fmt --check - - run: scarb build - - run: scarb test + build: + uses: ./.github/workflows/build.yml + with: + artifact-name: kakarot-ssj-build + + tests-unit: + uses: ./.github/workflows/tests-unit.yml + with: + run-fmt-check: true + + ef-tests: + uses: ./.github/workflows/ef-tests.yml + needs: [build] + with: + artifact-name: kakarot-ssj-build diff --git a/.github/workflows/tests-unit.yml b/.github/workflows/tests-unit.yml new file mode 100644 index 000000000..2ff0ef28d --- /dev/null +++ b/.github/workflows/tests-unit.yml @@ -0,0 +1,26 @@ +name: Reusable Unit Tests Workflow + +on: + workflow_call: + inputs: + run-fmt-check: + type: boolean + default: false + required: false + +permissions: read-all + +jobs: + unit-tests: + runs-on: ubuntu-latest-16-cores # trunk-ignore(actionlint/runner-label) + steps: + - uses: actions/checkout@v4 + - uses: foundry-rs/setup-snfoundry@v3 + - uses: software-mansion/setup-scarb@v1 + + - name: Run format check + if: inputs.run-fmt-check + run: scarb fmt --check + + - name: Run tests + run: scarb test diff --git a/.gitignore b/.gitignore index 0469dd3ad..bcdcc22c4 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ target node_modules/ *.snfoundry_cache cache/ + +scripts/libcairo_native_runtime.a From ad0eb3ccd1c011c0506ced8377f002b2842fd84a Mon Sep 17 00:00:00 2001 From: enitrat Date: Fri, 22 Nov 2024 00:26:32 +0800 Subject: [PATCH 11/11] add debug prints to locate long operations --- crates/evm/src/precompiles/modexp.cairo | 2 ++ crates/utils/src/crypto/modexp/lib.cairo | 4 ++++ crates/utils/src/crypto/modexp/mpnat.cairo | 11 ++++++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/crates/evm/src/precompiles/modexp.cairo b/crates/evm/src/precompiles/modexp.cairo index d2b35b73e..4bf993da8 100644 --- a/crates/evm/src/precompiles/modexp.cairo +++ b/crates/evm/src/precompiles/modexp.cairo @@ -26,6 +26,7 @@ pub impl ModExp of Precompile { } fn exec(input: Span) -> Result<(u64, Span), EVMError> { + println!("Start: Executing Modexp Precompile"); // The format of input is: // // Where every length is a 32-byte left-padded integer representing the number of bytes @@ -98,6 +99,7 @@ pub impl ModExp of Precompile { let output = modexp(base, exponent, modulus); let return_data = output.pad_left_with_zeroes(mod_len); + println!("End: Executing Modexp Precompile"); Result::Ok((gas.into(), return_data)) } } diff --git a/crates/utils/src/crypto/modexp/lib.cairo b/crates/utils/src/crypto/modexp/lib.cairo index a904bf8af..0d0f707ec 100644 --- a/crates/utils/src/crypto/modexp/lib.cairo +++ b/crates/utils/src/crypto/modexp/lib.cairo @@ -7,13 +7,17 @@ use crate::felt_vec::{Felt252VecTrait}; /// Computes `(base ^ exp) % modulus`, where all values are given as big-endian /// encoded bytes. pub fn modexp(base: Span, exp: Span, modulus: Span) -> Span { + println!("Start: MPNAT::from_big_endian operation"); let mut x = MPNatTrait::from_big_endian(base); let mut m = MPNatTrait::from_big_endian(modulus); + println!("End: MPNAT::from_big_endian operation"); if m.digits.len == 1 && m.digits[0] == 0 { return [].span(); } + println!("Start: modpow operation"); let mut result = x.modpow(exp, ref m); + println!("End: modpow operation"); result.digits.to_be_bytes() } diff --git a/crates/utils/src/crypto/modexp/mpnat.cairo b/crates/utils/src/crypto/modexp/mpnat.cairo index 5f461837f..f04238306 100644 --- a/crates/utils/src/crypto/modexp/mpnat.cairo +++ b/crates/utils/src/crypto/modexp/mpnat.cairo @@ -384,9 +384,13 @@ pub impl MPNatTraitImpl of MPNatTrait { } if modulus.is_power_of_two() { // return + println!("Start: modpow_with_power_of_two operation"); return self.modpow_with_power_of_two(exp, ref modulus); + println!("End: modpow_with_power_of_two operation"); } else if modulus.is_odd() { + println!("Start: modpow_montgomery operation"); return self.modpow_montgomery(exp, ref modulus); + println!("End: modpow_montgomery operation"); } // If the modulus is not a power of two and not an odd number then @@ -457,13 +461,18 @@ pub impl MPNatTraitImpl of MPNatTrait { }; let mut base_copy = MPNat { digits: self.digits.duplicate(), }; + println!("Start: modpow_montgomery operation"); let mut x1 = base_copy.modpow_montgomery(exp, ref odd); + println!("End: modpow_montgomery operation"); + println!("Start: modpow_with_power_of_two operation"); let mut x2 = self.modpow_with_power_of_two(exp, ref power_of_two); + println!("End: modpow_with_power_of_two operation"); + println!("Start: koc_2017_inverse operation"); let mut odd_inv = Self::koc_2017_inverse( ref odd, trailing_zeros * WORD_BITS + additional_zero_bits ); - + println!("End: koc_2017_inverse operation"); let s = power_of_two.digits.len(); let mut scratch: Felt252Vec = Felt252VecImpl::new(); scratch.expand(s).unwrap();