From b7b6cec55761b0c71f3e2c0c310223f571d84133 Mon Sep 17 00:00:00 2001 From: Zhengxuan Guo Date: Tue, 13 Aug 2024 16:37:48 +0800 Subject: [PATCH 01/12] init bandersnatch --- .gitignore | 73 ++++++++++++++++++++++ CMakeLists.txt | 5 ++ bandersnatch/CMakeLists.txt | 28 +++++++++ bandersnatch/bandersnatch/Bandersnatch.cpp | 4 ++ bandersnatch/bandersnatch/Bandersnatch.h | 5 ++ 5 files changed, 115 insertions(+) create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 bandersnatch/CMakeLists.txt create mode 100644 bandersnatch/bandersnatch/Bandersnatch.cpp create mode 100644 bandersnatch/bandersnatch/Bandersnatch.h diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8c9ab3e --- /dev/null +++ b/.gitignore @@ -0,0 +1,73 @@ +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app + +# java +*.class + + +# ignore some directory +build** +deps +deps/** + +# vs +*.sln +*.vcxproj* +.vs/ +.vscode/ +.idea/ + +# macOS +.DS_Store + +# log +*.log + +# python +*.pyc + +# vcpkg +vcpkg + +# clangd file +compile_commands.json +.cache + +# generated test +tools/BcosAirBuilder/nodes** +tools/BcosProBuilder/generated** +tools/BcosAirBuilder/* +*.log + +test/* +/CMakeSettings.json \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..9b9678b --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 3.10) + +project(verkle_tree) + +add_subdirectory(bandersnatch) diff --git a/bandersnatch/CMakeLists.txt b/bandersnatch/CMakeLists.txt new file mode 100644 index 0000000..f5507cf --- /dev/null +++ b/bandersnatch/CMakeLists.txt @@ -0,0 +1,28 @@ +cmake_minimum_required(VERSION 3.10) + +project(bandersnatch) + +include(ExternalProject) + +ExternalProject_Add( + blst + GIT_REPOSITORY https://github.com/supranational/blst.git + GIT_TAG 52cc60d78591a56abb2f3d0bd1cdafc6ba242997 + PREFIX ${CMAKE_BINARY_DIR}/blst + CONFIGURE_COMMAND "" + BUILD_COMMAND ${CMAKE_BINARY_DIR}/blst/src/blst/build.sh + BUILD_IN_SOURCE 0 + INSTALL_COMMAND "" +) + +ExternalProject_Get_Property(blst SOURCE_DIR) +ExternalProject_Get_Property(blst BINARY_DIR) +set(BLST_LIB ${BINARY_DIR}/libblst.a) +set(BLST_INCLUDE_DIR ${SOURCE_DIR}/bindings) + +include_directories(${BLST_INCLUDE_DIR}) + +add_library(bandersnatch bandersnatch/bandersnatch.cpp) + +add_dependencies(bandersnatch blst) +target_link_libraries(bandersnatch PRIVATE ${BLST_LIB}) \ No newline at end of file diff --git a/bandersnatch/bandersnatch/Bandersnatch.cpp b/bandersnatch/bandersnatch/Bandersnatch.cpp new file mode 100644 index 0000000..aef9fbc --- /dev/null +++ b/bandersnatch/bandersnatch/Bandersnatch.cpp @@ -0,0 +1,4 @@ +// +// Created by Zhengxuan Guo on 2024/8/12. +// +#include "Bandersnatch.h" \ No newline at end of file diff --git a/bandersnatch/bandersnatch/Bandersnatch.h b/bandersnatch/bandersnatch/Bandersnatch.h new file mode 100644 index 0000000..8c1e97b --- /dev/null +++ b/bandersnatch/bandersnatch/Bandersnatch.h @@ -0,0 +1,5 @@ +// +// Created by Zhengxuan Guo on 2024/8/12. +// +#pragma once +#include "blst.h" \ No newline at end of file From 7da04b4d5ddda3fab493b65be263217b0110f214 Mon Sep 17 00:00:00 2001 From: Zhengxuan Guo Date: Thu, 15 Aug 2024 12:24:23 +0800 Subject: [PATCH 02/12] impl Fr and Element --- bandersnatch/bandersnatch/Bandersnatch.cpp | 4 -- bandersnatch/bandersnatch/Bandersnatch.h | 5 -- bandersnatch/src/Element/Element.cpp | 74 ++++++++++++++++++++++ bandersnatch/src/Element/Element.h | 32 ++++++++++ bandersnatch/src/Fr/Fr.cpp | 57 +++++++++++++++++ bandersnatch/src/Fr/Fr.h | 28 ++++++++ 6 files changed, 191 insertions(+), 9 deletions(-) delete mode 100644 bandersnatch/bandersnatch/Bandersnatch.cpp delete mode 100644 bandersnatch/bandersnatch/Bandersnatch.h create mode 100644 bandersnatch/src/Element/Element.cpp create mode 100644 bandersnatch/src/Element/Element.h create mode 100644 bandersnatch/src/Fr/Fr.cpp create mode 100644 bandersnatch/src/Fr/Fr.h diff --git a/bandersnatch/bandersnatch/Bandersnatch.cpp b/bandersnatch/bandersnatch/Bandersnatch.cpp deleted file mode 100644 index aef9fbc..0000000 --- a/bandersnatch/bandersnatch/Bandersnatch.cpp +++ /dev/null @@ -1,4 +0,0 @@ -// -// Created by Zhengxuan Guo on 2024/8/12. -// -#include "Bandersnatch.h" \ No newline at end of file diff --git a/bandersnatch/bandersnatch/Bandersnatch.h b/bandersnatch/bandersnatch/Bandersnatch.h deleted file mode 100644 index 8c1e97b..0000000 --- a/bandersnatch/bandersnatch/Bandersnatch.h +++ /dev/null @@ -1,5 +0,0 @@ -// -// Created by Zhengxuan Guo on 2024/8/12. -// -#pragma once -#include "blst.h" \ No newline at end of file diff --git a/bandersnatch/src/Element/Element.cpp b/bandersnatch/src/Element/Element.cpp new file mode 100644 index 0000000..82ca206 --- /dev/null +++ b/bandersnatch/src/Element/Element.cpp @@ -0,0 +1,74 @@ +// +// Created by Zhengxuan Guo on 2024/8/13. +// + +#include "Element.h" + +using namespace verkle::bandersnatch; + +Element::Element() : m_point(std::make_shared()) {} + +Element::Element(const blst_p1& point) : m_point(std::make_shared(point)) {} + +Element::Element(const byte* in, size_t len) : m_point(std::make_shared()) +{ + if (len == 0 || len != (in[0]&0x80 ? 48 : 96)) + throw BLST_BAD_ENCODING; + blst_p1_affine a; + BLST_ERROR err = blst_p1_deserialize(&a, in); + if (err != BLST_SUCCESS) + throw err; + blst_p1_from_affine(m_point.get(), &a); +} + +Element& Element::add(const Element& other) +{ + blst_p1_add(m_point.get(), m_point.get(), other.m_point.get()); + return *this; +} + +Element& Element::dbl() +{ + blst_p1_double(m_point.get(), m_point.get()); + return *this; +} + +Element& Element::mult(const Fr& fr) +{ + auto scalar = fr.toScalar(); + blst_p1_mult(m_point.get(), m_point.get(), scalar->b, 255); + return *this; +} + +Element Element::add(const Element& a, const Element& b) +{ + Element ret; + blst_p1_add(ret.m_point.get(), a.m_point.get(), b.m_point.get()); + return ret; +} + +Element Element::dbl(const Element& a) +{ + Element ret; + blst_p1_double(ret.m_point.get(), a.m_point.get()); + return ret; +} + +Element Element::mult(const Fr& fr, const Element& a) +{ + Element ret; + auto scalar = fr.toScalar(); + blst_p1_mult(ret.m_point.get(), a.m_point.get(), scalar->b, 255); + return ret; +} + +Element Element::generator() +{ + auto const g = blst_p1_generator(); + return Element(*g); +} + +void Element::serialize(byte out[96]) const +{ + blst_p1_serialize(out, m_point.get()); +} diff --git a/bandersnatch/src/Element/Element.h b/bandersnatch/src/Element/Element.h new file mode 100644 index 0000000..098c5c2 --- /dev/null +++ b/bandersnatch/src/Element/Element.h @@ -0,0 +1,32 @@ +// +// Created by Zhengxuan Guo on 2024/8/13. +// +#pragma once +#include +#include +#include "Fr.h" + +namespace verkle::bandersnatch +{ + class Element + { + public: + Element(); + explicit Element(const blst_p1& point); + Element(const byte *in, size_t len); + + Element& add(const Element& other); + Element& dbl(); + Element& mult(const Fr& fr); + static Element add(const Element& a, const Element& b); + static Element dbl(const Element& a); + static Element mult(const Fr& fr, const Element& a); + + static Element generator(); + + void serialize(byte out[96]) const; + + private: + std::shared_ptr m_point; + }; +} diff --git a/bandersnatch/src/Fr/Fr.cpp b/bandersnatch/src/Fr/Fr.cpp new file mode 100644 index 0000000..f0ae259 --- /dev/null +++ b/bandersnatch/src/Fr/Fr.cpp @@ -0,0 +1,57 @@ +// +// Created by Zhengxuan Guo on 2024/8/13. +// + +#include "Fr.h" + +using namespace verkle::bandersnatch; + +Fr::Fr() : m_val(std::make_unique()) {} + +Fr::Fr(const uint8_t* msg, size_t len) : m_val(std::make_unique()) +{ + blst_scalar scalar; + blst_scalar_from_le_bytes(&scalar, msg, (len+7)/8); + blst_fr_from_scalar(m_val.get(), &scalar); +} + +Fr Fr::operator+(const Fr& other) const +{ + Fr ret; + blst_fr_add(ret.m_val.get(), m_val.get(), other.m_val.get()); + return ret; +} + +Fr Fr::operator-(const Fr& other) const +{ + Fr ret; + blst_fr_sub(ret.m_val.get(), m_val.get(), other.m_val.get()); + return ret; +} + +Fr Fr::operator*(const Fr& other) const +{ + Fr ret; + blst_fr_mul(ret.m_val.get(), m_val.get(), other.m_val.get()); + return ret; +} + +Fr Fr::inv() const +{ + Fr ret; + blst_fr_inverse(ret.m_val.get(), m_val.get()); + return ret; +} + +std::shared_ptr Fr::toScalar() const +{ + auto ret = std::make_shared(); + blst_scalar_from_fr(ret.get(), m_val.get()); + return ret; +} + + +void Fr::serialize(uint64_t ret[4]) const +{ + blst_uint64_from_fr(ret, m_val.get()); +} \ No newline at end of file diff --git a/bandersnatch/src/Fr/Fr.h b/bandersnatch/src/Fr/Fr.h new file mode 100644 index 0000000..31273c6 --- /dev/null +++ b/bandersnatch/src/Fr/Fr.h @@ -0,0 +1,28 @@ +// +// Created by Zhengxuan Guo on 2024/8/13. +// +#pragma once +#include +#include + +namespace verkle::bandersnatch +{ + class Fr + { + public: + Fr(); + Fr(const byte* msg, size_t len); + + Fr operator+(const Fr& other) const; + Fr operator-(const Fr& other) const; + Fr operator*(const Fr& other) const; + Fr inv() const; + + std::shared_ptr toScalar() const; + + void serialize(uint64_t ret[4]) const; + + private: + std::unique_ptr m_val; + }; +} From 4f1c3649a7348fe501b0215c7043783fcf9cfdaf Mon Sep 17 00:00:00 2001 From: Zhengxuan Guo Date: Thu, 15 Aug 2024 20:48:40 +0800 Subject: [PATCH 03/12] add HunterGate to CMakeLists.txt --- .gitignore | 3 + CMakeLists.txt | 16 + bandersnatch/CMakeLists.txt | 19 +- bandersnatch/src/{Element => }/Element.cpp | 6 +- bandersnatch/src/{Element => }/Element.h | 1 - bandersnatch/src/{Fr => }/Fr.cpp | 0 bandersnatch/src/{Fr => }/Fr.h | 0 bandersnatch/test/CMakeLists.txt | 7 + bandersnatch/test/unittests/ElementTest.cpp | 3 + bandersnatch/test/unittests/FrTest.cpp | 3 + cmake/config.cmake | 11 + verkle-cmake-scripts/HunterGate.cmake | 541 ++++++++++++++++++++ 12 files changed, 599 insertions(+), 11 deletions(-) rename bandersnatch/src/{Element => }/Element.cpp (92%) rename bandersnatch/src/{Element => }/Element.h (97%) rename bandersnatch/src/{Fr => }/Fr.cpp (100%) rename bandersnatch/src/{Fr => }/Fr.h (100%) create mode 100644 bandersnatch/test/CMakeLists.txt create mode 100644 bandersnatch/test/unittests/ElementTest.cpp create mode 100644 bandersnatch/test/unittests/FrTest.cpp create mode 100644 cmake/config.cmake create mode 100644 verkle-cmake-scripts/HunterGate.cmake diff --git a/.gitignore b/.gitignore index 8c9ab3e..a3347d9 100644 --- a/.gitignore +++ b/.gitignore @@ -47,6 +47,9 @@ deps/** .vscode/ .idea/ +# clion +**/cmake-build-debug/ + # macOS .DS_Store diff --git a/CMakeLists.txt b/CMakeLists.txt index 9b9678b..dda07c8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,21 @@ cmake_minimum_required(VERSION 3.10) +set(VERKLE_CMAKE_SCRIPTS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/verkle-cmake-scripts) +set(VERKLE_CMAKE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/cmake" CACHE PATH "The cmake path for the library") +list(APPEND CMAKE_MODULE_PATH ${VERKLE_CMAKE_SCRIPTS_DIR} ${VERKLE_CMAKE_DIR}) + +# init hunter +include(HunterGate) +HunterGate( + URL "https://github.com/FISCO-BCOS/hunter/archive/155dfdb7b5888493eefb656b3abcc026edb98730.tar.gz" + SHA1 "a797abf35de1904ec089a9f517d847637731d467" + FILEPATH "${VERKLE_CMAKE_DIR}/config.cmake" +) + project(verkle_tree) +set(CMAKE_CXX_STANDARD 20) + +hunter_add_package(Boost COMPONENTS unit_test_framework) +find_package(Boost CONFIG REQUIRED unit_test_framework) add_subdirectory(bandersnatch) diff --git a/bandersnatch/CMakeLists.txt b/bandersnatch/CMakeLists.txt index f5507cf..58bd0e4 100644 --- a/bandersnatch/CMakeLists.txt +++ b/bandersnatch/CMakeLists.txt @@ -1,9 +1,8 @@ cmake_minimum_required(VERSION 3.10) - project(bandersnatch) +set(CMAKE_CXX_STANDARD 20) include(ExternalProject) - ExternalProject_Add( blst GIT_REPOSITORY https://github.com/supranational/blst.git @@ -16,13 +15,19 @@ ExternalProject_Add( ) ExternalProject_Get_Property(blst SOURCE_DIR) +set(BLST_INCLUDE_DIR ${SOURCE_DIR}/bindings) ExternalProject_Get_Property(blst BINARY_DIR) set(BLST_LIB ${BINARY_DIR}/libblst.a) -set(BLST_INCLUDE_DIR ${SOURCE_DIR}/bindings) - -include_directories(${BLST_INCLUDE_DIR}) -add_library(bandersnatch bandersnatch/bandersnatch.cpp) +file(GLOB_RECURSE SRCS "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp") +add_library(bandersnatch ${SRCS}) +target_include_directories(bandersnatch PUBLIC ${BLST_INCLUDE_DIR}) add_dependencies(bandersnatch blst) -target_link_libraries(bandersnatch PRIVATE ${BLST_LIB}) \ No newline at end of file +target_link_libraries(bandersnatch PRIVATE ${BLST_LIB}) + +if (TESTS) + enable_testing() + set(CTEST_OUTPUT_ON_FAILURE TRUE) + add_subdirectory(test) +endif() \ No newline at end of file diff --git a/bandersnatch/src/Element/Element.cpp b/bandersnatch/src/Element.cpp similarity index 92% rename from bandersnatch/src/Element/Element.cpp rename to bandersnatch/src/Element.cpp index 82ca206..6e40896 100644 --- a/bandersnatch/src/Element/Element.cpp +++ b/bandersnatch/src/Element.cpp @@ -6,9 +6,9 @@ using namespace verkle::bandersnatch; -Element::Element() : m_point(std::make_shared()) {} +Element::Element() : m_point(std::make_shared()) {} -Element::Element(const blst_p1& point) : m_point(std::make_shared(point)) {} +Element::Element(const blst_p1& point) : m_point(std::make_shared(point)) {} Element::Element(const byte* in, size_t len) : m_point(std::make_shared()) { @@ -64,7 +64,7 @@ Element Element::mult(const Fr& fr, const Element& a) Element Element::generator() { - auto const g = blst_p1_generator(); + auto g = blst_p1_generator(); return Element(*g); } diff --git a/bandersnatch/src/Element/Element.h b/bandersnatch/src/Element.h similarity index 97% rename from bandersnatch/src/Element/Element.h rename to bandersnatch/src/Element.h index 098c5c2..e740712 100644 --- a/bandersnatch/src/Element/Element.h +++ b/bandersnatch/src/Element.h @@ -3,7 +3,6 @@ // #pragma once #include -#include #include "Fr.h" namespace verkle::bandersnatch diff --git a/bandersnatch/src/Fr/Fr.cpp b/bandersnatch/src/Fr.cpp similarity index 100% rename from bandersnatch/src/Fr/Fr.cpp rename to bandersnatch/src/Fr.cpp diff --git a/bandersnatch/src/Fr/Fr.h b/bandersnatch/src/Fr.h similarity index 100% rename from bandersnatch/src/Fr/Fr.h rename to bandersnatch/src/Fr.h diff --git a/bandersnatch/test/CMakeLists.txt b/bandersnatch/test/CMakeLists.txt new file mode 100644 index 0000000..af407e4 --- /dev/null +++ b/bandersnatch/test/CMakeLists.txt @@ -0,0 +1,7 @@ +file(GLOB_RECURSE TEST_SRCS "*.cpp") + +add_executable(bandersnatch-test ${TEST_SRCS}) +target_include_directories(bandersnatch-test PRIVATE .) +find_package(Boost CONFIG REQUIRED unit_test_framework) +target_link_libraries(bandersnatch-test PRIVATE bandersnatch Boost::unit_test_framework) +add_test(NAME test-bandersnatch WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} COMMAND bandersnatch-test) diff --git a/bandersnatch/test/unittests/ElementTest.cpp b/bandersnatch/test/unittests/ElementTest.cpp new file mode 100644 index 0000000..69ac15a --- /dev/null +++ b/bandersnatch/test/unittests/ElementTest.cpp @@ -0,0 +1,3 @@ +// +// Created by Zhengxuan Guo on 2024/8/15. +// diff --git a/bandersnatch/test/unittests/FrTest.cpp b/bandersnatch/test/unittests/FrTest.cpp new file mode 100644 index 0000000..69ac15a --- /dev/null +++ b/bandersnatch/test/unittests/FrTest.cpp @@ -0,0 +1,3 @@ +// +// Created by Zhengxuan Guo on 2024/8/15. +// diff --git a/cmake/config.cmake b/cmake/config.cmake new file mode 100644 index 0000000..a3fb784 --- /dev/null +++ b/cmake/config.cmake @@ -0,0 +1,11 @@ +hunter_config( + Boost VERSION "1.79.0" + URL + "https://osp-1257653870.cos.ap-guangzhou.myqcloud.com/FISCO-BCOS/FISCO-BCOS/deps/boost_1_79_0.tar.bz2 + https://downloads.sourceforge.net/project/boost/boost/1.79.0/source/boost_1_79_0.tar.bz2 + https://nchc.dl.sourceforge.net/project/boost/boost/1.79.0/boost_1_79_0.tar.bz2" + SHA1 + 31209dcff292bd6a64e5e08ceb3ce44a33615dc0 + CMAKE_ARGS + CONFIG_MACRO=BOOST_UUID_RANDOM_PROVIDER_FORCE_POSIX +) \ No newline at end of file diff --git a/verkle-cmake-scripts/HunterGate.cmake b/verkle-cmake-scripts/HunterGate.cmake new file mode 100644 index 0000000..ec6399a --- /dev/null +++ b/verkle-cmake-scripts/HunterGate.cmake @@ -0,0 +1,541 @@ +# Copyright (c) 2013-2019, Ruslan Baratov +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# This is a gate file to Hunter package manager. +# Include this file using `include` command and add package you need, example: +# +# cmake_minimum_required(VERSION 3.2) +# +# include("cmake/HunterGate.cmake") +# HunterGate( +# URL "https://github.com/path/to/hunter/archive.tar.gz" +# SHA1 "798501e983f14b28b10cda16afa4de69eee1da1d" +# ) +# +# project(MyProject) +# +# hunter_add_package(Foo) +# hunter_add_package(Boo COMPONENTS Bar Baz) +# +# Projects: +# * https://github.com/hunter-packages/gate/ +# * https://github.com/ruslo/hunter + +option(HUNTER_ENABLED "Enable Hunter package manager support" ON) + +if(HUNTER_ENABLED) + if(CMAKE_VERSION VERSION_LESS "3.2") + message( + FATAL_ERROR + "At least CMake version 3.2 required for Hunter dependency management." + " Update CMake or set HUNTER_ENABLED to OFF." + ) + endif() +endif() + +include(CMakeParseArguments) # cmake_parse_arguments + +option(HUNTER_STATUS_PRINT "Print working status" ON) +option(HUNTER_STATUS_DEBUG "Print a lot info" OFF) +option(HUNTER_TLS_VERIFY "Enable/disable TLS certificate checking on downloads" ON) + +set(HUNTER_ERROR_PAGE "https://docs.hunter.sh/en/latest/reference/errors") + +function(hunter_gate_status_print) + if(HUNTER_STATUS_PRINT OR HUNTER_STATUS_DEBUG) + foreach(print_message ${ARGV}) + message(STATUS "[hunter] ${print_message}") + endforeach() + endif() +endfunction() + +function(hunter_gate_status_debug) + if(HUNTER_STATUS_DEBUG) + foreach(print_message ${ARGV}) + string(TIMESTAMP timestamp) + message(STATUS "[hunter *** DEBUG *** ${timestamp}] ${print_message}") + endforeach() + endif() +endfunction() + +function(hunter_gate_error_page error_page) + message("------------------------------ ERROR ------------------------------") + message(" ${HUNTER_ERROR_PAGE}/${error_page}.html") + message("-------------------------------------------------------------------") + message("") + message(FATAL_ERROR "") +endfunction() + +function(hunter_gate_internal_error) + message("") + foreach(print_message ${ARGV}) + message("[hunter ** INTERNAL **] ${print_message}") + endforeach() + message("[hunter ** INTERNAL **] [Directory:${CMAKE_CURRENT_LIST_DIR}]") + message("") + hunter_gate_error_page("error.internal") +endfunction() + +function(hunter_gate_fatal_error) + cmake_parse_arguments(hunter "" "ERROR_PAGE" "" "${ARGV}") + if("${hunter_ERROR_PAGE}" STREQUAL "") + hunter_gate_internal_error("Expected ERROR_PAGE") + endif() + message("") + foreach(x ${hunter_UNPARSED_ARGUMENTS}) + message("[hunter ** FATAL ERROR **] ${x}") + endforeach() + message("[hunter ** FATAL ERROR **] [Directory:${CMAKE_CURRENT_LIST_DIR}]") + message("") + hunter_gate_error_page("${hunter_ERROR_PAGE}") +endfunction() + +function(hunter_gate_user_error) + hunter_gate_fatal_error(${ARGV} ERROR_PAGE "error.incorrect.input.data") +endfunction() + +function(hunter_gate_self root version sha1 result) + string(COMPARE EQUAL "${root}" "" is_bad) + if(is_bad) + hunter_gate_internal_error("root is empty") + endif() + + string(COMPARE EQUAL "${version}" "" is_bad) + if(is_bad) + hunter_gate_internal_error("version is empty") + endif() + + string(COMPARE EQUAL "${sha1}" "" is_bad) + if(is_bad) + hunter_gate_internal_error("sha1 is empty") + endif() + + string(SUBSTRING "${sha1}" 0 7 archive_id) + + if(EXISTS "${root}/cmake/Hunter") + set(hunter_self "${root}") + else() + set( + hunter_self + "${root}/_Base/Download/Hunter/${version}/${archive_id}/Unpacked" + ) + endif() + + set("${result}" "${hunter_self}" PARENT_SCOPE) +endfunction() + +# Set HUNTER_GATE_ROOT cmake variable to suitable value. +function(hunter_gate_detect_root) + # Check CMake variable + string(COMPARE NOTEQUAL "${HUNTER_ROOT}" "" not_empty) + if(not_empty) + set(HUNTER_GATE_ROOT "${HUNTER_ROOT}" PARENT_SCOPE) + hunter_gate_status_debug("HUNTER_ROOT detected by cmake variable") + return() + endif() + + # Check environment variable + string(COMPARE NOTEQUAL "$ENV{HUNTER_ROOT}" "" not_empty) + if(not_empty) + set(HUNTER_GATE_ROOT "$ENV{HUNTER_ROOT}" PARENT_SCOPE) + hunter_gate_status_debug("HUNTER_ROOT detected by environment variable") + return() + endif() + + # Check HOME environment variable + string(COMPARE NOTEQUAL "$ENV{HOME}" "" result) + if(result) + set(HUNTER_GATE_ROOT "$ENV{HOME}/.hunter" PARENT_SCOPE) + hunter_gate_status_debug("HUNTER_ROOT set using HOME environment variable") + return() + endif() + + # Check SYSTEMDRIVE and USERPROFILE environment variable (windows only) + if(WIN32) + string(COMPARE NOTEQUAL "$ENV{SYSTEMDRIVE}" "" result) + if(result) + set(HUNTER_GATE_ROOT "$ENV{SYSTEMDRIVE}/.hunter" PARENT_SCOPE) + hunter_gate_status_debug( + "HUNTER_ROOT set using SYSTEMDRIVE environment variable" + ) + return() + endif() + + string(COMPARE NOTEQUAL "$ENV{USERPROFILE}" "" result) + if(result) + set(HUNTER_GATE_ROOT "$ENV{USERPROFILE}/.hunter" PARENT_SCOPE) + hunter_gate_status_debug( + "HUNTER_ROOT set using USERPROFILE environment variable" + ) + return() + endif() + endif() + + hunter_gate_fatal_error( + "Can't detect HUNTER_ROOT" + ERROR_PAGE "error.detect.hunter.root" + ) +endfunction() + +function(hunter_gate_download dir) + string( + COMPARE + NOTEQUAL + "$ENV{HUNTER_DISABLE_AUTOINSTALL}" + "" + disable_autoinstall + ) + if(disable_autoinstall AND NOT HUNTER_RUN_INSTALL) + hunter_gate_fatal_error( + "Hunter not found in '${dir}'" + "Set HUNTER_RUN_INSTALL=ON to auto-install it from '${HUNTER_GATE_URL}'" + "Settings:" + " HUNTER_ROOT: ${HUNTER_GATE_ROOT}" + " HUNTER_SHA1: ${HUNTER_GATE_SHA1}" + ERROR_PAGE "error.run.install" + ) + endif() + string(COMPARE EQUAL "${dir}" "" is_bad) + if(is_bad) + hunter_gate_internal_error("Empty 'dir' argument") + endif() + + string(COMPARE EQUAL "${HUNTER_GATE_SHA1}" "" is_bad) + if(is_bad) + hunter_gate_internal_error("HUNTER_GATE_SHA1 empty") + endif() + + string(COMPARE EQUAL "${HUNTER_GATE_URL}" "" is_bad) + if(is_bad) + hunter_gate_internal_error("HUNTER_GATE_URL empty") + endif() + + set(done_location "${dir}/DONE") + set(sha1_location "${dir}/SHA1") + + set(build_dir "${dir}/Build") + set(cmakelists "${dir}/CMakeLists.txt") + + hunter_gate_status_debug("Locking directory: ${dir}") + file(LOCK "${dir}" DIRECTORY GUARD FUNCTION) + hunter_gate_status_debug("Lock done") + + if(EXISTS "${done_location}") + # while waiting for lock other instance can do all the job + hunter_gate_status_debug("File '${done_location}' found, skip install") + return() + endif() + + file(REMOVE_RECURSE "${build_dir}") + file(REMOVE_RECURSE "${cmakelists}") + + file(MAKE_DIRECTORY "${build_dir}") # check directory permissions + + # Disabling languages speeds up a little bit, reduces noise in the output + # and avoids path too long windows error + file( + WRITE + "${cmakelists}" + "cmake_minimum_required(VERSION 3.2)\n" + "project(HunterDownload LANGUAGES NONE)\n" + "include(ExternalProject)\n" + "ExternalProject_Add(\n" + " Hunter\n" + " URL\n" + " \"${HUNTER_GATE_URL}\"\n" + " URL_HASH\n" + " SHA1=${HUNTER_GATE_SHA1}\n" + " DOWNLOAD_DIR\n" + " \"${dir}\"\n" + " TLS_VERIFY\n" + " ${HUNTER_TLS_VERIFY}\n" + " SOURCE_DIR\n" + " \"${dir}/Unpacked\"\n" + " CONFIGURE_COMMAND\n" + " \"\"\n" + " BUILD_COMMAND\n" + " \"\"\n" + " INSTALL_COMMAND\n" + " \"\"\n" + ")\n" + ) + + if(HUNTER_STATUS_DEBUG) + set(logging_params "") + else() + set(logging_params OUTPUT_QUIET) + endif() + + hunter_gate_status_debug("Run generate") + + # Need to add toolchain file too. + # Otherwise on Visual Studio + MDD this will fail with error: + # "Could not find an appropriate version of the Windows 10 SDK installed on this machine" + if(EXISTS "${CMAKE_TOOLCHAIN_FILE}") + get_filename_component(absolute_CMAKE_TOOLCHAIN_FILE "${CMAKE_TOOLCHAIN_FILE}" ABSOLUTE) + set(toolchain_arg "-DCMAKE_TOOLCHAIN_FILE=${absolute_CMAKE_TOOLCHAIN_FILE}") + else() + # 'toolchain_arg' can't be empty + set(toolchain_arg "-DCMAKE_TOOLCHAIN_FILE=") + endif() + + string(COMPARE EQUAL "${CMAKE_MAKE_PROGRAM}" "" no_make) + if(no_make) + set(make_arg "") + else() + # Test case: remove Ninja from PATH but set it via CMAKE_MAKE_PROGRAM + set(make_arg "-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}") + endif() + + execute_process( + COMMAND + "${CMAKE_COMMAND}" + "-H${dir}" + "-B${build_dir}" + "-G${CMAKE_GENERATOR}" + "${toolchain_arg}" + ${make_arg} + WORKING_DIRECTORY "${dir}" + RESULT_VARIABLE download_result + ${logging_params} + ) + + if(NOT download_result EQUAL 0) + hunter_gate_internal_error( + "Configure project failed." + "To reproduce the error run: ${CMAKE_COMMAND} -H${dir} -B${build_dir} -G${CMAKE_GENERATOR} ${toolchain_arg} ${make_arg}" + "In directory ${dir}" + ) + endif() + + hunter_gate_status_print( + "Initializing Hunter workspace (${HUNTER_GATE_SHA1})" + " ${HUNTER_GATE_URL}" + " -> ${dir}" + ) + execute_process( + COMMAND "${CMAKE_COMMAND}" --build "${build_dir}" + WORKING_DIRECTORY "${dir}" + RESULT_VARIABLE download_result + ${logging_params} + ) + + if(NOT download_result EQUAL 0) + hunter_gate_internal_error("Build project failed") + endif() + + file(REMOVE_RECURSE "${build_dir}") + file(REMOVE_RECURSE "${cmakelists}") + + file(WRITE "${sha1_location}" "${HUNTER_GATE_SHA1}") + file(WRITE "${done_location}" "DONE") + + hunter_gate_status_debug("Finished") +endfunction() + +# Must be a macro so master file 'cmake/Hunter' can +# apply all variables easily just by 'include' command +# (otherwise PARENT_SCOPE magic needed) +macro(HunterGate) + if(HUNTER_GATE_DONE) + # variable HUNTER_GATE_DONE set explicitly for external project + # (see `hunter_download`) + set_property(GLOBAL PROPERTY HUNTER_GATE_DONE YES) + endif() + + # First HunterGate command will init Hunter, others will be ignored + get_property(_hunter_gate_done GLOBAL PROPERTY HUNTER_GATE_DONE SET) + + if(NOT HUNTER_ENABLED) + # Empty function to avoid error "unknown function" + function(hunter_add_package) + endfunction() + + set( + _hunter_gate_disabled_mode_dir + "${CMAKE_CURRENT_LIST_DIR}/cmake/Hunter/disabled-mode" + ) + if(EXISTS "${_hunter_gate_disabled_mode_dir}") + hunter_gate_status_debug( + "Adding \"disabled-mode\" modules: ${_hunter_gate_disabled_mode_dir}" + ) + list(APPEND CMAKE_PREFIX_PATH "${_hunter_gate_disabled_mode_dir}") + endif() + elseif(_hunter_gate_done) + hunter_gate_status_debug("Secondary HunterGate (use old settings)") + hunter_gate_self( + "${HUNTER_CACHED_ROOT}" + "${HUNTER_VERSION}" + "${HUNTER_SHA1}" + _hunter_self + ) + include("${_hunter_self}/cmake/Hunter") + else() + set(HUNTER_GATE_LOCATION ".") + + string(COMPARE NOTEQUAL "${PROJECT_NAME}" "" _have_project_name) + if(_have_project_name) + hunter_gate_fatal_error( + "Please set HunterGate *before* 'project' command. " + "Detected project: ${PROJECT_NAME}" + ERROR_PAGE "error.huntergate.before.project" + ) + endif() + + cmake_parse_arguments( + HUNTER_GATE "LOCAL" "URL;SHA1;GLOBAL;FILEPATH" "" ${ARGV} + ) + + string(COMPARE EQUAL "${HUNTER_GATE_SHA1}" "" _empty_sha1) + string(COMPARE EQUAL "${HUNTER_GATE_URL}" "" _empty_url) + string( + COMPARE + NOTEQUAL + "${HUNTER_GATE_UNPARSED_ARGUMENTS}" + "" + _have_unparsed + ) + string(COMPARE NOTEQUAL "${HUNTER_GATE_GLOBAL}" "" _have_global) + string(COMPARE NOTEQUAL "${HUNTER_GATE_FILEPATH}" "" _have_filepath) + + if(_have_unparsed) + hunter_gate_user_error( + "HunterGate unparsed arguments: ${HUNTER_GATE_UNPARSED_ARGUMENTS}" + ) + endif() + if(_empty_sha1) + hunter_gate_user_error("SHA1 suboption of HunterGate is mandatory") + endif() + if(_empty_url) + hunter_gate_user_error("URL suboption of HunterGate is mandatory") + endif() + if(_have_global) + if(HUNTER_GATE_LOCAL) + hunter_gate_user_error("Unexpected LOCAL (already has GLOBAL)") + endif() + if(_have_filepath) + hunter_gate_user_error("Unexpected FILEPATH (already has GLOBAL)") + endif() + endif() + if(HUNTER_GATE_LOCAL) + if(_have_global) + hunter_gate_user_error("Unexpected GLOBAL (already has LOCAL)") + endif() + if(_have_filepath) + hunter_gate_user_error("Unexpected FILEPATH (already has LOCAL)") + endif() + endif() + if(_have_filepath) + if(_have_global) + hunter_gate_user_error("Unexpected GLOBAL (already has FILEPATH)") + endif() + if(HUNTER_GATE_LOCAL) + hunter_gate_user_error("Unexpected LOCAL (already has FILEPATH)") + endif() + endif() + + hunter_gate_detect_root() # set HUNTER_GATE_ROOT + + # Beautify path, fix probable problems with windows path slashes + get_filename_component( + HUNTER_GATE_ROOT "${HUNTER_GATE_ROOT}" ABSOLUTE + ) + hunter_gate_status_debug("HUNTER_ROOT: ${HUNTER_GATE_ROOT}") + if(NOT HUNTER_ALLOW_SPACES_IN_PATH) + string(FIND "${HUNTER_GATE_ROOT}" " " _contain_spaces) + if(NOT _contain_spaces EQUAL -1) + hunter_gate_fatal_error( + "HUNTER_ROOT (${HUNTER_GATE_ROOT}) contains spaces." + "Set HUNTER_ALLOW_SPACES_IN_PATH=ON to skip this error" + "(Use at your own risk!)" + ERROR_PAGE "error.spaces.in.hunter.root" + ) + endif() + endif() + + string( + REGEX + MATCH + "[0-9]+\\.[0-9]+\\.[0-9]+[-_a-z0-9]*" + HUNTER_GATE_VERSION + "${HUNTER_GATE_URL}" + ) + string(COMPARE EQUAL "${HUNTER_GATE_VERSION}" "" _is_empty) + if(_is_empty) + set(HUNTER_GATE_VERSION "unknown") + endif() + + hunter_gate_self( + "${HUNTER_GATE_ROOT}" + "${HUNTER_GATE_VERSION}" + "${HUNTER_GATE_SHA1}" + _hunter_self + ) + + set(_master_location "${_hunter_self}/cmake/Hunter") + if(EXISTS "${HUNTER_GATE_ROOT}/cmake/Hunter") + # Hunter downloaded manually (e.g. by 'git clone') + set(_unused "xxxxxxxxxx") + set(HUNTER_GATE_SHA1 "${_unused}") + set(HUNTER_GATE_VERSION "${_unused}") + else() + get_filename_component(_archive_id_location "${_hunter_self}/.." ABSOLUTE) + set(_done_location "${_archive_id_location}/DONE") + set(_sha1_location "${_archive_id_location}/SHA1") + + # Check Hunter already downloaded by HunterGate + if(NOT EXISTS "${_done_location}") + hunter_gate_download("${_archive_id_location}") + endif() + + if(NOT EXISTS "${_done_location}") + hunter_gate_internal_error("hunter_gate_download failed") + endif() + + if(NOT EXISTS "${_sha1_location}") + hunter_gate_internal_error("${_sha1_location} not found") + endif() + file(READ "${_sha1_location}" _sha1_value) + string(TOLOWER "${_sha1_value}" _sha1_value_lower) + string(TOLOWER "${HUNTER_GATE_SHA1}" _HUNTER_GATE_SHA1_lower) + string(COMPARE EQUAL "${_sha1_value_lower}" "${_HUNTER_GATE_SHA1_lower}" _is_equal) + if(NOT _is_equal) + hunter_gate_internal_error( + "Short SHA1 collision:" + " ${_sha1_value} (from ${_sha1_location})" + " ${HUNTER_GATE_SHA1} (HunterGate)" + ) + endif() + if(NOT EXISTS "${_master_location}") + hunter_gate_user_error( + "Master file not found:" + " ${_master_location}" + "try to update Hunter/HunterGate" + ) + endif() + endif() + include("${_master_location}") + set_property(GLOBAL PROPERTY HUNTER_GATE_DONE YES) + endif() +endmacro() From 13430e86e0ff17070939e04b0820ebb568132da2 Mon Sep 17 00:00:00 2001 From: Zhengxuan Guo Date: Fri, 16 Aug 2024 20:58:08 +0800 Subject: [PATCH 04/12] stash import boost --- .gitignore | 1 + CMakeLists.txt | 24 +- bandersnatch/CMakeLists.txt | 35 +- bandersnatch/src/Element.h | 39 +- bandersnatch/src/Fr.h | 33 +- bandersnatch/test/CMakeLists.txt | 7 +- bandersnatch/test/unittests/ElementTest.cpp | 9 + bandersnatch/test/unittests/FrTest.cpp | 8 + cmake/CompilerSettings.cmake | 160 ++++++ cmake/Options.cmake | 182 +++++++ cmake/ProjectBLST.cmake | 39 ++ cmake/ProjectBoost.cmake | 145 ++++++ cmake/config.cmake | 11 - verkle-cmake-scripts/HunterGate.cmake | 541 -------------------- 14 files changed, 605 insertions(+), 629 deletions(-) create mode 100644 cmake/CompilerSettings.cmake create mode 100644 cmake/Options.cmake create mode 100644 cmake/ProjectBLST.cmake create mode 100644 cmake/ProjectBoost.cmake delete mode 100644 cmake/config.cmake delete mode 100644 verkle-cmake-scripts/HunterGate.cmake diff --git a/.gitignore b/.gitignore index a3347d9..48e657d 100644 --- a/.gitignore +++ b/.gitignore @@ -61,6 +61,7 @@ deps/** # vcpkg vcpkg +CMakeUserPresets.json # clangd file compile_commands.json diff --git a/CMakeLists.txt b/CMakeLists.txt index dda07c8..462c880 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,21 +1,15 @@ cmake_minimum_required(VERSION 3.10) -set(VERKLE_CMAKE_SCRIPTS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/verkle-cmake-scripts) -set(VERKLE_CMAKE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/cmake" CACHE PATH "The cmake path for the library") -list(APPEND CMAKE_MODULE_PATH ${VERKLE_CMAKE_SCRIPTS_DIR} ${VERKLE_CMAKE_DIR}) - -# init hunter -include(HunterGate) -HunterGate( - URL "https://github.com/FISCO-BCOS/hunter/archive/155dfdb7b5888493eefb656b3abcc026edb98730.tar.gz" - SHA1 "a797abf35de1904ec089a9f517d847637731d467" - FILEPATH "${VERKLE_CMAKE_DIR}/config.cmake" -) - project(verkle_tree) -set(CMAKE_CXX_STANDARD 20) +# set(CMAKE_CXX_STANDARD 20) + +set(VERKLE_CMAKE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/cmake") +list(APPEND CMAKE_MODULE_PATH ${VERKLE_CMAKE_DIR}) -hunter_add_package(Boost COMPONENTS unit_test_framework) -find_package(Boost CONFIG REQUIRED unit_test_framework) +include(Options) +configure_project() +include(CompilerSettings) +include(ProjectBLST) +include(ProjectBoost) add_subdirectory(bandersnatch) diff --git a/bandersnatch/CMakeLists.txt b/bandersnatch/CMakeLists.txt index 58bd0e4..a0ad2e4 100644 --- a/bandersnatch/CMakeLists.txt +++ b/bandersnatch/CMakeLists.txt @@ -1,33 +1,16 @@ cmake_minimum_required(VERSION 3.10) -project(bandersnatch) -set(CMAKE_CXX_STANDARD 20) - -include(ExternalProject) -ExternalProject_Add( - blst - GIT_REPOSITORY https://github.com/supranational/blst.git - GIT_TAG 52cc60d78591a56abb2f3d0bd1cdafc6ba242997 - PREFIX ${CMAKE_BINARY_DIR}/blst - CONFIGURE_COMMAND "" - BUILD_COMMAND ${CMAKE_BINARY_DIR}/blst/src/blst/build.sh - BUILD_IN_SOURCE 0 - INSTALL_COMMAND "" -) -ExternalProject_Get_Property(blst SOURCE_DIR) -set(BLST_INCLUDE_DIR ${SOURCE_DIR}/bindings) -ExternalProject_Get_Property(blst BINARY_DIR) -set(BLST_LIB ${BINARY_DIR}/libblst.a) +project(bandersnatch) +# set(CMAKE_CXX_STANDARD 20) file(GLOB_RECURSE SRCS "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp") +file(GLOB_RECURSE HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/src/*.h") -add_library(bandersnatch ${SRCS}) -target_include_directories(bandersnatch PUBLIC ${BLST_INCLUDE_DIR}) -add_dependencies(bandersnatch blst) -target_link_libraries(bandersnatch PRIVATE ${BLST_LIB}) +add_library(bandersnatch ${SRCS} ${HEADERS}) +target_link_libraries(bandersnatch PRIVATE blst) -if (TESTS) - enable_testing() - set(CTEST_OUTPUT_ON_FAILURE TRUE) +# if (TESTS) + # enable_testing() + # set(CTEST_OUTPUT_ON_FAILURE TRUE) add_subdirectory(test) -endif() \ No newline at end of file +# endif() diff --git a/bandersnatch/src/Element.h b/bandersnatch/src/Element.h index e740712..d44328d 100644 --- a/bandersnatch/src/Element.h +++ b/bandersnatch/src/Element.h @@ -5,27 +5,30 @@ #include #include "Fr.h" -namespace verkle::bandersnatch +namespace verkle { - class Element + namespace bandersnatch { - public: - Element(); - explicit Element(const blst_p1& point); - Element(const byte *in, size_t len); + class Element + { + public: + Element(); + explicit Element(const blst_p1& point); + Element(const byte *in, size_t len); - Element& add(const Element& other); - Element& dbl(); - Element& mult(const Fr& fr); - static Element add(const Element& a, const Element& b); - static Element dbl(const Element& a); - static Element mult(const Fr& fr, const Element& a); + Element& add(const Element& other); + Element& dbl(); + Element& mult(const Fr& fr); + static Element add(const Element& a, const Element& b); + static Element dbl(const Element& a); + static Element mult(const Fr& fr, const Element& a); - static Element generator(); + static Element generator(); - void serialize(byte out[96]) const; + void serialize(byte out[96]) const; - private: - std::shared_ptr m_point; - }; -} + private: + std::shared_ptr m_point; + }; + } + } \ No newline at end of file diff --git a/bandersnatch/src/Fr.h b/bandersnatch/src/Fr.h index 31273c6..d4dca5b 100644 --- a/bandersnatch/src/Fr.h +++ b/bandersnatch/src/Fr.h @@ -5,24 +5,27 @@ #include #include -namespace verkle::bandersnatch +namespace verkle { - class Fr + namespace bandersnatch { - public: - Fr(); - Fr(const byte* msg, size_t len); + class Fr + { + public: + Fr(); + Fr(const byte* msg, size_t len); - Fr operator+(const Fr& other) const; - Fr operator-(const Fr& other) const; - Fr operator*(const Fr& other) const; - Fr inv() const; + Fr operator+(const Fr& other) const; + Fr operator-(const Fr& other) const; + Fr operator*(const Fr& other) const; + Fr inv() const; - std::shared_ptr toScalar() const; + std::shared_ptr toScalar() const; - void serialize(uint64_t ret[4]) const; + void serialize(uint64_t ret[4]) const; - private: - std::unique_ptr m_val; - }; -} + private: + std::unique_ptr m_val; + }; + } +} \ No newline at end of file diff --git a/bandersnatch/test/CMakeLists.txt b/bandersnatch/test/CMakeLists.txt index af407e4..59379f8 100644 --- a/bandersnatch/test/CMakeLists.txt +++ b/bandersnatch/test/CMakeLists.txt @@ -1,7 +1,8 @@ file(GLOB_RECURSE TEST_SRCS "*.cpp") + + add_executable(bandersnatch-test ${TEST_SRCS}) target_include_directories(bandersnatch-test PRIVATE .) -find_package(Boost CONFIG REQUIRED unit_test_framework) -target_link_libraries(bandersnatch-test PRIVATE bandersnatch Boost::unit_test_framework) -add_test(NAME test-bandersnatch WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} COMMAND bandersnatch-test) +target_link_libraries(bandersnatch-test bandersnatch Boost::UnitTestFramework) +# add_test(NAME test-bandersnatch WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} COMMAND bandersnatch-test) diff --git a/bandersnatch/test/unittests/ElementTest.cpp b/bandersnatch/test/unittests/ElementTest.cpp index 69ac15a..f2fed56 100644 --- a/bandersnatch/test/unittests/ElementTest.cpp +++ b/bandersnatch/test/unittests/ElementTest.cpp @@ -1,3 +1,12 @@ // // Created by Zhengxuan Guo on 2024/8/15. // +#include + +namespace verkle { + namespace test { + BOOST_AUTO_TEST_SUITE(TEST) + + BOOST_AUTO_TEST_SUITE_END() + } +} \ No newline at end of file diff --git a/bandersnatch/test/unittests/FrTest.cpp b/bandersnatch/test/unittests/FrTest.cpp index 69ac15a..bd5c6b8 100644 --- a/bandersnatch/test/unittests/FrTest.cpp +++ b/bandersnatch/test/unittests/FrTest.cpp @@ -1,3 +1,11 @@ // // Created by Zhengxuan Guo on 2024/8/15. // +#include + +namespace verkle { + namespace test { + BOOST_AUTO_TEST_SUITE(TEST) + BOOST_AUTO_TEST_SUITE_END() + } +} \ No newline at end of file diff --git a/cmake/CompilerSettings.cmake b/cmake/CompilerSettings.cmake new file mode 100644 index 0000000..441bedc --- /dev/null +++ b/cmake/CompilerSettings.cmake @@ -0,0 +1,160 @@ +#------------------------------------------------------------------------------ +# Setting compiling for FISCO-BCOS. +# ------------------------------------------------------------------------------ +# This file is part of FISCO-BCOS. +# +# FISCO-BCOS is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# FISCO-BCOS is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with FISCO-BCOS. If not, see +# +# (c) 2016-2018 fisco-dev contributors. +#------------------------------------------------------------------------------ + +if (("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")) + find_program(CCACHE_PROGRAM ccache) + if(CCACHE_PROGRAM) + set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}") + set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "${CCACHE_PROGRAM}") + endif() + # set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "/usr/bin/time") + # set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "/usr/bin/time") + # Use ISO C++14 standard language. + set(CMAKE_CXX_FLAGS "-std=c++14 -pthread -fPIC -fvisibility=hidden -fvisibility-inlines-hidden -fexceptions") + set(CMAKE_CXX_VISIBILITY_PRESET hidden) + # Enables all the warnings about constructions that some users consider questionable, + # and that are easy to avoid. Also enable some extra warning flags that are not + # enabled by -Wall. Finally, treat at warnings-as-errors, which forces developers + # to fix warnings as they arise, so they don't accumulate "to be fixed later". + add_compile_options(-Werror) + add_compile_options(-Wall) + add_compile_options(-pedantic) + add_compile_options(-Wextra) + # add_compile_options(-Wno-unused-variable) + # add_compile_options(-Wno-unused-parameter) + # add_compile_options(-Wno-unused-function) + # add_compile_options(-Wno-missing-field-initializers) + # Disable warnings about unknown pragmas (which is enabled by -Wall). + add_compile_options(-Wno-unknown-pragmas) + add_compile_options(-fno-omit-frame-pointer) + # for boost json spirit + add_compile_options(-DBOOST_SPIRIT_THREADSAFE) + # for tbb, TODO: https://software.intel.com/sites/default/files/managed/b2/d2/TBBRevamp.pdf + add_compile_options(-DTBB_SUPPRESS_DEPRECATED_MESSAGES=1) + # build deps lib Release + set(_only_release_configuration "-DCMAKE_BUILD_TYPE=Release") + + if(BUILD_STATIC) + SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a") + SET(BUILD_SHARED_LIBRARIES OFF) + SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static") + # SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Bdynamic -ldl -lpthread -Wl,-Bstatic -static-libstdc++ ") + endif () + + if(TESTS) + add_compile_options(-DBOOST_TEST_THREAD_SAFE) + endif () + + if(PROF) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg") + SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg") + SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -pg") + endif () + + # Configuration-specific compiler settings. + set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -DFISCO_DEBUG") + set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG") + set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG") + set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g") + + if (USE_LD_GOLD) + # message("CompilerSettings: USE_LD_GOLD") + execute_process(COMMAND ${CMAKE_C_COMPILER} -fuse-ld=gold -Wl,--version ERROR_QUIET OUTPUT_VARIABLE LD_VERSION) + if ("${LD_VERSION}" MATCHES "GNU gold") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=gold") + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=gold") + endif () + endif () + + # Additional GCC-specific compiler settings. + if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") + # Check that we've got GCC 5.4 or newer. + execute_process( + COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION) + if (NOT (GCC_VERSION VERSION_GREATER 5.4 OR GCC_VERSION VERSION_EQUAL 5.4)) + message(FATAL_ERROR "${PROJECT_NAME} requires g++ 5.4 or greater. Current is ${GCC_VERSION}") + endif () + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MARCH_TYPE}") + set(CMAKE_C_FLAGS "-std=c99 ${CMAKE_C_FLAGS} ${MARCH_TYPE}") + + # Strong stack protection was only added in GCC 4.9. + # Use it if we have the option to do so. + # See https://lwn.net/Articles/584225/ + if (GCC_VERSION VERSION_GREATER 4.9 OR GCC_VERSION VERSION_EQUAL 4.9) + add_compile_options(-fstack-protector-strong) + add_compile_options(-fstack-protector) + endif() + # Additional Clang-specific compiler settings. + elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") + if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.0) + set(CMAKE_CXX_FLAGS_DEBUG "-O -g -DFISCO_DEBUG") + endif() + # set(CMAKE_CXX_FLAGS "-stdlib=libc++ ${CMAKE_CXX_FLAGS}") + add_compile_options(-fstack-protector) + add_compile_options(-Winconsistent-missing-override) + # Some Linux-specific Clang settings. We don't want these for OS X. + if ("${CMAKE_SYSTEM_NAME}" MATCHES "Linux") + # Tell Boost that we're using Clang's libc++. Not sure exactly why we need to do. + add_definitions(-DBOOST_ASIO_HAS_CLANG_LIBCXX) + # Use fancy colors in the compiler diagnostics + add_compile_options(-fcolor-diagnostics) + endif() + endif() + + if (COVERAGE) + set(TESTS ON) + if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") + set(CMAKE_CXX_FLAGS "-g --coverage ${CMAKE_CXX_FLAGS}") + set(CMAKE_C_FLAGS "-g --coverage ${CMAKE_C_FLAGS}") + set(CMAKE_SHARED_LINKER_FLAGS "--coverage ${CMAKE_SHARED_LINKER_FLAGS}") + set(CMAKE_EXE_LINKER_FLAGS "--coverage ${CMAKE_EXE_LINKER_FLAGS}") + elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") + add_compile_options(-Wno-unused-command-line-argument) + set(CMAKE_CXX_FLAGS "-g -fprofile-arcs -ftest-coverage ${CMAKE_CXX_FLAGS}") + set(CMAKE_C_FLAGS "-g -fprofile-arcs -ftest-coverage ${CMAKE_C_FLAGS}") + endif() + find_program(LCOV_TOOL lcov) + message(STATUS "lcov tool: ${LCOV_TOOL}") + if (LCOV_TOOL) + add_custom_target(coverage + COMMAND ${LCOV_TOOL} -o ${CMAKE_BINARY_DIR}/coverage.info.in -c -d ${CMAKE_BINARY_DIR}/ + COMMAND ${LCOV_TOOL} -r ${CMAKE_BINARY_DIR}/coverage.info.in '/usr*' '${CMAKE_SOURCE_DIR}/deps**' '${CMAKE_SOURCE_DIR}/evmc*' ‘${CMAKE_SOURCE_DIR}/fisco-bcos*’ -o ${CMAKE_BINARY_DIR}/coverage.info + COMMAND genhtml -q -o ${CMAKE_BINARY_DIR}/CodeCoverage ${CMAKE_BINARY_DIR}/coverage.info) + else () + message(FATAL_ERROR "Can't find lcov tool. Please install lcov") + endif() + endif () +else () + message(WARNING "Your compiler is not tested, if you run into any issues, we'd welcome any patches.") +endif () + +if (SANITIZE) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer -fsanitize=${SANITIZE}") + if (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize-blacklist=${CMAKE_SOURCE_DIR}/sanitizer-blacklist.txt") + endif() +endif() + +# rust static library linking requirements for macos +if(APPLE) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework Security") +endif() + diff --git a/cmake/Options.cmake b/cmake/Options.cmake new file mode 100644 index 0000000..bc4d76a --- /dev/null +++ b/cmake/Options.cmake @@ -0,0 +1,182 @@ +#------------------------------------------------------------------------------ +# Set compile options for FISCO-BCOS. +# ------------------------------------------------------------------------------ +# This file is part of FISCO-BCOS. +# +# FISCO-BCOS is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# FISCO-BCOS is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with FISCO-BCOS. If not, see +# +# (c) 2016-2018 fisco-dev contributors. +#------------------------------------------------------------------------------ +# change-list +# 2018/09/05: yujiechen +# 1. add DEBUG flag +# 2. add FISCO_DEBUG definition when DEBUG flag has been set + +macro(eth_default_option O DEF) + if (DEFINED ${O}) + if (${${O}}) + set(${O} ON) + else () + set(${O} OFF) + endif() + else () + set(${O} ${DEF}) + endif() +endmacro() + +# common settings +set(MARCH_TYPE "-march=x86-64 -mtune=generic -fvisibility=hidden -fvisibility-inlines-hidden") +set(ETH_CMAKE_DIR ${CMAKE_CURRENT_LIST_DIR}) +set(ETH_SCRIPTS_DIR ${ETH_CMAKE_DIR}/scripts) +set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) +if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4") + message(FATAL "The ${PROJECT_NAME} does not support compiling on 32-bit systems") +endif() + +EXECUTE_PROCESS(COMMAND uname -m COMMAND tr -d '\n' OUTPUT_VARIABLE ARCHITECTURE) + +macro(configure_project) + set(NAME ${PROJECT_NAME}) + # Default to RelWithDebInfo configuration if no configuration is explicitly specified. + if (NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING + "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE) + endif() + + eth_default_option(BUILD_SHARED_LIBS OFF) + + eth_default_option(BUILD_STATIC OFF) + + #ARCH TYPE + eth_default_option(ARCH_NATIVE OFF) + set(USE_LD_GOLD ON) + # if aarch64 set arch_native on + if("${ARCHITECTURE}" STREQUAL "aarch64" OR "${ARCHITECTURE}" STREQUAL "arm64") + set(ARCH_NATIVE ON) + endif() + if(ARCH_NATIVE) + if(APPLE) + set(MARCH_TYPE "-mtune=generic -fvisibility=hidden -fvisibility-inlines-hidden") + else() + set(MARCH_TYPE "-march=native") + set(USE_LD_GOLD OFF) + endif() + set(COMPILE_OPTIONS "native") + endif() + + # unit tests + eth_default_option(TESTS OFF) + # mini demos + eth_default_option(DEMO OFF) + # tools + eth_default_option(TOOL OFF) + # code coverage + eth_default_option(COVERAGE OFF) + # hardware crypto sdf interface + eth_default_option(USE_HSM_SDF OFF) + if(USE_HSM_SDF) + if(NOT "${CMAKE_SYSTEM_NAME}" MATCHES "Linux") + message(FATAL "${CMAKE_SYSTEM_NAME} ${ARCHITECTURE} does not support by hardware secure module") + endif() + add_definitions(-DFISCO_SDF) + if(NOT DEFINED COMPILE_OPTIONS) + set(COMPILE_OPTIONS "hsm_sdf") + else() + set(COMPILE_OPTIONS "${COMPILE_OPTIONS},hsm_sdf") + endif() + endif() + + #debug + eth_default_option(DEBUG OFF) + if (DEBUG) + add_definitions(-DFISCO_DEBUG) + endif() + + #perf + eth_default_option(PROF OFF) + if (PROF) + #add_definitions(-DPROF) + endif() + eth_default_option(WITH_URING OFF) + eth_default_option(WITH_TBB ON) + if(TESTS) + set(WITH_TBB ON) + endif() + if(NOT WITH_TBB) + if(NOT DEFINED COMPILE_OPTIONS) + set(COMPILE_OPTIONS "without_tbb") + else() + set(COMPILE_OPTIONS "${COMPILE_OPTIONS},without_tbb") + endif() + endif() + if (WITH_TBB) + add_definitions(-DWITH_TBB) + endif() + + # Define a matching property name of each of the "features". + foreach(FEATURE ${ARGN}) + set(SUPPORT_${FEATURE} TRUE) + endforeach() + if(DISABLE_OBSERVER_WRITE_REQUEST) + add_definitions(-DDISABLE_OBSERVER_WRITE_REQUEST) + if(NOT DEFINED COMPILE_OPTIONS) + set(COMPILE_OPTIONS "disable_observer_write_request") + else() + set(COMPILE_OPTIONS "${COMPILE_OPTIONS},disable_observer_write_request") + endif() + endif() + + # CI Builds should provide (for user builds this is totally optional) + # -DBUILD_NUMBER - A number to identify the current build with. Becomes TWEAK component of project version. + # -DVERSION_SUFFIX - A string to append to the end of the version string where applicable. + if (NOT DEFINED BUILD_NUMBER) + # default is big so that local build is always considered greater + # and can easily replace CI build for for all platforms if needed. + # Windows max version component number is 65535 + set(BUILD_NUMBER 65535) + endif() + + # Suffix like "-rc1" e.t.c. to append to versions wherever needed. + if (NOT DEFINED VERSION_SUFFIX) + set(VERSION_SUFFIX "") + endif() + +endmacro() + +macro(print_config NAME) + message("") + message("------------------------------------------------------------------------") + message("-- Configuring ${NAME} ${PROJECT_VERSION}${VERSION_SUFFIX}") + message("------------------------------------------------------------------------") + message("-- CMake Cmake version and location ${CMAKE_VERSION} (${CMAKE_COMMAND})") + message("-- Compiler C++ compiler version ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}") + message("-- CMAKE_BUILD_TYPE Build type ${CMAKE_BUILD_TYPE}") + message("-- TARGET_PLATFORM Target platform ${CMAKE_SYSTEM_NAME} ${ARCHITECTURE}") + message("-- BUILD_STATIC Build static ${BUILD_STATIC}") + message("-- USE_HSM_SDF Build SDF HSM ${USE_HSM_SDF}") + message("-- DEMO Build demos ${DEMO}") + message("-- TOOL Build tools ${TOOL}") + message("-- COVERAGE Build code coverage ${COVERAGE}") + message("-- TESTS Build tests ${TESTS}") + message("-- WITH_TBB Build with tbb ${WITH_TBB}") + message("-- APPLE Apple Machine ${APPLE}") + message("-- ARCH_NATIVE Enable native code ${ARCH_NATIVE}") + message("-- DEBUG Enable debug macro ${DEBUG}") + message("-- PROF Enable gcc prof ${PROF}") + message("-- DEFINE_FILTER_OWR DISABLE_OBSERVER_WRITE_REQUEST ${DISABLE_OBSERVER_WRITE_REQUEST}") + message("-- WITH_URING Compile with liburing ${WITH_URING}") + message("------------------------------------------------------------------------") + message("") +endmacro() + diff --git a/cmake/ProjectBLST.cmake b/cmake/ProjectBLST.cmake new file mode 100644 index 0000000..fa4517b --- /dev/null +++ b/cmake/ProjectBLST.cmake @@ -0,0 +1,39 @@ +include(ExternalProject) +include(GNUInstallDirs) + +find_program(BASH_COMMAND NAMES bash REQUIRED PATHS "/bin") +set(BLST_BUILD_COMMAND "${BASH_COMMAND}" build.sh) + +if (NOT BASH_COMMAND) + message(FATAL_ERROR "bash not found") +endif () + +ExternalProject_Add(blst_project + PREFIX ${CMAKE_SOURCE_DIR}/deps + GIT_REPOSITORY https://github.com/supranational/blst.git + GIT_TAG 3dd0f804b1819e5d03fb22ca2e6fac105932043a + GIT_SHALLOW 0 + + CMAKE_ARGS -DCMAKE_INSTALL_PREFIX= + BUILD_IN_SOURCE 1 + CONFIGURE_COMMAND "" + BUILD_COMMAND ${BLST_BUILD_COMMAND} + INSTALL_COMMAND sh -c "cp /bindings/blst.h /include/ && cp /bindings/blst_aux.h /include/ && cp /libblst.a /lib/" + LOG_BUILD true + LOG_INSTALL true + LOG_CONFIGURE true + BUILD_BYPRODUCTS libblst.a +) + +ExternalProject_Get_Property(blst_project INSTALL_DIR) +add_library(blst STATIC IMPORTED) + +set(BLST_LIBRARY ${INSTALL_DIR}/lib/libblst.a) +set(BLST_INCLUDE_DIR ${INSTALL_DIR}/include) +file(MAKE_DIRECTORY ${INSTALL_DIR}/lib/) +file(MAKE_DIRECTORY ${BLST_INCLUDE_DIR}) + +set_property(TARGET blst PROPERTY IMPORTED_LOCATION ${BLST_LIBRARY}) +set_property(TARGET blst PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${BLST_INCLUDE_DIR}) +add_dependencies(blst blst_project) +unset(INSTALL_DIR) \ No newline at end of file diff --git a/cmake/ProjectBoost.cmake b/cmake/ProjectBoost.cmake new file mode 100644 index 0000000..be126db --- /dev/null +++ b/cmake/ProjectBoost.cmake @@ -0,0 +1,145 @@ +include(ExternalProject) +include(GNUInstallDirs) + +include(ProcessorCount) +ProcessorCount(CORES) +if(CORES EQUAL 0) + set(CORES 1) +elseif(CORES GREATER 2) + set(CORES 2) +endif() + +set(BOOST_CXXFLAGS "cxxflags=${MARCH_TYPE}") + +if (APPLE) + set(SED_CMMAND sed -i .bkp) + set(BOOST_BOOTSTRAP_COMMAND ./bootstrap.sh COMMAND ${SED_CMMAND} "s/-fcoalesce-templates//g" ${CMAKE_SOURCE_DIR}/deps/src/boost/tools/build/src/tools/darwin.jam) +else() + set(SED_CMMAND sed -i) + set(BOOST_BOOTSTRAP_COMMAND ./bootstrap.sh) +endif() + +set(BOOST_INSTALL_COMMAND ./b2 install --prefix=${CMAKE_SOURCE_DIR}/deps) +set(BOOST_BUILD_TOOL ./b2) +set(BOOST_LIBRARY_SUFFIX .a) + +set(BOOST_LIB_PREFIX ${CMAKE_SOURCE_DIR}/deps/src/boost/stage/lib/libboost_) +set(BOOST_BUILD_FILES ${BOOST_LIB_PREFIX}chrono.a ${BOOST_LIB_PREFIX}date_time.a + ${BOOST_LIB_PREFIX}random.a ${BOOST_LIB_PREFIX}regex.a + ${BOOST_LIB_PREFIX}filesystem.a ${BOOST_LIB_PREFIX}system.a + ${BOOST_LIB_PREFIX}unit_test_framework.a ${BOOST_LIB_PREFIX}log.a + ${BOOST_LIB_PREFIX}thread.a ${BOOST_LIB_PREFIX}program_options.a + ${BOOST_LIB_PREFIX}serialization.a) + +ExternalProject_Add(boost + PREFIX ${CMAKE_SOURCE_DIR}/deps + DOWNLOAD_NO_PROGRESS 1 + URL https://archives.boost.io/release/1.86.0/source/boost_1_86_0.tar.gz + URL_HASH SHA256=2575e74ffc3ef1cd0babac2c1ee8bdb5782a0ee672b1912da40e5b4b591ca01f + BUILD_IN_SOURCE 1 + CONFIGURE_COMMAND ${BOOST_BOOTSTRAP_COMMAND} + BUILD_COMMAND ${BOOST_BUILD_TOOL} stage + ${BOOST_CXXFLAGS} + threading=multi + link=static + variant=release + address-model=64 + --with-chrono + --with-date_time + --with-filesystem + --with-system + --with-random + --with-regex + --with-test + --with-thread + --with-serialization + --with-program_options + --with-log + --with-iostreams + -s NO_BZIP2=1 -s NO_LZMA=1 -s NO_ZSTD=1 + -j${CORES} + LOG_CONFIGURE 1 + LOG_BUILD 1 + LOG_INSTALL 1 + INSTALL_COMMAND "" + # INSTALL_COMMAND ${BOOST_INSTALL_COMMAND} + BUILD_BYPRODUCTS ${BOOST_BUILD_FILES} +) + +ExternalProject_Get_Property(boost SOURCE_DIR) +set(BOOST_INCLUDE_DIR ${SOURCE_DIR}) +set(BOOST_LIB_DIR ${SOURCE_DIR}/stage/lib) + +add_library(Boost::System STATIC IMPORTED GLOBAL) +set_property(TARGET Boost::System PROPERTY IMPORTED_LOCATION ${BOOST_LIB_DIR}/libboost_system${BOOST_LIBRARY_SUFFIX}) +set_property(TARGET Boost::System PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${BOOST_INCLUDE_DIR}) +add_dependencies(Boost::System boost) + +add_library(Boost::Chrono STATIC IMPORTED GLOBAL) +set_property(TARGET Boost::Chrono PROPERTY IMPORTED_LOCATION ${BOOST_LIB_DIR}/libboost_chrono${BOOST_LIBRARY_SUFFIX}) +add_dependencies(Boost::Chrono boost) + +add_library(Boost::DataTime STATIC IMPORTED GLOBAL) +set_property(TARGET Boost::DataTime PROPERTY IMPORTED_LOCATION ${BOOST_LIB_DIR}/libboost_date_time${BOOST_LIBRARY_SUFFIX}) +set_property(TARGET Boost::DataTime PROPERTY INTERFACE_LINK_LIBRARIES Boost::System) +add_dependencies(Boost::DataTime boost) + +add_library(Boost::Regex STATIC IMPORTED GLOBAL) +set_property(TARGET Boost::Regex PROPERTY IMPORTED_LOCATION ${BOOST_LIB_DIR}/libboost_regex${BOOST_LIBRARY_SUFFIX}) +set_property(TARGET Boost::Regex PROPERTY INTERFACE_LINK_LIBRARIES Boost::System) +add_dependencies(Boost::Regex boost) + +add_library(Boost::Filesystem STATIC IMPORTED GLOBAL) +set_property(TARGET Boost::Filesystem PROPERTY IMPORTED_LOCATION ${BOOST_LIB_DIR}/libboost_filesystem${BOOST_LIBRARY_SUFFIX}) +set_property(TARGET Boost::Filesystem PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${BOOST_INCLUDE_DIR}) +set_property(TARGET Boost::Filesystem PROPERTY INTERFACE_LINK_LIBRARIES Boost::System) +add_dependencies(Boost::Filesystem boost) + +add_library(Boost::Random STATIC IMPORTED GLOBAL) +set_property(TARGET Boost::Random PROPERTY IMPORTED_LOCATION ${BOOST_LIB_DIR}/libboost_random${BOOST_LIBRARY_SUFFIX}) +add_dependencies(Boost::Random boost) + +add_library(Boost::UnitTestFramework STATIC IMPORTED GLOBAL) +set_property(TARGET Boost::UnitTestFramework PROPERTY IMPORTED_LOCATION ${BOOST_LIB_DIR}/libboost_unit_test_framework${BOOST_LIBRARY_SUFFIX}) +set_property(TARGET Boost::UnitTestFramework PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${BOOST_INCLUDE_DIR}) +add_dependencies(Boost::UnitTestFramework boost) + +add_library(Boost::Thread STATIC IMPORTED GLOBAL) +set_property(TARGET Boost::Thread PROPERTY IMPORTED_LOCATION ${BOOST_LIB_DIR}/libboost_thread${BOOST_LIBRARY_SUFFIX}) +set_property(TARGET Boost::Thread PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${BOOST_INCLUDE_DIR}) +set_property(TARGET Boost::Thread PROPERTY INTERFACE_LINK_LIBRARIES Boost::Chrono Boost::DataTime Boost::Regex) +add_dependencies(Boost::Thread boost) + +add_library(Boost::program_options STATIC IMPORTED GLOBAL) +set_property(TARGET Boost::program_options PROPERTY IMPORTED_LOCATION ${BOOST_LIB_DIR}/libboost_program_options${BOOST_LIBRARY_SUFFIX}) +set_property(TARGET Boost::program_options PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${BOOST_INCLUDE_DIR}) +add_dependencies(Boost::program_options boost) + +add_library(Boost::Log STATIC IMPORTED GLOBAL) +set_property(TARGET Boost::Log PROPERTY IMPORTED_LOCATION ${BOOST_LIB_DIR}/libboost_log${BOOST_LIBRARY_SUFFIX}) +set_property(TARGET Boost::Log PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${BOOST_INCLUDE_DIR}) +set_property(TARGET Boost::Log PROPERTY INTERFACE_LINK_LIBRARIES Boost::Filesystem Boost::Thread) +add_dependencies(Boost::Log boost) + +add_library(Boost::LogSetup STATIC IMPORTED GLOBAL) +set_property(TARGET Boost::LogSetup PROPERTY IMPORTED_LOCATION ${BOOST_LIB_DIR}/libboost_log_setup${BOOST_LIBRARY_SUFFIX}) +set_property(TARGET Boost::LogSetup PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${BOOST_INCLUDE_DIR}) +# set_property(TARGET Boost::LogSetup PROPERTY INTERFACE_LINK_LIBRARIES Boost::Filesystem Boost::Thread) +add_dependencies(Boost::LogSetup boost) + +add_library(Boost::Serialization STATIC IMPORTED GLOBAL) +set_property(TARGET Boost::Serialization PROPERTY IMPORTED_LOCATION ${BOOST_LIB_DIR}/libboost_serialization${BOOST_LIBRARY_SUFFIX}) +set_property(TARGET Boost::Serialization PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${BOOST_INCLUDE_DIR}) +add_dependencies(Boost::Serialization boost) + +# for boost compress/base64encode +add_library(Boost::iostreams STATIC IMPORTED GLOBAL) +set_property(TARGET Boost::iostreams PROPERTY IMPORTED_LOCATION ${BOOST_LIB_DIR}/libboost_iostreams${BOOST_LIBRARY_SUFFIX}) +set_property(TARGET Boost::iostreams PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${BOOST_INCLUDE_DIR}) +if(NOT APPLE) + # set_property(TARGET Boost::iostreams PROPERTY INTERFACE_LINK_LIBRARIES z) + find_package(ZLIB REQUIRED) + set_property(TARGET Boost::iostreams PROPERTY INTERFACE_LINK_LIBRARIES ZLIB::ZLIB) +endif() +add_dependencies(Boost::iostreams boost) +unset(SOURCE_DIR) \ No newline at end of file diff --git a/cmake/config.cmake b/cmake/config.cmake deleted file mode 100644 index a3fb784..0000000 --- a/cmake/config.cmake +++ /dev/null @@ -1,11 +0,0 @@ -hunter_config( - Boost VERSION "1.79.0" - URL - "https://osp-1257653870.cos.ap-guangzhou.myqcloud.com/FISCO-BCOS/FISCO-BCOS/deps/boost_1_79_0.tar.bz2 - https://downloads.sourceforge.net/project/boost/boost/1.79.0/source/boost_1_79_0.tar.bz2 - https://nchc.dl.sourceforge.net/project/boost/boost/1.79.0/boost_1_79_0.tar.bz2" - SHA1 - 31209dcff292bd6a64e5e08ceb3ce44a33615dc0 - CMAKE_ARGS - CONFIG_MACRO=BOOST_UUID_RANDOM_PROVIDER_FORCE_POSIX -) \ No newline at end of file diff --git a/verkle-cmake-scripts/HunterGate.cmake b/verkle-cmake-scripts/HunterGate.cmake deleted file mode 100644 index ec6399a..0000000 --- a/verkle-cmake-scripts/HunterGate.cmake +++ /dev/null @@ -1,541 +0,0 @@ -# Copyright (c) 2013-2019, Ruslan Baratov -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -# This is a gate file to Hunter package manager. -# Include this file using `include` command and add package you need, example: -# -# cmake_minimum_required(VERSION 3.2) -# -# include("cmake/HunterGate.cmake") -# HunterGate( -# URL "https://github.com/path/to/hunter/archive.tar.gz" -# SHA1 "798501e983f14b28b10cda16afa4de69eee1da1d" -# ) -# -# project(MyProject) -# -# hunter_add_package(Foo) -# hunter_add_package(Boo COMPONENTS Bar Baz) -# -# Projects: -# * https://github.com/hunter-packages/gate/ -# * https://github.com/ruslo/hunter - -option(HUNTER_ENABLED "Enable Hunter package manager support" ON) - -if(HUNTER_ENABLED) - if(CMAKE_VERSION VERSION_LESS "3.2") - message( - FATAL_ERROR - "At least CMake version 3.2 required for Hunter dependency management." - " Update CMake or set HUNTER_ENABLED to OFF." - ) - endif() -endif() - -include(CMakeParseArguments) # cmake_parse_arguments - -option(HUNTER_STATUS_PRINT "Print working status" ON) -option(HUNTER_STATUS_DEBUG "Print a lot info" OFF) -option(HUNTER_TLS_VERIFY "Enable/disable TLS certificate checking on downloads" ON) - -set(HUNTER_ERROR_PAGE "https://docs.hunter.sh/en/latest/reference/errors") - -function(hunter_gate_status_print) - if(HUNTER_STATUS_PRINT OR HUNTER_STATUS_DEBUG) - foreach(print_message ${ARGV}) - message(STATUS "[hunter] ${print_message}") - endforeach() - endif() -endfunction() - -function(hunter_gate_status_debug) - if(HUNTER_STATUS_DEBUG) - foreach(print_message ${ARGV}) - string(TIMESTAMP timestamp) - message(STATUS "[hunter *** DEBUG *** ${timestamp}] ${print_message}") - endforeach() - endif() -endfunction() - -function(hunter_gate_error_page error_page) - message("------------------------------ ERROR ------------------------------") - message(" ${HUNTER_ERROR_PAGE}/${error_page}.html") - message("-------------------------------------------------------------------") - message("") - message(FATAL_ERROR "") -endfunction() - -function(hunter_gate_internal_error) - message("") - foreach(print_message ${ARGV}) - message("[hunter ** INTERNAL **] ${print_message}") - endforeach() - message("[hunter ** INTERNAL **] [Directory:${CMAKE_CURRENT_LIST_DIR}]") - message("") - hunter_gate_error_page("error.internal") -endfunction() - -function(hunter_gate_fatal_error) - cmake_parse_arguments(hunter "" "ERROR_PAGE" "" "${ARGV}") - if("${hunter_ERROR_PAGE}" STREQUAL "") - hunter_gate_internal_error("Expected ERROR_PAGE") - endif() - message("") - foreach(x ${hunter_UNPARSED_ARGUMENTS}) - message("[hunter ** FATAL ERROR **] ${x}") - endforeach() - message("[hunter ** FATAL ERROR **] [Directory:${CMAKE_CURRENT_LIST_DIR}]") - message("") - hunter_gate_error_page("${hunter_ERROR_PAGE}") -endfunction() - -function(hunter_gate_user_error) - hunter_gate_fatal_error(${ARGV} ERROR_PAGE "error.incorrect.input.data") -endfunction() - -function(hunter_gate_self root version sha1 result) - string(COMPARE EQUAL "${root}" "" is_bad) - if(is_bad) - hunter_gate_internal_error("root is empty") - endif() - - string(COMPARE EQUAL "${version}" "" is_bad) - if(is_bad) - hunter_gate_internal_error("version is empty") - endif() - - string(COMPARE EQUAL "${sha1}" "" is_bad) - if(is_bad) - hunter_gate_internal_error("sha1 is empty") - endif() - - string(SUBSTRING "${sha1}" 0 7 archive_id) - - if(EXISTS "${root}/cmake/Hunter") - set(hunter_self "${root}") - else() - set( - hunter_self - "${root}/_Base/Download/Hunter/${version}/${archive_id}/Unpacked" - ) - endif() - - set("${result}" "${hunter_self}" PARENT_SCOPE) -endfunction() - -# Set HUNTER_GATE_ROOT cmake variable to suitable value. -function(hunter_gate_detect_root) - # Check CMake variable - string(COMPARE NOTEQUAL "${HUNTER_ROOT}" "" not_empty) - if(not_empty) - set(HUNTER_GATE_ROOT "${HUNTER_ROOT}" PARENT_SCOPE) - hunter_gate_status_debug("HUNTER_ROOT detected by cmake variable") - return() - endif() - - # Check environment variable - string(COMPARE NOTEQUAL "$ENV{HUNTER_ROOT}" "" not_empty) - if(not_empty) - set(HUNTER_GATE_ROOT "$ENV{HUNTER_ROOT}" PARENT_SCOPE) - hunter_gate_status_debug("HUNTER_ROOT detected by environment variable") - return() - endif() - - # Check HOME environment variable - string(COMPARE NOTEQUAL "$ENV{HOME}" "" result) - if(result) - set(HUNTER_GATE_ROOT "$ENV{HOME}/.hunter" PARENT_SCOPE) - hunter_gate_status_debug("HUNTER_ROOT set using HOME environment variable") - return() - endif() - - # Check SYSTEMDRIVE and USERPROFILE environment variable (windows only) - if(WIN32) - string(COMPARE NOTEQUAL "$ENV{SYSTEMDRIVE}" "" result) - if(result) - set(HUNTER_GATE_ROOT "$ENV{SYSTEMDRIVE}/.hunter" PARENT_SCOPE) - hunter_gate_status_debug( - "HUNTER_ROOT set using SYSTEMDRIVE environment variable" - ) - return() - endif() - - string(COMPARE NOTEQUAL "$ENV{USERPROFILE}" "" result) - if(result) - set(HUNTER_GATE_ROOT "$ENV{USERPROFILE}/.hunter" PARENT_SCOPE) - hunter_gate_status_debug( - "HUNTER_ROOT set using USERPROFILE environment variable" - ) - return() - endif() - endif() - - hunter_gate_fatal_error( - "Can't detect HUNTER_ROOT" - ERROR_PAGE "error.detect.hunter.root" - ) -endfunction() - -function(hunter_gate_download dir) - string( - COMPARE - NOTEQUAL - "$ENV{HUNTER_DISABLE_AUTOINSTALL}" - "" - disable_autoinstall - ) - if(disable_autoinstall AND NOT HUNTER_RUN_INSTALL) - hunter_gate_fatal_error( - "Hunter not found in '${dir}'" - "Set HUNTER_RUN_INSTALL=ON to auto-install it from '${HUNTER_GATE_URL}'" - "Settings:" - " HUNTER_ROOT: ${HUNTER_GATE_ROOT}" - " HUNTER_SHA1: ${HUNTER_GATE_SHA1}" - ERROR_PAGE "error.run.install" - ) - endif() - string(COMPARE EQUAL "${dir}" "" is_bad) - if(is_bad) - hunter_gate_internal_error("Empty 'dir' argument") - endif() - - string(COMPARE EQUAL "${HUNTER_GATE_SHA1}" "" is_bad) - if(is_bad) - hunter_gate_internal_error("HUNTER_GATE_SHA1 empty") - endif() - - string(COMPARE EQUAL "${HUNTER_GATE_URL}" "" is_bad) - if(is_bad) - hunter_gate_internal_error("HUNTER_GATE_URL empty") - endif() - - set(done_location "${dir}/DONE") - set(sha1_location "${dir}/SHA1") - - set(build_dir "${dir}/Build") - set(cmakelists "${dir}/CMakeLists.txt") - - hunter_gate_status_debug("Locking directory: ${dir}") - file(LOCK "${dir}" DIRECTORY GUARD FUNCTION) - hunter_gate_status_debug("Lock done") - - if(EXISTS "${done_location}") - # while waiting for lock other instance can do all the job - hunter_gate_status_debug("File '${done_location}' found, skip install") - return() - endif() - - file(REMOVE_RECURSE "${build_dir}") - file(REMOVE_RECURSE "${cmakelists}") - - file(MAKE_DIRECTORY "${build_dir}") # check directory permissions - - # Disabling languages speeds up a little bit, reduces noise in the output - # and avoids path too long windows error - file( - WRITE - "${cmakelists}" - "cmake_minimum_required(VERSION 3.2)\n" - "project(HunterDownload LANGUAGES NONE)\n" - "include(ExternalProject)\n" - "ExternalProject_Add(\n" - " Hunter\n" - " URL\n" - " \"${HUNTER_GATE_URL}\"\n" - " URL_HASH\n" - " SHA1=${HUNTER_GATE_SHA1}\n" - " DOWNLOAD_DIR\n" - " \"${dir}\"\n" - " TLS_VERIFY\n" - " ${HUNTER_TLS_VERIFY}\n" - " SOURCE_DIR\n" - " \"${dir}/Unpacked\"\n" - " CONFIGURE_COMMAND\n" - " \"\"\n" - " BUILD_COMMAND\n" - " \"\"\n" - " INSTALL_COMMAND\n" - " \"\"\n" - ")\n" - ) - - if(HUNTER_STATUS_DEBUG) - set(logging_params "") - else() - set(logging_params OUTPUT_QUIET) - endif() - - hunter_gate_status_debug("Run generate") - - # Need to add toolchain file too. - # Otherwise on Visual Studio + MDD this will fail with error: - # "Could not find an appropriate version of the Windows 10 SDK installed on this machine" - if(EXISTS "${CMAKE_TOOLCHAIN_FILE}") - get_filename_component(absolute_CMAKE_TOOLCHAIN_FILE "${CMAKE_TOOLCHAIN_FILE}" ABSOLUTE) - set(toolchain_arg "-DCMAKE_TOOLCHAIN_FILE=${absolute_CMAKE_TOOLCHAIN_FILE}") - else() - # 'toolchain_arg' can't be empty - set(toolchain_arg "-DCMAKE_TOOLCHAIN_FILE=") - endif() - - string(COMPARE EQUAL "${CMAKE_MAKE_PROGRAM}" "" no_make) - if(no_make) - set(make_arg "") - else() - # Test case: remove Ninja from PATH but set it via CMAKE_MAKE_PROGRAM - set(make_arg "-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}") - endif() - - execute_process( - COMMAND - "${CMAKE_COMMAND}" - "-H${dir}" - "-B${build_dir}" - "-G${CMAKE_GENERATOR}" - "${toolchain_arg}" - ${make_arg} - WORKING_DIRECTORY "${dir}" - RESULT_VARIABLE download_result - ${logging_params} - ) - - if(NOT download_result EQUAL 0) - hunter_gate_internal_error( - "Configure project failed." - "To reproduce the error run: ${CMAKE_COMMAND} -H${dir} -B${build_dir} -G${CMAKE_GENERATOR} ${toolchain_arg} ${make_arg}" - "In directory ${dir}" - ) - endif() - - hunter_gate_status_print( - "Initializing Hunter workspace (${HUNTER_GATE_SHA1})" - " ${HUNTER_GATE_URL}" - " -> ${dir}" - ) - execute_process( - COMMAND "${CMAKE_COMMAND}" --build "${build_dir}" - WORKING_DIRECTORY "${dir}" - RESULT_VARIABLE download_result - ${logging_params} - ) - - if(NOT download_result EQUAL 0) - hunter_gate_internal_error("Build project failed") - endif() - - file(REMOVE_RECURSE "${build_dir}") - file(REMOVE_RECURSE "${cmakelists}") - - file(WRITE "${sha1_location}" "${HUNTER_GATE_SHA1}") - file(WRITE "${done_location}" "DONE") - - hunter_gate_status_debug("Finished") -endfunction() - -# Must be a macro so master file 'cmake/Hunter' can -# apply all variables easily just by 'include' command -# (otherwise PARENT_SCOPE magic needed) -macro(HunterGate) - if(HUNTER_GATE_DONE) - # variable HUNTER_GATE_DONE set explicitly for external project - # (see `hunter_download`) - set_property(GLOBAL PROPERTY HUNTER_GATE_DONE YES) - endif() - - # First HunterGate command will init Hunter, others will be ignored - get_property(_hunter_gate_done GLOBAL PROPERTY HUNTER_GATE_DONE SET) - - if(NOT HUNTER_ENABLED) - # Empty function to avoid error "unknown function" - function(hunter_add_package) - endfunction() - - set( - _hunter_gate_disabled_mode_dir - "${CMAKE_CURRENT_LIST_DIR}/cmake/Hunter/disabled-mode" - ) - if(EXISTS "${_hunter_gate_disabled_mode_dir}") - hunter_gate_status_debug( - "Adding \"disabled-mode\" modules: ${_hunter_gate_disabled_mode_dir}" - ) - list(APPEND CMAKE_PREFIX_PATH "${_hunter_gate_disabled_mode_dir}") - endif() - elseif(_hunter_gate_done) - hunter_gate_status_debug("Secondary HunterGate (use old settings)") - hunter_gate_self( - "${HUNTER_CACHED_ROOT}" - "${HUNTER_VERSION}" - "${HUNTER_SHA1}" - _hunter_self - ) - include("${_hunter_self}/cmake/Hunter") - else() - set(HUNTER_GATE_LOCATION ".") - - string(COMPARE NOTEQUAL "${PROJECT_NAME}" "" _have_project_name) - if(_have_project_name) - hunter_gate_fatal_error( - "Please set HunterGate *before* 'project' command. " - "Detected project: ${PROJECT_NAME}" - ERROR_PAGE "error.huntergate.before.project" - ) - endif() - - cmake_parse_arguments( - HUNTER_GATE "LOCAL" "URL;SHA1;GLOBAL;FILEPATH" "" ${ARGV} - ) - - string(COMPARE EQUAL "${HUNTER_GATE_SHA1}" "" _empty_sha1) - string(COMPARE EQUAL "${HUNTER_GATE_URL}" "" _empty_url) - string( - COMPARE - NOTEQUAL - "${HUNTER_GATE_UNPARSED_ARGUMENTS}" - "" - _have_unparsed - ) - string(COMPARE NOTEQUAL "${HUNTER_GATE_GLOBAL}" "" _have_global) - string(COMPARE NOTEQUAL "${HUNTER_GATE_FILEPATH}" "" _have_filepath) - - if(_have_unparsed) - hunter_gate_user_error( - "HunterGate unparsed arguments: ${HUNTER_GATE_UNPARSED_ARGUMENTS}" - ) - endif() - if(_empty_sha1) - hunter_gate_user_error("SHA1 suboption of HunterGate is mandatory") - endif() - if(_empty_url) - hunter_gate_user_error("URL suboption of HunterGate is mandatory") - endif() - if(_have_global) - if(HUNTER_GATE_LOCAL) - hunter_gate_user_error("Unexpected LOCAL (already has GLOBAL)") - endif() - if(_have_filepath) - hunter_gate_user_error("Unexpected FILEPATH (already has GLOBAL)") - endif() - endif() - if(HUNTER_GATE_LOCAL) - if(_have_global) - hunter_gate_user_error("Unexpected GLOBAL (already has LOCAL)") - endif() - if(_have_filepath) - hunter_gate_user_error("Unexpected FILEPATH (already has LOCAL)") - endif() - endif() - if(_have_filepath) - if(_have_global) - hunter_gate_user_error("Unexpected GLOBAL (already has FILEPATH)") - endif() - if(HUNTER_GATE_LOCAL) - hunter_gate_user_error("Unexpected LOCAL (already has FILEPATH)") - endif() - endif() - - hunter_gate_detect_root() # set HUNTER_GATE_ROOT - - # Beautify path, fix probable problems with windows path slashes - get_filename_component( - HUNTER_GATE_ROOT "${HUNTER_GATE_ROOT}" ABSOLUTE - ) - hunter_gate_status_debug("HUNTER_ROOT: ${HUNTER_GATE_ROOT}") - if(NOT HUNTER_ALLOW_SPACES_IN_PATH) - string(FIND "${HUNTER_GATE_ROOT}" " " _contain_spaces) - if(NOT _contain_spaces EQUAL -1) - hunter_gate_fatal_error( - "HUNTER_ROOT (${HUNTER_GATE_ROOT}) contains spaces." - "Set HUNTER_ALLOW_SPACES_IN_PATH=ON to skip this error" - "(Use at your own risk!)" - ERROR_PAGE "error.spaces.in.hunter.root" - ) - endif() - endif() - - string( - REGEX - MATCH - "[0-9]+\\.[0-9]+\\.[0-9]+[-_a-z0-9]*" - HUNTER_GATE_VERSION - "${HUNTER_GATE_URL}" - ) - string(COMPARE EQUAL "${HUNTER_GATE_VERSION}" "" _is_empty) - if(_is_empty) - set(HUNTER_GATE_VERSION "unknown") - endif() - - hunter_gate_self( - "${HUNTER_GATE_ROOT}" - "${HUNTER_GATE_VERSION}" - "${HUNTER_GATE_SHA1}" - _hunter_self - ) - - set(_master_location "${_hunter_self}/cmake/Hunter") - if(EXISTS "${HUNTER_GATE_ROOT}/cmake/Hunter") - # Hunter downloaded manually (e.g. by 'git clone') - set(_unused "xxxxxxxxxx") - set(HUNTER_GATE_SHA1 "${_unused}") - set(HUNTER_GATE_VERSION "${_unused}") - else() - get_filename_component(_archive_id_location "${_hunter_self}/.." ABSOLUTE) - set(_done_location "${_archive_id_location}/DONE") - set(_sha1_location "${_archive_id_location}/SHA1") - - # Check Hunter already downloaded by HunterGate - if(NOT EXISTS "${_done_location}") - hunter_gate_download("${_archive_id_location}") - endif() - - if(NOT EXISTS "${_done_location}") - hunter_gate_internal_error("hunter_gate_download failed") - endif() - - if(NOT EXISTS "${_sha1_location}") - hunter_gate_internal_error("${_sha1_location} not found") - endif() - file(READ "${_sha1_location}" _sha1_value) - string(TOLOWER "${_sha1_value}" _sha1_value_lower) - string(TOLOWER "${HUNTER_GATE_SHA1}" _HUNTER_GATE_SHA1_lower) - string(COMPARE EQUAL "${_sha1_value_lower}" "${_HUNTER_GATE_SHA1_lower}" _is_equal) - if(NOT _is_equal) - hunter_gate_internal_error( - "Short SHA1 collision:" - " ${_sha1_value} (from ${_sha1_location})" - " ${HUNTER_GATE_SHA1} (HunterGate)" - ) - endif() - if(NOT EXISTS "${_master_location}") - hunter_gate_user_error( - "Master file not found:" - " ${_master_location}" - "try to update Hunter/HunterGate" - ) - endif() - endif() - include("${_master_location}") - set_property(GLOBAL PROPERTY HUNTER_GATE_DONE YES) - endif() -endmacro() From c0dd8395a310c216215bc5a98cb503d8a277c3d7 Mon Sep 17 00:00:00 2001 From: gzx Date: Sun, 18 Aug 2024 04:17:55 +0800 Subject: [PATCH 05/12] add vcpkg config --- CMakeLists.txt | 8 +- CMakePresets.json | 13 ++ bandersnatch/CMakeLists.txt | 5 +- bandersnatch/src/Element.h | 41 ++--- bandersnatch/src/Fr.h | 33 ++-- bandersnatch/test/CMakeLists.txt | 8 +- bandersnatch/test/unittests/ElementTest.cpp | 1 + cmake/CompilerSettings.cmake | 160 ----------------- cmake/Options.cmake | 182 -------------------- cmake/ProjectBoost.cmake | 145 ---------------- vcpkg-configuration.json | 14 ++ vcpkg.json | 8 + 12 files changed, 80 insertions(+), 538 deletions(-) create mode 100644 CMakePresets.json delete mode 100644 cmake/CompilerSettings.cmake delete mode 100644 cmake/Options.cmake delete mode 100644 cmake/ProjectBoost.cmake create mode 100644 vcpkg-configuration.json create mode 100644 vcpkg.json diff --git a/CMakeLists.txt b/CMakeLists.txt index 462c880..9c5822e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,15 +1,13 @@ cmake_minimum_required(VERSION 3.10) project(verkle_tree) -# set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD 20) set(VERKLE_CMAKE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/cmake") list(APPEND CMAKE_MODULE_PATH ${VERKLE_CMAKE_DIR}) -include(Options) -configure_project() -include(CompilerSettings) + include(ProjectBLST) -include(ProjectBoost) +# include(ProjectBoost) add_subdirectory(bandersnatch) diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 0000000..3fefc1f --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,13 @@ +{ + "version": 2, + "configurePresets": [ + { + "name": "default", + "generator": "Visual Studio 17 2022", + "binaryDir": "${sourceDir}/build", + "cacheVariables": { + "CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" + } + } + ] +} \ No newline at end of file diff --git a/bandersnatch/CMakeLists.txt b/bandersnatch/CMakeLists.txt index a0ad2e4..e5a5214 100644 --- a/bandersnatch/CMakeLists.txt +++ b/bandersnatch/CMakeLists.txt @@ -1,7 +1,6 @@ cmake_minimum_required(VERSION 3.10) project(bandersnatch) -# set(CMAKE_CXX_STANDARD 20) file(GLOB_RECURSE SRCS "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp") file(GLOB_RECURSE HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/src/*.h") @@ -10,7 +9,7 @@ add_library(bandersnatch ${SRCS} ${HEADERS}) target_link_libraries(bandersnatch PRIVATE blst) # if (TESTS) - # enable_testing() - # set(CTEST_OUTPUT_ON_FAILURE TRUE) +# enable_testing() +# set(CTEST_OUTPUT_ON_FAILURE TRUE) add_subdirectory(test) # endif() diff --git a/bandersnatch/src/Element.h b/bandersnatch/src/Element.h index d44328d..3042ce5 100644 --- a/bandersnatch/src/Element.h +++ b/bandersnatch/src/Element.h @@ -5,30 +5,27 @@ #include #include "Fr.h" -namespace verkle +namespace verkle::bandersnatch { - namespace bandersnatch - { - class Element - { - public: - Element(); - explicit Element(const blst_p1& point); - Element(const byte *in, size_t len); +class Element +{ +public: + Element(); + explicit Element(const blst_p1& point); + Element(const byte *in, size_t len); - Element& add(const Element& other); - Element& dbl(); - Element& mult(const Fr& fr); - static Element add(const Element& a, const Element& b); - static Element dbl(const Element& a); - static Element mult(const Fr& fr, const Element& a); + Element& add(const Element& other); + Element& dbl(); + Element& mult(const Fr& fr); + static Element add(const Element& a, const Element& b); + static Element dbl(const Element& a); + static Element mult(const Fr& fr, const Element& a); - static Element generator(); + static Element generator(); - void serialize(byte out[96]) const; + void serialize(byte out[96]) const; - private: - std::shared_ptr m_point; - }; - } - } \ No newline at end of file +private: + std::shared_ptr m_point; +}; +} \ No newline at end of file diff --git a/bandersnatch/src/Fr.h b/bandersnatch/src/Fr.h index d4dca5b..69860cb 100644 --- a/bandersnatch/src/Fr.h +++ b/bandersnatch/src/Fr.h @@ -5,27 +5,24 @@ #include #include -namespace verkle +namespace verkle::bandersnatch { - namespace bandersnatch - { - class Fr - { - public: - Fr(); - Fr(const byte* msg, size_t len); +class Fr +{ +public: + Fr(); + Fr(const byte* msg, size_t len); - Fr operator+(const Fr& other) const; - Fr operator-(const Fr& other) const; - Fr operator*(const Fr& other) const; - Fr inv() const; + Fr operator+(const Fr& other) const; + Fr operator-(const Fr& other) const; + Fr operator*(const Fr& other) const; + Fr inv() const; - std::shared_ptr toScalar() const; + std::shared_ptr toScalar() const; - void serialize(uint64_t ret[4]) const; + void serialize(uint64_t ret[4]) const; - private: - std::unique_ptr m_val; - }; - } +private: + std::unique_ptr m_val; +}; } \ No newline at end of file diff --git a/bandersnatch/test/CMakeLists.txt b/bandersnatch/test/CMakeLists.txt index 59379f8..b58b93b 100644 --- a/bandersnatch/test/CMakeLists.txt +++ b/bandersnatch/test/CMakeLists.txt @@ -1,8 +1,10 @@ file(GLOB_RECURSE TEST_SRCS "*.cpp") - - add_executable(bandersnatch-test ${TEST_SRCS}) target_include_directories(bandersnatch-test PRIVATE .) -target_link_libraries(bandersnatch-test bandersnatch Boost::UnitTestFramework) + +find_package(boost_unit_test_framework CONFIG REQUIRED) +find_package(boost_log CONFIG REQUIRED) + +target_link_libraries(bandersnatch-test bandersnatch Boost::unit_test_framework Boost::log) # add_test(NAME test-bandersnatch WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} COMMAND bandersnatch-test) diff --git a/bandersnatch/test/unittests/ElementTest.cpp b/bandersnatch/test/unittests/ElementTest.cpp index f2fed56..be8b733 100644 --- a/bandersnatch/test/unittests/ElementTest.cpp +++ b/bandersnatch/test/unittests/ElementTest.cpp @@ -8,5 +8,6 @@ namespace verkle { BOOST_AUTO_TEST_SUITE(TEST) BOOST_AUTO_TEST_SUITE_END() + } } \ No newline at end of file diff --git a/cmake/CompilerSettings.cmake b/cmake/CompilerSettings.cmake deleted file mode 100644 index 441bedc..0000000 --- a/cmake/CompilerSettings.cmake +++ /dev/null @@ -1,160 +0,0 @@ -#------------------------------------------------------------------------------ -# Setting compiling for FISCO-BCOS. -# ------------------------------------------------------------------------------ -# This file is part of FISCO-BCOS. -# -# FISCO-BCOS is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# FISCO-BCOS is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with FISCO-BCOS. If not, see -# -# (c) 2016-2018 fisco-dev contributors. -#------------------------------------------------------------------------------ - -if (("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")) - find_program(CCACHE_PROGRAM ccache) - if(CCACHE_PROGRAM) - set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}") - set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "${CCACHE_PROGRAM}") - endif() - # set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "/usr/bin/time") - # set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "/usr/bin/time") - # Use ISO C++14 standard language. - set(CMAKE_CXX_FLAGS "-std=c++14 -pthread -fPIC -fvisibility=hidden -fvisibility-inlines-hidden -fexceptions") - set(CMAKE_CXX_VISIBILITY_PRESET hidden) - # Enables all the warnings about constructions that some users consider questionable, - # and that are easy to avoid. Also enable some extra warning flags that are not - # enabled by -Wall. Finally, treat at warnings-as-errors, which forces developers - # to fix warnings as they arise, so they don't accumulate "to be fixed later". - add_compile_options(-Werror) - add_compile_options(-Wall) - add_compile_options(-pedantic) - add_compile_options(-Wextra) - # add_compile_options(-Wno-unused-variable) - # add_compile_options(-Wno-unused-parameter) - # add_compile_options(-Wno-unused-function) - # add_compile_options(-Wno-missing-field-initializers) - # Disable warnings about unknown pragmas (which is enabled by -Wall). - add_compile_options(-Wno-unknown-pragmas) - add_compile_options(-fno-omit-frame-pointer) - # for boost json spirit - add_compile_options(-DBOOST_SPIRIT_THREADSAFE) - # for tbb, TODO: https://software.intel.com/sites/default/files/managed/b2/d2/TBBRevamp.pdf - add_compile_options(-DTBB_SUPPRESS_DEPRECATED_MESSAGES=1) - # build deps lib Release - set(_only_release_configuration "-DCMAKE_BUILD_TYPE=Release") - - if(BUILD_STATIC) - SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a") - SET(BUILD_SHARED_LIBRARIES OFF) - SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static") - # SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Bdynamic -ldl -lpthread -Wl,-Bstatic -static-libstdc++ ") - endif () - - if(TESTS) - add_compile_options(-DBOOST_TEST_THREAD_SAFE) - endif () - - if(PROF) - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg") - SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg") - SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -pg") - endif () - - # Configuration-specific compiler settings. - set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -DFISCO_DEBUG") - set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG") - set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG") - set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g") - - if (USE_LD_GOLD) - # message("CompilerSettings: USE_LD_GOLD") - execute_process(COMMAND ${CMAKE_C_COMPILER} -fuse-ld=gold -Wl,--version ERROR_QUIET OUTPUT_VARIABLE LD_VERSION) - if ("${LD_VERSION}" MATCHES "GNU gold") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=gold") - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=gold") - endif () - endif () - - # Additional GCC-specific compiler settings. - if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") - # Check that we've got GCC 5.4 or newer. - execute_process( - COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION) - if (NOT (GCC_VERSION VERSION_GREATER 5.4 OR GCC_VERSION VERSION_EQUAL 5.4)) - message(FATAL_ERROR "${PROJECT_NAME} requires g++ 5.4 or greater. Current is ${GCC_VERSION}") - endif () - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MARCH_TYPE}") - set(CMAKE_C_FLAGS "-std=c99 ${CMAKE_C_FLAGS} ${MARCH_TYPE}") - - # Strong stack protection was only added in GCC 4.9. - # Use it if we have the option to do so. - # See https://lwn.net/Articles/584225/ - if (GCC_VERSION VERSION_GREATER 4.9 OR GCC_VERSION VERSION_EQUAL 4.9) - add_compile_options(-fstack-protector-strong) - add_compile_options(-fstack-protector) - endif() - # Additional Clang-specific compiler settings. - elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") - if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.0) - set(CMAKE_CXX_FLAGS_DEBUG "-O -g -DFISCO_DEBUG") - endif() - # set(CMAKE_CXX_FLAGS "-stdlib=libc++ ${CMAKE_CXX_FLAGS}") - add_compile_options(-fstack-protector) - add_compile_options(-Winconsistent-missing-override) - # Some Linux-specific Clang settings. We don't want these for OS X. - if ("${CMAKE_SYSTEM_NAME}" MATCHES "Linux") - # Tell Boost that we're using Clang's libc++. Not sure exactly why we need to do. - add_definitions(-DBOOST_ASIO_HAS_CLANG_LIBCXX) - # Use fancy colors in the compiler diagnostics - add_compile_options(-fcolor-diagnostics) - endif() - endif() - - if (COVERAGE) - set(TESTS ON) - if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") - set(CMAKE_CXX_FLAGS "-g --coverage ${CMAKE_CXX_FLAGS}") - set(CMAKE_C_FLAGS "-g --coverage ${CMAKE_C_FLAGS}") - set(CMAKE_SHARED_LINKER_FLAGS "--coverage ${CMAKE_SHARED_LINKER_FLAGS}") - set(CMAKE_EXE_LINKER_FLAGS "--coverage ${CMAKE_EXE_LINKER_FLAGS}") - elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") - add_compile_options(-Wno-unused-command-line-argument) - set(CMAKE_CXX_FLAGS "-g -fprofile-arcs -ftest-coverage ${CMAKE_CXX_FLAGS}") - set(CMAKE_C_FLAGS "-g -fprofile-arcs -ftest-coverage ${CMAKE_C_FLAGS}") - endif() - find_program(LCOV_TOOL lcov) - message(STATUS "lcov tool: ${LCOV_TOOL}") - if (LCOV_TOOL) - add_custom_target(coverage - COMMAND ${LCOV_TOOL} -o ${CMAKE_BINARY_DIR}/coverage.info.in -c -d ${CMAKE_BINARY_DIR}/ - COMMAND ${LCOV_TOOL} -r ${CMAKE_BINARY_DIR}/coverage.info.in '/usr*' '${CMAKE_SOURCE_DIR}/deps**' '${CMAKE_SOURCE_DIR}/evmc*' ‘${CMAKE_SOURCE_DIR}/fisco-bcos*’ -o ${CMAKE_BINARY_DIR}/coverage.info - COMMAND genhtml -q -o ${CMAKE_BINARY_DIR}/CodeCoverage ${CMAKE_BINARY_DIR}/coverage.info) - else () - message(FATAL_ERROR "Can't find lcov tool. Please install lcov") - endif() - endif () -else () - message(WARNING "Your compiler is not tested, if you run into any issues, we'd welcome any patches.") -endif () - -if (SANITIZE) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer -fsanitize=${SANITIZE}") - if (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize-blacklist=${CMAKE_SOURCE_DIR}/sanitizer-blacklist.txt") - endif() -endif() - -# rust static library linking requirements for macos -if(APPLE) - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework Security") -endif() - diff --git a/cmake/Options.cmake b/cmake/Options.cmake deleted file mode 100644 index bc4d76a..0000000 --- a/cmake/Options.cmake +++ /dev/null @@ -1,182 +0,0 @@ -#------------------------------------------------------------------------------ -# Set compile options for FISCO-BCOS. -# ------------------------------------------------------------------------------ -# This file is part of FISCO-BCOS. -# -# FISCO-BCOS is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# FISCO-BCOS is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with FISCO-BCOS. If not, see -# -# (c) 2016-2018 fisco-dev contributors. -#------------------------------------------------------------------------------ -# change-list -# 2018/09/05: yujiechen -# 1. add DEBUG flag -# 2. add FISCO_DEBUG definition when DEBUG flag has been set - -macro(eth_default_option O DEF) - if (DEFINED ${O}) - if (${${O}}) - set(${O} ON) - else () - set(${O} OFF) - endif() - else () - set(${O} ${DEF}) - endif() -endmacro() - -# common settings -set(MARCH_TYPE "-march=x86-64 -mtune=generic -fvisibility=hidden -fvisibility-inlines-hidden") -set(ETH_CMAKE_DIR ${CMAKE_CURRENT_LIST_DIR}) -set(ETH_SCRIPTS_DIR ${ETH_CMAKE_DIR}/scripts) -set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) -if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4") - message(FATAL "The ${PROJECT_NAME} does not support compiling on 32-bit systems") -endif() - -EXECUTE_PROCESS(COMMAND uname -m COMMAND tr -d '\n' OUTPUT_VARIABLE ARCHITECTURE) - -macro(configure_project) - set(NAME ${PROJECT_NAME}) - # Default to RelWithDebInfo configuration if no configuration is explicitly specified. - if (NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING - "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE) - endif() - - eth_default_option(BUILD_SHARED_LIBS OFF) - - eth_default_option(BUILD_STATIC OFF) - - #ARCH TYPE - eth_default_option(ARCH_NATIVE OFF) - set(USE_LD_GOLD ON) - # if aarch64 set arch_native on - if("${ARCHITECTURE}" STREQUAL "aarch64" OR "${ARCHITECTURE}" STREQUAL "arm64") - set(ARCH_NATIVE ON) - endif() - if(ARCH_NATIVE) - if(APPLE) - set(MARCH_TYPE "-mtune=generic -fvisibility=hidden -fvisibility-inlines-hidden") - else() - set(MARCH_TYPE "-march=native") - set(USE_LD_GOLD OFF) - endif() - set(COMPILE_OPTIONS "native") - endif() - - # unit tests - eth_default_option(TESTS OFF) - # mini demos - eth_default_option(DEMO OFF) - # tools - eth_default_option(TOOL OFF) - # code coverage - eth_default_option(COVERAGE OFF) - # hardware crypto sdf interface - eth_default_option(USE_HSM_SDF OFF) - if(USE_HSM_SDF) - if(NOT "${CMAKE_SYSTEM_NAME}" MATCHES "Linux") - message(FATAL "${CMAKE_SYSTEM_NAME} ${ARCHITECTURE} does not support by hardware secure module") - endif() - add_definitions(-DFISCO_SDF) - if(NOT DEFINED COMPILE_OPTIONS) - set(COMPILE_OPTIONS "hsm_sdf") - else() - set(COMPILE_OPTIONS "${COMPILE_OPTIONS},hsm_sdf") - endif() - endif() - - #debug - eth_default_option(DEBUG OFF) - if (DEBUG) - add_definitions(-DFISCO_DEBUG) - endif() - - #perf - eth_default_option(PROF OFF) - if (PROF) - #add_definitions(-DPROF) - endif() - eth_default_option(WITH_URING OFF) - eth_default_option(WITH_TBB ON) - if(TESTS) - set(WITH_TBB ON) - endif() - if(NOT WITH_TBB) - if(NOT DEFINED COMPILE_OPTIONS) - set(COMPILE_OPTIONS "without_tbb") - else() - set(COMPILE_OPTIONS "${COMPILE_OPTIONS},without_tbb") - endif() - endif() - if (WITH_TBB) - add_definitions(-DWITH_TBB) - endif() - - # Define a matching property name of each of the "features". - foreach(FEATURE ${ARGN}) - set(SUPPORT_${FEATURE} TRUE) - endforeach() - if(DISABLE_OBSERVER_WRITE_REQUEST) - add_definitions(-DDISABLE_OBSERVER_WRITE_REQUEST) - if(NOT DEFINED COMPILE_OPTIONS) - set(COMPILE_OPTIONS "disable_observer_write_request") - else() - set(COMPILE_OPTIONS "${COMPILE_OPTIONS},disable_observer_write_request") - endif() - endif() - - # CI Builds should provide (for user builds this is totally optional) - # -DBUILD_NUMBER - A number to identify the current build with. Becomes TWEAK component of project version. - # -DVERSION_SUFFIX - A string to append to the end of the version string where applicable. - if (NOT DEFINED BUILD_NUMBER) - # default is big so that local build is always considered greater - # and can easily replace CI build for for all platforms if needed. - # Windows max version component number is 65535 - set(BUILD_NUMBER 65535) - endif() - - # Suffix like "-rc1" e.t.c. to append to versions wherever needed. - if (NOT DEFINED VERSION_SUFFIX) - set(VERSION_SUFFIX "") - endif() - -endmacro() - -macro(print_config NAME) - message("") - message("------------------------------------------------------------------------") - message("-- Configuring ${NAME} ${PROJECT_VERSION}${VERSION_SUFFIX}") - message("------------------------------------------------------------------------") - message("-- CMake Cmake version and location ${CMAKE_VERSION} (${CMAKE_COMMAND})") - message("-- Compiler C++ compiler version ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}") - message("-- CMAKE_BUILD_TYPE Build type ${CMAKE_BUILD_TYPE}") - message("-- TARGET_PLATFORM Target platform ${CMAKE_SYSTEM_NAME} ${ARCHITECTURE}") - message("-- BUILD_STATIC Build static ${BUILD_STATIC}") - message("-- USE_HSM_SDF Build SDF HSM ${USE_HSM_SDF}") - message("-- DEMO Build demos ${DEMO}") - message("-- TOOL Build tools ${TOOL}") - message("-- COVERAGE Build code coverage ${COVERAGE}") - message("-- TESTS Build tests ${TESTS}") - message("-- WITH_TBB Build with tbb ${WITH_TBB}") - message("-- APPLE Apple Machine ${APPLE}") - message("-- ARCH_NATIVE Enable native code ${ARCH_NATIVE}") - message("-- DEBUG Enable debug macro ${DEBUG}") - message("-- PROF Enable gcc prof ${PROF}") - message("-- DEFINE_FILTER_OWR DISABLE_OBSERVER_WRITE_REQUEST ${DISABLE_OBSERVER_WRITE_REQUEST}") - message("-- WITH_URING Compile with liburing ${WITH_URING}") - message("------------------------------------------------------------------------") - message("") -endmacro() - diff --git a/cmake/ProjectBoost.cmake b/cmake/ProjectBoost.cmake deleted file mode 100644 index be126db..0000000 --- a/cmake/ProjectBoost.cmake +++ /dev/null @@ -1,145 +0,0 @@ -include(ExternalProject) -include(GNUInstallDirs) - -include(ProcessorCount) -ProcessorCount(CORES) -if(CORES EQUAL 0) - set(CORES 1) -elseif(CORES GREATER 2) - set(CORES 2) -endif() - -set(BOOST_CXXFLAGS "cxxflags=${MARCH_TYPE}") - -if (APPLE) - set(SED_CMMAND sed -i .bkp) - set(BOOST_BOOTSTRAP_COMMAND ./bootstrap.sh COMMAND ${SED_CMMAND} "s/-fcoalesce-templates//g" ${CMAKE_SOURCE_DIR}/deps/src/boost/tools/build/src/tools/darwin.jam) -else() - set(SED_CMMAND sed -i) - set(BOOST_BOOTSTRAP_COMMAND ./bootstrap.sh) -endif() - -set(BOOST_INSTALL_COMMAND ./b2 install --prefix=${CMAKE_SOURCE_DIR}/deps) -set(BOOST_BUILD_TOOL ./b2) -set(BOOST_LIBRARY_SUFFIX .a) - -set(BOOST_LIB_PREFIX ${CMAKE_SOURCE_DIR}/deps/src/boost/stage/lib/libboost_) -set(BOOST_BUILD_FILES ${BOOST_LIB_PREFIX}chrono.a ${BOOST_LIB_PREFIX}date_time.a - ${BOOST_LIB_PREFIX}random.a ${BOOST_LIB_PREFIX}regex.a - ${BOOST_LIB_PREFIX}filesystem.a ${BOOST_LIB_PREFIX}system.a - ${BOOST_LIB_PREFIX}unit_test_framework.a ${BOOST_LIB_PREFIX}log.a - ${BOOST_LIB_PREFIX}thread.a ${BOOST_LIB_PREFIX}program_options.a - ${BOOST_LIB_PREFIX}serialization.a) - -ExternalProject_Add(boost - PREFIX ${CMAKE_SOURCE_DIR}/deps - DOWNLOAD_NO_PROGRESS 1 - URL https://archives.boost.io/release/1.86.0/source/boost_1_86_0.tar.gz - URL_HASH SHA256=2575e74ffc3ef1cd0babac2c1ee8bdb5782a0ee672b1912da40e5b4b591ca01f - BUILD_IN_SOURCE 1 - CONFIGURE_COMMAND ${BOOST_BOOTSTRAP_COMMAND} - BUILD_COMMAND ${BOOST_BUILD_TOOL} stage - ${BOOST_CXXFLAGS} - threading=multi - link=static - variant=release - address-model=64 - --with-chrono - --with-date_time - --with-filesystem - --with-system - --with-random - --with-regex - --with-test - --with-thread - --with-serialization - --with-program_options - --with-log - --with-iostreams - -s NO_BZIP2=1 -s NO_LZMA=1 -s NO_ZSTD=1 - -j${CORES} - LOG_CONFIGURE 1 - LOG_BUILD 1 - LOG_INSTALL 1 - INSTALL_COMMAND "" - # INSTALL_COMMAND ${BOOST_INSTALL_COMMAND} - BUILD_BYPRODUCTS ${BOOST_BUILD_FILES} -) - -ExternalProject_Get_Property(boost SOURCE_DIR) -set(BOOST_INCLUDE_DIR ${SOURCE_DIR}) -set(BOOST_LIB_DIR ${SOURCE_DIR}/stage/lib) - -add_library(Boost::System STATIC IMPORTED GLOBAL) -set_property(TARGET Boost::System PROPERTY IMPORTED_LOCATION ${BOOST_LIB_DIR}/libboost_system${BOOST_LIBRARY_SUFFIX}) -set_property(TARGET Boost::System PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${BOOST_INCLUDE_DIR}) -add_dependencies(Boost::System boost) - -add_library(Boost::Chrono STATIC IMPORTED GLOBAL) -set_property(TARGET Boost::Chrono PROPERTY IMPORTED_LOCATION ${BOOST_LIB_DIR}/libboost_chrono${BOOST_LIBRARY_SUFFIX}) -add_dependencies(Boost::Chrono boost) - -add_library(Boost::DataTime STATIC IMPORTED GLOBAL) -set_property(TARGET Boost::DataTime PROPERTY IMPORTED_LOCATION ${BOOST_LIB_DIR}/libboost_date_time${BOOST_LIBRARY_SUFFIX}) -set_property(TARGET Boost::DataTime PROPERTY INTERFACE_LINK_LIBRARIES Boost::System) -add_dependencies(Boost::DataTime boost) - -add_library(Boost::Regex STATIC IMPORTED GLOBAL) -set_property(TARGET Boost::Regex PROPERTY IMPORTED_LOCATION ${BOOST_LIB_DIR}/libboost_regex${BOOST_LIBRARY_SUFFIX}) -set_property(TARGET Boost::Regex PROPERTY INTERFACE_LINK_LIBRARIES Boost::System) -add_dependencies(Boost::Regex boost) - -add_library(Boost::Filesystem STATIC IMPORTED GLOBAL) -set_property(TARGET Boost::Filesystem PROPERTY IMPORTED_LOCATION ${BOOST_LIB_DIR}/libboost_filesystem${BOOST_LIBRARY_SUFFIX}) -set_property(TARGET Boost::Filesystem PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${BOOST_INCLUDE_DIR}) -set_property(TARGET Boost::Filesystem PROPERTY INTERFACE_LINK_LIBRARIES Boost::System) -add_dependencies(Boost::Filesystem boost) - -add_library(Boost::Random STATIC IMPORTED GLOBAL) -set_property(TARGET Boost::Random PROPERTY IMPORTED_LOCATION ${BOOST_LIB_DIR}/libboost_random${BOOST_LIBRARY_SUFFIX}) -add_dependencies(Boost::Random boost) - -add_library(Boost::UnitTestFramework STATIC IMPORTED GLOBAL) -set_property(TARGET Boost::UnitTestFramework PROPERTY IMPORTED_LOCATION ${BOOST_LIB_DIR}/libboost_unit_test_framework${BOOST_LIBRARY_SUFFIX}) -set_property(TARGET Boost::UnitTestFramework PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${BOOST_INCLUDE_DIR}) -add_dependencies(Boost::UnitTestFramework boost) - -add_library(Boost::Thread STATIC IMPORTED GLOBAL) -set_property(TARGET Boost::Thread PROPERTY IMPORTED_LOCATION ${BOOST_LIB_DIR}/libboost_thread${BOOST_LIBRARY_SUFFIX}) -set_property(TARGET Boost::Thread PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${BOOST_INCLUDE_DIR}) -set_property(TARGET Boost::Thread PROPERTY INTERFACE_LINK_LIBRARIES Boost::Chrono Boost::DataTime Boost::Regex) -add_dependencies(Boost::Thread boost) - -add_library(Boost::program_options STATIC IMPORTED GLOBAL) -set_property(TARGET Boost::program_options PROPERTY IMPORTED_LOCATION ${BOOST_LIB_DIR}/libboost_program_options${BOOST_LIBRARY_SUFFIX}) -set_property(TARGET Boost::program_options PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${BOOST_INCLUDE_DIR}) -add_dependencies(Boost::program_options boost) - -add_library(Boost::Log STATIC IMPORTED GLOBAL) -set_property(TARGET Boost::Log PROPERTY IMPORTED_LOCATION ${BOOST_LIB_DIR}/libboost_log${BOOST_LIBRARY_SUFFIX}) -set_property(TARGET Boost::Log PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${BOOST_INCLUDE_DIR}) -set_property(TARGET Boost::Log PROPERTY INTERFACE_LINK_LIBRARIES Boost::Filesystem Boost::Thread) -add_dependencies(Boost::Log boost) - -add_library(Boost::LogSetup STATIC IMPORTED GLOBAL) -set_property(TARGET Boost::LogSetup PROPERTY IMPORTED_LOCATION ${BOOST_LIB_DIR}/libboost_log_setup${BOOST_LIBRARY_SUFFIX}) -set_property(TARGET Boost::LogSetup PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${BOOST_INCLUDE_DIR}) -# set_property(TARGET Boost::LogSetup PROPERTY INTERFACE_LINK_LIBRARIES Boost::Filesystem Boost::Thread) -add_dependencies(Boost::LogSetup boost) - -add_library(Boost::Serialization STATIC IMPORTED GLOBAL) -set_property(TARGET Boost::Serialization PROPERTY IMPORTED_LOCATION ${BOOST_LIB_DIR}/libboost_serialization${BOOST_LIBRARY_SUFFIX}) -set_property(TARGET Boost::Serialization PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${BOOST_INCLUDE_DIR}) -add_dependencies(Boost::Serialization boost) - -# for boost compress/base64encode -add_library(Boost::iostreams STATIC IMPORTED GLOBAL) -set_property(TARGET Boost::iostreams PROPERTY IMPORTED_LOCATION ${BOOST_LIB_DIR}/libboost_iostreams${BOOST_LIBRARY_SUFFIX}) -set_property(TARGET Boost::iostreams PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${BOOST_INCLUDE_DIR}) -if(NOT APPLE) - # set_property(TARGET Boost::iostreams PROPERTY INTERFACE_LINK_LIBRARIES z) - find_package(ZLIB REQUIRED) - set_property(TARGET Boost::iostreams PROPERTY INTERFACE_LINK_LIBRARIES ZLIB::ZLIB) -endif() -add_dependencies(Boost::iostreams boost) -unset(SOURCE_DIR) \ No newline at end of file diff --git a/vcpkg-configuration.json b/vcpkg-configuration.json new file mode 100644 index 0000000..032ef16 --- /dev/null +++ b/vcpkg-configuration.json @@ -0,0 +1,14 @@ +{ + "default-registry": { + "kind": "git", + "baseline": "73964f854d0d6424f335e9515b61b3a2dad5e15b", + "repository": "https://github.com/microsoft/vcpkg" + }, + "registries": [ + { + "kind": "artifact", + "location": "https://github.com/microsoft/vcpkg-ce-catalog/archive/refs/heads/main.zip", + "name": "microsoft" + } + ] +} diff --git a/vcpkg.json b/vcpkg.json new file mode 100644 index 0000000..77873ae --- /dev/null +++ b/vcpkg.json @@ -0,0 +1,8 @@ +{ + "name": "verke-tree", + "version": "1.0", + "dependencies": [ + "boost-test", + "boost-log" + ] +} From 352105ef256e3a4934eba6e5d16fd7c8b38dc78c Mon Sep 17 00:00:00 2001 From: Zhengxuan Guo Date: Mon, 19 Aug 2024 20:23:01 +0800 Subject: [PATCH 06/12] import bandersnatch test fixture --- CMakeLists.txt | 5 +- CMakePresets.json | 16 +-- bandersnatch/CMakeLists.txt | 8 +- .../{src => bandersnatch}/Element.cpp | 0 bandersnatch/{src => bandersnatch}/Element.h | 0 bandersnatch/{src => bandersnatch}/Fr.cpp | 45 ++++++++- bandersnatch/{src => bandersnatch}/Fr.h | 7 +- bandersnatch/test/CMakeLists.txt | 9 +- bandersnatch/test/unittests/ElementTest.cpp | 15 +-- bandersnatch/test/unittests/FrTest.cpp | 30 +++++- cmake/ProjectBLST.cmake | 26 ++--- utility/CMakelists.txt | 4 + utility/testutils/TestPromptFixture.h | 97 +++++++++++++++++++ 13 files changed, 214 insertions(+), 48 deletions(-) rename bandersnatch/{src => bandersnatch}/Element.cpp (100%) rename bandersnatch/{src => bandersnatch}/Element.h (100%) rename bandersnatch/{src => bandersnatch}/Fr.cpp (54%) rename bandersnatch/{src => bandersnatch}/Fr.h (74%) create mode 100644 utility/CMakelists.txt create mode 100644 utility/testutils/TestPromptFixture.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c5822e..e3a23d5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.14) project(verkle_tree) set(CMAKE_CXX_STANDARD 20) @@ -6,8 +6,7 @@ set(CMAKE_CXX_STANDARD 20) set(VERKLE_CMAKE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/cmake") list(APPEND CMAKE_MODULE_PATH ${VERKLE_CMAKE_DIR}) - include(ProjectBLST) -# include(ProjectBoost) add_subdirectory(bandersnatch) +add_subdirectory(utility) \ No newline at end of file diff --git a/CMakePresets.json b/CMakePresets.json index 3fefc1f..c151107 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -1,13 +1,13 @@ { "version": 2, "configurePresets": [ - { - "name": "default", - "generator": "Visual Studio 17 2022", - "binaryDir": "${sourceDir}/build", - "cacheVariables": { - "CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" - } + { + "name": "default", + "generator": "Unix Makefiles", + "binaryDir": "${sourceDir}/build", + "cacheVariables": { + "CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" } + } ] -} \ No newline at end of file + } \ No newline at end of file diff --git a/bandersnatch/CMakeLists.txt b/bandersnatch/CMakeLists.txt index e5a5214..cce5547 100644 --- a/bandersnatch/CMakeLists.txt +++ b/bandersnatch/CMakeLists.txt @@ -1,9 +1,9 @@ -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.14) project(bandersnatch) -file(GLOB_RECURSE SRCS "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp") -file(GLOB_RECURSE HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/src/*.h") +file(GLOB_RECURSE SRCS bandersnatch/*.cpp) +file(GLOB_RECURSE HEADERS bandersnatch/*.h) add_library(bandersnatch ${SRCS} ${HEADERS}) target_link_libraries(bandersnatch PRIVATE blst) @@ -12,4 +12,4 @@ target_link_libraries(bandersnatch PRIVATE blst) # enable_testing() # set(CTEST_OUTPUT_ON_FAILURE TRUE) add_subdirectory(test) -# endif() +# endif() \ No newline at end of file diff --git a/bandersnatch/src/Element.cpp b/bandersnatch/bandersnatch/Element.cpp similarity index 100% rename from bandersnatch/src/Element.cpp rename to bandersnatch/bandersnatch/Element.cpp diff --git a/bandersnatch/src/Element.h b/bandersnatch/bandersnatch/Element.h similarity index 100% rename from bandersnatch/src/Element.h rename to bandersnatch/bandersnatch/Element.h diff --git a/bandersnatch/src/Fr.cpp b/bandersnatch/bandersnatch/Fr.cpp similarity index 54% rename from bandersnatch/src/Fr.cpp rename to bandersnatch/bandersnatch/Fr.cpp index f0ae259..7866313 100644 --- a/bandersnatch/src/Fr.cpp +++ b/bandersnatch/bandersnatch/Fr.cpp @@ -2,19 +2,48 @@ // Created by Zhengxuan Guo on 2024/8/13. // +#include +#include #include "Fr.h" using namespace verkle::bandersnatch; -Fr::Fr() : m_val(std::make_unique()) {} +Fr::Fr() : m_val(std::make_shared()) {} -Fr::Fr(const uint8_t* msg, size_t len) : m_val(std::make_unique()) +Fr::Fr(const uint64_t a[4]) : m_val(std::make_shared()) +{ + blst_fr_from_uint64(m_val.get(), a); +} + +Fr::Fr(const uint8_t* msg, size_t len) : m_val(std::make_shared()) { blst_scalar scalar; blst_scalar_from_le_bytes(&scalar, msg, (len+7)/8); blst_fr_from_scalar(m_val.get(), &scalar); } +Fr Fr::zero() +{ + // zero value of Fr is simply 0x0 + return Fr(); +} + +Fr Fr::random() +{ + std::random_device rd; + std::mt19937_64 gen(rd()); + std::uniform_int_distribution dis(0, UINT64_MAX); + + uint64_t a[4]; + for (int i = 0; i < 4; ++i) + { + a[i] = dis(gen); + } + Fr ret; + blst_fr_from_uint64(ret.m_val.get(), a); + return ret; +} + Fr Fr::operator+(const Fr& other) const { Fr ret; @@ -36,6 +65,18 @@ Fr Fr::operator*(const Fr& other) const return ret; } +bool Fr::operator==(const Fr& other) const +{ + for (int i = 0; i < 4; ++i) + { + if (m_val.get()->l[i] != other.m_val.get()->l[i]) + { + return false; + } + } + return true; +} + Fr Fr::inv() const { Fr ret; diff --git a/bandersnatch/src/Fr.h b/bandersnatch/bandersnatch/Fr.h similarity index 74% rename from bandersnatch/src/Fr.h rename to bandersnatch/bandersnatch/Fr.h index 69860cb..185134d 100644 --- a/bandersnatch/src/Fr.h +++ b/bandersnatch/bandersnatch/Fr.h @@ -11,18 +11,23 @@ class Fr { public: Fr(); + Fr(const uint64_t a[4]); Fr(const byte* msg, size_t len); + static Fr zero(); + static Fr random(); + Fr operator+(const Fr& other) const; Fr operator-(const Fr& other) const; Fr operator*(const Fr& other) const; Fr inv() const; + bool operator==(const Fr& other) const; std::shared_ptr toScalar() const; void serialize(uint64_t ret[4]) const; private: - std::unique_ptr m_val; + std::shared_ptr m_val; }; } \ No newline at end of file diff --git a/bandersnatch/test/CMakeLists.txt b/bandersnatch/test/CMakeLists.txt index b58b93b..c0c9371 100644 --- a/bandersnatch/test/CMakeLists.txt +++ b/bandersnatch/test/CMakeLists.txt @@ -1,10 +1,9 @@ file(GLOB_RECURSE TEST_SRCS "*.cpp") -add_executable(bandersnatch-test ${TEST_SRCS}) -target_include_directories(bandersnatch-test PRIVATE .) +add_library(bandersnatch-test ${TEST_SRCS}) +target_include_directories(bandersnatch-test PRIVATE ..) find_package(boost_unit_test_framework CONFIG REQUIRED) -find_package(boost_log CONFIG REQUIRED) -target_link_libraries(bandersnatch-test bandersnatch Boost::unit_test_framework Boost::log) -# add_test(NAME test-bandersnatch WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} COMMAND bandersnatch-test) +target_link_libraries(bandersnatch-test PRIVATE bandersnatch Boost::unit_test_framework) +add_test(NAME test-bandersnatch WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} COMMAND bandersnatch-test) diff --git a/bandersnatch/test/unittests/ElementTest.cpp b/bandersnatch/test/unittests/ElementTest.cpp index be8b733..a3d6008 100644 --- a/bandersnatch/test/unittests/ElementTest.cpp +++ b/bandersnatch/test/unittests/ElementTest.cpp @@ -1,13 +1,14 @@ // // Created by Zhengxuan Guo on 2024/8/15. // +#include "bandersnatch/Element.h" #include -namespace verkle { - namespace test { - BOOST_AUTO_TEST_SUITE(TEST) - - BOOST_AUTO_TEST_SUITE_END() - - } +namespace verkle::test +{ + +BOOST_AUTO_TEST_CASE(testAdd) +{ + +} } \ No newline at end of file diff --git a/bandersnatch/test/unittests/FrTest.cpp b/bandersnatch/test/unittests/FrTest.cpp index bd5c6b8..2e6de1f 100644 --- a/bandersnatch/test/unittests/FrTest.cpp +++ b/bandersnatch/test/unittests/FrTest.cpp @@ -1,11 +1,31 @@ // // Created by Zhengxuan Guo on 2024/8/15. // +#include "bandersnatch/Fr.h" +#include "utility/testutils/TestPromptFixture.h" #include -namespace verkle { - namespace test { - BOOST_AUTO_TEST_SUITE(TEST) - BOOST_AUTO_TEST_SUITE_END() - } +namespace verkle::test +{ +BOOST_FIXTURE_TEST_SUITE(FrTest, TestPromptFixture) +static inline bandersnatch::Fr FixedFr1() +{ + static bandersnatch::Fr fr1( + (uint64_t[4]){ + 0x2ef123703093cbbb, + 0x9876543210fedcba, + 0, + 0, + } + ); + return fr1; +} + + +BOOST_AUTO_TEST_CASE(testAdd) +{ + +} + +BOOST_AUTO_TEST_SUITE_END() } \ No newline at end of file diff --git a/cmake/ProjectBLST.cmake b/cmake/ProjectBLST.cmake index fa4517b..f2cf910 100644 --- a/cmake/ProjectBLST.cmake +++ b/cmake/ProjectBLST.cmake @@ -9,20 +9,20 @@ if (NOT BASH_COMMAND) endif () ExternalProject_Add(blst_project - PREFIX ${CMAKE_SOURCE_DIR}/deps - GIT_REPOSITORY https://github.com/supranational/blst.git - GIT_TAG 3dd0f804b1819e5d03fb22ca2e6fac105932043a - GIT_SHALLOW 0 + PREFIX ${CMAKE_SOURCE_DIR}/deps + GIT_REPOSITORY https://github.com/supranational/blst.git + GIT_TAG 3dd0f804b1819e5d03fb22ca2e6fac105932043a + GIT_SHALLOW 0 - CMAKE_ARGS -DCMAKE_INSTALL_PREFIX= - BUILD_IN_SOURCE 1 - CONFIGURE_COMMAND "" - BUILD_COMMAND ${BLST_BUILD_COMMAND} - INSTALL_COMMAND sh -c "cp /bindings/blst.h /include/ && cp /bindings/blst_aux.h /include/ && cp /libblst.a /lib/" - LOG_BUILD true - LOG_INSTALL true - LOG_CONFIGURE true - BUILD_BYPRODUCTS libblst.a + CMAKE_ARGS -DCMAKE_INSTALL_PREFIX= + BUILD_IN_SOURCE 1 + CONFIGURE_COMMAND "" + BUILD_COMMAND ${BLST_BUILD_COMMAND} + INSTALL_COMMAND sh -c "cp /bindings/blst.h /include/ && cp /bindings/blst_aux.h /include/ && cp /libblst.a /lib/" + LOG_BUILD true + LOG_INSTALL true + LOG_CONFIGURE true + BUILD_BYPRODUCTS libblst.a ) ExternalProject_Get_Property(blst_project INSTALL_DIR) diff --git a/utility/CMakelists.txt b/utility/CMakelists.txt new file mode 100644 index 0000000..eafeaa8 --- /dev/null +++ b/utility/CMakelists.txt @@ -0,0 +1,4 @@ +project(utilities) + +find_package(boost_unit_test_framework CONFIG REQUIRED) +find_package(boost_filesystem CONFIG REQUIRED) \ No newline at end of file diff --git a/utility/testutils/TestPromptFixture.h b/utility/testutils/TestPromptFixture.h new file mode 100644 index 0000000..2cfa611 --- /dev/null +++ b/utility/testutils/TestPromptFixture.h @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2021 FISCO BCOS. + * SPDX-License-Identifier: Apache-2.0 + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * @file: TestPromptFixture.h + * fixture class for test case prompt + */ + +#pragma once +#include +#include + +namespace verkle::test +{ + +uint64_t utcTime() +{ + return std::chrono::duration_cast( + std::chrono::system_clock::now().time_since_epoch()) + .count(); +} + +class TestPrompt +{ +public: + static TestPrompt& get() + { + static TestPrompt instance; + return instance; + } + TestPrompt(TestPrompt const&) = delete; + void operator=(TestPrompt const&) = delete; + /** + * @brief : init every test-suite by printting the name of cases + * @param _maxTests + */ + void initTest(size_t _maxTests = 1) + { + m_currentTestName = "unknown"; + m_currentTestFileName = std::string(); + m_startTime = utcTime(); + m_currentTestCaseName = boost::unit_test::framework::current_test_case().p_name; + std::cout << "===== Verkle Test Case : " + m_currentTestCaseName << "=====" << std::endl; + m_maxTests = _maxTests; + m_currTest = 0; + }; + + /** + * @brief : release resources when test-suite finished + */ + void finishTest() + { + execTimeName res; + res.first = (double)(utcTime() - m_startTime); + res.second = caseName(); + std::cout << "#### Run " << res.second << " time elapsed: " << res.first << std::endl; + m_execTimeResults.push_back(res); + } + + void setCurrentTestFile(boost::filesystem::path const& _name) { m_currentTestFileName = _name; } + void setCurrentTestName(std::string const& _name) { m_currentTestName = _name; } + std::string const& testName() { return m_currentTestName; } + std::string const& caseName() { return m_currentTestCaseName; } + boost::filesystem::path const& testFile() { return m_currentTestFileName; } + +private: + TestPrompt() {} + size_t m_currTest; + size_t m_maxTests; + std::string m_currentTestName; + std::string m_currentTestCaseName; + boost::filesystem::path m_currentTestFileName; + typedef std::pair execTimeName; + std::vector m_execTimeResults; + int64_t m_startTime; +}; + +class TestPromptFixture +{ +public: + // init test-suite fixture + TestPromptFixture() { TestPrompt::get().initTest(); } + // release test-suite fixture + ~TestPromptFixture() { TestPrompt::get().finishTest(); } +}; +} // namespace test From 0e97863c693c6008b0d2d3f94d7d7e78b96d1559 Mon Sep 17 00:00:00 2001 From: Zhengxuan Guo Date: Tue, 20 Aug 2024 20:33:11 +0800 Subject: [PATCH 07/12] Fr unit tests --- CMakeLists.txt | 5 +- CMakePresets.json | 10 ++ bandersnatch/CMakeLists.txt | 10 +- bandersnatch/bandersnatch/Element.cpp | 11 +- bandersnatch/bandersnatch/Fr.cpp | 13 +-- bandersnatch/bandersnatch/Fr.h | 7 +- bandersnatch/test/CMakeLists.txt | 4 +- bandersnatch/test/unittests/FrTest.cpp | 148 +++++++++++++++++++++++- bandersnatch/test/unittests/main.cpp | 5 + utilities/CMakelists.txt | 7 ++ utilities/testutils/TestPromptFixture.h | 97 ++++++++++++++++ 11 files changed, 288 insertions(+), 29 deletions(-) create mode 100644 bandersnatch/test/unittests/main.cpp create mode 100644 utilities/CMakelists.txt create mode 100644 utilities/testutils/TestPromptFixture.h diff --git a/CMakeLists.txt b/CMakeLists.txt index e3a23d5..1e0311b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,5 +8,6 @@ list(APPEND CMAKE_MODULE_PATH ${VERKLE_CMAKE_DIR}) include(ProjectBLST) -add_subdirectory(bandersnatch) -add_subdirectory(utility) \ No newline at end of file +add_subdirectory(utilities) + +add_subdirectory(bandersnatch) \ No newline at end of file diff --git a/CMakePresets.json b/CMakePresets.json index c151107..32f30b3 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -8,6 +8,16 @@ "cacheVariables": { "CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" } + }, + { + "name": "test", + "generator": "Unix Makefiles", + "binaryDir": "${sourceDir}/build", + "cacheVariables": { + "CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake", + "CMAKE_BUILD_TYPE": "Debug", + "TESTS": "ON" + } } ] } \ No newline at end of file diff --git a/bandersnatch/CMakeLists.txt b/bandersnatch/CMakeLists.txt index cce5547..f3ba8d1 100644 --- a/bandersnatch/CMakeLists.txt +++ b/bandersnatch/CMakeLists.txt @@ -6,10 +6,10 @@ file(GLOB_RECURSE SRCS bandersnatch/*.cpp) file(GLOB_RECURSE HEADERS bandersnatch/*.h) add_library(bandersnatch ${SRCS} ${HEADERS}) -target_link_libraries(bandersnatch PRIVATE blst) +target_link_libraries(bandersnatch PUBLIC blst) -# if (TESTS) -# enable_testing() -# set(CTEST_OUTPUT_ON_FAILURE TRUE) +if (TESTS) + enable_testing() + set(CTEST_OUTPUT_ON_FAILURE TRUE) add_subdirectory(test) -# endif() \ No newline at end of file +endif() \ No newline at end of file diff --git a/bandersnatch/bandersnatch/Element.cpp b/bandersnatch/bandersnatch/Element.cpp index 6e40896..f1c6035 100644 --- a/bandersnatch/bandersnatch/Element.cpp +++ b/bandersnatch/bandersnatch/Element.cpp @@ -1,7 +1,6 @@ // // Created by Zhengxuan Guo on 2024/8/13. // - #include "Element.h" using namespace verkle::bandersnatch; @@ -35,8 +34,9 @@ Element& Element::dbl() Element& Element::mult(const Fr& fr) { - auto scalar = fr.toScalar(); - blst_p1_mult(m_point.get(), m_point.get(), scalar->b, 255); + blst_scalar scalar; + blst_scalar_from_fr(&scalar, fr.m_val.get()); + blst_p1_mult(m_point.get(), m_point.get(), scalar.b, 255); return *this; } @@ -57,8 +57,9 @@ Element Element::dbl(const Element& a) Element Element::mult(const Fr& fr, const Element& a) { Element ret; - auto scalar = fr.toScalar(); - blst_p1_mult(ret.m_point.get(), a.m_point.get(), scalar->b, 255); + blst_scalar scalar; + blst_scalar_from_fr(&scalar, fr.m_val.get()); + blst_p1_mult(ret.m_point.get(), a.m_point.get(), scalar.b, 255); return ret; } diff --git a/bandersnatch/bandersnatch/Fr.cpp b/bandersnatch/bandersnatch/Fr.cpp index 7866313..9426cb5 100644 --- a/bandersnatch/bandersnatch/Fr.cpp +++ b/bandersnatch/bandersnatch/Fr.cpp @@ -77,21 +77,18 @@ bool Fr::operator==(const Fr& other) const return true; } -Fr Fr::inv() const +bool Fr::operator!=(const Fr& other) const { - Fr ret; - blst_fr_inverse(ret.m_val.get(), m_val.get()); - return ret; + return !(*this == other); } -std::shared_ptr Fr::toScalar() const +Fr Fr::inv() const { - auto ret = std::make_shared(); - blst_scalar_from_fr(ret.get(), m_val.get()); + Fr ret; + blst_fr_inverse(ret.m_val.get(), m_val.get()); return ret; } - void Fr::serialize(uint64_t ret[4]) const { blst_uint64_from_fr(ret, m_val.get()); diff --git a/bandersnatch/bandersnatch/Fr.h b/bandersnatch/bandersnatch/Fr.h index 185134d..1b9621f 100644 --- a/bandersnatch/bandersnatch/Fr.h +++ b/bandersnatch/bandersnatch/Fr.h @@ -7,10 +7,13 @@ namespace verkle::bandersnatch { +class Element; class Fr { public: Fr(); + + // deserialize Fr(const uint64_t a[4]); Fr(const byte* msg, size_t len); @@ -22,12 +25,12 @@ class Fr Fr operator*(const Fr& other) const; Fr inv() const; bool operator==(const Fr& other) const; - - std::shared_ptr toScalar() const; + bool operator!=(const Fr& other) const; void serialize(uint64_t ret[4]) const; private: std::shared_ptr m_val; + friend class Element; }; } \ No newline at end of file diff --git a/bandersnatch/test/CMakeLists.txt b/bandersnatch/test/CMakeLists.txt index c0c9371..a886e6b 100644 --- a/bandersnatch/test/CMakeLists.txt +++ b/bandersnatch/test/CMakeLists.txt @@ -1,9 +1,9 @@ file(GLOB_RECURSE TEST_SRCS "*.cpp") -add_library(bandersnatch-test ${TEST_SRCS}) +add_executable(bandersnatch-test ${TEST_SRCS}) target_include_directories(bandersnatch-test PRIVATE ..) find_package(boost_unit_test_framework CONFIG REQUIRED) -target_link_libraries(bandersnatch-test PRIVATE bandersnatch Boost::unit_test_framework) +target_link_libraries(bandersnatch-test PRIVATE utilities bandersnatch Boost::unit_test_framework) add_test(NAME test-bandersnatch WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} COMMAND bandersnatch-test) diff --git a/bandersnatch/test/unittests/FrTest.cpp b/bandersnatch/test/unittests/FrTest.cpp index 2e6de1f..de09240 100644 --- a/bandersnatch/test/unittests/FrTest.cpp +++ b/bandersnatch/test/unittests/FrTest.cpp @@ -2,29 +2,167 @@ // Created by Zhengxuan Guo on 2024/8/15. // #include "bandersnatch/Fr.h" -#include "utility/testutils/TestPromptFixture.h" +#include "testutils/TestPromptFixture.h" #include namespace verkle::test { -BOOST_FIXTURE_TEST_SUITE(FrTest, TestPromptFixture) static inline bandersnatch::Fr FixedFr1() { static bandersnatch::Fr fr1( (uint64_t[4]){ + 0xe5d76b4ca918a221, + 0x81ed0b8d092ec3c6, + 0xd124e15f2054fa57, 0x2ef123703093cbbb, - 0x9876543210fedcba, - 0, - 0, } ); return fr1; } +static inline bandersnatch::Fr FixedFr2() +{ + static bandersnatch::Fr fr2( + (uint64_t[4]){ + 0xd894647091277b9c, + 0x5182f0e810967f58, + 0x42958c4a5cf47f12, + 0x61b589a0f601132d, + } + ); + return fr2; +} + +BOOST_FIXTURE_TEST_SUITE(FrTest, TestPromptFixture) + +BOOST_AUTO_TEST_CASE(testFromBytes) +{ + byte a[32] = { + 0x6e, 0xf7, 0xfe, 0x28, 0xfa, 0xc6, 0x6c, 0x7d, + 0xe1, 0x63, 0x15, 0xcd, 0x78, 0x42, 0x8c, 0x61, + 0x8a, 0xdd, 0x2d, 0x50, 0x08, 0x7b, 0xda, 0x61, + 0xe2, 0xf7, 0x02, 0xa0, 0x3c, 0xb8, 0xf1, 0x3e + }; + bandersnatch::Fr t1(a, 32); + bandersnatch::Fr t2(a, 32); + BOOST_ASSERT(t1 == t2); +} + +BOOST_AUTO_TEST_CASE(testZero) +{ + auto zero = bandersnatch::Fr::zero(); + auto fr1 = FixedFr1(); + auto fr1SumZero = fr1 + zero; + BOOST_ASSERT(fr1SumZero == fr1); +} + +BOOST_AUTO_TEST_CASE(testRandom) +{ + auto r1 = bandersnatch::Fr::random(); + auto r2 = bandersnatch::Fr::random(); + BOOST_ASSERT(r1 != r2); +} BOOST_AUTO_TEST_CASE(testAdd) { + bandersnatch::Fr exp( + (uint64_t[4]){ + 0xbe6bcfbe3a401dbc, + 0x7fb2587219c6e720, + 0xe08095a173a7a164, + 0x1cb905bdfcf761a0, + } + ); + auto f1 = FixedFr1(); + auto f2 = FixedFr2(); + + auto res = f1 + f2; + uint64_t another[4]; + res.serialize(another); + bandersnatch::Fr newExp(another); + + auto a = f1 - f2; + uint64_t aa[4]; + a.serialize(aa); + + auto b = f1 * f2; + uint64_t bb[4]; + b.serialize(bb); + + auto c = f1.inv(); + uint64_t cc[4]; + c.serialize(cc); + + BOOST_ASSERT(res == exp); +} + +BOOST_AUTO_TEST_CASE(testSub) +{ + bandersnatch::Fr exp( + (uint64_t[4]){ + 0xd4306db17f12686, + 0x8427bea7f896a06d, + 0xc1c92d1ccd02534a, + 0x41294122643035d6, + } + ); + auto f1 = FixedFr1(); + auto f2 = FixedFr2(); + auto res = f1 - f2; + BOOST_ASSERT(res == exp); +} + +BOOST_AUTO_TEST_CASE(testMult) +{ + bandersnatch::Fr exp( + (uint64_t[4]){ + 0xe9f26c96d15bb807, + 0x6ad84e7137609152, + 0xe193b5e1ce7d01c4, + 0x27625b6a622c0518, + } + ); + auto f1 = FixedFr1(); + auto f2 = FixedFr2(); + auto res = f1 * f2; + BOOST_ASSERT(res == exp); +} + +BOOST_AUTO_TEST_CASE(testInv) +{ + bandersnatch::Fr exp( + (uint64_t[4]){ + 0xc2eecde5714050d6, + 0x19f77495338244b4, + 0x65208d07b3ef94b1, + 0x524a236a985c691d, + } + ); + auto f1 = FixedFr1(); + auto res = f1.inv(); + BOOST_ASSERT(res == exp); +} + +BOOST_AUTO_TEST_CASE(testEqual) +{ + uint64_t a[4] = { + 0xc2eecde5714050d6, + 0x19f77495338244b4, + 0x65208d07b3ef94b1, + 0x524a236a985c691d, + }; + bandersnatch::Fr t1(a); + bandersnatch::Fr t2(a); + BOOST_ASSERT(t1 == t2); +} +BOOST_AUTO_TEST_CASE(testSerialize) +{ + auto fr1 = FixedFr1(); + uint64_t a[4]; + fr1.serialize(a); + bandersnatch::Fr fr1Copy(a); + BOOST_ASSERT(fr1Copy == fr1); } BOOST_AUTO_TEST_SUITE_END() diff --git a/bandersnatch/test/unittests/main.cpp b/bandersnatch/test/unittests/main.cpp new file mode 100644 index 0000000..178413e --- /dev/null +++ b/bandersnatch/test/unittests/main.cpp @@ -0,0 +1,5 @@ +#define BOOST_TEST_MODULE VERKLE_Tests +#define BOOST_TEST_MAIN + +#include +#include \ No newline at end of file diff --git a/utilities/CMakelists.txt b/utilities/CMakelists.txt new file mode 100644 index 0000000..f98be3c --- /dev/null +++ b/utilities/CMakelists.txt @@ -0,0 +1,7 @@ +project(utilities) + +find_package(boost_unit_test_framework CONFIG REQUIRED) +find_package(boost_filesystem CONFIG REQUIRED) + +add_library(utilities INTERFACE) +target_include_directories(utilities INTERFACE .) \ No newline at end of file diff --git a/utilities/testutils/TestPromptFixture.h b/utilities/testutils/TestPromptFixture.h new file mode 100644 index 0000000..2cfa611 --- /dev/null +++ b/utilities/testutils/TestPromptFixture.h @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2021 FISCO BCOS. + * SPDX-License-Identifier: Apache-2.0 + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * @file: TestPromptFixture.h + * fixture class for test case prompt + */ + +#pragma once +#include +#include + +namespace verkle::test +{ + +uint64_t utcTime() +{ + return std::chrono::duration_cast( + std::chrono::system_clock::now().time_since_epoch()) + .count(); +} + +class TestPrompt +{ +public: + static TestPrompt& get() + { + static TestPrompt instance; + return instance; + } + TestPrompt(TestPrompt const&) = delete; + void operator=(TestPrompt const&) = delete; + /** + * @brief : init every test-suite by printting the name of cases + * @param _maxTests + */ + void initTest(size_t _maxTests = 1) + { + m_currentTestName = "unknown"; + m_currentTestFileName = std::string(); + m_startTime = utcTime(); + m_currentTestCaseName = boost::unit_test::framework::current_test_case().p_name; + std::cout << "===== Verkle Test Case : " + m_currentTestCaseName << "=====" << std::endl; + m_maxTests = _maxTests; + m_currTest = 0; + }; + + /** + * @brief : release resources when test-suite finished + */ + void finishTest() + { + execTimeName res; + res.first = (double)(utcTime() - m_startTime); + res.second = caseName(); + std::cout << "#### Run " << res.second << " time elapsed: " << res.first << std::endl; + m_execTimeResults.push_back(res); + } + + void setCurrentTestFile(boost::filesystem::path const& _name) { m_currentTestFileName = _name; } + void setCurrentTestName(std::string const& _name) { m_currentTestName = _name; } + std::string const& testName() { return m_currentTestName; } + std::string const& caseName() { return m_currentTestCaseName; } + boost::filesystem::path const& testFile() { return m_currentTestFileName; } + +private: + TestPrompt() {} + size_t m_currTest; + size_t m_maxTests; + std::string m_currentTestName; + std::string m_currentTestCaseName; + boost::filesystem::path m_currentTestFileName; + typedef std::pair execTimeName; + std::vector m_execTimeResults; + int64_t m_startTime; +}; + +class TestPromptFixture +{ +public: + // init test-suite fixture + TestPromptFixture() { TestPrompt::get().initTest(); } + // release test-suite fixture + ~TestPromptFixture() { TestPrompt::get().finishTest(); } +}; +} // namespace test From ee3ab04a32202a40ee9e267eb338837d29210017 Mon Sep 17 00:00:00 2001 From: Zhengxuan Guo Date: Wed, 21 Aug 2024 17:32:55 +0800 Subject: [PATCH 08/12] modify Element, Fr and add unit tests --- bandersnatch/bandersnatch/Element.cpp | 55 +++++++--- bandersnatch/bandersnatch/Element.h | 10 +- bandersnatch/bandersnatch/Fr.cpp | 66 ++++++++---- bandersnatch/bandersnatch/Fr.h | 8 +- bandersnatch/test/CMakeLists.txt | 2 +- bandersnatch/test/unittests/Constants.h | 38 +++++++ bandersnatch/test/unittests/ElementTest.cpp | 109 +++++++++++++++++++- bandersnatch/test/unittests/FrTest.cpp | 67 ++++-------- utilities/testutils/TestPromptFixture.h | 2 +- 9 files changed, 269 insertions(+), 88 deletions(-) create mode 100644 bandersnatch/test/unittests/Constants.h diff --git a/bandersnatch/bandersnatch/Element.cpp b/bandersnatch/bandersnatch/Element.cpp index f1c6035..a052eb9 100644 --- a/bandersnatch/bandersnatch/Element.cpp +++ b/bandersnatch/bandersnatch/Element.cpp @@ -5,11 +5,21 @@ using namespace verkle::bandersnatch; -Element::Element() : m_point(std::make_shared()) {} +Element::Element() = default; -Element::Element(const blst_p1& point) : m_point(std::make_shared(point)) {} +Element::Element(const Element& other) : m_point(other.m_point) {} -Element::Element(const byte* in, size_t len) : m_point(std::make_shared()) +Element& Element::operator=(const Element& other) +{ + if (this == &other) + { + return *this; + } + this->m_point = other.m_point; + return *this; +} + +Element::Element(const byte* in, size_t len) { if (len == 0 || len != (in[0]&0x80 ? 48 : 96)) throw BLST_BAD_ENCODING; @@ -17,40 +27,50 @@ Element::Element(const byte* in, size_t len) : m_point(std::make_shared BLST_ERROR err = blst_p1_deserialize(&a, in); if (err != BLST_SUCCESS) throw err; - blst_p1_from_affine(m_point.get(), &a); + blst_p1_from_affine(&m_point, &a); } Element& Element::add(const Element& other) { - blst_p1_add(m_point.get(), m_point.get(), other.m_point.get()); + blst_p1_add_or_double(&m_point, &m_point, &other.m_point); return *this; } Element& Element::dbl() { - blst_p1_double(m_point.get(), m_point.get()); + blst_p1_double(&m_point, &m_point); return *this; } Element& Element::mult(const Fr& fr) { blst_scalar scalar; - blst_scalar_from_fr(&scalar, fr.m_val.get()); - blst_p1_mult(m_point.get(), m_point.get(), scalar.b, 255); + blst_scalar_from_fr(&scalar, &fr.m_val); + blst_p1_mult(&m_point, &m_point, scalar.b, 255); return *this; } +bool Element::operator==(const Element& other) const +{ + return blst_p1_is_equal(&m_point, &other.m_point); +} + +bool Element::operator!=(const Element& other) const +{ + return !(*this == other); +} + Element Element::add(const Element& a, const Element& b) { Element ret; - blst_p1_add(ret.m_point.get(), a.m_point.get(), b.m_point.get()); + blst_p1_add_or_double(&ret.m_point, &a.m_point, &b.m_point); return ret; } Element Element::dbl(const Element& a) { Element ret; - blst_p1_double(ret.m_point.get(), a.m_point.get()); + blst_p1_double(&ret.m_point, &a.m_point); return ret; } @@ -58,18 +78,25 @@ Element Element::mult(const Fr& fr, const Element& a) { Element ret; blst_scalar scalar; - blst_scalar_from_fr(&scalar, fr.m_val.get()); - blst_p1_mult(ret.m_point.get(), a.m_point.get(), scalar.b, 255); + blst_scalar_from_fr(&scalar, &fr.m_val); + blst_p1_mult(&ret.m_point, &a.m_point, scalar.b, 255); return ret; } Element Element::generator() { + Element ret; auto g = blst_p1_generator(); - return Element(*g); + ret.m_point = *g; + return ret; } void Element::serialize(byte out[96]) const { - blst_p1_serialize(out, m_point.get()); + blst_p1_serialize(out, &m_point); } + +void Element::compress(byte out[48]) const +{ + blst_p1_compress(out, &m_point); +} \ No newline at end of file diff --git a/bandersnatch/bandersnatch/Element.h b/bandersnatch/bandersnatch/Element.h index 3042ce5..b84a3fc 100644 --- a/bandersnatch/bandersnatch/Element.h +++ b/bandersnatch/bandersnatch/Element.h @@ -11,12 +11,17 @@ class Element { public: Element(); - explicit Element(const blst_p1& point); + Element(const Element& other); + Element& operator=(const Element& other); + Element(const byte *in, size_t len); Element& add(const Element& other); Element& dbl(); Element& mult(const Fr& fr); + bool operator==(const Element& other) const; + bool operator!=(const Element& other) const; + static Element add(const Element& a, const Element& b); static Element dbl(const Element& a); static Element mult(const Fr& fr, const Element& a); @@ -24,8 +29,9 @@ class Element static Element generator(); void serialize(byte out[96]) const; + void compress(byte out[48]) const; private: - std::shared_ptr m_point; + blst_p1 m_point; }; } \ No newline at end of file diff --git a/bandersnatch/bandersnatch/Fr.cpp b/bandersnatch/bandersnatch/Fr.cpp index 9426cb5..5494a6e 100644 --- a/bandersnatch/bandersnatch/Fr.cpp +++ b/bandersnatch/bandersnatch/Fr.cpp @@ -8,24 +8,38 @@ using namespace verkle::bandersnatch; -Fr::Fr() : m_val(std::make_shared()) {} +Fr::Fr() = default; -Fr::Fr(const uint64_t a[4]) : m_val(std::make_shared()) +Fr::Fr(const Fr& other) : m_val(other.m_val) {} + +Fr& Fr::operator=(const Fr& other) +{ + if (this == &other) + { + return *this; + } + this->m_val = other.m_val; + return *this; +} + +Fr::Fr(const uint64_t a[4]) { - blst_fr_from_uint64(m_val.get(), a); + blst_fr_from_uint64(&m_val, a); } -Fr::Fr(const uint8_t* msg, size_t len) : m_val(std::make_shared()) +Fr::Fr(const uint8_t* msg, size_t len) { blst_scalar scalar; blst_scalar_from_le_bytes(&scalar, msg, (len+7)/8); - blst_fr_from_scalar(m_val.get(), &scalar); + blst_fr_from_scalar(&m_val, &scalar); } Fr Fr::zero() { // zero value of Fr is simply 0x0 - return Fr(); + Fr ret; + memset(&ret.m_val, 0, sizeof(ret.m_val)); + return ret; } Fr Fr::random() @@ -39,42 +53,34 @@ Fr Fr::random() { a[i] = dis(gen); } - Fr ret; - blst_fr_from_uint64(ret.m_val.get(), a); + Fr ret(a); return ret; } Fr Fr::operator+(const Fr& other) const { Fr ret; - blst_fr_add(ret.m_val.get(), m_val.get(), other.m_val.get()); + blst_fr_add(&ret.m_val, &m_val, &other.m_val); return ret; } Fr Fr::operator-(const Fr& other) const { Fr ret; - blst_fr_sub(ret.m_val.get(), m_val.get(), other.m_val.get()); + blst_fr_sub(&ret.m_val, &m_val, &other.m_val); return ret; } Fr Fr::operator*(const Fr& other) const { Fr ret; - blst_fr_mul(ret.m_val.get(), m_val.get(), other.m_val.get()); + blst_fr_mul(&ret.m_val, &m_val, &other.m_val); return ret; } bool Fr::operator==(const Fr& other) const { - for (int i = 0; i < 4; ++i) - { - if (m_val.get()->l[i] != other.m_val.get()->l[i]) - { - return false; - } - } - return true; + return std::memcmp(&m_val, &other.m_val, sizeof(blst_fr)) == 0; } bool Fr::operator!=(const Fr& other) const @@ -85,11 +91,29 @@ bool Fr::operator!=(const Fr& other) const Fr Fr::inv() const { Fr ret; - blst_fr_inverse(ret.m_val.get(), m_val.get()); + blst_fr_inverse(&ret.m_val, &m_val); return ret; } +Fr& Fr::operator+=(const Fr& other) +{ + blst_fr_add(&m_val, &m_val, &other.m_val); + return *this; +} + +Fr& Fr::operator-=(const Fr& other) +{ + blst_fr_sub(&m_val, &m_val, &other.m_val); + return *this; +} + +Fr& Fr::operator*=(const Fr& other) +{ + blst_fr_mul(&m_val, &m_val, &other.m_val); + return *this; +} + void Fr::serialize(uint64_t ret[4]) const { - blst_uint64_from_fr(ret, m_val.get()); + blst_uint64_from_fr(ret, &m_val); } \ No newline at end of file diff --git a/bandersnatch/bandersnatch/Fr.h b/bandersnatch/bandersnatch/Fr.h index 1b9621f..cca2c57 100644 --- a/bandersnatch/bandersnatch/Fr.h +++ b/bandersnatch/bandersnatch/Fr.h @@ -12,6 +12,8 @@ class Fr { public: Fr(); + Fr(const Fr& other); + Fr& operator=(const Fr& other); // deserialize Fr(const uint64_t a[4]); @@ -27,10 +29,14 @@ class Fr bool operator==(const Fr& other) const; bool operator!=(const Fr& other) const; + Fr& operator+=(const Fr& other); + Fr& operator-=(const Fr& other); + Fr& operator*=(const Fr& other); + void serialize(uint64_t ret[4]) const; private: - std::shared_ptr m_val; + blst_fr m_val; friend class Element; }; } \ No newline at end of file diff --git a/bandersnatch/test/CMakeLists.txt b/bandersnatch/test/CMakeLists.txt index a886e6b..db61d3a 100644 --- a/bandersnatch/test/CMakeLists.txt +++ b/bandersnatch/test/CMakeLists.txt @@ -1,7 +1,7 @@ file(GLOB_RECURSE TEST_SRCS "*.cpp") add_executable(bandersnatch-test ${TEST_SRCS}) -target_include_directories(bandersnatch-test PRIVATE ..) +target_include_directories(bandersnatch-test PRIVATE . ..) find_package(boost_unit_test_framework CONFIG REQUIRED) diff --git a/bandersnatch/test/unittests/Constants.h b/bandersnatch/test/unittests/Constants.h new file mode 100644 index 0000000..320db39 --- /dev/null +++ b/bandersnatch/test/unittests/Constants.h @@ -0,0 +1,38 @@ +#pragma once +#include "bandersnatch/Fr.h" +#include "bandersnatch/Element.h" + +namespace verkle::test +{ +static inline const bandersnatch::Fr& FixedFr1() +{ + static bandersnatch::Fr fr1( + (uint64_t[4]){ + 0xe5d76b4ca918a221, + 0x81ed0b8d092ec3c6, + 0xd124e15f2054fa57, + 0x2ef123703093cbbb, + } + ); + return fr1; +} + +static inline const bandersnatch::Fr& FixedFr2() +{ + static bandersnatch::Fr fr2( + (uint64_t[4]){ + 0xd894647091277b9c, + 0x5182f0e810967f58, + 0x42958c4a5cf47f12, + 0x61b589a0f601132d, + } + ); + return fr2; +} + +static inline const bandersnatch::Element& FixedGenerator() +{ + static auto g = bandersnatch::Element::generator(); + return g; +} +} \ No newline at end of file diff --git a/bandersnatch/test/unittests/ElementTest.cpp b/bandersnatch/test/unittests/ElementTest.cpp index a3d6008..10565fa 100644 --- a/bandersnatch/test/unittests/ElementTest.cpp +++ b/bandersnatch/test/unittests/ElementTest.cpp @@ -2,13 +2,120 @@ // Created by Zhengxuan Guo on 2024/8/15. // #include "bandersnatch/Element.h" +#include "testutils/TestPromptFixture.h" +#include "Constants.h" #include namespace verkle::test { +BOOST_FIXTURE_TEST_SUITE(ElementTest, TestPromptFixture) BOOST_AUTO_TEST_CASE(testAdd) { - + bandersnatch::Element exp( + (uint8_t[96]){ + 0x5, 0x72, 0xcb, 0xea, 0x90, 0x4d, 0x67, 0x46, 0x88, 0x8, 0xc8, 0xeb, 0x50, 0xa9, 0x45, 0xc, + 0x97, 0x21, 0xdb, 0x30, 0x91, 0x28, 0x1, 0x25, 0x43, 0x90, 0x2d, 0xa, 0xc3, 0x58, 0xa6, 0x2a, + 0xe2, 0x8f, 0x75, 0xbb, 0x8f, 0x1c, 0x7c, 0x42, 0xc3, 0x9a, 0x8c, 0x55, 0x29, 0xbf, 0xf, 0x4e, + 0x16, 0x6a, 0x9d, 0x8c, 0xab, 0xc6, 0x73, 0xa3, 0x22, 0xfd, 0xa6, 0x73, 0x77, 0x9d, 0x8e, 0x38, + 0x22, 0xba, 0x3e, 0xcb, 0x86, 0x70, 0xe4, 0x61, 0xf7, 0x3b, 0xb9, 0x2, 0x1d, 0x5f, 0xd7, 0x6a, + 0x4c, 0x56, 0xd9, 0xd4, 0xcd, 0x16, 0xbd, 0x1b, 0xba, 0x86, 0x88, 0x19, 0x79, 0x74, 0x9d, 0x28 + }, + 96 + ); + auto g = FixedGenerator(); + auto res = bandersnatch::Element::add(g, g); + BOOST_ASSERT(res == exp); + + bandersnatch::Element g2(g); + g2.add(g); + BOOST_ASSERT(g2 == exp); +} + +BOOST_AUTO_TEST_CASE(testDouble) +{ + bandersnatch::Element exp( + (uint8_t[96]){ + 0x5, 0x72, 0xcb, 0xea, 0x90, 0x4d, 0x67, 0x46, 0x88, 0x8, 0xc8, 0xeb, 0x50, 0xa9, 0x45, 0xc, + 0x97, 0x21, 0xdb, 0x30, 0x91, 0x28, 0x1, 0x25, 0x43, 0x90, 0x2d, 0xa, 0xc3, 0x58, 0xa6, 0x2a, + 0xe2, 0x8f, 0x75, 0xbb, 0x8f, 0x1c, 0x7c, 0x42, 0xc3, 0x9a, 0x8c, 0x55, 0x29, 0xbf, 0xf, 0x4e, + 0x16, 0x6a, 0x9d, 0x8c, 0xab, 0xc6, 0x73, 0xa3, 0x22, 0xfd, 0xa6, 0x73, 0x77, 0x9d, 0x8e, 0x38, + 0x22, 0xba, 0x3e, 0xcb, 0x86, 0x70, 0xe4, 0x61, 0xf7, 0x3b, 0xb9, 0x2, 0x1d, 0x5f, 0xd7, 0x6a, + 0x4c, 0x56, 0xd9, 0xd4, 0xcd, 0x16, 0xbd, 0x1b, 0xba, 0x86, 0x88, 0x19, 0x79, 0x74, 0x9d, 0x28 + }, + 96 + ); + auto g = FixedGenerator(); + auto res = bandersnatch::Element::dbl(g); + BOOST_ASSERT(res == exp); + + bandersnatch::Element g2(g); + g2.dbl(); + BOOST_ASSERT(g2 == exp); +} + +BOOST_AUTO_TEST_CASE(testMult) +{ + bandersnatch::Element exp( + (uint8_t[96]){ + 0x16, 0xf8, 0x9e, 0x71, 0x6a, 0xbc, 0x6e, 0x4f, 0x4e, 0xc9, 0xd7, 0x1a, 0x5f, 0x5, 0x38, 0x32, + 0x51, 0xc0, 0x1e, 0xd9, 0xc4, 0xf, 0x2f, 0x4d, 0xdc, 0x9a, 0x77, 0xd8, 0x7b, 0xf6, 0xc, 0x4a, + 0xa2, 0xea, 0x60, 0x3a, 0x8d, 0x3a, 0xda, 0x49, 0x4f, 0x6f, 0x6d, 0x15, 0x87, 0x87, 0xa4, 0x49, + 0xd, 0x83, 0x9, 0x7b, 0xa7, 0x85, 0x97, 0x4, 0x2, 0x4b, 0x49, 0x41, 0xfd, 0x76, 0xf, 0x85, + 0xbc, 0xa6, 0xdb, 0xc4, 0xa8, 0x4a, 0x7, 0x1a, 0xf9, 0xef, 0x44, 0x3c, 0x1a, 0x55, 0x3f, 0xc8, + 0x7f, 0xc6, 0x1e, 0x9, 0x92, 0xa4, 0x0, 0x6d, 0x54, 0xfa, 0x36, 0x70, 0x5f, 0x61, 0x16, 0x90 + }, + 96 + ); + auto g = FixedGenerator(); + auto fr1 = FixedFr1(); + auto res1 = bandersnatch::Element::mult(fr1, g); + BOOST_ASSERT(res1 == exp); + + bandersnatch::Element g2(g); + g2.mult(fr1); + BOOST_ASSERT(g2 == exp); +} + +BOOST_AUTO_TEST_CASE(testEqual) +{ + bandersnatch::Element e( + (uint8_t[96]){ + 0x5, 0x72, 0xcb, 0xea, 0x90, 0x4d, 0x67, 0x46, 0x88, 0x8, 0xc8, 0xeb, 0x50, 0xa9, 0x45, 0xc, + 0x97, 0x21, 0xdb, 0x30, 0x91, 0x28, 0x1, 0x25, 0x43, 0x90, 0x2d, 0xa, 0xc3, 0x58, 0xa6, 0x2a, + 0xe2, 0x8f, 0x75, 0xbb, 0x8f, 0x1c, 0x7c, 0x42, 0xc3, 0x9a, 0x8c, 0x55, 0x29, 0xbf, 0xf, 0x4e, + 0x16, 0x6a, 0x9d, 0x8c, 0xab, 0xc6, 0x73, 0xa3, 0x22, 0xfd, 0xa6, 0x73, 0x77, 0x9d, 0x8e, 0x38, + 0x22, 0xba, 0x3e, 0xcb, 0x86, 0x70, 0xe4, 0x61, 0xf7, 0x3b, 0xb9, 0x2, 0x1d, 0x5f, 0xd7, 0x6a, + 0x4c, 0x56, 0xd9, 0xd4, 0xcd, 0x16, 0xbd, 0x1b, 0xba, 0x86, 0x88, 0x19, 0x79, 0x74, 0x9d, 0x28 + }, + 96 + ); + bandersnatch::Element e1(e); + bandersnatch::Element e2(e); + BOOST_ASSERT(e1 == e2); } + +BOOST_AUTO_TEST_CASE(testSerialize) +{ + auto g = FixedGenerator(); + + byte out[96]; + g.serialize(out); + + bandersnatch::Element recover(out, 96); + BOOST_ASSERT(recover == g); +} + +BOOST_AUTO_TEST_CASE(testCompress) +{ + auto g = FixedGenerator(); + + byte out[48]; + g.compress(out); + + bandersnatch::Element recover(out, 48); + BOOST_ASSERT(recover == g); +} + +BOOST_AUTO_TEST_SUITE_END() } \ No newline at end of file diff --git a/bandersnatch/test/unittests/FrTest.cpp b/bandersnatch/test/unittests/FrTest.cpp index de09240..fcd0021 100644 --- a/bandersnatch/test/unittests/FrTest.cpp +++ b/bandersnatch/test/unittests/FrTest.cpp @@ -3,36 +3,11 @@ // #include "bandersnatch/Fr.h" #include "testutils/TestPromptFixture.h" +#include "Constants.h" #include namespace verkle::test { -static inline bandersnatch::Fr FixedFr1() -{ - static bandersnatch::Fr fr1( - (uint64_t[4]){ - 0xe5d76b4ca918a221, - 0x81ed0b8d092ec3c6, - 0xd124e15f2054fa57, - 0x2ef123703093cbbb, - } - ); - return fr1; -} - -static inline bandersnatch::Fr FixedFr2() -{ - static bandersnatch::Fr fr2( - (uint64_t[4]){ - 0xd894647091277b9c, - 0x5182f0e810967f58, - 0x42958c4a5cf47f12, - 0x61b589a0f601132d, - } - ); - return fr2; -} - BOOST_FIXTURE_TEST_SUITE(FrTest, TestPromptFixture) BOOST_AUTO_TEST_CASE(testFromBytes) @@ -76,24 +51,12 @@ BOOST_AUTO_TEST_CASE(testAdd) auto f1 = FixedFr1(); auto f2 = FixedFr2(); - auto res = f1 + f2; - uint64_t another[4]; - res.serialize(another); - bandersnatch::Fr newExp(another); - - auto a = f1 - f2; - uint64_t aa[4]; - a.serialize(aa); - - auto b = f1 * f2; - uint64_t bb[4]; - b.serialize(bb); - - auto c = f1.inv(); - uint64_t cc[4]; - c.serialize(cc); + auto res1 = f1 + f2; + BOOST_ASSERT(res1 == exp); - BOOST_ASSERT(res == exp); + bandersnatch::Fr res2(f1); + res2 += f2; + BOOST_ASSERT(res2 == exp); } BOOST_AUTO_TEST_CASE(testSub) @@ -108,8 +71,13 @@ BOOST_AUTO_TEST_CASE(testSub) ); auto f1 = FixedFr1(); auto f2 = FixedFr2(); - auto res = f1 - f2; - BOOST_ASSERT(res == exp); + + auto res1 = f1 - f2; + BOOST_ASSERT(res1 == exp); + + bandersnatch::Fr res2(f1); + res2 -= f2; + BOOST_ASSERT(res2 == exp); } BOOST_AUTO_TEST_CASE(testMult) @@ -124,8 +92,13 @@ BOOST_AUTO_TEST_CASE(testMult) ); auto f1 = FixedFr1(); auto f2 = FixedFr2(); - auto res = f1 * f2; - BOOST_ASSERT(res == exp); + + auto res1 = f1 * f2; + BOOST_ASSERT(res1 == exp); + + bandersnatch::Fr res2(f1); + res2 *= f2; + BOOST_ASSERT(res2 == exp); } BOOST_AUTO_TEST_CASE(testInv) diff --git a/utilities/testutils/TestPromptFixture.h b/utilities/testutils/TestPromptFixture.h index 2cfa611..3ac1865 100644 --- a/utilities/testutils/TestPromptFixture.h +++ b/utilities/testutils/TestPromptFixture.h @@ -24,7 +24,7 @@ namespace verkle::test { -uint64_t utcTime() +inline uint64_t utcTime() { return std::chrono::duration_cast( std::chrono::system_clock::now().time_since_epoch()) From a08b8102c07dfdbe1488f76f2d596cfbff3ff6dc Mon Sep 17 00:00:00 2001 From: Zhengxuan Guo Date: Wed, 21 Aug 2024 19:14:49 +0800 Subject: [PATCH 09/12] remove utility/ --- utility/CMakelists.txt | 4 -- utility/testutils/TestPromptFixture.h | 97 --------------------------- 2 files changed, 101 deletions(-) delete mode 100644 utility/CMakelists.txt delete mode 100644 utility/testutils/TestPromptFixture.h diff --git a/utility/CMakelists.txt b/utility/CMakelists.txt deleted file mode 100644 index eafeaa8..0000000 --- a/utility/CMakelists.txt +++ /dev/null @@ -1,4 +0,0 @@ -project(utilities) - -find_package(boost_unit_test_framework CONFIG REQUIRED) -find_package(boost_filesystem CONFIG REQUIRED) \ No newline at end of file diff --git a/utility/testutils/TestPromptFixture.h b/utility/testutils/TestPromptFixture.h deleted file mode 100644 index 2cfa611..0000000 --- a/utility/testutils/TestPromptFixture.h +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (C) 2021 FISCO BCOS. - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * @file: TestPromptFixture.h - * fixture class for test case prompt - */ - -#pragma once -#include -#include - -namespace verkle::test -{ - -uint64_t utcTime() -{ - return std::chrono::duration_cast( - std::chrono::system_clock::now().time_since_epoch()) - .count(); -} - -class TestPrompt -{ -public: - static TestPrompt& get() - { - static TestPrompt instance; - return instance; - } - TestPrompt(TestPrompt const&) = delete; - void operator=(TestPrompt const&) = delete; - /** - * @brief : init every test-suite by printting the name of cases - * @param _maxTests - */ - void initTest(size_t _maxTests = 1) - { - m_currentTestName = "unknown"; - m_currentTestFileName = std::string(); - m_startTime = utcTime(); - m_currentTestCaseName = boost::unit_test::framework::current_test_case().p_name; - std::cout << "===== Verkle Test Case : " + m_currentTestCaseName << "=====" << std::endl; - m_maxTests = _maxTests; - m_currTest = 0; - }; - - /** - * @brief : release resources when test-suite finished - */ - void finishTest() - { - execTimeName res; - res.first = (double)(utcTime() - m_startTime); - res.second = caseName(); - std::cout << "#### Run " << res.second << " time elapsed: " << res.first << std::endl; - m_execTimeResults.push_back(res); - } - - void setCurrentTestFile(boost::filesystem::path const& _name) { m_currentTestFileName = _name; } - void setCurrentTestName(std::string const& _name) { m_currentTestName = _name; } - std::string const& testName() { return m_currentTestName; } - std::string const& caseName() { return m_currentTestCaseName; } - boost::filesystem::path const& testFile() { return m_currentTestFileName; } - -private: - TestPrompt() {} - size_t m_currTest; - size_t m_maxTests; - std::string m_currentTestName; - std::string m_currentTestCaseName; - boost::filesystem::path m_currentTestFileName; - typedef std::pair execTimeName; - std::vector m_execTimeResults; - int64_t m_startTime; -}; - -class TestPromptFixture -{ -public: - // init test-suite fixture - TestPromptFixture() { TestPrompt::get().initTest(); } - // release test-suite fixture - ~TestPromptFixture() { TestPrompt::get().finishTest(); } -}; -} // namespace test From 793dfc041a50e043639cc731f2dd33c731e7f844 Mon Sep 17 00:00:00 2001 From: Zhengxuan Guo Date: Thu, 22 Aug 2024 11:04:10 +0800 Subject: [PATCH 10/12] add github workflows --- .github/workflows/workflow.yml | 161 +++++++++++++++++++++++++++++++++ vcpkg.json | 2 +- 2 files changed, 162 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/workflow.yml diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml new file mode 100644 index 0000000..12a6619 --- /dev/null +++ b/.github/workflows/workflow.yml @@ -0,0 +1,161 @@ +name: bcos-crypto GitHub Actions +on: + push: + paths-ignore: + - "docs/**" + - "Changelog.md" + - "README.md" + pull_request: + paths-ignore: + - "docs/**" + - "Changelog.md" + - "README.md" + release: + types: [published, created, edited] +env: + CCACHE_DIR: ${{ github.workspace }}/ccache + +jobs: + build_with_clang: + name: build_with_clang + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [macos-latest] + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 5 + - name: install macOS dependencies + if: runner.os == 'macOS' + run: brew install ccache + - name: install Ubuntu dependencies + if: runner.os == 'Linux' + run: sudo apt install -y git curl build-essential clang cmake ccache + - name: vcpkg essentials + run: | + git clone https://github.com/microsoft/vcpkg.git + export VCPKG_ROOT=$(pwd)/vcpkg + export PATH=$PATH:$VCPKG_ROOT + - name: configure + if: runner.os == 'macOS' + run: | + export SDKROOT=$(xcrun --sdk macosx --show-sdk-path) && CC=/usr/bin/clang CXX=/usr/bin/clang++ + cmake --preset=test + - name: configure + if: runner.os == 'Linux' + run: | + export CC=/usr/bin/clang CXX=/usr/bin/clang++ + cmake --preset=test + - name: compile + run: cmake --build build -j2 + - name: run test + run: cd build/bandersnatch && ctest + build_with_gcc: + name: build_with_gcc + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-20.04] + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 5 + - uses: actions/cache@v2 + id: ccache + with: + path: ccache + key: ccache-ubuntu20-v2-notest-${{ runner.temp }}-${{ github.base_ref }}-${{ hashFiles('.github/workflows/workflow.yml') }} + restore-keys: | + ccache-ubuntu20-v2-notest-${{ runner.temp }}-${{ github.base_ref }}-${{ hashFiles('.github/workflows/workflow.yml') }} + ccache-ubuntu20-v2-notest-${{ runner.temp }}-${{ github.base_ref }}- + ccache-ubuntu20-v2-notest-${{ runner.temp }}- + - name: install Ubuntu dependencies + run: | + sudo apt update + sudo apt install -y git curl build-essential cmake ccache + - name: vcpkg essentials + run: | + git clone https://github.com/microsoft/vcpkg.git + export VCPKG_ROOT=$(pwd)/vcpkg + export PATH=$PATH:$VCPKG_ROOT + - name: configure + run: | + export GCC='gcc-10' + export CXX='g++-10' + export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" + cmake --preset=test + - name: compile + run: cmake --build build -j2 + - name: run test + run: cd build/bandersnatch && ctest + ubuntu22_04_build_with_gcc: + name: ubuntu22_04_build_with_gcc + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-22.04] + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 5 + - uses: actions/cache@v2 + id: ccache + with: + path: ccache + key: ccache-ubuntu-v2-notest-${{ runner.temp }}-${{ github.base_ref }}-${{ hashFiles('.github/workflows/workflow.yml') }} + restore-keys: | + ccache-ubuntu-v2-notest-${{ runner.temp }}-${{ github.base_ref }}-${{ hashFiles('.github/workflows/workflow.yml') }} + ccache-ubuntu-v2-notest-${{ runner.temp }}-${{ github.base_ref }}- + ccache-ubuntu-v2-notest-${{ runner.temp }}- + - name: install Ubuntu dependencies + run: | + sudo apt-get update + sudo apt-get install -y git curl build-essential cmake ccache lcov libzstd-dev python3-dev + - name: vcpkg essentials + run: | + git clone https://github.com/microsoft/vcpkg.git + export VCPKG_ROOT=$(pwd)/vcpkg + export PATH=$PATH:$VCPKG_ROOT + - name: configure + run: | + export GCC='gcc-10' + export CXX='g++-10' + export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" + export CPATH=/Library/Developer/CommandLineTools/usr/include/c++/v1 + cmake --preset=test + - name: compile + run: cmake --build build -j2 + - name: run test + run: cd build/bandersnatch && ctest + build_with_centos: + name: build_with_centos + runs-on: ubuntu-latest + container: + image: docker.io/centos:7 + volumes: + - /github/home/.hunter:/github/home/.hunter + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 5 + - name: install CentOS dependencies + run: | + yum install -y epel-release centos-release-scl + yum install -y git make gcc gcc-c++ glibc-static glibc-devel cmake3 ccache devtoolset-11 llvm-toolset-7.0 rh-perl530-perl libzstd-devel zlib-devel flex bison python-devel python3-devel + - name: configure and compile + run: | + rustup override set stable + cargo --version + export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" + . /opt/rh/devtoolset-11/enable + . /opt/rh/rh-perl530/enable + export LIBCLANG_PATH=/opt/rh/llvm-toolset-7.0/root/lib64/ + . /opt/rh/llvm-toolset-7.0/enable + alias cmake='cmake3' + git clone https://github.com/microsoft/vcpkg.git + export VCPKG_ROOT=$(pwd)/vcpkg + export PATH=$PATH:$VCPKG_ROOT + cmake3 --preset=test + cmake --build build -j2 + cd build/bandersnatch && ctest \ No newline at end of file diff --git a/vcpkg.json b/vcpkg.json index 77873ae..c76fc33 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -3,6 +3,6 @@ "version": "1.0", "dependencies": [ "boost-test", - "boost-log" + "boost-filesystem" ] } From b605bc0b6ef3c678f747f0abd2cd5a95f8962975 Mon Sep 17 00:00:00 2001 From: Zhengxuan Guo Date: Thu, 22 Aug 2024 11:24:11 +0800 Subject: [PATCH 11/12] test native workflow --- .github/workflows/workflow.yml | 120 ++------------------------------- 1 file changed, 5 insertions(+), 115 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 12a6619..b21ae69 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -12,8 +12,6 @@ on: - "README.md" release: types: [published, created, edited] -env: - CCACHE_DIR: ${{ github.workspace }}/ccache jobs: build_with_clang: @@ -21,7 +19,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [macos-latest] + os: [macos-latest, ubuntu-latest] steps: - uses: actions/checkout@v2 with: @@ -31,7 +29,7 @@ jobs: run: brew install ccache - name: install Ubuntu dependencies if: runner.os == 'Linux' - run: sudo apt install -y git curl build-essential clang cmake ccache + run: sudo apt install -y git curl build-essential clang cmake - name: vcpkg essentials run: | git clone https://github.com/microsoft/vcpkg.git @@ -40,8 +38,8 @@ jobs: - name: configure if: runner.os == 'macOS' run: | - export SDKROOT=$(xcrun --sdk macosx --show-sdk-path) && CC=/usr/bin/clang CXX=/usr/bin/clang++ - cmake --preset=test + export SDKROOT=$(xcrun --sdk macosx --show-sdk-path) && CC=/usr/bin/clang CXX=/usr/bin/clang++ + cmake --preset=test - name: configure if: runner.os == 'Linux' run: | @@ -50,112 +48,4 @@ jobs: - name: compile run: cmake --build build -j2 - name: run test - run: cd build/bandersnatch && ctest - build_with_gcc: - name: build_with_gcc - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ubuntu-20.04] - steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 5 - - uses: actions/cache@v2 - id: ccache - with: - path: ccache - key: ccache-ubuntu20-v2-notest-${{ runner.temp }}-${{ github.base_ref }}-${{ hashFiles('.github/workflows/workflow.yml') }} - restore-keys: | - ccache-ubuntu20-v2-notest-${{ runner.temp }}-${{ github.base_ref }}-${{ hashFiles('.github/workflows/workflow.yml') }} - ccache-ubuntu20-v2-notest-${{ runner.temp }}-${{ github.base_ref }}- - ccache-ubuntu20-v2-notest-${{ runner.temp }}- - - name: install Ubuntu dependencies - run: | - sudo apt update - sudo apt install -y git curl build-essential cmake ccache - - name: vcpkg essentials - run: | - git clone https://github.com/microsoft/vcpkg.git - export VCPKG_ROOT=$(pwd)/vcpkg - export PATH=$PATH:$VCPKG_ROOT - - name: configure - run: | - export GCC='gcc-10' - export CXX='g++-10' - export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" - cmake --preset=test - - name: compile - run: cmake --build build -j2 - - name: run test - run: cd build/bandersnatch && ctest - ubuntu22_04_build_with_gcc: - name: ubuntu22_04_build_with_gcc - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ubuntu-22.04] - steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 5 - - uses: actions/cache@v2 - id: ccache - with: - path: ccache - key: ccache-ubuntu-v2-notest-${{ runner.temp }}-${{ github.base_ref }}-${{ hashFiles('.github/workflows/workflow.yml') }} - restore-keys: | - ccache-ubuntu-v2-notest-${{ runner.temp }}-${{ github.base_ref }}-${{ hashFiles('.github/workflows/workflow.yml') }} - ccache-ubuntu-v2-notest-${{ runner.temp }}-${{ github.base_ref }}- - ccache-ubuntu-v2-notest-${{ runner.temp }}- - - name: install Ubuntu dependencies - run: | - sudo apt-get update - sudo apt-get install -y git curl build-essential cmake ccache lcov libzstd-dev python3-dev - - name: vcpkg essentials - run: | - git clone https://github.com/microsoft/vcpkg.git - export VCPKG_ROOT=$(pwd)/vcpkg - export PATH=$PATH:$VCPKG_ROOT - - name: configure - run: | - export GCC='gcc-10' - export CXX='g++-10' - export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" - export CPATH=/Library/Developer/CommandLineTools/usr/include/c++/v1 - cmake --preset=test - - name: compile - run: cmake --build build -j2 - - name: run test - run: cd build/bandersnatch && ctest - build_with_centos: - name: build_with_centos - runs-on: ubuntu-latest - container: - image: docker.io/centos:7 - volumes: - - /github/home/.hunter:/github/home/.hunter - steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 5 - - name: install CentOS dependencies - run: | - yum install -y epel-release centos-release-scl - yum install -y git make gcc gcc-c++ glibc-static glibc-devel cmake3 ccache devtoolset-11 llvm-toolset-7.0 rh-perl530-perl libzstd-devel zlib-devel flex bison python-devel python3-devel - - name: configure and compile - run: | - rustup override set stable - cargo --version - export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" - . /opt/rh/devtoolset-11/enable - . /opt/rh/rh-perl530/enable - export LIBCLANG_PATH=/opt/rh/llvm-toolset-7.0/root/lib64/ - . /opt/rh/llvm-toolset-7.0/enable - alias cmake='cmake3' - git clone https://github.com/microsoft/vcpkg.git - export VCPKG_ROOT=$(pwd)/vcpkg - export PATH=$PATH:$VCPKG_ROOT - cmake3 --preset=test - cmake --build build -j2 - cd build/bandersnatch && ctest \ No newline at end of file + run: cd build/bandersnatch && ctest \ No newline at end of file From cd3eafcf01d5d473c9ea142255052f7f352ada16 Mon Sep 17 00:00:00 2001 From: Zhengxuan Guo Date: Thu, 22 Aug 2024 17:04:31 +0800 Subject: [PATCH 12/12] add workflows & fix bandersnatch test error --- .github/workflows/workflow.yml | 61 ++++++++++++++- bandersnatch/bandersnatch/Fr.cpp | 1 + bandersnatch/test/unittests/Constants.h | 30 ++++---- bandersnatch/test/unittests/ElementTest.cpp | 80 +++++++++----------- bandersnatch/test/unittests/FrTest.cpp | 61 +++++++-------- utilities/{CMakelists.txt => CMakeLists.txt} | 0 6 files changed, 139 insertions(+), 94 deletions(-) rename utilities/{CMakelists.txt => CMakeLists.txt} (100%) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index b21ae69..a690cb3 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -33,8 +33,8 @@ jobs: - name: vcpkg essentials run: | git clone https://github.com/microsoft/vcpkg.git - export VCPKG_ROOT=$(pwd)/vcpkg - export PATH=$PATH:$VCPKG_ROOT + echo "VCPKG_ROOT=$(pwd)/vcpkg" >> "$GITHUB_ENV" + echo "PATH=$PATH:$VCPKG_ROOT" >> "$GITHUB_ENV" - name: configure if: runner.os == 'macOS' run: | @@ -47,5 +47,62 @@ jobs: cmake --preset=test - name: compile run: cmake --build build -j2 + - name: run test + run: cd build/bandersnatch && ctest + build_with_gcc: + name: build_with_gcc + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-20.04] + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 5 + - name: install Ubuntu dependencies + run: | + sudo apt update + sudo apt install -y git curl build-essential cmake + - name: vcpkg essentials + run: | + git clone https://github.com/microsoft/vcpkg.git + echo "VCPKG_ROOT=$(pwd)/vcpkg" >> "$GITHUB_ENV" + echo "PATH=$PATH:$VCPKG_ROOT" >> "$GITHUB_ENV" + - name: configure + run: | + export GCC='gcc-10' + export CXX='g++-10' + cmake --preset=test + - name: compile + run: cmake --build build -j2 + - name: run test + run: cd build/bandersnatch && ctest + ubuntu22_04_build_with_gcc: + name: ubuntu22_04_build_with_gcc + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-22.04] + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 5 + - name: install Ubuntu dependencies + run: | + sudo apt-get update + sudo apt-get install -y git curl build-essential cmake lcov libzstd-dev python3-dev + - name: vcpkg essentials + run: | + git clone https://github.com/microsoft/vcpkg.git + echo "VCPKG_ROOT=$(pwd)/vcpkg" >> "$GITHUB_ENV" + echo "PATH=$PATH:$VCPKG_ROOT" >> "$GITHUB_ENV" + - name: configure + run: | + export GCC='gcc-10' + export CXX='g++-10' + export CPATH=/Library/Developer/CommandLineTools/usr/include/c++/v1 + cmake --preset=test + - name: compile + run: cmake --build build -j2 - name: run test run: cd build/bandersnatch && ctest \ No newline at end of file diff --git a/bandersnatch/bandersnatch/Fr.cpp b/bandersnatch/bandersnatch/Fr.cpp index 5494a6e..06fefe7 100644 --- a/bandersnatch/bandersnatch/Fr.cpp +++ b/bandersnatch/bandersnatch/Fr.cpp @@ -3,6 +3,7 @@ // #include +#include #include #include "Fr.h" diff --git a/bandersnatch/test/unittests/Constants.h b/bandersnatch/test/unittests/Constants.h index 320db39..33a6784 100644 --- a/bandersnatch/test/unittests/Constants.h +++ b/bandersnatch/test/unittests/Constants.h @@ -6,27 +6,25 @@ namespace verkle::test { static inline const bandersnatch::Fr& FixedFr1() { - static bandersnatch::Fr fr1( - (uint64_t[4]){ - 0xe5d76b4ca918a221, - 0x81ed0b8d092ec3c6, - 0xd124e15f2054fa57, - 0x2ef123703093cbbb, - } - ); + static uint64_t raw[4] = { + 0xe5d76b4ca918a221, + 0x81ed0b8d092ec3c6, + 0xd124e15f2054fa57, + 0x2ef123703093cbbb, + }; + static bandersnatch::Fr fr1(raw); return fr1; } static inline const bandersnatch::Fr& FixedFr2() { - static bandersnatch::Fr fr2( - (uint64_t[4]){ - 0xd894647091277b9c, - 0x5182f0e810967f58, - 0x42958c4a5cf47f12, - 0x61b589a0f601132d, - } - ); + static uint64_t raw[4] = { + 0xd894647091277b9c, + 0x5182f0e810967f58, + 0x42958c4a5cf47f12, + 0x61b589a0f601132d, + }; + static bandersnatch::Fr fr2(raw); return fr2; } diff --git a/bandersnatch/test/unittests/ElementTest.cpp b/bandersnatch/test/unittests/ElementTest.cpp index 10565fa..c6f0259 100644 --- a/bandersnatch/test/unittests/ElementTest.cpp +++ b/bandersnatch/test/unittests/ElementTest.cpp @@ -12,17 +12,15 @@ BOOST_FIXTURE_TEST_SUITE(ElementTest, TestPromptFixture) BOOST_AUTO_TEST_CASE(testAdd) { - bandersnatch::Element exp( - (uint8_t[96]){ - 0x5, 0x72, 0xcb, 0xea, 0x90, 0x4d, 0x67, 0x46, 0x88, 0x8, 0xc8, 0xeb, 0x50, 0xa9, 0x45, 0xc, - 0x97, 0x21, 0xdb, 0x30, 0x91, 0x28, 0x1, 0x25, 0x43, 0x90, 0x2d, 0xa, 0xc3, 0x58, 0xa6, 0x2a, - 0xe2, 0x8f, 0x75, 0xbb, 0x8f, 0x1c, 0x7c, 0x42, 0xc3, 0x9a, 0x8c, 0x55, 0x29, 0xbf, 0xf, 0x4e, - 0x16, 0x6a, 0x9d, 0x8c, 0xab, 0xc6, 0x73, 0xa3, 0x22, 0xfd, 0xa6, 0x73, 0x77, 0x9d, 0x8e, 0x38, - 0x22, 0xba, 0x3e, 0xcb, 0x86, 0x70, 0xe4, 0x61, 0xf7, 0x3b, 0xb9, 0x2, 0x1d, 0x5f, 0xd7, 0x6a, - 0x4c, 0x56, 0xd9, 0xd4, 0xcd, 0x16, 0xbd, 0x1b, 0xba, 0x86, 0x88, 0x19, 0x79, 0x74, 0x9d, 0x28 - }, - 96 - ); + uint8_t raw[96] = { + 0x5, 0x72, 0xcb, 0xea, 0x90, 0x4d, 0x67, 0x46, 0x88, 0x8, 0xc8, 0xeb, 0x50, 0xa9, 0x45, 0xc, + 0x97, 0x21, 0xdb, 0x30, 0x91, 0x28, 0x1, 0x25, 0x43, 0x90, 0x2d, 0xa, 0xc3, 0x58, 0xa6, 0x2a, + 0xe2, 0x8f, 0x75, 0xbb, 0x8f, 0x1c, 0x7c, 0x42, 0xc3, 0x9a, 0x8c, 0x55, 0x29, 0xbf, 0xf, 0x4e, + 0x16, 0x6a, 0x9d, 0x8c, 0xab, 0xc6, 0x73, 0xa3, 0x22, 0xfd, 0xa6, 0x73, 0x77, 0x9d, 0x8e, 0x38, + 0x22, 0xba, 0x3e, 0xcb, 0x86, 0x70, 0xe4, 0x61, 0xf7, 0x3b, 0xb9, 0x2, 0x1d, 0x5f, 0xd7, 0x6a, + 0x4c, 0x56, 0xd9, 0xd4, 0xcd, 0x16, 0xbd, 0x1b, 0xba, 0x86, 0x88, 0x19, 0x79, 0x74, 0x9d, 0x28 + }; + bandersnatch::Element exp(raw, 96); auto g = FixedGenerator(); auto res = bandersnatch::Element::add(g, g); BOOST_ASSERT(res == exp); @@ -34,17 +32,15 @@ BOOST_AUTO_TEST_CASE(testAdd) BOOST_AUTO_TEST_CASE(testDouble) { - bandersnatch::Element exp( - (uint8_t[96]){ - 0x5, 0x72, 0xcb, 0xea, 0x90, 0x4d, 0x67, 0x46, 0x88, 0x8, 0xc8, 0xeb, 0x50, 0xa9, 0x45, 0xc, - 0x97, 0x21, 0xdb, 0x30, 0x91, 0x28, 0x1, 0x25, 0x43, 0x90, 0x2d, 0xa, 0xc3, 0x58, 0xa6, 0x2a, - 0xe2, 0x8f, 0x75, 0xbb, 0x8f, 0x1c, 0x7c, 0x42, 0xc3, 0x9a, 0x8c, 0x55, 0x29, 0xbf, 0xf, 0x4e, - 0x16, 0x6a, 0x9d, 0x8c, 0xab, 0xc6, 0x73, 0xa3, 0x22, 0xfd, 0xa6, 0x73, 0x77, 0x9d, 0x8e, 0x38, - 0x22, 0xba, 0x3e, 0xcb, 0x86, 0x70, 0xe4, 0x61, 0xf7, 0x3b, 0xb9, 0x2, 0x1d, 0x5f, 0xd7, 0x6a, - 0x4c, 0x56, 0xd9, 0xd4, 0xcd, 0x16, 0xbd, 0x1b, 0xba, 0x86, 0x88, 0x19, 0x79, 0x74, 0x9d, 0x28 - }, - 96 - ); + uint8_t raw[96] = { + 0x5, 0x72, 0xcb, 0xea, 0x90, 0x4d, 0x67, 0x46, 0x88, 0x8, 0xc8, 0xeb, 0x50, 0xa9, 0x45, 0xc, + 0x97, 0x21, 0xdb, 0x30, 0x91, 0x28, 0x1, 0x25, 0x43, 0x90, 0x2d, 0xa, 0xc3, 0x58, 0xa6, 0x2a, + 0xe2, 0x8f, 0x75, 0xbb, 0x8f, 0x1c, 0x7c, 0x42, 0xc3, 0x9a, 0x8c, 0x55, 0x29, 0xbf, 0xf, 0x4e, + 0x16, 0x6a, 0x9d, 0x8c, 0xab, 0xc6, 0x73, 0xa3, 0x22, 0xfd, 0xa6, 0x73, 0x77, 0x9d, 0x8e, 0x38, + 0x22, 0xba, 0x3e, 0xcb, 0x86, 0x70, 0xe4, 0x61, 0xf7, 0x3b, 0xb9, 0x2, 0x1d, 0x5f, 0xd7, 0x6a, + 0x4c, 0x56, 0xd9, 0xd4, 0xcd, 0x16, 0xbd, 0x1b, 0xba, 0x86, 0x88, 0x19, 0x79, 0x74, 0x9d, 0x28 + }; + bandersnatch::Element exp(raw, 96); auto g = FixedGenerator(); auto res = bandersnatch::Element::dbl(g); BOOST_ASSERT(res == exp); @@ -56,17 +52,15 @@ BOOST_AUTO_TEST_CASE(testDouble) BOOST_AUTO_TEST_CASE(testMult) { - bandersnatch::Element exp( - (uint8_t[96]){ - 0x16, 0xf8, 0x9e, 0x71, 0x6a, 0xbc, 0x6e, 0x4f, 0x4e, 0xc9, 0xd7, 0x1a, 0x5f, 0x5, 0x38, 0x32, - 0x51, 0xc0, 0x1e, 0xd9, 0xc4, 0xf, 0x2f, 0x4d, 0xdc, 0x9a, 0x77, 0xd8, 0x7b, 0xf6, 0xc, 0x4a, - 0xa2, 0xea, 0x60, 0x3a, 0x8d, 0x3a, 0xda, 0x49, 0x4f, 0x6f, 0x6d, 0x15, 0x87, 0x87, 0xa4, 0x49, - 0xd, 0x83, 0x9, 0x7b, 0xa7, 0x85, 0x97, 0x4, 0x2, 0x4b, 0x49, 0x41, 0xfd, 0x76, 0xf, 0x85, - 0xbc, 0xa6, 0xdb, 0xc4, 0xa8, 0x4a, 0x7, 0x1a, 0xf9, 0xef, 0x44, 0x3c, 0x1a, 0x55, 0x3f, 0xc8, - 0x7f, 0xc6, 0x1e, 0x9, 0x92, 0xa4, 0x0, 0x6d, 0x54, 0xfa, 0x36, 0x70, 0x5f, 0x61, 0x16, 0x90 - }, - 96 - ); + uint8_t raw[96] = { + 0x16, 0xf8, 0x9e, 0x71, 0x6a, 0xbc, 0x6e, 0x4f, 0x4e, 0xc9, 0xd7, 0x1a, 0x5f, 0x5, 0x38, 0x32, + 0x51, 0xc0, 0x1e, 0xd9, 0xc4, 0xf, 0x2f, 0x4d, 0xdc, 0x9a, 0x77, 0xd8, 0x7b, 0xf6, 0xc, 0x4a, + 0xa2, 0xea, 0x60, 0x3a, 0x8d, 0x3a, 0xda, 0x49, 0x4f, 0x6f, 0x6d, 0x15, 0x87, 0x87, 0xa4, 0x49, + 0xd, 0x83, 0x9, 0x7b, 0xa7, 0x85, 0x97, 0x4, 0x2, 0x4b, 0x49, 0x41, 0xfd, 0x76, 0xf, 0x85, + 0xbc, 0xa6, 0xdb, 0xc4, 0xa8, 0x4a, 0x7, 0x1a, 0xf9, 0xef, 0x44, 0x3c, 0x1a, 0x55, 0x3f, 0xc8, + 0x7f, 0xc6, 0x1e, 0x9, 0x92, 0xa4, 0x0, 0x6d, 0x54, 0xfa, 0x36, 0x70, 0x5f, 0x61, 0x16, 0x90 + }; + bandersnatch::Element exp(raw, 96); auto g = FixedGenerator(); auto fr1 = FixedFr1(); auto res1 = bandersnatch::Element::mult(fr1, g); @@ -79,17 +73,15 @@ BOOST_AUTO_TEST_CASE(testMult) BOOST_AUTO_TEST_CASE(testEqual) { - bandersnatch::Element e( - (uint8_t[96]){ - 0x5, 0x72, 0xcb, 0xea, 0x90, 0x4d, 0x67, 0x46, 0x88, 0x8, 0xc8, 0xeb, 0x50, 0xa9, 0x45, 0xc, - 0x97, 0x21, 0xdb, 0x30, 0x91, 0x28, 0x1, 0x25, 0x43, 0x90, 0x2d, 0xa, 0xc3, 0x58, 0xa6, 0x2a, - 0xe2, 0x8f, 0x75, 0xbb, 0x8f, 0x1c, 0x7c, 0x42, 0xc3, 0x9a, 0x8c, 0x55, 0x29, 0xbf, 0xf, 0x4e, - 0x16, 0x6a, 0x9d, 0x8c, 0xab, 0xc6, 0x73, 0xa3, 0x22, 0xfd, 0xa6, 0x73, 0x77, 0x9d, 0x8e, 0x38, - 0x22, 0xba, 0x3e, 0xcb, 0x86, 0x70, 0xe4, 0x61, 0xf7, 0x3b, 0xb9, 0x2, 0x1d, 0x5f, 0xd7, 0x6a, - 0x4c, 0x56, 0xd9, 0xd4, 0xcd, 0x16, 0xbd, 0x1b, 0xba, 0x86, 0x88, 0x19, 0x79, 0x74, 0x9d, 0x28 - }, - 96 - ); + uint8_t raw[96] = { + 0x5, 0x72, 0xcb, 0xea, 0x90, 0x4d, 0x67, 0x46, 0x88, 0x8, 0xc8, 0xeb, 0x50, 0xa9, 0x45, 0xc, + 0x97, 0x21, 0xdb, 0x30, 0x91, 0x28, 0x1, 0x25, 0x43, 0x90, 0x2d, 0xa, 0xc3, 0x58, 0xa6, 0x2a, + 0xe2, 0x8f, 0x75, 0xbb, 0x8f, 0x1c, 0x7c, 0x42, 0xc3, 0x9a, 0x8c, 0x55, 0x29, 0xbf, 0xf, 0x4e, + 0x16, 0x6a, 0x9d, 0x8c, 0xab, 0xc6, 0x73, 0xa3, 0x22, 0xfd, 0xa6, 0x73, 0x77, 0x9d, 0x8e, 0x38, + 0x22, 0xba, 0x3e, 0xcb, 0x86, 0x70, 0xe4, 0x61, 0xf7, 0x3b, 0xb9, 0x2, 0x1d, 0x5f, 0xd7, 0x6a, + 0x4c, 0x56, 0xd9, 0xd4, 0xcd, 0x16, 0xbd, 0x1b, 0xba, 0x86, 0x88, 0x19, 0x79, 0x74, 0x9d, 0x28 + }; + bandersnatch::Element e(raw, 96); bandersnatch::Element e1(e); bandersnatch::Element e2(e); BOOST_ASSERT(e1 == e2); diff --git a/bandersnatch/test/unittests/FrTest.cpp b/bandersnatch/test/unittests/FrTest.cpp index fcd0021..95df24b 100644 --- a/bandersnatch/test/unittests/FrTest.cpp +++ b/bandersnatch/test/unittests/FrTest.cpp @@ -40,14 +40,13 @@ BOOST_AUTO_TEST_CASE(testRandom) BOOST_AUTO_TEST_CASE(testAdd) { - bandersnatch::Fr exp( - (uint64_t[4]){ - 0xbe6bcfbe3a401dbc, - 0x7fb2587219c6e720, - 0xe08095a173a7a164, - 0x1cb905bdfcf761a0, - } - ); + uint64_t raw[4] = { + 0xbe6bcfbe3a401dbc, + 0x7fb2587219c6e720, + 0xe08095a173a7a164, + 0x1cb905bdfcf761a0, + }; + bandersnatch::Fr exp(raw); auto f1 = FixedFr1(); auto f2 = FixedFr2(); @@ -61,14 +60,14 @@ BOOST_AUTO_TEST_CASE(testAdd) BOOST_AUTO_TEST_CASE(testSub) { - bandersnatch::Fr exp( - (uint64_t[4]){ - 0xd4306db17f12686, - 0x8427bea7f896a06d, - 0xc1c92d1ccd02534a, - 0x41294122643035d6, - } - ); + uint64_t raw[4] = + { + 0xd4306db17f12686, + 0x8427bea7f896a06d, + 0xc1c92d1ccd02534a, + 0x41294122643035d6, + }; + bandersnatch::Fr exp(raw); auto f1 = FixedFr1(); auto f2 = FixedFr2(); @@ -82,14 +81,13 @@ BOOST_AUTO_TEST_CASE(testSub) BOOST_AUTO_TEST_CASE(testMult) { - bandersnatch::Fr exp( - (uint64_t[4]){ - 0xe9f26c96d15bb807, - 0x6ad84e7137609152, - 0xe193b5e1ce7d01c4, - 0x27625b6a622c0518, - } - ); + uint64_t raw[4] = { + 0xe9f26c96d15bb807, + 0x6ad84e7137609152, + 0xe193b5e1ce7d01c4, + 0x27625b6a622c0518, + }; + bandersnatch::Fr exp(raw); auto f1 = FixedFr1(); auto f2 = FixedFr2(); @@ -103,14 +101,13 @@ BOOST_AUTO_TEST_CASE(testMult) BOOST_AUTO_TEST_CASE(testInv) { - bandersnatch::Fr exp( - (uint64_t[4]){ - 0xc2eecde5714050d6, - 0x19f77495338244b4, - 0x65208d07b3ef94b1, - 0x524a236a985c691d, - } - ); + uint64_t raw[4] = { + 0xc2eecde5714050d6, + 0x19f77495338244b4, + 0x65208d07b3ef94b1, + 0x524a236a985c691d, + }; + bandersnatch::Fr exp(raw); auto f1 = FixedFr1(); auto res = f1.inv(); BOOST_ASSERT(res == exp); diff --git a/utilities/CMakelists.txt b/utilities/CMakeLists.txt similarity index 100% rename from utilities/CMakelists.txt rename to utilities/CMakeLists.txt