diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b82214c..c5b94bf 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -34,5 +34,3 @@ jobs: - name: Run tests run: nix flake -L check - - name: Check build without nix additional environment flags - run: .github/scripts/pure-cmake-build.sh diff --git a/cmake/Config.cmake.in b/cmake/Config.cmake.in index a119cd1..0bf1956 100644 --- a/cmake/Config.cmake.in +++ b/cmake/Config.cmake.in @@ -2,7 +2,6 @@ include(CMakeFindDependencyMacro) find_dependency(crypto3 REQUIRED) -find_dependency(crypto3_blueprint REQUIRED) find_dependency(intx REQUIRED) find_dependency(ethash REQUIRED) diff --git a/evm-assigner.nix b/evm-assigner.nix new file mode 100644 index 0000000..c9d71c9 --- /dev/null +++ b/evm-assigner.nix @@ -0,0 +1,49 @@ +{ lib, + stdenv, + src_repo, + ninja, + pkg-config, + cmake, + boost183, + # We'll use boost183 by default, but you can override it + boost_lib ? boost183, + gdb, + ethash, + intx, + gtest, + crypto3, + enableDebugging, + enableDebug ? false, + runTests ? false, + }: +let + inherit (lib) optional; +in stdenv.mkDerivation rec { + name = "evm-assigner"; + + src = src_repo; + + nativeBuildInputs = [ cmake ninja pkg-config ] ++ (lib.optional (!stdenv.isDarwin) gdb); + + # enableDebugging will keep debug symbols in boost + propagatedBuildInputs = [ (if enableDebug then (enableDebugging boost_lib) else boost_lib) ]; + + buildInputs = [crypto3 ethash intx gtest]; + + cmakeFlags = + [ + (if runTests then "-DBUILD_TESTS=TRUE" else "") + (if runTests then "-DCMAKE_ENABLE_TESTS=TRUE" else "") + (if runTests then "-DBUILD_ASSIGNER_TESTS=TRUE" else "") + (if enableDebug then "-DCMAKE_BUILD_TYPE=Debug" else "-DCMAKE_BUILD_TYPE=Release") + (if enableDebug then "-DCMAKE_CXX_FLAGS=-ggdb" else "") + "-G Ninja" + ]; + + doCheck = runTests; + + shellHook = '' + PS1="\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ " + echo "Welcome to evm-assigner development environment!" + ''; +} diff --git a/flake.lock b/flake.lock index c78da9e..295daa4 100644 --- a/flake.lock +++ b/flake.lock @@ -19,56 +19,29 @@ } }, "nil-crypto3": { - "inputs": { - "nix-3rdparty": [ - "nix-3rdparty" - ], - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1720200505, - "narHash": "sha256-eKb9e/+E+jZKdoJrsvUhaKqElfio6PMl97W+bSvKq+Q=", - "owner": "NilFoundation", - "repo": "crypto3", - "rev": "3bd5b8df2091274abaa28fd86b9e3e89d661b95a", - "type": "github" - }, - "original": { - "owner": "NilFoundation", - "repo": "crypto3", - "rev": "3bd5b8df2091274abaa28fd86b9e3e89d661b95a", - "type": "github" - } - }, - "nil-zkllvm-blueprint": { "inputs": { "flake-utils": [ "flake-utils" ], - "nil-crypto3": [ - "nil-crypto3" + "nix-3rdparty": [ + "nix-3rdparty" ], "nixpkgs": [ "nixpkgs" ] }, "locked": { - "lastModified": 1720092182, - "narHash": "sha256-WTjhgYwkHjDCSDmDX1SwCH+cuz6OWl9vQaOYCUKOw7c=", + "lastModified": 1724068894, + "narHash": "sha256-sTg66s+8BlhKs5HmnEJFw5hjwi8+dEXMFGwU4aS3juM=", "ref": "refs/heads/master", - "rev": "73d6a40e39b6b6fc7b1c84441e62337206dc0815", - "revCount": 1246, - "submodules": true, + "rev": "e4772b04564ef76c413136d3798c6caf7d99e195", + "revCount": 10446, "type": "git", - "url": "https://github.com/NilFoundation/zkllvm-blueprint" + "url": "https://github.com/NilFoundation/crypto3" }, "original": { - "rev": "73d6a40e39b6b6fc7b1c84441e62337206dc0815", - "submodules": true, "type": "git", - "url": "https://github.com/NilFoundation/zkllvm-blueprint" + "url": "https://github.com/NilFoundation/crypto3" } }, "nix-3rdparty": { @@ -81,11 +54,11 @@ ] }, "locked": { - "lastModified": 1717519917, - "narHash": "sha256-GqzEqEW4Uz9Z7uDZwers0t9seWRNbRWPNE3OJnjE1Uw=", + "lastModified": 1721822436, + "narHash": "sha256-AQidmv80fA72FFHgyjCq9Psc04w9aaHedJpoVgnLb6M=", "owner": "NilFoundation", "repo": "nix-3rdparty", - "rev": "a2e45429aa25a4a6e8e362ef17df6f197312f224", + "rev": "d14a2a3c4b9498b297400b225fc09570bfe0a9a1", "type": "github" }, "original": { @@ -96,11 +69,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1721804089, - "narHash": "sha256-1a4FrLzn4I1xoASzWfhGEF3Gln33g4lrtRLDNybftak=", + "lastModified": 1724099983, + "narHash": "sha256-KUCIVWPXs+F1Elzwczns/arptrLTiB0FyjeTNTLiRFQ=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "633ae2570ec145a008d7703886e78faa24b9c1bd", + "rev": "975ba1bed8410267a8866f26f6d79af8d9232aee", "type": "github" }, "original": { @@ -113,7 +86,6 @@ "inputs": { "flake-utils": "flake-utils", "nil-crypto3": "nil-crypto3", - "nil-zkllvm-blueprint": "nil-zkllvm-blueprint", "nix-3rdparty": "nix-3rdparty", "nixpkgs": "nixpkgs" } diff --git a/flake.nix b/flake.nix index fd6e130..9e508ca 100644 --- a/flake.nix +++ b/flake.nix @@ -1,5 +1,5 @@ { - description = "Nix flake for EVM-assigner"; + description = "Nix flake for evm-assigner"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs"; @@ -14,142 +14,67 @@ nil-crypto3 = { url = "https://github.com/NilFoundation/crypto3"; type = "git"; - rev = "3bd5b8df2091274abaa28fd86b9e3e89d661b95a"; - inputs = { - nixpkgs.follows = "nixpkgs"; - nix-3rdparty.follows = "nix-3rdparty"; - }; - }; - nil-zkllvm-blueprint = { - url = "https://github.com/NilFoundation/zkllvm-blueprint"; - type = "git"; - submodules = true; - rev = "73d6a40e39b6b6fc7b1c84441e62337206dc0815"; inputs = { nixpkgs.follows = "nixpkgs"; flake-utils.follows = "flake-utils"; - nil-crypto3.follows = "nil-crypto3"; + nix-3rdparty.follows = "nix-3rdparty"; }; }; }; - outputs = - { - self, - nixpkgs, - flake-utils, - nix-3rdparty, - ... - }@inputs: - flake-utils.lib.eachDefaultSystem ( - system: + outputs = { self, nixpkgs, nil-crypto3, flake-utils, nix-3rdparty }: + (flake-utils.lib.eachDefaultSystem (system: let - pkgs = import nixpkgs { - overlays = [ nix-3rdparty.overlays.${system}.default ]; - inherit system; - }; - - # Add more complicated logic here if you need to have debug packages - resolveInput = input: input.packages.${system}.default; - - nil-inputs = with inputs; [ - nil-crypto3 - nil-zkllvm-blueprint - ]; - - nil-packages = map resolveInput nil-inputs; - - defaultNativeBuildInputs = with pkgs; [ - cmake - ninja - ]; - - defaultCheckInputs = [ pkgs.gtest ]; - - commonBuildInputs = [ pkgs.boost ]; - - inputsToPropagate = - { - enableDebug ? false, - }: - let - deps = with pkgs; [ - (intx.override { inherit enableDebug; }) - ethash - ]; - in - deps ++ nil-packages; - - devInputs = [ pkgs.clang_17 ]; - - makePackage = - { - enableDebug ? false, - }: - pkgs.gcc13Stdenv.mkDerivation { - name = "EVM-assigner" + "${if enableDebug then "-debug" else ""}"; - - nativeBuildInputs = defaultNativeBuildInputs; + pkgs = import nixpkgs { inherit system; }; + stdenv = pkgs.llvmPackages_16.stdenv; + crypto3 = nil-crypto3.packages.${system}.crypto3; + intx = nix-3rdparty.packages.${system}.intx; - buildInputs = commonBuildInputs; - - propagatedBuildInputs = inputsToPropagate { inherit enableDebug; }; - - src = self; - - cmakeBuildType = if enableDebug then "Debug" else "Release"; - - doCheck = false; - dontStrip = enableDebug; - }; - - makeTests = - { - enableDebug ? false, - }: - (makePackage { inherit enableDebug; }).overrideAttrs ( - finalAttrs: previousAttrs: { - name = previousAttrs.name + "-tests"; - - checkInputs = defaultCheckInputs; - - cmakeFlags = [ "-DBUILD_ASSIGNER_TESTS=TRUE" ]; - - dontInstall = true; - - doCheck = true; - - GTEST_OUTPUT = "xml:${placeholder "out"}/test-reports/"; - } - ); - - makeDevShell = - { - enableDebug ? false, - }: - pkgs.mkShell { - nativeBuildInputs = defaultNativeBuildInputs; - buildInputs = - commonBuildInputs ++ inputsToPropagate { inherit enableDebug; } ++ defaultCheckInputs ++ devInputs; - - shellHook = '' - echo "evm-assigner dev ${if enableDebug then "debug" else "release"} environment activated" - ''; - }; - in - { + in { packages = rec { - release = makePackage { }; - debug = makePackage { enableDebug = true; }; - default = release; - }; - checks = { - default = makeTests { }; + evm-assigner = (pkgs.callPackage ./evm-assigner.nix { + src_repo = self; + crypto3 = crypto3; + intx = intx; + }); + evm-assigner-debug = (pkgs.callPackage ./evm-assigner.nix { + src_repo = self; + crypto3 = crypto3; + intx = intx; + enableDebug = true; + }); + evm-assigner-debug-tests = (pkgs.callPackage ./evm-assigner.nix { + src_repo = self; + crypto3 = crypto3; + intx = intx; + enableDebug = true; + runTests = true; + }); + default = evm-assigner-debug-tests; }; - devShells = { - default = makeDevShell { }; - debug = makeDevShell { enableDebug = true; }; + checks = rec { + gcc = (pkgs.callPackage ./evm-assigner.nix { + src_repo = self; + crypto3 = crypto3; + intx = intx; + runTests = true; + }); + clang = (pkgs.callPackage ./evm-assigner.nix { + stdenv = pkgs.llvmPackages_18.stdenv; + src_repo = self; + crypto3 = crypto3; + intx = intx; + runTests = true; + }); + all = pkgs.symlinkJoin { + name = "all"; + paths = [ gcc clang ]; + }; + default = all; }; - } - ); + })); } + +# `nix flake -L check` to run all tests (-L to output build logs) +# `nix flake show` to show derivations tree +# If build fails due to OOM, run `export NIX_CONFIG="cores = 2"` to set desired parallel level diff --git a/lib/assigner/CMakeLists.txt b/lib/assigner/CMakeLists.txt index 96d921a..c824cb9 100644 --- a/lib/assigner/CMakeLists.txt +++ b/lib/assigner/CMakeLists.txt @@ -16,7 +16,6 @@ add_library(${PROJECT_NAME} STATIC ${evmone_sources}) target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_20) find_package(crypto3 REQUIRED) -find_package(crypto3_blueprint REQUIRED) target_include_directories(${PROJECT_NAME} PUBLIC $ @@ -25,7 +24,7 @@ target_include_directories(${PROJECT_NAME} PUBLIC $) target_link_libraries(${PROJECT_NAME} - PUBLIC intx::intx crypto3::all crypto3::blueprint ethash::keccak) + PUBLIC intx::intx crypto3::all ethash::keccak) set_target_properties( ${PROJECT_NAME} diff --git a/lib/assigner/include/zkevm_word.hpp b/lib/assigner/include/zkevm_word.hpp index 5fd0884..2d3d1c7 100644 --- a/lib/assigner/include/zkevm_word.hpp +++ b/lib/assigner/include/zkevm_word.hpp @@ -269,9 +269,9 @@ namespace nil { template std::ostream& operator<<(std::ostream& os, const zkevm_word& obj){ - const auto bytes = obj.to_uint256be().bytes; + const auto word = obj.to_uint256be(); for (uint8_t i = 0; i < 32; i++) { - os << (int)bytes[i] << " "; + os << (int)word.bytes[i] << " "; } return os; } diff --git a/lib/assigner/test/CMakeLists.txt b/lib/assigner/test/CMakeLists.txt index dcf5ac7..1c0d51a 100644 --- a/lib/assigner/test/CMakeLists.txt +++ b/lib/assigner/test/CMakeLists.txt @@ -5,13 +5,21 @@ find_package(GTest CONFIG REQUIRED) add_executable(assigner_tests assigner_test.cpp) +if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + target_compile_options(assigner_tests PRIVATE "-fconstexpr-steps=2147483647") +elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + target_compile_options(assigner_tests PRIVATE "-fconstexpr-ops-limit=4294967295") +endif() + target_include_directories(assigner_tests PRIVATE $) + target_link_libraries( assigner_tests PRIVATE ${PROJECT_NAME} GTest::gtest_main + Boost::log ) gtest_discover_tests(assigner_tests PROPERTIES LABELS ASSIGNER) diff --git a/lib/assigner/test/assigner_test.cpp b/lib/assigner/test/assigner_test.cpp index f6088f8..6d9d60a 100644 --- a/lib/assigner/test/assigner_test.cpp +++ b/lib/assigner/test/assigner_test.cpp @@ -177,7 +177,7 @@ TEST_F(AssignerTest, conversions_address_to_zkevm_word) TEST_F(AssignerTest, conversions_hash_to_zkevm_word) { - ethash::hash256 hash; + ethash::hash256 hash {.bytes = {0}}; hash.bytes[2] = 10; // conversion to zkevm_word auto tmp = nil::evm_assigner::zkevm_word(hash); diff --git a/nix/intx.nix b/nix/intx.nix deleted file mode 100644 index af60bb7..0000000 --- a/nix/intx.nix +++ /dev/null @@ -1,15 +0,0 @@ -{ repo, pkgs, stdenv, enable_debug, ... }: -stdenv.mkDerivation { - name = "intx"; - - src = repo; - - nativeBuildInputs = [ pkgs.cmake ]; - - cmakeFlags = [ - "-DINTX_TESTING=OFF" - ]; - - doCheck = true; - dontStrip = enable_debug; -}