diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fcd35cb6..6c3c16b7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,32 +1,35 @@ -name: Build on Ubuntu +name: Build and test on Linux on: push: - branches: [ "master" ] + branches: [ master ] pull_request: - branches: [ "master" ] -env: - # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) - BUILD_TYPE: Release +concurrency: + # In master we want to run for every commit, in other branches — only for the last one + group: ${{ + ( github.ref == 'refs/heads/master' && + format('{0}/{1}/{2}', github.workflow, github.ref, github.sha) ) + || + format('{0}/{1}', github.workflow, github.ref) }} + cancel-in-progress: true jobs: - build: - # The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac. - # You can convert this to a matrix build if you need cross-platform coverage. - # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix - runs-on: ubuntu-latest + build-and-test: + name: Build and run tests + + runs-on: [self-hosted, Linux, X64, aws_autoscaling] steps: - - uses: actions/checkout@v3 - with: - submodules: 'recursive' - - - name: Configure CMake - # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. - # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type - run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} - - - name: Build - # Build your program with the given configuration - run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} + # https://github.com/actions/checkout/issues/1552 + - name: Clean up after previous checkout + run: chmod +w -R ${GITHUB_WORKSPACE}; rm -rf ${GITHUB_WORKSPACE}/*; + + - name: Checkout sources + uses: actions/checkout@v3 + + - name: Build sources + run: nix build -L + + - name: Run tests + run: nix flake -L check diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index b16c59af..00000000 --- a/.gitmodules +++ /dev/null @@ -1,12 +0,0 @@ -[submodule "evmc"] - path = evmc - url = https://github.com/ethereum/evmc -[submodule "evm-benchmarks"] - path = test/evm-benchmarks - url = https://github.com/ipsilon/evm-benchmarks -[submodule "lib/blueprint"] - path = lib/blueprint - url = ../../NilFoundation/zkllvm-blueprint.git -[submodule "lib/crypto3"] - path = lib/crypto3 - url = ../../NilFoundation/crypto3.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 03b2c1f4..e5e12058 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,10 +4,6 @@ cmake_minimum_required(VERSION 3.16...3.27) -if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/evmc/.git) - message(FATAL_ERROR "Git submodules not initialized, execute:\n git submodule update --init") -endif() - option(BUILD_SHARED_LIBS "Build evmone as a shared library" ON) option(EVMONE_TESTING "Build tests and test tools" OFF) option(EVMONE_FUZZING "Instrument libraries and build fuzzing tools" OFF) @@ -39,10 +35,7 @@ endif() hunter_add_package(ethash) find_package(ethash CONFIG REQUIRED) - -option(EVMC_TOOLS "Build EVMC test tools" ${EVMONE_TESTING}) -option(EVMC_INSTALL "Install EVMC" OFF) -add_subdirectory(evmc) +find_package(evmc REQUIRED) cable_configure_compiler(NO_STACK_PROTECTION) if(CABLE_COMPILER_GNULIKE) diff --git a/README.md b/README.md index f1245a1a..4cc0a2e1 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# evm1_assigner +# evm-assigner Simulator of Ethereum Virtual Machine pipeline for fill assignment table associate with evm1 circuit. @@ -7,20 +7,50 @@ Created by members of the [Ipsilon] (ex-[Ewasm]) team. ## Dependencies +### Build tools + +- CMake 3.16+ +- Clang or GCC (tested with GCC 13) +- Ninja (recommended) + +### Libraries + +- [evmc](https://github.com/ethereum/evmc) +- [intx](https://github.com/chfast/intx) - [blueprint](https://github.com/NilFoundation/zkllvm-blueprint) - [crypto3](https://github.com/NilFoundation/crypto3) +## Nix support + +`evm-assigner` supports [Nix](https://nixos.org/) flakes. This means that you can get development-ready environment with: + +```bash +nix develop +``` + +Build package: + +```bash +nix build +``` + +Run tests: + +```bash +nix flake check +``` + ## Build ### Configure cmake -``` +```bash cmake -G "Ninja" -B build -DCMAKE_BUILD_TYPE=Release -DBUILD_ASSIGNER_TESTS=TRUE ``` ### Build test -``` +```bash cmake --build build -t assigner_tests ``` diff --git a/evmc b/evmc deleted file mode 160000 index 24f939eb..00000000 --- a/evmc +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 24f939ebbfc1cf416b5d4c328c0ef29153f030f8 diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..79a2f4f2 --- /dev/null +++ b/flake.lock @@ -0,0 +1,173 @@ +{ + "nodes": { + "evmc": { + "flake": false, + "locked": { + "lastModified": 1711484129, + "narHash": "sha256-yqEbtRA4GiQ/pjaH2+ZPfnthgt9gLPY4lWPTYbBWJhE=", + "owner": "ethereum", + "repo": "evmc", + "rev": "fc86231960348790bbee8254a809bf1f9d7c8517", + "type": "github" + }, + "original": { + "owner": "ethereum", + "repo": "evmc", + "type": "github" + } + }, + "intx": { + "flake": false, + "locked": { + "lastModified": 1704400684, + "narHash": "sha256-XNpSO++FuG27Bgf5My9eJ/zrQlsWcGajfq4Y2UI2Kpk=", + "owner": "chfast", + "repo": "intx", + "rev": "e0732242e36b3bb08cc8cc23445b2bee7c28b9d0", + "type": "github" + }, + "original": { + "owner": "chfast", + "repo": "intx", + "type": "github" + } + }, + "nil_crypto3": { + "inputs": { + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1712603294, + "narHash": "sha256-0L7ir0E+jFv9dxmLV6Vxlf+st6BNaJrhRXyNCK3xPsY=", + "ref": "refs/heads/master", + "rev": "13909af052a998c92d2a6a96e0bcfd21156aed72", + "revCount": 701, + "submodules": true, + "type": "git", + "url": "https://github.com/NilFoundation/crypto3" + }, + "original": { + "submodules": true, + "type": "git", + "url": "https://github.com/NilFoundation/crypto3" + } + }, + "nil_crypto3_2": { + "inputs": { + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1712603294, + "narHash": "sha256-0L7ir0E+jFv9dxmLV6Vxlf+st6BNaJrhRXyNCK3xPsY=", + "ref": "refs/heads/master", + "rev": "13909af052a998c92d2a6a96e0bcfd21156aed72", + "revCount": 701, + "submodules": true, + "type": "git", + "url": "https://github.com/NilFoundation/crypto3" + }, + "original": { + "submodules": true, + "type": "git", + "url": "https://github.com/NilFoundation/crypto3" + } + }, + "nil_zkllvm_blueprint": { + "inputs": { + "nil_crypto3": "nil_crypto3_2", + "nixpkgs": "nixpkgs_3" + }, + "locked": { + "lastModified": 1712853518, + "narHash": "sha256-eTnjr51YYlU7PeFH6xJIpytaOne5NFHckLMj3RaxOlI=", + "ref": "refs/heads/master", + "rev": "01964c21ab68e0cd77e08c0a9225f220a5b6bf2d", + "revCount": 1204, + "submodules": true, + "type": "git", + "url": "https://github.com/NilFoundation/zkllvm-blueprint" + }, + "original": { + "rev": "01964c21ab68e0cd77e08c0a9225f220a5b6bf2d", + "submodules": true, + "type": "git", + "url": "https://github.com/NilFoundation/zkllvm-blueprint" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1708831307, + "narHash": "sha256-0iL/DuGjiUeck1zEaL+aIe2WvA3/cVhp/SlmTcOZXH4=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "5bf1cadb72ab4e77cb0b700dab76bcdaf88f706b", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1708831307, + "narHash": "sha256-0iL/DuGjiUeck1zEaL+aIe2WvA3/cVhp/SlmTcOZXH4=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "5bf1cadb72ab4e77cb0b700dab76bcdaf88f706b", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_3": { + "locked": { + "lastModified": 1712741485, + "narHash": "sha256-bCs0+MSTra80oXAsnM6Oq62WsirOIaijQ/BbUY59tR4=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "b2cf36f43f9ef2ded5711b30b1f393ac423d8f72", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_4": { + "locked": { + "lastModified": 1712741485, + "narHash": "sha256-bCs0+MSTra80oXAsnM6Oq62WsirOIaijQ/BbUY59tR4=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "b2cf36f43f9ef2ded5711b30b1f393ac423d8f72", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "evmc": "evmc", + "intx": "intx", + "nil_crypto3": "nil_crypto3", + "nil_zkllvm_blueprint": "nil_zkllvm_blueprint", + "nixpkgs": "nixpkgs_4" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..3099496f --- /dev/null +++ b/flake.nix @@ -0,0 +1,153 @@ +{ + description = "Nix flake for EVM-assigner"; + + inputs = { + nixpkgs = { url = "github:NixOS/nixpkgs/nixos-23.11"; }; + nil_crypto3 = { + url = "https://github.com/NilFoundation/crypto3"; + type = "git"; + submodules = true; + }; + nil_zkllvm_blueprint = { + url = "https://github.com/NilFoundation/zkllvm-blueprint"; + type = "git"; + rev = "01964c21ab68e0cd77e08c0a9225f220a5b6bf2d"; + submodules = true; + }; + intx = { url = "github:chfast/intx"; flake = false; }; + evmc = { url = "github:ethereum/evmc"; flake = false; }; + }; + + outputs = { self, nixpkgs, nil_crypto3, nil_zkllvm_blueprint, ... } @ repos: + let + supportedSystems = [ + "x86_64-linux" + ]; + + # For all supported systems call `f` providing system pkgs, crypto3 and blueprint + forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: f { + pkgs = import nixpkgs { + inherit system; + }; + }); + + nonFlakeDependencies = { pkgs, repos, enable_debug }: + let + lib = pkgs.lib; + stdenv = pkgs.gcc13Stdenv; + in + rec { + intx = (pkgs.callPackage ./nix/intx.nix) { + repo = repos.intx; + inherit pkgs lib stdenv enable_debug; + }; + + evmc = (pkgs.callPackage ./nix/evmc.nix) { + repo = repos.evmc; + inherit pkgs lib stdenv enable_debug; + }; + }; + + makeReleaseBuild = { pkgs }: + let + deps = nonFlakeDependencies { enable_debug = false; inherit repos pkgs; }; + crypto3 = nil_crypto3.packages.${pkgs.system}.default; + blueprint = nil_zkllvm_blueprint.packages.${pkgs.system}.default; + in + pkgs.gcc13Stdenv.mkDerivation { + name = "EVM-assigner"; + + buildInputs = with pkgs; [ + cmake + ninja + gtest + boost + ethash + ]; + + propagatedBuildInputs = [ + deps.intx + deps.evmc + crypto3 + blueprint + ]; + + src = self; + + cmakeFlags = [ + "-DHUNTER_ENABLED=OFF" # TODO: this will be removed after we get rid of Hunter + ]; + + doCheck = false; + }; + + makeTests = { pkgs }: + let + deps = nonFlakeDependencies { enable_debug = false; inherit repos pkgs; }; + crypto3 = nil_crypto3.packages.${pkgs.system}.default; + blueprint = nil_zkllvm_blueprint.packages.${pkgs.system}.default; + in + pkgs.gcc13Stdenv.mkDerivation { + # TODO: rewrite this using overrideAttr on makeReleaseBuild + name = "EVM-assigner-tests"; + + buildInputs = with pkgs; [ + cmake + ninja + gtest + boost + ethash + deps.intx + deps.evmc + crypto3 + blueprint + ]; + + src = self; + + cmakeFlags = [ + "-DHUNTER_ENABLED=OFF" # TODO: this will be removed after we get rid of Hunter + "-DBUILD_ASSIGNER_TESTS=TRUE" + ]; + + dontInstall = true; + + doCheck = true; + + GTEST_OUTPUT = "xml:${placeholder "out"}/test-reports/"; + + checkPhase = '' + ./lib/assigner/test/assigner_tests + ''; + }; + + makeDevShell = { pkgs }: + let + deps = nonFlakeDependencies { enable_debug = true; inherit repos pkgs; }; + crypto3 = nil_crypto3.packages.${pkgs.system}.default; + blueprint = nil_zkllvm_blueprint.packages.${pkgs.system}.default; + in + pkgs.mkShell { + buildInputs = with pkgs; [ + cmake + ninja + gtest + boost + clang_17 + ethash + deps.intx + crypto3 + blueprint + ]; + + shellHook = '' + echo "evm-assigner dev environment activated" + ''; + }; + in + { + packages = forAllSystems ({ pkgs }: { default = makeReleaseBuild { inherit pkgs; }; }); + checks = forAllSystems ({ pkgs }: { default = makeTests { inherit pkgs; }; }); + devShells = forAllSystems ({ pkgs }: { default = makeDevShell { inherit pkgs; }; }); + }; +} diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 4fbbc28f..dd20833f 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -6,7 +6,5 @@ hunter_add_package(intx) find_package(intx CONFIG REQUIRED) add_subdirectory(fprinter) -add_subdirectory(crypto3) -add_subdirectory(blueprint) add_subdirectory(evmone) add_subdirectory(assigner) diff --git a/lib/assigner/CMakeLists.txt b/lib/assigner/CMakeLists.txt index ba7426a3..d06f6b28 100644 --- a/lib/assigner/CMakeLists.txt +++ b/lib/assigner/CMakeLists.txt @@ -14,15 +14,14 @@ target_include_directories(${PROJECT_NAME} INTERFACE ${Boost_INCLUDE_DIRS}) +# TODO: link to blueprint and crypto3 here after fixing this in crypto3: +# https://github.com/NilFoundation/crypto3/issues/175 target_link_libraries(${PROJECT_NAME} INTERFACE - crypto3::blueprint evmone) install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/nil/blueprint/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/nil/blueprint) -#evmc -install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../evmc/include/ - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + #evmone install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/../evmone/vm.hpp ${CMAKE_CURRENT_SOURCE_DIR}/../evmone/execution_state.hpp diff --git a/lib/blueprint b/lib/blueprint deleted file mode 160000 index 324d61a2..00000000 --- a/lib/blueprint +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 324d61a282324402f9c20f3ab06647e5f54412df diff --git a/lib/crypto3 b/lib/crypto3 deleted file mode 160000 index d9f4661d..00000000 --- a/lib/crypto3 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit d9f4661d01510f5221ecc179c4253c7798719a99 diff --git a/nix/evmc.nix b/nix/evmc.nix new file mode 100644 index 00000000..8e60439a --- /dev/null +++ b/nix/evmc.nix @@ -0,0 +1,15 @@ +{ repo, pkgs, stdenv, enable_debug, ... }: +stdenv.mkDerivation { + name = "evmc"; + + src = repo; + + nativeBuildInputs = [ pkgs.cmake ]; + + cmakeFlags = [ + "-DEVMC_TOOLS=FALSE" + ]; + + doCheck = false; + dontStrip = enable_debug; +} diff --git a/nix/intx.nix b/nix/intx.nix new file mode 100644 index 00000000..af60bb77 --- /dev/null +++ b/nix/intx.nix @@ -0,0 +1,15 @@ +{ repo, pkgs, stdenv, enable_debug, ... }: +stdenv.mkDerivation { + name = "intx"; + + src = repo; + + nativeBuildInputs = [ pkgs.cmake ]; + + cmakeFlags = [ + "-DINTX_TESTING=OFF" + ]; + + doCheck = true; + dontStrip = enable_debug; +}