From 65274b17491974b167fbc3aa46d2e4ce9eb7cdcc Mon Sep 17 00:00:00 2001 From: Andrei Malashkin Date: Mon, 16 Sep 2024 22:55:39 +0200 Subject: [PATCH 01/13] add sanitizers for crypto3 --- .../clang-sanitizers-linux-nix-check.yml | 38 ++++++++++++ .github/workflows/nightly.yml | 33 +++++++++++ .github/workflows/pull-request.yml | 59 ++++++++++++------- .gitignore | 1 - crypto3.nix | 6 +- flake.nix | 22 ++++++- parallel-crypto3.nix | 10 +++- parse_tests.py | 42 +++++++++++++ proof-producer.nix | 6 +- requirements.txt | 14 +++++ zkevm-framework.nix | 9 ++- 11 files changed, 210 insertions(+), 30 deletions(-) create mode 100644 .github/workflows/clang-sanitizers-linux-nix-check.yml create mode 100644 .github/workflows/nightly.yml create mode 100644 parse_tests.py create mode 100644 requirements.txt diff --git a/.github/workflows/clang-sanitizers-linux-nix-check.yml b/.github/workflows/clang-sanitizers-linux-nix-check.yml new file mode 100644 index 0000000000..7405aeed8a --- /dev/null +++ b/.github/workflows/clang-sanitizers-linux-nix-check.yml @@ -0,0 +1,38 @@ +name: Build and Test sanitizers on Linux with clang + +on: + workflow_call: + +jobs: + build-and-test: + name: "Build and test Linux with clang" + runs-on: [self-hosted, Linux, X64, aws_autoscaling] + continue-on-error: true + steps: + # https://github.com/actions/checkout/issues/1552 + - name: Clean up after previous checkout + run: chmod +w -R ${GITHUB_WORKSPACE}; rm -rf ${GITHUB_WORKSPACE}/*; + + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Run checks + run: | + nix build -L .?#checks.x86_64-linux.all-sanitizers + mkdir results + cp result/test-logs/*_test.xml results/ + continue-on-error: true + env: + NIX_CONFIG: | + cores = 4 + + - name: Publish Test Results + uses: EnricoMi/publish-unit-test-result-action/linux@v2 + with: + check_name: "Sanitizers Test Results" + files: "results/*.xml" + comment_mode: ${{ github.event.pull_request.head.repo.fork && 'off' || 'always' }} # Don't create PR comment from fork runs + action_fail_on_inconclusive: true # fail, if no reports + diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml new file mode 100644 index 0000000000..9b4b9ec821 --- /dev/null +++ b/.github/workflows/nightly.yml @@ -0,0 +1,33 @@ +name: Nightly Testing + +on: + schedule: + - cron: '0 0 * * *' + +jobs: + test-linux-sanitizers: + name: Linux placeholder testing and sanitize with clang + uses: ./.github/workflows/clang-sanitizers-linux-nix-check.yml + if: | + always() && !cancelled() + secrets: inherit + + post-telemetry: + name: Post test results in Open Telemetry format + runs-on: [self-hosted, Linux, X64, aws_autoscaling] + needs: + - test-linux-sanitizers + steps: + - name: Post logs to Sig Noz + run: | + ls -l -a + ls -l -a ./result/ + pip3 install -r requirements.txt + export OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true + ping 172.31.23.196 + opentelemetry-instrument \ + --traces_exporter console,otlp \ + --metrics_exporter console,otlp \ + --logs_exporter console,otlp \ + --service_name nightly-build \ + python3 ./parse_tests.py diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index a353b144f4..8a8250c0c7 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -16,31 +16,46 @@ concurrency: cancel-in-progress: true jobs: - test-linux-gcc: - name: Linux placeholder testing with gcc - uses: ./.github/workflows/gcc-linux-nix-check.yml + test-linux-sanitizers: + name: Linux Crypto3 Test and sanitize with clang + uses: ./.github/workflows/clang-sanitizers-linux-nix-check.yml if: | always() && !cancelled() secrets: inherit - test-linux-clang: - name: Linux placeholder testing with clang - uses: ./.github/workflows/clang-linux-nix-check.yml - if: | - always() && !cancelled() - secrets: inherit - - check-proof-producer: - name: Check Proof Producer - uses: ./.github/workflows/check-proof-producer.yml - if: | - always() && !cancelled() - secrets: inherit + post-telemetry: + name: Post test results in Open Telemetry format + runs-on: [self-hosted, Linux, X64, aws_autoscaling] + needs: + - test-linux-sanitizers + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 - verify-circuit-proof: - name: Verify Circuit Proof - uses: ./.github/workflows/verify-circuit-proof.yml - if: | - always() && !cancelled() - secrets: inherit + - name: Post logs to Sig Noz + run: | + ls -l -a + nix build -L .?#checks.x86_64-linux.all-sanitizers + ls -l -a result/test-logs + cat ./result/test-logs/test_errors.txt + export UndefinedBehaviorSanitizer=$(grep UndefinedBehaviorSanitizer result/test-logs/test_errors.txt | wc -l) + export AddressSanitizer=$(grep AddressSanitizer result/test-logs/test_errors.txt | wc -l) + export LeakSanitizer=$(grep LeakSanitizer result/test-logs/test_errors.txt | wc -l) + ls -l -a + ls -l -a ./result/ + export OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true + python3 --version + sudo yum update -y + sudo yum install -y python3-pip + pip3 install -r requirements.txt + python3 ./parse_tests.py + ls /home/ec2-user/.local/bin/ + /home/ec2-user/.local/bin/opentelemetry-instrument \ + --traces_exporter console,otlp \ + --metrics_exporter console,otlp \ + --logs_exporter console,otlp \ + --service_name nightly-build \ + python3 ./parse_tests.py diff --git a/.gitignore b/.gitignore index 6655d0051b..dcfaa0c942 100644 --- a/.gitignore +++ b/.gitignore @@ -626,7 +626,6 @@ callgrind.* /*.c /*.cpp /*.h -/*.py /*.key /*.pem /*.der diff --git a/crypto3.nix b/crypto3.nix index c9ef06990b..d9bda7d513 100644 --- a/crypto3.nix +++ b/crypto3.nix @@ -42,9 +42,13 @@ in stdenv.mkDerivation { checkPhase = '' # JUNIT file without explicit file name is generated after the name of the master test suite inside `CMAKE_CURRENT_SOURCE_DIR` export BOOST_TEST_LOGGER=JUNIT:HRF - cd crypto3 && ctest --verbose --output-on-failure -R && cd .. + cd crypto3 + # remove || true after all tests are fixed under clang-sanitizers check: + ctest --verbose --output-on-failure -R > test_errors.txt || true + cd .. mkdir -p ${placeholder "out"}/test-logs find .. -type f -name '*_test.xml' -exec cp {} ${placeholder "out"}/test-logs \; + cp crypto3/test_errors.txt ${placeholder "out"}/test-logs \ ''; shellHook = '' diff --git a/flake.nix b/flake.nix index 0cc747f9a1..f2ff51ae62 100644 --- a/flake.nix +++ b/flake.nix @@ -33,10 +33,17 @@ crypto3-debug-tests = (pkgs.callPackage ./crypto3.nix { enableDebug = true; runTests = true; + sanitize = true; }); crypto3-sanitize = (pkgs.callPackage ./crypto3.nix { - enableDebug = true; runTests = true; + enableDebug = false; + sanitize = true; + }); + crypto3-clang-sanitize = (pkgs.callPackage ./crypto3.nix { + stdenv = pkgs.llvmPackages_19.stdenv; + runTests = true; + enableDebug = false; sanitize = true; }); crypto3-clang-debug = (pkgs.callPackage ./crypto3.nix { @@ -121,6 +128,11 @@ runTests = true; enableDebug = false; }); + parallel-crypto3-clang-sanitize = (pkgs.callPackage ./parallel-crypto3.nix { + stdenv = pkgs.llvmPackages_19.stdenv; + runTests = true; + enableDebug = false; + }); proof-producer-gcc = (pkgs.callPackage ./proof-producer.nix { runTests = true; @@ -131,6 +143,12 @@ runTests = true; enableDebug = false; }); + proof-producer-sanitize = (pkgs.callPackage ./proof-producer.nix { + stdenv = pkgs.llvmPackages_19.stdenv; + runTests = true; + enableDebug = false; + sanitize = true; + }); all-clang = pkgs.symlinkJoin { name = "all"; @@ -138,7 +156,7 @@ }; all-sanitizers = pkgs.symlinkJoin { name = "all"; - paths = [ crypto3-clang-sanitize ]; + paths = [ crypto3-clang-sanitize parallel-crypto3-clang-sanitize proof-producer-sanitize ]; }; all-gcc = pkgs.symlinkJoin { name = "all"; diff --git a/parallel-crypto3.nix b/parallel-crypto3.nix index 2f6f163a69..4a0671e995 100644 --- a/parallel-crypto3.nix +++ b/parallel-crypto3.nix @@ -10,6 +10,7 @@ enableDebugging, enableDebug ? false, runTests ? false, + sanitize? false, }: let inherit (lib) optional; @@ -32,13 +33,20 @@ in stdenv.mkDerivation { [ (if runTests then "-DBUILD_PARALLEL_CRYPTO3_TESTS=TRUE" else "") (if enableDebug then "-DCMAKE_BUILD_TYPE=Debug" else "-DCMAKE_BUILD_TYPE=Release") + (if sanitize then "-DSANITIZE=ON" else "-DSANITIZE=OFF") "-DPARALLEL_CRYPTO3_ENABLE=TRUE" ]; doCheck = runTests; # tests are inside parallel-crypto3-tests derivation checkPhase = '' - cd parallel-crypto3 && ctest --verbose --output-on-failure -R && cd .. + # JUNIT file without explicit file name is generated after the name of the master test suite inside `CMAKE_CURRENT_SOURCE_DIR` + export BOOST_TEST_LOGGER=JUNIT:HRF + cd parallel-crypto3 + ctest --verbose --output-on-failure -R + cd .. + mkdir -p ${placeholder "out"}/test-logs + find .. -type f -name '*_test.xml' -exec cp {} ${placeholder "out"}/test-logs \; ''; shellHook = '' diff --git a/parse_tests.py b/parse_tests.py new file mode 100644 index 0000000000..20339e810d --- /dev/null +++ b/parse_tests.py @@ -0,0 +1,42 @@ +import logging, json +from junitparser import JUnitXml +import glob, os +from opentelemetry import trace + +undefined_behavior_sanitizer=os.environ['UndefinedBehaviorSanitizer'] +address_sanitizer=os.environ['AddressSanitizer'] +leak_sanitizer=os.environ['LeakSanitizer'] + +aggregated_test_results = JUnitXml(); +for file in glob.glob("result/test-logs/*.xml"): + try: + aggregated_test_results.append(JUnitXml.fromfile(file)) + except Exception as ex: + print("Error processing {}".format(file)) + print(ex) + +succeeded = aggregated_test_results.tests - \ + aggregated_test_results.failures - \ + aggregated_test_results.errors - \ + aggregated_test_results.skipped + +result = { + "tests" : aggregated_test_results.tests, + "failures" : aggregated_test_results.failures, + "errors" : aggregated_test_results.errors, + "skipped" : aggregated_test_results.skipped, + "succeeded" : succeeded, + "execution_time" : aggregated_test_results.time, + "undefined_behavior_sanitizer" : int(undefined_behavior_sanitizer), + "address_sanitizer" : int(address_sanitizer), + "leak_sanitizer" : int(leak_sanitizer), +} + +print("Resulting JSON: {}".format(json.dumps(result))) + +tracer = trace.get_tracer_provider().get_tracer(__name__) +with tracer.start_as_current_span("nightly_span"): + current_span = trace.get_current_span() + current_span.add_event("Nightly build finished") + logging.getLogger().error(json.dumps(result)) + diff --git a/proof-producer.nix b/proof-producer.nix index a2f5456f79..68e89d9969 100644 --- a/proof-producer.nix +++ b/proof-producer.nix @@ -11,6 +11,7 @@ gtest, enableDebug ? false, runTests ? false, + sanitize? false, }: let inherit (lib) optional; @@ -34,6 +35,7 @@ in stdenv.mkDerivation { "-DCMAKE_INSTALL_PREFIX=${placeholder "out"}" (if enableDebug then "-DCMAKE_BUILD_TYPE=Debug" else "-DCMAKE_BUILD_TYPE=Release") (if runTests then "-DENABLE_TESTS=ON" else "-DENABLE_TESTS=OFF") + (if sanitize then "-DSANITIZE=ON" else "-DSANITIZE=OFF") "-DPROOF_PRODUCER_ENABLE=TRUE" "-G Ninja" ]; @@ -43,7 +45,9 @@ in stdenv.mkDerivation { checkPhase = '' # JUNIT file without explicit file name is generated after the name of the master test suite inside `CMAKE_CURRENT_SOURCE_DIR` export BOOST_TEST_LOGGER=JUNIT:HRF - cd proof-producer && ctest --verbose --output-on-failure -R && cd .. + cd proof-producer + ctest --verbose --output-on-failure -R + cd .. mkdir -p ${placeholder "out"}/test-logs find .. -type f -name '*_test.xml' -exec cp {} ${placeholder "out"}/test-logs \; ''; diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000000..795cdc65b8 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,14 @@ +requests==2.32.2 +opentelemetry-distro[otlp]==0.45b0 +opentelemetry-instrumentation-requests==0.45b0 +opentelemetry-util-http==0.45b0 +opentelemetry-instrumentation==0.45b0 +opentelemetry-semantic-conventions==0.45b0 +opentelemetry-instrumentation==0.45b0 +opentelemetry-semantic-conventions==0.45b0 +opentelemetry-util-http==0.45b0 +opentelemetry-instrumentation==0.45b0 +opentelemetry-semantic-conventions==0.45b0 +opentelemetry-util-http==0.45b0 +opentelemetry-sdk +junitparser==3.2.0 diff --git a/zkevm-framework.nix b/zkevm-framework.nix index 868e0b0042..545b9d02e6 100644 --- a/zkevm-framework.nix +++ b/zkevm-framework.nix @@ -45,8 +45,13 @@ in stdenv.mkDerivation rec { doCheck = runTests; checkPhase = '' - cd zkevm-framework && ctest - cd .. && ninja executables_tests + # JUNIT file without explicit file name is generated after the name of the master test suite inside `CMAKE_CURRENT_SOURCE_DIR` + export BOOST_TEST_LOGGER=JUNIT:HRF + cd zkevm-framework + ctest --verbose --output-on-failure -R + cd .. + mkdir -p ${placeholder "out"}/test-logs + find .. -type f -name '*_test.xml' -exec cp {} ${placeholder "out"}/test-logs \; ''; shellHook = '' From 60a70c46fe35a661351931e7adbdecd12c74bf05 Mon Sep 17 00:00:00 2001 From: Andrei Malashkin Date: Mon, 25 Nov 2024 18:56:32 +0100 Subject: [PATCH 02/13] remove testing of nightly from regular build; restore normal pull request workflow --- .github/workflows/nightly.yml | 20 ++++++++--- .github/workflows/pull-request.yml | 58 +++++++++++------------------- 2 files changed, 37 insertions(+), 41 deletions(-) diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 9b4b9ec821..949c7e6db9 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -18,16 +18,28 @@ jobs: needs: - test-linux-sanitizers steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Post logs to Sig Noz run: | ls -l -a - ls -l -a ./result/ - pip3 install -r requirements.txt + nix build -L .?#checks.x86_64-linux.all-sanitizers + cat ./result/test-logs/test_errors.txt + export UndefinedBehaviorSanitizer=$(grep UndefinedBehaviorSanitizer result/test-logs/test_errors.txt | wc -l) + export AddressSanitizer=$(grep AddressSanitizer result/test-logs/test_errors.txt | wc -l) + export LeakSanitizer=$(grep LeakSanitizer result/test-logs/test_errors.txt | wc -l) export OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true - ping 172.31.23.196 - opentelemetry-instrument \ + python3 --version + sudo yum update -y + sudo yum install -y python3-pip + pip3 install -r requirements.txt + /home/ec2-user/.local/bin/opentelemetry-instrument \ --traces_exporter console,otlp \ --metrics_exporter console,otlp \ --logs_exporter console,otlp \ --service_name nightly-build \ python3 ./parse_tests.py + diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 8a8250c0c7..91ac921fab 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -16,46 +16,30 @@ concurrency: cancel-in-progress: true jobs: - test-linux-sanitizers: - name: Linux Crypto3 Test and sanitize with clang - uses: ./.github/workflows/clang-sanitizers-linux-nix-check.yml + test-linux-gcc: + name: Linux placeholder testing with gcc + uses: ./.github/workflows/gcc-linux-nix-check.yml if: | always() && !cancelled() secrets: inherit - post-telemetry: - name: Post test results in Open Telemetry format - runs-on: [self-hosted, Linux, X64, aws_autoscaling] - needs: - - test-linux-sanitizers - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 + test-linux-clang: + name: Linux placeholder testing with clang + uses: ./.github/workflows/clang-linux-nix-check.yml + if: | + always() && !cancelled() + secrets: inherit - - name: Post logs to Sig Noz - run: | - ls -l -a - nix build -L .?#checks.x86_64-linux.all-sanitizers - ls -l -a result/test-logs - cat ./result/test-logs/test_errors.txt - export UndefinedBehaviorSanitizer=$(grep UndefinedBehaviorSanitizer result/test-logs/test_errors.txt | wc -l) - export AddressSanitizer=$(grep AddressSanitizer result/test-logs/test_errors.txt | wc -l) - export LeakSanitizer=$(grep LeakSanitizer result/test-logs/test_errors.txt | wc -l) - ls -l -a - ls -l -a ./result/ - export OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true - python3 --version - sudo yum update -y - sudo yum install -y python3-pip - pip3 install -r requirements.txt - python3 ./parse_tests.py - ls /home/ec2-user/.local/bin/ - /home/ec2-user/.local/bin/opentelemetry-instrument \ - --traces_exporter console,otlp \ - --metrics_exporter console,otlp \ - --logs_exporter console,otlp \ - --service_name nightly-build \ - python3 ./parse_tests.py + check-proof-producer: + name: Check Proof Producer + uses: ./.github/workflows/check-proof-producer.yml + if: | + always() && !cancelled() + secrets: inherit + verify-circuit-proof: + name: Verify Circuit Proof + uses: ./.github/workflows/verify-circuit-proof.yml + if: | + always() && !cancelled() + secrets: inherit From f90340409a079fa3cb78b39e82e449d9423f7dfd Mon Sep 17 00:00:00 2001 From: Andrei Malashkin Date: Mon, 25 Nov 2024 20:18:38 +0100 Subject: [PATCH 03/13] fix test parsing issue --- .../libs/parallelization-utils/test/thread_pool.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/parallel-crypto3/libs/parallelization-utils/test/thread_pool.cpp b/parallel-crypto3/libs/parallelization-utils/test/thread_pool.cpp index d6501c661f..d3813debaf 100644 --- a/parallel-crypto3/libs/parallelization-utils/test/thread_pool.cpp +++ b/parallel-crypto3/libs/parallelization-utils/test/thread_pool.cpp @@ -55,7 +55,8 @@ BOOST_AUTO_TEST_CASE(vector_multiplication_test) { }, nil::crypto3::ThreadPool::PoolLevel::HIGH)); for (std::size_t i = 0; i < size; ++i) { - BOOST_CHECK(v[i] == i * i); + if(v[i] != i * i) // If uncomment, test result parser will log an error: CData section too big found + BOOST_CHECK(v[i] == i * i); } } From 4d8068c931b7cb1ac5759c4b9bd478e223a37dca Mon Sep 17 00:00:00 2001 From: Andrei Malashkin Date: Mon, 25 Nov 2024 20:19:01 +0100 Subject: [PATCH 04/13] add parallel-crypto3 to derivation named all --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index f2ff51ae62..382cfd2683 100644 --- a/flake.nix +++ b/flake.nix @@ -97,7 +97,7 @@ # fetched from the cache. all = pkgs.symlinkJoin { name = "all"; - paths = [ crypto3 proof-producer]; + paths = [ crypto3 parallel-crypto3 proof-producer]; }; default = all; }; From 7ff592b9055121c003395541a6a19a1d40a55948 Mon Sep 17 00:00:00 2001 From: Andrei Malashkin Date: Tue, 26 Nov 2024 07:50:22 +0100 Subject: [PATCH 05/13] correct review notes --- flake.nix | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index 382cfd2683..c2419b745d 100644 --- a/flake.nix +++ b/flake.nix @@ -33,7 +33,6 @@ crypto3-debug-tests = (pkgs.callPackage ./crypto3.nix { enableDebug = true; runTests = true; - sanitize = true; }); crypto3-sanitize = (pkgs.callPackage ./crypto3.nix { runTests = true; @@ -154,7 +153,7 @@ name = "all"; paths = [ crypto3-clang parallel-crypto3-clang proof-producer-clang ]; }; - all-sanitizers = pkgs.symlinkJoin { + all-clang-sanitize = pkgs.symlinkJoin { name = "all"; paths = [ crypto3-clang-sanitize parallel-crypto3-clang-sanitize proof-producer-sanitize ]; }; From a61da0bffeafc2e2de2003ce11c29d72831bdfe9 Mon Sep 17 00:00:00 2001 From: Andrei Malashkin Date: Tue, 26 Nov 2024 09:42:07 +0100 Subject: [PATCH 06/13] use BOOST_CHECK_EQUAL --- .../libs/parallelization-utils/test/thread_pool.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/parallel-crypto3/libs/parallelization-utils/test/thread_pool.cpp b/parallel-crypto3/libs/parallelization-utils/test/thread_pool.cpp index d3813debaf..22f8319ca3 100644 --- a/parallel-crypto3/libs/parallelization-utils/test/thread_pool.cpp +++ b/parallel-crypto3/libs/parallelization-utils/test/thread_pool.cpp @@ -55,8 +55,7 @@ BOOST_AUTO_TEST_CASE(vector_multiplication_test) { }, nil::crypto3::ThreadPool::PoolLevel::HIGH)); for (std::size_t i = 0; i < size; ++i) { - if(v[i] != i * i) // If uncomment, test result parser will log an error: CData section too big found - BOOST_CHECK(v[i] == i * i); + BOOST_CHECK_EQUAL(v[i], i * i); } } From 00540eed5c16f60777ba8b0447fba1c5cdb1ed0f Mon Sep 17 00:00:00 2001 From: Andrei Malashkin Date: Tue, 26 Nov 2024 09:42:54 +0100 Subject: [PATCH 07/13] correct review notes --- flake.nix | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/flake.nix b/flake.nix index c2419b745d..b15ec32710 100644 --- a/flake.nix +++ b/flake.nix @@ -34,16 +34,18 @@ enableDebug = true; runTests = true; }); - crypto3-sanitize = (pkgs.callPackage ./crypto3.nix { + crypto3-clang-sanitize = (pkgs.callPackage ./crypto3.nix { + stdenv = pkgs.llvmPackages_19.stdenv; runTests = true; enableDebug = false; sanitize = true; }); - crypto3-clang-sanitize = (pkgs.callPackage ./crypto3.nix { + crypto3-clang-sanitize-bench = (pkgs.callPackage ./crypto3.nix { stdenv = pkgs.llvmPackages_19.stdenv; runTests = true; enableDebug = false; sanitize = true; + bench = true; }); crypto3-clang-debug = (pkgs.callPackage ./crypto3.nix { stdenv = pkgs.llvmPackages_19.stdenv; @@ -117,6 +119,13 @@ enableDebug = false; sanitize = true; }); + crypto3-clang-sanitize-bench = (pkgs.callPackage ./crypto3.nix { + stdenv = pkgs.llvmPackages_19.stdenv; + runTests = true; + enableDebug = false; + sanitize = true; + bench = true; + }); parallel-crypto3-gcc = (pkgs.callPackage ./parallel-crypto3.nix { runTests = true; @@ -142,7 +151,7 @@ runTests = true; enableDebug = false; }); - proof-producer-sanitize = (pkgs.callPackage ./proof-producer.nix { + proof-producer-clang-sanitize = (pkgs.callPackage ./proof-producer.nix { stdenv = pkgs.llvmPackages_19.stdenv; runTests = true; enableDebug = false; @@ -155,7 +164,7 @@ }; all-clang-sanitize = pkgs.symlinkJoin { name = "all"; - paths = [ crypto3-clang-sanitize parallel-crypto3-clang-sanitize proof-producer-sanitize ]; + paths = [ crypto3-clang-sanitize parallel-crypto3-clang-sanitize proof-producer-clang-sanitize ]; }; all-gcc = pkgs.symlinkJoin { name = "all"; From 6df180e2b5a4108c8fc6b2e2e4b774dddb9e8fb0 Mon Sep 17 00:00:00 2001 From: Andrei Malashkin Date: Tue, 26 Nov 2024 14:14:41 +0100 Subject: [PATCH 08/13] implement benchmarks derivation --- .../workflows/clang-sanitizers-linux-nix-check.yml | 2 +- .github/workflows/nightly.yml | 2 +- crypto3.nix | 2 ++ crypto3/benchmarks/CMakeLists.txt | 2 +- crypto3/benchmarks/algebra/curves.cpp | 2 +- flake.nix | 14 ++++++++++++-- 6 files changed, 18 insertions(+), 6 deletions(-) diff --git a/.github/workflows/clang-sanitizers-linux-nix-check.yml b/.github/workflows/clang-sanitizers-linux-nix-check.yml index 7405aeed8a..6144548dbc 100644 --- a/.github/workflows/clang-sanitizers-linux-nix-check.yml +++ b/.github/workflows/clang-sanitizers-linux-nix-check.yml @@ -20,7 +20,7 @@ jobs: - name: Run checks run: | - nix build -L .?#checks.x86_64-linux.all-sanitizers + nix build -L .?#checks.x86_64-linux.all-clang-sanitize mkdir results cp result/test-logs/*_test.xml results/ continue-on-error: true diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 949c7e6db9..b7accb798f 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -26,7 +26,7 @@ jobs: - name: Post logs to Sig Noz run: | ls -l -a - nix build -L .?#checks.x86_64-linux.all-sanitizers + nix build -L .?#checks.x86_64-linux.all-clang-sanitize cat ./result/test-logs/test_errors.txt export UndefinedBehaviorSanitizer=$(grep UndefinedBehaviorSanitizer result/test-logs/test_errors.txt | wc -l) export AddressSanitizer=$(grep AddressSanitizer result/test-logs/test_errors.txt | wc -l) diff --git a/crypto3.nix b/crypto3.nix index d9bda7d513..50d7b58ab4 100644 --- a/crypto3.nix +++ b/crypto3.nix @@ -11,6 +11,7 @@ enableDebug ? false, runTests ? false, sanitize ? false, + benchmarkTests ? false, }: let inherit (lib) optional; @@ -34,6 +35,7 @@ in stdenv.mkDerivation { (if runTests then "-DBUILD_CRYPTO3_TESTS=TRUE" else "-DBUILD_CRYPTO3_TESTS=False") (if enableDebug then "-DCMAKE_BUILD_TYPE=Debug" else "-DCMAKE_BUILD_TYPE=Release") (if sanitize then "-DSANITIZE=ON" else "-DSANITIZE=OFF") + (if benchmarkTests then "-DBUILD_CRYPTO3_BENCH_TESTS=ON" else "-DBUILD_CRYPTO3_BENCH_TESTS=OFF") "-G Ninja" ]; diff --git a/crypto3/benchmarks/CMakeLists.txt b/crypto3/benchmarks/CMakeLists.txt index c1f19f6dde..4e1c9528c1 100644 --- a/crypto3/benchmarks/CMakeLists.txt +++ b/crypto3/benchmarks/CMakeLists.txt @@ -60,7 +60,7 @@ set(BENCHMARK_NAMES "multiprecision/modular_adaptor_fixed" - "zk/lpc" + #"zk/lpc" "zk/pedersen" ) diff --git a/crypto3/benchmarks/algebra/curves.cpp b/crypto3/benchmarks/algebra/curves.cpp index 67264be342..50c4e33253 100644 --- a/crypto3/benchmarks/algebra/curves.cpp +++ b/crypto3/benchmarks/algebra/curves.cpp @@ -113,7 +113,7 @@ void benchmark_curve_operations(std::string const& curve_name) return A *= B; }); - if constexpr (has_template_g2_type::value) { + if constexpr (has_type_g2_type::value) { using g2_type = typename curve_type::template g2_type<>; using g2_field = typename g2_type::field_type; diff --git a/flake.nix b/flake.nix index b15ec32710..d3d0feb429 100644 --- a/flake.nix +++ b/flake.nix @@ -45,7 +45,12 @@ runTests = true; enableDebug = false; sanitize = true; - bench = true; + benchmarkTests = true; + }); + crypto3-clang-bench = (pkgs.callPackage ./crypto3.nix { + runTests = true; + enableDebug = false; + benchmarkTests = true; }); crypto3-clang-debug = (pkgs.callPackage ./crypto3.nix { stdenv = pkgs.llvmPackages_19.stdenv; @@ -108,6 +113,11 @@ runTests = true; enableDebug = false; }); + crypto3-gcc-bench = (pkgs.callPackage ./crypto3.nix { + runTests = true; + enableDebug = false; + benchmarkTests = true; + }); crypto3-clang = (pkgs.callPackage ./crypto3.nix { stdenv = pkgs.llvmPackages_19.stdenv; runTests = true; @@ -124,7 +134,7 @@ runTests = true; enableDebug = false; sanitize = true; - bench = true; + benchmarkTests = true; }); parallel-crypto3-gcc = (pkgs.callPackage ./parallel-crypto3.nix { From 4e488bdf0899c255a0843640a91abb2fd29d2638 Mon Sep 17 00:00:00 2001 From: Andrei Malashkin Date: Tue, 26 Nov 2024 21:10:11 +0100 Subject: [PATCH 09/13] fix error, when CMAKE_BUILD_TYPE is not defined --- CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 685a75d957..62a9f19643 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,9 +8,11 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") add_compile_options (-fcolor-diagnostics) endif () -if(DEFINED CMAKE_BUILD_TYPE AND ${CMAKE_BUILD_TYPE} STREQUAL "Debug") +if(DEFINED CMAKE_BUILD_TYPE) + if(${CMAKE_BUILD_TYPE} STREQUAL "Debug") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -ggdb") set(BOOST_FORCEINLINE "OFF") # improves debugging traces + endif() endif() option(SANITIZE "Build sanitizers" FALSE) From f5ce9e73361ec60109e9f6da46e32457525fc6fb Mon Sep 17 00:00:00 2001 From: Andrei Malashkin Date: Tue, 26 Nov 2024 21:10:40 +0100 Subject: [PATCH 10/13] fixed error CData section too big --- .../libs/parallelization-utils/test/thread_pool.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/parallel-crypto3/libs/parallelization-utils/test/thread_pool.cpp b/parallel-crypto3/libs/parallelization-utils/test/thread_pool.cpp index 22f8319ca3..c422356b48 100644 --- a/parallel-crypto3/libs/parallelization-utils/test/thread_pool.cpp +++ b/parallel-crypto3/libs/parallelization-utils/test/thread_pool.cpp @@ -39,6 +39,8 @@ BOOST_AUTO_TEST_SUITE(thread_pool_test_suite) BOOST_AUTO_TEST_CASE(vector_multiplication_test) { + boost::unit_test::unit_test_log_t::instance().set_threshold_level( boost::unit_test::log_messages ); + //boost::unit_test::framework::instance().set_report_level(boost::unit_test::log_silent); size_t size = 131072; std::vector v(size); From 03545ca2f3a108b2b190134d182e4a050c17d21a Mon Sep 17 00:00:00 2001 From: Andrei Malashkin Date: Wed, 27 Nov 2024 10:20:51 +0100 Subject: [PATCH 11/13] review notes --- flake.nix | 26 +++++++++++++++++--------- parallel-crypto3.nix | 2 ++ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/flake.nix b/flake.nix index d3d0feb429..9e1ff9bd7d 100644 --- a/flake.nix +++ b/flake.nix @@ -40,13 +40,6 @@ enableDebug = false; sanitize = true; }); - crypto3-clang-sanitize-bench = (pkgs.callPackage ./crypto3.nix { - stdenv = pkgs.llvmPackages_19.stdenv; - runTests = true; - enableDebug = false; - sanitize = true; - benchmarkTests = true; - }); crypto3-clang-bench = (pkgs.callPackage ./crypto3.nix { runTests = true; enableDebug = false; @@ -66,6 +59,11 @@ runTests = true; enableDebug = false; }); + parallel-crypto3-clang-bench = (pkgs.callPackage ./parallel-crypto3.nix { + runTests = true; + enableDebug = false; + benchmarkTests = true; + }); parallel-crypto3-debug-tests = (pkgs.callPackage ./parallel-crypto3.nix { enableDebug = true; runTests = true; @@ -129,17 +127,21 @@ enableDebug = false; sanitize = true; }); - crypto3-clang-sanitize-bench = (pkgs.callPackage ./crypto3.nix { + crypto3-clang-bench = (pkgs.callPackage ./crypto3.nix { stdenv = pkgs.llvmPackages_19.stdenv; runTests = true; enableDebug = false; - sanitize = true; benchmarkTests = true; }); parallel-crypto3-gcc = (pkgs.callPackage ./parallel-crypto3.nix { runTests = true; enableDebug = false; + benchmarkTests = true; + }); + parallel-crypto3-gcc-bench = (pkgs.callPackage ./parallel-crypto3.nix { + runTests = true; + enableDebug = false; }); parallel-crypto3-clang = (pkgs.callPackage ./parallel-crypto3.nix { stdenv = pkgs.llvmPackages_19.stdenv; @@ -151,6 +153,12 @@ runTests = true; enableDebug = false; }); + parallel-crypto3-clang-bench = (pkgs.callPackage ./parallel-crypto3.nix { + stdenv = pkgs.llvmPackages_19.stdenv; + runTests = true; + enableDebug = false; + benchmarkTests = true; + }); proof-producer-gcc = (pkgs.callPackage ./proof-producer.nix { runTests = true; diff --git a/parallel-crypto3.nix b/parallel-crypto3.nix index 4a0671e995..2316ac548c 100644 --- a/parallel-crypto3.nix +++ b/parallel-crypto3.nix @@ -11,6 +11,7 @@ enableDebug ? false, runTests ? false, sanitize? false, + benchmarkTests ? false, }: let inherit (lib) optional; @@ -34,6 +35,7 @@ in stdenv.mkDerivation { (if runTests then "-DBUILD_PARALLEL_CRYPTO3_TESTS=TRUE" else "") (if enableDebug then "-DCMAKE_BUILD_TYPE=Debug" else "-DCMAKE_BUILD_TYPE=Release") (if sanitize then "-DSANITIZE=ON" else "-DSANITIZE=OFF") + (if benchmarkTests then "-DENABLE_BENCHMARKS=ON" else "-DENABLE_BENCHMARKS=OFF") "-DPARALLEL_CRYPTO3_ENABLE=TRUE" ]; From 89a3786b80ef2e95d78ab4c760a97567d00cf1d5 Mon Sep 17 00:00:00 2001 From: Martun Karapetyan Date: Wed, 27 Nov 2024 17:30:12 +0400 Subject: [PATCH 12/13] Fix creation of FRI params. --- crypto3/benchmarks/zk/lpc.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/crypto3/benchmarks/zk/lpc.cpp b/crypto3/benchmarks/zk/lpc.cpp index 7f02f20dd1..77b8d440aa 100644 --- a/crypto3/benchmarks/zk/lpc.cpp +++ b/crypto3/benchmarks/zk/lpc.cpp @@ -135,11 +135,12 @@ void lpc_test_case(std::size_t steps) math::calculate_domain_set(extended_log, r); typename fri_type::params_type fri_params( - d - 1, - D, - generate_random_step_list(r, steps), + steps, r, - lambda + lambda, + 2, //expand_factor + true, // use_grinding + 12 // grinding_parameter ); using lpc_scheme_type = nil::crypto3::zk::commitments::lpc_commitment_scheme>; From 5cfb8dd7769acad1b66e1243150ce98a2b939807 Mon Sep 17 00:00:00 2001 From: Andrei Malashkin Date: Wed, 27 Nov 2024 14:51:08 +0100 Subject: [PATCH 13/13] reenable zk/lpc test --- crypto3/benchmarks/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crypto3/benchmarks/CMakeLists.txt b/crypto3/benchmarks/CMakeLists.txt index 4e1c9528c1..c1f19f6dde 100644 --- a/crypto3/benchmarks/CMakeLists.txt +++ b/crypto3/benchmarks/CMakeLists.txt @@ -60,7 +60,7 @@ set(BENCHMARK_NAMES "multiprecision/modular_adaptor_fixed" - #"zk/lpc" + "zk/lpc" "zk/pedersen" )