diff --git a/.github/resources/prover/windows.Makefile b/.github/resources/prover/windows.Makefile new file mode 100644 index 0000000..8bc079c --- /dev/null +++ b/.github/resources/prover/windows.Makefile @@ -0,0 +1,104 @@ +### + +#Build targets +host: + rm -rf build_prover && mkdir build_prover && cd build_prover && \ + cmake .. \ + -DCMAKE_BUILD_TYPE=Release + -DCMAKE_INSTALL_PREFIX=../package && \ + make -j$(nproc) -vvv && make install + +# Copy of the original host target, with specific flags for Windows x86_64 to add patches, missing libraries and +# include paths +host_windows_x86_64: + rm -rf build_prover && mkdir build_prover && cd build_prover && \ + cmake .. \ + -DUSE_ASM=OFF \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX=../package \ + -DCMAKE_EXE_LINKER_FLAGS="-L/lib -lmman" \ + -DCMAKE_CXX_FLAGS="-I/include -include mman_patch.hpp -include cstdint -Duint=unsigned\ int -Du_int32_t=uint32_t -Du_int64_t=uint64_t" && \ + make -j$(nproc) -vvv && make install + +host_noasm: + rm -rf build_prover_noasm && mkdir build_prover_noasm && cd build_prover_noasm && \ + cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package_noasm -DUSE_ASM=NO && \ + make -j$(nproc) -vvv && make install + +host_arm64: + rm -rf build_prover_arm64 && mkdir build_prover_arm64 && cd build_prover_arm64 && \ + cmake .. -DTARGET_PLATFORM=aarch64 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package_arm64 && \ + make -j$(nproc) -vvv && make install + +android: + rm -rf build_prover_android && mkdir build_prover_android && cd build_prover_android && \ + cmake .. -DTARGET_PLATFORM=ANDROID -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package_android -DBUILD_TESTS=OFF -DUSE_OPENMP=OFF && \ + make -j$(nproc) -vvv && make install + +android_openmp: + rm -rf build_prover_android_openmp && mkdir build_prover_android_openmp && cd build_prover_android_openmp && \ + cmake .. -DTARGET_PLATFORM=ANDROID -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package_android_openmp -DBUILD_TESTS=OFF -DUSE_OPENMP=ON && \ + make -j$(nproc) -vvv && make install + +android_x86_64: + rm -rf build_prover_android_x86_64 && mkdir build_prover_android_x86_64 && cd build_prover_android_x86_64 && \ + cmake .. -DTARGET_PLATFORM=ANDROID_x86_64 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package_android_x86_64 -DBUILD_TESTS=OFF -DUSE_OPENMP=OFF && \ + make -j$(nproc) -vvv && make install + +android_openmp_x86_64: + rm -rf build_prover_android_openmp_x86_64 && mkdir build_prover_android_openmp_x86_64 && cd build_prover_android_openmp_x86_64 && \ + cmake .. -DTARGET_PLATFORM=ANDROID_x86_64 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package_android_openmp_x86_64 -DBUILD_TESTS=OFF -DUSE_OPENMP=ON && \ + make -j$(nproc) -vvv && make install + +ios: + @if [ ! -d "./depends/gmp/package_ios_arm64" ]; then echo "Looks like gmp lib is not built. Run './build_gmp.sh ios' first." && exit 1; fi + rm -rf build_prover_ios && mkdir build_prover_ios && cd build_prover_ios && \ + cmake .. -GXcode -DTARGET_PLATFORM=IOS -DCMAKE_INSTALL_PREFIX=../package_ios && \ + xcodebuild -destination 'generic/platform=iOS' -scheme rapidsnarkStatic -project rapidsnark.xcodeproj -configuration Release && \ + xcodebuild -destination 'generic/platform=iOS' -scheme rapidsnark -project rapidsnark.xcodeproj -configuration Release CODE_SIGNING_ALLOWED=NO && \ + cp ../depends/gmp/package_ios_arm64/lib/libgmp.a src/Release-iphoneos && \ + echo "" && echo "iOS Simulator artifacts built in build_prover_ios/src/Release-iphoneos" && echo "" + +ios_simulator: + @if [ ! -d "./depends/gmp/package_iphone_simulator" ]; then echo "Looks like gmp lib is not built. Run './build_gmp.sh ios_simulator' first." && exit 1; fi + rm -rf build_prover_ios_simulator && mkdir build_prover_ios_simulator && cd build_prover_ios_simulator && \ + cmake .. -GXcode -DTARGET_PLATFORM=IOS_SIMULATOR -DCMAKE_INSTALL_PREFIX=../package_ios_simulator -DUSE_ASM=NO && \ + xcodebuild -destination 'generic/platform=iOS Simulator' -scheme rapidsnarkStatic -project rapidsnark.xcodeproj && \ + xcodebuild -destination 'generic/platform=iOS Simulator' -scheme rapidsnark -project rapidsnark.xcodeproj CODE_SIGNING_ALLOWED=NO ARCHS=arm64 && \ + cp ../depends/gmp/package_iphone_simulator/lib/libgmp.a src/Debug-iphonesimulator && \ + echo "" && echo "iOS Simulator artifacts built in build_prover_ios_simulator/src/Debug-iphonesimulator" && echo "" + +macos_arm64: + @if [ ! -d "./depends/gmp/package_macos_arm64" ]; then echo "Looks like gmp lib is not built. Run './build_gmp.sh macos_arm64' first." && exit 1; fi + rm -rf build_prover_macos_arm64 && mkdir build_prover_macos_arm64 && cd build_prover_macos_arm64 && \ + cmake .. -DTARGET_PLATFORM=macos_arm64 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package_macos_arm64 && \ + make -j$(nproc) -vvv && make install + +macos_x86_64: + @if [ ! -d "./depends/gmp/package_macos_x86_64" ]; then echo "Looks like gmp lib is not built. Run './build_gmp.sh macos_x86_64' first." && exit 1; fi + rm -rf build_prover_macos_x86_64 && mkdir build_prover_macos_x86_64 && cd build_prover_macos_x86_64 && \ + cmake .. -DTARGET_PLATFORM=macos_x86_64 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package_macos_x86_64 && \ + make -j$(nproc) -vvv && make install + +clean: + rm -rf build_prover \ + build_prover_macos_arm64 \ + build_prover_macos_x86_64 \ + build_prover_android \ + build_prover_android_x86_64 \ + build_prover_ios \ + build_prover_ios_simulator \ + package \ + package_macos_arm64 \ + package_macos_x86_64 \ + package_android \ + package_android_x86_64 \ + package_ios \ + package_ios_simulator \ + depends/gmp/package \ + depends/gmp/package_macos_arm64 \ + depends/gmp/package_macos_x86_64 \ + depends/gmp/package_android_arm64 \ + depends/gmp/package_android_x86_64 \ + depends/gmp/package_ios_arm64 \ + depends/gmp/package_iphone_simulator diff --git a/.github/resources/prover/windows.build_gmp.sh b/.github/resources/prover/windows.build_gmp.sh new file mode 100755 index 0000000..245ec0a --- /dev/null +++ b/.github/resources/prover/windows.build_gmp.sh @@ -0,0 +1,423 @@ +#!/usr/bin/env bash + +set -e + +NPROC=8 +fetch_cmd=$( (type wget > /dev/null 2>&1 && echo "wget") || echo "curl -O" ) + +usage() +{ + echo "USAGE: $0 " + echo "where target is one of:" + echo " ios: build for iOS arm64" + echo " ios_simulator: build for iPhone Simulator for arm64/x86_64 (fat binary)" + echo " macos: build for macOS for arm64/x86_64 (fat binary)" + echo " macos_arm64: build for macOS arm64" + echo " macos_x86_64: build for macOS x86_64" + echo " android: build for Android arm64" + echo " android_x86_64: build for Android x86_64" + echo " host: build for this host" + echo " host_noasm: build for this host without asm optimizations (e.g. needed for macOS)" + echo " aarch64: build for Linux aarch64" + + exit 1 +} + +get_gmp() +{ + GMP_NAME=gmp-6.2.1 + GMP_ARCHIVE=${GMP_NAME}.tar.xz + GMP_URL=https://ftp.gnu.org/gnu/gmp/${GMP_ARCHIVE} + + if [ ! -f ${GMP_ARCHIVE} ]; then + + $fetch_cmd ${GMP_URL} + fi + + + if [ ! -d gmp ]; then + + tar -xvf ${GMP_ARCHIVE} + mv ${GMP_NAME} gmp + fi +} + +build_aarch64() +{ + PACKAGE_DIR="$GMP_DIR/package_aarch64" + BUILD_DIR=build_aarch64 + + if [ -d "$PACKAGE_DIR" ]; then + echo "aarch64 package is built already. See $PACKAGE_DIR" + return 1 + fi + + + export TARGET=aarch64-linux-gnu + + echo $TARGET + + rm -rf "$BUILD_DIR" + mkdir "$BUILD_DIR" + cd "$BUILD_DIR" + + ../configure --host $TARGET --prefix="$PACKAGE_DIR" --with-pic --disable-fft && + make -j${NPROC} && + make install + + cd .. +} + +build_host() +{ + PACKAGE_DIR="$GMP_DIR/package" + BUILD_DIR=build + + if [ -d "$PACKAGE_DIR" ]; then + echo "Host package is built already. See $PACKAGE_DIR" + return 1 + fi + + rm -rf "$BUILD_DIR" + mkdir "$BUILD_DIR" + cd "$BUILD_DIR" + + # The following line is a workaround for the Windows build due to an existing incompatibility with current compiler + # when building GMP. + CFLAGS="-O2 -std=gnu17" CXXFLAGS="-O2 -std=gnu++17" \ + ../configure --prefix="$PACKAGE_DIR" --with-pic --disable-fft && + make -j${NPROC} && + make install + + cd .. +} + +build_host_noasm() +{ + PACKAGE_DIR="$GMP_DIR/package" + BUILD_DIR=build + + if [ -d "$PACKAGE_DIR" ]; then + echo "Host package is built already. See $PACKAGE_DIR" + return 1 + fi + + rm -rf "$BUILD_DIR" + mkdir "$BUILD_DIR" + cd "$BUILD_DIR" + + ../configure --prefix="$PACKAGE_DIR" --with-pic --disable-fft --disable-assembly && + make -j${NPROC} && + make install + + cd .. +} + +build_android() +{ + PACKAGE_DIR="$GMP_DIR/package_android_arm64" + BUILD_DIR=build_android_arm64 + + if [ -d "$PACKAGE_DIR" ]; then + echo "Android package is built already. See $PACKAGE_DIR" + return 1 + fi + + if [ -z "$ANDROID_NDK" ]; then + + echo "ERROR: ANDROID_NDK environment variable is not set." + echo " It must be an absolute path to the root directory of Android NDK." + echo " For instance /home/test/Android/Sdk/ndk/23.1.7779620" + return 1 + fi + + if [ "$(uname)" == "Darwin" ]; then + export TOOLCHAIN=$ANDROID_NDK/toolchains/llvm/prebuilt/darwin-x86_64 + else + export TOOLCHAIN=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64 + fi + + export TARGET=aarch64-linux-android + export API=21 + + export AR=$TOOLCHAIN/bin/llvm-ar + export CC=$TOOLCHAIN/bin/$TARGET$API-clang + export AS=$CC + export CXX=$TOOLCHAIN/bin/$TARGET$API-clang++ + export LD=$TOOLCHAIN/bin/ld + export RANLIB=$TOOLCHAIN/bin/llvm-ranlib + export STRIP=$TOOLCHAIN/bin/llvm-strip + + echo "$TOOLCHAIN" + echo "$TARGET" + + rm -rf "$BUILD_DIR" + mkdir "$BUILD_DIR" + cd "$BUILD_DIR" + + ../configure --host $TARGET --prefix="$PACKAGE_DIR" --with-pic --disable-fft && + make -j${NPROC} && + make install + + cd .. +} + +build_android_x86_64() +{ + PACKAGE_DIR="$GMP_DIR/package_android_x86_64" + BUILD_DIR=build_android_x86_64 + + if [ -d "$PACKAGE_DIR" ]; then + echo "Android package is built already. See $PACKAGE_DIR" + return 1 + fi + + if [ -z "$ANDROID_NDK" ]; then + + echo "ERROR: ANDROID_NDK environment variable is not set." + echo " It must be an absolute path to the root directory of Android NDK." + echo " For instance /home/test/Android/Sdk/ndk/23.1.7779620" + return 1 + fi + + if [ "$(uname)" == "Darwin" ]; then + export TOOLCHAIN=$ANDROID_NDK/toolchains/llvm/prebuilt/darwin-x86_64 + else + export TOOLCHAIN=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64 + fi + + export TARGET=x86_64-linux-android + export API=21 + + export AR=$TOOLCHAIN/bin/llvm-ar + export CC=$TOOLCHAIN/bin/$TARGET$API-clang + export AS=$CC + export CXX=$TOOLCHAIN/bin/$TARGET$API-clang++ + export LD=$TOOLCHAIN/bin/ld + export RANLIB=$TOOLCHAIN/bin/llvm-ranlib + export STRIP=$TOOLCHAIN/bin/llvm-strip + + echo "$TOOLCHAIN" + echo $TARGET + + rm -rf "$BUILD_DIR" + mkdir "$BUILD_DIR" + cd "$BUILD_DIR" + + ../configure --host $TARGET --prefix="$PACKAGE_DIR" --with-pic --disable-fft && + make -j${NPROC} && + make install + + cd .. +} + +build_ios() +{ + PACKAGE_DIR="$GMP_DIR/package_ios_arm64" + BUILD_DIR=build_ios_arm64 + + if [ -d "$PACKAGE_DIR" ]; then + echo "iOS package is built already. See $PACKAGE_DIR" + return 1 + fi + + export SDK="iphoneos" + export TARGET=arm64-apple-darwin + export MIN_IOS_VERSION=8.0 + + export ARCH_FLAGS="-arch arm64 -arch arm64e" + export OPT_FLAGS="-O3 -g3 -fembed-bitcode" + HOST_FLAGS="${ARCH_FLAGS} -miphoneos-version-min=${MIN_IOS_VERSION} -isysroot $(xcrun --sdk ${SDK} --show-sdk-path)" + + CC=$(xcrun --find --sdk "${SDK}" clang) + export CC + CXX=$(xcrun --find --sdk "${SDK}" clang++) + export CXX + CPP=$(xcrun --find --sdk "${SDK}" cpp) + export CPP + export CFLAGS="${HOST_FLAGS} ${OPT_FLAGS}" + export CXXFLAGS="${HOST_FLAGS} ${OPT_FLAGS}" + export LDFLAGS="${HOST_FLAGS}" + + echo $TARGET + + rm -rf "$BUILD_DIR" + mkdir "$BUILD_DIR" + cd "$BUILD_DIR" + + ../configure --host $TARGET --prefix="$PACKAGE_DIR" --with-pic --disable-fft --disable-assembly && + make -j${NPROC} && + make install + + cd .. +} + +build_ios_simulator() +{ + libs=() + for ARCH in "arm64" "x86_64"; do + case "$ARCH" in + "arm64" ) + echo "Building for iPhone Simulator arm64" + ARCH_FLAGS="-arch arm64 -arch arm64e" + ;; + "x86_64" ) + echo "Building for iPhone Simulator x86_64" + ARCH_FLAGS="-arch x86_64" + ;; + * ) + echo "Incorrect iPhone Simulator arch" + exit 1 + esac + + BUILD_DIR="build_iphone_simulator_${ARCH}" + PACKAGE_DIR="$GMP_DIR/package_iphone_simulator_${ARCH}" + libs+=("${PACKAGE_DIR}/lib/libgmp.a") + + if [ -d "$PACKAGE_DIR" ]; then + echo "iPhone Simulator ${ARCH} package is built already. See $PACKAGE_DIR. Skip building this ARCH." + continue + fi + + rm -rf "$BUILD_DIR" + mkdir "$BUILD_DIR" + cd "$BUILD_DIR" + + ../configure --prefix="${PACKAGE_DIR}" \ + CC="$(xcrun --sdk iphonesimulator --find clang)" \ + CFLAGS="-O3 -isysroot $(xcrun --sdk iphonesimulator --show-sdk-path) ${ARCH_FLAGS} -fvisibility=hidden -mios-simulator-version-min=8.0" \ + LDFLAGS="" \ + --host ${ARCH}-apple-darwin --disable-assembly --enable-static --disable-shared --with-pic && + make -j${NPROC} && + make install + + cd .. + done + + mkdir -p "${GMP_DIR}/package_iphone_simulator/lib" + lipo "${libs[@]}" -create -output "${GMP_DIR}/package_iphone_simulator/lib/libgmp.a" + echo "Wrote universal fat library for iPhone Simulator arm64/x86_64 to ${GMP_DIR}/package_iphone_simulator/lib/libgmp.a" +} + +build_macos_arch() +{ + ARCH="$1" + case "$ARCH" in + "arm64" ) + ARCH_FLAGS="-arch arm64 -arch arm64e" + ;; + "x86_64" ) + ARCH_FLAGS="-arch x86_64" + ;; + * ) + echo "Incorrect arch" + exit 1 + esac + + BUILD_DIR="build_macos_${ARCH}" + PACKAGE_DIR="$GMP_DIR/package_macos_${ARCH}" + if [ -d "$PACKAGE_DIR" ]; then + echo "macOS ${ARCH} package is built already. See $PACKAGE_DIR. Skip building this ARCH." + return + fi + rm -rf "$BUILD_DIR" + mkdir "$BUILD_DIR" + cd "$BUILD_DIR" + ../configure --prefix="${PACKAGE_DIR}" \ + CC="$(xcrun --sdk macosx --find clang)" \ + CFLAGS="-O3 -isysroot $(xcrun --sdk macosx --show-sdk-path) ${ARCH_FLAGS} -fvisibility=hidden -mmacos-version-min=14.0" \ + LDFLAGS="" \ + --host "${ARCH}-apple-darwin" --disable-assembly --enable-static --disable-shared --with-pic && + make -j${NPROC} && + make install + cd .. +} + +build_macos_fat() +{ + echo "Building for macOS arm64" + build_macos_arch "arm64" + echo "Building for macOS x86_64" + build_macos_arch "x86_64" + + gmp_lib_arm64="$GMP_DIR/package_macos_arm64/lib/libgmp.a" + gmp_lib_x86_64="$GMP_DIR/package_macos_x86_64/lib/libgmp.a" + gmp_lib_fat="$GMP_DIR/package_macos/lib/libgmp.a" + + mkdir -p "${GMP_DIR}/package_macos/lib" + lipo "${gmp_lib_arm64}" "${gmp_lib_x86_64}" -create -output "${gmp_lib_fat}" + mkdir -p "${GMP_DIR}/package_macos/include" + cp "${GMP_DIR}/package_macos_arm64/include/gmp.h" "${GMP_DIR}/package_macos/include/" + echo "Wrote universal fat library for macOS arm64/x86_64 to ${GMP_DIR}/package_macos/lib/libgmp.a" +} + +if [ $# -ne 1 ]; then + usage +fi + +TARGET_PLATFORM=$(echo "$1" | tr "[:upper:]" "[:lower:]") + +cd depends + +get_gmp + +cd gmp + +GMP_DIR=$PWD + +case "$TARGET_PLATFORM" in + + "ios" ) + echo "Building for ios" + build_ios + ;; + + "ios_simulator" ) + echo "Building for iPhone Simulator" + build_ios_simulator + ;; + + "macos" ) + echo "Building fat library for macOS" + build_macos_fat + ;; + + "macos_arm64" ) + echo "Building library for macOS arm64" + build_macos_arch "arm64" + ;; + + "macos_x86_64" ) + echo "Building library for macOS x86_64" + build_macos_arch "x86_64" + ;; + + "android" ) + echo "Building for android" + build_android + ;; + + "android_x86_64" ) + echo "Building for android x86_64" + build_android_x86_64 + ;; + + "host" ) + echo "Building for this host" + build_host + ;; + + "host_noasm" ) + echo "Building for this host without asm optimizations (e.g. needed for macOS)" + build_host_noasm + ;; + + "aarch64" ) + echo "Building for linux aarch64" + build_aarch64 + ;; + + * ) + usage + +esac diff --git a/.github/resources/prover/windows.mman_patch.hpp b/.github/resources/prover/windows.mman_patch.hpp new file mode 100644 index 0000000..718acb3 --- /dev/null +++ b/.github/resources/prover/windows.mman_patch.hpp @@ -0,0 +1,7 @@ +// Workaround for Windows where some mman functions are not defined + +#ifdef _WIN32 +#include +inline int madvise(void*, size_t, int) { return 0; } +#define MADV_SEQUENTIAL 0 +#endif diff --git a/.github/resources/prover/windows.src-CMakeLists.txt b/.github/resources/prover/windows.src-CMakeLists.txt new file mode 100644 index 0000000..d97580f --- /dev/null +++ b/.github/resources/prover/windows.src-CMakeLists.txt @@ -0,0 +1,181 @@ +# Workaround for CMake on Windows to +# Added explicit linking (e.g., mman), which are otherwise resolved transitively on Linux and macOS. + +find_library(MMAN_LIB mman PATHS /lib NO_DEFAULT_PATH REQUIRED) + +link_libraries(${GMP_LIB}) + +add_definitions(${GMP_DEFINIONS}) + +if(USE_ASM) + if(ARCH MATCHES "arm64") + add_definitions(-DUSE_ASM -DARCH_ARM64) + elseif(ARCH MATCHES "x86_64") + add_definitions(-DUSE_ASM -DARCH_X86_64) + endif() +endif() + +if(DEFINED BITS_PER_CHUNK) + add_definitions(-DMSM_BITS_PER_CHUNK=${BITS_PER_CHUNK}) +endif() + +if(USE_ASM AND ARCH MATCHES "x86_64") + + if (CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin" AND NOT TARGET_PLATFORM MATCHES "^android(_x86_64)?") + set(NASM_FLAGS -fmacho64 --prefix _) + else() + set(NASM_FLAGS -felf64 -DPIC) + endif() + + add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/build/fq_asm.o + COMMAND nasm ${NASM_FLAGS} fq.asm -o fq_asm.o + DEPENDS ${CMAKE_SOURCE_DIR}/build/fq.asm + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/build) + + add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/build/fr_asm.o + COMMAND nasm ${NASM_FLAGS} fr.asm -o fr_asm.o + DEPENDS ${CMAKE_SOURCE_DIR}/build/fr.asm + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/build) +endif() + +set(FR_SOURCES + ../build/fr.hpp + ../build/fr.cpp + ) + +if(USE_ASM) + if(ARCH MATCHES "arm64") + set(FR_SOURCES ${FR_SOURCES} ../build/fr_raw_arm64.s ../build/fr_raw_generic.cpp ../build/fr_generic.cpp) + elseif(ARCH MATCHES "x86_64") + set(FR_SOURCES ${FR_SOURCES} ../build/fr_asm.o) + endif() +else() + set(FR_SOURCES ${FR_SOURCES} ../build/fr_generic.cpp ../build/fr_raw_generic.cpp) +endif() + +add_library(fr STATIC ${FR_SOURCES}) +set_target_properties(fr PROPERTIES POSITION_INDEPENDENT_CODE ON) + +link_libraries(fr) + +set(FQ_SOURCES + ../build/fq.hpp + ../build/fq.cpp + ) + +if(USE_ASM) + if(ARCH MATCHES "arm64") + set(FQ_SOURCES ${FQ_SOURCES} ../build/fq_raw_arm64.s ../build/fq_raw_generic.cpp ../build/fq_generic.cpp) + elseif(ARCH MATCHES "x86_64") + set(FQ_SOURCES ${FQ_SOURCES} ../build/fq_asm.o) + endif() +else() + set(FQ_SOURCES ${FQ_SOURCES} ../build/fq_raw_generic.cpp ../build/fq_generic.cpp) +endif() + +add_library(fq STATIC ${FQ_SOURCES}) +set_target_properties(fq PROPERTIES POSITION_INDEPENDENT_CODE ON) + +link_libraries(fq) + + +if(OpenMP_CXX_FOUND) + add_definitions(-DUSE_OPENMP) + add_compile_options(${OpenMP_CXX_FLAGS}) +endif() + +set(LIB_SOURCES + binfile_utils.hpp + binfile_utils.cpp + zkey_utils.hpp + zkey_utils.cpp + wtns_utils.hpp + wtns_utils.cpp + logger.hpp + logger.cpp + fileloader.cpp + fileloader.hpp + prover.cpp + prover.h + verifier.cpp + verifier.h + ../depends/ffiasm/c/misc.cpp + ../depends/ffiasm/c/naf.cpp + ../depends/ffiasm/c/splitparstr.cpp + ../depends/ffiasm/c/alt_bn128.cpp + ) + +if(USE_LOGGER) + set(LIB_SOURCES ${LIB_SOURCES} logger.cpp) + add_definitions(-DUSE_LOGGER) +endif() + +include_directories( + ../src + ../build + ../depends/ffiasm/c + ../depends/json/single_include + /include +) + +add_library(rapidsnarkStatic STATIC ${LIB_SOURCES}) +set_target_properties(rapidsnarkStatic PROPERTIES OUTPUT_NAME rapidsnark) + +add_library(rapidsnarkStaticFrFq STATIC ${LIB_SOURCES} ${FQ_SOURCES} ${FR_SOURCES}) +set_target_properties(rapidsnarkStaticFrFq PROPERTIES POSITION_INDEPENDENT_CODE ON) +set_target_properties(rapidsnarkStaticFrFq PROPERTIES OUTPUT_NAME rapidsnark-fr-fq) + +add_executable(prover main_prover.cpp) +target_link_libraries( + prover rapidsnarkStatic + fr fq ${MMAN_LIB} # Explicit linking +) + +add_executable(verifier main_verifier.cpp) +target_link_libraries( + verifier rapidsnarkStatic + fr fq ${MMAN_LIB} # Explicit linking +) + +add_library(rapidsnark SHARED ${LIB_SOURCES}) +target_link_libraries(rapidsnark ${MMAN_LIB}) # Explicit linking + +if((USE_LOGGER OR NOT USE_OPENMP) AND NOT TARGET_PLATFORM MATCHES "android") + target_link_libraries(prover pthread) + target_link_libraries(verifier pthread) +endif() + +if(USE_SODIUM) + target_link_libraries(prover sodium) +endif() + +option(BUILD_TESTS "Build the tests" ON) + +if(BUILD_TESTS) + enable_testing() + add_executable(test_public_size test_public_size.c) + target_link_libraries( + test_public_size rapidsnarkStaticFrFq pthread + ${MMAN_LIB} # Explicit linking + ) + add_test(NAME test_public_size COMMAND test_public_size circuit_final.zkey 86 + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/testdata) +endif() + +if(OpenMP_CXX_FOUND) + + if(TARGET_PLATFORM MATCHES "android") + target_link_libraries(prover -static-openmp -fopenmp) + target_link_libraries(verifier -static-openmp -fopenmp) + target_link_libraries(rapidsnark -static-openmp -fopenmp) + + elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux") + target_link_libraries(prover OpenMP::OpenMP_CXX) + target_link_libraries(verifier OpenMP::OpenMP_CXX) + target_link_libraries(test_public_size OpenMP::OpenMP_CXX) + endif() + +endif() + + +add_executable(test_prover test_prover.cpp) diff --git a/.github/resources/prover/windows.uio.h b/.github/resources/prover/windows.uio.h new file mode 100644 index 0000000..8ac0de2 --- /dev/null +++ b/.github/resources/prover/windows.uio.h @@ -0,0 +1,19 @@ +// Workaround for Windows UIO header, as it's not available by default + +#ifndef SYS_UIO_H +#define SYS_UIO_H + +#include +#include + +struct iovec +{ + void *iov_base; + size_t iov_len; +}; + +ssize_t readv(int fildes, const struct iovec *iov, int iovcnt); +ssize_t writev(int fildes, const struct iovec *iov, int iovcnt); + +#endif + diff --git a/.github/resources/Makefile.macos b/.github/resources/witness-generator/macos.Makefile similarity index 95% rename from .github/resources/Makefile.macos rename to .github/resources/witness-generator/macos.Makefile index 0ee9c92..6bca6a3 100644 --- a/.github/resources/Makefile.macos +++ b/.github/resources/witness-generator/macos.Makefile @@ -1,5 +1,5 @@ CC = g++ -CFLAGS = -std=c++11 -O3 -I. -I/opt/homebrew/include -include gmp_patch.macos.hpp +CFLAGS = -std=c++11 -O3 -I. -I/opt/homebrew/include -include gmp_patch.hpp LDFLAGS = -L/opt/homebrew/lib -lgmp DEPS_HPP = circom.hpp calcwit.hpp fr.hpp pol.cpp diff --git a/.github/resources/gmp_patch.macos.hpp b/.github/resources/witness-generator/macos.gmp_patch.hpp similarity index 100% rename from .github/resources/gmp_patch.macos.hpp rename to .github/resources/witness-generator/macos.gmp_patch.hpp index ff06356..53ff683 100644 --- a/.github/resources/gmp_patch.macos.hpp +++ b/.github/resources/witness-generator/macos.gmp_patch.hpp @@ -1,13 +1,13 @@ +// Workaround for a known macOS issue where certain GMP functions fail to compile +// due to strict type checking, despite uint64_t and mp_limb_t being the same size. +// These wrappers explicitly cast uint64_t parameters to mp_limb_t to resolve the mismatch. + #ifndef GMP_PATCH_CAST_HPP #define GMP_PATCH_CAST_HPP #include #include -// Workaround for a known macOS issue where certain GMP functions fail to compile -// due to strict type checking, despite uint64_t and mp_limb_t being the same size. -// These wrappers explicitly cast uint64_t parameters to mp_limb_t to resolve the mismatch. - // Arithmetic Wrappers inline mp_limb_t gmp_add_n_cast(uint64_t* rp, const uint64_t* up, const uint64_t* vp, mp_size_t n) { return mpn_add_n(reinterpret_cast(rp), diff --git a/.github/resources/Makefile.windows b/.github/resources/witness-generator/windows.Makefile similarity index 100% rename from .github/resources/Makefile.windows rename to .github/resources/witness-generator/windows.Makefile diff --git a/.github/workflows/build-circuits.yml b/.github/workflows/build-circuits.yml new file mode 100644 index 0000000..23dfdf5 --- /dev/null +++ b/.github/workflows/build-circuits.yml @@ -0,0 +1,421 @@ +name: Build Circuits + +on: + push: + branches: + - main + tags: + - "v*.*.*" + workflow_dispatch: + inputs: + version: + description: "Version to release. Must follow the format of 'vX.Y.Z'." + required: true + pull_request: # For testing purposes + +jobs: + setup: + name: Configure Environment + runs-on: ubuntu-latest + outputs: + version: ${{ steps.define-version.outputs.version }} + steps: + - name: Define version + id: define-version + env: + # Use the tag name if it is available, otherwise use the input version. + # If neither is available, default to the commit hash. + VERSION: ${{ github.event.release.tag_name || inputs.version }} + run: | + if [ -z "$VERSION" ]; then + echo "No version tag found. Defaulting to commit hash." + VERSION=$GITHUB_SHA + elif [[ ! "$VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "VERSION must follow the format of 'vX.Y.Z'. Value: '$VERSION'." + exit 1 + fi + + # Export the version to be used in the following jobs. + echo "version=$VERSION" >> $GITHUB_OUTPUT + + build-linux: + name: Build Linux Binaries (Native) + runs-on: ubuntu-latest + needs: + - setup + env: + VERSION: ${{ needs.setup.outputs.version }} + OS: linux + ARCH: x86_64 + steps: + - name: Install Rust Toolchain + uses: actions-rust-lang/setup-rust-toolchain@fb51252c7ba57d633bc668f941da052e410add48 + with: + toolchain: stable + cache: false + + - name: Install Circom + run: | + git clone https://github.com/iden3/circom.git + cd circom + RUSTFLAGS="-A dead_code" cargo build --release + RUSTFLAGS="-A dead_code" cargo install --path circom + circom --version + + - name: Checkout + uses: actions/checkout@8edcb1bdb4e267140fa742c62e395cd74f332709 + with: + path: repo + + - name: Initialise Submodules + working-directory: repo + run: git submodule update --init --recursive + + - name: Setup Dependencies + working-directory: repo/circom_circuits/rapidsnark + run: sudo apt update -y + + - name: Install Dependencies [Prover] + run: sudo apt install -y build-essential cmake libgmp-dev libsodium-dev nasm curl m4 + + - name: Install Dependencies [Witness Generator] + run: sudo apt install nlohmann-json3-dev + + - name: Compile Prover + working-directory: repo/circom_circuits/rapidsnark + run: | + ./build_gmp.sh host + make host + + - name: Generate Witness Generator's C++ Circuit + working-directory: repo/circom_circuits/Mantle + run: circom --c --r1cs --no_asm --O2 pol.circom + + - name: Compile Witness Generator + working-directory: repo/circom_circuits/Mantle/pol_cpp + run: make pol + + - name: Bundle + working-directory: repo + env: + BUNDLE_NAME: circom_circuits-${{ env.OS }}-${{ env.ARCH }} + WITNESS_GENERATOR_DIR: circom_circuits/Mantle/pol_cpp + RAPIDSNARK_DIR: circom_circuits/rapidsnark/package + run: | + BUNDLE_DIR_WITNESS_GENERATOR="${BUNDLE_NAME}/witness-generator" + BUNDLE_DIR_RAPIDSNARK="${BUNDLE_NAME}/rapidsnark" + + mkdir -p "$BUNDLE_DIR_WITNESS_GENERATOR" "$BUNDLE_DIR_RAPIDSNARK" + + mv "${WITNESS_GENERATOR_DIR}/pol" "$BUNDLE_DIR_WITNESS_GENERATOR/" + mv "${WITNESS_GENERATOR_DIR}/pol.dat" "$BUNDLE_DIR_WITNESS_GENERATOR/" + + mv "${RAPIDSNARK_DIR}"/bin/{prover,verifier} "$BUNDLE_DIR_RAPIDSNARK/" + + tar -czf "${BUNDLE_NAME}.tar.gz" "${BUNDLE_NAME}" + + - name: Upload Bundle + uses: actions/upload-artifact@de65e23aa2b7e23d713bb51fbfcb6d502f8667d8 + with: + name: circom_circuits-${{ env.OS }}-${{ env.ARCH }}.tar.gz + path: repo/circom_circuits-${{ env.OS }}-${{ env.ARCH }}.tar.gz + + build-windows: + name: Build Windows Binaries (Native) + runs-on: windows-latest + needs: + - setup + env: + VERSION: ${{ needs.setup.outputs.version }} + OS: windows + ARCH: x86_64 + steps: + - name: Setup MSYS2 + uses: msys2/setup-msys2@v2.28.0 # FIXME: Ideally use the hash to avoid supply chain attacks. Currently unable to. + with: + update: true + install: >- + base-devel + mingw-w64-x86_64-toolchain + make + git + + - name: Install Rust Toolchain + uses: actions-rust-lang/setup-rust-toolchain@fb51252c7ba57d633bc668f941da052e410add48 + with: + toolchain: stable + cache: false + + - name: Install Circom + run: | + git clone https://github.com/iden3/circom.git + cd circom + $env:RUSTFLAGS="-A dead_code"; cargo build --release + $env:RUSTFLAGS="-A dead_code"; cargo install --path circom + circom --version + + - name: Checkout + uses: actions/checkout@8edcb1bdb4e267140fa742c62e395cd74f332709 + with: + path: repo + + - name: Initialise Submodules + working-directory: repo + run: git submodule update --init --recursive + + - name: Install Dependencies [Witness Generator] + shell: msys2 {0} + run: | + # nlohmann/json + mkdir -p /include/nlohmann/ + wget -O /include/nlohmann/json.hpp https://github.com/nlohmann/json/releases/download/v3.12.0/json.hpp + + # mman-win32 + git clone https://github.com/alitrack/mman-win32.git + pushd mman-win32 + ./configure --prefix= # Path: / + make + make install + popd + + - name: Install Dependencies [Prover] + shell: msys2 {0} + run: pacman --noconfirm -Sy --needed cmake nasm mingw-w64-ucrt-x86_64-libsodium + + - name: Replace Prover Makefile # TODO: Make a fork generate the appropriate Windows Makefile + shell: msys2 {0} + working-directory: repo + run: cp .github/resources/prover/${{ env.OS }}.Makefile circom_circuits/rapidsnark/Makefile + + - name: Replace Prover CMakeLists + shell: msys2 {0} + working-directory: repo + run: cp .github/resources/prover/${{ env.OS }}.src-CMakeLists.txt circom_circuits/rapidsnark/src/CMakeLists.txt + + - name: Patch Windows mman + shell: msys2 {0} + working-directory: repo + run: cp .github/resources/prover/${{ env.OS }}.mman_patch.hpp /include/mman_patch.hpp + + - name: Add uio.h headers + shell: msys2 {0} + working-directory: repo + run: cp .github/resources/prover/${{ env.OS }}.uio.h /include/sys/uio.h + + - name: Replace build_gmp + shell: msys2 {0} + working-directory: repo + run: cp .github/resources/prover/${{ env.OS }}.build_gmp.sh circom_circuits/rapidsnark/build_gmp.sh + + - name: Compile Prover + shell: msys2 {0} + working-directory: repo/circom_circuits/rapidsnark + run: | + ./build_gmp.sh host + make host_windows_x86_64 + + - name: Generate Witness Generator's C++ Circuit + working-directory: repo/circom_circuits/Mantle + run: circom --c --r1cs --no_asm pol.circom + + - name: Replace Witness Generator Makefile # TODO: Make a fork generate the appropriate Windows Makefile + working-directory: repo + shell: msys2 {0} + run: cp .github/resources/witness-generator/${{ env.OS }}.Makefile circom_circuits/Mantle/pol_cpp/Makefile + + - name: Compile Witness Generator + shell: msys2 {0} + working-directory: repo/circom_circuits/Mantle/pol_cpp + run: make pol.exe + + - name: Bundle + working-directory: repo + shell: msys2 {0} + env: + BUNDLE_NAME: circom_circuits-${{ env.OS }}-${{ env.ARCH }} + WITNESS_GENERATOR_DIR: circom_circuits/Mantle/pol_cpp + RAPIDSNARK_DIR: circom_circuits/rapidsnark/package + run: | + BUNDLE_DIR_WITNESS_GENERATOR="${BUNDLE_NAME}/witness-generator" + BUNDLE_DIR_RAPIDSNARK="${BUNDLE_NAME}/rapidsnark" + MINGW_BASE_DIR="/${MSYSTEM,,}" + MINGW_DLL_DIR="$MINGW_BASE_DIR/bin" + + mkdir -p "$BUNDLE_DIR_WITNESS_GENERATOR" "$BUNDLE_DIR_RAPIDSNARK" + + cp "$MINGW_DLL_DIR"/{libgcc_s_seh-1.dll,libwinpthread-1.dll,libstdc++-6.dll,libgmp-10.dll} "$BUNDLE_DIR_WITNESS_GENERATOR/" + mv "${WITNESS_GENERATOR_DIR}/pol" "$BUNDLE_DIR_WITNESS_GENERATOR/pol.exe" + mv "${WITNESS_GENERATOR_DIR}/pol.dat" "$BUNDLE_DIR_WITNESS_GENERATOR/pol.exe.dat" + + cp "$MINGW_DLL_DIR"/{libgcc_s_seh-1.dll,libwinpthread-1.dll,libstdc++-6.dll} "$BUNDLE_DIR_RAPIDSNARK/" + mv "${RAPIDSNARK_DIR}"/bin/{prover.exe,verifier.exe} "$BUNDLE_DIR_RAPIDSNARK/" + + tar -czf "${BUNDLE_NAME}.tar.gz" "${BUNDLE_NAME}" + + - name: Upload Bundle + uses: actions/upload-artifact@de65e23aa2b7e23d713bb51fbfcb6d502f8667d8 + with: + name: circom_circuits-${{ env.OS }}-${{ env.ARCH }}.tar.gz + path: repo/circom_circuits-${{ env.OS }}-${{ env.ARCH }}.tar.gz + + build-macos: + name: Build MacOS Binaries (Native) + runs-on: macos-latest + needs: + - setup + env: + VERSION: ${{ needs.setup.outputs.version }} + ARCH: arm64 + OS: macos + steps: + - name: Install Rust Toolchain + uses: actions-rust-lang/setup-rust-toolchain@fb51252c7ba57d633bc668f941da052e410add48 + with: + toolchain: stable + cache: false + + - name: Install Circom + run: | + git clone https://github.com/iden3/circom.git + cd circom + RUSTFLAGS="-A dead_code" cargo build --release + RUSTFLAGS="-A dead_code" cargo install --path circom + circom --version + + - name: Checkout + uses: actions/checkout@8edcb1bdb4e267140fa742c62e395cd74f332709 + with: + path: repo + + - name: Initialise Submodules + working-directory: repo + run: git submodule update --init --recursive + + - name: Setup Dependencies + run: mkdir include + + - name: Install Dependencies [Witness Generator] + run: brew install nlohmann-json + + - name: Install Dependencies [Prover] + run: brew install cmake nasm m4 + + - name: Compile Prover + working-directory: repo/circom_circuits/rapidsnark + run: | + ./build_gmp.sh macos_arm64 + make macos_arm64 + + - name: Generate Witness Generator's C++ Circuit + working-directory: repo/circom_circuits/Mantle + run: circom --c --r1cs --no_asm --O2 pol.circom + + - name: Replace Witness Generator's Makefile # TODO: Make a fork generate the appropriate MacOS Makefile + working-directory: repo + run: cp .github/resources/witness-generator/${{ env.OS }}.Makefile circom_circuits/Mantle/pol_cpp/Makefile + + - name: Patch MacOS GMP # TODO: Maybe not needed? + working-directory: repo + run: cp .github/resources/witness-generator/${{ env.OS }}.gmp_patch.hpp circom_circuits/Mantle/pol_cpp/gmp_patch.hpp + + - name: Compile Witness Generator + working-directory: repo/circom_circuits/Mantle/pol_cpp + run: make pol + + - name: Bundle + working-directory: repo + env: + BUNDLE_NAME: circom_circuits-${{ env.OS }}-${{ env.ARCH }} + WITNESS_GENERATOR_DIR: circom_circuits/Mantle/pol_cpp + RAPIDSNARK_DIR: circom_circuits/rapidsnark/package_macos_arm64 + run: | + BUNDLE_DIR_WITNESS_GENERATOR="${BUNDLE_NAME}/witness-generator" + BUNDLE_DIR_RAPIDSNARK="${BUNDLE_NAME}/rapidsnark" + + mkdir -p "$BUNDLE_DIR_WITNESS_GENERATOR" "$BUNDLE_DIR_RAPIDSNARK" + + mv "${WITNESS_GENERATOR_DIR}/pol" "$BUNDLE_DIR_WITNESS_GENERATOR/" + mv "${WITNESS_GENERATOR_DIR}/pol.dat" "$BUNDLE_DIR_WITNESS_GENERATOR/" + + mv "${RAPIDSNARK_DIR}"/bin/{prover,verifier} "$BUNDLE_DIR_RAPIDSNARK/" + + tar -czf "${BUNDLE_NAME}.tar.gz" "${BUNDLE_NAME}" + + - name: Upload Bundle + uses: actions/upload-artifact@de65e23aa2b7e23d713bb51fbfcb6d502f8667d8 + with: + name: circom_circuits-${{ env.OS }}-${{ env.ARCH }}.tar.gz + path: repo/circom_circuits-${{ env.OS }}-${{ env.ARCH }}.tar.gz + + publish-release: + name: Create Release + runs-on: ubuntu-latest + needs: + - setup + - build-linux + - build-windows + - build-macos + env: + VERSION: ${{ needs.setup.outputs.version }} + outputs: + upload_url: ${{ steps.create_release.outputs.upload_url }} + steps: + - name: Create Release + uses: actions/create-release@4c11c9fe1dcd9636620a16455165783b20fc7ea0 + id: create_release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ env.VERSION }} + release_name: Circom Circuits ${{ env.VERSION }} + body: | + This is a release of Circom Circuits ${{ env.VERSION }}. + ## Changelog + - feature(X): new feature + - fix(Y): bug description + - feature: performance improvement on Z + ## Checklist + Before publishing please ensure: + - [ ] Description is complete + - [ ] Changelog is correct + - [ ] Assets for all platforms exist + - [ ] Pre-release is checked if necessary + - [ ] Remove this checklist before publishing the release. + draft: true + prerelease: true + + upload-artifacts: + name: Upload Artifacts to Release + runs-on: ubuntu-latest + needs: + - setup + - publish-release + strategy: + fail-fast: false + matrix: + platform: + - os: linux + arch: x86_64 + - os: macos + arch: arm64 + - os: windows + arch: x86_64 + env: + VERSION: ${{ needs.setup.outputs.version }} + UPLOAD_URL: ${{ needs.publish-release.outputs.upload_url }} + ARTIFACT_NAME: circom_circuits-${{ matrix.platform.os }}-${{ matrix.platform.arch }}.tar.gz + steps: + - name: Download Artifacts + uses: actions/download-artifact@448e3f862ab3ef47aa50ff917776823c9946035b + with: + name: ${{ env.ARTIFACT_NAME }} + + - name: Upload Artifacts to Release + uses: actions/upload-release-asset@ef2adfe8cb8ebfa540930c452c576b3819990faa + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ env.UPLOAD_URL }} + asset_path: ${{ env.ARTIFACT_NAME }} + asset_name: ${{ env.ARTIFACT_NAME }} + asset_content_type: application/octet-stream diff --git a/.github/workflows/build-witness-generator.yml b/.github/workflows/build-witness-generator.yml deleted file mode 100644 index 8b85655..0000000 --- a/.github/workflows/build-witness-generator.yml +++ /dev/null @@ -1,328 +0,0 @@ -name: Build Witness Generator - -on: - push: - branches: - - main - tags: - - "v*.*.*" - workflow_dispatch: - inputs: - version: - description: "Version to release. Must follow the format of 'vX.Y.Z'." - required: true - pull_request: # For testing purposes - -jobs: - setup: - name: Define variables and configure environment - runs-on: ubuntu-latest - outputs: - version: ${{ steps.define-version.outputs.version }} - steps: - - name: Define version - id: define-version - env: - # Use the tag name if it is available, otherwise use the input version. - # If neither is available, default to the commit hash. - VERSION: ${{ github.event.release.tag_name || inputs.version }} - run: | - if [ -z "$VERSION" ]; then - echo "No version tag found. Defaulting to commit hash." - VERSION=$GITHUB_SHA - elif [[ ! "$VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then - echo "VERSION must follow the format of 'vX.Y.Z'. Value: '$VERSION'." - exit 1 - fi - - # Export the version to be used in the following jobs. - echo "version=$VERSION" >> $GITHUB_OUTPUT - - build-linux-native: - name: Build Linux Binary (Native) - runs-on: ubuntu-latest - needs: - - setup - env: - VERSION: ${{ needs.setup.outputs.version }} - OS: linux - ARCH: x86_64 - steps: - - name: Install Rust Toolchain - uses: actions-rust-lang/setup-rust-toolchain@v1 - with: - toolchain: stable - cache: false - - - name: Install Circom - run: | - git clone https://github.com/iden3/circom.git - cd circom - RUSTFLAGS="-A dead_code" cargo build --release - RUSTFLAGS="-A dead_code" cargo install --path circom - circom --version - - - name: Checkout - uses: actions/checkout@v4 - with: - path: repo - - - name: Initialise Submodules - working-directory: repo - run: git submodule update --init --recursive - - - name: Generate C++ Circuit - working-directory: repo/circom_circuits/Mantle - run: circom --c --r1cs --no_asm --O2 pol.circom - - - name: Dependencies - Setup - run: | - sudo apt update - - - name: Dependencies - Install [nlohmann/json] - run: sudo apt install nlohmann-json3-dev - - - name: Compile Circuit - working-directory: repo/circom_circuits/Mantle/pol_cpp - run: make pol - - - name: Bundle - working-directory: repo/circom_circuits/Mantle/pol_cpp - run: tar -czf pol-linux-${{ env.ARCH }}.tar.gz pol pol.dat - - - name: Upload Binary - uses: actions/upload-artifact@v4 - with: - name: pol-${{ env.OS }}-${{ env.ARCH }}.tar.gz - path: repo/circom_circuits/Mantle/pol_cpp/pol-${{ env.OS }}-${{ env.ARCH }}.tar.gz - - build-windows-native: - name: Build Windows Binary (Native) - runs-on: windows-latest - needs: - - setup - env: - VERSION: ${{ needs.setup.outputs.version }} - OS: windows - ARCH: x86_64 - steps: - - name: Setup MSYS2 - uses: msys2/setup-msys2@v2 - with: - update: true - install: >- - base-devel - mingw-w64-x86_64-toolchain - make - git - - - name: Install Rust Toolchain - uses: actions-rust-lang/setup-rust-toolchain@v1 - with: - toolchain: stable - cache: false - - - name: Install Circom - run: | - git clone https://github.com/iden3/circom.git - cd circom - $env:RUSTFLAGS="-A dead_code"; cargo build --release - $env:RUSTFLAGS="-A dead_code"; cargo install --path circom - circom --version - - - name: Checkout - uses: actions/checkout@v4 - with: - path: repo - - - name: Initialise Submodules - working-directory: repo - run: git submodule update --init --recursive - - - name: Generate C++ Circuit - working-directory: repo/circom_circuits/Mantle - run: circom --c --r1cs --no_asm --O2 pol.circom - - - name: Dependencies - Setup - shell: msys2 {0} - run: mkdir /include - - - name: Dependencies - Install [mman-win32] - shell: msys2 {0} - run: | - git clone https://github.com/alitrack/mman-win32.git - cd mman-win32 - pwd - ./configure --prefix= # Path: / - make - make install - - - name: Dependencies - Install [nlohmann/json] - shell: msys2 {0} - run: | - mkdir -p /include/nlohmann/ - wget -O /include/nlohmann/json.hpp https://github.com/nlohmann/json/releases/download/v3.12.0/json.hpp - - - name: Replace pol Makefile # TODO: Make a fork generate the appropriate Windows Makefile - working-directory: repo - shell: msys2 {0} - run: cp .github/resources/Makefile.${{ env.OS }} circom_circuits/Mantle/pol_cpp/Makefile - - - name: Compile Circuit - shell: msys2 {0} - working-directory: repo/circom_circuits/Mantle/pol_cpp - run: make pol.exe - - - name: Bundle - shell: msys2 {0} - working-directory: repo/circom_circuits/Mantle/pol_cpp - run: | - MINGW_BASE_DIR="/${MSYSTEM,,}" # converts to lowercase, e.g., MINGW64 -> mingw64 - MINGW_DLL_DIR="$MINGW_BASE_DIR/bin" - cp "$MINGW_DLL_DIR"/{libgcc_s_seh-1.dll,libgmp-10.dll,libwinpthread-1.dll,libstdc++-6.dll} . - mv pol.dat pol.exe.dat - tar -czf pol-${{ env.OS }}-${{ env.ARCH }}.tar.gz pol.exe pol.exe.dat *.dll - - - name: Upload Binary - uses: actions/upload-artifact@v4 - with: - name: pol-${{ env.OS }}-${{ env.ARCH }}.tar.gz - path: repo/circom_circuits/Mantle/pol_cpp/pol-${{ env.OS }}-${{ env.ARCH }}.tar.gz - - build-macos-native: - name: Build MacOS Binary (Native) - runs-on: macos-latest - needs: - - setup - env: - VERSION: ${{ needs.setup.outputs.version }} - ARCH: arm64 - OS: macos - steps: - - name: Install Rust Toolchain - uses: actions-rust-lang/setup-rust-toolchain@v1 - with: - toolchain: stable - cache: false - - - name: Install Circom - run: | - git clone https://github.com/iden3/circom.git - cd circom - RUSTFLAGS="-A dead_code" cargo build --release - RUSTFLAGS="-A dead_code" cargo install --path circom - circom --version - - - name: Checkout - uses: actions/checkout@v4 - with: - path: repo - - - name: Initialise Submodules - working-directory: repo - run: git submodule update --init --recursive - - - name: Generate C++ Circuit - working-directory: repo/circom_circuits/Mantle - run: circom --c --r1cs --no_asm --O2 pol.circom - - - name: Dependencies - Setup - run: mkdir include - - - name: Dependencies - Install [nlohmann/json] - run: brew install nlohmann-json - - - name: Replace pol Makefile # TODO: Make a fork generate the appropriate MacOS Makefile - working-directory: repo - run: cp .github/resources/Makefile.${{ env.OS }} circom_circuits/Mantle/pol_cpp/Makefile - - - name: Patch MacOS GMP - working-directory: repo - run: cp .github/resources/gmp_patch.${{ env.OS }}.hpp circom_circuits/Mantle/pol_cpp/gmp_patch.${{ env.OS }}.hpp - - - name: Compile Circuit - working-directory: repo/circom_circuits/Mantle/pol_cpp - run: make pol - - - name: Bundle - working-directory: repo/circom_circuits/Mantle/pol_cpp - run: tar -czf pol-${{ env.OS }}-${{ env.ARCH }}.tar.gz pol pol.dat - - - name: Upload Binary - uses: actions/upload-artifact@v4 - with: - name: pol-${{ env.OS }}-${{ env.ARCH }}.tar.gz - path: repo/circom_circuits/Mantle/pol_cpp/pol-${{ env.OS }}-${{ env.ARCH }}.tar.gz - - publish-release: - name: Create Release - runs-on: ubuntu-latest - needs: - - setup - - build-linux-native - - build-windows-native - - build-macos-native - env: - VERSION: ${{ needs.setup.outputs.version }} - outputs: - upload_url: ${{ steps.create_release.outputs.upload_url }} - steps: - - name: Create Release - uses: actions/create-release@v1 - id: create_release - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - tag_name: ${{ env.VERSION }} - release_name: PoL Witness Generator ${{ env.VERSION }} - body: | - This is a release of PoL Witness Generator ${{ env.VERSION }}. - ## Changelog - - feature(X): new feature - - fix(Y): bug description - - feature: performance improvement on Z - ## Checklist - Before publishing please ensure: - - [ ] Description is complete - - [ ] Changelog is correct - - [ ] Assets for all platforms exist - - [ ] Pre-release is checked if necessary - - [ ] Remove this checklist before publishing the release. - draft: true - prerelease: true - - upload-artifacts: - name: Upload Artifacts to Release - runs-on: ubuntu-latest - needs: - - setup - - publish-release - strategy: - fail-fast: false - matrix: - platform: - - os: linux - arch: x86_64 - - os: macos - arch: arm64 - - os: windows - arch: x86_64 - env: - VERSION: ${{ needs.setup.outputs.version }} - UPLOAD_URL: ${{ needs.publish-release.outputs.upload_url }} - ARTIFACT_NAME: pol-${{ matrix.platform.os }}-${{ matrix.platform.arch }}.tar.gz - steps: - - name: Download Artifacts - uses: actions/download-artifact@v4 - with: - name: ${{ env.ARTIFACT_NAME }} - - - name: Upload Artifacts to Release - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ env.UPLOAD_URL }} - asset_path: ${{ env.ARTIFACT_NAME }} - asset_name: ${{ env.ARTIFACT_NAME }} - asset_content_type: application/octet-stream diff --git a/.gitmodules b/.gitmodules index e9845e6..f4b938b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "circomlib"] path = circom_circuits/circomlib url = https://github.com/iden3/circomlib.git +[submodule "circom_circuits/rapidsnark"] + path = circom_circuits/rapidsnark + url = https://github.com/iden3/rapidsnark diff --git a/circom_circuits/rapidsnark b/circom_circuits/rapidsnark new file mode 160000 index 0000000..9983837 --- /dev/null +++ b/circom_circuits/rapidsnark @@ -0,0 +1 @@ +Subproject commit 998383787ee86bcb6bfb8741e9a638d203c08eae