Skip to content

Commit 750d8a3

Browse files
authored
Libsnark get_evaluation_domain works on macOS (#1419)
Before this change on macOS systems, libsnark would crash on get_root_of_unity and exception handlers would not work. The hypothesis is that using exceptions for control flow in get_evaluation_domain triggers some sort of UB (probably because this runs statically before the main function). On Linux, the UB happens to work properly, but on OSX it doesn't. As such, I rewrote all the control-flow related exception handling in get_evaluation_domain to use an error bool pointer. I'll open a PR against libsnark directly when the review for this PR finishes. On macOS the Coda build succeeds only after these changes are made (as we use libsnark at compile time). CI will tell us that the build still works on Linux.
1 parent 56496e6 commit 750d8a3

24 files changed

+192
-67
lines changed

src/lib/snarky/src/camlsnark_c/libsnark-caml/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ if(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
105105
# Common compilation flags and warning configuration
106106
set(
107107
CMAKE_CXX_FLAGS
108-
"${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra -Wfatal-errors"
108+
"${CMAKE_CXX_FLAGS} -std=c++14 -Wall -Wextra -Wfatal-errors"
109109
)
110110
if("${MULTICORE}")
111111
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")

src/lib/snarky/src/camlsnark_c/libsnark-caml/depends/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
add_subdirectory(gtest EXCLUDE_FROM_ALL)
22

3+
find_package(OpenSSL REQUIRED)
4+
35
if(${CURVE} STREQUAL "BN128")
46
include_directories(ate-pairing/include)
57
include_directories(xbyak)
8+
include_directories(${OPENSSL_INCLUDE_DIR})
69
add_library(
710
zm
811
STATIC
912

1013
ate-pairing/src/zm.cpp
1114
ate-pairing/src/zm2.cpp
1215
)
16+
target_link_libraries(zm ${OPENSSL_LIBRARIES})
1317
endif()
1418

1519
if("${WITH_SUPERCOP}")

src/lib/snarky/src/camlsnark_c/libsnark-caml/depends/gtest/.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ env:
3838
matrix:
3939
- GTEST_TARGET=googletest SHARED_LIB=OFF STATIC_LIB=ON CMAKE_PKG=OFF BUILD_TYPE=debug VERBOSE_MAKE=true VERBOSE
4040
- GTEST_TARGET=googlemock SHARED_LIB=OFF STATIC_LIB=ON CMAKE_PKG=OFF BUILD_TYPE=debug VERBOSE_MAKE=true VERBOSE
41-
- GTEST_TARGET=googlemock SHARED_LIB=OFF STATIC_LIB=ON CMAKE_PKG=OFF BUILD_TYPE=debug CXX_FLAGS=-std=c++11 VERBOSE_MAKE=true VERBOSE
41+
- GTEST_TARGET=googlemock SHARED_LIB=OFF STATIC_LIB=ON CMAKE_PKG=OFF BUILD_TYPE=debug CXX_FLAGS=-std=c++14 VERBOSE_MAKE=true VERBOSE
4242
# - GTEST_TARGET=googletest SHARED_LIB=ON STATIC_LIB=ON CMAKE_PKG=ON BUILD_TYPE=release VERBOSE_MAKE=false
4343
# - GTEST_TARGET=googlemock SHARED_LIB=ON STATIC_LIB=ON CMAKE_PKG=ON BUILD_TYPE=release VERBOSE_MAKE=false
4444
notifications:

src/lib/snarky/src/camlsnark_c/libsnark-caml/depends/libff/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ if(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
9393
# Common compilation flags and warning configuration
9494
set(
9595
CMAKE_CXX_FLAGS
96-
"${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra -Wfatal-errors"
96+
"${CMAKE_CXX_FLAGS} -std=c++14 -Wall -Wextra -Wfatal-errors"
9797
)
9898
if("${MULTICORE}")
9999
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")

src/lib/snarky/src/camlsnark_c/libsnark-caml/depends/libff/libff/algebra/fields/field_utils.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ namespace libff {
1818
// returns root of unity of order n (for n a power of 2), if one exists
1919
template<typename FieldT>
2020
typename std::enable_if<std::is_same<FieldT, Double>::value, FieldT>::type
21-
get_root_of_unity(const size_t n);
21+
get_root_of_unity(const size_t n, bool &err);
2222

2323
template<typename FieldT>
2424
typename std::enable_if<!std::is_same<FieldT, Double>::value, FieldT>::type
25-
get_root_of_unity(const size_t n);
25+
get_root_of_unity(const size_t n, bool &err);
2626

2727
template<typename FieldT>
2828
std::vector<FieldT> pack_int_vector_into_field_element_vector(const std::vector<size_t> &v, const size_t w);

src/lib/snarky/src/camlsnark_c/libsnark-caml/depends/libff/libff/algebra/fields/field_utils.tcc

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ FieldT coset_shift()
2626

2727
template<typename FieldT>
2828
typename std::enable_if<std::is_same<FieldT, Double>::value, FieldT>::type
29-
get_root_of_unity(const size_t n)
29+
get_root_of_unity(const size_t n, bool &err)
3030
{
3131
const double PI = 3.141592653589793238460264338328L;
3232

@@ -39,11 +39,18 @@ get_root_of_unity(const size_t n)
3939

4040
template<typename FieldT>
4141
typename std::enable_if<!std::is_same<FieldT, Double>::value, FieldT>::type
42-
get_root_of_unity(const size_t n)
42+
get_root_of_unity(const size_t n, bool &err)
4343
{
4444
const size_t logn = log2(n);
45-
if (n != (1u << logn)) throw std::invalid_argument("libff::get_root_of_unity: expected n == (1u << logn)");
46-
if (logn > FieldT::s) throw std::invalid_argument("libff::get_root_of_unity: expected logn <= FieldT::s");
45+
if (n != (1u << logn)) {
46+
err = true;
47+
return FieldT(1,1);
48+
}
49+
50+
if (logn > FieldT::s) {
51+
err = true;
52+
return FieldT(1,1);
53+
}
4754

4855
FieldT omega = FieldT::root_of_unity;
4956
for (size_t i = FieldT::s; i > logn; --i)

src/lib/snarky/src/camlsnark_c/libsnark-caml/depends/libfqfft/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ if(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
6262
set(
6363
CMAKE_CXX_FLAGS
6464

65-
"${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra -Wfatal-errors -pthread"
65+
"${CMAKE_CXX_FLAGS} -std=c++14 -Wall -Wextra -Wfatal-errors -pthread"
6666
)
6767

6868
if("${MULTICORE}")

src/lib/snarky/src/camlsnark_c/libsnark-caml/depends/libfqfft/depends/gtest/.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ env:
3838
matrix:
3939
- GTEST_TARGET=googletest SHARED_LIB=OFF STATIC_LIB=ON CMAKE_PKG=OFF BUILD_TYPE=debug VERBOSE_MAKE=true VERBOSE
4040
- GTEST_TARGET=googlemock SHARED_LIB=OFF STATIC_LIB=ON CMAKE_PKG=OFF BUILD_TYPE=debug VERBOSE_MAKE=true VERBOSE
41-
- GTEST_TARGET=googlemock SHARED_LIB=OFF STATIC_LIB=ON CMAKE_PKG=OFF BUILD_TYPE=debug CXX_FLAGS=-std=c++11 VERBOSE_MAKE=true VERBOSE
41+
- GTEST_TARGET=googlemock SHARED_LIB=OFF STATIC_LIB=ON CMAKE_PKG=OFF BUILD_TYPE=debug CXX_FLAGS=-std=c++14 VERBOSE_MAKE=true VERBOSE
4242
# - GTEST_TARGET=googletest SHARED_LIB=ON STATIC_LIB=ON CMAKE_PKG=ON BUILD_TYPE=release VERBOSE_MAKE=false
4343
# - GTEST_TARGET=googlemock SHARED_LIB=ON STATIC_LIB=ON CMAKE_PKG=ON BUILD_TYPE=release VERBOSE_MAKE=false
4444
notifications:

src/lib/snarky/src/camlsnark_c/libsnark-caml/depends/libfqfft/depends/libff/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ if(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
9393
# Common compilation flags and warning configuration
9494
set(
9595
CMAKE_CXX_FLAGS
96-
"${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra -Wfatal-errors"
96+
"${CMAKE_CXX_FLAGS} -std=c++14 -Wall -Wextra -Wfatal-errors"
9797
)
9898
if("${MULTICORE}")
9999
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")

src/lib/snarky/src/camlsnark_c/libsnark-caml/depends/libfqfft/libfqfft/evaluation_domain/domains/arithmetic_sequence_domain.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace libfqfft {
2828
FieldT arithmetic_generator;
2929
void do_precomputation();
3030

31-
arithmetic_sequence_domain(const size_t m);
31+
arithmetic_sequence_domain(const size_t m, bool &err);
3232

3333
void FFT(std::vector<FieldT> &a);
3434
void iFFT(std::vector<FieldT> &a);
@@ -46,4 +46,4 @@ namespace libfqfft {
4646

4747
#include <libfqfft/evaluation_domain/domains/arithmetic_sequence_domain.tcc>
4848

49-
#endif // ARITHMETIC_SEQUENCE_DOMAIN_HPP
49+
#endif // ARITHMETIC_SEQUENCE_DOMAIN_HPP

0 commit comments

Comments
 (0)