From 2ac9e1004bcebf306f1fc5b782516ad7d43dcde7 Mon Sep 17 00:00:00 2001 From: Elias Tazartes <66871571+Eikix@users.noreply.github.com> Date: Thu, 27 Jul 2023 18:17:09 +0200 Subject: [PATCH] feat: cleanup kakarot ssj to match latest version of cairo (#38) * feat: cleanup kakarot ssj to match latest version of cairo * fix: fix CI * fix: fix readme --- .github/ISSUE_TEMPLATE/02_FEATURE_REQUEST.md | 18 +----- .github/workflows/lock.yml | 32 ---------- .github/workflows/test.yml | 50 +++------------ Makefile | 62 ------------------- README.md | 35 +++-------- Scarb.toml | 1 + examples/bugs/.gitkeep | 0 scripts/generate_cairo_project.sh | 25 -------- src/lib.cairo | 3 + src/memory.cairo | 2 +- src/stack.cairo | 2 +- tests/lib.cairo => src/tests.cairo | 0 {tests => src/tests}/test_kakarot.cairo | 0 {tests => src/tests}/test_memory.cairo | 0 {tests => src/tests}/test_stack.cairo | 0 {tests => src/tests}/utils.cairo | 0 {tests => src/tests}/utils/test_helpers.cairo | 0 src/utils/helpers.cairo | 17 ----- 18 files changed, 27 insertions(+), 220 deletions(-) delete mode 100644 .github/workflows/lock.yml delete mode 100644 Makefile delete mode 100644 examples/bugs/.gitkeep delete mode 100644 scripts/generate_cairo_project.sh rename tests/lib.cairo => src/tests.cairo (100%) rename {tests => src/tests}/test_kakarot.cairo (100%) rename {tests => src/tests}/test_memory.cairo (100%) rename {tests => src/tests}/test_stack.cairo (100%) rename {tests => src/tests}/utils.cairo (100%) rename {tests => src/tests}/utils/test_helpers.cairo (100%) diff --git a/.github/ISSUE_TEMPLATE/02_FEATURE_REQUEST.md b/.github/ISSUE_TEMPLATE/02_FEATURE_REQUEST.md index 571914791..2ac7dbacb 100644 --- a/.github/ISSUE_TEMPLATE/02_FEATURE_REQUEST.md +++ b/.github/ISSUE_TEMPLATE/02_FEATURE_REQUEST.md @@ -1,33 +1,21 @@ --- name: Feature Request about: Suggest an idea for this project -title: "feat: " -labels: "enhancement" -assignees: "" +title: 'feat: ' +labels: 'enhancement' +assignees: '' --- # Feature Request **Describe the Feature Request** - - **Describe Preferred Solution** - - -**Describe Alternatives** - - - **Related Code** - - **Additional Context** - - **If the feature request is approved, would you be willing to submit a PR?** _(Help can be provided if you need assistance submitting a PR)_ diff --git a/.github/workflows/lock.yml b/.github/workflows/lock.yml deleted file mode 100644 index 20524e841..000000000 --- a/.github/workflows/lock.yml +++ /dev/null @@ -1,32 +0,0 @@ ---- -name: Lock - -on: - schedule: - - cron: "0 9 * * *" - workflow_dispatch: - -jobs: - lock: - name: 🔒 Lock closed issues and PRs - runs-on: ubuntu-latest - steps: - - uses: dessant/lock-threads@v2.0.3 - with: - github-token: ${{ github.token }} - issue-lock-inactive-days: "30" - issue-lock-reason: "" - issue-comment: > - Issue closed and locked due to lack of activity. - - If you encounter this same issue, please open a new issue and refer - to this closed one. - pr-lock-inactive-days: "1" - pr-lock-reason: "" - pr-comment: > - Pull Request closed and locked due to lack of activity. - - If you'd like to build on this closed PR, you can clone it using - this method: https://stackoverflow.com/a/14969986 - - Then open a new PR, referencing this closed PR in your message. diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 10d26b76d..f24c0071c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,48 +1,14 @@ -name: test +name: CI on: [push, pull_request] -env: - CAIRO_COMPILER_VERSION: 1.0.0-rc0 - # Temporary use artifacts from custom CI build - ARTIFACT_RELEASE_ARCHIVE_LINK: https://api.github.com/repos/starkware-libs/cairo/actions/artifacts/689746858/zip - ARTIFACT_RELEASE_ARCHIVE_NAME: cairo.zip - RELEASE_ARCHIVE_NAME: x86_64-unknown-linux-musl.tar.gz - jobs: - build: - name: build - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - run: | - curl -H "Accept: application/vnd.github+json" -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -L -o $ARTIFACT_RELEASE_ARCHIVE_NAME $ARTIFACT_RELEASE_ARCHIVE_LINK - unzip $ARTIFACT_RELEASE_ARCHIVE_NAME - tar -xvf $RELEASE_ARCHIVE_NAME - export PATH=$PATH:$(pwd)/cairo/bin - make build - - run: - name: run - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - run: | - curl -H "Accept: application/vnd.github+json" -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -L -o $ARTIFACT_RELEASE_ARCHIVE_NAME $ARTIFACT_RELEASE_ARCHIVE_LINK - unzip $ARTIFACT_RELEASE_ARCHIVE_NAME - tar -xvf $RELEASE_ARCHIVE_NAME - export PATH=$PATH:$(pwd)/cairo/bin - # TODO: uncomment when demo is ready - #make run - - test: - name: test + tests: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - run: | - curl -H "Accept: application/vnd.github+json" -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -L -o $ARTIFACT_RELEASE_ARCHIVE_NAME $ARTIFACT_RELEASE_ARCHIVE_LINK - unzip $ARTIFACT_RELEASE_ARCHIVE_NAME - tar -xvf $RELEASE_ARCHIVE_NAME - export PATH=$PATH:$(pwd)/cairo/bin - make test + - uses: actions/checkout@v3 + - uses: software-mansion/setup-scarb@v1 + with: + scarb-version: '0.5.2' + - run: scarb fmt --check + - run: scarb test diff --git a/Makefile b/Makefile deleted file mode 100644 index 5770ed2f9..000000000 --- a/Makefile +++ /dev/null @@ -1,62 +0,0 @@ -.PHONY: default - -# Configuration -PROJECT_NAME = kakarot -ENTRYPOINT = . -TEST_ENTRYPOINT = . -BUILD_DIR = build - -# Default target -default: run - -# All relevant targets -all: build run test - -# Targets - -# There is no integration between Scarb and the default `cairo-test` runner. -# Therefore, we need to generate the cairo_project.toml file, required -# by the `cairo-test` runner, manually. This is done by the generate_cairo_project script. -cairo-project: - @echo "Generating cairo project..." - sh scripts/generate_cairo_project.sh -# Test the project - -# Compile the project -build: cairo-project FORCE - $(MAKE) clean format - @echo "Building..." - cairo-compile . > $(BUILD_DIR)/$(PROJECT_NAME).sierra - -# Run the project -run: - @echo "Running..." - #cairo-run -p $(ENTRYPOINT) - - - -test: cairo-project - @echo "Testing..." - cairo-test $(TEST_ENTRYPOINT) - -# Format the project -format: - @echo "Formatting..." - cairo-format src - -# Clean the project -clean: - @echo "Cleaning..." - rm -rf $(BUILD_DIR)/* - mkdir -p $(BUILD_DIR) - -# Special filter tests targets - -# Run tests related to the stack -test-stack: - @echo "Testing stack..." - cairo-test -p $(TEST_ENTRYPOINT) -f stack - -# FORCE is a special target that is always out of date -# It enable to force a target to be executed -FORCE: \ No newline at end of file diff --git a/README.md b/README.md index d8bd97618..d634c9b45 100644 --- a/README.md +++ b/README.md @@ -45,56 +45,41 @@ ## About -**Kakarot** is an Ethereum Virtual Machine written in Cairo. It means it can be -deployed on StarkNet, a layer 2 scaling solution for Ethereum, and run any EVM -bytecode program. Hence, Kakarot can be used to run Ethereum smart contracts on -StarkNet. Kakarot is the super sayajin zkEVM! Why? Because: -`It's over 9000!!!!!`. +Kakarot is an (zk)-Ethereum Virtual Machine implementation written in Cairo. Kakarot is Ethereum compatible, i.e. all existing smart contracts, developer tools and wallets work out-of-the-box on Kakarot. It's been open source from day one. Soon available on Starknet L2 and L3. It is a work in progress, and it is not ready for production. ## Getting Started +This repository is a rewrite of [the first version of Kakarot zkEVM](https://github.com/kkrt-labs/kakarot). + ### Prerequisites - [Cairo](https://github.com/starkware-libs/cairo) -- [Rust](https://www.rust-lang.org/tools/install) - [Scarb](https://docs.swmansion.com/scarb/download) -- [jq](https://stedolan.github.io/jq/download/) ### Installation -> **[TODO]** - -## Usage +- Install Scarb: + - `curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | sh` +- [Fork](https://docs.github.com/en/get-started/quickstart/fork-a-repo) the repository and clone your fork (`git clone https://github.com//kakarot-ssj`) ### Build ```bash -make build -``` - -### Run - -```bash -make run +scarb build ``` ### Test -We use the `cairo-test` runner to run the unit tests on Kakarot. -However, it is not directly compatible with Scarb. Hence, we use a script -to generate the `cairo_project.toml` file from Scarb's metadata. -Running this script requires `jq` to be installed. - ```bash -make test +scarb test ``` ### Format ```bash -make format +scarb fmt ``` ## Roadmap @@ -117,7 +102,7 @@ Reach out to the maintainer at one of the following places: If you want to say **thank you** or/and support active development of Kakarot: - Add a [GitHub Star](https://github.com/sayajin-labs/kakarot-ssj) to the project. -- Tweet about the Kakarot. +- Tweet about [Kakarot](https://twitter.com/KakarotZkEvm). - Write interesting articles about the project on [Dev.to](https://dev.to/), [Medium](https://medium.com/) or your personal blog. Together, we can make Kakarot **better**! diff --git a/Scarb.toml b/Scarb.toml index 929dcec57..21c8c862b 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -1,3 +1,4 @@ [package] +cairo-version = "2.0.2" name = "kakarot" version = "0.1.0" diff --git a/examples/bugs/.gitkeep b/examples/bugs/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/scripts/generate_cairo_project.sh b/scripts/generate_cairo_project.sh deleted file mode 100644 index fa137976b..000000000 --- a/scripts/generate_cairo_project.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash - -# This script is used to generate the `cairo_project.toml` file -# from the Scarb project's metadata. -# It is required to run the `cairo-test` runner. - -# Run the scarb metadata command and store the JSON output in a variable -json_output=$(scarb metadata --format-version 1| sed -n '/^{/,$p') - -# Create a temporary file to store the JSON output -temp_file=$(mktemp) -echo "$json_output" > "$temp_file" - -# Initialize cairo_project.toml file -echo "[crate_roots]" > cairo_project.toml - -# Process the JSON output and create the cairo_project.toml file using jq -jq -r '.packages[] | select(.name != "core" and .name != "kakarot") | .name + " = \"" + .root + "/src\""' "$temp_file" >> cairo_project.toml - -# Add kakarot and tests to the cairo_project.toml -echo 'kakarot = "src"' >> cairo_project.toml -echo 'tests = "tests"' >> cairo_project.toml - -# Remove the temporary file -rm "$temp_file" \ No newline at end of file diff --git a/src/lib.cairo b/src/lib.cairo index a1aaad5eb..4289530b5 100644 --- a/src/lib.cairo +++ b/src/lib.cairo @@ -15,3 +15,6 @@ mod context; // Utils module mod utils; + +// tests +mod tests; diff --git a/src/memory.cairo b/src/memory.cairo index dcbc20a24..fbceee73d 100644 --- a/src/memory.cairo +++ b/src/memory.cairo @@ -108,7 +108,7 @@ impl MemoryImpl of MemoryTrait { /// /// * A new `Memory` instance. fn new() -> Memory { - Memory { items: Felt252DictTrait::new(), bytes_len: 0, } + Memory { items: Default::default(), bytes_len: 0, } } /// Stores a 32-bytes element into the memory. diff --git a/src/stack.cairo b/src/stack.cairo index d188486e3..cb6519e4d 100644 --- a/src/stack.cairo +++ b/src/stack.cairo @@ -53,7 +53,7 @@ impl StackImpl of StackTrait { /// Returns /// * Stack The new stack instance. fn new() -> Stack { - let items = Felt252DictTrait::::new(); + let items: Felt252Dict = Default::default(); Stack { items, len: 0 } } diff --git a/tests/lib.cairo b/src/tests.cairo similarity index 100% rename from tests/lib.cairo rename to src/tests.cairo diff --git a/tests/test_kakarot.cairo b/src/tests/test_kakarot.cairo similarity index 100% rename from tests/test_kakarot.cairo rename to src/tests/test_kakarot.cairo diff --git a/tests/test_memory.cairo b/src/tests/test_memory.cairo similarity index 100% rename from tests/test_memory.cairo rename to src/tests/test_memory.cairo diff --git a/tests/test_stack.cairo b/src/tests/test_stack.cairo similarity index 100% rename from tests/test_stack.cairo rename to src/tests/test_stack.cairo diff --git a/tests/utils.cairo b/src/tests/utils.cairo similarity index 100% rename from tests/utils.cairo rename to src/tests/utils.cairo diff --git a/tests/utils/test_helpers.cairo b/src/tests/utils/test_helpers.cairo similarity index 100% rename from tests/utils/test_helpers.cairo rename to src/tests/utils/test_helpers.cairo diff --git a/src/utils/helpers.cairo b/src/utils/helpers.cairo index 838e10094..e30562b98 100644 --- a/src/utils/helpers.cairo +++ b/src/utils/helpers.cairo @@ -200,23 +200,6 @@ fn reverse_array, impl TDrop: Drop>(src: Span) -> A dst } -/// Tries to convert a u256 into a u8. -impl U256TryIntoU8 of TryInto { - fn try_into(self: u256) -> Option { - if self.high != 0 { - return Option::None(()); - } - self.low.try_into() - } -} - -/// Converts a u8 into a u256. -impl U8IntoU256 of Into { - fn into(self: u8) -> u256 { - u256 { low: self.into(), high: 0 } - } -} - //TODO(eni) make PR and add this in corelib