diff --git a/.github/workflows/run-3pc-tests.yml b/.github/workflows/run-3pc-tests.yml index c22bf34a..fbfb04ac 100644 --- a/.github/workflows/run-3pc-tests.yml +++ b/.github/workflows/run-3pc-tests.yml @@ -22,9 +22,7 @@ jobs: test-all-3pc: if: github.event.pull_request.draft == false - # ubuntu-latest, for private repos, only gives us 2 cores - # see github docs for more info - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 # Bumping this because apt install is slow (and we need coproto installed) timeout-minutes: 30 @@ -64,7 +62,7 @@ jobs: test-2pc: if: github.event.pull_request.draft == false - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 # This should be more than enough time to run tests, but also need enough # time to install libOTe + save cache, where necessary @@ -110,7 +108,7 @@ jobs: with: path: | build/secure-join-install - key: secrecy-securejoin-${{ hashFiles('scripts/_setup_libote.sh', 'scripts/_clone_libote.sh', 'scripts/_setup_securejoin.sh', 'scripts/cmake/FindlibOTe.cmake') }} + key: secrecy-securejoin-${{ hashFiles('scripts/_setup_libote.sh', 'scripts/_clone_libote.sh', 'scripts/_setup_securejoin.sh') }} # cache miss, so install from scratch - if: ${{ steps.cache-securejoin.outputs.cache-hit != 'true' }} @@ -140,9 +138,9 @@ jobs: test-others: if: github.event.pull_request.draft == false - # ubuntu-latest, for private repos, only gives us 2 cores + # for private repos, only gives us 2 cores # see github docs for more info - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 timeout-minutes: 10 diff --git a/CMakeLists.txt b/CMakeLists.txt index 53a3c606..1456ec0a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ project(Orq VERSION 1.0.0 LANGUAGES CXX) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(OPT_LEVEL "2" CACHE STRING "Optimization level (0-3)") -set(CMAKE_CXX_FLAGS "-O${OPT_LEVEL} -pthread -fwrapv") +set(CMAKE_CXX_FLAGS "-O${OPT_LEVEL} -g -pthread -fwrapv") add_compile_options(-Wno-deprecated-declarations) @@ -25,13 +25,7 @@ endif (PERF) if (NOT NO_X86_SSE) if (CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64") - # ubuntu-latest runners are a mix of AVX2-only and AVX-512 machines, and - # x86-64-v3 (common ancestor) is sufficient for our purposes. - if(DEFINED ENV{GITHUB_ACTIONS}) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mbmi -march=x86-64-v3") - else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mbmi -march=native") - endif() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mbmi -march=native") endif() endif (NOT NO_X86_SSE) @@ -96,6 +90,10 @@ find_package(Threads REQUIRED) # Adding Dependencies # add_subdirectory(src/external-lib/sql-parser) +# Skip MPI C++ bindings: RELIC (via libOTe/SecureJoin) #define's DOUBLE, +# which collides with OpenMPI's MPI::DOUBLE when the CXX headers are pulled in. +add_compile_definitions(OMPI_SKIP_MPICXX MPICH_SKIP_MPICXX) + # Adding MPI Library find_package(MPI REQUIRED) if (MPI_FOUND) @@ -129,9 +127,7 @@ if (PROTOCOL EQUAL "2" AND LINK_LIBOTE) find_package(secureJoin REQUIRED HINTS secure-join-install/lib/cmake/secureJoin/ - secure-join-install/lib64/cmake/secureJoin/ - build/secure-join-install/lib/cmake/secureJoin/ - build/secure-join-install/lib64/cmake/secureJoin/) + build/secure-join-install/lib/cmake/secureJoin/) link_directories(${CMAKE_CURRENT_SOURCE_DIR}/build/secure-join-install/lib) endif () @@ -143,10 +139,10 @@ find_package(cryptoTools REQUIRED HINTS list(APPEND LINK_LIBRARIES "oc::cryptoTools") function(add_secure_join target_name) - if(PROTOCOL EQUAL "2" AND LINK_LIBOTE) - target_link_libraries(${target_name} secureJoin) - target_include_directories(${target_name} SYSTEM PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/build/secure-join-install/include/secureJoin/) - endif() + if(PROTOCOL EQUAL "2" AND LINK_LIBOTE) + target_link_libraries(${target_name} secureJoin) + target_include_directories(${target_name} SYSTEM PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/build/secure-join-install/include/secureJoin/) + endif() endfunction() # Option: switch between custom 4PC and original Dalskov et al. protocol diff --git a/bench/micro/micro_comm_batch.cpp b/bench/micro/micro_comm_batch.cpp index 3a37c22a..4ace70d8 100644 --- a/bench/micro/micro_comm_batch.cpp +++ b/bench/micro/micro_comm_batch.cpp @@ -41,7 +41,7 @@ int main(int argc, char** argv) { comm_suffix = "NoCopyComm (" + std::to_string(NOCOPY_COMMUNICATOR_THREADS) + ")"; single_cout( - "Vector: " << test_size << " x " << std::numeric_limits>::digits + "Vector: " << test_size << " x " << std::numeric_limits>::digits << "b | Sample count: " << SAMPLE_COUNT << " | Communicator: " << comm_suffix); orq::Vector send_batch(test_size), recv_batch(test_size); diff --git a/bench/micro/micro_comm_threads.cpp b/bench/micro/micro_comm_threads.cpp index 50b5986f..c0509996 100644 --- a/bench/micro/micro_comm_threads.cpp +++ b/bench/micro/micro_comm_threads.cpp @@ -74,7 +74,7 @@ int main(int argc, char** argv) { comm_suffix = "NoCopyComm (" + std::to_string(NOCOPY_COMMUNICATOR_THREADS) + ")"; single_cout( - "Vector: " << test_size << " x " << std::numeric_limits>::digits + "Vector: " << test_size << " x " << std::numeric_limits>::digits << "b | Sample count: " << SAMPLE_COUNT << " | Communicator: " << comm_suffix); #ifdef CORRECTNESS_CHECK diff --git a/bench/micro/micro_primitives.cpp b/bench/micro/micro_primitives.cpp index ff77d782..297793f7 100644 --- a/bench/micro/micro_primitives.cpp +++ b/bench/micro/micro_primitives.cpp @@ -26,7 +26,7 @@ int main(int argc, char** argv) { ASharedVector x(test_size), y(test_size); single_cout("Vector " << test_size << " x " - << std::numeric_limits>::digits << "b"); + << std::numeric_limits>::digits << "b"); stopwatch::timepoint("Start"); diff --git a/bench/micro/thread_test.cpp b/bench/micro/thread_test.cpp index d989decc..82d37a29 100644 --- a/bench/micro/thread_test.cpp +++ b/bench/micro/thread_test.cpp @@ -34,7 +34,7 @@ int main(int argc, char** argv) { BSharedVector a(test_size), b(test_size); - const int bw = std::numeric_limits>::digits; + const int bw = std::numeric_limits>::digits; single_cout("Test " << test_size << " x " << bw << " " << op << "\n"); diff --git a/bench/queries/other/comorbidity.cpp b/bench/queries/other/comorbidity.cpp index 9e12cb5a..148c14c5 100644 --- a/bench/queries/other/comorbidity.cpp +++ b/bench/queries/other/comorbidity.cpp @@ -47,7 +47,7 @@ using sec = duration; #endif using T = int64_t; -using uT = std::make_unsigned_t; +using uT = orq::make_unsigned_t; // Setting these up to be roughly similar in size to TPCH, SF 1 -> ~5M rows // Update later based on dataset if required diff --git a/bench/queries/other/distinct_patients.cpp b/bench/queries/other/distinct_patients.cpp index 92b19588..38005a25 100644 --- a/bench/queries/other/distinct_patients.cpp +++ b/bench/queries/other/distinct_patients.cpp @@ -49,7 +49,7 @@ using sec = duration; #endif using T = int64_t; -using uT = std::make_unsigned_t; +using uT = orq::make_unsigned_t; // Setting these up to be roughly similar in size to TPCH, SF 1 -> ~5M rows // Update later based on dataset if required diff --git a/bench/queries/tpch/tpch_dbgen.h b/bench/queries/tpch/tpch_dbgen.h index effd7c07..f739d22d 100644 --- a/bench/queries/tpch/tpch_dbgen.h +++ b/bench/queries/tpch/tpch_dbgen.h @@ -77,7 +77,7 @@ class TPCDatabase { * @return Vector */ Vector randomColumn(size_t size, T min_val, T max_val) { - using uT = std::make_unsigned_t; + using uT = orq::make_unsigned_t; Vector uvec(size); runTime->populateLocalRandom(uvec); diff --git a/examples/ex4_wagegap.cpp b/examples/ex4_wagegap.cpp index 70dcd667..a317b710 100644 --- a/examples/ex4_wagegap.cpp +++ b/examples/ex4_wagegap.cpp @@ -64,7 +64,7 @@ int main(int argc, char **argv) { auto pID = runTime->getPartyID(); using D = int32_t; - using uD = std::make_unsigned_t; + using uD = orq::make_unsigned_t; std::vector schema = { "Salary", // in USD diff --git a/include/backend/common/util.h b/include/backend/common/util.h index cc047043..687fc9a6 100644 --- a/include/backend/common/util.h +++ b/include/backend/common/util.h @@ -1,15 +1,77 @@ #pragma once +#include #include +#include #include -template && !std::is_same_v, bool>)> +// GCC 15's libstdc++ does not treat __int128 as an integral type, so +// std::integral, std::make_unsigned, and std::is_signed reject it. Clang +// still accepts it. __int128 and unsigned __int128 are __int128_t and +// __uint128_t. +template +concept extended_integral = std::same_as, __int128> || + std::same_as, unsigned __int128>; + +namespace orq { + +template +struct make_unsigned { + using type = std::make_unsigned_t; +}; + +template +struct make_unsigned { + using type = unsigned __int128; +}; + +template +using make_unsigned_t = typename make_unsigned::type; + +template +inline constexpr bool is_signed_v = + std::is_signed_v || std::same_as, __int128>; + +template +inline constexpr bool is_unsigned_v = + std::is_unsigned_v || std::same_as, unsigned __int128>; + +// std::popcount and std::bit_width require __unsigned_integer, which also +// excludes unsigned __int128 on GCC 15. +constexpr int popcount(unsigned __int128 x) { + return std::popcount(static_cast(x)) + + std::popcount(static_cast(x >> 64)); +} + +template + requires(!extended_integral) +constexpr int popcount(T x) { + return std::popcount(x); +} + +constexpr int bit_width(unsigned __int128 x) { + auto hi = static_cast(x >> 64); + if (hi != 0) { + return 64 + std::bit_width(hi); + } + return std::bit_width(static_cast(x)); +} + +template + requires(!extended_integral) +constexpr int bit_width(T x) { + return std::bit_width(x); +} + +} // namespace orq + +template || extended_integral) && + !std::is_same_v, bool>)> struct UnsignedTypeSelector { using type = U; }; template struct UnsignedTypeSelector { - using type = std::make_unsigned_t; -}; \ No newline at end of file + using type = orq::make_unsigned_t; +}; diff --git a/include/core/containers/b_shared_vector.h b/include/core/containers/b_shared_vector.h index 20db7f13..711f3575 100644 --- a/include/core/containers/b_shared_vector.h +++ b/include/core/containers/b_shared_vector.h @@ -48,7 +48,7 @@ using unique_B = std::unique_ptr>; */ template class BSharedVector : public SharedVector { - static const uint MAX_BITS_NUMBER = std::numeric_limits>::digits; + static const uint MAX_BITS_NUMBER = std::numeric_limits>::digits; static const uint LOG_MAX_BITS_NUMBER = std::bit_width(MAX_BITS_NUMBER - 1); using unique_B = std::unique_ptr; diff --git a/include/core/containers/dummy_vector.h b/include/core/containers/dummy_vector.h index 04446f51..471a021c 100644 --- a/include/core/containers/dummy_vector.h +++ b/include/core/containers/dummy_vector.h @@ -71,15 +71,15 @@ namespace service { */ template class Vector { - template && !std::is_same_v, bool>)> + template || extended_integral) && + !std::is_same_v, bool>)> struct UnsignedTypeSelector { using type = U; }; template struct UnsignedTypeSelector { - using type = std::make_unsigned_t; + using type = orq::make_unsigned_t; }; /** @@ -161,7 +161,7 @@ class Vector { * conversion. Default is 16. */ template - requires std::integral + requires std::integral || extended_integral Vector(const std::vector& _other, int fixed_point_precision = 16) : Vector(static_cast(_other.size())) { precision = fixed_point_precision; diff --git a/include/core/containers/mapping_access_vector.h b/include/core/containers/mapping_access_vector.h index ef77ed91..298ed5c3 100644 --- a/include/core/containers/mapping_access_vector.h +++ b/include/core/containers/mapping_access_vector.h @@ -38,7 +38,8 @@ struct is_ntl_gf2e : std::true_type {}; } // namespace orq template -concept arithmetic = std::integral or std::floating_point or orq::is_ntl_gf2e::value; +concept arithmetic = std::integral or extended_integral or std::floating_point or + orq::is_ntl_gf2e::value; /** * @brief Define a binary operation between two vectors, such as `a - b`. @@ -180,7 +181,7 @@ static inline T getBit(const T& share, int bitIndex) { if constexpr (_use_bmi && std::numeric_limits::digits <= 64) { return _bextr_u64(share, bitIndex, 1); } else { - using Unsigned_type = typename std::make_unsigned::type; + using Unsigned_type = orq::make_unsigned_t; return ((Unsigned_type)share >> bitIndex) & (Unsigned_type)1; } } @@ -194,7 +195,7 @@ static inline T getBit(const T& share, int bitIndex) { */ template static inline void setBit(T& share, const T& bit, int bitIndex) { - using Unsigned_type = typename std::make_unsigned::type; + using Unsigned_type = orq::make_unsigned_t; share = (share & ~(((Unsigned_type)1 << bitIndex))) | (bit << bitIndex); } @@ -207,7 +208,7 @@ static inline void setBit(T& share, const T& bit, int bitIndex) { */ template static inline void clrBit(T& share, int bitIndex) { - using Unsigned_type = typename std::make_unsigned::type; + using Unsigned_type = orq::make_unsigned_t; share &= ~((Unsigned_type)1 << bitIndex); } @@ -238,7 +239,7 @@ static inline void setBitValue(T& share, const T& value, int bitIndex) { * @param mask which bits to modify */ template -static inline void setBitMask(T& share, const bool& value, const std::make_unsigned_t& mask) { +static inline void setBitMask(T& share, const bool& value, const orq::make_unsigned_t& mask) { share = (share & ~mask) | (-value & mask); } @@ -248,15 +249,15 @@ static inline void setBitMask(T& share, const bool& value, const std::make_unsig */ template class Vector { - template && !std::is_same_v, bool>)> + template || extended_integral) && + !std::is_same_v, bool>)> struct UnsignedTypeSelector { using type = U; }; template struct UnsignedTypeSelector { - using type = std::make_unsigned_t; + using type = orq::make_unsigned_t; }; /** @@ -418,7 +419,7 @@ class Vector { * conversion. Default is 16. */ template - requires std::integral + requires std::integral || extended_integral Vector(const std::vector& _other, int fixed_point_precision = 16) : Vector(static_cast(_other.size())) { precision = fixed_point_precision; @@ -508,7 +509,7 @@ class Vector { Vector res = this->construct_like(); for (VectorSizeType i = 0; i < size; ++i) { - res[i] = std::popcount(static_cast((*this)[i])) & 1; + res[i] = orq::popcount(static_cast((*this)[i])) & 1; } return res; diff --git a/include/core/containers/permutation.h b/include/core/containers/permutation.h index db0f5127..dbe407b8 100644 --- a/include/core/containers/permutation.h +++ b/include/core/containers/permutation.h @@ -88,7 +88,7 @@ class ElementwisePermutation { ElementwisePermutation(const SharedVector &v) : sharedVector(v.vector, v.encoding) { // ensure we're not discarding data when converting to 32 bits - const int bit_length = std::numeric_limits>::digits; + const int bit_length = std::numeric_limits>::digits; static_assert(bit_length <= 32); } diff --git a/include/core/math/util.h b/include/core/math/util.h index 029de5b0..4143b1ef 100644 --- a/include/core/math/util.h +++ b/include/core/math/util.h @@ -11,6 +11,8 @@ #include #include +#include "backend/common/util.h" + namespace orq::math { static_assert(std::numeric_limits::digits == 64, "unsigned long must be 64 bits"); @@ -37,7 +39,7 @@ NTL::ZZ to_ZZ(T x) { return NTL::ZZ(x); } else { // 128-bit - using U = std::make_unsigned_t; + using U = orq::make_unsigned_t; static_assert(std::numeric_limits::digits == 128); U ux = static_cast(x); @@ -45,7 +47,7 @@ NTL::ZZ to_ZZ(T x) { auto hi = static_cast(ux >> 64); NTL::ZZ res = (NTL::to_ZZ(hi) << 64) | NTL::to_ZZ(lo); - if constexpr (std::is_signed_v) { + if constexpr (orq::is_signed_v) { if (x < 0) { // handle 2s compl res -= pow_128; @@ -66,17 +68,17 @@ NTL::ZZ to_ZZ(T x) { template T from_ZZ(NTL::ZZ x) { if constexpr (sizeof(T) <= sizeof(long)) { - if constexpr (std::is_signed_v) { + if constexpr (orq::is_signed_v) { return static_cast(NTL::to_long(x)); } else { return static_cast(NTL::to_ulong(x)); } } else { // 128-bit - using U = std::make_unsigned_t; + using U = orq::make_unsigned_t; static_assert(std::numeric_limits::digits == 128); - if constexpr (std::is_signed_v) { + if constexpr (orq::is_signed_v) { if (x < 0) { // handle 2s compl x += pow_128; diff --git a/include/core/operators/circuits.h b/include/core/operators/circuits.h index dbc6da3c..b54a7b23 100644 --- a/include/core/operators/circuits.h +++ b/include/core/operators/circuits.h @@ -37,7 +37,7 @@ template static unique_B ripple_carry_adder(const BSharedVector& a, const BSharedVector& b, const bool carry_in) { - static const size_t MAX_BITS_NUMBER = std::numeric_limits>::digits; + static const size_t MAX_BITS_NUMBER = std::numeric_limits>::digits; size_t compressed_size = math::div_ceil(a.size(), MAX_BITS_NUMBER); // Compressed vectors @@ -96,7 +96,7 @@ static unique_B rca_compare(const BSharedVector& a, const BSharedVec // compute a + (~b) + 1 auto nb = ~b; - static const size_t MAX_BITS_NUMBER = std::numeric_limits>::digits; + static const size_t MAX_BITS_NUMBER = std::numeric_limits>::digits; size_t compressed_size = math::div_ceil(a.size(), MAX_BITS_NUMBER); // Compressed vectors @@ -180,7 +180,7 @@ std::pair, BSharedVector> prefix_sum( template unique_B parallel_prefix_adder(const BSharedVector& current, const BSharedVector& other, const bool carry_in) { - static const uint MAX_BITS_NUMBER = std::numeric_limits>::digits; + static const uint MAX_BITS_NUMBER = std::numeric_limits>::digits; static const uint LOG_MAX_BITS_NUMBER = std::bit_width(MAX_BITS_NUMBER - 1); BSharedVector p = current ^ other, g = current & other, propagate(current.size()); @@ -234,7 +234,7 @@ static void linear_compare(const BSharedVector& current, const BSharedVect assert(size == other.size()); // Number of bits in the share representation - const size_t MAX_BITS_NUMBER = std::numeric_limits>::digits; + const size_t MAX_BITS_NUMBER = std::numeric_limits>::digits; auto compressed_size = math::div_ceil(size, MAX_BITS_NUMBER); BSharedVector b1(compressed_size), b2(compressed_size), r(compressed_size); @@ -259,7 +259,7 @@ static void linear_compare(const BSharedVector& current, const BSharedVect gt_bits.bit_xor(gt_bits); // If the shares are signed numbers, we need to treat the sign bits differently - if (std::is_signed::value) { + if (orq::is_signed_v) { // Extract MSB (sign bit), compressed b1.pack_from(current, MAX_BITS_NUMBER - 1); b2.pack_from(other, MAX_BITS_NUMBER - 1); @@ -316,7 +316,7 @@ void orq::BSharedVector::_compare(const orq::BSharedVector& other, } // Number of bits in the share representation - const size_t MAX_BITS_NUMBER = std::numeric_limits>::digits; + const size_t MAX_BITS_NUMBER = std::numeric_limits>::digits; auto compressed_size = math::div_ceil(size, MAX_BITS_NUMBER); @@ -340,7 +340,7 @@ void orq::BSharedVector::_compare(const orq::BSharedVector& other, gt_bits.bit_xor(gt_bits); // If the shares are signed numbers, we need to treat the sign bits differently - if (std::is_signed::value) { + if (orq::is_signed_v) { BSharedVector s1(compressed_size), s2(compressed_size), r(compressed_size); // Extract MSB (sign bit), compressed diff --git a/include/core/operators/join.h b/include/core/operators/join.h index 80a16af7..394b13ac 100644 --- a/include/core/operators/join.h +++ b/include/core/operators/join.h @@ -195,7 +195,7 @@ TABLE_T TABLE_T::_join(TABLE_T &right, std::vector keys, Aggregatio auto L = size(); auto R = right.size(); - auto w = std::numeric_limits>::digits; + auto w = std::numeric_limits>::digits; auto c = schema.size() - 1; // don't count valid if (R < (L * (w + c - 1) / (c + 2))) { diff --git a/include/core/operators/sorting.h b/include/core/operators/sorting.h index c30b1712..caa4373c 100644 --- a/include/core/operators/sorting.h +++ b/include/core/operators/sorting.h @@ -30,7 +30,7 @@ namespace operators { template static ElementwisePermutation radix_sort( BSharedVector& v, SortOrder order = SortOrder::ASC, - const size_t bits = std::numeric_limits>::digits, + const size_t bits = std::numeric_limits>::digits, bool no_invert = false); // \endcond DOXYGEN_IGNORE diff --git a/include/core/protocols/dummy_0pc.h b/include/core/protocols/dummy_0pc.h index 51695061..9b79c164 100644 --- a/include/core/protocols/dummy_0pc.h +++ b/include/core/protocols/dummy_0pc.h @@ -64,7 +64,7 @@ class Dummy_0PC : public Protocol { }) ->second; - auto bits = std::numeric_limits>::digits; + auto bits = std::numeric_limits>::digits; uint64_t max_count_width = std::ceil(std::log10(max_count * bits)); diff --git a/include/core/protocols/plaintext_1pc.h b/include/core/protocols/plaintext_1pc.h index e49dea3f..f55e0aa4 100644 --- a/include/core/protocols/plaintext_1pc.h +++ b/include/core/protocols/plaintext_1pc.h @@ -68,7 +68,7 @@ class Plaintext_1PC : public Protocol { }) ->second; - auto bits = std::numeric_limits>::digits; + auto bits = std::numeric_limits>::digits; uint64_t max_count_width = std::ceil(std::log10(max_count * bits)); diff --git a/include/core/protocols/protocol.h b/include/core/protocols/protocol.h index d807caa6..f30f0df7 100644 --- a/include/core/protocols/protocol.h +++ b/include/core/protocols/protocol.h @@ -692,7 +692,7 @@ class Protocol : public ProtocolBase { * @param x - The shared vector to truncate. */ virtual void truncate(EVector& x) { - if constexpr (!std::integral) { + if constexpr (!(std::integral || extended_integral)) { // Only integral types support fixed point (no NTL types) return; } else { diff --git a/include/core/random/correlation/gilboa_crt.h b/include/core/random/correlation/gilboa_crt.h index 1663affa..cfdd2912 100644 --- a/include/core/random/correlation/gilboa_crt.h +++ b/include/core/random/correlation/gilboa_crt.h @@ -169,7 +169,7 @@ namespace internal { */ template class GilboaCRT : public OLEGenerator { - static constexpr int L = std::numeric_limits>::digits; + static constexpr int L = std::numeric_limits>::digits; using OLEBase = OLEGenerator; diff --git a/include/core/random/correlation/gilboa_ole.h b/include/core/random/correlation/gilboa_ole.h index 9f89e24d..296cb389 100644 --- a/include/core/random/correlation/gilboa_ole.h +++ b/include/core/random/correlation/gilboa_ole.h @@ -38,7 +38,7 @@ class GilboaOLE : public OLEGenerator { std::unique_ptr recv; std::unique_ptr send; - static constexpr size_t L = std::numeric_limits>::digits; + static constexpr size_t L = std::numeric_limits>::digits; /** * @brief Sender side of an additive correlated OT. libOTe provides XOR-correlations; we diff --git a/include/core/random/correlation/ole_generator.h b/include/core/random/correlation/ole_generator.h index 848fea22..7f6f6485 100644 --- a/include/core/random/correlation/ole_generator.h +++ b/include/core/random/correlation/ole_generator.h @@ -130,7 +130,7 @@ class OLEGenerator : public CorrelationGenerator, Vector */ template class OLEmodPrimeInterface { - static_assert(std::is_unsigned_v, "OLEmodPrimeInterface: T must be unsigned!"); + static_assert(orq::is_unsigned_v, "OLEmodPrimeInterface: T must be unsigned!"); public: using wide_t = typename DoubleWidth::type; @@ -148,7 +148,7 @@ class OLEmodPrimeInterface { T getPrime() const { return prime; } - int primeBits() const { return std::bit_width(prime); } + int primeBits() const { return orq::bit_width(prime); } using ole_t = std::tuple, Vector>; diff --git a/include/core/random/correlation/oprf.h b/include/core/random/correlation/oprf.h index a0896518..65ad3601 100644 --- a/include/core/random/correlation/oprf.h +++ b/include/core/random/correlation/oprf.h @@ -1,5 +1,7 @@ #pragma once +#include + #include "backend/common/libote_io.h" #include "constants.h" #include "coproto/Socket/AsioSocket.h" @@ -142,19 +144,19 @@ class OPRF { std::vector y(n); - // initialize the OLE generators - ole.init(sock_ole_send->fork(), prng, !isServer, 1, 1 << 18, 0); - - // handle the thread pool, not quite sure what this does + // One thread runs the PRF and the OLE generator. The work guard keeps + // the pool alive while both tasks are scheduled on it. macoro::thread_pool pool; - auto e = pool.make_work(); // this line is CRITICAL, even though e is never used (reference - // counting) + auto work = pool.make_work(); pool.create_threads(1); + // fork() copies the current executor. Install it first so OLE + // completions resume on this pool, same as the PRF task. An empty + // executor resumes on the Asio thread and races the generator. sock_main_send->setExecutor(pool); sock_ole_send->setExecutor(pool); + ole.init(sock_ole_send->fork(), prng, !isServer, 1, 1 << 18, 0); - // evaluate sender->init(n, ole, secJoin::AltModPrfKeyMode::SenderOnly, secJoin::AltModPrfInputMode::ReceiverOnly, key, rk); sender->preprocess(); @@ -162,6 +164,10 @@ class OPRF { auto r = coproto::sync_wait(coproto::when_all_ready( ole.start() | macoro::start_on(pool), sender->evaluate({}, y, *sock_main_send, prng) | macoro::start_on(pool))); + // when_all_ready does not rethrow. An unchecked failure leaves y zero + // and the correctness test fails with no protocol error. + std::get<0>(r).result(); + std::get<1>(r).result(); oc::cp::sync_wait(sock_main_send->flush()); // flush the socket oc::cp::sync_wait(sock_ole_send->flush()); // flush the socket @@ -202,19 +208,15 @@ class OPRF { std::vector x(reinterpret_cast(x_vec.data()), reinterpret_cast(x_vec.data() + n)); - // initialize the OLE generators - ole.init(sock_ole_recv->fork(), prng, !isServer, 1, 1 << 18, 0); - - // handle the thread pool, not quite sure what this does macoro::thread_pool pool; - auto e = pool.make_work(); // this line is CRITICAL, even though e is never used (reference - // counting) + auto work = pool.make_work(); pool.create_threads(1); + // Same ordering as evaluate_sender: executor before fork. sock_main_recv->setExecutor(pool); sock_ole_recv->setExecutor(pool); + ole.init(sock_ole_recv->fork(), prng, !isServer, 1, 1 << 18, 0); - // evaluate receiver->init(n, ole, secJoin::AltModPrfKeyMode::SenderOnly, secJoin::AltModPrfInputMode::ReceiverOnly, {}, sk); receiver->preprocess(); @@ -222,6 +224,8 @@ class OPRF { auto r = coproto::sync_wait(coproto::when_all_ready( ole.start() | macoro::start_on(pool), receiver->evaluate(x, y, *sock_main_recv, prng) | macoro::start_on(pool))); + std::get<0>(r).result(); + std::get<1>(r).result(); oc::cp::sync_wait(sock_main_recv->flush()); // flush the socket oc::cp::sync_wait(sock_ole_recv->flush()); // flush the socket diff --git a/include/core/random/correlation/silent_ot.h b/include/core/random/correlation/silent_ot.h index 4f020afe..05318d09 100644 --- a/include/core/random/correlation/silent_ot.h +++ b/include/core/random/correlation/silent_ot.h @@ -173,7 +173,7 @@ class SilentOT : public OTGenerator { bool isServer; int thread; - size_t L = std::numeric_limits>::digits; + size_t L = std::numeric_limits>::digits; public: /** diff --git a/include/debug/orq_debug.h b/include/debug/orq_debug.h index 05238d94..02dea7fd 100644 --- a/include/debug/orq_debug.h +++ b/include/debug/orq_debug.h @@ -508,7 +508,7 @@ static void print_table(const std::pair>& ta template T get_bit(const T& s, int i) { - using Unsigned_type = typename std::make_unsigned::type; + using Unsigned_type = orq::make_unsigned_t; return ((Unsigned_type)s >> i) & (Unsigned_type)1; } diff --git a/scripts/_setup_cryptotools.sh b/scripts/_setup_cryptotools.sh index a2fb7373..d1eef7fd 100755 --- a/scripts/_setup_cryptotools.sh +++ b/scripts/_setup_cryptotools.sh @@ -4,16 +4,4 @@ source $(dirname $0)/_clone_libote.sh cd cryptoTools -# prevent illegal instruction issue -case "$(uname -m)" in - x86_64|amd64|AMD64) - ISA_FLAGS= - if [[ -n "${GITHUB_ACTIONS:-}" ]]; then - ISA_FLAGS="-DENABLE_AVX512=OFF" - fi - ;; - *) - ISA_FLAGS="-DENABLE_SSE=OFF -DENABLE_AVX=OFF -DENABLE_AVX512=OFF" - ;; -esac -python3 build.py --par=4 --install=../../libOTe-install $ISA_FLAGS \ No newline at end of file +python3 build.py --par=4 --install=../../libOTe-install diff --git a/scripts/_setup_libote.sh b/scripts/_setup_libote.sh index a782cb6e..f1726f49 100755 --- a/scripts/_setup_libote.sh +++ b/scripts/_setup_libote.sh @@ -6,43 +6,28 @@ set -e ## Set up libOTe echo "==== Building libOTe..." -# Resolve before _clone_libote.sh, which cds into libOTe. -script_dir=$(cd "$(dirname "$0")" && pwd) -source "${script_dir}/_clone_libote.sh" +source $(dirname $0)/_clone_libote.sh -case "$(uname -m)" in - x86_64|amd64|AMD64) - SSE_OPTION="-DENABLE_SSE=ON" - # Do not cache an AVX-512 libOTe and run it on an AVX2-only runner. - # Leave host detection alone on other x86 machines. - AVX512_FLAG= - if [[ -n "${GITHUB_ACTIONS:-}" ]]; then - AVX512_FLAG="-DENABLE_AVX512=OFF" - fi - ;; - *) - # SSE, AVX, and AVX-512 are x86. ARM builds use the scalar paths. - SSE_OPTION="-DENABLE_SSE=OFF -DENABLE_AVX=OFF -DENABLE_AVX512=OFF -DENABLE_SPIN=OFF" - AVX512_FLAG= - ;; -esac +if [[ $(uname -m) == x86_64 ]]; then + SSE_OPTION="-DENABLE_SSE=ON" +else + SSE_OPTION="-DENABLE_SSE=OFF -DENABLE_AVX=OFF " +fi -# #defines B0 as the baud rate 0. macOS has always done this, and -# glibc does too (bits/termios.h). libOTe tests declare variables named B0 -# after Boost.Asio has included termios.h, so the preprocessor turns B0(n) -# into a numeric constant. Force-include a header that keeps B0 usable both -# as an identifier and as Asio's baud-rate constant. The compiler is launched -# from per-target directories under out/build, at different depths, so a -# relative -include path cannot resolve. Pass an absolute path with no space: -# build.py joins arguments into a shell command. -termios_header="${script_dir}/mac_undef_termios.h" -if [[ ! -f "${termios_header}" ]]; then - echo "missing termios workaround header: ${termios_header}" >&2 - exit 1 +# is in libstdc++ from GCC 13. Use g++-13 when the default compiler is older. +if ! echo '#include ' | ${CXX:-g++} -std=c++20 -x c++ -E - >/dev/null 2>&1; then + if command -v g++-13 >/dev/null 2>&1; then + export CXX=g++-13 + export CC=gcc-13 + else + echo "libOTe requires GCC 13 or newer (missing ). Install g++-13 and rerun." >&2 + exit 1 + fi fi -TERMIOS_CXX_FLAGS="-DCMAKE_CXX_FLAGS=-include${termios_header}" -python3 build.py --par=4 --boost --sodium --relic -DSODIUM_MONTGOMERY=false --all --install=../libOTe-install \ - $SSE_OPTION $TERMIOS_CXX_FLAGS $AVX512_FLAG +# Boost.Asio includes , and that header's B0 macro breaks the libOTe tests. +python3 build.py --par=4 --boost --sodium --relic -DSODIUM_MONTGOMERY=false -DENABLE_LOGVOLE=OFF --all --install=../libOTe-install \ + -DCMAKE_CXX_FLAGS=-DBOOST_ASIO_DISABLE_SERIAL_PORT \ + $SSE_OPTION echo "==== libOTe installed" diff --git a/scripts/cmake/FindlibOTe.cmake b/scripts/cmake/FindlibOTe.cmake deleted file mode 100644 index 4dae45f5..00000000 --- a/scripts/cmake/FindlibOTe.cmake +++ /dev/null @@ -1,40 +0,0 @@ -# SecureJoin calls find_package(libOTe) and then links the target name libOTe. -# That target exists when SecureJoin builds libOTe with add_subdirectory. An -# install from scripts/_setup_libote.sh exports oc::libOTe instead, and that -# imported target does not carry cryptoTools' headers. Point this search at -# that install and publish the target names SecureJoin already uses. -# -# scripts/_setup_securejoin.sh passes -DCMAKE_MODULE_PATH to this directory -# and -DLIBOTE_INSTALL_PREFIX to the install root. --noauto makes SecureJoin -# take this find_package path instead of compiling libOTe again. - -if(NOT LIBOTE_INSTALL_PREFIX) - message(FATAL_ERROR "LIBOTE_INSTALL_PREFIX is not set") -endif() - -message(STATUS "Using installed libOTe at ${LIBOTE_INSTALL_PREFIX}") - -# The caller asked for components (no_asan, sse, ...). The installed config -# does not mark those components found. A nested find_package of this same -# name inherits them while libOTe_FIND_MODULE is on, and then rejects the -# install. Remember the names, and turn that inheritance off for the search. -set(_orq_libote_components ${libOTe_FIND_COMPONENTS}) -set(libOTe_FIND_MODULE OFF) - -find_package(libOTe CONFIG REQUIRED HINTS "${LIBOTE_INSTALL_PREFIX}") -find_package(cryptoTools CONFIG REQUIRED HINTS "${LIBOTE_INSTALL_PREFIX}") - -if(NOT TARGET libOTe) - add_library(libOTe INTERFACE) - target_link_libraries(libOTe INTERFACE oc::libOTe oc::cryptoTools) -endif() - -if(TARGET oc::tests_cryptoTools AND NOT TARGET tests_cryptoTools) - add_library(tests_cryptoTools INTERFACE) - target_link_libraries(tests_cryptoTools INTERFACE oc::tests_cryptoTools) -endif() - -foreach(comp IN LISTS _orq_libote_components) - set(libOTe_${comp}_FOUND TRUE) -endforeach() -set(libOTe_FOUND TRUE) diff --git a/scripts/setup.sh b/scripts/setup.sh index 8391129c..b551b4ba 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -7,4 +7,3 @@ $scripts_dir/_setup_cryptotools.sh $scripts_dir/_setup_ntl.sh $scripts_dir/_setup_libote.sh $scripts_dir/_setup_securejoin.sh -$scripts_dir/_setup_blaze.sh diff --git a/tests/test_correlated.cpp b/tests/test_correlated.cpp index 828ff59e..868d7495 100644 --- a/tests/test_correlated.cpp +++ b/tests/test_correlated.cpp @@ -15,7 +15,7 @@ const size_t test_size = 1 << 12; template class C> void checkCorrelation(std::string label) { - auto L = std::numeric_limits>::digits; + auto L = std::numeric_limits>::digits; single_cout_nonl("Checking length " << test_size << " " << L << "-bit " << label << "... "); auto gen = runTime->rand0()->template getCorrelation>(); diff --git a/tests/test_libote.cpp b/tests/test_libote.cpp index e175234e..fa8f7c97 100644 --- a/tests/test_libote.cpp +++ b/tests/test_libote.cpp @@ -53,7 +53,7 @@ inline auto eval(macoro::task<>& t0, macoro::task<>& t1) { */ template void test_noisy_vole_local(u64 n) { - auto L = std::numeric_limits>::digits; + auto L = std::numeric_limits>::digits; std::cout << "Local Noisy VOLE " << L << "-bit... "; std::vector A(n), B(n), C(n); @@ -108,7 +108,7 @@ void test_noisy_vole_local(u64 n) { */ template void test_silent_vole_local(u64 n) { - auto L = std::numeric_limits>::digits; + auto L = std::numeric_limits>::digits; std::cout << "Local Silent VOLE " << L << "-bit... "; using VecF = typename Ctx::template Vec; @@ -155,7 +155,7 @@ const uint LOG_OT_BLOCK_SIZE = std::bit_width(OT_BLOCK_SIZE) - 1; template void test_silent_ot_local(u64 n) { assert(n % OT_BLOCK_SIZE == 0); - auto L = std::numeric_limits>::digits; + auto L = std::numeric_limits>::digits; std::cout << "Local Silent OT " << L << "-bit... "; PRNG prng(sysRandomSeed()); @@ -236,7 +236,7 @@ void test_silent_ot_local(u64 n) { */ template void test_silent_vole_loopback(u64 n) { - auto L = std::numeric_limits>::digits; + auto L = std::numeric_limits>::digits; single_cout_nonl("LAN Silent OLE " << L << "-bit... "); using VecF = typename Ctx::template Vec; @@ -304,7 +304,7 @@ void test_silent_vole_loopback(u64 n) { template void test_silent_ot_loopback(u64 n) { assert(n % OT_BLOCK_SIZE == 0); - auto L = std::numeric_limits>::digits; + auto L = std::numeric_limits>::digits; bool isServer = (runTime->getPartyID() == 0); @@ -399,7 +399,7 @@ void test_silent_ot_loopback(u64 n) { template void test_silent_ot_chosen(u64 n) { - auto L = std::numeric_limits>::digits; + auto L = std::numeric_limits>::digits; bool isServer = (runTime->getPartyID() == 0); @@ -521,6 +521,10 @@ int main(int argc, char** argv) { test_silent_ot_local(test_size); } + // Party 0 runs the in-process tests above before it listens. Party 1 + // would otherwise connect, retry, and speak to whatever accepts first. + MPI_Barrier(MPI_COMM_WORLD); + // 2PC tests of Silent VOLE test_silent_vole_loopback(test_size); test_silent_vole_loopback(test_size); diff --git a/tests/test_operators.cpp b/tests/test_operators.cpp index e4a855b9..0d29da67 100644 --- a/tests/test_operators.cpp +++ b/tests/test_operators.cpp @@ -58,7 +58,7 @@ void test_minimal_agg_example() { template void test_vector_aggregation(const size_t test_size = 32) { - single_cout("Testing " << std::numeric_limits>::digits + single_cout("Testing " << std::numeric_limits>::digits << "-bit vector aggregation..."); std::vector data(test_size); // TODO: random values @@ -199,7 +199,7 @@ void test_vector_aggregation(const size_t test_size = 32) { template void test_distinct(const int test_size = 32) { - single_cout("Testing " << std::numeric_limits>::digits + single_cout("Testing " << std::numeric_limits>::digits << "-bit distinct..."); orq::Vector data(test_size); orq::Vector truth(test_size); @@ -237,7 +237,7 @@ void test_distinct(const int test_size = 32) { template void test_multi_distinct() { - single_cout("Testing " << std::numeric_limits>::digits + single_cout("Testing " << std::numeric_limits>::digits << "-bit multi-key distinct..."); auto pid = runTime->getPartyID(); std::vector> c1 = {{0, 0, 0, 1, 1, 1, 2}, {0, 0, 1, 1, 1, 0, 2}, Vector(7)}; @@ -259,7 +259,7 @@ void test_multi_distinct() { // TODO: auto generate tables and test results as above. template void test_table_operators() { - single_cout("Testing " << std::numeric_limits>::digits + single_cout("Testing " << std::numeric_limits>::digits << "-bit tables..."); const std::vector schema = { diff --git a/tests/test_primitives.cpp b/tests/test_primitives.cpp index a0d81747..fd7241e7 100644 --- a/tests/test_primitives.cpp +++ b/tests/test_primitives.cpp @@ -43,7 +43,7 @@ void test_b2a(int test_size) { #define DEFINE_TEST_BINARY_OP(_op_, shareType, name) \ template \ void test_##name(int test_size) { \ - auto L = std::numeric_limits>::digits; \ + auto L = std::numeric_limits>::digits; \ single_cout_nonl(L << "-bit " #name "... "); \ orq::Vector x(test_size); \ orq::Vector y(test_size); \ @@ -83,7 +83,7 @@ DEFINE_TEST_BINARY_OP(<, BSharedVector, less_than); template void test_private_division(int test_size) { - using uT = std::make_unsigned_t; + using uT = orq::make_unsigned_t; auto L = std::numeric_limits::digits; single_cout_nonl("Boolean long division, " << L << "-bit... "); @@ -120,7 +120,7 @@ void test_private_division(int test_size) { template void test_dot_product(int test_size, const int aggSize = 7) { - auto L = std::numeric_limits>::digits; + auto L = std::numeric_limits>::digits; single_cout_nonl(L << "-bit dot product(" << aggSize << ")... "); if (test_size % aggSize != 0) { @@ -149,7 +149,7 @@ void test_dot_product(int test_size, const int aggSize = 7) { template void test_equals(int test_size) { - auto L = std::numeric_limits>::digits; + auto L = std::numeric_limits>::digits; single_cout_nonl(L << "-bit equals..."); orq::Vector x(test_size), y(test_size); diff --git a/tests/test_table_operators.cpp b/tests/test_table_operators.cpp index 8fa823ef..6b6c79c8 100644 --- a/tests/test_table_operators.cpp +++ b/tests/test_table_operators.cpp @@ -29,7 +29,7 @@ void assert_table_schema(EncodedTable table, size_t column_count) { template void test_add_columns() { - single_cout_nonl("Testing " << std::numeric_limits>::digits + single_cout_nonl("Testing " << std::numeric_limits>::digits << "-bit: addColumns... "); EncodedTable table = create_test_table(1); @@ -47,7 +47,7 @@ void test_add_columns() { template void test_delete_columns() { - single_cout_nonl("Testing " << std::numeric_limits>::digits + single_cout_nonl("Testing " << std::numeric_limits>::digits << "-bit: deleteColumns... "); EncodedTable table = create_test_table(6); @@ -69,7 +69,7 @@ void test_delete_columns() { template void test_project() { - single_cout_nonl("Testing " << std::numeric_limits>::digits + single_cout_nonl("Testing " << std::numeric_limits>::digits << "-bit: project... "); // Project single column @@ -91,7 +91,7 @@ void test_project() { template void test_resize() { - single_cout_nonl("Testing " << std::numeric_limits>::digits + single_cout_nonl("Testing " << std::numeric_limits>::digits << "-bit: resize... "); const size_t n_rows = 10000;