Skip to content

Commit 1e04d32

Browse files
committed
Merge #288: cmake: Add support for -zkp modules
4228fd1 cmake: Add support for -zkp modules (Tim Ruffing) Pull request description: ACKs for top commit: jonasnick: utACK 4228fd1 Tree-SHA512: 72606bb3421a4d6479c5cbc94e2468d6a9a53581f571fd5340edc41595eac18fbb04dcaacce8f39020e32a69b733ba6743aac4b901e1600f5245a4a04cb0e27a
2 parents 03aecaf + 4228fd1 commit 1e04d32

File tree

4 files changed

+137
-4
lines changed

4 files changed

+137
-4
lines changed

CMakeLists.txt

+70
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,70 @@ option(SECP256K1_ENABLE_MODULE_EXTRAKEYS "Enable extrakeys module." ON)
6161
option(SECP256K1_ENABLE_MODULE_SCHNORRSIG "Enable schnorrsig module." ON)
6262
option(SECP256K1_ENABLE_MODULE_ELLSWIFT "Enable ElligatorSwift module." ON)
6363

64+
option(SECP256K1_ENABLE_MODULE_GENERATOR "Enable NUMS generator module." ON)
65+
option(SECP256K1_ENABLE_MODULE_RANGEPROOF "Enable Range proof module." ON)
66+
option(SECP256K1_ENABLE_MODULE_SURJECTIONPROOF "Enable Surjection proof module." ON)
67+
option(SECP256K1_ENABLE_MODULE_WHITELIST "Enable key whitelist module." ON)
68+
option(SECP256K1_ENABLE_MODULE_MUSIG "Enable MuSig module." ON)
69+
option(SECP256K1_ENABLE_MODULE_ECDSA_ADAPTOR "Enable ecdsa adaptor signatures module." ON)
70+
option(SECP256K1_ENABLE_MODULE_ECDSA_S2C "Enable ECDSA sign-to-contract module." ON)
71+
option(SECP256K1_ENABLE_MODULE_BPPP "Enable Bulletproofs++ module." ON)
72+
6473
# Processing must be done in a topological sorting of the dependency graph
6574
# (dependent module first).
75+
if(SECP256K1_ENABLE_MODULE_BPPP)
76+
if(DEFINED SECP256K1_ENABLE_MODULE_GENERATOR AND NOT SECP256K1_ENABLE_MODULE_GENERATOR)
77+
message(FATAL_ERROR "Module dependency error: You have disabled the generator module explicitly, but it is required by the bppp module.")
78+
endif()
79+
set(SECP256K1_ENABLE_MODULE_GENERATOR ON)
80+
add_compile_definitions(ENABLE_MODULE_BPPP=1)
81+
endif()
82+
83+
if(SECP256K1_ENABLE_MODULE_ECDSA_S2C)
84+
add_compile_definitions(ENABLE_MODULE_ECDSA_S2C=1)
85+
endif()
86+
87+
if(SECP256K1_ENABLE_MODULE_ECDSA_ADAPTOR)
88+
add_compile_definitions(ENABLE_MODULE_ECDSA_ADAPTOR=1)
89+
endif()
90+
91+
if(SECP256K1_ENABLE_MODULE_MUSIG)
92+
if(DEFINED SECP256K1_ENABLE_MODULE_SCHNORRSIG AND NOT SECP256K1_ENABLE_MODULE_SCHNORRSIG)
93+
message(FATAL_ERROR "Module dependency error: You have disabled the schnorrsig module explicitly, but it is required by the musig module.")
94+
endif()
95+
set(SECP256K1_ENABLE_MODULE_SCHNORRSIG ON)
96+
add_compile_definitions(ENABLE_MODULE_MUSIG=1)
97+
endif()
98+
99+
if(SECP256K1_ENABLE_MODULE_WHITELIST)
100+
if(DEFINED SECP256K1_ENABLE_MODULE_RANGEPROOF AND NOT SECP256K1_ENABLE_MODULE_RANGEPROOF)
101+
message(FATAL_ERROR "Module dependency error: You have disabled the rangeproof module explicitly, but it is required by the whitelist module.")
102+
endif()
103+
set(SECP256K1_ENABLE_MODULE_RANGEPROOF ON)
104+
add_compile_definitions(ENABLE_MODULE_WHITELIST=1)
105+
endif()
106+
107+
if(SECP256K1_ENABLE_MODULE_SURJECTIONPROOF)
108+
if(DEFINED SECP256K1_ENABLE_MODULE_RANGEPROOF AND NOT SECP256K1_ENABLE_MODULE_RANGEPROOF)
109+
message(FATAL_ERROR "Module dependency error: You have disabled the rangeproof module explicitly, but it is required by the surjectionproof module.")
110+
endif()
111+
set(SECP256K1_ENABLE_MODULE_RANGEPROOF ON)
112+
add_compile_definitions(ENABLE_MODULE_SURJECTIONPROOF=1)
113+
endif()
114+
115+
if(SECP256K1_ENABLE_MODULE_RANGEPROOF)
116+
if(DEFINED SECP256K1_ENABLE_MODULE_GENERATOR AND NOT SECP256K1_ENABLE_MODULE_GENERATOR)
117+
message(FATAL_ERROR "Module dependency error: You have disabled the generator module explicitly, but it is required by the rangeproof module.")
118+
endif()
119+
set(SECP256K1_ENABLE_MODULE_GENERATOR ON)
120+
add_compile_definitions(ENABLE_MODULE_RANGEPROOF=1)
121+
endif()
122+
123+
if(SECP256K1_ENABLE_MODULE_GENERATOR)
124+
add_compile_definitions(ENABLE_MODULE_GENERATOR=1)
125+
endif()
126+
127+
66128
if(SECP256K1_ENABLE_MODULE_ELLSWIFT)
67129
add_compile_definitions(ENABLE_MODULE_ELLSWIFT=1)
68130
endif()
@@ -292,6 +354,14 @@ message(" ECDSA pubkey recovery ............... ${SECP256K1_ENABLE_MODULE_RECOV
292354
message(" extrakeys ........................... ${SECP256K1_ENABLE_MODULE_EXTRAKEYS}")
293355
message(" schnorrsig .......................... ${SECP256K1_ENABLE_MODULE_SCHNORRSIG}")
294356
message(" ElligatorSwift ...................... ${SECP256K1_ENABLE_MODULE_ELLSWIFT}")
357+
message(" generator ........................... ${SECP256K1_ENABLE_MODULE_GENERATOR}")
358+
message(" rangeproof .......................... ${SECP256K1_ENABLE_MODULE_RANGEPROOF}")
359+
message(" surjectionproof ..................... ${SECP256K1_ENABLE_MODULE_SURJECTIONPROOF}")
360+
message(" whitelist ........................... ${SECP256K1_ENABLE_MODULE_WHITELIST}")
361+
message(" musig ............................... ${SECP256K1_ENABLE_MODULE_MUSIG}")
362+
message(" ecdsa-s2c ........................... ${SECP256K1_ENABLE_MODULE_ECDSA_S2C}")
363+
message(" ecdsa-adaptor ....................... ${SECP256K1_ENABLE_MODULE_ECDSA_ADAPTOR}")
364+
message(" bppp ................................ ${SECP256K1_ENABLE_MODULE_BPPP}")
295365
message("Parameters:")
296366
message(" ecmult window size .................. ${SECP256K1_ECMULT_WINDOW_SIZE}")
297367
message(" ecmult gen precision bits ........... ${SECP256K1_ECMULT_GEN_PREC_BITS}")

README.md

+37
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,43 @@ Building with Autotools
2929

3030
To compile optional modules (such as Schnorr signatures), you need to run `./configure` with additional flags (such as `--enable-module-schnorrsig`). Run `./configure --help` to see the full list of available flags. For experimental modules, you will also need `--enable-experimental` as well as a flag for each individual module, e.g. `--enable-module-musig`.
3131

32+
Building with CMake (experimental)
33+
----------------------------------
34+
35+
To maintain a pristine source tree, CMake encourages to perform an out-of-source build by using a separate dedicated build tree.
36+
37+
### Building on POSIX systems
38+
39+
$ mkdir build && cd build
40+
$ cmake ..
41+
$ cmake --build .
42+
$ ctest # run the test suite
43+
$ sudo cmake --build . --target install # optional
44+
45+
To compile optional modules (such as Schnorr signatures), you need to run `cmake` with additional flags (such as `-DSECP256K1_ENABLE_MODULE_SCHNORRSIG=ON`). Run `cmake .. -LH` to see the full list of available flags.
46+
47+
### Cross compiling
48+
49+
To alleviate issues with cross compiling, preconfigured toolchain files are available in the `cmake` directory.
50+
For example, to cross compile for Windows:
51+
52+
$ cmake .. -DCMAKE_TOOLCHAIN_FILE=../cmake/x86_64-w64-mingw32.toolchain.cmake
53+
54+
To cross compile for Android with [NDK](https://developer.android.com/ndk/guides/cmake) (using NDK's toolchain file, and assuming the `ANDROID_NDK_ROOT` environment variable has been set):
55+
56+
$ cmake .. -DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK_ROOT}/build/cmake/android.toolchain.cmake" -DANDROID_ABI=arm64-v8a -DANDROID_PLATFORM=28
57+
58+
### Building on Windows
59+
60+
To build on Windows with Visual Studio, a proper [generator](https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html#visual-studio-generators) must be specified for a new build tree.
61+
62+
The following example assumes using of Visual Studio 2022 and CMake v3.21+.
63+
64+
In "Developer Command Prompt for VS 2022":
65+
66+
>cmake -G "Visual Studio 17 2022" -A x64 -S . -B build
67+
>cmake --build build --config RelWithDebInfo
68+
3269
Usage examples
3370
-----------
3471

configure.ac

+5-4
Original file line numberDiff line numberDiff line change
@@ -454,14 +454,14 @@ if test x"$enable_module_bppp" = x"yes"; then
454454
enable_module_generator=yes
455455
fi
456456

457-
if test x"$enable_module_ecdsa_adaptor" = x"yes"; then
458-
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_ECDSA_ADAPTOR=1"
459-
fi
460-
461457
if test x"$enable_module_ecdsa_s2c" = x"yes"; then
462458
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_ECDSA_S2C=1"
463459
fi
464460

461+
if test x"$enable_module_ecdsa_adaptor" = x"yes"; then
462+
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_ECDSA_ADAPTOR=1"
463+
fi
464+
465465
if test x"$enable_module_musig" = x"yes"; then
466466
if test x"$enable_module_schnorrsig" = x"no"; then
467467
AC_MSG_ERROR([Module dependency error: You have disabled the schnorrsig module explicitly, but it is required by the musig module.])
@@ -498,6 +498,7 @@ if test x"$enable_module_generator" = x"yes"; then
498498
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_GENERATOR=1"
499499
fi
500500

501+
501502
if test x"$enable_module_ellswift" = x"yes"; then
502503
SECP_CONFIG_DEFINES="$SECP_CONFIG_DEFINES -DENABLE_MODULE_ELLSWIFT=1"
503504
fi

src/CMakeLists.txt

+25
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,31 @@ if(SECP256K1_INSTALL)
120120
"${PROJECT_SOURCE_DIR}/include/secp256k1.h"
121121
"${PROJECT_SOURCE_DIR}/include/secp256k1_preallocated.h"
122122
)
123+
if(SECP256K1_ENABLE_MODULE_BPPP)
124+
list(APPEND ${PROJECT_NAME}_headers "${PROJECT_SOURCE_DIR}/include/secp256k1_bppp.h")
125+
endif()
126+
if(SECP256K1_ENABLE_MODULE_ECDSA_S2C)
127+
list(APPEND ${PROJECT_NAME}_headers "${PROJECT_SOURCE_DIR}/include/secp256k1_ecdsa_s2c.h")
128+
endif()
129+
if(SECP256K1_ENABLE_MODULE_ECDSA_ADAPTOR)
130+
list(APPEND ${PROJECT_NAME}_headers "${PROJECT_SOURCE_DIR}/include/secp256k1_ecdsa_adaptor.h")
131+
endif()
132+
if(SECP256K1_ENABLE_MODULE_MUSIG)
133+
list(APPEND ${PROJECT_NAME}_headers "${PROJECT_SOURCE_DIR}/include/secp256k1_musig.h")
134+
endif()
135+
if(SECP256K1_ENABLE_MODULE_WHITELIST)
136+
list(APPEND ${PROJECT_NAME}_headers "${PROJECT_SOURCE_DIR}/include/secp256k1_whitelist.h")
137+
endif()
138+
if(SECP256K1_ENABLE_MODULE_SURJECTIONPROOF)
139+
list(APPEND ${PROJECT_NAME}_headers "${PROJECT_SOURCE_DIR}/include/secp256k1_surjectionproof.h")
140+
endif()
141+
if(SECP256K1_ENABLE_MODULE_RANGEPROOF)
142+
list(APPEND ${PROJECT_NAME}_headers "${PROJECT_SOURCE_DIR}/include/secp256k1_rangeproof.h")
143+
endif()
144+
if(SECP256K1_ENABLE_MODULE_GENERATOR)
145+
list(APPEND ${PROJECT_NAME}_headers "${PROJECT_SOURCE_DIR}/include/secp256k1_generator.h")
146+
endif()
147+
123148
if(SECP256K1_ENABLE_MODULE_ECDH)
124149
list(APPEND ${PROJECT_NAME}_headers "${PROJECT_SOURCE_DIR}/include/secp256k1_ecdh.h")
125150
endif()

0 commit comments

Comments
 (0)