From cf6a989fb8f65c3d03dc558ab9b6004387a4946f Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Mon, 2 Jun 2025 16:46:49 +0100 Subject: [PATCH 1/2] Fix UB in benchmark From https://en.cppreference.com/w/c/language/operator_arithmetic.html: > The behavior is undefined if rhs is negative or is greater or equal > the number of bits in the promoted lhs. --- src/bench.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/bench.cpp b/src/bench.cpp index dc44379..ac7fb03 100644 --- a/src/bench.cpp +++ b/src/bench.cpp @@ -6,6 +6,7 @@ #include "../include/minisketch.h" #include +#include #include #include #include @@ -42,7 +43,13 @@ int main(int argc, char** argv) { std::vector states; std::vector roots(2 * syndromes); std::random_device rng; - std::uniform_int_distribution dist(1, (uint64_t(1) << bits) - 1); + uint64_t upper_bound; + if (bits < 64) { + upper_bound = (uint64_t(1) << bits) - 1; + } else { + upper_bound = std::numeric_limits::max(); + } + std::uniform_int_distribution dist(1, upper_bound); states.resize(iters); std::vector benches; benches.reserve(iters); From b0919e10a0e8db7c8eab2a7bb19962146612f532 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Wed, 2 Jul 2025 09:52:16 +0100 Subject: [PATCH 2/2] ci: Enable benchmarks for all Windows jobs --- .github/workflows/ci.yml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8a57838..32837a9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,18 +28,12 @@ jobs: build_configuration: 'Release' - job_name: 'x64 (MSVC): Windows (VS 2022, debug)' build_configuration: 'Debug' - # TODO: Resolve the issue and re-enable benchmark. - # See: https://github.com/bitcoin-core/minisketch/pull/96. - skip_benchmark: true - job_name: 'x64 (MSVC): Windows (VS 2022, shared)' cmake_options: '-DBUILD_SHARED_LIBS=ON' build_configuration: 'Release' - job_name: 'x64 (clang-cl): Windows (VS 2022)' cmake_options: '-T ClangCL' build_configuration: 'Release' - # TODO: Resolve the issue and re-enable benchmark. - # See: https://github.com/bitcoin-core/minisketch/pull/96. - skip_benchmark: true steps: - name: Checkout @@ -64,6 +58,5 @@ jobs: run: ctest --output-on-failure -j $env:NUMBER_OF_PROCESSORS -C ${{ matrix.configuration.build_configuration }} - name: Benchmark - if: ${{ ! matrix.configuration.skip_benchmark }} working-directory: build run: bin\${{ matrix.configuration.build_configuration }}\bench.exe