From 5a1597f7d83882b2466fab939def450846bed852 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Tue, 19 Feb 2019 11:30:43 +0100 Subject: [PATCH 1/4] ethash: Add Ethash algorithm revision information --- include/ethash/ethash.h | 6 ++++++ include/ethash/ethash.hpp | 2 ++ test/unittests/test_ethash.cpp | 7 +++++++ 3 files changed, 15 insertions(+) diff --git a/include/ethash/ethash.h b/include/ethash/ethash.h index fbcd3c85..b12f1aa9 100644 --- a/include/ethash/ethash.h +++ b/include/ethash/ethash.h @@ -19,6 +19,12 @@ extern "C" { #endif +/** + * The Ethash algorithm revision implemented as specified in the Ethash spec + * https://github.com/ethereum/wiki/wiki/Ethash. + */ +#define ETHASH_REVISION "23" + #define ETHASH_EPOCH_LENGTH 30000 #define ETHASH_LIGHT_CACHE_ITEM_SIZE 64 #define ETHASH_FULL_DATASET_ITEM_SIZE 128 diff --git a/include/ethash/ethash.hpp b/include/ethash/ethash.hpp index 6cd82ca2..03f29afd 100644 --- a/include/ethash/ethash.hpp +++ b/include/ethash/ethash.hpp @@ -23,6 +23,8 @@ namespace ethash { +constexpr auto revision = ETHASH_REVISION; + static constexpr int epoch_length = ETHASH_EPOCH_LENGTH; static constexpr int light_cache_item_size = ETHASH_LIGHT_CACHE_ITEM_SIZE; static constexpr int full_dataset_item_size = ETHASH_FULL_DATASET_ITEM_SIZE; diff --git a/test/unittests/test_ethash.cpp b/test/unittests/test_ethash.cpp index 383c4c36..cfd28ee5 100644 --- a/test/unittests/test_ethash.cpp +++ b/test/unittests/test_ethash.cpp @@ -63,6 +63,13 @@ hash512 copy(const hash512& h) noexcept } } +TEST(ethash, revision) +{ + static_assert(ethash::revision[0] == '2', ""); + static_assert(ethash::revision[1] == '3', ""); + EXPECT_EQ(ethash::revision, "23"); + EXPECT_EQ(ethash::revision, (std::string{"23"})); +} TEST(hash, hash256_from_bytes) { From 997eeff75a128fdfe781099af6910fa96b756034 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Tue, 19 Feb 2019 11:35:33 +0100 Subject: [PATCH 2/4] progpow: Add ProgPoW algorithm revision information --- include/ethash/progpow.hpp | 5 +++++ test/unittests/test_progpow.cpp | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/include/ethash/progpow.hpp b/include/ethash/progpow.hpp index 8add7d4d..81e6dbaa 100644 --- a/include/ethash/progpow.hpp +++ b/include/ethash/progpow.hpp @@ -14,6 +14,11 @@ namespace progpow { using namespace ethash; // Include ethash namespace. + +/// The ProgPoW algorithm revision implemented as specified in the spec +/// https://github.com/ifdefelse/ProgPOW#change-history. +constexpr auto revision = "0.9.2"; + constexpr int period_length = 50; constexpr uint32_t num_regs = 32; constexpr size_t num_lanes = 16; diff --git a/test/unittests/test_progpow.cpp b/test/unittests/test_progpow.cpp index f6d0677d..d7967c4d 100644 --- a/test/unittests/test_progpow.cpp +++ b/test/unittests/test_progpow.cpp @@ -11,6 +11,16 @@ #include #include +TEST(progpow, revision) +{ + static_assert(progpow::revision[0] == '0', ""); + static_assert(progpow::revision[1] == '.', ""); + static_assert(progpow::revision[2] == '9', ""); + static_assert(progpow::revision[3] == '.', ""); + static_assert(progpow::revision[4] == '2', ""); + EXPECT_EQ(progpow::revision, "0.9.2"); + EXPECT_EQ(progpow::revision, (std::string{"0.9.2"})); +} TEST(progpow, l1_cache) { From 379022e95f53542572684fa888170eef2510c0b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Tue, 19 Feb 2019 12:14:11 +0100 Subject: [PATCH 3/4] Squashed 'cmake/cable/' changes from 3e54f97..1bcca8c 1bcca8c Cable 0.2.16 e1770c8 Add toolchains for C++14 and C++17 cd585c5 Cable 0.2.15 f1083ec Cable: Add NO_PEDANTIC option to cable_configure_compiler() git-subtree-dir: cmake/cable git-subtree-split: 1bcca8c5efcb251d2b89d1b72237b32b1b212b55 --- CableCompilerSettings.cmake | 8 ++++++-- bootstrap.cmake | 2 +- toolchains/cxx14-pic.cmake | 9 +++++++++ toolchains/cxx14.cmake | 7 +++++++ toolchains/cxx17-pic.cmake | 9 +++++++++ toolchains/cxx17.cmake | 7 +++++++ 6 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 toolchains/cxx14-pic.cmake create mode 100644 toolchains/cxx14.cmake create mode 100644 toolchains/cxx17-pic.cmake create mode 100644 toolchains/cxx17.cmake diff --git a/CableCompilerSettings.cmake b/CableCompilerSettings.cmake index d3ea268a..fd49e780 100644 --- a/CableCompilerSettings.cmake +++ b/CableCompilerSettings.cmake @@ -32,7 +32,7 @@ macro(cable_configure_compiler) if(NOT PROJECT_IS_NESTED) # Do this configuration only in the top project. - cmake_parse_arguments(cable "NO_CONVERSION_WARNINGS;NO_STACK_PROTECTION" "" "" ${ARGN}) + cmake_parse_arguments(cable "NO_CONVERSION_WARNINGS;NO_STACK_PROTECTION;NO_PEDANTIC" "" "" ${ARGN}) if(cable_UNPARSED_ARGUMENTS) message(FATAL_ERROR "cable_configure_compiler: Unknown options: ${cable_UNPARSED_ARGUMENTS}") @@ -52,8 +52,12 @@ macro(cable_configure_compiler) if(CABLE_COMPILER_GNULIKE) + if(NOT cable_NO_PEDANTIC) + add_compile_options(-pedantic) + endif() + # Enable basing warnings set and treat them as errors. - add_compile_options(-pedantic -Werror -Wall -Wextra) + add_compile_options(-Werror -Wall -Wextra) if(NOT cable_NO_CONVERSION_WARNINGS) # Enable conversion warnings if not explicitly disabled. diff --git a/bootstrap.cmake b/bootstrap.cmake index 0e60126e..554cd0b1 100644 --- a/bootstrap.cmake +++ b/bootstrap.cmake @@ -10,7 +10,7 @@ # # This is internal variable automatically updated with external tools. # Use CABLE_VERSION variable if you need this information. -set(version 0.2.14) +set(version 0.2.16) # For convenience, add the project CMake module dir to module path. set(module_dir ${CMAKE_CURRENT_SOURCE_DIR}/cmake) diff --git a/toolchains/cxx14-pic.cmake b/toolchains/cxx14-pic.cmake new file mode 100644 index 00000000..507771fc --- /dev/null +++ b/toolchains/cxx14-pic.cmake @@ -0,0 +1,9 @@ +# Cable: CMake Bootstrap Library. +# Copyright 2019 Pawel Bylica. +# Licensed under the Apache License, Version 2.0. + +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD_REQUIRED TRUE) +set(CMAKE_CXX_EXTENSIONS OFF) + +set(CMAKE_POSITION_INDEPENDENT_CODE ON) diff --git a/toolchains/cxx14.cmake b/toolchains/cxx14.cmake new file mode 100644 index 00000000..646acafb --- /dev/null +++ b/toolchains/cxx14.cmake @@ -0,0 +1,7 @@ +# Cable: CMake Bootstrap Library. +# Copyright 2019 Pawel Bylica. +# Licensed under the Apache License, Version 2.0. + +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD_REQUIRED TRUE) +set(CMAKE_CXX_EXTENSIONS OFF) diff --git a/toolchains/cxx17-pic.cmake b/toolchains/cxx17-pic.cmake new file mode 100644 index 00000000..edb3559e --- /dev/null +++ b/toolchains/cxx17-pic.cmake @@ -0,0 +1,9 @@ +# Cable: CMake Bootstrap Library. +# Copyright 2019 Pawel Bylica. +# Licensed under the Apache License, Version 2.0. + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED TRUE) +set(CMAKE_CXX_EXTENSIONS OFF) + +set(CMAKE_POSITION_INDEPENDENT_CODE ON) diff --git a/toolchains/cxx17.cmake b/toolchains/cxx17.cmake new file mode 100644 index 00000000..a4efcaa2 --- /dev/null +++ b/toolchains/cxx17.cmake @@ -0,0 +1,7 @@ +# Cable: CMake Bootstrap Library. +# Copyright 2019 Pawel Bylica. +# Licensed under the Apache License, Version 2.0. + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED TRUE) +set(CMAKE_CXX_EXTENSIONS OFF) From 1d5ca8825d13705511e468c7e2c125481fb0927b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Tue, 19 Feb 2019 15:09:47 +0100 Subject: [PATCH 4/4] Add version.h header with information about the library version --- .bumpversion.cfg | 1 + include/ethash/version.h | 18 ++++++++++++++++++ .../cmake-config/cmake_config_test.cpp | 3 +++ test/unittests/CMakeLists.txt | 3 +++ test/unittests/test_version.cpp | 15 +++++++++++++++ 5 files changed, 40 insertions(+) create mode 100644 include/ethash/version.h create mode 100644 test/unittests/test_version.cpp diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 24445088..fe65e729 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -18,4 +18,5 @@ values = rel [bumpversion:file:CMakeLists.txt] +[bumpversion:file:include/ethash/version.h] diff --git a/include/ethash/version.h b/include/ethash/version.h new file mode 100644 index 00000000..d0f081fb --- /dev/null +++ b/include/ethash/version.h @@ -0,0 +1,18 @@ +/* ethash: C/C++ implementation of Ethash, the Ethereum Proof of Work algorithm. + * Copyright 2019 Pawel Bylica. + * Licensed under the Apache License, Version 2.0. + */ + +#pragma once + +/** The ethash library version. */ +#define ETHASH_VERSION "0.4.2" + +#ifdef __cplusplus +namespace ethash +{ +/// The ethash library version. +constexpr auto version = ETHASH_VERSION; + +} // namespace ethash +#endif diff --git a/test/integration/cmake-config/cmake_config_test.cpp b/test/integration/cmake-config/cmake_config_test.cpp index d77c4049..2c449712 100644 --- a/test/integration/cmake-config/cmake_config_test.cpp +++ b/test/integration/cmake-config/cmake_config_test.cpp @@ -3,9 +3,12 @@ // Licensed under the Apache License, Version 2.0. See the LICENSE file. #include +#include int main() { + static_assert(sizeof(ethash::version) >= 6, "incorrect ethash::version"); + uint8_t seed_bytes[32] = {0}; ethash::hash256 seed = ethash::hash256_from_bytes(seed_bytes); return ethash::find_epoch_number(seed); diff --git a/test/unittests/CMakeLists.txt b/test/unittests/CMakeLists.txt index c27d10b0..d3c3f36a 100644 --- a/test/unittests/CMakeLists.txt +++ b/test/unittests/CMakeLists.txt @@ -16,8 +16,11 @@ add_executable( test_managed.cpp test_primes.cpp test_progpow.cpp + test_version.cpp ) +set_source_files_properties(test_version.cpp PROPERTIES COMPILE_DEFINITIONS TEST_PROJECT_VERSION="${PROJECT_VERSION}") + target_link_libraries(ethash-test PRIVATE ethash GTest::gtest GTest::main) target_include_directories(ethash-test PRIVATE ${ETHASH_PRIVATE_INCLUDE_DIR}) set_target_properties(ethash-test PROPERTIES RUNTIME_OUTPUT_DIRECTORY ..) diff --git a/test/unittests/test_version.cpp b/test/unittests/test_version.cpp new file mode 100644 index 00000000..3108fc05 --- /dev/null +++ b/test/unittests/test_version.cpp @@ -0,0 +1,15 @@ +// ethash: C/C++ implementation of Ethash, the Ethereum Proof of Work algorithm. +// Copyright 2019 Pawel Bylica. +// Licensed under the Apache License, Version 2.0. + +#include + +#include + +TEST(libethash, version) +{ + static_assert(ethash::version[0] != 0, "incorrect ethash::version"); + + EXPECT_EQ(ETHASH_VERSION, TEST_PROJECT_VERSION); + EXPECT_EQ(ethash::version, TEST_PROJECT_VERSION); +}