diff --git a/.github/workflows/build_linux.yml b/.github/workflows/build_linux.yml deleted file mode 100644 index a4566c3f..00000000 --- a/.github/workflows/build_linux.yml +++ /dev/null @@ -1,431 +0,0 @@ -name: build-linux - -on: - push: - branches: [ master ] - pull_request: - -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: - handle-syncwith: - if: github.event_name == 'pull_request' - name: Call Reusable SyncWith Handler - uses: NilFoundation/ci-cd/.github/workflows/reusable-handle-syncwith.yml@v1.1.2 - with: - ci-cd-ref: 'v1.1.2' - secrets: inherit - - build-and-test-linux: - name: Build zkLLVM, run local tests, prepare for integration testing - runs-on: [ self-hosted, Linux, X64, aws_autoscaling ] - needs: - - handle-syncwith - # Condition is needed to run it for push event (handle-syncwith is skipped) - if: | - always() && !cancelled() && - (needs.handle-syncwith.result == 'success' || needs.handle-syncwith.result == 'skipped') - outputs: - transpiler-artifact-name: ${{ steps.artifact-names.outputs.transpiler }} - examples-artifact-name: ${{ steps.artifact-names.outputs.examples }} - evm-targets: ${{ steps.get-targets.outputs.evm-targets }} - prover-targets: ${{ steps.get-targets.outputs.prover-targets }} - - env: - CONTAINER_TMP: /opt/ - HOST_TMP: /home/runner/work/_temp/ - DEBIAN_FRONTEND: noninteractive - BOOST_VERSION: "1.78.0" - INTEGRATION_TESTING_TARGETS: | - arithmetics_cpp_example - polynomial_cpp_example - poseidon_cpp_example - merkle_tree_poseidon_cpp_example - uint_remainder_cpp - uint_shift_left - uint_bit_decomposition - uint_bit_composition - compare_eq_cpp - private_input_cpp - - container: - image: ubuntu:22.04 - volumes: - - /home/runner/work/_temp/:/opt/ - - steps: - - name: Install dependencies - run: | - env && \ - apt update && \ - apt install -y \ - build-essential \ - libssl-dev \ - cmake \ - ninja-build \ - git \ - libicu-dev \ - curl \ - pkg-config - - - name: Print toolchain information - run: | - git --version - cc --version - cmake --version - ninja --version - - - name: Checkout sources - # We need full history, because during CMake config stage we are finding the nearest tag - uses: actions/checkout@v4 - with: - fetch-depth: 0 - submodules: false - - # Workaround: https://github.com/actions/checkout/issues/1169 - - name: Mark directory as safe - run: | - git config --system --add safe.directory $PWD - - - name: Checkout submodules - run: | - git submodule update --init --recursive --depth=1 - - - name: Checkout modules to specified refs - if: needs.handle-syncwith.outputs.prs-refs != '' - uses: NilFoundation/ci-cd/actions/recursive-checkout@v1.2.1 - # TODO: figure out the mapping of volumes and use variable here, not hardcoded path - with: - paths: | - /__w/zkLLVM/zkLLVM/** - !/__w/zkLLVM/zkLLVM/ - !/__w/zkLLVM/zkLLVM/**/.git/** - refs: ${{ needs.handle-syncwith.outputs.prs-refs }} - - - name: Clean index.lock files if checkout step was cancelled or failed - if: cancelled() || failure() - run: | - find .git -name 'index.lock' -exec rm -v {} \; - - - name: Install boost - uses: MarkusJx/install-boost@v2.4.1 - id: install-boost - with: - # A list of supported versions can be found here: - # https://github.com/MarkusJx/prebuilt-boost/blob/main/versions-manifest.json - boost_version: ${{ env.BOOST_VERSION }} - boost_install_dir: ${{ env.CONTAINER_TMP }} - platform_version: 22.04 - toolset: gcc - arch: x86 - - - name: Install Python - uses: actions/setup-python@v4 - with: - python-version: '3.10' - - - name: Install Rust - uses: dtolnay/rust-toolchain@stable - - - name: Configure CMake - env: - BOOST_ROOT: "${{ steps.install-boost.outputs.BOOST_ROOT }}" - run: | - cmake . \ - -G "Ninja" \ - -B build \ - -DCMAKE_BUILD_TYPE=Release \ - -DBUILD_TESTS=TRUE \ - -DRSLANG_BUILD_EXTENDED=TRUE \ - -DRSLANG_BUILD_TOOLS=cargo \ - -DGENERATE_EVM_VERIFIER=TRUE - - - name: Build zkllvm - run: | - cmake --build build -t assigner clang transpiler - - - name: Build IR of the C++ examples - run: | - cmake --build build -t compile_cpp_examples - ls -al ./build/examples/cpp - - - name: Build circuits(.crct) of the C++ examples - run: | - cmake --build build -t cpp_examples_generate_crct - ls -al ./build/examples/cpp - - - name: Build assignment tables(.tbl) of the C++ examples - run: | - cmake --build build -t cpp_examples_generate_tbl_no_check - ls -al ./build/examples/cpp - - - name: Copy assigner output from separate generation mode - run: | - bash ./tests/copy_assigner_outputs.sh build/separate_generatuon - - - name: Run simultaneous .tbl and .crct generation of the C++ examples - run: | - cmake --build build -t cpp_examples_generate_both - ls -al ./build/examples/cpp - - - name: Copy assigner output from simultaneous generation mode - run: | - bash ./tests/copy_assigner_outputs.sh 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: | - cmake --build build -t 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 - - - name: Set aritfacts' names - id: artifact-names - run: | - echo "transpiler=transpiler-output" >> $GITHUB_OUTPUT - echo "examples=circuits-and-assignments" >> $GITHUB_OUTPUT - - - name: Upload examples' circuits and assignments artifact - uses: actions/upload-artifact@v3 - with: - name: ${{ steps.artifact-names.outputs.examples }} - path: | - examples_output - - - name: Compile tests as cpp code - run: | - cmake --build build -t all_tests_compile_as_cpp_code - - - name: Compile tests as circuits - run: | - cmake --build build -t all_tests_compile_as_circuits - - - name: Run tests as cpp code (expected res calculation) - run: | - cmake --build build -t all_tests_run_expected_res_calculation -j$(nproc) - - - name: Get transpiler output for integration testing - run: | - targets_str=$(echo "${{ env.INTEGRATION_TESTING_TARGETS }}" | awk 'NF {printf "-t %s_evm_verifier ", $0}' | sed 's/[[:space:]]*$//') - cmake --build build ${targets_str} - - - 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: | - cmake --build build -t all_tests_assign_circuits -j$(nproc) - - - 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: | - cmake --build build -t check-crypto3-assigner - - - name: Build proof for the circuit of the C++ examples - run: | - cmake --build build -t prove_cpp_examples - - - name: Build recursive gen - run: | - cmake --build build -t recursive_gen - - - name: Build and run transpiler test - run: | - cmake --build build -t compile_and_run_transpiler_tests - - - name: Run recursive verifier tests - run: | - cmake --build build -t recursion - - - name: Build rslang - run: | - export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$(pwd)/build/libs/circifier/llvm/lib" - echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$(pwd)/build/libs/circifier/llvm/lib" >> $GITHUB_ENV - cmake --build build -t rslang - - - name: Build IR of the Rust examples - run: | - cmake --build build -t compile_rust_examples - ls -al ./build/examples/rust/target/assigner-unknown-unknown/release/examples - - - name: Build circuits(.crct) of the Rust examples - run: | - cmake --build build -t rust_examples_generate_crct - ls -al ./build/examples/cpp - - - name: Build assignment tables(.tbl) of the Rust examples - run: | - cmake --build build -t rust_examples_generate_tbl - ls -al ./build/examples/cpp - - - name: Build proof for the circuit of the Rust examples - run: | - cmake --build build -t prove_rust_examples - - - name: Set targets for integration testing - id: get-targets - run: | - targets_str=$(echo "${{ env.INTEGRATION_TESTING_TARGETS }}" | awk 'NF {print "transpiler_output_" $1}') - echo "evm-targets<> $GITHUB_OUTPUT - echo "${targets_str}" >> $GITHUB_OUTPUT - echo "EOF" >> $GITHUB_OUTPUT - - echo "prover-targets<> $GITHUB_OUTPUT - echo "${{ env.INTEGRATION_TESTING_TARGETS }}" >> $GITHUB_OUTPUT - echo "EOF" >> $GITHUB_OUTPUT - - - verify-zkllvm-proofs: - name: Verify built-it proofs with EVM-placeholder - needs: - - build-and-test-linux - - handle-syncwith - if: | - always() && !cancelled() && - (needs.handle-syncwith.result == 'success' || needs.handle-syncwith.result == 'skipped') && - needs.build-and-test-linux.result == 'success' - uses: NilFoundation/evm-placeholder-verification/.github/workflows/reusable-verify-proofs.yml@2a0ef5fc67e97be8e3c7b59338cf9eecd030c57d - with: - artifact-name: ${{ needs.build-and-test-linux.outputs.transpiler-artifact-name }} - evm-placeholder-verification-ref: 2a0ef5fc67e97be8e3c7b59338cf9eecd030c57d - refs: ${{ needs.handle-syncwith.outputs.prs-refs }} - test-names: ${{ needs.build-and-test-linux.outputs.evm-targets }} - - - generate-proofs: - name: Generate proofs for cpp examples - needs: - - build-and-test-linux - - handle-syncwith - if: | - always() && !cancelled() && - (needs.handle-syncwith.result == 'success' || needs.handle-syncwith.result == 'skipped') && - needs.build-and-test-linux.result == 'success' - uses: NilFoundation/proof-producer/.github/workflows/reusable-generate-proofs-linux.yml@ef8cd9152b4bec871e7efdc1d6b606e445bad274 - with: - artifact-name: ${{ needs.build-and-test-linux.outputs.examples-artifact-name }} - # Update next line if you need new version of proof producer - proof-producer-ref: ef8cd9152b4bec871e7efdc1d6b606e445bad274 - refs: ${{ needs.handle-syncwith.outputs.prs-refs }} - targets: ${{ needs.build-and-test-linux.outputs.prover-targets }} - - - merge-proofs-to-transpiler-output: - runs-on: ubuntu-22.04 - needs: - - generate-proofs - - build-and-test-linux - if: | - always() && !cancelled() && - needs.generate-proofs.result == 'success' && - needs.build-and-test-linux.result == 'success' - outputs: - merged-artifact-name: ${{ steps.artifact-name.outputs.merged }} - steps: - - name: Download artifact with proofs - uses: actions/download-artifact@v3 - with: - name: ${{ needs.generate-proofs.outputs.artifact-name }} - - - name: Download artifact with transpiler output - uses: actions/download-artifact@v3 - with: - name: ${{ needs.build-and-test-linux.outputs.transpiler-artifact-name }} - - - name: Merge proofs into transpiler output - run: | - copy_failed=0 - while read dir; do - base_name=${dir#./transpiler_output_} - - if [[ -d "$base_name" ]]; then - if ! cp "${base_name}/proof.bin" "${dir}/"; then - echo "Failed to copy proof.bin to ${dir}" >&2 - copy_failed=1 - else - echo "proof.bin added to ${dir}" - fi - else - echo "Error: No matching directory found for ${dir}" >&2 - fi - done < <(find . -type d -name "transpiler_output_*") - - if [ $copy_failed -eq 1 ]; then - echo "One or more copy operations failed." - exit 1 - fi - - - name: Set aritfact name - id: artifact-name - run: | - echo "merged=transpiler-output-merged-proofs" >> $GITHUB_OUTPUT - - - name: Upload merged artifact - uses: actions/upload-artifact@v3 - with: - name: ${{ steps.artifact-name.outputs.merged }} - path: | - transpiler_output_* - - - verify-proof-producer-proofs: - name: Verify proof-producer proofs with EVM-placeholder - needs: - - handle-syncwith - - merge-proofs-to-transpiler-output - - build-and-test-linux - if: | - always() && !cancelled() && - (needs.handle-syncwith.result == 'success' || needs.handle-syncwith.result == 'skipped') && - needs.build-and-test-linux.result == 'success' && - needs.merge-proofs-to-transpiler-output.result == 'success' - uses: NilFoundation/evm-placeholder-verification/.github/workflows/reusable-verify-proofs.yml@2a0ef5fc67e97be8e3c7b59338cf9eecd030c57d - with: - artifact-name: ${{ needs.merge-proofs-to-transpiler-output.outputs.merged-artifact-name }} - evm-placeholder-verification-ref: 2a0ef5fc67e97be8e3c7b59338cf9eecd030c57d - refs: ${{ needs.handle-syncwith.outputs.prs-refs }} - test-names: ${{ needs.build-and-test-linux.outputs.evm-targets }} - - cleanup-integration-testing: - # For now each artifact is 12 GB. Better clean it up to keep the space - name: Clean up after integration testing - needs: - - verify-proof-producer-proofs - - verify-zkllvm-proofs - - merge-proofs-to-transpiler-output - - build-and-test-linux - - generate-proofs - if: always() - runs-on: ubuntu-22.04 - steps: - - uses: geekyeggo/delete-artifact@v2 - with: - name: | - ${{ needs.merge-proofs-to-transpiler-output.outputs.merged-artifact-name }} - ${{ needs.generate-proofs.outputs.artifact-name }} diff --git a/.github/workflows/build_macos.yml b/.github/workflows/build_macos.yml deleted file mode 100644 index 84606f80..00000000 --- a/.github/workflows/build_macos.yml +++ /dev/null @@ -1,185 +0,0 @@ -name: build-macos - -on: - push: - branches: [ master ] - pull_request: - -concurrency: - group: ${{ - ( github.ref == 'refs/heads/master' && - format('{0}/{1}', github.run_id, github.run_attempt) ) - || - format('{0}/{1}', github.workflow, github.ref) }} - cancel-in-progress: true - -jobs: - handle-syncwith: - if: github.event_name == 'pull_request' - name: Call Reusable SyncWith Handler - uses: NilFoundation/ci-cd/.github/workflows/reusable-handle-syncwith.yml@v1 - with: - ci-cd-ref: 'v1' - fetch-only: true - secrets: inherit - - build-macos: - runs-on: [ macos-11 ] - - needs: - - handle-syncwith - - steps: - - name: Install homebrew - run: > - /bin/bash -c "$(curl -fsSL - https://raw.githubusercontent.com/Homebrew/install/master/install.sh - )" - - - name: Run brew install - id: brew-install - run: | - brew install \ - boost@1.76 \ - cmake \ - ninja \ - icu4c \ - libiconv \ - openssl \ - curl \ - bash - - - name: Install Python - uses: actions/setup-python@v4 - with: - python-version: '3.10' - - - name: Print toolchain information - run: | - git --version - cc --version - cmake --version - ninja --version - bash --version - python3 --version - which -a bash - echo PATH: $PATH - - - name: Checkout sources - # We need full history, because during CMake config stage we are finding the nearest tag - uses: actions/checkout@v3 - with: - fetch-depth: 0 - submodules: false - - - name: Checkout submodules - run: | - git submodule update --init --recursive --depth=1 - - - name: Checkout modules to specified refs - if: needs.handle-syncwith.outputs.prs-refs != '' - uses: NilFoundation/ci-cd/actions/recursive-checkout@v1.2.1 - with: - paths: | - ${{ github.workspace }}/** - !${{ github.workspace }} - !${{ github.workspace }}/**/.git/** - refs: ${{ needs.handle-syncwith.outputs.prs-refs }} - - - name: Enable ccache - uses: hendrikmuhs/ccache-action@v1.2 - with: - key: ${{ github.job }} - - - name: Configure CMake - env: - BOOST_ROOT: "/usr/local/opt/boost@1.76" - LDFLAGS: "-L/usr/local/opt/icu4c/lib" - CPPFLAGS: "-I/usr/local/opt/icu4c/include" - run: | - cmake -G "Ninja" \ - -B build \ - -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ - -DCMAKE_BUILD_TYPE=Release \ - -DBUILD_SHARED_LIBS=FALSE \ - -DBUILD_TESTS=TRUE . - - - name: Build zkllvm - run: | - cmake --build build -t assigner clang transpiler - - - name: Build IR of the C++ examples - run: | - cmake --build build -t compile_cpp_examples - ls -al ./build/examples/cpp - - - name: Build circuits(.crct) of the C++ examples - run: | - cmake --build build -t cpp_examples_generate_crct - ls -al ./build/examples/cpp - - - name: Build assignment tables(.tbl) of the C++ examples - run: | - cmake --build build -t cpp_examples_generate_tbl_no_check - ls -al ./build/examples/cpp - - - name: Run size estimation for C++ examples - run: | - cmake --build build -t cpp_examples_estimate_size - - - name: Compile tests as cpp code - run: | - cmake --build build -t all_tests_compile_as_cpp_code - - - name: Compile tests as circuits - run: | - cmake --build build -t all_tests_compile_as_circuits - - - name: Run tests as cpp code (expected res calculation) - run: | - cmake --build build -t all_tests_run_expected_res_calculation - - - name: Run tests as circuits (real res calculation) - run: | - cmake --build build -t 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: | - cmake --build build -t check-crypto3-assigner - - - name: Build proof for the circuit of the C++ examples - run: | - cmake --build build -t prove_cpp_examples - - - name: Build rslang - run: | - cmake --build build -t rslang - - - name: Build IR of the Rust examples - run: | - cmake --build build -t compile_rust_examples - ls -al ./build/examples/rust/target/assigner-unknown-unknown/release/examples - - - name: Build circuits(.crct) of the Rust examples - run: | - cmake --build build -t rust_examples_generate_crct - ls -al ./build/examples/cpp - - - name: Build assignment tables(.tbl) of the Rust examples - run: | - cmake --build build -t rust_examples_generate_tbl - ls -al ./build/examples/cpp - - - name: Build proofs for the circuits of the Rust examples - run: | - cmake --build build -t prove_rust_examples diff --git a/.github/workflows/nix_build_linux.yml b/.github/workflows/nix_build_linux.yml new file mode 100644 index 00000000..0c58d12e --- /dev/null +++ b/.github/workflows/nix_build_linux.yml @@ -0,0 +1,231 @@ +name: Run tests + +on: + # Triggers the workflow on pull request events but only for the master branch + pull_request: + branches: [ master ] + push: + branches: [ master ] + +jobs: + handle-syncwith: + if: github.event_name == 'pull_request' + name: Call Reusable SyncWith Handler + uses: NilFoundation/ci-cd/.github/workflows/reusable-handle-syncwith.yml@v1 + with: + ci-cd-ref: 'v1' + secrets: inherit + + build-and-test-with-nix: + needs: [ handle-syncwith ] + runs-on: ["self-hosted", "aws_autoscaling"] + outputs: + transpiler-artifact-name: ${{ steps.artifact-names.outputs.transpiler }} + examples-artifact-name: ${{ steps.artifact-names.outputs.examples }} + evm-targets: ${{ steps.get-targets.outputs.evm-targets }} + prover-targets: ${{ steps.get-targets.outputs.prover-targets }} + env: + INTEGRATION_TESTING_TARGETS: | + arithmetics_cpp_example + polynomial_cpp_example + poseidon_cpp_example + merkle_tree_poseidon_cpp_example + uint_remainder_cpp + compare_eq_cpp + private_input_cpp + # uint_shift_left # TODO fix and re-enable tests + # uint_bit_decomposition # TODO fix and re-enable tests + # uint_bit_composition # TODO fix and re-enable tests + strategy: + fail-fast: false + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 1 + submodules: recursive + + - name: Checkout submodules to specified refs + if: inputs.submodules-refs != '' + uses: NilFoundation/ci-cd/actions/recursive-checkout@master + with: + refs: ${{ inputs.submodules-refs }} + paths: | + ${{ github.workspace }}/** + !${{ github.workspace }}/ + !${{ github.workspace }}/**/.git/** + + - name: Build zkLLVM, run local tests, prepare for integration testing + run: | + nix build -L .?submodules=1#checks.x86_64-linux.debug-tests + echo "nix build finished" + 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 + run: | + echo "transpiler=transpiler-output" >> $GITHUB_OUTPUT + echo "examples=circuits-and-assignments" >> $GITHUB_OUTPUT + + - name: Upload examples' circuits and assignments artifact + uses: actions/upload-artifact@v3 + with: + name: ${{ steps.artifact-names.outputs.examples }} + path: | + examples_output + 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: | + result/artifacts/cpp/transpiler_output_* + if-no-files-found: error + + - name: Set targets for integration testing + id: get-targets + run: | + targets_str=$(echo "${{ env.INTEGRATION_TESTING_TARGETS }}" | awk 'NF {print "transpiler_output_" $1}') + echo "evm-targets<> $GITHUB_OUTPUT + echo "${targets_str}" >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT + + echo "prover-targets<> $GITHUB_OUTPUT + echo "${{ env.INTEGRATION_TESTING_TARGETS }}" >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT + + verify-zkllvm-proofs: + name: Verify built-it proofs with EVM-placeholder + needs: + - build-and-test-with-nix + - handle-syncwith + if: | + always() && !cancelled() && + (needs.handle-syncwith.result == 'success' || needs.handle-syncwith.result == 'skipped') && + needs.build-and-test-with-nix.result == 'success' + uses: NilFoundation/evm-placeholder-verification/.github/workflows/reusable-verify-proofs.yml@2a0ef5fc67e97be8e3c7b59338cf9eecd030c57d + with: + artifact-name: ${{ needs.build-and-test-with-nix.outputs.transpiler-artifact-name }} + evm-placeholder-verification-ref: 2a0ef5fc67e97be8e3c7b59338cf9eecd030c57d + refs: ${{ needs.handle-syncwith.outputs.prs-refs }} + test-names: ${{ needs.build-and-test-with-nix.outputs.evm-targets }} + + generate-proofs: + name: Generate proofs for cpp examples + needs: + - build-and-test-with-nix + - handle-syncwith + if: | + 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@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: f3e985dabe0d20ecb75375f86d8cf2a71e2eb58b + refs: ${{ needs.handle-syncwith.outputs.prs-refs }} + targets: ${{ needs.build-and-test-with-nix.outputs.prover-targets }} + + merge-proofs-to-transpiler-output: + runs-on: ubuntu-22.04 + needs: + - generate-proofs + - build-and-test-with-nix + if: | + always() && !cancelled() && + needs.generate-proofs.result == 'success' && + needs.build-and-test-with-nix.result == 'success' + outputs: + merged-artifact-name: ${{ steps.artifact-name.outputs.merged }} + steps: + - name: Download artifact with proofs + uses: actions/download-artifact@v3 + with: + name: ${{ needs.generate-proofs.outputs.artifact-name }} + + - name: Download artifact with transpiler output + uses: actions/download-artifact@v3 + with: + name: ${{ needs.build-and-test-with-nix.outputs.transpiler-artifact-name }} + + - name: Merge proofs into transpiler output + run: | + copy_failed=0 + while read dir; do + base_name=${dir#./transpiler_output_} + + if [[ -d "$base_name" ]]; then + if ! cp "${base_name}/proof.bin" "${dir}/"; then + echo "Failed to copy proof.bin to ${dir}" >&2 + copy_failed=1 + else + echo "proof.bin added to ${dir}" + fi + else + echo "Error: No matching directory found for ${dir}" >&2 + fi + done < <(find . -type d -name "transpiler_output_*") + + if [ $copy_failed -eq 1 ]; then + echo "One or more copy operations failed." + exit 1 + fi + + - name: Set aritfact name + id: artifact-name + run: | + echo "merged=transpiler-output-merged-proofs" >> $GITHUB_OUTPUT + + - name: Upload merged artifact + uses: actions/upload-artifact@v3 + with: + name: ${{ steps.artifact-name.outputs.merged }} + path: | + transpiler_output_* + + verify-proof-producer-proofs: + name: Verify proof-producer proofs with EVM-placeholder + needs: + - handle-syncwith + - merge-proofs-to-transpiler-output + - build-and-test-with-nix + if: | + always() && !cancelled() && + (needs.handle-syncwith.result == 'success' || needs.handle-syncwith.result == 'skipped') && + needs.build-and-test-with-nix.result == 'success' && + needs.merge-proofs-to-transpiler-output.result == 'success' + uses: NilFoundation/evm-placeholder-verification/.github/workflows/reusable-verify-proofs.yml@2a0ef5fc67e97be8e3c7b59338cf9eecd030c57d + with: + artifact-name: ${{ needs.merge-proofs-to-transpiler-output.outputs.merged-artifact-name }} + evm-placeholder-verification-ref: 2a0ef5fc67e97be8e3c7b59338cf9eecd030c57d + refs: ${{ needs.handle-syncwith.outputs.prs-refs }} + test-names: ${{ needs.build-and-test-with-nix.outputs.evm-targets }} + + cleanup-integration-testing: + # For now each artifact is 12 GB. Better clean it up to keep the space + name: Clean up after integration testing + needs: + - verify-proof-producer-proofs + - verify-zkllvm-proofs + - merge-proofs-to-transpiler-output + - build-and-test-with-nix + - generate-proofs + if: always() + runs-on: ubuntu-22.04 + steps: + - uses: geekyeggo/delete-artifact@v2 + with: + name: | + ${{ needs.merge-proofs-to-transpiler-output.outputs.merged-artifact-name }} + ${{ needs.generate-proofs.outputs.artifact-name }} diff --git a/.github/workflows/release_linux.yml b/.github/workflows/release_linux.yml deleted file mode 100644 index 46529840..00000000 --- a/.github/workflows/release_linux.yml +++ /dev/null @@ -1,170 +0,0 @@ -name: Make release - -# Controls when the action will run. Workflow runs when manually triggered using the UI -# or API. -on: - workflow_dispatch: - inputs: - release_type: - type: choice - description: Release type - options: - - major - - minor - - patch - default: minor - -jobs: - make-release: - runs-on: [ self-hosted, Linux, X64, aws_autoscaling ] - environment: prod - - env: - CONTAINER_TMP: /opt/ - HOST_TMP: /home/runner/work/_temp/ - DEBIAN_FRONTEND: noninteractive - BOOST_VERSION: "1.80.0" - - container: - image: ubuntu:22.04 - volumes: - - /home/runner/work/_temp/:/opt/ - - steps: - - name: Install dependencies - run: | - env && \ - apt update && \ - apt install -y \ - build-essential \ - libssl-dev \ - cmake \ - git \ - curl \ - unzip \ - zstd \ - libicu-dev \ - pkg-config - - - name: Print toolchain information - run: | - git --version - cc --version - cmake --version - - - name: Checkout sources - uses: actions/checkout@v3 - with: - submodules: 'recursive' - fetch-depth: 0 - - # Workaround: https://github.com/actions/checkout/issues/1169 - - name: Mark directory as safe - run: | - git config --system --add safe.directory $PWD - - - name: Install boost - uses: MarkusJx/install-boost@v2.4.1 - id: install-boost - with: - # A list of supported versions can be found here: - # https://github.com/MarkusJx/prebuilt-boost/blob/main/versions-manifest.json - boost_version: ${{ env.BOOST_VERSION }} - boost_install_dir: ${{ env.CONTAINER_TMP }} - platform_version: 22.04 - toolset: gcc - arch: x86 - - - name: Install Python - uses: actions/setup-python@v4 - with: - python-version: '3.10' - - - name: Install Rust - uses: dtolnay/rust-toolchain@stable - - - name: Install aws tools - run: | - curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" - unzip awscliv2.zip - ./aws/install - pip3 install mkrepo - - - name: Compute release number - env: - RELEASE_TYPE: ${{ inputs.release_type }} - run: | - LATEST_TAG=`git describe --tags | cut -d'-' -f1 | tr -d v` - MAJOR=`echo $LATEST_TAG | cut -d'.' -f1` - MINOR=`echo $LATEST_TAG | cut -d'.' -f2` - PATCH=`echo $LATEST_TAG | cut -d'.' -f3` - - case $RELEASE_TYPE in - - major) - MAJOR=$((MAJOR+1)) - MINOR=0 - PATCH=0 - ;; - minor) - MINOR=$((MINOR+1)) - PATCH=0 - ;; - patch) - PATCH=$((PATCH+1)) - ;; - *) - echo "Unknown release type" - exit 1 - ;; - esac - echo "VERSION=$MAJOR.$MINOR.$PATCH" >> $GITHUB_ENV - echo "VERSION=$MAJOR.$MINOR.$PATCH" - - - name: Configure CMake - env: - BOOST_ROOT: "${{ steps.install-boost.outputs.BOOST_ROOT }}" - run: | - cmake -G "Unix Makefiles" \ - -B build \ - -DCMAKE_BUILD_TYPE=Release \ - -DZKLLVM_VERSION=${{ env.VERSION }} . - - - name: Build packages - run: | - make -C build package -j$(nproc) - - # TODO: we should consider distribution with dynamically linked LLVM - - name: Configure CMake for rslang - env: - BOOST_ROOT: "${{ steps.install-boost.outputs.BOOST_ROOT }}" - run: | - cmake -G "Unix Makefiles" \ - -B build_rslang \ - -DCMAKE_BUILD_TYPE=Release \ - -DBUILD_SHARED_LIBS=FALSE \ - -DZKLLVM_VERSION=${{ env.VERSION }} \ - -DRSLANG_BUILD_EXTENDED=TRUE \ - -DRSLANG_BUILD_TOOLS=cargo . - - - name: Build rslang distribution - run: | - make -C build_rslang rslang_dist -j$(nproc) - - - name: Create release - uses: ncipollo/release-action@v1 - with: - name: "zkllvm-v${{ env.VERSION }}" - tag: "v${{ env.VERSION }}" - artifacts: "build/zkllvm_*.deb,build/zkllvm-stdlib_*.deb,build_rslang/libs/rslang/build/dist/*" - - - name: Upload packages to repository - env: - AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} - AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }} - run: | - ZKLLVM_PACKAGE=`ls build/zkllvm_*.deb | cut -d'/' -f2` - POOL="ubuntu/pool/main/z/zkllvm" - aws s3api put-object --bucket deb.nil.foundation --key $POOL/$ZKLLVM_PACKAGE --body build/$ZKLLVM_PACKAGE - mkrepo s3://deb.nil.foundation/ubuntu/ diff --git a/.gitignore b/.gitignore index 150a7389..909fa04e 100644 --- a/.gitignore +++ b/.gitignore @@ -360,6 +360,9 @@ install_manifest.txt compile_commands.json CTestTestfile.cmake build +*build +build* +result ### LaTeX ### ## Core latex/pdflatex auxiliary files: diff --git a/.gitmodules b/.gitmodules index 82da3a01..92da7c0a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,15 +1,9 @@ -[submodule "cmake-modules"] - path = cmake/modules - url = ../../BoostCMake/cmake_modules.git [submodule "zkllvm-assigner"] path = libs/assigner url = ../../NilFoundation/zkllvm-assigner.git [submodule "zkllvm-circifier"] path = libs/circifier url = ../../NilFoundation/zkllvm-circifier.git -[submodule "zkllvm-blueprint"] - path = libs/blueprint - url = ../../NilFoundation/zkllvm-blueprint.git [submodule "libs/stdlib"] path = libs/stdlib url = ../../NilFoundation/zkllvm-stdlib.git @@ -19,6 +13,3 @@ [submodule "libs/rslang"] path = libs/rslang url = ../../NilFoundation/zkllvm-rslang.git -[submodule "libs/crypto3"] - path = libs/crypto3 - url = ../../NilFoundation/crypto3.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 5f4e788a..56185070 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,29 +14,17 @@ 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) - -macro(cm_find_package NAME) - if(NOT "${NAME}" MATCHES "^${CMAKE_WORKSPACE_NAME}_.*$" AND NOT "${NAME}" STREQUAL CM) - find_package(${ARGV}) - else() - set(${ARGV0}_FOUND ON CACHE BOOL "") - endif() -endmacro() - cm_setup_version(VERSION 0.3.0 PREFIX ${CMAKE_WORKSPACE_NAME}) option(BUILD_SHARED_LIBS "Build shared library" TRUE) -option(BUILD_WITH_CCACHE "Build with ccache usage" TRUE) option(BUILD_WITH_BOOST_STATIC_LIBS "Build using Boost static libraries" TRUE) -option(BUILD_TESTS "Build unit tests" FALSE) +option(CMAKE_ENABLE_TESTS "Build unit tests" FALSE) option(BUILD_DOCS "Build with configuring Doxygen documentation compiler" TRUE) option(CIRCUIT_BINARY_OUTPUT "Emit circuit IR as binary file" FALSE) option(RSLANG_BUILD_EXTENDED "Build Rust tools (see build.extended)" FALSE) @@ -51,51 +39,39 @@ set(RSLANG_BUILD_TOOLS "" CACHE STRING "Rust tools to build (see build.too include(TargetArchitecture) 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) set(Boost_USE_STATIC_LIBS TRUE) else() set(Boost_USE_STATIC_LIBS FALSE) endif() -if(UNIX AND BUILD_WITH_CCACHE) - find_program(CCACHE_FOUND ccache) - if(CCACHE_FOUND) - set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache) - set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache) - endif(CCACHE_FOUND) -endif() - if(BUILD_WITH_TARGET_ARCHITECTURE) set(CMAKE_TARGET_ARCHITECTURE ${BUILD_WITH_TARGET_ARCHITECTURE}) else() target_architecture(CMAKE_TARGET_ARCHITECTURE) endif() -if(BUILD_TESTS) - cm_find_package(Boost COMPONENTS REQUIRED unit_test_framework) -endif() - -add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/libs/crypto3") - -add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/libs/blueprint") add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/libs/assigner") add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/libs/transpiler") set(LLVM_ENABLE_PROJECTS "clang" CACHE STRING "Additional llvm projects") add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/libs/circifier/llvm") +include(CMTest) +cm_add_test_subdirectory(tests) add_subdirectory(examples) -if(BUILD_TESTS) - add_subdirectory(tests) -endif() - add_subdirectory(libs/stdlib) install(FILES cmake/CircuitCompile.cmake DESTINATION share/zkllvm) -find_package(Git REQUIRED) - if(NOT ZKLLVM_VERSION) + find_package(Git REQUIRED) execute_process(COMMAND ${GIT_EXECUTABLE} describe --tags HEAD OUTPUT_VARIABLE DESCRIBE_OUTBUT OUTPUT_STRIP_TRAILING_WHITESPACE @@ -135,13 +111,13 @@ set(CPACK_PACKAGE_VERSION "${ZKLLVM_VERSION_MAJOR}.${ZKLLVM_VERSION_MINOR}.${ZKL if(ZKLLVM_VERSION_INCREMENT) string(APPEND CPACK_PACKAGE_VERSION "-${ZKLLVM_VERSION_INCREMENT}") endif() -set(CPACK_PACKAGING_INSTALL_PREFIX "/usr/lib/zkllvm") +set(CPACK_PACKAGING_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/lib/zkllvm") 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 ${CMAKE_INSTALL_SYSCONFDIR}/ld.so.conf.d) set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_CURRENT_LIST_DIR}/cmake/triggers") set(CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION TRUE) @@ -154,8 +130,6 @@ include(CPack) add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/bin") -find_package(Python3 REQUIRED COMPONENTS Interpreter) - message(STATUS "Configuring rslang") execute_process(COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_LIST_DIR}/detect-platform.py 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/CMakeLists.txt b/bin/CMakeLists.txt index 78189ff7..37b5bf02 100644 --- a/bin/CMakeLists.txt +++ b/bin/CMakeLists.txt @@ -11,25 +11,6 @@ cmake_minimum_required(VERSION 3.5) cm_find_package(CM) include(CMDeploy) -if(NOT CMAKE_CROSSCOMPILING) - find_package(Boost COMPONENTS REQUIRED filesystem log log_setup program_options thread system) -elseif(CMAKE_CROSSCOMPILING) - if(NOT TARGET boost) - include(ExternalProject) - set(Boost_LIBRARIES boost_random) - externalproject_add(boost - PREFIX ${CMAKE_BINARY_DIR}/libs/boost - GIT_REPOSITORY git@github.com:boostorg/boost.git - GIT_TAG boost-1.77.0 - BUILD_IN_SOURCE TRUE - CMAKE_ARGS -DCMAKE_CROSSCOMPILING_EMULATOR=${CMAKE_CROSSCOMPILING_EMULATOR} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} - BUILD_COMMAND cmake --build . --target ${Boost_LIBRARIES} - INSTALL_COMMAND "") - else() - set(Boost_LIBRARIES boost_random) - endif() -endif() - set(WITNESS_COLUMNS 15 CACHE STRING "Number of witness columns") set(PUBLIC_INPUT_COLUMNS 1 CACHE STRING "Number of public input columns") set(COMPONENT_CONSTANT_COLUMNS 5 CACHE STRING "Number of component constant columns") diff --git a/bin/assigner/CMakeLists.txt b/bin/assigner/CMakeLists.txt index bc3553da..6a98635d 100644 --- a/bin/assigner/CMakeLists.txt +++ b/bin/assigner/CMakeLists.txt @@ -41,35 +41,16 @@ target_link_libraries(${CURRENT_PROJECT_NAME} LLVMIRReader LLVMCore LLVMSupport - crypto3::algebra - crypto3::block - crypto3::blueprint - crypto3::codec - crypto3::math - crypto3::multiprecision - crypto3::pkpad - crypto3::pubkey - crypto3::random - crypto3::zk - + crypto3::all crypto3::assigner - crypto3::transpiler - - marshalling::core - marshalling::crypto3_algebra - marshalling::crypto3_multiprecision - marshalling::crypto3_zk - + crypto3::blueprint ${Boost_LIBRARIES}) target_include_directories(${CURRENT_PROJECT_NAME} PUBLIC - $ - $ - ${CMAKE_CURRENT_SOURCE_DIR}/../../libs/circifier/llvm/include - ${CMAKE_CURRENT_SOURCE_DIR}/../../libs/circifier/utils/bazel/llvm-project-overlay/llvm/include + ${CMAKE_SOURCE_DIR}/libs/circifier/llvm/include + ${CMAKE_SOURCE_DIR}/libs/circifier/utils/bazel/llvm-project-overlay/llvm/include ${CMAKE_BINARY_DIR}/libs/circifier/llvm/include - - $<$:${Boost_INCLUDE_DIRS}>) + ${Boost_INCLUDE_DIRS}) if(APPLE OR NOT ${CMAKE_TARGET_ARCHITECTURE} STREQUAL ${CMAKE_HOST_SYSTEM_PROCESSOR}) set_target_properties(${CURRENT_PROJECT_NAME} PROPERTIES @@ -86,4 +67,4 @@ elseif(CMAKE_CROSSCOMPILING AND CMAKE_SYSTEM_NAME STREQUAL "Emscripten") add_dependencies(${CURRENT_PROJECT_NAME} boost) endif() -install(TARGETS ${CURRENT_PROJECT_NAME} RUNTIME DESTINATION bin) \ No newline at end of file +install(TARGETS ${CURRENT_PROJECT_NAME} RUNTIME DESTINATION bin) diff --git a/bin/recursive_gen/CMakeLists.txt b/bin/recursive_gen/CMakeLists.txt index 8cffdc85..2245056a 100644 --- a/bin/recursive_gen/CMakeLists.txt +++ b/bin/recursive_gen/CMakeLists.txt @@ -36,35 +36,18 @@ set_target_properties(${CURRENT_PROJECT_NAME} PROPERTIES CXX_STANDARD_REQUIRED TRUE) target_link_libraries(${CURRENT_PROJECT_NAME} - crypto3::algebra - crypto3::block + crypto3::all crypto3::blueprint - crypto3::codec - crypto3::math - crypto3::multiprecision - crypto3::pkpad - crypto3::pubkey - crypto3::random - crypto3::zk - crypto3::assigner crypto3::transpiler - - marshalling::core - marshalling::crypto3_algebra - marshalling::crypto3_multiprecision - marshalling::crypto3_zk - ${Boost_LIBRARIES}) target_include_directories(${CURRENT_PROJECT_NAME} PUBLIC - $ - $ - ${CMAKE_CURRENT_SOURCE_DIR}/../../libs/circifier/llvm/include - ${CMAKE_CURRENT_SOURCE_DIR}/../../libs/circifier/utils/bazel/llvm-project-overlay/llvm/include + ${CMAKE_SOURCE_DIR}/libs/circifier/llvm/include + ${CMAKE_SOURCE_DIR}/libs/circifier/utils/bazel/llvm-project-overlay/llvm/include ${CMAKE_BINARY_DIR}/libs/circifier/llvm/include - $<$:${Boost_INCLUDE_DIRS}>) + ${Boost_INCLUDE_DIRS}) if(APPLE OR NOT ${CMAKE_TARGET_ARCHITECTURE} STREQUAL ${CMAKE_HOST_SYSTEM_PROCESSOR}) set_target_properties(${CURRENT_PROJECT_NAME} PROPERTIES diff --git a/bin/transpiler/CMakeLists.txt b/bin/transpiler/CMakeLists.txt index 9f5c8a9c..105d946f 100644 --- a/bin/transpiler/CMakeLists.txt +++ b/bin/transpiler/CMakeLists.txt @@ -38,35 +38,16 @@ set_target_properties(${CURRENT_PROJECT_NAME} PROPERTIES CXX_STANDARD_REQUIRED TRUE) target_link_libraries(${CURRENT_PROJECT_NAME} - crypto3::algebra - crypto3::block + crypto3::all crypto3::blueprint - crypto3::codec - crypto3::math - crypto3::multiprecision - crypto3::pkpad - crypto3::pubkey - crypto3::random - crypto3::zk - crypto3::assigner crypto3::transpiler - - marshalling::core - marshalling::crypto3_algebra - marshalling::crypto3_multiprecision - marshalling::crypto3_zk - ${Boost_LIBRARIES}) target_include_directories(${CURRENT_PROJECT_NAME} PUBLIC - $ - $ - ${CMAKE_CURRENT_SOURCE_DIR}/../../libs/circifier/llvm/include - ${CMAKE_CURRENT_SOURCE_DIR}/../../libs/circifier/utils/bazel/llvm-project-overlay/llvm/include - ${CMAKE_BINARY_DIR}/libs/circifier/llvm/include - - $<$:${Boost_INCLUDE_DIRS}>) + ${CMAKE_SOURCE_DIR}/libs/circifier/llvm/include + ${CMAKE_SOURCE_DIR}/libs/circifier/utils/bazel/llvm-project-overlay/llvm/include + ${Boost_INCLUDE_DIRS}) if(APPLE OR NOT ${CMAKE_TARGET_ARCHITECTURE} STREQUAL ${CMAKE_HOST_SYSTEM_PROCESSOR}) set_target_properties(${CURRENT_PROJECT_NAME} PROPERTIES @@ -83,4 +64,4 @@ elseif(CMAKE_CROSSCOMPILING AND CMAKE_SYSTEM_NAME STREQUAL "Emscripten") add_dependencies(${CURRENT_PROJECT_NAME} boost) endif() -install(TARGETS ${CURRENT_PROJECT_NAME} RUNTIME DESTINATION bin) \ No newline at end of file +install(TARGETS ${CURRENT_PROJECT_NAME} RUNTIME DESTINATION bin) diff --git a/bin/transpiler/src/main.cpp b/bin/transpiler/src/main.cpp index 41380f2c..849e8073 100644 --- a/bin/transpiler/src/main.cpp +++ b/bin/transpiler/src/main.cpp @@ -15,7 +15,6 @@ #include #include #include -#include #include #include diff --git a/cmake/CheckSSE.cmake b/cmake/CheckSSE.cmake index 83cfe820..821eb10e 100644 --- a/cmake/CheckSSE.cmake +++ b/cmake/CheckSSE.cmake @@ -59,7 +59,7 @@ macro(check_sse) endif(SSE42_TRUE) elseif(CMAKE_SYSTEM_NAME MATCHES "Darwin") - exec_program("/usr/sbin/sysctl -n machdep.cpu.features" OUTPUT_VARIABLE + exec_program("${CMAKE_INSTALL_PREFIX}/sbin/sysctl -n machdep.cpu.features" OUTPUT_VARIABLE CPUINFO) string(REGEX REPLACE "^.*[^S](SSE2).*$" "\\1" SSE_THERE "${CPUINFO}") @@ -143,4 +143,4 @@ macro(check_sse) mark_as_advanced(SSE2_FOUND SSE3_FOUND SSSE3_FOUND SSE4_1_FOUND SSE4_2_FOUND) -endmacro(check_sse) \ No newline at end of file +endmacro(check_sse) diff --git a/cmake/CircuitCompile.cmake b/cmake/CircuitCompile.cmake index 90fc7515..55f4e5c5 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 "${CMAKE_INSTALL_PREFIX}/lib/zkllvm/lib/zkllvm/zkllvm-libc.ll") + set(libcpp_stdlib "${CMAKE_INSTALL_PREFIX}/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 a016a421..00000000 --- a/cmake/modules +++ /dev/null @@ -1 +0,0 @@ -Subproject commit a016a42163a58ef68bbde48082d0ddafe68b8e56 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/CMakeLists.txt b/examples/CMakeLists.txt index bc381ce8..13924990 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -374,30 +374,7 @@ function(assign_recursive_verifier target curve_type provers_amount) COMPILER_OPTIONS ${ARG_COMPILER_OPTIONS} LINK_LIBRARIES - crypto3::algebra - crypto3::block - crypto3::blueprint - crypto3::codec - crypto3::containers - crypto3::hash - crypto3::kdf - crypto3::mac - marshalling::core - marshalling::crypto3_algebra - marshalling::crypto3_multiprecision - marshalling::crypto3_zk - crypto3::math - crypto3::modes - crypto3::multiprecision - crypto3::passhash - crypto3::pbkdf - crypto3::threshold - crypto3::pkpad - crypto3::pubkey - crypto3::random - crypto3::stream - crypto3::vdf - crypto3::zk + crypto3::all ${Boost_LIBRARIES} ) diff --git a/examples/cpp/CMakeLists.txt b/examples/cpp/CMakeLists.txt index 29235f07..a1e08221 100644 --- a/examples/cpp/CMakeLists.txt +++ b/examples/cpp/CMakeLists.txt @@ -24,31 +24,7 @@ function(add_example_without_proving example_target) COMPILER_OPTIONS ${ARG_COMPILER_OPTIONS} LINK_LIBRARIES - crypto3::algebra - crypto3::block - crypto3::blueprint - crypto3::codec - crypto3::containers - crypto3::hash - crypto3::kdf - crypto3::mac - marshalling::core - marshalling::crypto3_algebra - marshalling::crypto3_multiprecision - marshalling::crypto3_zk - crypto3::math - crypto3::modes - crypto3::multiprecision - crypto3::passhash - crypto3::pbkdf - crypto3::threshold - crypto3::pkpad - crypto3::pubkey - crypto3::random - crypto3::stream - crypto3::vdf - crypto3::zk - + crypto3::all ${Boost_LIBRARIES}) set(binary_name ${example_target}.ll) diff --git a/examples/cpp/arithmetics.cpp b/examples/cpp/arithmetics.cpp index cfab6c3d..aae7f91e 100644 --- a/examples/cpp/arithmetics.cpp +++ b/examples/cpp/arithmetics.cpp @@ -14,6 +14,6 @@ typename pallas::base_field_type::value_type pow_2(typename pallas::base_field_t typename pallas::base_field_type::value_type b) { typename pallas::base_field_type::value_type c = (a + b) * a + b * (a + b) * (a + b); - const typename pallas::base_field_type::value_type constant = 0x12345678901234567890_cppui255; + const typename pallas::base_field_type::value_type constant = 0x12345678901234567890_cppui_modular255; return c * c * c / (b - a) + pow_2(a) + constant; } diff --git a/examples/cpp/balances_tree.cpp b/examples/cpp/balances_tree.cpp index 21768171..90bd6c46 100644 --- a/examples/cpp/balances_tree.cpp +++ b/examples/cpp/balances_tree.cpp @@ -8,45 +8,45 @@ constexpr std::size_t validators_amount_log2 = 6; constexpr std::size_t validators_per_leaf_log2 = 2; const std::array::block_type, 39> precomputed_zero_hashes = {{ -{0xf5a5fd42d16a20302798ef6ed309979b_cppui255, 0x43003d2320d9f0e8ea9831a92759fb4b_cppui255}, -{0xdb56114e00fdd4c1f85c892bf35ac9a8_cppui255, 0x9289aaecb1ebd0a96cde606a748b5d71_cppui255}, -{0xc78009fdf07fc56a11f122370658a353_cppui255, 0xaaa542ed63e44c4bc15ff4cd105ab33c_cppui255}, -{0x536d98837f2dd165a55d5eeae9148595_cppui255, 0x4472d56f246df256bf3cae19352a123c_cppui255}, -{0x9efde052aa15429fae05bad4d0b1d7c6_cppui255, 0x4da64d03d7a1854a588c2cb8430c0d30_cppui255}, -{0xd88ddfeed400a8755596b21942c1497e_cppui255, 0x114c302e6118290f91e6772976041fa1_cppui255}, -{0x87eb0ddba57e35f6d286673802a4af59_cppui255, 0x75e22506c7cf4c64bb6be5ee11527f2c_cppui255}, -{0x26846476fd5fc54a5d43385167c95144_cppui255, 0xf2643f533cc85bb9d16b782f8d7db193_cppui255}, -{0x506d86582d252405b840018792cad2bf_cppui255, 0x1259f1ef5aa5f887e13cb2f0094f51e1_cppui255}, -{0xffff0ad7e659772f9534c195c815efc4_cppui255, 0x14ef1e1daed4404c06385d11192e92b_cppui255}, -{0x6cf04127db05441cd833107a52be8528_cppui255, 0x68890e4317e6a02ab47683aa75964220_cppui255}, -{0xb7d05f875f140027ef5118a2247bbb84_cppui255, 0xce8f2f0f1123623085daf7960c329f5f_cppui255}, -{0xdf6af5f5bbdb6be9ef8aa618e4bf8073_cppui255, 0x960867171e29676f8b284dea6a08a85e_cppui255}, -{0xb58d900f5e182e3c50ef74969ea16c77_cppui255, 0x26c549757cc23523c369587da7293784_cppui255}, -{0xd49a7502ffcfb0340b1d7885688500ca_cppui255, 0x308161a7f96b62df9d083b71fcc8f2bb_cppui255}, -{0x8fe6b1689256c0d385f42f5bbe2027a2_cppui255, 0x2c1996e110ba97c171d3e5948de92beb_cppui255}, -{0x8d0d63c39ebade8509e0ae3c9c3876fb_cppui255, 0x5fa112be18f905ecacfecb92057603ab_cppui255}, -{0x95eec8b2e541cad4e91de38385f2e046_cppui255, 0x619f54496c2382cb6cacd5b98c26f5a4_cppui255}, -{0xf893e908917775b62bff23294dbbe3a1_cppui255, 0xcd8e6cc1c35b4801887b646a6f81f17f_cppui255}, -{0xcddba7b592e3133393c16194fac7431a_cppui255, 0xbf2f5485ed711db282183c819e08ebaa_cppui255}, -{0x8a8d7fe3af8caa085a7639a832001457_cppui255, 0xdfb9128a8061142ad0335629ff23ff9c_cppui255}, -{0xfeb3c337d7a51a6fbf00b9e34c52e1c9_cppui255, 0x195c969bd4e7a0bfd51d5c5bed9c1167_cppui255}, -{0xe71f0aa83cc32edfbefa9f4d3e0174ca_cppui255, 0x85182eec9f3a09f6a6c0df6377a510d7_cppui255}, -{0x31206fa80a50bb6abe29085058f16212_cppui255, 0x212a60eec8f049fecb92d8c8e0a84bc0_cppui255}, -{0x21352bfecbeddde993839f614c3dac0a_cppui255, 0x3ee37543f9b412b16199dc158e23b544_cppui255}, -{0x619e312724bb6d7c3153ed9de791d764_cppui255, 0xa366b389af13c58bf8a8d90481a46765_cppui255}, -{0x7cdd2986268250628d0c10e385c58c61_cppui255, 0x91e6fbe05191bcc04f133f2cea72c1c4_cppui255}, -{0x848930bd7ba8cac54661072113fb2788_cppui255, 0x69e07bb8587f91392933374d017bcbe1_cppui255}, -{0x8869ff2c22b28cc10510d98532928033_cppui255, 0x28be4fb0e80495e8bb8d271f5b889636_cppui255}, -{0xb5fe28e79f1b850f8658246ce9b6a1e7_cppui255, 0xb49fc06db7143e8fe0b4f2b0c5523a5c_cppui255}, -{0x985e929f70af28d0bdd1a90a808f977f_cppui255, 0x597c7c778c489e98d3bd8910d31ac0f7_cppui255}, -{0xc6f67e02e6e4e1bdefb994c6098953f3_cppui255, 0x4636ba2b6ca20a4721d2b26a886722ff_cppui255}, -{0x1c9a7e5ff1cf48b4ad1582d3f4e4a100_cppui255, 0x4f3b20d8c5a2b71387a4254ad933ebc5_cppui255}, -{0x2f075ae229646b6f6aed19a5e372cf29_cppui255, 0x5081401eb893ff599b3f9acc0c0d3e7d_cppui255}, -{0x328921deb59612076801e8cd61592107_cppui255, 0xb5c67c79b846595cc6320c395b46362c_cppui255}, -{0xbfb909fdb236ad2411b4e4883810a074_cppui255, 0xb840464689986c3f8a8091827e17c327_cppui255}, -{0x55d8fb3687ba3ba49f342c77f5a1f89b_cppui255, 0xec83d811446e1a467139213d640b6a74_cppui255}, -{0xf7210d4f8e7e1039790e7bf4efa20755_cppui255, 0x5a10a6db1dd4b95da313aaa88b88fe76_cppui255}, -{0xad21b516cbc645ffe34ab5de1c8aef8c_cppui255, 0xd4e7f8d2b51e8e1456adc7563cda206f_cppui255} +{0xf5a5fd42d16a20302798ef6ed309979b_cppui_modular255, 0x43003d2320d9f0e8ea9831a92759fb4b_cppui_modular255}, +{0xdb56114e00fdd4c1f85c892bf35ac9a8_cppui_modular255, 0x9289aaecb1ebd0a96cde606a748b5d71_cppui_modular255}, +{0xc78009fdf07fc56a11f122370658a353_cppui_modular255, 0xaaa542ed63e44c4bc15ff4cd105ab33c_cppui_modular255}, +{0x536d98837f2dd165a55d5eeae9148595_cppui_modular255, 0x4472d56f246df256bf3cae19352a123c_cppui_modular255}, +{0x9efde052aa15429fae05bad4d0b1d7c6_cppui_modular255, 0x4da64d03d7a1854a588c2cb8430c0d30_cppui_modular255}, +{0xd88ddfeed400a8755596b21942c1497e_cppui_modular255, 0x114c302e6118290f91e6772976041fa1_cppui_modular255}, +{0x87eb0ddba57e35f6d286673802a4af59_cppui_modular255, 0x75e22506c7cf4c64bb6be5ee11527f2c_cppui_modular255}, +{0x26846476fd5fc54a5d43385167c95144_cppui_modular255, 0xf2643f533cc85bb9d16b782f8d7db193_cppui_modular255}, +{0x506d86582d252405b840018792cad2bf_cppui_modular255, 0x1259f1ef5aa5f887e13cb2f0094f51e1_cppui_modular255}, +{0xffff0ad7e659772f9534c195c815efc4_cppui_modular255, 0x14ef1e1daed4404c06385d11192e92b_cppui_modular255}, +{0x6cf04127db05441cd833107a52be8528_cppui_modular255, 0x68890e4317e6a02ab47683aa75964220_cppui_modular255}, +{0xb7d05f875f140027ef5118a2247bbb84_cppui_modular255, 0xce8f2f0f1123623085daf7960c329f5f_cppui_modular255}, +{0xdf6af5f5bbdb6be9ef8aa618e4bf8073_cppui_modular255, 0x960867171e29676f8b284dea6a08a85e_cppui_modular255}, +{0xb58d900f5e182e3c50ef74969ea16c77_cppui_modular255, 0x26c549757cc23523c369587da7293784_cppui_modular255}, +{0xd49a7502ffcfb0340b1d7885688500ca_cppui_modular255, 0x308161a7f96b62df9d083b71fcc8f2bb_cppui_modular255}, +{0x8fe6b1689256c0d385f42f5bbe2027a2_cppui_modular255, 0x2c1996e110ba97c171d3e5948de92beb_cppui_modular255}, +{0x8d0d63c39ebade8509e0ae3c9c3876fb_cppui_modular255, 0x5fa112be18f905ecacfecb92057603ab_cppui_modular255}, +{0x95eec8b2e541cad4e91de38385f2e046_cppui_modular255, 0x619f54496c2382cb6cacd5b98c26f5a4_cppui_modular255}, +{0xf893e908917775b62bff23294dbbe3a1_cppui_modular255, 0xcd8e6cc1c35b4801887b646a6f81f17f_cppui_modular255}, +{0xcddba7b592e3133393c16194fac7431a_cppui_modular255, 0xbf2f5485ed711db282183c819e08ebaa_cppui_modular255}, +{0x8a8d7fe3af8caa085a7639a832001457_cppui_modular255, 0xdfb9128a8061142ad0335629ff23ff9c_cppui_modular255}, +{0xfeb3c337d7a51a6fbf00b9e34c52e1c9_cppui_modular255, 0x195c969bd4e7a0bfd51d5c5bed9c1167_cppui_modular255}, +{0xe71f0aa83cc32edfbefa9f4d3e0174ca_cppui_modular255, 0x85182eec9f3a09f6a6c0df6377a510d7_cppui_modular255}, +{0x31206fa80a50bb6abe29085058f16212_cppui_modular255, 0x212a60eec8f049fecb92d8c8e0a84bc0_cppui_modular255}, +{0x21352bfecbeddde993839f614c3dac0a_cppui_modular255, 0x3ee37543f9b412b16199dc158e23b544_cppui_modular255}, +{0x619e312724bb6d7c3153ed9de791d764_cppui_modular255, 0xa366b389af13c58bf8a8d90481a46765_cppui_modular255}, +{0x7cdd2986268250628d0c10e385c58c61_cppui_modular255, 0x91e6fbe05191bcc04f133f2cea72c1c4_cppui_modular255}, +{0x848930bd7ba8cac54661072113fb2788_cppui_modular255, 0x69e07bb8587f91392933374d017bcbe1_cppui_modular255}, +{0x8869ff2c22b28cc10510d98532928033_cppui_modular255, 0x28be4fb0e80495e8bb8d271f5b889636_cppui_modular255}, +{0xb5fe28e79f1b850f8658246ce9b6a1e7_cppui_modular255, 0xb49fc06db7143e8fe0b4f2b0c5523a5c_cppui_modular255}, +{0x985e929f70af28d0bdd1a90a808f977f_cppui_modular255, 0x597c7c778c489e98d3bd8910d31ac0f7_cppui_modular255}, +{0xc6f67e02e6e4e1bdefb994c6098953f3_cppui_modular255, 0x4636ba2b6ca20a4721d2b26a886722ff_cppui_modular255}, +{0x1c9a7e5ff1cf48b4ad1582d3f4e4a100_cppui_modular255, 0x4f3b20d8c5a2b71387a4254ad933ebc5_cppui_modular255}, +{0x2f075ae229646b6f6aed19a5e372cf29_cppui_modular255, 0x5081401eb893ff599b3f9acc0c0d3e7d_cppui_modular255}, +{0x328921deb59612076801e8cd61592107_cppui_modular255, 0xb5c67c79b846595cc6320c395b46362c_cppui_modular255}, +{0xbfb909fdb236ad2411b4e4883810a074_cppui_modular255, 0xb840464689986c3f8a8091827e17c327_cppui_modular255}, +{0x55d8fb3687ba3ba49f342c77f5a1f89b_cppui_modular255, 0xec83d811446e1a467139213d640b6a74_cppui_modular255}, +{0xf7210d4f8e7e1039790e7bf4efa20755_cppui_modular255, 0x5a10a6db1dd4b95da313aaa88b88fe76_cppui_modular255}, +{0xad21b516cbc645ffe34ab5de1c8aef8c_cppui_modular255, 0xd4e7f8d2b51e8e1456adc7563cda206f_cppui_modular255} }}; // The more precomputed powers of two are uncommented, the more RAM is used during circuit generation phase. constexpr std::array precomputed_powers_of_two = {{ diff --git a/examples/cpp/placeholder_prover/fri_cosets.cpp b/examples/cpp/placeholder_prover/fri_cosets.cpp index fdeea53e..325ce37c 100644 --- a/examples/cpp/placeholder_prover/fri_cosets.cpp +++ b/examples/cpp/placeholder_prover/fri_cosets.cpp @@ -4,7 +4,7 @@ using namespace nil::crypto3::algebra::curves; constexpr std::size_t bits_amount = 64; constexpr std::size_t array_length = 3; - constexpr typename pallas::base_field_type::value_type omega = 0x1ff2863fd35bfc59e51f3693bf37e2d841d1b5fbed4138f755a638bec8750abd_cppui255; + constexpr typename pallas::base_field_type::value_type omega = 0x1ff2863fd35bfc59e51f3693bf37e2d841d1b5fbed4138f755a638bec8750abd_cppui_modular255; [[circuit]] std::array, array_length> fri_cosets(typename pallas::base_field_type::value_type input) { 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 new file mode 100644 index 00000000..fdefbae1 --- /dev/null +++ b/flake.lock @@ -0,0 +1,223 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_3": { + "inputs": { + "systems": "systems_3" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nil-crypto3": { + "inputs": { + "nix-3rdparty": "nix-3rdparty", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1720625736, + "narHash": "sha256-hN9H6kpGAUn0JJQDCgZi8PjR2lOvMxC9M/Nm3D7ngs0=", + "ref": "refs/heads/master", + "rev": "3033b706940d20433651963d4ee8b751805d388f", + "revCount": 9151, + "submodules": false, + "type": "git", + "url": "https://github.com/NilFoundation/crypto3" + }, + "original": { + "submodules": false, + "type": "git", + "url": "https://github.com/NilFoundation/crypto3" + } + }, + "nil-zkllvm-blueprint": { + "inputs": { + "flake-utils": "flake-utils_3", + "nil-crypto3": [ + "nil-crypto3" + ], + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1720537031, + "narHash": "sha256-ucn4h+p17acwRv7GjpwtPj99mUk3WHqA7Ag4zvTvJ8U=", + "ref": "refs/heads/master", + "rev": "30377e6d7d1b71a3c777c326d2140945398f651f", + "revCount": 1249, + "submodules": true, + "type": "git", + "url": "https://github.com/NilFoundation/zkllvm-blueprint" + }, + "original": { + "submodules": true, + "type": "git", + "url": "https://github.com/NilFoundation/zkllvm-blueprint" + } + }, + "nix-3rdparty": { + "inputs": { + "flake-utils": "flake-utils_2", + "nixpkgs": [ + "nil-crypto3", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1717519917, + "narHash": "sha256-GqzEqEW4Uz9Z7uDZwers0t9seWRNbRWPNE3OJnjE1Uw=", + "owner": "NilFoundation", + "repo": "nix-3rdparty", + "rev": "a2e45429aa25a4a6e8e362ef17df6f197312f224", + "type": "github" + }, + "original": { + "owner": "NilFoundation", + "repo": "nix-3rdparty", + "type": "github" + } + }, + "nix-3rdparty_2": { + "inputs": { + "flake-utils": [ + "flake-utils" + ], + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1717519917, + "narHash": "sha256-GqzEqEW4Uz9Z7uDZwers0t9seWRNbRWPNE3OJnjE1Uw=", + "owner": "NilFoundation", + "repo": "nix-3rdparty", + "rev": "a2e45429aa25a4a6e8e362ef17df6f197312f224", + "type": "github" + }, + "original": { + "owner": "NilFoundation", + "repo": "nix-3rdparty", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1720679975, + "narHash": "sha256-8yHvqa7P7y4kFiNW9BPgeQdZ6FVFXD3Sp/oUVRyzYpA=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "1f86d2ae2cb15b411e11ff1e4638beb079b7190d", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nil-crypto3": "nil-crypto3", + "nil-zkllvm-blueprint": "nil-zkllvm-blueprint", + "nix-3rdparty": "nix-3rdparty_2", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_3": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..5b7aeeee --- /dev/null +++ b/flake.nix @@ -0,0 +1,105 @@ +{ + description = "Nix flake for zkLLVM"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs"; + flake-utils.url = "github:numtide/flake-utils"; + nix-3rdparty = { + url = "github:NilFoundation/nix-3rdparty"; + inputs = { + nixpkgs.follows = "nixpkgs"; + flake-utils.follows = "flake-utils"; + }; + }; + nil-crypto3 = { + url = "https://github.com/NilFoundation/crypto3"; + type = "git"; + submodules = false; + inputs = { + nixpkgs.follows = "nixpkgs"; + }; + }; + nil-zkllvm-blueprint = { + url = "https://github.com/NilFoundation/zkllvm-blueprint"; + type = "git"; + submodules = true; + inputs = { + nixpkgs.follows = "nixpkgs"; + nil-crypto3.follows = "nil-crypto3"; + }; + }; + }; + + outputs = { self + , nixpkgs + , flake-utils + , nix-3rdparty + , nil-crypto3 + , nil-zkllvm-blueprint + }: + (flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { + inherit system; + overlays = [ nix-3rdparty.overlays.${system}.default ]; + }; + 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; + }; + 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; + }; + 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: +# nix build --override-input nil-crypto3 /your/local/path/crypto3/ +# to configure build: +# nix develop . -c cmake -B build -DCMAKE_CXX_STANDARD=17 -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=FALSE -DCMAKE_ENABLE_TESTS=TRUE +# to build: +# cd build +# nix develop ../ -c cmake --build . -t compile_cpp_examples diff --git a/libs/assigner b/libs/assigner index c1cad6c3..94c85b94 160000 --- a/libs/assigner +++ b/libs/assigner @@ -1 +1 @@ -Subproject commit c1cad6c3541a7534ce3e85e6ec5b7002f67553dd +Subproject commit 94c85b94aae37886508343ca1f15e6feb45ebed1 diff --git a/libs/blueprint b/libs/blueprint deleted file mode 160000 index 5a2209e0..00000000 --- a/libs/blueprint +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 5a2209e09c1e19ad41b1d3ff308185ea03a3c114 diff --git a/libs/circifier b/libs/circifier index a425ae93..03e06120 160000 --- a/libs/circifier +++ b/libs/circifier @@ -1 +1 @@ -Subproject commit a425ae939cbdc88d861dbc27ad9adce5da68cf94 +Subproject commit 03e0612051e52b9d7283e8d18aff3284282e399d diff --git a/libs/crypto3 b/libs/crypto3 deleted file mode 160000 index 1baa6194..00000000 --- a/libs/crypto3 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 1baa619449013b5fb2962b7edc59a14dbe2f59f2 diff --git a/libs/stdlib b/libs/stdlib index 27978853..e0ef4b3e 160000 --- a/libs/stdlib +++ b/libs/stdlib @@ -1 +1 @@ -Subproject commit 279788538e8b6d4a7a58aa3cdbed9fff9c790e0e +Subproject commit e0ef4b3e1184e7af4da681ad94f859b4ca4c113b diff --git a/libs/transpiler b/libs/transpiler index a614c989..92332ff9 160000 --- a/libs/transpiler +++ b/libs/transpiler @@ -1 +1 @@ -Subproject commit a614c989bbd89eb9f93b11662ef1741c490378f6 +Subproject commit 92332ff93e2d818191c7abb6149ad1f0fcbf404e diff --git a/run_tests.sh b/run_tests.sh new file mode 100755 index 00000000..1739a732 --- /dev/null +++ b/run_tests.sh @@ -0,0 +1,96 @@ +#!/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 0402b3ee..e219f3b2 100644 --- a/tests/cpp/CMakeLists.txt +++ b/tests/cpp/CMakeLists.txt @@ -17,12 +17,8 @@ add_custom_target(all_tests_run_expected_res_calculation) add_custom_target(all_tests_assign_circuits) add_custom_target(all_tests_run) -if(NOT Boost_UNIT_TEST_FRAMEWORK_FOUND) - cm_find_package(Boost REQUIRED COMPONENTS unit_test_framework filesystem) -endif() - cm_test_link_libraries( - crypto3::zk + crypto3::all crypto3::assigner ${Boost_LIBRARIES}) @@ -47,9 +43,8 @@ macro(define_zkllvm_test test curve_type provers_max_num) endforeach() target_include_directories(${full_test_name} PRIVATE - "$" - "$" - + ${CMAKE_CURRENT_SOURCE_DIR}/include> + ${CMAKE_BINARY_DIR}/include ${Boost_INCLUDE_DIRS}) set_target_properties(${full_test_name} PROPERTIES CXX_STANDARD 17) @@ -81,31 +76,7 @@ function(add_test_circuit test) SOURCES ${test}.cpp LINK_LIBRARIES - crypto3::algebra - crypto3::block - crypto3::blueprint - crypto3::codec - crypto3::containers - crypto3::hash - crypto3::kdf - crypto3::mac - marshalling::core - marshalling::crypto3_algebra - marshalling::crypto3_multiprecision - marshalling::crypto3_zk - crypto3::math - crypto3::modes - crypto3::multiprecision - crypto3::passhash - crypto3::pbkdf - crypto3::threshold - crypto3::pkpad - crypto3::pubkey - crypto3::random - crypto3::stream - crypto3::vdf - crypto3::zk - + crypto3::all ${Boost_LIBRARIES}) endfunction() @@ -124,31 +95,7 @@ function(add_test_circuit_assign example_target) SOURCES ${ARG_SOURCES} LINK_LIBRARIES - crypto3::algebra - crypto3::block - crypto3::blueprint - crypto3::codec - crypto3::containers - crypto3::hash - crypto3::kdf - crypto3::mac - marshalling::core - marshalling::crypto3_algebra - marshalling::crypto3_multiprecision - marshalling::crypto3_zk - crypto3::math - crypto3::modes - crypto3::multiprecision - crypto3::passhash - crypto3::pbkdf - crypto3::threshold - crypto3::pkpad - crypto3::pubkey - crypto3::random - crypto3::stream - crypto3::vdf - crypto3::zk - + crypto3::all ${Boost_LIBRARIES}) set(binary_name ${example_target}.ll) @@ -184,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") -add_zkllvm_unit_test("algebra/curves/25519_arithmetics_2/mul") +# 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") -add_zkllvm_unit_test("algebra/curves/constructors/one_pallas") -add_zkllvm_unit_test("algebra/curves/constructors/zero_ed25519") -add_zkllvm_unit_test("algebra/curves/constructors/one_ed25519") +# 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") @@ -216,7 +163,7 @@ add_zkllvm_unit_test("algebra/fields/pallas_arithmetics/loop") add_zkllvm_unit_test("algebra/fields/pallas_arithmetics/mul") add_zkllvm_unit_test("algebra/fields/pallas_arithmetics/sub") -# add_zkllvm_unit_test("algebra/fields/private_input/private_input_add") +add_zkllvm_unit_test("algebra/fields/private_input/private_input_add") add_zkllvm_unit_test("algebra/fields/conversion/itogf_pallas") # int tests @@ -242,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/cpp/algebra/fields/private_input/private_input_add.cpp b/tests/cpp/algebra/fields/private_input/private_input_add.cpp index c4477b83..7d9195d3 100644 --- a/tests/cpp/algebra/fields/private_input/private_input_add.cpp +++ b/tests/cpp/algebra/fields/private_input/private_input_add.cpp @@ -44,7 +44,7 @@ int main (int argc, char *argv[]){ using BlueprintFieldType = typename pallas::base_field_type; - typename BlueprintFieldType::value_type a = read_field (pubic_input_json, 0); + typename BlueprintFieldType::value_type a = read_field (public_input_json, 0); typename BlueprintFieldType::value_type b = read_field (private_input_json, 0); pallas_field_add(a, b); diff --git a/tests/cpp/algebra/recursive_prover/fri_cosets/fri_cosets.cpp b/tests/cpp/algebra/recursive_prover/fri_cosets/fri_cosets.cpp index e21ec012..d49323db 100644 --- a/tests/cpp/algebra/recursive_prover/fri_cosets/fri_cosets.cpp +++ b/tests/cpp/algebra/recursive_prover/fri_cosets/fri_cosets.cpp @@ -7,12 +7,12 @@ using namespace nil::crypto3::algebra::curves; -constexpr typename pallas::base_field_type::value_type omega = 0x1ff2863fd35bfc59e51f3693bf37e2d841d1b5fbed4138f755a638bec8750abd_cppui255; +constexpr typename pallas::base_field_type::value_type omega = 0x1ff2863fd35bfc59e51f3693bf37e2d841d1b5fbed4138f755a638bec8750abd_cppui_modular255; constexpr size_t n = 4; #ifndef __ZKLLVM__ void calculate_expected_res (std::array, n> &res){ - typename pallas::base_field_type::integral_type pi_num = 0xa53a16c34fb833b5_cppui255; + typename pallas::base_field_type::integral_type pi_num = 0xa53a16c34fb833b5_cppui_modular255; typename pallas::base_field_type::value_type w_powers = omega; typename pallas::base_field_type::value_type w_pow_x = 1; 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!" + ''; +}