diff --git a/.github/workflows/nix_build_linux.yml b/.github/workflows/nix_build_linux.yml index b84bc2e2..ee79b691 100644 --- a/.github/workflows/nix_build_linux.yml +++ b/.github/workflows/nix_build_linux.yml @@ -55,51 +55,19 @@ jobs: !${{ github.workspace }}/ !${{ github.workspace }}/**/.git/** - # nix is taken from the cloud-init template, no need to install it. - - name: Setup build - run: | - nix develop .?submodules=1# -c cmake -G Ninja -B build -DCMAKE_CXX_STANDARD=17 -DCMAKE_BUILD_TYPE=Debug -DCMAKE_ENABLE_TESTS=TRUE -DGENERATE_EVM_VERIFIER=TRUE -DZKLLVM_VERSION=0.1.18 - - - name: Build zkllvm - run: | - nix develop -c ninja -C build assigner clang transpiler - - - name: Build circuits(.crct) of the C++ examples - run: | - nix develop -c ninja -C build -k 0 cpp_examples_generate_crct - ls -al ./examples/cpp - - - name: Build assignment tables(.tbl) of the C++ examples - run: | - nix develop -c ninja -C build -k 0 cpp_examples_generate_tbl_no_check - ls -al ./examples/cpp - - - name: Copy assigner output from separate generation mode - run: | - bash ./tests/copy_assigner_outputs.sh ./build/examples/cpp/ build/separate_generatuon - - - name: Run simultaneous .tbl and .crct generation of the C++ examples - run: | - nix develop -c ninja -C build -k 0 cpp_examples_generate_both - ls -al ./examples/cpp - - - name: Copy assigner output from simultaneous generation mode - run: | - bash ./tests/copy_assigner_outputs.sh ./build/examples/cpp/ build/simultaneous_generation - - - name: Compare different assigner modes output - run: | - bash ./tests/compare_folders_content.sh build/separate_generatuon build/simultaneous_generation - - - name: Run size estimation for C++ examples - run: | - nix develop -c ninja -C build -k 0 cpp_examples_estimate_size - - - name: Copy examples' circuits and assignments for uploading - run: | - chmod +x ./examples/copy_artifacts.sh - ./examples/copy_artifacts.sh build/examples/cpp examples_output - ls -al examples_output/ + - name: Build zkLLVM, run local tests, prepare for integration testing + run: | + nix build -L .?submodules=1#checks.x86_64-linux.debug-tests + ls + ls -al result/ + ls -al result/artifacts/ + cd result + find -name "*.ll" + find -name "*.tbl" + find -name "transpiler_output_*" + cd - + ls -al result/artifacts/examples_output + cp -r result/artifacts/examples_output . - name: Set aritfacts' names id: artifact-names @@ -113,71 +81,15 @@ jobs: name: ${{ steps.artifact-names.outputs.examples }} path: | examples_output - - - name: Compile tests as cpp code - run: | - nix develop -c ninja -C build -k 0 all_tests_compile_as_cpp_code - - - name: Compile tests as circuits - run: | - nix develop -c ninja -C build -k 0 all_tests_compile_as_circuits - - - name: Run tests as cpp code (expected res calculation) - run: | - nix develop -c ninja -C build -k 0 all_tests_run_expected_res_calculation - - - name: Get transpiler output for integration testing - run: | - targets_str=$(echo "${{ env.INTEGRATION_TESTING_TARGETS }}" | awk 'NF {printf " %s_evm_verifier ", $0}' | sed 's/[[:space:]]*$//') - echo "targets: ${targets_str}" - nix develop -c ninja -C build -k 0 ${targets_str} - ls -al build/examples/cpp/ + if-no-files-found: error - name: Upload examples' circuits and assignments artifact uses: actions/upload-artifact@v3 with: name: ${{ steps.artifact-names.outputs.transpiler }} path: | - build/examples/cpp/transpiler_output_* - - - name: Run tests as circuits (real res calculation) - run: | - nix develop -c ninja -C build -k 0 all_tests_assign_circuits - - - name: Compare expected and real test results - run: | - chmod +x ./tests/run_test_results_comparison.sh - bash ./tests/run_test_results_comparison.sh - - - name: Run tests on faulty inputs - run: | - chmod +x ./tests/run_tests_faulty_input.sh - bash ./tests/run_tests_faulty_input.sh pallas - - - name: Run assigner unit tests - run: | - nix develop -c ninja -C build -k 0 check-crypto3-assigner - - - name: Build proof for the circuit of the C++ examples - run: | - nix develop -c ninja -C build -k 0 prove_cpp_examples - - - name: Build recursive gen - run: | - nix develop -c ninja -C build -k 0 recursive_gen - - - name: Build and run transpiler test - run: | - nix develop -c ninja -C build -k 0 compile_and_run_transpiler_tests - - - name: Run recursive verifier tests - run: | - nix develop -c ninja -C build -k 0 recursion - - - name: Build IR of the C++ examples - run: | - nix develop -c ninja -C build -k 0 compile_cpp_examples - ls -al ./examples/cpp + result/artifacts/cpp/transpiler_output_* + if-no-files-found: error - name: Set targets for integration testing id: get-targets @@ -216,11 +128,11 @@ jobs: always() && !cancelled() && (needs.handle-syncwith.result == 'success' || needs.handle-syncwith.result == 'skipped') && needs.build-and-test-with-nix.result == 'success' - uses: NilFoundation/proof-producer/.github/workflows/reusable-generate-proofs-linux.yml@ef8cd9152b4bec871e7efdc1d6b606e445bad274 + uses: NilFoundation/proof-producer/.github/workflows/reusable-generate-proofs-linux.yml@f3e985dabe0d20ecb75375f86d8cf2a71e2eb58b with: artifact-name: ${{ needs.build-and-test-with-nix.outputs.examples-artifact-name }} # Update next line if you need new version of proof producer - proof-producer-ref: ef8cd9152b4bec871e7efdc1d6b606e445bad274 + proof-producer-ref: f3e985dabe0d20ecb75375f86d8cf2a71e2eb58b refs: ${{ needs.handle-syncwith.outputs.prs-refs }} targets: ${{ needs.build-and-test-with-nix.outputs.prover-targets }} diff --git a/.gitignore b/.gitignore index 4e5bee31..909fa04e 100644 --- a/.gitignore +++ b/.gitignore @@ -360,6 +360,8 @@ install_manifest.txt compile_commands.json CTestTestfile.cmake build +*build +build* result ### LaTeX ### diff --git a/.gitmodules b/.gitmodules index 8ce8a377..92da7c0a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ -[submodule "cmake-modules"] - path = cmake/modules - url = ../../BoostCMake/cmake_modules.git [submodule "zkllvm-assigner"] path = libs/assigner url = ../../NilFoundation/zkllvm-assigner.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 2756513b..39edc78c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,11 +14,9 @@ cmake_policy(SET CMP0028 NEW) cmake_policy(SET CMP0057 NEW) cmake_policy(SET CMP0063 NEW) -list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake" - "${CMAKE_CURRENT_LIST_DIR}/cmake/packages" - "${CMAKE_CURRENT_LIST_DIR}/cmake/modules/share/modules/cmake") +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") -include(CMConfig) +find_package(CM) include(CMSetupVersion) cm_workspace(zkllvm) @@ -44,6 +42,7 @@ include(CircuitCompile) find_package(Python3 3.6 REQUIRED COMPONENTS Interpreter) find_package(crypto3 REQUIRED) +find_package(crypto3_blueprint REQUIRED) find_package(Boost COMPONENTS REQUIRED filesystem log log_setup program_options thread system random unit_test_framework timer) if(BUILD_WITH_BOOST_STATIC_LIBS) @@ -118,7 +117,7 @@ configure_file("${CMAKE_CURRENT_LIST_DIR}/cmake/zkllvm.conf.in" "${CMAKE_CURRENT_BINARY_DIR}/zkllvm.conf" NO_SOURCE_PERMISSIONS @ONLY) -install(FILES "${CMAKE_CURRENT_BINARY_DIR}/zkllvm.conf" DESTINATION /etc/ld.so.conf.d) +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/zkllvm.conf" DESTINATION etc/ld.so.conf.d) set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_CURRENT_LIST_DIR}/cmake/triggers") set(CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION TRUE) @@ -196,3 +195,5 @@ add_custom_target(rslang_dist COMMENT "Building rslang distribution package" USES_TERMINAL WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/libs/rslang) + +add_executable(test_package bin/test_package.cpp) diff --git a/README.md b/README.md index d730d11a..0d92b3de 100644 --- a/README.md +++ b/README.md @@ -37,16 +37,27 @@ Languages currently supported are: #### Install Dependencies -* [Boost](https://www.boost.org/) >= 1.76.0 -* [CMake](https://cmake.org/) >= 3.5 -* [Clang](https://clang.llvm.org/) >= 12.0 -* [Python](https://www.python.org/) >= 3.7 -* [Rust](https://www.rust-lang.org/) >= 1.68 (if you want to build Rust compiler) +Install nix using the following command: -On Debian systems, everything except Boost and Rust can be installed with the following command: +``` +curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install +``` + +for most cases, you want to have an incremental build: +``` +nix develop +eval "$configurePhase" +eval "$buildPhase" +eval "$checkPhase" +``` +only build: +``` +nix build -L .?submodules=1 ``` -sudo apt install build-essential libssl-dev cmake clang-12 git curl pkg-config +build and test: +``` +nix build -L .?submodules=1#checks.x86_64-linux.debug-tests ``` #### 1. Clone the repository @@ -282,4 +293,4 @@ Ninja: ```bash ninja -C ${ZKLLVM_BUILD:-build} arithmetics_cpp_example -j$(sysctl -n hw.logicalcpu) ${ZKLLVM_BUILD:-build}/bin/assigner/assigner -b ${ZKLLVM_BUILD:-build}/examples/cpp/arithmetics_cpp_example.ll -i examples/inputs/arithmetics.inp -t assignment.tbl -c circuit.crct -e pallas --check -``` \ No newline at end of file +``` diff --git a/bin/assigner/CMakeLists.txt b/bin/assigner/CMakeLists.txt index 2b6bc888..0613c188 100644 --- a/bin/assigner/CMakeLists.txt +++ b/bin/assigner/CMakeLists.txt @@ -42,6 +42,7 @@ target_link_libraries(${CURRENT_PROJECT_NAME} LLVMCore LLVMSupport crypto3::all + crypto3::blueprint ${Boost_LIBRARIES}) target_include_directories(${CURRENT_PROJECT_NAME} PUBLIC @@ -50,7 +51,6 @@ target_include_directories(${CURRENT_PROJECT_NAME} PUBLIC ${CMAKE_SOURCE_DIR}/libs/circifier/llvm/include ${CMAKE_SOURCE_DIR}/libs/circifier/utils/bazel/llvm-project-overlay/llvm/include ${CMAKE_SOURCE_DIR}/libs/assigner/include - ${CMAKE_SOURCE_DIR}/libs/blueprint/include ${CMAKE_BINARY_DIR}/libs/circifier/llvm/include ${Boost_INCLUDE_DIRS}) diff --git a/bin/recursive_gen/CMakeLists.txt b/bin/recursive_gen/CMakeLists.txt index 0ca6c0bc..4648b4d0 100644 --- a/bin/recursive_gen/CMakeLists.txt +++ b/bin/recursive_gen/CMakeLists.txt @@ -37,6 +37,9 @@ set_target_properties(${CURRENT_PROJECT_NAME} PROPERTIES target_link_libraries(${CURRENT_PROJECT_NAME} crypto3::all + crypto3::blueprint + crypto3::assigner + crypto3::transpiler ${Boost_LIBRARIES}) target_include_directories(${CURRENT_PROJECT_NAME} PUBLIC @@ -44,9 +47,6 @@ target_include_directories(${CURRENT_PROJECT_NAME} PUBLIC $ ${CMAKE_SOURCE_DIR}/libs/circifier/llvm/include ${CMAKE_SOURCE_DIR}/libs/circifier/utils/bazel/llvm-project-overlay/llvm/include - ${CMAKE_SOURCE_DIR}/libs/assigner/include - ${CMAKE_SOURCE_DIR}/libs/blueprint/include - ${CMAKE_SOURCE_DIR}/libs/transpiler/include ${CMAKE_BINARY_DIR}/libs/circifier/llvm/include ${Boost_INCLUDE_DIRS}) diff --git a/bin/test_package.cpp b/bin/test_package.cpp new file mode 100644 index 00000000..31a13372 --- /dev/null +++ b/bin/test_package.cpp @@ -0,0 +1,5 @@ + +int main() +{ + return 0; +} diff --git a/bin/transpiler/CMakeLists.txt b/bin/transpiler/CMakeLists.txt index 22176bde..f8cde599 100644 --- a/bin/transpiler/CMakeLists.txt +++ b/bin/transpiler/CMakeLists.txt @@ -39,14 +39,14 @@ set_target_properties(${CURRENT_PROJECT_NAME} PROPERTIES target_link_libraries(${CURRENT_PROJECT_NAME} crypto3::all + crypto3::blueprint + crypto3::assigner ${Boost_LIBRARIES}) target_include_directories(${CURRENT_PROJECT_NAME} PUBLIC $ $ ${CMAKE_SOURCE_DIR}/libs/circifier/llvm/include - ${CMAKE_SOURCE_DIR}/libs/assigner/include - ${CMAKE_SOURCE_DIR}/libs/blueprint/include ${CMAKE_SOURCE_DIR}/libs/transpiler/include ${CMAKE_SOURCE_DIR}/libs/circifier/utils/bazel/llvm-project-overlay/llvm/include ${Boost_INCLUDE_DIRS}) diff --git a/cmake/CircuitCompile.cmake b/cmake/CircuitCompile.cmake index 90fc7515..f2cc5b2c 100644 --- a/cmake/CircuitCompile.cmake +++ b/cmake/CircuitCompile.cmake @@ -107,8 +107,8 @@ function(add_circuit) set(libcpp_stdlib ${CMAKE_BINARY_DIR}/libs/stdlib/libcpp/zkllvm-libcpp.ll) else() set(LINKER llvm-link-zkllvm) - set(libc_stdlib "/usr/lib/zkllvm/lib/zkllvm/zkllvm-libc.ll") - set(libcpp_stdlib "/usr/lib/zkllvm/lib/zkllvm/zkllvm-libcpp.ll") + set(libc_stdlib "/var/empty/lib/zkllvm/lib/zkllvm/zkllvm-libc.ll") + set(libcpp_stdlib "/var/empty/lib/zkllvm/lib/zkllvm/zkllvm-libcpp.ll") endif() if (NOT ${CIRCUIT_BINARY_OUTPUT}) set(link_options "-S") diff --git a/cmake/modules b/cmake/modules deleted file mode 160000 index 57639741..00000000 --- a/cmake/modules +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 57639741ecf018835deb97a04db2200241d7fbd3 diff --git a/cmake/packages/FindCrypto3.cmake b/cmake/packages/FindCrypto3.cmake deleted file mode 100644 index e69de29b..00000000 diff --git a/cmake/packages/FindValgrind.cmake b/cmake/packages/FindValgrind.cmake deleted file mode 100644 index 82730b17..00000000 --- a/cmake/packages/FindValgrind.cmake +++ /dev/null @@ -1,23 +0,0 @@ -# Find Valgrind. -# -# This module defines: -# VALGRIND_INCLUDE_DIR, where to find valgrind/memcheck.h, etc. -# VALGRIND_PROGRAM, the valgrind executable. -# VALGRIND_FOUND, If false, do not try to use valgrind. -# -# If you have valgrind installed in a non-standard place, you can define -# VALGRIND_PREFIX to tell cmake_backup where it is. -# -# NOTE: Copied from the opencog project, where it is distributed under the -# terms of the New BSD License. - -find_path(VALGRIND_INCLUDE_DIR valgrind/memcheck.h - /usr/include /usr/local/include ${VALGRIND_PREFIX}/include) -find_program(VALGRIND_PROGRAM NAMES valgrind PATH - /usr/bin /usr/local/bin ${VALGRIND_PREFIX}/bin) - -find_package_handle_standard_args(VALGRIND DEFAULT_MSG - VALGRIND_INCLUDE_DIR - VALGRIND_PROGRAM) - -mark_as_advanced(VALGRIND_INCLUDE_DIR VALGRIND_PROGRAM) \ No newline at end of file diff --git a/examples/move_artifacts.sh b/examples/move_artifacts.sh new file mode 100755 index 00000000..2a65c561 --- /dev/null +++ b/examples/move_artifacts.sh @@ -0,0 +1,51 @@ +#!/bin/bash + +usage() { + echo "Usage: $0 " + exit 1 +} + +if [ "$#" -ne 2 ]; then + usage +fi + +base_dir=$1 +target_dir=$(realpath "$2") + +if [ ! -d "$base_dir" ]; then + echo "Error: Base directory '$base_dir' does not exist." + exit 1 +fi + +mkdir -p "$target_dir" + +cd "$base_dir" || exit + +declare -A base_names +for ll_file in *.ll; do + base_name=$(echo "$ll_file" | sed -E 's/_no_stdlib.*//' | sed -E 's/\.ll$//') + base_names["$base_name"]=1 +done + +for base_name in "${!base_names[@]}"; do + echo "Processing $base_name" + + mkdir -p "$target_dir/$base_name" + + for variant in "$base_name"*".ll"; do + if [[ -f "$variant" ]]; then + suffix=$(echo "$variant" | sed -E "s/${base_name}(_no_stdlib.*)?\.ll/\1/") + suffix=${suffix:-""} + mv "$variant" "$target_dir/$base_name/bytecode${suffix}.ll" + fi + done + + if [[ -f "circuit_${base_name}.crct" ]]; then + mv "circuit_${base_name}.crct" "$target_dir/$base_name/circuit.crct" + fi + if [[ -f "assignment_${base_name}.tbl" ]]; then + mv "assignment_${base_name}.tbl" "$target_dir/$base_name/assignment.tbl" + fi +done + +echo "Files have been moved from $base_dir to $target_dir" diff --git a/flake.lock b/flake.lock index 0464523b..fdefbae1 100644 --- a/flake.lock +++ b/flake.lock @@ -62,17 +62,17 @@ ] }, "locked": { - "lastModified": 1718821034, - "narHash": "sha256-j3fsPiltYzctIgAWakAHdPLAxq+UiXXnKNmAu+oN7Us=", + "lastModified": 1720625736, + "narHash": "sha256-hN9H6kpGAUn0JJQDCgZi8PjR2lOvMxC9M/Nm3D7ngs0=", "ref": "refs/heads/master", - "rev": "caf78b83692b39f504c4ee74a3834a4c38662a77", - "revCount": 9146, - "submodules": true, + "rev": "3033b706940d20433651963d4ee8b751805d388f", + "revCount": 9151, + "submodules": false, "type": "git", "url": "https://github.com/NilFoundation/crypto3" }, "original": { - "submodules": true, + "submodules": false, "type": "git", "url": "https://github.com/NilFoundation/crypto3" } @@ -80,7 +80,7 @@ "nil-zkllvm-blueprint": { "inputs": { "flake-utils": "flake-utils_3", - "nil_crypto3": [ + "nil-crypto3": [ "nil-crypto3" ], "nixpkgs": [ @@ -88,11 +88,11 @@ ] }, "locked": { - "lastModified": 1719590043, - "narHash": "sha256-C2O0EAmWOR+Fq+lNqumwd7YS9+TBDkWGNpS1CjCAwvY=", + "lastModified": 1720537031, + "narHash": "sha256-ucn4h+p17acwRv7GjpwtPj99mUk3WHqA7Ag4zvTvJ8U=", "ref": "refs/heads/master", - "rev": "84ebc6dbdd94256424904c8270cb16d764236a31", - "revCount": 1243, + "rev": "30377e6d7d1b71a3c777c326d2140945398f651f", + "revCount": 1249, "submodules": true, "type": "git", "url": "https://github.com/NilFoundation/zkllvm-blueprint" @@ -150,11 +150,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1719824438, - "narHash": "sha256-pY0wosAgcr9W4vmGML0T3BVhQiGuKoozCbs2t+Je1zc=", + "lastModified": 1720679975, + "narHash": "sha256-8yHvqa7P7y4kFiNW9BPgeQdZ6FVFXD3Sp/oUVRyzYpA=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "7f993cdf26ccef564eabf31fdb40d140821e12bc", + "rev": "1f86d2ae2cb15b411e11ff1e4638beb079b7190d", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 197385dc..5b7aeeee 100644 --- a/flake.nix +++ b/flake.nix @@ -1,5 +1,5 @@ { - description = "Nix flake for zkEVM"; + description = "Nix flake for zkLLVM"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs"; @@ -14,7 +14,7 @@ nil-crypto3 = { url = "https://github.com/NilFoundation/crypto3"; type = "git"; - submodules = true; + submodules = false; inputs = { nixpkgs.follows = "nixpkgs"; }; @@ -25,110 +25,75 @@ submodules = true; inputs = { nixpkgs.follows = "nixpkgs"; - nil_crypto3.follows = "nil-crypto3"; + nil-crypto3.follows = "nil-crypto3"; }; }; }; - outputs = - { self + outputs = { self , nixpkgs , flake-utils , nix-3rdparty , nil-crypto3 , nil-zkllvm-blueprint }: - flake-utils.lib.eachDefaultSystem (system: - let - pkgs = import nixpkgs { - overlays = [ nix-3rdparty.overlays.${system}.default ]; - inherit system; - }; - crypto3 = nil-crypto3.packages.${system}.default; - blueprint = nil-zkllvm-blueprint.packages.${system}.default; - - # Default env will bring us GCC 13 as default compiler - stdenv = pkgs.stdenv; - - defaultNativeBuildInputs = [ - pkgs.cmake - pkgs.ninja - pkgs.python3 - pkgs.git - ]; - - defaultBuildInputs = [ - # Default nixpkgs packages - pkgs.boost - # Repo dependencies - crypto3 - blueprint - ]; - - defaultDevTools = [ - pkgs.clang_17 # clang-format and clang-tidy - ]; - - - defaultCmakeFlags = [ - "-DCMAKE_CXX_STANDARD=17" - "-DBUILD_SHARED_LIBS=TRUE" - "-DZKLLVM_VERSION=1.2.3" # TODO change this - ]; - - releaseBuild = stdenv.mkDerivation { - name = "zkLLVM"; - cmakeBuildType = "Release"; - buildInputs = defaultBuildInputs ++ defaultNativeBuildInputs; - - ninjaFlags = "assigner clang transpiler"; - - src = self; # Here we should ignore all tests/* test/* examples/* folders to minimize rebuilds - - doCheck = false; - dontInstall = true; - }; - - # TODO: we need to propagate debug mode to dependencies here: - debugBuild = releaseBuild.overrideAttrs (finalAttrs: previousAttrs: { - name = previousAttrs.name + "-debug"; - cmakeBuildType = "Debug"; - buildInputs = defaultBuildInputs ++ defaultNativeBuildInputs; - }); - - makeDevShell = pkgs.mkShell { - nativeBuildInputs = defaultNativeBuildInputs - ++ defaultBuildInputs - ++ defaultDevTools; - - shellHook = '' - echo "zkLLVM dev environment activated" - export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${placeholder "out"}/libs/circifier/llvm/lib" - ''; - }; - in - { - packages = { - default = releaseBuild; - debug = debugBuild; - }; - apps = { - assigner = { - type = "app"; - program = "${self.packages.${system}.default}/bin/assigner"; + (flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { + inherit system; + overlays = [ nix-3rdparty.overlays.${system}.default ]; }; - clang = { - type = "app"; - program = "${self.packages.${system}.default}/bin/clang"; + crypto3 = nil-crypto3.packages.${system}.default; + blueprint = nil-zkllvm-blueprint.packages.${system}.default; + + in { + packages = rec { + inherit pkgs crypto3 blueprint; + zkllvm = (pkgs.callPackage ./zkllvm.nix { + src_repo = self; + crypto3 = crypto3; + blueprint = blueprint; + }); + debug = (pkgs.callPackage ./zkllvm.nix { + src_repo = self; + enableDebug = true; + crypto3 = crypto3; + blueprint = blueprint; + }); + release = zkllvm; + default = debug; }; - transpiler = { - type = "app"; - program = "${self.packages.${system}.default}/bin/transpiler"; + checks = rec { + release-tests = (pkgs.callPackage ./zkllvm.nix { + src_repo = self; + crypto3 = crypto3; + blueprint = blueprint; + enableTesting = true; + }); + debug-tests = (pkgs.callPackage ./zkllvm.nix { + src_repo = self; + enableDebug = true; + crypto3 = crypto3; + blueprint = blueprint; + enableTesting = true; + }); + default = debug-tests; }; - }; - devShells.default = makeDevShell; - } - ); + apps = { + assigner = { + type = "app"; + program = "${self.packages.${system}.default}/bin/assigner"; + }; + clang = { + type = "app"; + program = "${self.packages.${system}.default}/bin/clang"; + }; + transpiler = { + type = "app"; + program = "${self.packages.${system}.default}/bin/transpiler"; + }; + }; + })); } # To override some inputs: diff --git a/libs/assigner b/libs/assigner index d5424da7..94c85b94 160000 --- a/libs/assigner +++ b/libs/assigner @@ -1 +1 @@ -Subproject commit d5424da76d2a12de19203d47173a1ee9d2baedbd +Subproject commit 94c85b94aae37886508343ca1f15e6feb45ebed1 diff --git a/libs/circifier b/libs/circifier index 06e061e3..03e06120 160000 --- a/libs/circifier +++ b/libs/circifier @@ -1 +1 @@ -Subproject commit 06e061e333acf38165e6629b6f44d5f13bceaa58 +Subproject commit 03e0612051e52b9d7283e8d18aff3284282e399d diff --git a/libs/stdlib b/libs/stdlib index 888b44a3..e0ef4b3e 160000 --- a/libs/stdlib +++ b/libs/stdlib @@ -1 +1 @@ -Subproject commit 888b44a397cc57d29ffba47d324c5b76441b1e77 +Subproject commit e0ef4b3e1184e7af4da681ad94f859b4ca4c113b diff --git a/libs/transpiler b/libs/transpiler index 12a4a0ee..92332ff9 160000 --- a/libs/transpiler +++ b/libs/transpiler @@ -1 +1 @@ -Subproject commit 12a4a0eee4ec3c0c9e2ada644ef3e1603934e71d +Subproject commit 92332ff93e2d818191c7abb6149ad1f0fcbf404e diff --git a/run_tests.sh b/run_tests.sh new file mode 100755 index 00000000..6e40a4b3 --- /dev/null +++ b/run_tests.sh @@ -0,0 +1,97 @@ +#!/usr/bin/env bash +set -e +df -h + +echo "Build IR of the C++ examples" +df -h +ninja -k 0 compile_cpp_examples +ls -al ./examples/cpp + +echo "Build circuits(.crct) of the C++ examples" +ninja -k 0 cpp_examples_generate_crct +ls -al ./examples/cpp + +echo "Run simultaneous .tbl and .crct generation of the C++ examples" +df -h +ninja -k 0 cpp_examples_generate_both +ls -al ./examples/cpp + +echo "Run size estimation for C++ examples" +df -h +ninja -k 0 cpp_examples_estimate_size + +echo "Move examples' circuits and assignments for uploading" +df -h +chmod +x ../examples/move_artifacts.sh +bash ../examples/move_artifacts.sh examples/cpp ${ARTIFACTS_DIR}examples_output +ls -al ${ARTIFACTS_DIR}examples_output/ + +echo "Compile tests as cpp code" +df -h +ninja -k 0 all_tests_compile_as_cpp_code + +echo "Compile tests as circuits" +df -h +ninja -k 0 all_tests_compile_as_circuits + +echo "Run tests as cpp code (expected res calculation)" +df -h +ninja -k 0 all_tests_run_expected_res_calculation + +echo "Get transpiler output for integration testing" +ninja -k 0 arithmetics_cpp_example_evm_verifier \ + polynomial_cpp_example_evm_verifier \ + poseidon_cpp_example_evm_verifier \ + merkle_tree_poseidon_cpp_example_evm_verifier \ + uint_remainder_cpp_evm_verifier \ + compare_eq_cpp_evm_verifier \ + private_input_cpp_evm_verifier + + #uint_shift_left_evm_verifier \ TODO fix and re-enable tests + #uint_bit_decomposition_evm_verifier \ TODO fix and re-enable tests + #uint_bit_composition_evm_verifier \ TODO fix and re-enable tests + +ls -al ./examples/cpp/ +find -name "transpiler_output_*" +mkdir -p "$ARTIFACTS_DIR"cpp +mv examples/cpp/transpiler_output_* "$ARTIFACTS_DIR"cpp + +echo "Run tests as circuits (real res calculation)" +df -h +ninja -k 0 all_tests_assign_circuits + +echo "Compare expected and real test results" +df -h +cd .. + # the following scripts are expected to run from the root of repository + chmod +x ./tests/run_test_results_comparison.sh + bash ./tests/run_test_results_comparison.sh + + echo "Run tests on faulty inputs" + df -h + chmod +x ./tests/run_tests_faulty_input.sh + bash ./tests/run_tests_faulty_input.sh pallas +cd - + +echo "Run assigner unit tests" +df -h +ninja -k 0 check-crypto3-assigner + +echo "Build proof for the circuit of the C++ examples" +df -h +ninja -k 0 prove_cpp_examples + +echo "Build recursive gen" +df -h +ninja -k 0 recursive_gen + +echo "Build and run transpiler test" +df -h +ninja -k 0 compile_and_run_transpiler_tests + +echo "Run recursive verifier tests" +df -h +ninja -k 0 recursion + +echo "finish" + diff --git a/tests/cpp/CMakeLists.txt b/tests/cpp/CMakeLists.txt index de1e1c3b..8de48228 100644 --- a/tests/cpp/CMakeLists.txt +++ b/tests/cpp/CMakeLists.txt @@ -131,14 +131,14 @@ file(REMOVE ../../build/tests/cpp/expected_results_list.txt) # curve tests add_zkllvm_unit_test("algebra/curves/25519_arithmetics/compare") -# add_zkllvm_unit_test("algebra/curves/25519_arithmetics/add") # fails when return value is 0,0 due to crypto3 bug, temporarily disabled -# add_zkllvm_unit_test("algebra/curves/25519_arithmetics_2/mul") # fails when return value is 0,0 due to crypto3 bug, temporarily disabled +# add_zkllvm_unit_test("algebra/curves/25519_arithmetics/add") # fails when return value is 0,0 due to https://github.com/NilFoundation/zkLLVM/issues/618, temporarily disabled +# add_zkllvm_unit_test("algebra/curves/25519_arithmetics_2/mul") # fails when return value is 0,0 due to https://github.com/NilFoundation/zkLLVM/issues/618, temporarily disabled if(APPLE) -# add_zkllvm_unit_test("algebra/curves/constructors/zero_pallas") # fails when return value is 0,0 due to crypto3 bug, temporarily disabled -# add_zkllvm_unit_test("algebra/curves/constructors/one_pallas") # fails when return value is 0,0 due to crypto3 bug, temporarily disabled -# add_zkllvm_unit_test("algebra/curves/constructors/zero_ed25519") # fails when return value is 0,0 due to crypto3 bug, temporarily disabled -# add_zkllvm_unit_test("algebra/curves/constructors/one_ed25519") # fails when return value is 0,0 due to crypto3 bug, temporarily disabled +# add_zkllvm_unit_test("algebra/curves/constructors/zero_pallas") # fails when return value is 0,0 due to https://github.com/NilFoundation/zkLLVM/issues/618, temporarily disabled +# add_zkllvm_unit_test("algebra/curves/constructors/one_pallas") # fails when return value is 0,0 due to https://github.com/NilFoundation/zkLLVM/issues/618, temporarily disabled +# add_zkllvm_unit_test("algebra/curves/constructors/zero_ed25519") # fails when return value is 0,0 due to https://github.com/NilFoundation/zkLLVM/issues/618, temporarily disabled +# add_zkllvm_unit_test("algebra/curves/constructors/one_ed25519") # fails when return value is 0,0 due to https://github.com/NilFoundation/zkLLVM/issues/618, temporarily disabled endif() add_zkllvm_unit_test("algebra/curves/pallas_arithmetics/compare") @@ -189,12 +189,12 @@ add_zkllvm_unit_test_pallas_multiprover("multi_provers/if" 2) add_zkllvm_unit_test("custom_cases/getelementptr_as_constant/getelementptr_as_constant") #libc functions -#add_zkllvm_unit_test("libc/memset/memset") -#add_zkllvm_unit_test("libc/strlen/strlen") -#add_zkllvm_unit_test("libc/strcmp/strcmp") -#add_zkllvm_unit_test("libc/strncmp/strncmp") -#add_zkllvm_unit_test("libc/strcpy/strcpy") -#add_zkllvm_unit_test("libc/strncpy/strncpy") +#add_zkllvm_unit_test("libc/memset/memset") # fails when return value is 0,0 due to https://github.com/NilFoundation/zkLLVM/issues/618, temporarily disabled +#add_zkllvm_unit_test("libc/strlen/strlen") # fails when return value is 0,0 due to https://github.com/NilFoundation/zkLLVM/issues/618, temporarily disabled +#add_zkllvm_unit_test("libc/strcmp/strcmp") # fails when return value is 0,0 due to https://github.com/NilFoundation/zkLLVM/issues/618, temporarily disabled +#add_zkllvm_unit_test("libc/strncmp/strncmp") # fails when return value is 0,0 due to https://github.com/NilFoundation/zkLLVM/issues/618, temporarily disabled +#add_zkllvm_unit_test("libc/strcpy/strcpy") # fails when return value is 0,0 due to https://github.com/NilFoundation/zkLLVM/issues/618, temporarily disabled +#add_zkllvm_unit_test("libc/strncpy/strncpy") # fails when return value is 0,0 due to https://github.com/NilFoundation/zkLLVM/issues/618, temporarily disabled # hashes add_zkllvm_unit_test("hashes/sha256/sha2_256") diff --git a/tests/move_assigner_outputs.sh b/tests/move_assigner_outputs.sh new file mode 100755 index 00000000..ce717303 --- /dev/null +++ b/tests/move_assigner_outputs.sh @@ -0,0 +1,11 @@ +SRC_DIR="$1" +DEST_DIR="$2" + +if [ ! -d "$DEST_DIR" ]; then + mkdir -p "$DEST_DIR" +fi + +find "$SRC_DIR" -type f -name "*.crct*" -exec mv {} "$DEST_DIR" \; +find "$SRC_DIR" -type f -name "*.tbl*" -exec mv {} "$DEST_DIR" \; + +echo "All .crct and .tbl files have been moved from $SRC_DIR to $DEST_DIR." diff --git a/zkllvm.nix b/zkllvm.nix new file mode 100644 index 00000000..cfe9733b --- /dev/null +++ b/zkllvm.nix @@ -0,0 +1,61 @@ +{ lib, + stdenv, + src_repo, + pkgs, + ninja, + pkg-config, + cmake, + # We'll use boost183 by default, but you can override it + boost_lib ? pkgs.boost183, + gdb, + cmake_modules, + crypto3, + blueprint, + python3, + git, + cargo, + openssl, + enableDebugging, + enableDebug ? false, + enableTesting ? false + }: +let + inherit (lib) optional; +in stdenv.mkDerivation { + name = "Zkllvm"; + 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 blueprint cmake_modules python3 git cargo openssl]; + + cmakeFlags = + [ + (if enableTesting then "-DENABLE_TESTS=TRUE" else "") + (if enableTesting then "-DBUILD_TESTS=TRUE" else "") + (if enableTesting then "-DCMAKE_ENABLE_TESTS=TRUE" else "") + + (if enableDebug then "-DCMAKE_BUILD_TYPE=Debug" else "-DCMAKE_BUILD_TYPE=Release") + (if enableDebug then "-DCMAKE_CXX_FLAGS=-ggdb" else "") + "-DZKLLVM_VERSION=0.1.18" + "-DGENERATE_EVM_VERIFIER=TRUE" + ]; + + ninjaFlags = "assigner clang transpiler"; + + doCheck = enableTesting; + + checkPhase = '' + export ARTIFACTS_DIR="$out/artifacts/" + echo "ARTIFACTS_DIR=$ARTIFACTS_DIR" + mkdir -p "$ARTIFACTS_DIR/artifacts" + bash ../run_tests.sh + ''; + + shellHook = '' + echo "Welcome to zkllvm development environment!" + ''; +}