Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use latest crypto3 #33

Merged
merged 6 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion cmake/Config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

include(CMakeFindDependencyMacro)
find_dependency(crypto3 REQUIRED)
find_dependency(crypto3_blueprint REQUIRED)
find_dependency(intx REQUIRED)
find_dependency(ethash REQUIRED)

Expand Down
49 changes: 49 additions & 0 deletions evm-assigner.nix
Original file line number Diff line number Diff line change
@@ -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!"
'';
}
56 changes: 14 additions & 42 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

179 changes: 52 additions & 127 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
description = "Nix flake for EVM-assigner";
description = "Nix flake for evm-assigner";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs";
Expand All @@ -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
3 changes: 1 addition & 2 deletions lib/assigner/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
Expand All @@ -25,7 +24,7 @@ target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/evmone>)

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}
Expand Down
4 changes: 2 additions & 2 deletions lib/assigner/include/zkevm_word.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,9 @@ namespace nil {

template <typename BlueprintFieldType>
std::ostream& operator<<(std::ostream& os, const zkevm_word<BlueprintFieldType>& 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;
}
Expand Down
Loading
Loading