Skip to content

Commit

Permalink
Merge pull request #156 from skalenetwork/feature/SKALE-4510-compile-…
Browse files Browse the repository at this point in the history
…with-emscripten

Feature/skale 4510 compile with emscripten
  • Loading branch information
olehnikolaiev authored Oct 13, 2021
2 parents e9b70e2 + 15bc88e commit 5886f8c
Show file tree
Hide file tree
Showing 29 changed files with 628 additions and 79 deletions.
75 changes: 73 additions & 2 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
run: |
sudo apt-get update
sudo apt-get install g++-7 clang-format-6.0 gawk sed shtool \
libffi-dev yasm texinfo flex bison libc6-dbg
libffi-dev yasm texinfo flex bison libc6-dbg gcc-multilib
sudo snap install valgrind --classic
python -m pip install --upgrade pip
pip install coincurve
Expand Down Expand Up @@ -81,4 +81,75 @@ jobs:
- name: Run tools tests
run: |
./scripts/run_tools_test.sh
linux_build_with_emscripten:
runs-on: ubuntu-18.04

strategy:
matrix:
node-version: [14.x]

steps:
- name: Extract repo name
run: echo ::set-env name=REPOSITORY_NAME::$(echo "$GITHUB_REPOSITORY" | awk -F / '{print $2}')
shell: bash
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
- name: Checkout
uses: actions/checkout@v2
- name: Update apt
run: sudo add-apt-repository ppa:ubuntu-toolchain-r/test;
- name: Install packages
run: |
sudo apt-get update
sudo apt-get install g++-7 clang-format-6.0 gawk sed shtool \
libffi-dev yasm texinfo flex bison \
python3.6 lcov gcc-multilib
sudo apt-get update -qq
sudo apt install python3-pip
pip3 install --upgrade pip
sudo python3.6 -m pip install --upgrade pip
sudo python3.6 -m pip install pyopenssl ndg-httpsclient pyasn1
sudo python3.6 -m pip install requests[security]
sudo python3.6 -m pip install codecov --ignore-installed
- name: Install NODE JS
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}

- name: Build dependencies
run: |
export CC=gcc-7
export CXX=g++-7
export TARGET=all
export CMAKE_BUILD_FLAGS="-DCOVERAGE=ON"
cd deps
./build.sh WITH_EMSCRIPTEN=1
cd ..
- name: Build all
run: |
cd deps/emsdk
./emsdk install latest
./emsdk activate latest
source ./emsdk_env.sh
cd ../..
mkdir -p build_em
cd build_em
export LIBRARIES_ROOT=../deps/deps_inst/x86_or_x64/lib
emcmake cmake -DEMSCRIPTEN=ON .. -DGMP_LIBRARY="$LIBRARIES_ROOT"/libgmp.a -DCRYPTOPP_LIBRARY="$LIBRARIES_ROOT"/libcrypto.a -DGMPXX_LIBRARY="$LIBRARIES_ROOT"/libgmpxx.a
emmake make -j$(nproc)
cd ..
- name: Run tests
run: |
cp tools/generate_bls_keys build_em/
cp tools/decrypt_message build_em/
cd build_em/
cp threshold_encryption/encrypt_message.* .
./generate_bls_keys
MESSAGE=`cat message.txt`
PUBLIC_BLS_KEY=`cat bls_public_key.txt`
node encrypt_message.js $MESSAGE $PUBLIC_BLS_KEY > encrypted_data.txt
./decrypt_message
3 changes: 1 addition & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ jobs:
run: |
sudo apt-get update
sudo apt-get install g++-7 clang-format-6.0 gawk sed shtool \
libffi-dev yasm texinfo flex bison
libffi-dev yasm texinfo flex bison gcc-multilib
- name: Build dependencies
run: |
export CC=gcc-7
Expand Down
78 changes: 75 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ defaults:
run:
shell: bash
jobs:
build_linux:
linux_build_and_test:
runs-on: ubuntu-18.04

steps:
Expand All @@ -28,7 +28,7 @@ jobs:
sudo apt-get update
sudo apt-get install g++-7 clang-format-6.0 gawk sed shtool \
libffi-dev yasm texinfo flex bison \
python3.6 lcov
python3.6 lcov gcc-multilib
sudo apt-get update -qq
sudo apt install python3-pip
pip3 install --upgrade pip
Expand Down Expand Up @@ -91,7 +91,7 @@ jobs:
# Uploading report to CodeCov
bash <(curl -s https://codecov.io/bash) -f coverage.info -t $CODECOV_TOKEN || echo "Codecov did not collect coverage reports"
build_osx:
osx_build_and_test:
runs-on: macos-11

steps:
Expand Down Expand Up @@ -127,3 +127,75 @@ jobs:
./threshold_encryption/te_unit_test
./threshold_encryption/te_test
./dkg_attack
linux_build_with_emscripten:
runs-on: ubuntu-18.04

strategy:
matrix:
node-version: [14.x]

steps:
- name: Extract repo name
run: echo ::set-env name=REPOSITORY_NAME::$(echo "$GITHUB_REPOSITORY" | awk -F / '{print $2}')
shell: bash
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
- name: Checkout
uses: actions/checkout@v2
- name: Update apt
run: sudo add-apt-repository ppa:ubuntu-toolchain-r/test;
- name: Install packages
run: |
sudo apt-get update
sudo apt-get install g++-7 clang-format-6.0 gawk sed shtool \
libffi-dev yasm texinfo flex bison \
python3.6 lcov gcc-multilib
sudo apt-get update -qq
sudo apt install python3-pip
pip3 install --upgrade pip
sudo python3.6 -m pip install --upgrade pip
sudo python3.6 -m pip install pyopenssl ndg-httpsclient pyasn1
sudo python3.6 -m pip install requests[security]
sudo python3.6 -m pip install codecov --ignore-installed
- name: Install NODE JS
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}

- name: Build dependencies
run: |
export CC=gcc-7
export CXX=g++-7
export TARGET=all
export CMAKE_BUILD_FLAGS="-DCOVERAGE=ON"
cd deps
./build.sh WITH_EMSCRIPTEN=1
cd ..
- name: Build all
run: |
cd deps/emsdk
./emsdk install latest
./emsdk activate latest
source ./emsdk_env.sh
cd ../..
mkdir -p build_em
cd build_em
export LIBRARIES_ROOT=../deps/deps_inst/x86_or_x64/lib
emcmake cmake -DEMSCRIPTEN=ON .. -DGMP_LIBRARY="$LIBRARIES_ROOT"/libgmp.a -DCRYPTOPP_LIBRARY="$LIBRARIES_ROOT"/libcrypto.a -DGMPXX_LIBRARY="$LIBRARIES_ROOT"/libgmpxx.a
emmake make -j$(nproc)
cd ..
- name: Run tests
run: |
cp tools/generate_bls_keys build_em/
cp tools/decrypt_message build_em/
cd build_em/
cp threshold_encryption/encrypt_message.* .
./generate_bls_keys
MESSAGE=`cat message.txt`
PUBLIC_BLS_KEY=`cat bls_public_key.txt`
node encrypt_message.js $MESSAGE $PUBLIC_BLS_KEY > encrypted_data.txt
./decrypt_message
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ deps/*
saved_environment_on_startup.txt
test/dkgpython.so
test/test_sgx.py
qt_build/
qt_build/
node/node_modules
89 changes: 70 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ endif()
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
message(STATUS "*** Have SIZEOF void * = 8, so 64-bit")
else ()
message(FATAL_ERROR "*** SIZEOF void * != 8, so not 64-bit - libBLS supports only 64-bit")
if (EMSCRIPTEN)
message(STATUS "*** SIZEOF void * = 4, while building with emscripten ")
else()
message(FATAL_ERROR "*** SIZEOF void * != 8, so not 64-bit - libBLS supports only 64-bit")
endif()
endif ()

if( NOT DEFINED DEPS_INSTALL_ROOT )
Expand All @@ -31,7 +35,7 @@ list( APPEND CMAKE_MODULE_PATH ${LIBBLS_CMAKE_DIR} )

find_library( GMP_LIBRARY NAMES "gmp" PATHS "${DEPS_INSTALL_ROOT}/lib" )
find_library( GMPXX_LIBRARY NAMES "gmpxx" PATHS "${DEPS_INSTALL_ROOT}/lib" )
find_library( CRYPTOPP NAMES "crypto" PATHS "${DEPS_INSTALL_ROOT}/lib" )
find_library( CRYPTOPP_LIBRARY NAMES "crypto" PATHS "${DEPS_INSTALL_ROOT}/lib" )

set( HUNTER_ENABLED OFF )

Expand Down Expand Up @@ -107,7 +111,11 @@ add_definitions(-DBLS_VERSION=${PROJECT_VERSION})
if ( APPLE )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wparentheses -Wunused -Wunreachable-code -Wextra -fPIC -std=c++17")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wall -Wparentheses -Wunused -Wunreachable-code -Wextra -Wno-error=int-in-bool-context -fPIC -std=c++17")
if (EMSCRIPTEN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -std=c++17")#-Werror -Wall -Wparentheses -Wunused -Wunreachable-code -Wextra -Wno-error=int-in-bool-context
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wall -Wparentheses -Wunused -Wunreachable-code -Wextra -Wno-error=int-in-bool-context -fPIC -std=c++17")
endif()
endif()

include_directories(${CMAKE_BINARY_DIR}/deps/include)
Expand All @@ -118,9 +126,9 @@ add_library(bls ${sourses_bls} ${headers_bls})
include_directories(${Boost_INCLUDE_DIRS})

if( SKALE_HAVE_BOOST_FROM_HUNTER )
set( BOOST_LIBS_4_BLS Boost::program_options )
set( BOOST_LIBS_4_BLS Boost::program_options )
else()
set( BOOST_LIBS_4_BLS boost_program_options )
set( BOOST_LIBS_4_BLS boost_program_options )
endif()

set (WITH_PROCPS OFF)
Expand All @@ -135,68 +143,111 @@ set(BLS_INCLUDE_DIRS
)

target_include_directories(bls PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(bls PRIVATE ff ${CRYPTOPP} ${GMPXX_LIBRARY} ${GMP_LIBRARY})
target_link_libraries(bls PRIVATE ff ${CRYPTOPP_LIBRARY} ${GMPXX_LIBRARY} ${GMP_LIBRARY})

add_subdirectory(threshold_encryption)

add_executable(dkg_keygen tools/dkg_key_gen.cpp)
target_include_directories(dkg_keygen PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
if (EMSCRIPTEN)
target_compile_options(dkg_keygen PRIVATE -s DISABLE_EXCEPTION_CATCHING=1)
set_target_properties(dkg_keygen PROPERTIES LINK_FLAGS "-s DISABLE_EXCEPTION_CATCHING=1")
endif()

target_link_libraries(dkg_keygen PRIVATE bls ${CRYPTOPP} ff ${GMPXX_LIBRARY} ${GMP_LIBRARY} ${BOOST_LIBS_4_BLS})
target_link_libraries(dkg_keygen PRIVATE bls ${CRYPTOPP_LIBRARY} ff ${GMPXX_LIBRARY} ${GMP_LIBRARY} ${BOOST_LIBS_4_BLS})

add_executable(dkg_glue tools/dkg_glue.cpp)
target_include_directories(dkg_glue PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(dkg_glue PRIVATE bls ${CRYPTOPP} ff ${GMPXX_LIBRARY} ${GMP_LIBRARY} ${BOOST_LIBS_4_BLS})
if (EMSCRIPTEN)
target_compile_options(dkg_glue PRIVATE -s DISABLE_EXCEPTION_CATCHING=1)
set_target_properties(dkg_glue PROPERTIES LINK_FLAGS "-s DISABLE_EXCEPTION_CATCHING=1")
endif()
target_link_libraries(dkg_glue PRIVATE bls ${CRYPTOPP_LIBRARY} ff ${GMPXX_LIBRARY} ${GMP_LIBRARY} ${BOOST_LIBS_4_BLS})

add_executable(sign_bls tools/sign_bls.cpp)
target_include_directories(sign_bls PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(sign_bls PRIVATE bls ${CRYPTOPP} ff ${GMPXX_LIBRARY} ${GMP_LIBRARY} ${BOOST_LIBS_4_BLS})
if (EMSCRIPTEN)
target_compile_options(sign_bls PRIVATE -s DISABLE_EXCEPTION_CATCHING=1)
set_target_properties(sign_bls PROPERTIES LINK_FLAGS "-s DISABLE_EXCEPTION_CATCHING=1")
endif()
target_link_libraries(sign_bls PRIVATE bls ${CRYPTOPP_LIBRARY} ff ${GMPXX_LIBRARY} ${GMP_LIBRARY} ${BOOST_LIBS_4_BLS})

add_executable(hash_g1 tools/hash_g1.cpp)
target_include_directories(hash_g1 PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(hash_g1 PRIVATE bls ${CRYPTOPP} ff ${GMPXX_LIBRARY} ${GMP_LIBRARY} ${BOOST_LIBS_4_BLS})
if (EMSCRIPTEN)
target_compile_options(hash_g1 PRIVATE -s DISABLE_EXCEPTION_CATCHING=1)
set_target_properties(hash_g1 PROPERTIES LINK_FLAGS "-s DISABLE_EXCEPTION_CATCHING=1")
endif()
target_link_libraries(hash_g1 PRIVATE bls ${CRYPTOPP_LIBRARY} ff ${GMPXX_LIBRARY} ${GMP_LIBRARY} ${BOOST_LIBS_4_BLS})

add_executable(bls_glue tools/bls_glue.cpp)
target_include_directories(bls_glue PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(bls_glue PRIVATE bls ${CRYPTOPP} ff ${GMPXX_LIBRARY} ${GMP_LIBRARY} ${BOOST_LIBS_4_BLS})
if (EMSCRIPTEN)
target_compile_options(bls_glue PRIVATE -s DISABLE_EXCEPTION_CATCHING=1)
set_target_properties(bls_glue PROPERTIES LINK_FLAGS "-s DISABLE_EXCEPTION_CATCHING=1")
endif()
target_link_libraries(bls_glue PRIVATE bls ${CRYPTOPP_LIBRARY} ff ${GMPXX_LIBRARY} ${GMP_LIBRARY} ${BOOST_LIBS_4_BLS})

add_executable(verify_bls tools/verify_bls.cpp)
target_include_directories(verify_bls PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(verify_bls PRIVATE bls ${CRYPTOPP} ff ${GMPXX_LIBRARY} ${GMP_LIBRARY} ${BOOST_LIBS_4_BLS})
if (EMSCRIPTEN)
target_compile_options(verify_bls PRIVATE -s DISABLE_EXCEPTION_CATCHING=1)
set_target_properties(verify_bls PROPERTIES LINK_FLAGS "-s DISABLE_EXCEPTION_CATCHING=1")
endif()
target_link_libraries(verify_bls PRIVATE bls ${CRYPTOPP_LIBRARY} ff ${GMPXX_LIBRARY} ${GMP_LIBRARY} ${BOOST_LIBS_4_BLS})

add_executable(generate_key_system tools/generate_key_system.cpp)
target_include_directories(generate_key_system PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(generate_key_system PRIVATE bls ${CRYPTOPP} ff ${GMPXX_LIBRARY} ${GMP_LIBRARY} ${BOOST_LIBS_4_BLS})

if (EMSCRIPTEN)
target_compile_options(generate_key_system PRIVATE -s DISABLE_EXCEPTION_CATCHING=1)
set_target_properties(generate_key_system PROPERTIES LINK_FLAGS "-s DISABLE_EXCEPTION_CATCHING=1")
endif()
target_link_libraries(generate_key_system PRIVATE bls ${CRYPTOPP_LIBRARY} ff ${GMPXX_LIBRARY} ${GMP_LIBRARY} ${BOOST_LIBS_4_BLS})

if(BUILD_TESTS)
add_executable(bls_unit_test test/unit_tests_bls.cpp)
target_include_directories(bls_unit_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(bls_unit_test PRIVATE bls ${CRYPTOPP} ff ${GMPXX_LIBRARY} ${GMP_LIBRARY} ${BOOST_LIBS_4_BLS})
if (EMSCRIPTEN)
target_compile_options(bls_unit_test PRIVATE -s DISABLE_EXCEPTION_CATCHING=1)
set_target_properties(bls_unit_test PROPERTIES LINK_FLAGS "-s DISABLE_EXCEPTION_CATCHING=1")
endif()
target_link_libraries(bls_unit_test PRIVATE bls ${CRYPTOPP_LIBRARY} ff ${GMPXX_LIBRARY} ${GMP_LIBRARY} ${BOOST_LIBS_4_BLS})

add_test(NAME bls_tests COMMAND bls_unit_test)

add_executable(dkg_unit_test test/unit_tests_dkg.cpp)
target_include_directories(dkg_unit_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(dkg_unit_test PRIVATE bls ${CRYPTOPP} ff ${GMP_LIBRARY} ${GMPXX_LIBRARY} ${BOOST_LIBS_4_BLS})
if (EMSCRIPTEN)
target_compile_options(dkg_unit_test PRIVATE -s DISABLE_EXCEPTION_CATCHING=1)
set_target_properties(dkg_unit_test PROPERTIES LINK_FLAGS "-s DISABLE_EXCEPTION_CATCHING=1")
endif()
target_link_libraries(dkg_unit_test PRIVATE bls ${CRYPTOPP_LIBRARY} ff ${GMP_LIBRARY} ${GMPXX_LIBRARY} ${BOOST_LIBS_4_BLS})

add_test(NAME dkg_tests COMMAND dkg_unit_test)

add_executable(bls_test test/test_bls.cpp)
target_include_directories(bls_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(bls_test PRIVATE bls ${CRYPTOPP} ff ${GMP_LIBRARY} ${GMPXX_LIBRARY} ${BOOST_LIBS_4_BLS})
if (EMSCRIPTEN)
target_compile_options(bls_test PRIVATE -s DISABLE_EXCEPTION_CATCHING=1)
set_target_properties(bls_test PROPERTIES LINK_FLAGS "-s DISABLE_EXCEPTION_CATCHING=1")
endif()
target_link_libraries(bls_test PRIVATE bls ${CRYPTOPP_LIBRARY} ff ${GMP_LIBRARY} ${GMPXX_LIBRARY} ${BOOST_LIBS_4_BLS})

add_test(NAME bls_test COMMAND bls_test)

add_executable(dkg_attack test/dkg_attack.cpp)
target_include_directories(dkg_attack PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(dkg_attack PRIVATE bls ${CRYPTOPP} ff ${GMP_LIBRARY} ${GMPXX_LIBRARY} ${BOOST_LIBS_4_BLS})
target_link_libraries(dkg_attack PRIVATE bls ${CRYPTOPP_LIBRARY} ff ${GMP_LIBRARY} ${GMPXX_LIBRARY} ${BOOST_LIBS_4_BLS})

add_test(NAME dkg_attack COMMAND dkg_attack)

add_executable(utils_unit_test test/unit_tests_utils.cpp)
target_include_directories(utils_unit_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(utils_unit_test PRIVATE bls te ${CRYPTOPP} ff ${GMPXX_LIBRARY} ${GMP_LIBRARY} ${BOOST_LIBS_4_BLS})
if (EMSCRIPTEN)
target_compile_options(utils_unit_test PRIVATE -s DISABLE_EXCEPTION_CATCHING=1)
set_target_properties(utils_unit_test PROPERTIES LINK_FLAGS "-s DISABLE_EXCEPTION_CATCHING=1")
endif()
target_link_libraries(utils_unit_test PRIVATE bls te ${CRYPTOPP_LIBRARY} ff ${GMPXX_LIBRARY} ${GMP_LIBRARY} ${BOOST_LIBS_4_BLS})

add_test(NAME utils_tests COMMAND utils_unit_test)

Expand Down
Loading

0 comments on commit 5886f8c

Please sign in to comment.