├── .gitignore ├── .gitmodules ├── BuildInfo.h.in ├── CMakeLists.txt ├── GPLV3_LICENSE ├── LICENSE ├── README.md ├── cmake ├── CMakeParseArguments.cmake ├── EthCompilerSettings.cmake ├── EthDependencies.cmake ├── EthExecutableHelper.cmake ├── EthUtils.cmake ├── FindCURL.cmake ├── FindCpuid.cmake ├── FindCryptoPP.cmake ├── FindEth.cmake ├── FindGmp.cmake ├── FindJsoncpp.cmake ├── FindLevelDB.cmake ├── FindMHD.cmake ├── FindMiniupnpc.cmake ├── FindOpenCL.cmake ├── FindPackageHandleStandardArgs.cmake ├── FindPackageMessage.cmake ├── FindReadline.cmake ├── FindWindowsSDK.cmake ├── Findjson_rpc_cpp.cmake ├── Findv8.cmake └── scripts │ ├── appdmg.cmake │ ├── buildinfo.cmake │ ├── configure.cmake │ ├── copydlls.cmake │ ├── jsonrpcstub.cmake │ ├── macdeployfix.sh │ ├── resource.hpp.in │ ├── resources.cmake │ └── runtest.cmake ├── doc └── Doxyfile ├── ethminer ├── CMakeLists.txt ├── FarmClient.h ├── MinerAux.h ├── PhoneHome.h ├── farm.json ├── main.cpp └── phonehome.json ├── extdep └── getstuff.bat ├── libdevcore ├── Assertions.h ├── Base64.cpp ├── Base64.h ├── CMakeLists.txt ├── Common.cpp ├── Common.h ├── CommonData.cpp ├── CommonData.h ├── CommonIO.cpp ├── CommonIO.h ├── CommonJS.cpp ├── CommonJS.h ├── Diff.h ├── Exceptions.h ├── FileSystem.cpp ├── FileSystem.h ├── FixedHash.cpp ├── FixedHash.h ├── Guards.cpp ├── Guards.h ├── Hash.cpp ├── Hash.h ├── Log.cpp ├── Log.h ├── MemoryDB.cpp ├── MemoryDB.h ├── RLP.cpp ├── RLP.h ├── RangeMask.cpp ├── RangeMask.h ├── SHA3.cpp ├── SHA3.h ├── StructuredLogger.cpp ├── StructuredLogger.h ├── Terminal.h ├── TransientDirectory.cpp ├── TransientDirectory.h ├── TrieCommon.cpp ├── TrieCommon.h ├── TrieDB.cpp ├── TrieDB.h ├── TrieHash.cpp ├── TrieHash.h ├── UndefMacros.h ├── Worker.cpp ├── Worker.h ├── boost_multiprecision_number_compare_bug_workaround.hpp ├── concurrent_queue.h ├── db.h ├── debugbreak.h ├── picosha2.h └── vector_ref.h ├── libethash-cl ├── CL │ └── cl.hpp ├── CMakeLists.txt ├── bin2h.cmake ├── ethash_cl_miner.cpp ├── ethash_cl_miner.h └── ethash_cl_miner_kernel.cl ├── libethash-cuda ├── CMakeLists.txt ├── cuda_helper.h ├── dagger_shared.cuh ├── dagger_shuffled.cuh ├── ethash_cuda_miner.cpp ├── ethash_cuda_miner.h ├── ethash_cuda_miner_kernel.cu ├── ethash_cuda_miner_kernel.h ├── ethash_cuda_miner_kernel_globals.h ├── fnv.cuh ├── keccak.cuh └── keccak_u64.cuh ├── libethash ├── CMakeLists.txt ├── compiler.h ├── data_sizes.h ├── endian.h ├── ethash.h ├── fnv.h ├── internal.c ├── internal.h ├── io.c ├── io.h ├── io_posix.c ├── io_win32.c ├── mmap.h ├── mmap_win32.c ├── sha3.c ├── sha3.h ├── sha3_cryptopp.cpp ├── sha3_cryptopp.h ├── util.c ├── util.h └── util_win32.c ├── libethcore ├── BlockInfo.cpp ├── BlockInfo.h ├── CMakeLists.txt ├── Common.cpp ├── Common.h ├── Ethash.cpp ├── Ethash.h ├── EthashAux.cpp ├── EthashAux.h ├── EthashCPUMiner.cpp ├── EthashCPUMiner.h ├── EthashCUDAMiner.cpp ├── EthashCUDAMiner.h ├── EthashGPUMiner.cpp ├── EthashGPUMiner.h ├── EthashSealEngine.cpp ├── EthashSealEngine.h ├── Exceptions.h ├── Farm.h ├── Miner.cpp ├── Miner.h ├── Params.cpp ├── Params.h ├── Sealer.cpp └── Sealer.h ├── libstratum ├── CMakeLists.txt ├── EthStratumClient.cpp ├── EthStratumClient.h ├── EthStratumClientV2.cpp └── EthStratumClientV2.h └── releases ├── cuda-6.5 └── ethminer-0.9.41-genoil-1.0.5-cuda6.5.zip ├── ethminer-0.9.41-genoil-1.0.7-chunked.zip ├── ethminer-0.9.41-genoil-1.0.8.zip ├── ethminer-0.9.41-genoil-1.1.6.zip └── ethminer-0.9.41-genoil-1.1.7.zip /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | 6 | # Compiled Dynamic libraries 7 | *.so 8 | *.dylib 9 | 10 | # Compiled Static libraries 11 | *.lai 12 | *.la 13 | *.a 14 | 15 | # VS stuff 16 | build 17 | ipch 18 | *.sdf 19 | *.opensdf 20 | *.suo 21 | *.vcxproj 22 | *.vcxproj.filters 23 | *.sln 24 | 25 | # VIM stuff 26 | *.swp 27 | 28 | # Xcode stuff 29 | build_xc 30 | 31 | *.user 32 | *.user.* 33 | *~ 34 | 35 | # build system 36 | build.*/ 37 | extdep/install 38 | extdep/download 39 | 40 | *.pyc 41 | 42 | # MacOS Development 43 | .DS_Store 44 | # CocoaPods 45 | Pods/ 46 | Podfile.lock 47 | # Xcode 48 | .DS_Store 49 | build/ 50 | *.pbxuser 51 | !default.pbxuser 52 | *.mode1v3 53 | !default.mode1v3 54 | *.mode2v3 55 | !default.mode2v3 56 | *.perspectivev3 57 | !default.perspectivev3 58 | *.xcworkspace 59 | !default.xcworkspace 60 | xcuserdata 61 | *.xcuserstate 62 | profile 63 | *.moved-aside 64 | DerivedData 65 | project.pbxproj 66 | 67 | # JetBrains stuff 68 | .idea/ 69 | 70 | doc/html 71 | *.autosave 72 | node_modules/ 73 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "evmjit"] 2 | path = evmjit 3 | url = https://github.com/ethereum/evmjit 4 | branch = develop 5 | -------------------------------------------------------------------------------- /BuildInfo.h.in: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define ETH_PROJECT_VERSION "@PROJECT_VERSION@-genoil-@GENOIL_VERSION@" 4 | #define ETH_COMMIT_HASH @ETH_COMMIT_HASH@ 5 | #define ETH_CLEAN_REPO @ETH_CLEAN_REPO@ 6 | #define ETH_BUILD_TYPE @ETH_BUILD_TYPE@ 7 | #define ETH_BUILD_PLATFORM @ETH_BUILD_PLATFORM@ 8 | #define ETH_FATDB @ETH_FATDB@ 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /cmake/EthUtils.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # renames the file if it is different from its destination 3 | include(CMakeParseArguments) 4 | # 5 | macro(replace_if_different SOURCE DST) 6 | set(extra_macro_args ${ARGN}) 7 | set(options CREATE) 8 | set(one_value_args) 9 | set(multi_value_args) 10 | cmake_parse_arguments(REPLACE_IF_DIFFERENT "${options}" "${one_value_args}" "${multi_value_args}" "${extra_macro_args}") 11 | 12 | if (REPLACE_IF_DIFFERENT_CREATE AND (NOT (EXISTS "${DST}"))) 13 | file(WRITE "${DST}" "") 14 | endif() 15 | 16 | execute_process(COMMAND ${CMAKE_COMMAND} -E compare_files "${SOURCE}" "${DST}" RESULT_VARIABLE DIFFERENT) 17 | 18 | if (DIFFERENT) 19 | execute_process(COMMAND ${CMAKE_COMMAND} -E rename "${SOURCE}" "${DST}") 20 | else() 21 | execute_process(COMMAND ${CMAKE_COMMAND} -E remove "${SOURCE}") 22 | endif() 23 | endmacro() 24 | 25 | macro(eth_add_test NAME) 26 | 27 | # parse arguments here 28 | set(commands) 29 | set(current_command "") 30 | foreach (arg ${ARGN}) 31 | if (arg STREQUAL "ARGS") 32 | if (current_command) 33 | list(APPEND commands ${current_command}) 34 | endif() 35 | set(current_command "") 36 | else () 37 | set(current_command "${current_command} ${arg}") 38 | endif() 39 | endforeach(arg) 40 | list(APPEND commands ${current_command}) 41 | 42 | message(STATUS "test: ${NAME} | ${commands}") 43 | 44 | # create tests 45 | set(index 0) 46 | list(LENGTH commands count) 47 | while (index LESS count) 48 | list(GET commands ${index} test_arguments) 49 | 50 | set(run_test "--run_test=${NAME}") 51 | add_test(NAME "${NAME}.${index}" COMMAND testeth ${run_test} ${test_arguments}) 52 | 53 | math(EXPR index "${index} + 1") 54 | endwhile(index LESS count) 55 | 56 | # add target to run them 57 | add_custom_target("test.${NAME}" 58 | DEPENDS testeth 59 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} 60 | COMMAND ${CMAKE_COMMAND} -DETH_TEST_NAME="${NAME}" -DCTEST_COMMAND="${CTEST_COMMAND}" -P "${ETH_SCRIPTS_DIR}/runtest.cmake" 61 | ) 62 | 63 | endmacro() 64 | 65 | # Creates C resources file from files 66 | function(eth_add_resources RESOURCE_FILE OUT_FILE) 67 | include("${RESOURCE_FILE}") 68 | set(OUTPUT "${ETH_RESOURCE_LOCATION}/${ETH_RESOURCE_NAME}.hpp") 69 | set(${OUT_FILE} "${OUTPUT}" PARENT_SCOPE) 70 | 71 | set(filenames "${RESOURCE_FILE}") 72 | list(APPEND filenames "${ETH_SCRIPTS_DIR}/resources.cmake") 73 | foreach(resource ${ETH_RESOURCES}) 74 | list(APPEND filenames "${${resource}}") 75 | endforeach(resource) 76 | 77 | add_custom_command(OUTPUT ${OUTPUT} 78 | COMMAND ${CMAKE_COMMAND} -DETH_RES_FILE="${RESOURCE_FILE}" -P "${ETH_SCRIPTS_DIR}/resources.cmake" 79 | DEPENDS ${filenames} 80 | ) 81 | endfunction() 82 | -------------------------------------------------------------------------------- /cmake/FindCURL.cmake: -------------------------------------------------------------------------------- 1 | # Find CURL 2 | # 3 | # Find the curl includes and library 4 | # 5 | # if you nee to add a custom library search path, do it via via CMAKE_PREFIX_PATH 6 | # 7 | # This module defines 8 | # CURL_INCLUDE_DIRS, where to find header, etc. 9 | # CURL_LIBRARIES, the libraries needed to use curl. 10 | # CURL_FOUND, If false, do not try to use curl. 11 | 12 | # only look in default directories 13 | find_path( 14 | CURL_INCLUDE_DIR 15 | NAMES curl/curl.h 16 | DOC "curl include dir" 17 | ) 18 | 19 | find_library( 20 | CURL_LIBRARY 21 | # names from cmake's FindCURL 22 | NAMES curl curllib libcurl_imp curllib_static libcurl 23 | DOC "curl library" 24 | ) 25 | 26 | set(CURL_INCLUDE_DIRS ${CURL_INCLUDE_DIR}) 27 | set(CURL_LIBRARIES ${CURL_LIBRARY}) 28 | 29 | # debug library on windows 30 | # same naming convention as in qt (appending debug library with d) 31 | # boost is using the same "hack" as us with "optimized" and "debug" 32 | if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") 33 | 34 | find_library( 35 | CURL_LIBRARY_DEBUG 36 | NAMES curld libcurld 37 | DOC "curl debug library" 38 | ) 39 | 40 | set(CURL_LIBRARIES optimized ${CURL_LIBRARIES} debug ${CURL_LIBRARY_DEBUG}) 41 | 42 | # prepare dlls 43 | string(REPLACE ".lib" ".dll" CURL_DLL ${CURL_LIBRARY}) 44 | string(REPLACE "/lib/" "/bin/" CURL_DLL ${CURL_DLL}) 45 | string(REPLACE ".lib" ".dll" CURL_DLL_DEBUG ${CURL_LIBRARY_DEBUG}) 46 | string(REPLACE "/lib/" "/bin/" CURL_DLL_DEBUG ${CURL_DLL_DEBUG}) 47 | set(CURL_DLLS optimized ${CURL_DLL} debug ${CURL_DLL_DEBUG}) 48 | 49 | endif() 50 | 51 | # handle the QUIETLY and REQUIRED arguments and set CURL_FOUND to TRUE 52 | # if all listed variables are TRUE, hide their existence from configuration view 53 | include(FindPackageHandleStandardArgs) 54 | find_package_handle_standard_args(CURL DEFAULT_MSG 55 | CURL_INCLUDE_DIR CURL_LIBRARY) 56 | mark_as_advanced (CURL_INCLUDE_DIR CURL_LIBRARY) 57 | 58 | -------------------------------------------------------------------------------- /cmake/FindCpuid.cmake: -------------------------------------------------------------------------------- 1 | # Find libcpuid 2 | # 3 | # Find the libcpuid includes and library 4 | # 5 | # if you nee to add a custom library search path, do it via via CMAKE_PREFIX_PATH 6 | # 7 | # This module defines 8 | # CPUID_INCLUDE_DIRS, where to find header, etc. 9 | # CPUID_LIBRARIES, the libraries needed to use cpuid. 10 | # CPUID_FOUND, If false, do not try to use cpuid. 11 | 12 | # only look in default directories 13 | find_path( 14 | CPUID_INCLUDE_DIR 15 | NAMES libcpuid/libcpuid.h 16 | DOC "libcpuid include dir" 17 | ) 18 | 19 | find_library( 20 | CPUID_LIBRARY 21 | NAMES cpuid 22 | DOC "libcpuid library" 23 | ) 24 | 25 | set(CPUID_INCLUDE_DIRS ${CPUID_INCLUDE_DIR}) 26 | set(CPUID_LIBRARIES ${CPUID_LIBRARY}) 27 | 28 | # handle the QUIETLY and REQUIRED arguments and set CPUID_FOUND to TRUE 29 | # if all listed variables are TRUE, hide their existence from configuration view 30 | include(FindPackageHandleStandardArgs) 31 | find_package_handle_standard_args(cpuid DEFAULT_MSG CPUID_INCLUDE_DIR CPUID_LIBRARY) 32 | mark_as_advanced (CPUID_INCLUDE_DIR CPUID_LIBRARY) 33 | 34 | -------------------------------------------------------------------------------- /cmake/FindCryptoPP.cmake: -------------------------------------------------------------------------------- 1 | # Module for locating the Crypto++ encryption library. 2 | # 3 | # Customizable variables: 4 | # CRYPTOPP_ROOT_DIR 5 | # This variable points to the CryptoPP root directory. On Windows the 6 | # library location typically will have to be provided explicitly using the 7 | # -D command-line option. The directory should include the include/cryptopp, 8 | # lib and/or bin sub-directories. 9 | # 10 | # Read-only variables: 11 | # CRYPTOPP_FOUND 12 | # Indicates whether the library has been found. 13 | # 14 | # CRYPTOPP_INCLUDE_DIRS 15 | # Points to the CryptoPP include directory. 16 | # 17 | # CRYPTOPP_LIBRARIES 18 | # Points to the CryptoPP libraries that should be passed to 19 | # target_link_libararies. 20 | # 21 | # 22 | # Copyright (c) 2012 Sergiu Dotenco 23 | # 24 | # Permission is hereby granted, free of charge, to any person obtaining a copy 25 | # of this software and associated documentation files (the "Software"), to deal 26 | # in the Software without restriction, including without limitation the rights 27 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 28 | # copies of the Software, and to permit persons to whom the Software is 29 | # furnished to do so, subject to the following conditions: 30 | # 31 | # The above copyright notice and this permission notice shall be included in all 32 | # copies or substantial portions of the Software. 33 | # 34 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 35 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 36 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 37 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 38 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 39 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 40 | # SOFTWARE. 41 | 42 | INCLUDE (FindPackageHandleStandardArgs) 43 | 44 | FIND_PATH (CRYPTOPP_ROOT_DIR 45 | NAMES cryptopp/cryptlib.h include/cryptopp/cryptlib.h 46 | PATHS ENV CRYPTOPPROOT 47 | DOC "CryptoPP root directory") 48 | 49 | # Re-use the previous path: 50 | FIND_PATH (CRYPTOPP_INCLUDE_DIR 51 | NAMES cryptopp/cryptlib.h 52 | HINTS ${CRYPTOPP_ROOT_DIR} 53 | PATH_SUFFIXES include 54 | DOC "CryptoPP include directory") 55 | 56 | FIND_LIBRARY (CRYPTOPP_LIBRARY_DEBUG 57 | NAMES cryptlibd cryptoppd 58 | HINTS ${CRYPTOPP_ROOT_DIR} 59 | PATH_SUFFIXES lib 60 | DOC "CryptoPP debug library") 61 | 62 | FIND_LIBRARY (CRYPTOPP_LIBRARY_RELEASE 63 | NAMES cryptlib cryptopp 64 | HINTS ${CRYPTOPP_ROOT_DIR} 65 | PATH_SUFFIXES lib 66 | DOC "CryptoPP release library") 67 | 68 | IF (CRYPTOPP_LIBRARY_DEBUG AND CRYPTOPP_LIBRARY_RELEASE) 69 | SET (CRYPTOPP_LIBRARY 70 | optimized ${CRYPTOPP_LIBRARY_RELEASE} 71 | debug ${CRYPTOPP_LIBRARY_DEBUG} CACHE DOC "CryptoPP library") 72 | ELSEIF (CRYPTOPP_LIBRARY_RELEASE) 73 | SET (CRYPTOPP_LIBRARY ${CRYPTOPP_LIBRARY_RELEASE} CACHE DOC 74 | "CryptoPP library") 75 | ENDIF (CRYPTOPP_LIBRARY_DEBUG AND CRYPTOPP_LIBRARY_RELEASE) 76 | 77 | IF (CRYPTOPP_INCLUDE_DIR) 78 | SET (_CRYPTOPP_VERSION_HEADER ${CRYPTOPP_INCLUDE_DIR}/cryptopp/config.h) 79 | 80 | IF (EXISTS ${_CRYPTOPP_VERSION_HEADER}) 81 | FILE (STRINGS ${_CRYPTOPP_VERSION_HEADER} _CRYPTOPP_VERSION_TMP REGEX 82 | "^#define CRYPTOPP_VERSION[ \t]+[0-9]+$") 83 | 84 | STRING (REGEX REPLACE 85 | "^#define CRYPTOPP_VERSION[ \t]+([0-9]+)" "\\1" _CRYPTOPP_VERSION_TMP 86 | ${_CRYPTOPP_VERSION_TMP}) 87 | 88 | STRING (REGEX REPLACE "([0-9]+)[0-9][0-9]" "\\1" CRYPTOPP_VERSION_MAJOR 89 | ${_CRYPTOPP_VERSION_TMP}) 90 | STRING (REGEX REPLACE "[0-9]([0-9])[0-9]" "\\1" CRYPTOPP_VERSION_MINOR 91 | ${_CRYPTOPP_VERSION_TMP}) 92 | STRING (REGEX REPLACE "[0-9][0-9]([0-9])" "\\1" CRYPTOPP_VERSION_PATCH 93 | ${_CRYPTOPP_VERSION_TMP}) 94 | 95 | SET (CRYPTOPP_VERSION_COUNT 3) 96 | SET (CRYPTOPP_VERSION 97 | ${CRYPTOPP_VERSION_MAJOR}.${CRYPTOPP_VERSION_MINOR}.${CRYPTOPP_VERSION_PATCH}) 98 | ENDIF (EXISTS ${_CRYPTOPP_VERSION_HEADER}) 99 | ENDIF (CRYPTOPP_INCLUDE_DIR) 100 | 101 | SET (CRYPTOPP_INCLUDE_DIRS ${CRYPTOPP_INCLUDE_DIR}) 102 | SET (CRYPTOPP_LIBRARIES ${CRYPTOPP_LIBRARY}) 103 | 104 | MARK_AS_ADVANCED (CRYPTOPP_INCLUDE_DIR CRYPTOPP_LIBRARY CRYPTOPP_LIBRARY_DEBUG 105 | CRYPTOPP_LIBRARY_RELEASE) 106 | 107 | FIND_PACKAGE_HANDLE_STANDARD_ARGS (CryptoPP REQUIRED_VARS 108 | CRYPTOPP_INCLUDE_DIR CRYPTOPP_LIBRARY VERSION_VAR CRYPTOPP_VERSION) 109 | -------------------------------------------------------------------------------- /cmake/FindEth.cmake: -------------------------------------------------------------------------------- 1 | # Find ethereum 2 | # 3 | # Find the ethereum includes and library 4 | # 5 | # This module defines 6 | # ETH_CORE_LIBRARIES, the libraries needed to use ethereum. 7 | # ETH_FOUND, If false, do not try to use ethereum. 8 | # TODO: ETH_INCLUDE_DIRS 9 | 10 | set(CORE_LIBS web3jsonrpc;webthree;whisper;ethereum;evm;ethcore;lll;p2p;evmasm;devcrypto;evmcore;natspec;devcore;ethash-cl;ethash;secp256k1;scrypt;jsqrc) 11 | set(ALL_LIBS ${CORE_LIBS};evmjit;solidity;secp256k1) 12 | 13 | set(ETH_INCLUDE_DIRS ${ETH_INCLUDE_DIR}) 14 | set(ETH_CORE_LIBRARIES ${ETH_LIBRARY}) 15 | 16 | foreach (l ${ALL_LIBS}) 17 | string(TOUPPER ${l} L) 18 | find_library(ETH_${L}_LIBRARY 19 | NAMES ${l} 20 | PATH_SUFFIXES "lib${l}" "${l}" 21 | ) 22 | endforeach() 23 | 24 | foreach (l ${CORE_LIBS}) 25 | string(TOUPPER ${l} L) 26 | list(APPEND ETH_CORE_LIBRARIES ${ETH_${L}_LIBRARY}) 27 | endforeach() 28 | 29 | # handle the QUIETLY and REQUIRED arguments and set ETH_FOUND to TRUE 30 | # if all listed variables are TRUE, hide their existence from configuration view 31 | include(FindPackageHandleStandardArgs) 32 | find_package_handle_standard_args(ethereum DEFAULT_MSG 33 | ETH_CORE_LIBRARIES) 34 | mark_as_advanced (ETH_CORE_LIBRARIES) 35 | 36 | -------------------------------------------------------------------------------- /cmake/FindGmp.cmake: -------------------------------------------------------------------------------- 1 | # Find gmp 2 | # 3 | # Find the gmp includes and library 4 | # 5 | # if you nee to add a custom library search path, do it via via CMAKE_PREFIX_PATH 6 | # 7 | # This module defines 8 | # GMP_INCLUDE_DIRS, where to find header, etc. 9 | # GMP_LIBRARIES, the libraries needed to use gmp. 10 | # GMP_FOUND, If false, do not try to use gmp. 11 | 12 | # only look in default directories 13 | find_path( 14 | GMP_INCLUDE_DIR 15 | NAMES gmp.h 16 | DOC "gmp include dir" 17 | ) 18 | 19 | find_library( 20 | GMP_LIBRARY 21 | NAMES gmp 22 | DOC "gmp library" 23 | ) 24 | 25 | set(GMP_INCLUDE_DIRS ${GMP_INCLUDE_DIR}) 26 | set(GMP_LIBRARIES ${GMP_LIBRARY}) 27 | 28 | # handle the QUIETLY and REQUIRED arguments and set GMP_FOUND to TRUE 29 | # if all listed variables are TRUE, hide their existence from configuration view 30 | include(FindPackageHandleStandardArgs) 31 | find_package_handle_standard_args(gmp DEFAULT_MSG 32 | GMP_INCLUDE_DIR GMP_LIBRARY) 33 | mark_as_advanced (GMP_INCLUDE_DIR GMP_LIBRARY) 34 | 35 | -------------------------------------------------------------------------------- /cmake/FindJsoncpp.cmake: -------------------------------------------------------------------------------- 1 | # Find jsoncpp 2 | # 3 | # Find the jsoncpp includes and library 4 | # 5 | # if you nee to add a custom library search path, do it via via CMAKE_PREFIX_PATH 6 | # 7 | # This module defines 8 | # JSONCPP_INCLUDE_DIRS, where to find header, etc. 9 | # JSONCPP_LIBRARIES, the libraries needed to use jsoncpp. 10 | # JSONCPP_FOUND, If false, do not try to use jsoncpp. 11 | 12 | # only look in default directories 13 | find_path( 14 | JSONCPP_INCLUDE_DIR 15 | NAMES json/json.h 16 | PATH_SUFFIXES jsoncpp 17 | DOC "jsoncpp include dir" 18 | ) 19 | 20 | find_library( 21 | JSONCPP_LIBRARY 22 | NAMES jsoncpp 23 | DOC "jsoncpp library" 24 | ) 25 | 26 | set(JSONCPP_INCLUDE_DIRS ${JSONCPP_INCLUDE_DIR}) 27 | set(JSONCPP_LIBRARIES ${JSONCPP_LIBRARY}) 28 | 29 | # debug library on windows 30 | # same naming convention as in qt (appending debug library with d) 31 | # boost is using the same "hack" as us with "optimized" and "debug" 32 | if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") 33 | 34 | find_library( 35 | JSONCPP_LIBRARY_DEBUG 36 | NAMES jsoncppd 37 | DOC "jsoncpp debug library" 38 | ) 39 | 40 | set(JSONCPP_LIBRARIES optimized ${JSONCPP_LIBRARIES} debug ${JSONCPP_LIBRARY_DEBUG}) 41 | 42 | endif() 43 | 44 | # handle the QUIETLY and REQUIRED arguments and set JSONCPP_FOUND to TRUE 45 | # if all listed variables are TRUE, hide their existence from configuration view 46 | include(FindPackageHandleStandardArgs) 47 | find_package_handle_standard_args(jsoncpp DEFAULT_MSG 48 | JSONCPP_INCLUDE_DIR JSONCPP_LIBRARY) 49 | mark_as_advanced (JSONCPP_INCLUDE_DIR JSONCPP_LIBRARY) 50 | 51 | -------------------------------------------------------------------------------- /cmake/FindLevelDB.cmake: -------------------------------------------------------------------------------- 1 | # Find leveldb 2 | # 3 | # Find the leveldb includes and library 4 | # 5 | # if you nee to add a custom library search path, do it via via CMAKE_PREFIX_PATH 6 | # 7 | # This module defines 8 | # LEVELDB_INCLUDE_DIRS, where to find header, etc. 9 | # LEVELDB_LIBRARIES, the libraries needed to use leveldb. 10 | # LEVELDB_FOUND, If false, do not try to use leveldb. 11 | 12 | # only look in default directories 13 | find_path( 14 | LEVELDB_INCLUDE_DIR 15 | NAMES leveldb/db.h 16 | DOC "leveldb include dir" 17 | ) 18 | 19 | find_library( 20 | LEVELDB_LIBRARY 21 | NAMES leveldb 22 | DOC "leveldb library" 23 | ) 24 | 25 | set(LEVELDB_INCLUDE_DIRS ${LEVELDB_INCLUDE_DIR}) 26 | set(LEVELDB_LIBRARIES ${LEVELDB_LIBRARY}) 27 | 28 | # debug library on windows 29 | # same naming convention as in qt (appending debug library with d) 30 | # boost is using the same "hack" as us with "optimized" and "debug" 31 | if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") 32 | 33 | find_library( 34 | LEVELDB_LIBRARY_DEBUG 35 | NAMES leveldbd 36 | DOC "leveldb debug library" 37 | ) 38 | 39 | set(LEVELDB_LIBRARIES optimized ${LEVELDB_LIBRARIES} debug ${LEVELDB_LIBRARY_DEBUG}) 40 | 41 | endif() 42 | 43 | # handle the QUIETLY and REQUIRED arguments and set LEVELDB_FOUND to TRUE 44 | # if all listed variables are TRUE, hide their existence from configuration view 45 | include(FindPackageHandleStandardArgs) 46 | find_package_handle_standard_args(leveldb DEFAULT_MSG 47 | LEVELDB_INCLUDE_DIR LEVELDB_LIBRARY) 48 | mark_as_advanced (LEVELDB_INCLUDE_DIR LEVELDB_LIBRARY) 49 | 50 | -------------------------------------------------------------------------------- /cmake/FindMHD.cmake: -------------------------------------------------------------------------------- 1 | # Find microhttpd 2 | # 3 | # Find the microhttpd includes and library 4 | # 5 | # if you need to add a custom library search path, do it via via CMAKE_PREFIX_PATH 6 | # 7 | # This module defines 8 | # MHD_INCLUDE_DIRS, where to find header, etc. 9 | # MHD_LIBRARIES, the libraries needed to use jsoncpp. 10 | # MHD_FOUND, If false, do not try to use jsoncpp. 11 | 12 | find_path( 13 | MHD_INCLUDE_DIR 14 | NAMES microhttpd.h 15 | DOC "microhttpd include dir" 16 | ) 17 | 18 | find_library( 19 | MHD_LIBRARY 20 | NAMES microhttpd microhttpd-10 libmicrohttpd libmicrohttpd-dll 21 | DOC "microhttpd library" 22 | ) 23 | 24 | set(MHD_INCLUDE_DIRS ${MHD_INCLUDE_DIR}) 25 | set(MHD_LIBRARIES ${MHD_LIBRARY}) 26 | 27 | # debug library on windows 28 | # same naming convention as in QT (appending debug library with d) 29 | # boost is using the same "hack" as us with "optimized" and "debug" 30 | # official MHD project actually uses _d suffix 31 | if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") 32 | 33 | find_library( 34 | MHD_LIBRARY_DEBUG 35 | NAMES microhttpd_d microhttpd-10_d libmicrohttpd_d libmicrohttpd-dll_d 36 | DOC "mhd debug library" 37 | ) 38 | 39 | set(MHD_LIBRARIES optimized ${MHD_LIBRARIES} debug ${MHD_LIBRARY_DEBUG}) 40 | 41 | # prepare dlls 42 | string(REPLACE ".lib" ".dll" MHD_DLL ${MHD_LIBRARY}) 43 | string(REPLACE "/lib/" "/bin/" MHD_DLL ${MHD_DLL}) 44 | string(REPLACE ".lib" ".dll" MHD_DLL_DEBUG ${MHD_LIBRARY_DEBUG}) 45 | string(REPLACE "/lib/" "/bin/" MHD_DLL_DEBUG ${MHD_DLL_DEBUG}) 46 | set(MHD_DLLS optimized ${MHD_DLL} debug ${MHD_DLL_DEBUG}) 47 | 48 | endif() 49 | 50 | include(FindPackageHandleStandardArgs) 51 | find_package_handle_standard_args(mhd DEFAULT_MSG 52 | MHD_INCLUDE_DIR MHD_LIBRARY) 53 | 54 | mark_as_advanced(MHD_INCLUDE_DIR MHD_LIBRARY) 55 | -------------------------------------------------------------------------------- /cmake/FindMiniupnpc.cmake: -------------------------------------------------------------------------------- 1 | # Find miniupnpc 2 | # 3 | # Find the miniupnpc includes and library 4 | # 5 | # if you nee to add a custom library search path, do it via via CMAKE_PREFIX_PATH 6 | # 7 | # This module defines 8 | # MINIUPNPC_INCLUDE_DIRS, where to find header, etc. 9 | # MINIUPNPC_LIBRARIES, the libraries needed to use gmp. 10 | # MINIUPNPC_FOUND, If false, do not try to use gmp. 11 | 12 | # only look in default directories 13 | find_path( 14 | MINIUPNPC_INCLUDE_DIR 15 | NAMES miniupnpc/miniupnpc.h 16 | DOC "miniupnpc include dir" 17 | ) 18 | 19 | find_library( 20 | MINIUPNPC_LIBRARY 21 | NAMES miniupnpc 22 | DOC "miniupnpc library" 23 | ) 24 | 25 | set(MINIUPNPC_INCLUDE_DIRS ${MINIUPNPC_INCLUDE_DIR}) 26 | set(MINIUPNPC_LIBRARIES ${MINIUPNPC_LIBRARY}) 27 | 28 | # debug library on windows 29 | # same naming convention as in QT (appending debug library with d) 30 | # boost is using the same "hack" as us with "optimized" and "debug" 31 | if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") 32 | 33 | find_library( 34 | MINIUPNPC_LIBRARY_DEBUG 35 | NAMES miniupnpcd 36 | DOC "miniupnpc debug library" 37 | ) 38 | 39 | set(MINIUPNPC_LIBRARIES "iphlpapi" optimized ${MINIUPNPC_LIBRARIES} debug ${MINIUPNPC_LIBRARY_DEBUG}) 40 | 41 | endif() 42 | 43 | # handle the QUIETLY and REQUIRED arguments and set MINIUPNPC_FOUND to TRUE 44 | # if all listed variables are TRUE, hide their existence from configuration view 45 | include(FindPackageHandleStandardArgs) 46 | find_package_handle_standard_args(miniupnpc DEFAULT_MSG 47 | MINIUPNPC_INCLUDE_DIR MINIUPNPC_LIBRARY) 48 | mark_as_advanced (MINIUPNPC_INCLUDE_DIR MINIUPNPC_LIBRARY) 49 | 50 | -------------------------------------------------------------------------------- /cmake/FindPackageMessage.cmake: -------------------------------------------------------------------------------- 1 | #.rst: 2 | # FindPackageMessage 3 | # ------------------ 4 | # 5 | # 6 | # 7 | # FIND_PACKAGE_MESSAGE( "message for user" "find result details") 8 | # 9 | # This macro is intended to be used in FindXXX.cmake modules files. It 10 | # will print a message once for each unique find result. This is useful 11 | # for telling the user where a package was found. The first argument 12 | # specifies the name (XXX) of the package. The second argument 13 | # specifies the message to display. The third argument lists details 14 | # about the find result so that if they change the message will be 15 | # displayed again. The macro also obeys the QUIET argument to the 16 | # find_package command. 17 | # 18 | # Example: 19 | # 20 | # :: 21 | # 22 | # if(X11_FOUND) 23 | # FIND_PACKAGE_MESSAGE(X11 "Found X11: ${X11_X11_LIB}" 24 | # "[${X11_X11_LIB}][${X11_INCLUDE_DIR}]") 25 | # else() 26 | # ... 27 | # endif() 28 | 29 | #============================================================================= 30 | # Copyright 2008-2009 Kitware, Inc. 31 | # 32 | # Distributed under the OSI-approved BSD License (the "License"); 33 | # see accompanying file Copyright.txt for details. 34 | # 35 | # This software is distributed WITHOUT ANY WARRANTY; without even the 36 | # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 37 | # See the License for more information. 38 | #============================================================================= 39 | # (To distribute this file outside of CMake, substitute the full 40 | # License text for the above reference.) 41 | 42 | function(FIND_PACKAGE_MESSAGE pkg msg details) 43 | # Avoid printing a message repeatedly for the same find result. 44 | if(NOT ${pkg}_FIND_QUIETLY) 45 | string(REPLACE "\n" "" details "${details}") 46 | set(DETAILS_VAR FIND_PACKAGE_MESSAGE_DETAILS_${pkg}) 47 | if(NOT "${details}" STREQUAL "${${DETAILS_VAR}}") 48 | # The message has not yet been printed. 49 | message(STATUS "${msg}") 50 | 51 | # Save the find details in the cache to avoid printing the same 52 | # message again. 53 | set("${DETAILS_VAR}" "${details}" 54 | CACHE INTERNAL "Details about finding ${pkg}") 55 | endif() 56 | endif() 57 | endfunction() 58 | -------------------------------------------------------------------------------- /cmake/FindReadline.cmake: -------------------------------------------------------------------------------- 1 | # Find readline 2 | # 3 | # Find the readline includes and library 4 | # 5 | # if you nee to add a custom library search path, do it via via CMAKE_PREFIX_PATH 6 | # 7 | # This module defines 8 | # READLINE_INCLUDE_DIRS, where to find header, etc. 9 | # READLINE_LIBRARIES, the libraries needed to use readline. 10 | # READLINE_FOUND, If false, do not try to use readline. 11 | 12 | # only look in default directories 13 | find_path( 14 | READLINE_INCLUDE_DIR 15 | NAMES readline/readline.h 16 | DOC "readling include dir" 17 | ) 18 | 19 | find_library( 20 | READLINE_LIBRARY 21 | NAMES readline 22 | DOC "readline library" 23 | ) 24 | 25 | set(READLINE_INCLUDE_DIRS ${READLINE_INCLUDE_DIR}) 26 | set(READLINE_LIBRARIES ${READLINE_LIBRARY}) 27 | 28 | # handle the QUIETLY and REQUIRED arguments and set READLINE_FOUND to TRUE 29 | # if all listed variables are TRUE, hide their existence from configuration view 30 | include(FindPackageHandleStandardArgs) 31 | find_package_handle_standard_args(readline DEFAULT_MSG 32 | READLINE_INCLUDE_DIR READLINE_LIBRARY) 33 | mark_as_advanced (READLINE_INCLUDE_DIR READLINE_LIBRARY) 34 | 35 | -------------------------------------------------------------------------------- /cmake/Findv8.cmake: -------------------------------------------------------------------------------- 1 | # Find v8 2 | # 3 | # Find the v8 includes and library 4 | # 5 | # if you nee to add a custom library search path, do it via via CMAKE_PREFIX_PATH 6 | # 7 | # This module defines 8 | # V8_INCLUDE_DIRS, where to find header, etc. 9 | # V8_LIBRARIES, the libraries needed to use v8. 10 | # V8_FOUND, If false, do not try to use v8. 11 | 12 | # only look in default directories 13 | find_path( 14 | V8_INCLUDE_DIR 15 | NAMES v8.h 16 | DOC "v8 include dir" 17 | ) 18 | 19 | find_library( 20 | V8_LIBRARY 21 | NAMES v8 22 | DOC "v8 library" 23 | ) 24 | 25 | set(V8_INCLUDE_DIRS ${V8_INCLUDE_DIR}) 26 | set(V8_LIBRARIES ${V8_LIBRARY}) 27 | 28 | # debug library on windows 29 | # same naming convention as in qt (appending debug library with d) 30 | # boost is using the same "hack" as us with "optimized" and "debug" 31 | if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") 32 | 33 | find_library( 34 | V8_LIBRARY 35 | NAMES v8_base 36 | DOC "v8 base library" 37 | ) 38 | 39 | find_library( 40 | V8_NO_SNAPSHOT_LIBRARY 41 | NAMES v8_nosnapshot 42 | DOC "v8 nosnapshot library" 43 | ) 44 | 45 | set(V8_LIBRARIES ${V8_LIBRARY} ${V8_NO_SNAPSHOT_LIBRARY}) 46 | 47 | find_library( 48 | V8_LIBRARY_DEBUG 49 | NAMES v8_based 50 | DOC "v8 base library" 51 | ) 52 | 53 | find_library( 54 | V8_NO_SNAPSHOT_LIBRARY_DEBUG 55 | NAMES v8_nosnapshotd 56 | DOC "v8 nosnapshot library" 57 | ) 58 | 59 | set(V8_LIBRARIES "ws2_32" "winmm" optimized ${V8_LIBRARIES} debug ${V8_LIBRARY_DEBUG} ${V8_NO_SNAPSHOT_LIBRARY_DEBUG}) 60 | 61 | endif() 62 | 63 | # handle the QUIETLY and REQUIRED arguments and set V8_FOUND to TRUE 64 | # if all listed variables are TRUE, hide their existence from configuration view 65 | include(FindPackageHandleStandardArgs) 66 | find_package_handle_standard_args(v8 DEFAULT_MSG 67 | V8_INCLUDE_DIR V8_LIBRARY) 68 | mark_as_advanced (V8_INCLUDE_DIR V8_LIBRARY) 69 | 70 | -------------------------------------------------------------------------------- /cmake/scripts/appdmg.cmake: -------------------------------------------------------------------------------- 1 | 2 | if (NOT APP_DMG_EXE) 3 | message(FATAL_ERROR "Please install appdmg! https://github.com/LinusU/node-appdmg") 4 | endif() 5 | 6 | string(REPLACE "/Contents/MacOS" "" ETH_MIX_APP "${ETH_MIX_APP}") 7 | string(REPLACE "/Contents/MacOS" "" ETH_ALETHZERO_APP "${ETH_ALETHZERO_APP}") 8 | 9 | set(OUTFILE "${ETH_BUILD_DIR}/appdmg.json") 10 | 11 | configure_file(${APP_DMG_FILE} ${OUTFILE}) 12 | 13 | execute_process(COMMAND ${CMAKE_COMMAND} -E copy "${APP_DMG_ICON}" "${ETH_BUILD_DIR}/appdmg_icon.icns") 14 | execute_process(COMMAND ${CMAKE_COMMAND} -E copy "${APP_DMG_BACKGROUND}" "${ETH_BUILD_DIR}/appdmg_background.png") 15 | execute_process(COMMAND ${CMAKE_COMMAND} -E remove "${ETH_BUILD_DIR}/Ethereum.dmg") 16 | execute_process(COMMAND ${APP_DMG_EXE} ${OUTFILE} "${ETH_BUILD_DIR}/Ethereum.dmg") 17 | 18 | -------------------------------------------------------------------------------- /cmake/scripts/buildinfo.cmake: -------------------------------------------------------------------------------- 1 | # generates BuildInfo.h 2 | # 3 | # this module expects 4 | # ETH_SOURCE_DIR - main CMAKE_SOURCE_DIR 5 | # ETH_DST_DIR - main CMAKE_BINARY_DIR 6 | # ETH_BUILD_TYPE 7 | # ETH_BUILD_PLATFORM 8 | # 9 | # example usage: 10 | # cmake -DETH_SOURCE_DIR=. -DETH_DST_DIR=build -DETH_BUILD_TYPE=Debug -DETH_BUILD_PLATFORM=mac -P scripts/buildinfo.cmake 11 | 12 | if (ETH_FATDB) 13 | set(ETH_FATDB 1) 14 | else() 15 | set(ETH_FATDB 0) 16 | endif() 17 | 18 | if (NOT ETH_BUILD_TYPE) 19 | set(ETH_BUILD_TYPE "unknown") 20 | endif() 21 | 22 | if (NOT ETH_BUILD_PLATFORM) 23 | set(ETH_BUILD_PLATFORM "unknown") 24 | endif() 25 | 26 | execute_process( 27 | COMMAND git --git-dir=${ETH_SOURCE_DIR}/.git --work-tree=${ETH_SOURCE_DIR} rev-parse HEAD 28 | OUTPUT_VARIABLE ETH_COMMIT_HASH OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET 29 | ) 30 | 31 | if (NOT ETH_COMMIT_HASH) 32 | set(ETH_COMMIT_HASH 0) 33 | endif() 34 | 35 | execute_process( 36 | COMMAND git --git-dir=${ETH_SOURCE_DIR}/.git --work-tree=${ETH_SOURCE_DIR} diff --shortstat 37 | OUTPUT_VARIABLE ETH_LOCAL_CHANGES OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET 38 | ) 39 | 40 | if (ETH_LOCAL_CHANGES) 41 | set(ETH_CLEAN_REPO 0) 42 | else() 43 | set(ETH_CLEAN_REPO 1) 44 | endif() 45 | 46 | set(INFILE "${ETH_SOURCE_DIR}/BuildInfo.h.in") 47 | set(TMPFILE "${ETH_DST_DIR}/BuildInfo.h.tmp") 48 | set(OUTFILE "${ETH_DST_DIR}/BuildInfo.h") 49 | 50 | configure_file("${INFILE}" "${TMPFILE}") 51 | 52 | include("${ETH_SOURCE_DIR}/cmake/EthUtils.cmake") 53 | replace_if_different("${TMPFILE}" "${OUTFILE}" CREATE) 54 | 55 | -------------------------------------------------------------------------------- /cmake/scripts/configure.cmake: -------------------------------------------------------------------------------- 1 | # adds possibility to run configure_file as buildstep 2 | # reference: 3 | # http://www.cmake.org/pipermail/cmake/2012-May/050227.html 4 | # 5 | # This module expects 6 | # INFILE 7 | # OUTFILE 8 | # other custom vars 9 | # 10 | # example usage: 11 | # cmake -DINFILE=blah.in -DOUTFILE=blah.out -Dvar1=value1 -Dvar2=value2 -P scripts/configure.cmake 12 | 13 | configure_file(${INFILE} ${OUTFILE}) 14 | 15 | -------------------------------------------------------------------------------- /cmake/scripts/copydlls.cmake: -------------------------------------------------------------------------------- 1 | # this module expects 2 | # DLLS 3 | # CONF 4 | # DESTINATION 5 | 6 | # example usage: 7 | # cmake -DDLL_DEBUG=xd.dll -DDLL_RELEASE=x.dll -DCONFIGURATION=Release -DDESTINATION=dest -P scripts/copydlls.cmake 8 | 9 | # this script is created cause we do not know configuration in multiconfiguration generators at cmake configure phase ;) 10 | 11 | if ("${CONF}" STREQUAL "Debug") 12 | set(DLL ${DLL_DEBUG}) 13 | else () 14 | set(DLL ${DLL_RELEASE}) 15 | endif() 16 | 17 | execute_process(COMMAND ${CMAKE_COMMAND} -E copy "${DLL}" "${DESTINATION}") 18 | 19 | -------------------------------------------------------------------------------- /cmake/scripts/jsonrpcstub.cmake: -------------------------------------------------------------------------------- 1 | # generates JSONRPC Stub Server && Client 2 | # 3 | # this script expects 4 | # ETH_SOURCE_DIR - main CMAKE_SOURCE_DIR 5 | # ETH_SPEC_PATH 6 | # ETH_SERVER_DIR 7 | # ETH_CLIENT_DIR 8 | # ETH_SERVER_NAME 9 | # ETH_CLIENT_NAME 10 | # ETH_JSON_RPC_STUB 11 | # 12 | # example usage: 13 | # cmake -DETH_SPEC_PATH=spec.json -DETH_SERVER_DIR=libweb3jsonrpc -DETH_CLIENT_DIR=test 14 | # -DETH_SERVER_NAME=AbstractWebThreeStubServer -DETH_CLIENT_NAME=WebThreeStubClient -DETH_JSON_RPC_STUB=/usr/local/bin/jsonrpcstub 15 | 16 | # by default jsonrpcstub produces files in lowercase, we want to stick to this 17 | string(TOLOWER ${ETH_SERVER_NAME} ETH_SERVER_NAME_LOWER) 18 | string(TOLOWER ${ETH_CLIENT_NAME} ETH_CLIENT_NAME_LOWER) 19 | 20 | # setup names 21 | set(SERVER_TMPFILE "${ETH_SERVER_DIR}/${ETH_SERVER_NAME_LOWER}.h.tmp") 22 | set(SERVER_OUTFILE "${ETH_SERVER_DIR}/${ETH_SERVER_NAME_LOWER}.h") 23 | set(CLIENT_TMPFILE "${ETH_CLIENT_DIR}/${ETH_CLIENT_NAME_LOWER}.h.tmp") 24 | set(CLIENT_OUTFILE "${ETH_CLIENT_DIR}/${ETH_CLIENT_NAME_LOWER}.h") 25 | 26 | # create tmp files 27 | execute_process( 28 | COMMAND ${ETH_JSON_RPC_STUB} ${ETH_SPEC_PATH} 29 | --cpp-server=${ETH_SERVER_NAME} --cpp-server-file=${SERVER_TMPFILE} 30 | --cpp-client=${ETH_CLIENT_NAME} --cpp-client-file=${CLIENT_TMPFILE} 31 | OUTPUT_VARIABLE ERR ERROR_QUIET 32 | ) 33 | 34 | # don't throw fatal error on jsonrpcstub error, someone might have old version of jsonrpcstub, 35 | # he does not need to upgrade it if he is not working on JSON RPC 36 | # show him warning instead 37 | if (ERR) 38 | message(WARNING "Your version of jsonrcpstub tool is not supported. Please upgrade it.") 39 | message(WARNING "${ERR}") 40 | else() 41 | include("${ETH_SOURCE_DIR}/cmake/EthUtils.cmake") 42 | replace_if_different("${SERVER_TMPFILE}" "${SERVER_OUTFILE}") 43 | replace_if_different("${CLIENT_TMPFILE}" "${CLIENT_OUTFILE}") 44 | endif() 45 | -------------------------------------------------------------------------------- /cmake/scripts/macdeployfix.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # solves problem with macdeployqt on Qt 5.4 RC and Qt 5.5 4 | # http://qt-project.org/forums/viewthread/50118 5 | 6 | BUILD_FOLDER_PATH=$1 7 | BUILD_QML_FOLDER_PATH="$BUILD_FOLDER_PATH/Resources/qml" 8 | BUILD_PLUGINS_FOLDER_PATH="$BUILD_FOLDER_PATH/PlugIns" 9 | 10 | if [ -d ${BUILD_QML_FOLDER_PATH} ]; then 11 | 12 | declare -a BROKEN_FILES; 13 | k=0; 14 | for j in $(find ${BUILD_QML_FOLDER_PATH} -name *.dylib); do 15 | BROKEN_FILES[${k}]=$j 16 | 17 | ((k=k+1)) 18 | done 19 | 20 | 21 | for i in "${BROKEN_FILES[@]}"; do 22 | REPLACE_STRING="$BUILD_FOLDER_PATH/" 23 | APP_CONTENT_FILE=${i//$REPLACE_STRING/""} 24 | IFS='/' read -a array <<< "$APP_CONTENT_FILE" 25 | LENGTH=${#array[@]} 26 | LAST_ITEM_INDEX=$((LENGTH-1)) 27 | FILE=${array[${LENGTH} - 1]} 28 | 29 | ORIGINE_PATH=$(find ${BUILD_PLUGINS_FOLDER_PATH} -name ${FILE}) 30 | ORIGINE_PATH=${ORIGINE_PATH//$REPLACE_STRING/""} 31 | s="" 32 | for((l=0;l<${LAST_ITEM_INDEX};l++)) do 33 | s=$s"../" 34 | done 35 | s=$s$ORIGINE_PATH 36 | echo "s: $s" 37 | 38 | REMOVE_BROKEN_ALIAS=$(rm -rf $i) 39 | RESULT=$(ln -s $s $i) 40 | done 41 | fi 42 | 43 | # replace framework links 44 | declare -a BROKEN_FRAMEWORKS; 45 | k=0; 46 | BUILD_FRAMEWORKS_FOLDER_PATH="$BUILD_FOLDER_PATH/Frameworks" 47 | for j in $(find ${BUILD_FRAMEWORKS_FOLDER_PATH} -name Qt*.framework); do 48 | BROKEN_FRAMEWORKS[${k}]=$j 49 | ((k=k+1)) 50 | done 51 | for i in "${BROKEN_FRAMEWORKS[@]}"; do 52 | FRAMEWORK_FILE=$i/$(basename -s ".framework" $i) 53 | otool -L $FRAMEWORK_FILE | grep -o /usr/.*Qt.*framework/\\w* | while read -a libs ; do 54 | install_name_tool -change ${libs[0]} @loader_path/../../../`basename ${libs[0]}`.framework/`basename ${libs[0]}` $FRAMEWORK_FILE 55 | done 56 | done 57 | 58 | declare -a BROKEN_PLUGINS; 59 | k=0; 60 | BUILD_PLUGINS_FOLDER_PATH="$BUILD_FOLDER_PATH/PlugIns" 61 | for j in $(find ${BUILD_PLUGINS_FOLDER_PATH} -name *.dylib); do 62 | BROKEN_PLUGINS[${k}]=$j 63 | ((k=k+1)) 64 | done 65 | for i in "${BROKEN_PLUGINS[@]}"; do 66 | FRAMEWORK_FILE=$i 67 | otool -L $FRAMEWORK_FILE | grep -o /usr/.*Qt.*framework/\\w* | while read -a libs ; do 68 | install_name_tool -change ${libs[0]} @loader_path/../../Frameworks/`basename ${libs[0]}`.framework/`basename ${libs[0]}` $FRAMEWORK_FILE 69 | done 70 | done 71 | 72 | -------------------------------------------------------------------------------- /cmake/scripts/resource.hpp.in: -------------------------------------------------------------------------------- 1 | // this file is autogenerated, do not modify!!! 2 | #pragma once 3 | 4 | #include 5 | #include 6 | 7 | namespace dev 8 | { 9 | namespace eth 10 | { 11 | 12 | class ${ETH_RESOURCE_NAME} 13 | { 14 | public: 15 | ${ETH_RESOURCE_NAME}() 16 | { 17 | ${ETH_RESULT_DATA} 18 | ${ETH_RESULT_INIT} 19 | } 20 | 21 | std::string loadResourceAsString(std::string _name) { return std::string(m_resources[_name], m_sizes[_name]); } 22 | 23 | private: 24 | std::map m_resources; 25 | std::map m_sizes; 26 | }; 27 | 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /cmake/scripts/resources.cmake: -------------------------------------------------------------------------------- 1 | # based on: http://stackoverflow.com/questions/11813271/embed-resources-eg-shader-code-images-into-executable-library-with-cmake 2 | # 3 | # example: 4 | # cmake -DETH_RES_FILE=test.cmake -P resources.cmake 5 | # 6 | # where test.cmake is: 7 | # 8 | # # BEGIN OF cmake.test 9 | # 10 | # set(copydlls "copydlls.cmake") 11 | # set(conf "configure.cmake") 12 | # 13 | # # this three properties must be set! 14 | # 15 | # set(ETH_RESOURCE_NAME "EthResources") 16 | # set(ETH_RESOURCE_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}") 17 | # set(ETH_RESOURCES "copydlls" "conf") 18 | # 19 | # # END of cmake.test 20 | # 21 | 22 | # should define ETH_RESOURCES 23 | include(${ETH_RES_FILE}) 24 | 25 | set(ETH_RESULT_DATA "") 26 | set(ETH_RESULT_INIT "") 27 | 28 | # resource is a name visible for cpp application 29 | foreach(resource ${ETH_RESOURCES}) 30 | 31 | # filename is the name of file which will be used in app 32 | set(filename ${${resource}}) 33 | 34 | # filedata is a file content 35 | file(READ ${filename} filedata HEX) 36 | 37 | # read full name of the file 38 | file(GLOB filename ${filename}) 39 | 40 | # Convert hex data for C compatibility 41 | string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1," filedata ${filedata}) 42 | 43 | # append static variables to result variable 44 | set(ETH_RESULT_DATA "${ETH_RESULT_DATA} static const unsigned char eth_${resource}[] = {\n // ${filename}\n ${filedata}\n};\n") 45 | 46 | # append init resources 47 | set(ETH_RESULT_INIT "${ETH_RESULT_INIT} m_resources[\"${resource}\"] = (char const*)eth_${resource};\n") 48 | set(ETH_RESULT_INIT "${ETH_RESULT_INIT} m_sizes[\"${resource}\"] = sizeof(eth_${resource});\n") 49 | 50 | endforeach(resource) 51 | 52 | set(ETH_DST_NAME "${ETH_RESOURCE_LOCATION}/${ETH_RESOURCE_NAME}") 53 | 54 | configure_file("${CMAKE_CURRENT_LIST_DIR}/resource.hpp.in" "${ETH_DST_NAME}.hpp.tmp") 55 | 56 | include("${CMAKE_CURRENT_LIST_DIR}/../EthUtils.cmake") 57 | replace_if_different("${ETH_DST_NAME}.hpp.tmp" "${ETH_DST_NAME}.hpp") 58 | -------------------------------------------------------------------------------- /cmake/scripts/runtest.cmake: -------------------------------------------------------------------------------- 1 | # Should be used to run ctest 2 | # 3 | # example usage: 4 | # cmake -DETH_TEST_NAME=TestInterfaceStub -DCTEST_COMMAND=/path/to/ctest -P scripts/runtest.cmake 5 | 6 | if (NOT CTEST_COMMAND) 7 | message(FATAL_ERROR "ctest could not be found!") 8 | endif() 9 | 10 | # verbosity is off, cause BOOST_MESSAGE is not thread safe and output is a trash 11 | # see https://codecrafter.wordpress.com/2012/11/01/c-unit-test-framework-adapter-part-3/ 12 | # 13 | # output might not be usefull cause of thread safety issue 14 | execute_process(COMMAND ${CTEST_COMMAND} --force-new-ctest-process -C Debug --output-on-failure -j 4 -R "${ETH_TEST_NAME}[.].*") 15 | 16 | -------------------------------------------------------------------------------- /ethminer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_policy(SET CMP0015 NEW) 2 | set(CMAKE_AUTOMOC OFF) 3 | 4 | aux_source_directory(. SRC_LIST) 5 | 6 | include_directories(BEFORE ..) 7 | include_directories(${Boost_INCLUDE_DIRS}) 8 | 9 | if (JSONRPC) 10 | include_directories(BEFORE ${JSONCPP_INCLUDE_DIRS}) 11 | include_directories(${JSON_RPC_CPP_INCLUDE_DIRS}) 12 | endif() 13 | 14 | if (ETHASHCUDA) 15 | include_directories(${CUDA_INCLUDE_DIRS}) 16 | endif () 17 | 18 | set(EXECUTABLE ethminer) 19 | 20 | file(GLOB HEADERS "*.h") 21 | 22 | add_executable(${EXECUTABLE} ${SRC_LIST} ${HEADERS}) 23 | 24 | add_dependencies(${EXECUTABLE} BuildInfo.h) 25 | 26 | target_link_libraries(${EXECUTABLE} ${Boost_REGEX_LIBRARIES}) 27 | 28 | if (JSONRPC) 29 | target_link_libraries(${EXECUTABLE} ${JSON_RPC_CPP_CLIENT_LIBRARIES}) 30 | target_link_libraries(${EXECUTABLE} ${CURL_LIBRARIES}) 31 | if (DEFINED WIN32 AND NOT DEFINED CMAKE_COMPILER_IS_MINGW) 32 | eth_copy_dlls(${EXECUTABLE} CURL_DLLS) 33 | endif() 34 | endif() 35 | 36 | target_link_libraries(${EXECUTABLE} ethcore) 37 | target_link_libraries(${EXECUTABLE} ethash) 38 | target_link_libraries(${EXECUTABLE} devcore) 39 | 40 | if (ETHSTRATUM) 41 | target_link_libraries(${EXECUTABLE} ethstratum) 42 | endif() 43 | 44 | if (DEFINED WIN32 AND NOT DEFINED CMAKE_COMPILER_IS_MINGW) 45 | eth_copy_dlls("${EXECUTABLE}" MHD_DLLS) 46 | eth_copy_dlls("${EXECUTABLE}" OpenCL_DLLS) 47 | endif() 48 | 49 | 50 | if (APPLE) 51 | install(TARGETS ${EXECUTABLE} DESTINATION bin) 52 | else() 53 | eth_install_executable(${EXECUTABLE}) 54 | endif() 55 | -------------------------------------------------------------------------------- /ethminer/FarmClient.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is generated by jsonrpcstub, DO NOT CHANGE IT MANUALLY! 3 | */ 4 | 5 | #ifndef JSONRPC_CPP_STUB_FARMCLIENT_H_ 6 | #define JSONRPC_CPP_STUB_FARMCLIENT_H_ 7 | 8 | #include 9 | 10 | class FarmClient : public jsonrpc::Client 11 | { 12 | public: 13 | FarmClient(jsonrpc::IClientConnector &conn, jsonrpc::clientVersion_t type = jsonrpc::JSONRPC_CLIENT_V2) : jsonrpc::Client(conn, type) {} 14 | 15 | Json::Value eth_getWork() throw (jsonrpc::JsonRpcException) 16 | { 17 | Json::Value p; 18 | p = Json::nullValue; 19 | Json::Value result = this->CallMethod("eth_getWork",p); 20 | if (result.isArray()) 21 | return result; 22 | else 23 | throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); 24 | } 25 | bool eth_submitWork(const std::string& param1, const std::string& param2, const std::string& param3) throw (jsonrpc::JsonRpcException) 26 | { 27 | Json::Value p; 28 | p.append(param1); 29 | p.append(param2); 30 | p.append(param3); 31 | Json::Value result = this->CallMethod("eth_submitWork",p); 32 | if (result.isBool()) 33 | return result.asBool(); 34 | else 35 | throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); 36 | } 37 | bool eth_submitHashrate(const std::string& param1, const std::string& param2) throw (jsonrpc::JsonRpcException) 38 | { 39 | Json::Value p; 40 | p.append(param1); 41 | p.append(param2); 42 | Json::Value result = this->CallMethod("eth_submitHashrate",p); 43 | if (result.isBool()) 44 | return result.asBool(); 45 | else 46 | throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); 47 | } 48 | Json::Value eth_awaitNewWork() throw (jsonrpc::JsonRpcException) 49 | { 50 | Json::Value p; 51 | p = Json::nullValue; 52 | Json::Value result = this->CallMethod("eth_awaitNewWork",p); 53 | if (result.isArray()) 54 | return result; 55 | else 56 | throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); 57 | } 58 | bool eth_progress() throw (jsonrpc::JsonRpcException) 59 | { 60 | Json::Value p; 61 | p = Json::nullValue; 62 | Json::Value result = this->CallMethod("eth_progress",p); 63 | if (result.isBool()) 64 | return result.asBool(); 65 | else 66 | throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); 67 | } 68 | }; 69 | 70 | #endif //JSONRPC_CPP_STUB_FARMCLIENT_H_ 71 | -------------------------------------------------------------------------------- /ethminer/PhoneHome.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is generated by jsonrpcstub, DO NOT CHANGE IT MANUALLY! 3 | */ 4 | 5 | #ifndef JSONRPC_CPP_STUB_PHONEHOME_H_ 6 | #define JSONRPC_CPP_STUB_PHONEHOME_H_ 7 | 8 | #include 9 | 10 | class PhoneHome : public jsonrpc::Client 11 | { 12 | public: 13 | PhoneHome(jsonrpc::IClientConnector &conn, jsonrpc::clientVersion_t type = jsonrpc::JSONRPC_CLIENT_V2) : jsonrpc::Client(conn, type) {} 14 | 15 | int report_benchmark(const std::string& param1, int param2) throw (jsonrpc::JsonRpcException) 16 | { 17 | Json::Value p; 18 | p.append(param1); 19 | p.append(param2); 20 | Json::Value result = this->CallMethod("report_benchmark",p); 21 | if (result.isInt()) 22 | return result.asInt(); 23 | else 24 | throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); 25 | } 26 | }; 27 | 28 | #endif //JSONRPC_CPP_STUB_PHONEHOME_H_ 29 | -------------------------------------------------------------------------------- /ethminer/farm.json: -------------------------------------------------------------------------------- 1 | [ 2 | { "name": "eth_getWork", "params": [], "order": [], "returns": []}, 3 | { "name": "eth_submitWork", "params": ["", "", ""], "order": [], "returns": true}, 4 | { "name": "eth_submitHashrate", "params": ["", ""], "order": [], "returns": true}, 5 | { "name": "eth_awaitNewWork", "params": [], "order": [], "returns": []}, 6 | { "name": "eth_progress", "params": [], "order": [], "returns": true} 7 | ] 8 | -------------------------------------------------------------------------------- /ethminer/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file main.cpp 18 | * @author Gav Wood 19 | * @date 2014 20 | * Ethereum client. 21 | */ 22 | 23 | // Solves the problem of including windows.h before including winsock.h 24 | // as detailed here: 25 | // http://stackoverflow.com/questions/1372480/c-redefinition-header-files-winsock2-h 26 | #if defined(_WIN32) 27 | #define _WINSOCKAPI_ 28 | #include 29 | #endif 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include "MinerAux.h" 40 | using namespace std; 41 | using namespace dev; 42 | using namespace dev::eth; 43 | using namespace boost::algorithm; 44 | 45 | #undef RETURN 46 | 47 | void help() 48 | { 49 | cout 50 | << "Usage ethminer [OPTIONS]" << endl 51 | << "Options:" << endl << endl; 52 | MinerCLI::streamHelp(cout); 53 | cout 54 | << "General Options:" << endl 55 | << " -v,--verbosity <0 - 9> Set the log verbosity from 0 to 9 (default: 8)." << endl 56 | << " -V,--version Show the version and exit." << endl 57 | << " -h,--help Show this help message and exit." << endl 58 | ; 59 | exit(0); 60 | } 61 | 62 | void version() 63 | { 64 | cout << "ethminer version " << dev::Version << endl; 65 | cout << "Build: " << DEV_QUOTED(ETH_BUILD_PLATFORM) << "/" << DEV_QUOTED(ETH_BUILD_TYPE) << endl; 66 | exit(0); 67 | } 68 | 69 | int main(int argc, char** argv) 70 | { 71 | cout << "Genoil's ethminer " << ETH_PROJECT_VERSION << endl; 72 | cout << "=====================================================================" << endl; 73 | cout << "Forked from github.com/ethereum/cpp-ethereum" << endl; 74 | cout << "CUDA kernel ported from Tim Hughes' OpenCL kernel" << endl; 75 | cout << "With contributions from nicehash, nerdralph, RoBiK and sp_ " << endl << endl; 76 | cout << "Please consider a donation to:" << endl; 77 | cout << "ETH: 0xeb9310b185455f863f526dab3d245809f6854b4d" << endl << endl; 78 | 79 | MinerCLI m(MinerCLI::OperationMode::Farm); 80 | 81 | for (int i = 1; i < argc; ++i) 82 | { 83 | string arg = argv[i]; 84 | if (m.interpretOption(i, argc, argv)) 85 | {} 86 | else if ((arg == "-v" || arg == "--verbosity") && i + 1 < argc) 87 | g_logVerbosity = atoi(argv[++i]); 88 | else if (arg == "-h" || arg == "--help") 89 | help(); 90 | else if (arg == "-V" || arg == "--version") 91 | version(); 92 | else 93 | { 94 | cerr << "Invalid argument: " << arg << endl; 95 | exit(-1); 96 | } 97 | } 98 | 99 | m.execute(); 100 | 101 | return 0; 102 | } 103 | 104 | -------------------------------------------------------------------------------- /ethminer/phonehome.json: -------------------------------------------------------------------------------- 1 | [ 2 | { "name": "report_benchmark", "params": [ "", 0 ], "order": [], "returns": 0 } 3 | ] 4 | -------------------------------------------------------------------------------- /extdep/getstuff.bat: -------------------------------------------------------------------------------- 1 | REM get stuff! 2 | if not exist download mkdir download 3 | if not exist install mkdir install 4 | if not exist install\windows mkdir install\windows 5 | 6 | set eth_server=https://build.ethdev.com/builds/windows-precompiled 7 | 8 | call :download boost 1.55.0 9 | call :download cryptopp 5.6.2 10 | call :download curl 7.4.2 11 | call :download jsoncpp 1.6.2 12 | call :download json-rpc-cpp 0.5.0 13 | call :download leveldb 1.2 14 | call :download microhttpd 0.9.2 15 | call :download OpenCL_ICD 1 16 | 17 | goto :EOF 18 | 19 | :download 20 | 21 | set eth_name=%1 22 | set eth_version=%2 23 | 24 | cd download 25 | 26 | if not exist %eth_name%-%eth_version%-x64.tar.gz ( 27 | for /f "tokens=2 delims={}" %%g in ('bitsadmin /create %eth_name%-%eth_version%-x64.tar.gz') do ( 28 | bitsadmin /transfer {%%g} /download /priority normal %eth_server%/%eth_name%-%eth_version%-x64.tar.gz %cd%\%eth_name%-%eth_version%-x64.tar.gz 29 | bitsadmin /cancel {%%g} 30 | ) 31 | ) 32 | if not exist %eth_name%-%eth_version% cmake -E tar -zxvf %eth_name%-%eth_version%-x64.tar.gz 33 | cmake -E copy_directory %eth_name%-%eth_version% ..\install\windows 34 | 35 | cd .. 36 | 37 | goto :EOF 38 | 39 | 40 | -------------------------------------------------------------------------------- /libdevcore/Assertions.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** 18 | * @file Assertions.h 19 | * @author Christian 20 | * @date 2015 21 | * 22 | * Assertion handling. 23 | */ 24 | 25 | #pragma once 26 | 27 | #include "Exceptions.h" 28 | #include "debugbreak.h" 29 | 30 | namespace dev 31 | { 32 | 33 | #if defined(_MSC_VER) 34 | #define ETH_FUNC __FUNCSIG__ 35 | #elif defined(__GNUC__) 36 | #define ETH_FUNC __PRETTY_FUNCTION__ 37 | #else 38 | #define ETH_FUNC __func__ 39 | #endif 40 | 41 | #define asserts(A) ::dev::assertAux(A, #A, __LINE__, __FILE__, ETH_FUNC) 42 | #define assertsEqual(A, B) ::dev::assertEqualAux(A, B, #A, #B, __LINE__, __FILE__, ETH_FUNC) 43 | 44 | inline bool assertAux(bool _a, char const* _aStr, unsigned _line, char const* _file, char const* _func) 45 | { 46 | bool ret = _a; 47 | if (!ret) 48 | { 49 | std::cerr << "Assertion failed:" << _aStr << " [func=" << _func << ", line=" << _line << ", file=" << _file << "]" << std::endl; 50 | #if ETH_DEBUG 51 | debug_break(); 52 | #endif 53 | } 54 | return !ret; 55 | } 56 | 57 | template 58 | inline bool assertEqualAux(A const& _a, B const& _b, char const* _aStr, char const* _bStr, unsigned _line, char const* _file, char const* _func) 59 | { 60 | bool ret = _a == _b; 61 | if (!ret) 62 | { 63 | std::cerr << "Assertion failed: " << _aStr << " == " << _bStr << " [func=" << _func << ", line=" << _line << ", file=" << _file << "]" << std::endl; 64 | std::cerr << " Fail equality: " << _a << "==" << _b << std::endl; 65 | #if ETH_DEBUG 66 | debug_break(); 67 | #endif 68 | } 69 | return !ret; 70 | } 71 | 72 | /// Assertion that throws an exception containing the given description if it is not met. 73 | /// Use it as assertThrow(1 == 1, ExceptionType, "Mathematics is wrong."); 74 | /// Do NOT supply an exception object as the second parameter. 75 | #define assertThrow(_condition, _ExceptionType, _description) \ 76 | ::dev::assertThrowAux<_ExceptionType>(_condition, _description, __LINE__, __FILE__, ETH_FUNC) 77 | 78 | using errinfo_comment = boost::error_info; 79 | 80 | template 81 | inline void assertThrowAux( 82 | bool _condition, 83 | ::std::string const& _errorDescription, 84 | unsigned _line, 85 | char const* _file, 86 | char const* _function 87 | ) 88 | { 89 | if (!_condition) 90 | ::boost::throw_exception( 91 | _ExceptionType() << 92 | ::dev::errinfo_comment(_errorDescription) << 93 | ::boost::throw_function(_function) << 94 | ::boost::throw_file(_file) << 95 | ::boost::throw_line(_line) 96 | ); 97 | } 98 | 99 | template 100 | inline void assertThrowAux( 101 | void const* _pointer, 102 | ::std::string const& _errorDescription, 103 | unsigned _line, 104 | char const* _file, 105 | char const* _function 106 | ) 107 | { 108 | assertThrowAux<_ExceptionType>(_pointer != nullptr, _errorDescription, _line, _file, _function); 109 | } 110 | 111 | } 112 | -------------------------------------------------------------------------------- /libdevcore/Base64.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | base64.cpp and base64.h 3 | 4 | Copyright (C) 2004-2008 René Nyffenegger 5 | 6 | This source code is provided 'as-is', without any express or implied 7 | warranty. In no event will the author be held liable for any damages 8 | arising from the use of this software. 9 | 10 | Permission is granted to anyone to use this software for any purpose, 11 | including commercial applications, and to alter it and redistribute it 12 | freely, subject to the following restrictions: 13 | 14 | 1. The origin of this source code must not be misrepresented; you must not 15 | claim that you wrote the original source code. If you use this source code 16 | in a product, an acknowledgment in the product documentation would be 17 | appreciated but is not required. 18 | 19 | 2. Altered source versions must be plainly marked as such, and must not be 20 | misrepresented as being the original source code. 21 | 22 | 3. This notice may not be removed or altered from any source distribution. 23 | 24 | René Nyffenegger rene.nyffenegger@adp-gmbh.ch 25 | */ 26 | /// Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c 27 | /// Originally by René Nyffenegger, modified by some other guy and then devified by Gav Wood. 28 | 29 | #include "Base64.h" 30 | 31 | using namespace std; 32 | using namespace dev; 33 | 34 | static inline bool is_base64(byte c) 35 | { 36 | return (isalnum(c) || (c == '+') || (c == '/')); 37 | } 38 | 39 | static inline byte find_base64_char_index(byte c) 40 | { 41 | if ('A' <= c && c <= 'Z') return c - 'A'; 42 | else if ('a' <= c && c <= 'z') return c - 'a' + 1 + find_base64_char_index('Z'); 43 | else if ('0' <= c && c <= '9') return c - '0' + 1 + find_base64_char_index('z'); 44 | else if (c == '+') return 1 + find_base64_char_index('9'); 45 | else if (c == '/') return 1 + find_base64_char_index('+'); 46 | else return 1 + find_base64_char_index('/'); 47 | } 48 | 49 | string dev::toBase64(bytesConstRef _in) 50 | { 51 | static const char base64_chars[] = 52 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 53 | "abcdefghijklmnopqrstuvwxyz" 54 | "0123456789+/"; 55 | 56 | string ret; 57 | int i = 0; 58 | int j = 0; 59 | byte char_array_3[3]; 60 | byte char_array_4[4]; 61 | 62 | auto buf = _in.data(); 63 | auto bufLen = _in.size(); 64 | 65 | while (bufLen--) 66 | { 67 | char_array_3[i++] = *(buf++); 68 | if (i == 3) 69 | { 70 | char_array_4[0] = (char_array_3[0] & 0xfc) >> 2; 71 | char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4); 72 | char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6); 73 | char_array_4[3] = char_array_3[2] & 0x3f; 74 | 75 | for (i = 0; i < 4; i++) 76 | ret += base64_chars[char_array_4[i]]; 77 | i = 0; 78 | } 79 | } 80 | 81 | if (i) 82 | { 83 | for (j = i; j < 3; j++) 84 | char_array_3[j] = '\0'; 85 | 86 | char_array_4[0] = (char_array_3[0] & 0xfc) >> 2; 87 | char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4); 88 | char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6); 89 | char_array_4[3] = char_array_3[2] & 0x3f; 90 | 91 | for (j = 0; j < i + 1; j++) 92 | ret += base64_chars[char_array_4[j]]; 93 | 94 | while (i++ < 3) 95 | ret += '='; 96 | } 97 | 98 | return ret; 99 | } 100 | 101 | bytes dev::fromBase64(string const& encoded_string) 102 | { 103 | auto in_len = encoded_string.size(); 104 | int i = 0; 105 | int j = 0; 106 | int in_ = 0; 107 | byte char_array_3[3]; 108 | byte char_array_4[4]; 109 | bytes ret; 110 | 111 | while (in_len-- && encoded_string[in_] != '=' && is_base64(encoded_string[in_])) 112 | { 113 | char_array_4[i++] = encoded_string[in_]; in_++; 114 | if (i == 4) 115 | { 116 | for (i = 0; i < 4; i++) 117 | char_array_4[i] = find_base64_char_index(char_array_4[i]); 118 | 119 | char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4); 120 | char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2); 121 | char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3]; 122 | 123 | for (i = 0; (i < 3); i++) 124 | ret.push_back(char_array_3[i]); 125 | i = 0; 126 | } 127 | } 128 | 129 | if (i) 130 | { 131 | for (j = i; j < 4; j++) 132 | char_array_4[j] = 0; 133 | 134 | for (j = 0; j < 4; j++) 135 | char_array_4[j] = find_base64_char_index(char_array_4[j]); 136 | 137 | char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4); 138 | char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2); 139 | char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3]; 140 | 141 | for (j = 0; j < i - 1; j++) 142 | ret.push_back(char_array_3[j]); 143 | } 144 | 145 | return ret; 146 | } 147 | -------------------------------------------------------------------------------- /libdevcore/Base64.h: -------------------------------------------------------------------------------- 1 | /* 2 | base64.cpp and base64.h 3 | 4 | Copyright (C) 2004-2008 René Nyffenegger 5 | 6 | This source code is provided 'as-is', without any express or implied 7 | warranty. In no event will the author be held liable for any damages 8 | arising from the use of this software. 9 | 10 | Permission is granted to anyone to use this software for any purpose, 11 | including commercial applications, and to alter it and redistribute it 12 | freely, subject to the following restrictions: 13 | 14 | 1. The origin of this source code must not be misrepresented; you must not 15 | claim that you wrote the original source code. If you use this source code 16 | in a product, an acknowledgment in the product documentation would be 17 | appreciated but is not required. 18 | 19 | 2. Altered source versions must be plainly marked as such, and must not be 20 | misrepresented as being the original source code. 21 | 22 | 3. This notice may not be removed or altered from any source distribution. 23 | 24 | René Nyffenegger rene.nyffenegger@adp-gmbh.ch 25 | */ 26 | /// Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c 27 | /// Originally by René Nyffenegger. 28 | /// DEVified by Gav Wood. 29 | #pragma once 30 | 31 | #include 32 | #include "Common.h" 33 | #include "FixedHash.h" 34 | 35 | namespace dev 36 | { 37 | 38 | std::string toBase64(bytesConstRef _in); 39 | bytes fromBase64(std::string const& _in); 40 | 41 | template inline std::string toBase36(FixedHash const& _h) 42 | { 43 | static char const* c_alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 44 | typename FixedHash::Arith a = _h; 45 | std::string ret; 46 | for (; a > 0; a /= 36) 47 | { 48 | unsigned r = (unsigned)(a - a / 36 * 36); // boost's % is broken 49 | ret = c_alphabet[r] + ret; 50 | } 51 | return ret; 52 | } 53 | 54 | template inline FixedHash fromBase36(std::string const& _h) 55 | { 56 | typename FixedHash::Arith ret = 0; 57 | for (char c: _h) 58 | ret = ret * 36 + (c < 'A' ? c - '0' : (c - 'A' + 10)); 59 | return ret; 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /libdevcore/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_policy(SET CMP0015 NEW) 2 | set(CMAKE_AUTOMOC OFF) 3 | 4 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSTATICLIB") 5 | 6 | aux_source_directory(. SRC_LIST) 7 | 8 | include_directories(BEFORE ${JSONCPP_INCLUDE_DIRS}) 9 | include_directories(BEFORE ..) 10 | include_directories(${Boost_INCLUDE_DIRS}) 11 | include_directories(${DB_INCLUDE_DIRS}) 12 | 13 | set(EXECUTABLE devcore) 14 | 15 | file(GLOB HEADERS "*.h") 16 | 17 | add_library(${EXECUTABLE} ${SRC_LIST} ${HEADERS}) 18 | 19 | target_link_libraries(${EXECUTABLE} ${Boost_THREAD_LIBRARIES}) 20 | target_link_libraries(${EXECUTABLE} ${Boost_RANDOM_LIBRARIES}) 21 | target_link_libraries(${EXECUTABLE} ${Boost_FILESYSTEM_LIBRARIES}) 22 | target_link_libraries(${EXECUTABLE} ${Boost_SYSTEM_LIBRARIES}) 23 | if (JSONRPC) 24 | target_link_libraries(${EXECUTABLE} ${JSONCPP_LIBRARIES}) 25 | endif() 26 | target_link_libraries(${EXECUTABLE} ${DB_LIBRARIES}) 27 | 28 | # transitive dependencies for windows executables 29 | if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") 30 | target_link_libraries(${EXECUTABLE} ${Boost_CHRONO_LIBRARIES}) 31 | target_link_libraries(${EXECUTABLE} ${Boost_DATE_TIME_LIBRARIES}) 32 | endif() 33 | 34 | if (APPLE) 35 | find_package(Threads REQUIRED) 36 | target_link_libraries(${EXECUTABLE} ${CMAKE_THREAD_LIBS_INIT}) 37 | elseif (UNIX) 38 | find_package(Threads REQUIRED) 39 | target_link_libraries(${EXECUTABLE} ${CMAKE_THREAD_LIBS_INIT}) 40 | endif() 41 | 42 | install( TARGETS ${EXECUTABLE} RUNTIME DESTINATION bin ARCHIVE DESTINATION lib LIBRARY DESTINATION lib ) 43 | install( FILES ${HEADERS} DESTINATION include/${EXECUTABLE} ) 44 | 45 | -------------------------------------------------------------------------------- /libdevcore/Common.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file Common.cpp 18 | * @author Gav Wood 19 | * @date 2014 20 | */ 21 | 22 | #include "Common.h" 23 | #include "Exceptions.h" 24 | #include "Log.h" 25 | #include "BuildInfo.h" 26 | using namespace std; 27 | using namespace dev; 28 | 29 | namespace dev 30 | { 31 | 32 | char const* Version = ETH_PROJECT_VERSION; 33 | 34 | const u256 UndefinedU256 = ~(u256)0; 35 | 36 | void InvariantChecker::checkInvariants(HasInvariants const* _this, char const* _fn, char const* _file, int _line, bool _pre) 37 | { 38 | if (!_this->invariants()) 39 | { 40 | cwarn << (_pre ? "Pre" : "Post") << "invariant failed in" << _fn << "at" << _file << ":" << _line; 41 | ::boost::exception_detail::throw_exception_(FailedInvariant(), _fn, _file, _line); 42 | } 43 | } 44 | 45 | struct TimerChannel: public LogChannel { static const char* name(); static const int verbosity = 0; }; 46 | 47 | #ifdef _WIN32 48 | const char* TimerChannel::name() { return EthRed " ! "; } 49 | #else 50 | const char* TimerChannel::name() { return EthRed " ⚡ "; } 51 | #endif 52 | 53 | TimerHelper::~TimerHelper() 54 | { 55 | auto e = std::chrono::high_resolution_clock::now() - m_t; 56 | if (!m_ms || e > chrono::milliseconds(m_ms)) 57 | { 58 | clog(TimerChannel) << m_id << chrono::duration_cast(e).count() << "ms"; 59 | } 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /libdevcore/CommonData.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file CommonData.cpp 18 | * @author Gav Wood 19 | * @date 2014 20 | */ 21 | 22 | #include "CommonData.h" 23 | #include 24 | #include 25 | #include "Exceptions.h" 26 | #include "Log.h" 27 | 28 | using namespace std; 29 | using namespace dev; 30 | 31 | std::string dev::escaped(std::string const& _s, bool _all) 32 | { 33 | static const map prettyEscapes{{'\r', 'r'}, {'\n', 'n'}, {'\t', 't'}, {'\v', 'v'}}; 34 | std::string ret; 35 | ret.reserve(_s.size() + 2); 36 | ret.push_back('"'); 37 | for (auto i: _s) 38 | if (i == '"' && !_all) 39 | ret += "\\\""; 40 | else if (i == '\\' && !_all) 41 | ret += "\\\\"; 42 | else if (prettyEscapes.count(i) && !_all) 43 | { 44 | ret += '\\'; 45 | ret += prettyEscapes.find(i)->second; 46 | } 47 | else if (i < ' ' || _all) 48 | { 49 | ret += "\\x"; 50 | ret.push_back("0123456789abcdef"[(uint8_t)i / 16]); 51 | ret.push_back("0123456789abcdef"[(uint8_t)i % 16]); 52 | } 53 | else 54 | ret.push_back(i); 55 | ret.push_back('"'); 56 | return ret; 57 | } 58 | 59 | std::string dev::randomWord() 60 | { 61 | static std::mt19937_64 s_eng(0); 62 | std::string ret(boost::random::uniform_int_distribution(1, 5)(s_eng), ' '); 63 | char const n[] = "qwertyuiop";//asdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890"; 64 | boost::random::uniform_int_distribution d(0, sizeof(n) - 2); 65 | for (char& c: ret) 66 | c = n[d(s_eng)]; 67 | return ret; 68 | } 69 | 70 | int dev::fromHex(char _i, WhenError _throw) 71 | { 72 | if (_i >= '0' && _i <= '9') 73 | return _i - '0'; 74 | if (_i >= 'a' && _i <= 'f') 75 | return _i - 'a' + 10; 76 | if (_i >= 'A' && _i <= 'F') 77 | return _i - 'A' + 10; 78 | if (_throw == WhenError::Throw) 79 | BOOST_THROW_EXCEPTION(BadHexCharacter() << errinfo_invalidSymbol(_i)); 80 | else 81 | return -1; 82 | } 83 | 84 | bytes dev::fromHex(std::string const& _s, WhenError _throw) 85 | { 86 | unsigned s = (_s[0] == '0' && _s[1] == 'x') ? 2 : 0; 87 | std::vector ret; 88 | ret.reserve((_s.size() - s + 1) / 2); 89 | 90 | if (_s.size() % 2) 91 | { 92 | int h = fromHex(_s[s++], WhenError::DontThrow); 93 | if (h != -1) 94 | ret.push_back(h); 95 | else if (_throw == WhenError::Throw) 96 | BOOST_THROW_EXCEPTION(BadHexCharacter()); 97 | else 98 | return bytes(); 99 | } 100 | for (unsigned i = s; i < _s.size(); i += 2) 101 | { 102 | int h = fromHex(_s[i], WhenError::DontThrow); 103 | int l = fromHex(_s[i + 1], WhenError::DontThrow); 104 | if (h != -1 && l != -1) 105 | ret.push_back((byte)(h * 16 + l)); 106 | else if (_throw == WhenError::Throw) 107 | BOOST_THROW_EXCEPTION(BadHexCharacter()); 108 | else 109 | return bytes(); 110 | } 111 | return ret; 112 | } 113 | 114 | bytes dev::asNibbles(bytesConstRef const& _s) 115 | { 116 | std::vector ret; 117 | ret.reserve(_s.size() * 2); 118 | for (auto i: _s) 119 | { 120 | ret.push_back(i / 16); 121 | ret.push_back(i % 16); 122 | } 123 | return ret; 124 | } 125 | 126 | std::string dev::toString(string32 const& _s) 127 | { 128 | std::string ret; 129 | for (unsigned i = 0; i < 32 && _s[i]; ++i) 130 | ret.push_back(_s[i]); 131 | return ret; 132 | } 133 | -------------------------------------------------------------------------------- /libdevcore/CommonJS.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file CommonJS.cpp 18 | * @authors: 19 | * Gav Wood 20 | * Marek Kotewicz 21 | * @date 2014 22 | */ 23 | 24 | #include "CommonJS.h" 25 | 26 | using namespace std; 27 | 28 | namespace dev 29 | { 30 | 31 | bytes jsToBytes(string const& _s) 32 | { 33 | if (_s.substr(0, 2) == "0x") 34 | // Hex 35 | return fromHex(_s.substr(2)); 36 | else if (_s.find_first_not_of("0123456789") == string::npos) 37 | // Decimal 38 | return toCompactBigEndian(bigint(_s)); 39 | else 40 | return bytes(); 41 | } 42 | 43 | bytes padded(bytes _b, unsigned _l) 44 | { 45 | while (_b.size() < _l) 46 | _b.insert(_b.begin(), 0); 47 | return asBytes(asString(_b).substr(_b.size() - max(_l, _l))); 48 | } 49 | 50 | bytes paddedRight(bytes _b, unsigned _l) 51 | { 52 | _b.resize(_l); 53 | return _b; 54 | } 55 | 56 | bytes unpadded(bytes _b) 57 | { 58 | auto p = asString(_b).find_last_not_of((char)0); 59 | _b.resize(p == string::npos ? 0 : (p + 1)); 60 | return _b; 61 | } 62 | 63 | bytes unpadLeft(bytes _b) 64 | { 65 | unsigned int i = 0; 66 | if (_b.size() == 0) 67 | return _b; 68 | 69 | while (i < _b.size() && _b[i] == byte(0)) 70 | i++; 71 | 72 | if (i != 0) 73 | _b.erase(_b.begin(), _b.begin() + i); 74 | return _b; 75 | } 76 | 77 | string fromRaw(h256 _n, unsigned* _inc) 78 | { 79 | if (_n) 80 | { 81 | string s((char const*)_n.data(), 32); 82 | auto l = s.find_first_of('\0'); 83 | if (!l) 84 | return ""; 85 | if (l != string::npos) 86 | { 87 | auto p = s.find_first_not_of('\0', l); 88 | if (!(p == string::npos || (_inc && p == 31))) 89 | return ""; 90 | if (_inc) 91 | *_inc = (byte)s[31]; 92 | s.resize(l); 93 | } 94 | for (auto i: s) 95 | if (i < 32) 96 | return ""; 97 | return s; 98 | } 99 | return ""; 100 | } 101 | 102 | } 103 | 104 | -------------------------------------------------------------------------------- /libdevcore/CommonJS.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file CommonJS.h 18 | * @authors: 19 | * Gav Wood 20 | * Marek Kotewicz 21 | * @date 2014 22 | */ 23 | 24 | #pragma once 25 | 26 | #include 27 | #include "FixedHash.h" 28 | #include "CommonData.h" 29 | #include "CommonIO.h" 30 | 31 | namespace dev 32 | { 33 | 34 | template std::string toJS(FixedHash const& _h) 35 | { 36 | return "0x" + toHex(_h.ref()); 37 | } 38 | 39 | template std::string toJS(boost::multiprecision::number> const& _n) 40 | { 41 | std::string h = toHex(toCompactBigEndian(_n, 1)); 42 | // remove first 0, if it is necessary; 43 | std::string res = h[0] != '0' ? h : h.substr(1); 44 | return "0x" + res; 45 | } 46 | 47 | inline std::string toJS(bytes const& _n, std::size_t _padding = 0) 48 | { 49 | bytes n = _n; 50 | n.resize(std::max(n.size(), _padding)); 51 | return "0x" + toHex(n); 52 | } 53 | 54 | template std::string toJS(SecureFixedHash const& _i) 55 | { 56 | std::stringstream stream; 57 | stream << "0x" << _i.makeInsecure().hex(); 58 | return stream.str(); 59 | } 60 | 61 | template std::string toJS(T const& _i) 62 | { 63 | std::stringstream stream; 64 | stream << "0x" << std::hex << _i; 65 | return stream.str(); 66 | } 67 | 68 | /// Convert string to byte array. Input parameters can be hex or dec. Returns empty array if invalid input e.g neither dec or hex. 69 | bytes jsToBytes(std::string const& _s); 70 | /// Add '0' on, or remove items from, the front of @a _b until it is of length @a _l. 71 | bytes padded(bytes _b, unsigned _l); 72 | /// Add '0' on, or remove items from, the back of @a _b until it is of length @a _l. 73 | bytes paddedRight(bytes _b, unsigned _l); 74 | /// Removing all trailing '0'. Returns empty array if input contains only '0' char. 75 | bytes unpadded(bytes _s); 76 | /// Remove all 0 byte on the head of @a _s. 77 | bytes unpadLeft(bytes _s); 78 | /// Convert h256 into user-readable string (by directly using std::string constructor). 79 | std::string fromRaw(h256 _n, unsigned* _inc = nullptr); 80 | 81 | template FixedHash jsToFixed(std::string const& _s) 82 | { 83 | if (_s.substr(0, 2) == "0x") 84 | // Hex 85 | return FixedHash(_s.substr(2 + std::max(N * 2, _s.size() - 2) - N * 2)); 86 | else if (_s.find_first_not_of("0123456789") == std::string::npos) 87 | // Decimal 88 | return (typename FixedHash::Arith)(_s); 89 | else 90 | // Binary 91 | return FixedHash(); // FAIL 92 | } 93 | 94 | inline std::string jsToFixed(double _s) 95 | { 96 | return toJS(u256(_s * (double)(u256(1) << 128))); 97 | } 98 | 99 | template boost::multiprecision::number> jsToInt(std::string const& _s) 100 | { 101 | if (_s.substr(0, 2) == "0x") 102 | // Hex 103 | return fromBigEndian>>(fromHex(_s.substr(2))); 104 | else if (_s.find_first_not_of("0123456789") == std::string::npos) 105 | // Decimal 106 | return boost::multiprecision::number>(_s); 107 | else 108 | // Binary 109 | return 0; // FAIL 110 | } 111 | 112 | inline u256 jsToU256(std::string const& _s) { return jsToInt<32>(_s); } 113 | 114 | inline int jsToInt(std::string const& _s) 115 | { 116 | return std::stoi(_s, nullptr, 0); 117 | } 118 | 119 | inline std::string jsToDecimal(std::string const& _s) 120 | { 121 | return toString(jsToU256(_s)); 122 | } 123 | 124 | } 125 | -------------------------------------------------------------------------------- /libdevcore/Diff.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file Diff.h 18 | * @author Gav Wood 19 | * @date 2014 20 | */ 21 | 22 | #pragma once 23 | 24 | namespace dev 25 | { 26 | 27 | enum class ExistDiff 28 | { 29 | Same, 30 | New, 31 | Dead 32 | }; 33 | 34 | template 35 | class Diff 36 | { 37 | public: 38 | Diff() {} 39 | Diff(T _from, T _to): m_from(_from), m_to(_to) {} 40 | 41 | T const& from() const { return m_from; } 42 | T const& to() const { return m_to; } 43 | 44 | explicit operator bool() const { return m_from != m_to; } 45 | 46 | private: 47 | T m_from; 48 | T m_to; 49 | }; 50 | 51 | } 52 | 53 | -------------------------------------------------------------------------------- /libdevcore/Exceptions.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file Exceptions.h 18 | * @author Gav Wood 19 | * @date 2014 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include "CommonData.h" 29 | #include "FixedHash.h" 30 | 31 | namespace dev 32 | { 33 | 34 | /// Base class for all exceptions. 35 | struct Exception: virtual std::exception, virtual boost::exception 36 | { 37 | Exception(std::string _message = std::string()): m_message(std::move(_message)) {} 38 | const char* what() const noexcept override { return m_message.empty() ? std::exception::what() : m_message.c_str(); } 39 | 40 | private: 41 | std::string m_message; 42 | }; 43 | 44 | #define DEV_SIMPLE_EXCEPTION(X) struct X: virtual Exception { const char* what() const noexcept override { return #X; } } 45 | 46 | /// Base class for all RLP exceptions. 47 | struct RLPException: virtual Exception { RLPException(std::string _message = std::string()): Exception(_message) {} }; 48 | #define DEV_SIMPLE_EXCEPTION_RLP(X) struct X: virtual RLPException { const char* what() const noexcept override { return #X; } } 49 | 50 | DEV_SIMPLE_EXCEPTION_RLP(BadCast); 51 | DEV_SIMPLE_EXCEPTION_RLP(BadRLP); 52 | DEV_SIMPLE_EXCEPTION_RLP(OversizeRLP); 53 | DEV_SIMPLE_EXCEPTION_RLP(UndersizeRLP); 54 | 55 | DEV_SIMPLE_EXCEPTION(BadHexCharacter); 56 | DEV_SIMPLE_EXCEPTION(NoNetworking); 57 | DEV_SIMPLE_EXCEPTION(NoUPnPDevice); 58 | DEV_SIMPLE_EXCEPTION(RootNotFound); 59 | struct BadRoot: virtual Exception { public: BadRoot(h256 const& _root): Exception("BadRoot " + _root.hex()), root(_root) {} h256 root; }; 60 | DEV_SIMPLE_EXCEPTION(FileError); 61 | DEV_SIMPLE_EXCEPTION(Overflow); 62 | DEV_SIMPLE_EXCEPTION(FailedInvariant); 63 | DEV_SIMPLE_EXCEPTION(ValueTooLarge); 64 | 65 | struct InterfaceNotSupported: virtual Exception { public: InterfaceNotSupported(std::string _f): Exception("Interface " + _f + " not supported.") {} }; 66 | struct ExternalFunctionFailure: virtual Exception { public: ExternalFunctionFailure(std::string _f): Exception("Function " + _f + "() failed.") {} }; 67 | 68 | // error information to be added to exceptions 69 | using errinfo_invalidSymbol = boost::error_info; 70 | using errinfo_wrongAddress = boost::error_info; 71 | using errinfo_comment = boost::error_info; 72 | using errinfo_required = boost::error_info; 73 | using errinfo_got = boost::error_info; 74 | using errinfo_min = boost::error_info; 75 | using errinfo_max = boost::error_info; 76 | using RequirementError = boost::tuple; 77 | using errinfo_hash256 = boost::error_info; 78 | using errinfo_required_h256 = boost::error_info; 79 | using errinfo_got_h256 = boost::error_info; 80 | using Hash256RequirementError = boost::tuple; 81 | using errinfo_extraData = boost::error_info; 82 | 83 | } 84 | -------------------------------------------------------------------------------- /libdevcore/FileSystem.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file FileSystem.cpp 18 | * @authors 19 | * Eric Lombrozo 20 | * Gav Wood 21 | * @date 2014 22 | */ 23 | 24 | #include "FileSystem.h" 25 | #include "Common.h" 26 | #include "Log.h" 27 | 28 | #if defined(_WIN32) 29 | #include 30 | #else 31 | #include 32 | #include 33 | #include 34 | #include 35 | #endif 36 | #include 37 | using namespace std; 38 | using namespace dev; 39 | 40 | std::string dev::getDataDir(std::string _prefix) 41 | { 42 | if (_prefix.empty()) 43 | _prefix = "ethereum"; 44 | #ifdef _WIN32 45 | _prefix[0] = toupper(_prefix[0]); 46 | char path[1024] = ""; 47 | if (SHGetSpecialFolderPathA(NULL, path, CSIDL_APPDATA, true)) 48 | return (boost::filesystem::path(path) / _prefix).string(); 49 | else 50 | { 51 | #ifndef _MSC_VER // todo? 52 | cwarn << "getDataDir(): SHGetSpecialFolderPathA() failed."; 53 | #endif 54 | BOOST_THROW_EXCEPTION(std::runtime_error("getDataDir() - SHGetSpecialFolderPathA() failed.")); 55 | } 56 | #else 57 | boost::filesystem::path dataDirPath; 58 | char const* homeDir = getenv("HOME"); 59 | if (!homeDir || strlen(homeDir) == 0) 60 | { 61 | struct passwd* pwd = getpwuid(getuid()); 62 | if (pwd) 63 | homeDir = pwd->pw_dir; 64 | } 65 | 66 | if (!homeDir || strlen(homeDir) == 0) 67 | dataDirPath = boost::filesystem::path("/"); 68 | else 69 | dataDirPath = boost::filesystem::path(homeDir); 70 | 71 | return (dataDirPath / ("." + _prefix)).string(); 72 | #endif 73 | } 74 | -------------------------------------------------------------------------------- /libdevcore/FileSystem.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file FileSystem.h 18 | * @authors 19 | * Eric Lombrozo 20 | * Gav Wood 21 | * @date 2014 22 | */ 23 | 24 | #pragma once 25 | 26 | #include 27 | #include 28 | 29 | namespace dev 30 | { 31 | 32 | /// @returns the path for user data. 33 | std::string getDataDir(std::string _prefix = "ethereum"); 34 | 35 | } 36 | -------------------------------------------------------------------------------- /libdevcore/FixedHash.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file FixedHash.cpp 18 | * @author Gav Wood 19 | * @date 2014 20 | */ 21 | 22 | #include "FixedHash.h" 23 | #include 24 | #include 25 | 26 | using namespace std; 27 | using namespace dev; 28 | 29 | boost::random_device dev::s_fixedHashEngine; 30 | 31 | h128 dev::fromUUID(std::string const& _uuid) 32 | { 33 | try 34 | { 35 | return h128(boost::replace_all_copy(_uuid, "-", "")); 36 | } 37 | catch (...) 38 | { 39 | return h128(); 40 | } 41 | } 42 | 43 | std::string dev::toUUID(h128 const& _uuid) 44 | { 45 | std::string ret = toHex(_uuid.ref()); 46 | for (unsigned i: {20, 16, 12, 8}) 47 | ret.insert(ret.begin() + i, '-'); 48 | return ret; 49 | } 50 | 51 | -------------------------------------------------------------------------------- /libdevcore/Guards.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file Guards.cpp 18 | * @author Gav Wood 19 | * @date 2014 20 | */ 21 | 22 | #include "Guards.h" 23 | using namespace std; 24 | using namespace dev; 25 | 26 | namespace dev 27 | { 28 | 29 | } 30 | -------------------------------------------------------------------------------- /libdevcore/Hash.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file Hash.h 18 | * @author Gav Wood 19 | * @date 2014 20 | * 21 | * The FixedHash fixed-size "hash" container type. 22 | */ 23 | 24 | #pragma once 25 | 26 | #include 27 | #include 28 | #include 29 | #include "SHA3.h" 30 | 31 | namespace dev 32 | { 33 | 34 | h256 sha256(bytesConstRef _input); 35 | 36 | h160 ripemd160(bytesConstRef _input); 37 | 38 | } 39 | -------------------------------------------------------------------------------- /libdevcore/MemoryDB.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file MemoryDB.h 18 | * @author Gav Wood 19 | * @date 2014 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include "SHA3.h" 31 | 32 | namespace dev 33 | { 34 | 35 | struct DBChannel: public LogChannel { static const char* name(); static const int verbosity = 18; }; 36 | struct DBWarn: public LogChannel { static const char* name(); static const int verbosity = 1; }; 37 | 38 | #define dbdebug clog(DBChannel) 39 | #define dbwarn clog(DBWarn) 40 | 41 | class MemoryDB 42 | { 43 | friend class EnforceRefs; 44 | 45 | public: 46 | MemoryDB() {} 47 | MemoryDB(MemoryDB const& _c) { operator=(_c); } 48 | 49 | MemoryDB& operator=(MemoryDB const& _c); 50 | 51 | void clear() { m_main.clear(); } // WARNING !!!! didn't originally clear m_refCount!!! 52 | std::unordered_map get() const; 53 | 54 | std::string lookup(h256 const& _h) const; 55 | bool exists(h256 const& _h) const; 56 | void insert(h256 const& _h, bytesConstRef _v); 57 | bool kill(h256 const& _h); 58 | void purge(); 59 | 60 | bytes lookupAux(h256 const& _h) const; 61 | void removeAux(h256 const& _h); 62 | void insertAux(h256 const& _h, bytesConstRef _v); 63 | 64 | h256Hash keys() const; 65 | 66 | protected: 67 | #if DEV_GUARDED_DB 68 | mutable SharedMutex x_this; 69 | #endif 70 | std::unordered_map> m_main; 71 | std::unordered_map> m_aux; 72 | 73 | mutable bool m_enforceRefs = false; 74 | }; 75 | 76 | class EnforceRefs 77 | { 78 | public: 79 | EnforceRefs(MemoryDB const& _o, bool _r): m_o(_o), m_r(_o.m_enforceRefs) { _o.m_enforceRefs = _r; } 80 | ~EnforceRefs() { m_o.m_enforceRefs = m_r; } 81 | 82 | private: 83 | MemoryDB const& m_o; 84 | bool m_r; 85 | }; 86 | 87 | inline std::ostream& operator<<(std::ostream& _out, MemoryDB const& _m) 88 | { 89 | for (auto const& i: _m.get()) 90 | { 91 | _out << i.first << ": "; 92 | _out << RLP(i.second); 93 | _out << " " << toHex(i.second); 94 | _out << std::endl; 95 | } 96 | return _out; 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /libdevcore/RangeMask.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file RangeMask.cpp 18 | * @author Gav Wood 19 | * @date 2014 20 | */ 21 | 22 | #include "RangeMask.h" 23 | -------------------------------------------------------------------------------- /libdevcore/SHA3.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file SHA3.h 18 | * @author Gav Wood 19 | * @date 2014 20 | * 21 | * The FixedHash fixed-size "hash" container type. 22 | */ 23 | 24 | #pragma once 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | namespace dev 31 | { 32 | 33 | // SHA-3 convenience routines. 34 | 35 | /// Calculate SHA3-256 hash of the given input and load it into the given output. 36 | /// @returns false if o_output.size() != 32. 37 | bool sha3(bytesConstRef _input, bytesRef o_output); 38 | 39 | /// Calculate SHA3-256 hash of the given input, returning as a 256-bit hash. 40 | inline h256 sha3(bytesConstRef _input) { h256 ret; sha3(_input, ret.ref()); return ret; } 41 | inline SecureFixedHash<32> sha3Secure(bytesConstRef _input) { SecureFixedHash<32> ret; sha3(_input, ret.writable().ref()); return ret; } 42 | 43 | /// Calculate SHA3-256 hash of the given input, returning as a 256-bit hash. 44 | inline h256 sha3(bytes const& _input) { return sha3(bytesConstRef(&_input)); } 45 | inline SecureFixedHash<32> sha3Secure(bytes const& _input) { return sha3Secure(bytesConstRef(&_input)); } 46 | 47 | /// Calculate SHA3-256 hash of the given input (presented as a binary-filled string), returning as a 256-bit hash. 48 | inline h256 sha3(std::string const& _input) { return sha3(bytesConstRef(_input)); } 49 | inline SecureFixedHash<32> sha3Secure(std::string const& _input) { return sha3Secure(bytesConstRef(_input)); } 50 | 51 | /// Calculate SHA3-256 hash of the given input (presented as a FixedHash), returns a 256-bit hash. 52 | template inline h256 sha3(FixedHash const& _input) { return sha3(_input.ref()); } 53 | template inline SecureFixedHash<32> sha3Secure(FixedHash const& _input) { return sha3Secure(_input.ref()); } 54 | 55 | /// Fully secure variants are equivalent for sha3 and sha3Secure. 56 | inline SecureFixedHash<32> sha3(bytesSec const& _input) { return sha3Secure(_input.ref()); } 57 | inline SecureFixedHash<32> sha3Secure(bytesSec const& _input) { return sha3Secure(_input.ref()); } 58 | template inline SecureFixedHash<32> sha3(SecureFixedHash const& _input) { return sha3Secure(_input.ref()); } 59 | template inline SecureFixedHash<32> sha3Secure(SecureFixedHash const& _input) { return sha3Secure(_input.ref()); } 60 | 61 | /// Calculate SHA3-256 hash of the given input, possibly interpreting it as nibbles, and return the hash as a string filled with binary data. 62 | inline std::string sha3(std::string const& _input, bool _isNibbles) { return asString((_isNibbles ? sha3(fromHex(_input)) : sha3(bytesConstRef(&_input))).asBytes()); } 63 | 64 | /// Calculate SHA3-256 MAC 65 | inline void sha3mac(bytesConstRef _secret, bytesConstRef _plain, bytesRef _output) { sha3(_secret.toBytes() + _plain.toBytes()).ref().populate(_output); } 66 | 67 | extern h256 EmptySHA3; 68 | 69 | extern h256 EmptyListSHA3; 70 | 71 | } 72 | -------------------------------------------------------------------------------- /libdevcore/StructuredLogger.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file StructuredLogger.h 18 | * @author Lefteris Karapetsas 19 | * @date 2015 20 | * 21 | * A simple helper class for the structured logging 22 | * The spec for the implemented log events is here: 23 | * https://github.com/ethereum/system-testing/wiki/Log-Events 24 | */ 25 | 26 | #pragma once 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | namespace Json { class Value; } 33 | namespace boost { namespace asio { namespace ip { templateclass basic_endpoint; class tcp; }}} 34 | namespace bi = boost::asio::ip; 35 | 36 | namespace dev 37 | { 38 | 39 | // TODO: Make the output stream configurable. stdout, stderr, file e.t.c. 40 | class StructuredLogger 41 | { 42 | public: 43 | /** 44 | * Initializes the structured logger object 45 | * @param _enabled Whether logging is on or off 46 | * @param _timeFormat A time format string as described here: 47 | * http://en.cppreference.com/w/cpp/chrono/c/strftime 48 | * with which to display timestamps 49 | */ 50 | void initialize(bool _enabled, std::string const& _timeFormat, std::string const& _destinationURL = ""); 51 | 52 | static StructuredLogger& get() 53 | { 54 | static StructuredLogger instance; 55 | return instance; 56 | } 57 | 58 | static void starting(std::string const& _clientImpl, const char* _ethVersion); 59 | static void stopping(std::string const& _clientImpl, const char* _ethVersion); 60 | static void p2pConnected( 61 | std::string const& _id, 62 | bi::basic_endpoint const& _addr, 63 | std::chrono::system_clock::time_point const& _ts, 64 | std::string const& _remoteVersion, 65 | unsigned int _numConnections 66 | ); 67 | static void p2pDisconnected( 68 | std::string const& _id, 69 | bi::basic_endpoint const& _addr, 70 | unsigned int _numConnections 71 | ); 72 | static void minedNewBlock( 73 | std::string const& _hash, 74 | std::string const& _blockNumber, 75 | std::string const& _chainHeadHash, 76 | std::string const& _prevHash 77 | ); 78 | static void chainReceivedNewBlock( 79 | std::string const& _hash, 80 | std::string const& _blockNumber, 81 | std::string const& _chainHeadHash, 82 | std::string const& _remoteID, 83 | std::string const& _prevHash 84 | ); 85 | static void chainNewHead( 86 | std::string const& _hash, 87 | std::string const& _blockNumber, 88 | std::string const& _chainHeadHash, 89 | std::string const& _prevHash 90 | ); 91 | static void transactionReceived(std::string const& _hash, std::string const& _remoteId); 92 | // TODO: static void pendingQueueChanged(std::vector const& _hashes); 93 | // TODO: static void miningStarted(); 94 | // TODO: static void stillMining(unsigned _hashrate); 95 | // TODO: static void miningStopped(); 96 | 97 | private: 98 | // Singleton class. Private default ctor and no copying 99 | StructuredLogger() = default; 100 | StructuredLogger(StructuredLogger const&) = delete; 101 | void operator=(StructuredLogger const&) = delete; 102 | 103 | void outputJson(Json::Value const& _value, std::string const& _name) const; 104 | 105 | bool m_enabled = false; 106 | std::string m_timeFormat = "%Y-%m-%dT%H:%M:%S"; 107 | 108 | mutable std::ofstream m_out; 109 | }; 110 | 111 | } 112 | -------------------------------------------------------------------------------- /libdevcore/TransientDirectory.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file TransientDirectory.cpp 18 | * @author Marek Kotewicz 19 | * @date 2015 20 | */ 21 | 22 | #include 23 | #include 24 | #include "Exceptions.h" 25 | #include "TransientDirectory.h" 26 | #include "CommonIO.h" 27 | #include "Log.h" 28 | using namespace std; 29 | using namespace dev; 30 | namespace fs = boost::filesystem; 31 | 32 | TransientDirectory::TransientDirectory(): 33 | TransientDirectory((boost::filesystem::temp_directory_path() / "eth_transient" / toString(FixedHash<4>::random())).string()) 34 | {} 35 | 36 | TransientDirectory::TransientDirectory(std::string const& _path): 37 | m_path(_path) 38 | { 39 | // we never ever want to delete a directory (including all its contents) that we did not create ourselves. 40 | if (boost::filesystem::exists(m_path)) 41 | BOOST_THROW_EXCEPTION(FileError()); 42 | 43 | fs::create_directories(m_path); 44 | DEV_IGNORE_EXCEPTIONS(fs::permissions(m_path, fs::owner_all)); 45 | } 46 | 47 | TransientDirectory::~TransientDirectory() 48 | { 49 | boost::system::error_code ec; 50 | fs::remove_all(m_path, ec); 51 | if (!ec) 52 | return; 53 | 54 | // In some cases, antivirus runnig on Windows will scan all the newly created directories. 55 | // As a consequence, directory is locked and can not be deleted immediately. 56 | // Retry after 10 milliseconds usually is successful. 57 | // This will help our tests run smoothly in such environment. 58 | this_thread::sleep_for(chrono::milliseconds(10)); 59 | 60 | ec.clear(); 61 | fs::remove_all(m_path, ec); 62 | if (!ec) 63 | { 64 | cwarn << "Failed to delete directory '" << m_path << "': " << ec.message(); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /libdevcore/TransientDirectory.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file TransientDirectory.h 18 | * @author Marek Kotewicz 19 | * @date 2015 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | 26 | namespace dev 27 | { 28 | 29 | /** 30 | * @brief temporary directory implementation 31 | * It creates temporary directory in the given path. On dealloc it removes the directory 32 | * @throws if the given path already exists, throws an exception 33 | */ 34 | class TransientDirectory 35 | { 36 | public: 37 | TransientDirectory(); 38 | TransientDirectory(std::string const& _path); 39 | ~TransientDirectory(); 40 | 41 | std::string const& path() const { return m_path; } 42 | 43 | private: 44 | std::string m_path; 45 | }; 46 | 47 | } 48 | -------------------------------------------------------------------------------- /libdevcore/TrieCommon.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file TrieCommon.cpp 18 | * @author Gav Wood 19 | * @date 2014 20 | */ 21 | 22 | #include "TrieCommon.h" 23 | 24 | namespace dev 25 | { 26 | 27 | /* 28 | * Hex-prefix Notation. First nibble has flags: oddness = 2^0 & termination = 2^1 29 | * NOTE: the "termination marker" and "leaf-node" specifier are completely equivalent. 30 | * [0,0,1,2,3,4,5] 0x10012345 31 | * [0,1,2,3,4,5] 0x00012345 32 | * [1,2,3,4,5] 0x112345 33 | * [0,0,1,2,3,4] 0x00001234 34 | * [0,1,2,3,4] 0x101234 35 | * [1,2,3,4] 0x001234 36 | * [0,0,1,2,3,4,5,T] 0x30012345 37 | * [0,0,1,2,3,4,T] 0x20001234 38 | * [0,1,2,3,4,5,T] 0x20012345 39 | * [1,2,3,4,5,T] 0x312345 40 | * [1,2,3,4,T] 0x201234 41 | */ 42 | 43 | std::string hexPrefixEncode(bytes const& _hexVector, bool _leaf, int _begin, int _end) 44 | { 45 | unsigned begin = _begin; 46 | unsigned end = _end < 0 ? _hexVector.size() + 1 + _end : _end; 47 | bool odd = ((end - begin) % 2) != 0; 48 | 49 | std::string ret(1, ((_leaf ? 2 : 0) | (odd ? 1 : 0)) * 16); 50 | if (odd) 51 | { 52 | ret[0] |= _hexVector[begin]; 53 | ++begin; 54 | } 55 | for (unsigned i = begin; i < end; i += 2) 56 | ret += _hexVector[i] * 16 + _hexVector[i + 1]; 57 | return ret; 58 | } 59 | 60 | std::string hexPrefixEncode(bytesConstRef _data, bool _leaf, int _beginNibble, int _endNibble, unsigned _offset) 61 | { 62 | unsigned begin = _beginNibble + _offset; 63 | unsigned end = (_endNibble < 0 ? ((int)(_data.size() * 2 - _offset) + 1) + _endNibble : _endNibble) + _offset; 64 | bool odd = (end - begin) & 1; 65 | 66 | std::string ret(1, ((_leaf ? 2 : 0) | (odd ? 1 : 0)) * 16); 67 | ret.reserve((end - begin) / 2 + 1); 68 | 69 | unsigned d = odd ? 1 : 2; 70 | for (auto i = begin; i < end; ++i, ++d) 71 | { 72 | byte n = nibble(_data, i); 73 | if (d & 1) // odd 74 | ret.back() |= n; // or the nibble onto the back 75 | else 76 | ret.push_back(n << 4); // push the nibble on to the back << 4 77 | } 78 | return ret; 79 | } 80 | 81 | std::string hexPrefixEncode(bytesConstRef _d1, unsigned _o1, bytesConstRef _d2, unsigned _o2, bool _leaf) 82 | { 83 | unsigned begin1 = _o1; 84 | unsigned end1 = _d1.size() * 2; 85 | unsigned begin2 = _o2; 86 | unsigned end2 = _d2.size() * 2; 87 | 88 | bool odd = (end1 - begin1 + end2 - begin2) & 1; 89 | 90 | std::string ret(1, ((_leaf ? 2 : 0) | (odd ? 1 : 0)) * 16); 91 | ret.reserve((end1 - begin1 + end2 - begin2) / 2 + 1); 92 | 93 | unsigned d = odd ? 1 : 2; 94 | for (auto i = begin1; i < end1; ++i, ++d) 95 | { 96 | byte n = nibble(_d1, i); 97 | if (d & 1) // odd 98 | ret.back() |= n; // or the nibble onto the back 99 | else 100 | ret.push_back(n << 4); // push the nibble on to the back << 4 101 | } 102 | for (auto i = begin2; i < end2; ++i, ++d) 103 | { 104 | byte n = nibble(_d2, i); 105 | if (d & 1) // odd 106 | ret.back() |= n; // or the nibble onto the back 107 | else 108 | ret.push_back(n << 4); // push the nibble on to the back << 4 109 | } 110 | return ret; 111 | } 112 | 113 | byte uniqueInUse(RLP const& _orig, byte except) 114 | { 115 | byte used = 255; 116 | for (unsigned i = 0; i < 17; ++i) 117 | if (i != except && !_orig[i].isEmpty()) 118 | { 119 | if (used == 255) 120 | used = (byte)i; 121 | else 122 | return 255; 123 | } 124 | return used; 125 | } 126 | 127 | } 128 | -------------------------------------------------------------------------------- /libdevcore/TrieDB.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file TrieDB.cpp 18 | * @author Gav Wood 19 | * @date 2014 20 | */ 21 | 22 | #include 23 | #include "TrieDB.h" 24 | using namespace std; 25 | using namespace dev; 26 | 27 | h256 const dev::c_shaNull = sha3(rlp("")); 28 | h256 const dev::EmptyTrie = sha3(rlp("")); 29 | 30 | const char* TrieDBChannel::name() { return "-T-"; } 31 | -------------------------------------------------------------------------------- /libdevcore/TrieHash.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file TrieHash.h 18 | * @author Gav Wood 19 | * @date 2014 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | 27 | namespace dev 28 | { 29 | 30 | bytes rlp256(BytesMap const& _s); 31 | h256 hash256(BytesMap const& _s); 32 | 33 | h256 orderedTrieRoot(std::vector const& _data); 34 | 35 | template inline h256 trieRootOver(unsigned _itemCount, T const& _getKey, U const& _getValue) 36 | { 37 | BytesMap m; 38 | for (unsigned i = 0; i < _itemCount; ++i) 39 | m[_getKey(i)] = _getValue(i); 40 | return hash256(m); 41 | } 42 | 43 | h256 orderedTrieRoot(std::vector const& _data); 44 | h256 orderedTrieRoot(std::vector const& _data); 45 | 46 | } 47 | -------------------------------------------------------------------------------- /libdevcore/UndefMacros.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file UndefMacros.h 18 | * @author Lefteris 19 | * @date 2015 20 | * 21 | * This header should be used to #undef some really evil macros defined by 22 | * windows.h which result in conflict with our libsolidity/Token.h 23 | */ 24 | #pragma once 25 | 26 | #if defined(_MSC_VER) || defined(__MINGW32__) 27 | 28 | #undef DELETE 29 | #undef IN 30 | #undef VOID 31 | #undef THIS 32 | #undef CONST 33 | 34 | // Conflicting define on MinGW in windows.h 35 | // windows.h(19): #define interface struct 36 | #ifdef interface 37 | #undef interface 38 | #endif 39 | 40 | #elif defined(DELETE) || defined(IN) || defined(VOID) || defined(THIS) || defined(CONST) || defined(interface) 41 | 42 | #error "The preceding macros in this header file are reserved for V8's "\ 43 | "TOKEN_LIST. Please add a platform specific define above to undefine "\ 44 | "overlapping macros." 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /libdevcore/Worker.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file Worker.cpp 18 | * @author Gav Wood 19 | * @date 2014 20 | */ 21 | 22 | #include "Worker.h" 23 | 24 | #include 25 | #include 26 | #include "Log.h" 27 | using namespace std; 28 | using namespace dev; 29 | 30 | void Worker::startWorking() 31 | { 32 | // cnote << "startWorking for thread" << m_name; 33 | Guard l(x_work); 34 | if (m_work) 35 | { 36 | WorkerState ex = WorkerState::Stopped; 37 | m_state.compare_exchange_strong(ex, WorkerState::Starting); 38 | } 39 | else 40 | { 41 | m_state = WorkerState::Starting; 42 | m_work.reset(new thread([&]() 43 | { 44 | setThreadName(m_name.c_str()); 45 | // cnote << "Thread begins"; 46 | while (m_state != WorkerState::Killing) 47 | { 48 | WorkerState ex = WorkerState::Starting; 49 | bool ok = m_state.compare_exchange_strong(ex, WorkerState::Started); 50 | // cnote << "Trying to set Started: Thread was" << (unsigned)ex << "; " << ok; 51 | (void)ok; 52 | 53 | try 54 | { 55 | startedWorking(); 56 | workLoop(); 57 | doneWorking(); 58 | } 59 | catch (std::exception const& _e) 60 | { 61 | clog(WarnChannel) << "Exception thrown in Worker thread: " << _e.what(); 62 | } 63 | 64 | // ex = WorkerState::Stopping; 65 | // m_state.compare_exchange_strong(ex, WorkerState::Stopped); 66 | 67 | ex = m_state.exchange(WorkerState::Stopped); 68 | // cnote << "State: Stopped: Thread was" << (unsigned)ex; 69 | if (ex == WorkerState::Killing || ex == WorkerState::Starting) 70 | m_state.exchange(ex); 71 | 72 | // cnote << "Waiting until not Stopped..."; 73 | DEV_TIMED_ABOVE("Worker stopping", 100) 74 | while (m_state == WorkerState::Stopped) 75 | this_thread::sleep_for(chrono::milliseconds(20)); 76 | } 77 | })); 78 | // cnote << "Spawning" << m_name; 79 | } 80 | DEV_TIMED_ABOVE("Start worker", 100) 81 | while (m_state == WorkerState::Starting) 82 | this_thread::sleep_for(chrono::microseconds(20)); 83 | } 84 | 85 | void Worker::stopWorking() 86 | { 87 | DEV_GUARDED(x_work) 88 | if (m_work) 89 | { 90 | WorkerState ex = WorkerState::Started; 91 | m_state.compare_exchange_strong(ex, WorkerState::Stopping); 92 | 93 | DEV_TIMED_ABOVE("Stop worker", 100) 94 | while (m_state != WorkerState::Stopped) 95 | this_thread::sleep_for(chrono::microseconds(20)); 96 | } 97 | } 98 | 99 | void Worker::terminate() 100 | { 101 | // cnote << "stopWorking for thread" << m_name; 102 | DEV_GUARDED(x_work) 103 | if (m_work) 104 | { 105 | m_state.exchange(WorkerState::Killing); 106 | 107 | DEV_TIMED_ABOVE("Terminate worker", 100) 108 | m_work->join(); 109 | 110 | m_work.reset(); 111 | } 112 | } 113 | 114 | void Worker::workLoop() 115 | { 116 | while (m_state == WorkerState::Started) 117 | { 118 | if (m_idleWaitMs) 119 | this_thread::sleep_for(chrono::milliseconds(m_idleWaitMs)); 120 | doWork(); 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /libdevcore/Worker.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file Worker.h 18 | * @author Gav Wood 19 | * @date 2014 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | #include 27 | #include "Guards.h" 28 | 29 | namespace dev 30 | { 31 | 32 | enum class IfRunning 33 | { 34 | Fail, 35 | Join, 36 | Detach 37 | }; 38 | 39 | enum class WorkerState 40 | { 41 | Starting, 42 | Started, 43 | Stopping, 44 | Stopped, 45 | Killing 46 | }; 47 | 48 | class Worker 49 | { 50 | protected: 51 | Worker(std::string const& _name = "anon", unsigned _idleWaitMs = 30): m_name(_name), m_idleWaitMs(_idleWaitMs) {} 52 | 53 | /// Move-constructor. 54 | Worker(Worker&& _m) { std::swap(m_name, _m.m_name); } 55 | 56 | /// Move-assignment. 57 | Worker& operator=(Worker&& _m) 58 | { 59 | assert(&_m != this); 60 | std::swap(m_name, _m.m_name); 61 | return *this; 62 | } 63 | 64 | virtual ~Worker() { terminate(); } 65 | 66 | /// Allows changing worker name if work is stopped. 67 | void setName(std::string _n) { if (!isWorking()) m_name = _n; } 68 | 69 | /// Starts worker thread; causes startedWorking() to be called. 70 | void startWorking(); 71 | 72 | /// Stop worker thread; causes call to stopWorking(). 73 | void stopWorking(); 74 | 75 | /// Returns if worker thread is present. 76 | bool isWorking() const { Guard l(x_work); return m_state == WorkerState::Started; } 77 | 78 | /// Called after thread is started from startWorking(). 79 | virtual void startedWorking() {} 80 | 81 | /// Called continuously following sleep for m_idleWaitMs. 82 | virtual void doWork() {} 83 | 84 | /// Overrides doWork(); should call shouldStop() often and exit when true. 85 | virtual void workLoop(); 86 | bool shouldStop() const { return m_state != WorkerState::Started; } 87 | 88 | /// Called when is to be stopped, just prior to thread being joined. 89 | virtual void doneWorking() {} 90 | 91 | /// Blocks caller into worker thread has finished. 92 | // void join() const { Guard l(x_work); try { if (m_work) m_work->join(); } catch (...) {} } 93 | 94 | private: 95 | /// Stop and never start again. 96 | void terminate(); 97 | 98 | std::string m_name; 99 | 100 | unsigned m_idleWaitMs = 0; 101 | 102 | mutable Mutex x_work; ///< Lock for the network existance. 103 | std::unique_ptr m_work; ///< The network thread. 104 | std::atomic m_state = {WorkerState::Starting}; 105 | }; 106 | 107 | } 108 | -------------------------------------------------------------------------------- /libdevcore/concurrent_queue.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | #pragma once 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | 24 | namespace dev 25 | { 26 | 27 | /// Concurrent queue. 28 | /// You can push and pop elements to/from the queue. Pop will block until the queue is not empty. 29 | /// The default backend (_QueueT) is std::queue. It can be changed to any type that has 30 | /// proper push(), pop(), empty() and front() methods. 31 | template> 32 | class concurrent_queue 33 | { 34 | public: 35 | template 36 | void push(_U&& _elem) 37 | { 38 | { 39 | std::lock_guard guard{x_mutex}; 40 | m_queue.push(std::forward<_U>(_elem)); 41 | } 42 | m_cv.notify_one(); 43 | } 44 | 45 | _T pop() 46 | { 47 | std::unique_lock lock{x_mutex}; 48 | m_cv.wait(lock, [this]{ return !m_queue.empty(); }); 49 | auto item = std::move(m_queue.front()); 50 | m_queue.pop(); 51 | return item; 52 | } 53 | 54 | private: 55 | _QueueT m_queue; 56 | std::mutex x_mutex; 57 | std::condition_variable m_cv; 58 | }; 59 | 60 | } 61 | -------------------------------------------------------------------------------- /libdevcore/db.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file DB.h 18 | * @author Gav Wood 19 | * @date 2014 20 | */ 21 | 22 | #pragma once 23 | 24 | #pragma warning(push) 25 | #pragma warning(disable: 4100 4267) 26 | #include 27 | #include 28 | namespace ldb = leveldb; 29 | #pragma warning(pop) 30 | #define DEV_LDB 1 31 | -------------------------------------------------------------------------------- /libdevcore/debugbreak.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2013, Scott Tsai 2 | * 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef DEBUG_BREAK_H 28 | #define DEBUG_BREAK_H 29 | 30 | #if defined(_MSC_VER) || defined(__MINGW32__) 31 | 32 | #define debug_break __debugbreak 33 | 34 | #else 35 | 36 | #include 37 | #include 38 | #include 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | enum { 45 | /* gcc optimizers consider code after __builtin_trap() dead. 46 | * Making __builtin_trap() unsuitable for breaking into the debugger */ 47 | DEBUG_BREAK_PREFER_BUILTIN_TRAP_TO_SIGTRAP = 0, 48 | }; 49 | 50 | #if defined(__i386__) || defined(__x86_64__) 51 | enum { HAVE_TRAP_INSTRUCTION = 1, }; 52 | __attribute__((gnu_inline, always_inline)) 53 | static void __inline__ trap_instruction(void) 54 | { 55 | __asm__ volatile("int $0x03"); 56 | } 57 | #elif defined(__thumb__) 58 | enum { HAVE_TRAP_INSTRUCTION = 1, }; 59 | /* FIXME: handle __THUMB_INTERWORK__ */ 60 | __attribute__((gnu_inline, always_inline)) 61 | static void __inline__ trap_instruction(void) 62 | { 63 | /* See 'arm-linux-tdep.c' in GDB source. 64 | * Both instruction sequences below works. */ 65 | #if 1 66 | /* 'eabi_linux_thumb_le_breakpoint' */ 67 | __asm__ volatile(".inst 0xde01"); 68 | #else 69 | /* 'eabi_linux_thumb2_le_breakpoint' */ 70 | __asm__ volatile(".inst.w 0xf7f0a000"); 71 | #endif 72 | 73 | /* Known problem: 74 | * After a breakpoint hit, can't stepi, step, or continue in GDB. 75 | * 'step' stuck on the same instruction. 76 | * 77 | * Workaround: a new GDB command, 78 | * 'debugbreak-step' is defined in debugbreak-gdb.py 79 | * that does: 80 | * (gdb) set $instruction_len = 2 81 | * (gdb) tbreak *($pc + $instruction_len) 82 | * (gdb) jump *($pc + $instruction_len) 83 | */ 84 | } 85 | #elif defined(__arm__) && !defined(__thumb__) 86 | enum { HAVE_TRAP_INSTRUCTION = 1, }; 87 | __attribute__((gnu_inline, always_inline)) 88 | static void __inline__ trap_instruction(void) 89 | { 90 | /* See 'arm-linux-tdep.c' in GDB source, 91 | * 'eabi_linux_arm_le_breakpoint' */ 92 | __asm__ volatile(".inst 0xe7f001f0"); 93 | /* Has same known problem and workaround 94 | * as Thumb mode */ 95 | } 96 | #else 97 | enum { HAVE_TRAP_INSTRUCTION = 0, }; 98 | #endif 99 | 100 | __attribute__((gnu_inline, always_inline)) 101 | static void __inline__ debug_break(void) 102 | { 103 | if (HAVE_TRAP_INSTRUCTION) { 104 | trap_instruction(); 105 | } else if (DEBUG_BREAK_PREFER_BUILTIN_TRAP_TO_SIGTRAP) { 106 | /* raises SIGILL on Linux x86{,-64}, to continue in gdb: 107 | * (gdb) handle SIGILL stop nopass 108 | * */ 109 | __builtin_trap(); 110 | } else { 111 | raise(SIGTRAP); 112 | } 113 | } 114 | 115 | #ifdef __cplusplus 116 | } 117 | #endif 118 | 119 | #endif 120 | 121 | #endif 122 | -------------------------------------------------------------------------------- /libethash-cl/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(EXECUTABLE ethash-cl) 2 | 3 | # A custom command and target to turn the OpenCL kernel into a byte array header 4 | # The normal build depends on it properly and if the kernel file is changed, then 5 | # a rebuild of libethash-cl should be triggered 6 | add_custom_command( 7 | OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ethash_cl_miner_kernel.h 8 | COMMAND ${CMAKE_COMMAND} ARGS 9 | -DBIN2H_SOURCE_FILE="${CMAKE_CURRENT_SOURCE_DIR}/ethash_cl_miner_kernel.cl" 10 | -DBIN2H_VARIABLE_NAME=ethash_cl_miner_kernel 11 | -DBIN2H_HEADER_FILE="${CMAKE_CURRENT_BINARY_DIR}/ethash_cl_miner_kernel.h" 12 | -P "${CMAKE_CURRENT_SOURCE_DIR}/bin2h.cmake" 13 | COMMENT "Generating OpenCL Kernel Byte Array" 14 | DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/ethash_cl_miner_kernel.cl 15 | ) 16 | add_custom_target(clbin2h DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/ethash_cl_miner_kernel.h ${CMAKE_CURRENT_SOURCE_DIR}/ethash_cl_miner_kernel.cl) 17 | 18 | aux_source_directory(. SRC_LIST) 19 | file(GLOB OUR_HEADERS "*.h") 20 | set(HEADERS ${OUR_HEADERS} ${CMAKE_CURRENT_BINARY_DIR}/ethash_cl_miner_kernel.h) 21 | 22 | include_directories(${CMAKE_CURRENT_BINARY_DIR}) 23 | include_directories(${Boost_INCLUDE_DIRS}) 24 | include_directories(..) 25 | add_library(${EXECUTABLE} ${SRC_LIST} ${HEADERS}) 26 | target_include_directories(${EXECUTABLE} PUBLIC ${OpenCL_INCLUDE_DIR}) 27 | target_link_libraries(${EXECUTABLE} ${OpenCL_LIBRARIES} ethash) 28 | 29 | install( TARGETS ${EXECUTABLE} RUNTIME DESTINATION bin ARCHIVE DESTINATION lib LIBRARY DESTINATION lib ) 30 | install( FILES ${HEADERS} DESTINATION include/${EXECUTABLE} ) 31 | -------------------------------------------------------------------------------- /libethash-cl/bin2h.cmake: -------------------------------------------------------------------------------- 1 | # https://gist.github.com/sivachandran/3a0de157dccef822a230 2 | include(CMakeParseArguments) 3 | 4 | # Function to wrap a given string into multiple lines at the given column position. 5 | # Parameters: 6 | # VARIABLE - The name of the CMake variable holding the string. 7 | # AT_COLUMN - The column position at which string will be wrapped. 8 | function(WRAP_STRING) 9 | set(oneValueArgs VARIABLE AT_COLUMN) 10 | cmake_parse_arguments(WRAP_STRING "${options}" "${oneValueArgs}" "" ${ARGN}) 11 | 12 | string(LENGTH ${${WRAP_STRING_VARIABLE}} stringLength) 13 | math(EXPR offset "0") 14 | 15 | while(stringLength GREATER 0) 16 | 17 | if(stringLength GREATER ${WRAP_STRING_AT_COLUMN}) 18 | math(EXPR length "${WRAP_STRING_AT_COLUMN}") 19 | else() 20 | math(EXPR length "${stringLength}") 21 | endif() 22 | 23 | string(SUBSTRING ${${WRAP_STRING_VARIABLE}} ${offset} ${length} line) 24 | set(lines "${lines}\n${line}") 25 | 26 | math(EXPR stringLength "${stringLength} - ${length}") 27 | math(EXPR offset "${offset} + ${length}") 28 | endwhile() 29 | 30 | set(${WRAP_STRING_VARIABLE} "${lines}" PARENT_SCOPE) 31 | endfunction() 32 | 33 | # Script to embed contents of a file as byte array in C/C++ header file(.h). The header file 34 | # will contain a byte array and integer variable holding the size of the array. 35 | # Parameters 36 | # SOURCE_FILE - The path of source file whose contents will be embedded in the header file. 37 | # VARIABLE_NAME - The name of the variable for the byte array. The string "_SIZE" will be append 38 | # to this name and will be used a variable name for size variable. 39 | # HEADER_FILE - The path of header file. 40 | # APPEND - If specified appends to the header file instead of overwriting it 41 | # NULL_TERMINATE - If specified a null byte(zero) will be append to the byte array. This will be 42 | # useful if the source file is a text file and we want to use the file contents 43 | # as string. But the size variable holds size of the byte array without this 44 | # null byte. 45 | set(options APPEND NULL_TERMINATE) 46 | set(oneValueArgs SOURCE_FILE VARIABLE_NAME HEADER_FILE) 47 | # cmake_parse_arguments(BIN2H "${options}" "${oneValueArgs}" "" ${ARGN}) 48 | 49 | # reads source file contents as hex string 50 | file(READ ${BIN2H_SOURCE_FILE} hexString HEX) 51 | string(LENGTH ${hexString} hexStringLength) 52 | 53 | # appends null byte if asked 54 | if(BIN2H_NULL_TERMINATE) 55 | set(hexString "${hexString}00") 56 | endif() 57 | 58 | # wraps the hex string into multiple lines at column 32(i.e. 16 bytes per line) 59 | wrap_string(VARIABLE hexString AT_COLUMN 32) 60 | math(EXPR arraySize "${hexStringLength} / 2") 61 | 62 | # adds '0x' prefix and comma suffix before and after every byte respectively 63 | string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1, " arrayValues ${hexString}) 64 | # removes trailing comma 65 | string(REGEX REPLACE ", $" "" arrayValues ${arrayValues}) 66 | 67 | # converts the variable name into proper C identifier 68 | IF (${CMAKE_VERSION} GREATER 2.8.10) # fix for legacy cmake 69 | string(MAKE_C_IDENTIFIER "${BIN2H_VARIABLE_NAME}" BIN2H_VARIABLE_NAME) 70 | ENDIF() 71 | string(TOUPPER "${BIN2H_VARIABLE_NAME}" BIN2H_VARIABLE_NAME) 72 | 73 | # declares byte array and the length variables 74 | set(arrayDefinition "const unsigned char ${BIN2H_VARIABLE_NAME}[] = { ${arrayValues} };") 75 | set(arraySizeDefinition "const size_t ${BIN2H_VARIABLE_NAME}_SIZE = ${arraySize};") 76 | 77 | set(declarations "${arrayDefinition}\n\n${arraySizeDefinition}\n\n") 78 | if(BIN2H_APPEND) 79 | file(APPEND ${BIN2H_HEADER_FILE} "${declarations}") 80 | else() 81 | file(WRITE ${BIN2H_HEADER_FILE} "${declarations}") 82 | endif() 83 | -------------------------------------------------------------------------------- /libethash-cl/ethash_cl_miner.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define __CL_ENABLE_EXCEPTIONS 4 | #define CL_USE_DEPRECATED_OPENCL_2_0_APIS 5 | 6 | #if defined(__clang__) 7 | #pragma clang diagnostic push 8 | #pragma clang diagnostic ignored "-Wunused-parameter" 9 | #include "CL/cl.hpp" 10 | #pragma clang diagnostic pop 11 | #else 12 | #include "CL/cl.hpp" 13 | #endif 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | class ethash_cl_miner 20 | { 21 | private: 22 | enum { c_maxSearchResults = 63, c_bufferCount = 2, c_hashBatchSize = 1024 }; 23 | 24 | public: 25 | struct search_hook 26 | { 27 | virtual ~search_hook(); // always a virtual destructor for a class with virtuals. 28 | 29 | // reports progress, return true to abort 30 | virtual bool found(uint64_t const* nonces, uint32_t count) = 0; 31 | virtual bool searched(uint64_t start_nonce, uint32_t count) = 0; 32 | }; 33 | 34 | ethash_cl_miner(); 35 | ~ethash_cl_miner(); 36 | 37 | static bool searchForAllDevices(unsigned _platformId, std::function _callback); 38 | static bool searchForAllDevices(std::function _callback); 39 | static void doForAllDevices(unsigned _platformId, std::function _callback); 40 | static void doForAllDevices(std::function _callback); 41 | static unsigned getNumPlatforms(); 42 | static unsigned getNumDevices(unsigned _platformId = 0); 43 | static std::string platform_info(unsigned _platformId = 0, unsigned _deviceId = 0); 44 | static void listDevices(); 45 | static bool configureGPU( 46 | unsigned _platformId, 47 | unsigned _localWorkSize, 48 | unsigned _globalWorkSize, 49 | bool _allowCPU, 50 | unsigned _extraGPUMemory, 51 | uint64_t _currentBlock 52 | ); 53 | 54 | bool init( 55 | ethash_light_t _light, 56 | uint8_t const* _lightData, 57 | uint64_t _lightSize, 58 | unsigned _platformId, 59 | unsigned _deviceId 60 | ); 61 | void finish(); 62 | void search(uint8_t const* _header, uint64_t _target, search_hook& _hook, bool _ethStratum, uint64_t _startN); 63 | 64 | /* -- default values -- */ 65 | /// Default value of the local work size. Also known as workgroup size. 66 | static unsigned const c_defaultLocalWorkSize; 67 | /// Default value of the global work size as a multiplier of the local work size 68 | static unsigned const c_defaultGlobalWorkSizeMultiplier; 69 | 70 | private: 71 | 72 | static std::vector getDevices(std::vector const& _platforms, unsigned _platformId); 73 | static std::vector getPlatforms(); 74 | 75 | cl::Context m_context; 76 | cl::CommandQueue m_queue; 77 | cl::Kernel m_searchKernel; 78 | cl::Kernel m_dagKernel; 79 | cl::Buffer m_dag; 80 | cl::Buffer m_light; 81 | cl::Buffer m_header; 82 | cl::Buffer m_searchBuffer[c_bufferCount]; 83 | unsigned m_globalWorkSize; 84 | bool m_openclOnePointOne; 85 | 86 | /// The local work size for the search 87 | static unsigned s_workgroupSize; 88 | /// The initial global work size for the searches 89 | static unsigned s_initialGlobalWorkSize; 90 | /// The target milliseconds per batch for the search. If 0, then no adjustment will happen 91 | static unsigned s_msPerBatch; 92 | /// Allow CPU to appear as an OpenCL device or not. Default is false 93 | static bool s_allowCPU; 94 | /// GPU memory required for other things, like window rendering e.t.c. 95 | /// User can set it via the --cl-extragpu-mem argument. 96 | static unsigned s_extraRequiredGPUMem; 97 | }; 98 | -------------------------------------------------------------------------------- /libethash-cuda/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(EXECUTABLE ethash-cuda) 2 | 3 | FIND_PACKAGE(CUDA REQUIRED) 4 | 5 | file(GLOB SRC_LIST "*.cpp" "*.cu") 6 | file(GLOB HEADERS "*.h" "*.cuh") 7 | 8 | set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS};--std=c++11;--disable-warnings;--ptxas-options=-v;-use_fast_math;-lineinfo) 9 | 10 | LIST(APPEND CUDA_NVCC_FLAGS_RELEASE -O3) 11 | LIST(APPEND CUDA_NVCC_FLAGS_DEBUG -G) 12 | 13 | if(COMPUTE AND (COMPUTE GREATER 0)) 14 | LIST(APPEND CUDA_NVCC_FLAGS -gencode arch=compute_${COMPUTE},code=sm_${COMPUTE}) 15 | else(COMPUTE AND (COMPUTE GREATER 0)) 16 | set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS};-gencode arch=compute_20,code=sm_20;-gencode arch=compute_30,code=sm_30;-gencode arch=compute_35,code=sm_35;-gencode arch=compute_50,code=sm_50;-gencode arch=compute_52,code=sm_52;-gencode arch=compute_61,code=sm_61) 17 | endif(COMPUTE AND (COMPUTE GREATER 0)) 18 | 19 | 20 | 21 | include_directories(${CMAKE_CURRENT_BINARY_DIR}) 22 | include_directories(${CUDA_INCLUDE_DIRS}) 23 | include_directories(..) 24 | CUDA_ADD_LIBRARY(${EXECUTABLE} STATIC ${SRC_LIST} ${HEADERS}) 25 | TARGET_LINK_LIBRARIES(${EXECUTABLE} ${CUDA_LIBRARIES} ethash) 26 | 27 | install( TARGETS ${EXECUTABLE} RUNTIME DESTINATION bin ARCHIVE DESTINATION lib LIBRARY DESTINATION lib ) 28 | install( FILES ${HEADERS} DESTINATION include/${EXECUTABLE} ) 29 | -------------------------------------------------------------------------------- /libethash-cuda/cuda_helper.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Genoil/cpp-ethereum/07344156ffe35cc5949817f3d0660fb57bb18cdc/libethash-cuda/cuda_helper.h -------------------------------------------------------------------------------- /libethash-cuda/dagger_shared.cuh: -------------------------------------------------------------------------------- 1 | #include "ethash_cuda_miner_kernel_globals.h" 2 | #include "ethash_cuda_miner_kernel.h" 3 | 4 | typedef union { 5 | uint4 uint4s[4]; 6 | uint64_t ulongs[8]; 7 | uint32_t uints[16]; 8 | } compute_hash_share; 9 | 10 | 11 | __device__ uint64_t compute_hash( 12 | uint64_t nonce 13 | ) 14 | { 15 | // sha3_512(header .. nonce) 16 | uint64_t state[25]; 17 | state[4] = nonce; 18 | keccak_f1600_init(state); 19 | 20 | // Threads work together in this phase in groups of 8. 21 | const int thread_id = threadIdx.x & (THREADS_PER_HASH - 1); 22 | const int hash_id = threadIdx.x >> 3; 23 | 24 | extern __shared__ compute_hash_share share[]; 25 | 26 | for (int i = 0; i < THREADS_PER_HASH; i++) 27 | { 28 | // share init with other threads 29 | if (i == thread_id) 30 | copy(share[hash_id].ulongs, state, 8); 31 | 32 | __syncthreads(); 33 | 34 | uint4 mix = share[hash_id].uint4s[thread_id & 3]; 35 | __syncthreads(); 36 | 37 | uint32_t *share0 = share[hash_id].uints; 38 | 39 | // share init0 40 | if (thread_id == 0) 41 | *share0 = mix.x; 42 | __syncthreads(); 43 | uint32_t init0 = *share0; 44 | 45 | for (uint32_t a = 0; a < ACCESSES; a += 4) 46 | { 47 | int t = bfe(a, 2u, 3u); 48 | 49 | for (uint32_t b = 0; b < 4; b++) 50 | { 51 | if (thread_id == t) { 52 | *share0 = fnv(init0 ^ (a + b), ((uint32_t *)&mix)[b]) % d_dag_size; 53 | } 54 | __syncthreads(); 55 | 56 | mix = fnv4(mix, d_dag[*share0].uint4s[thread_id]); 57 | } 58 | } 59 | 60 | share[hash_id].uints[thread_id] = fnv_reduce(mix); 61 | __syncthreads(); 62 | 63 | if (i == thread_id) 64 | copy(state + 8, share[hash_id].ulongs, 4); 65 | 66 | __syncthreads(); 67 | } 68 | 69 | // keccak_256(keccak_512(header..nonce) .. mix); 70 | return keccak_f1600_final(state); 71 | } -------------------------------------------------------------------------------- /libethash-cuda/dagger_shuffled.cuh: -------------------------------------------------------------------------------- 1 | #include "ethash_cuda_miner_kernel_globals.h" 2 | #include "ethash_cuda_miner_kernel.h" 3 | #include "cuda_helper.h" 4 | 5 | __device__ uint64_t compute_hash( 6 | uint64_t nonce 7 | ) 8 | { 9 | // sha3_512(header .. nonce) 10 | uint2 state[25]; 11 | 12 | state[4] = vectorize(nonce); 13 | 14 | keccak_f1600_init(state); 15 | 16 | // Threads work together in this phase in groups of 8. 17 | const int thread_id = threadIdx.x & (THREADS_PER_HASH - 1); 18 | const int mix_idx = thread_id & 3; 19 | 20 | uint4 mix; 21 | uint2 shuffle[8]; 22 | 23 | for (int i = 0; i < THREADS_PER_HASH; i++) 24 | { 25 | // share init among threads 26 | for (int j = 0; j < 8; j++) { 27 | shuffle[j].x = __shfl(state[j].x, i, THREADS_PER_HASH); 28 | shuffle[j].y = __shfl(state[j].y, i, THREADS_PER_HASH); 29 | } 30 | 31 | // ugly but avoids local reads/writes 32 | if (mix_idx < 2) { 33 | if (mix_idx == 0) 34 | mix = vectorize2(shuffle[0], shuffle[1]); 35 | else 36 | mix = vectorize2(shuffle[2], shuffle[3]); 37 | } 38 | else { 39 | if (mix_idx == 2) 40 | mix = vectorize2(shuffle[4], shuffle[5]); 41 | else 42 | mix = vectorize2(shuffle[6], shuffle[7]); 43 | } 44 | 45 | uint32_t init0 = __shfl(shuffle[0].x, 0, THREADS_PER_HASH); 46 | 47 | for (uint32_t a = 0; a < ACCESSES; a += 4) 48 | { 49 | int t = bfe(a, 2u, 3u); 50 | 51 | for (uint32_t b = 0; b < 4; b++) 52 | { 53 | if (thread_id == t) 54 | { 55 | shuffle[0].x = fnv(init0 ^ (a + b), ((uint32_t *)&mix)[b]) % d_dag_size; 56 | } 57 | shuffle[0].x = __shfl(shuffle[0].x, t, THREADS_PER_HASH); 58 | mix = fnv4(mix, d_dag[shuffle[0].x].uint4s[thread_id]); 59 | } 60 | } 61 | 62 | uint32_t thread_mix = fnv_reduce(mix); 63 | 64 | // update mix accross threads 65 | 66 | shuffle[0].x = __shfl(thread_mix, 0, THREADS_PER_HASH); 67 | shuffle[0].y = __shfl(thread_mix, 1, THREADS_PER_HASH); 68 | shuffle[1].x = __shfl(thread_mix, 2, THREADS_PER_HASH); 69 | shuffle[1].y = __shfl(thread_mix, 3, THREADS_PER_HASH); 70 | shuffle[2].x = __shfl(thread_mix, 4, THREADS_PER_HASH); 71 | shuffle[2].y = __shfl(thread_mix, 5, THREADS_PER_HASH); 72 | shuffle[3].x = __shfl(thread_mix, 6, THREADS_PER_HASH); 73 | shuffle[3].y = __shfl(thread_mix, 7, THREADS_PER_HASH); 74 | 75 | if (i == thread_id) { 76 | //move mix into state: 77 | state[8] = shuffle[0]; 78 | state[9] = shuffle[1]; 79 | state[10] = shuffle[2]; 80 | state[11] = shuffle[3]; 81 | } 82 | } 83 | 84 | // keccak_256(keccak_512(header..nonce) .. mix); 85 | return keccak_f1600_final(state); 86 | } -------------------------------------------------------------------------------- /libethash-cuda/ethash_cuda_miner.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | //#include 4 | 5 | #include 6 | #include 7 | #include 8 | #include "ethash_cuda_miner_kernel.h" 9 | 10 | class ethash_cuda_miner 11 | { 12 | public: 13 | struct search_hook 14 | { 15 | virtual ~search_hook(); // always a virtual destructor for a class with virtuals. 16 | 17 | // reports progress, return true to abort 18 | virtual bool found(uint64_t const* nonces, uint32_t count) = 0; 19 | virtual bool searched(uint64_t start_nonce, uint32_t count) = 0; 20 | }; 21 | 22 | public: 23 | ethash_cuda_miner(); 24 | 25 | static std::string platform_info(unsigned _deviceId = 0); 26 | static unsigned getNumDevices(); 27 | static void listDevices(); 28 | static bool configureGPU( 29 | int * _devices, 30 | unsigned _blockSize, 31 | unsigned _gridSize, 32 | unsigned _numStreams, 33 | unsigned _extraGPUMemory, 34 | unsigned _scheduleFlag, 35 | uint64_t _currentBlock 36 | ); 37 | 38 | bool init(ethash_light_t _light, uint8_t const* _lightData, uint64_t _lightSize, unsigned _deviceId, bool _cpyToHost, volatile void** hostDAG); 39 | 40 | void finish(); 41 | void search(uint8_t const* header, uint64_t target, search_hook& hook, bool _ethStratum, uint64_t _startN); 42 | 43 | /* -- default values -- */ 44 | /// Default value of the block size. Also known as workgroup size. 45 | static unsigned const c_defaultBlockSize; 46 | /// Default value of the grid size 47 | static unsigned const c_defaultGridSize; 48 | // default number of CUDA streams 49 | static unsigned const c_defaultNumStreams; 50 | 51 | private: 52 | hash32_t m_current_header; 53 | uint64_t m_current_target; 54 | uint64_t m_current_nonce; 55 | uint64_t m_starting_nonce; 56 | uint64_t m_current_index; 57 | 58 | uint32_t m_sharedBytes; 59 | 60 | volatile uint32_t ** m_search_buf; 61 | cudaStream_t * m_streams; 62 | 63 | /// The local work size for the search 64 | static unsigned s_blockSize; 65 | /// The initial global work size for the searches 66 | static unsigned s_gridSize; 67 | /// The number of CUDA streams 68 | static unsigned s_numStreams; 69 | /// CUDA schedule flag 70 | static unsigned s_scheduleFlag; 71 | 72 | /// GPU memory required for other things, like window rendering e.t.c. 73 | /// User can set it via the --cl-extragpu-mem argument. 74 | static unsigned s_extraRequiredGPUMem; 75 | }; -------------------------------------------------------------------------------- /libethash-cuda/ethash_cuda_miner_kernel.h: -------------------------------------------------------------------------------- 1 | #ifndef _ETHASH_CUDA_MINER_KERNEL_H_ 2 | #define _ETHASH_CUDA_MINER_KERNEL_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #define SEARCH_RESULT_BUFFER_SIZE 64 9 | #define ACCESSES 64 10 | #define THREADS_PER_HASH (128 / 16) 11 | 12 | typedef struct 13 | { 14 | uint4 uint4s[32 / sizeof(uint4)]; 15 | } hash32_t; 16 | 17 | typedef struct 18 | { 19 | uint4 uint4s[128 / sizeof(uint4)]; 20 | } hash128_t; 21 | 22 | typedef union { 23 | uint32_t words[64 / sizeof(uint32_t)]; 24 | uint2 uint2s[64 / sizeof(uint2)]; 25 | uint4 uint4s[64 / sizeof(uint4)]; 26 | } hash64_t; 27 | 28 | typedef union { 29 | uint32_t words[200 / sizeof(uint32_t)]; 30 | uint2 uint2s[200 / sizeof(uint2)]; 31 | uint4 uint4s[200 / sizeof(uint4)]; 32 | } hash200_t; 33 | 34 | void set_constants( 35 | hash128_t* _dag, 36 | uint32_t _dag_size, 37 | hash64_t * _light, 38 | uint32_t _light_size 39 | ); 40 | 41 | void set_header( 42 | hash32_t _header 43 | ); 44 | 45 | void set_target( 46 | uint64_t _target 47 | ); 48 | 49 | void run_ethash_search( 50 | uint32_t search_batch_size, 51 | uint32_t workgroup_size, 52 | uint32_t sharedbytes, 53 | cudaStream_t stream, 54 | volatile uint32_t* g_output, 55 | uint64_t start_nonce 56 | ); 57 | 58 | void ethash_generate_dag( 59 | uint64_t dag_size, 60 | uint32_t blocks, 61 | uint32_t threads, 62 | cudaStream_t stream, 63 | int device 64 | ); 65 | 66 | 67 | #define CUDA_SAFE_CALL(call) \ 68 | do { \ 69 | cudaError_t err = call; \ 70 | if (cudaSuccess != err) { \ 71 | const char * errorString = cudaGetErrorString(err); \ 72 | fprintf(stderr, \ 73 | "CUDA error in func '%s' at line %i : %s.\n", \ 74 | __FUNCTION__, __LINE__, errorString); \ 75 | throw std::runtime_error(errorString); \ 76 | } \ 77 | } while (0) 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /libethash-cuda/ethash_cuda_miner_kernel_globals.h: -------------------------------------------------------------------------------- 1 | #ifndef _ETHASH_CUDA_MINER_KERNEL_GLOBALS_H_ 2 | #define _ETHASH_CUDA_MINER_KERNEL_GLOBALS_H_ 3 | 4 | #define SHUFFLE_MIN_VER 300 5 | 6 | //#include "cuda_helper.h" 7 | 8 | __constant__ uint32_t d_dag_size; 9 | __constant__ hash128_t* d_dag; 10 | __constant__ uint32_t d_light_size; 11 | __constant__ hash64_t* d_light; 12 | __constant__ hash32_t d_header; 13 | __constant__ uint64_t d_target; 14 | 15 | #endif -------------------------------------------------------------------------------- /libethash-cuda/fnv.cuh: -------------------------------------------------------------------------------- 1 | 2 | #define FNV_PRIME 0x01000193 3 | 4 | #define fnv(x,y) ((x) * FNV_PRIME ^(y)) 5 | 6 | __device__ uint4 fnv4(uint4 a, uint4 b) 7 | { 8 | uint4 c; 9 | c.x = a.x * FNV_PRIME ^ b.x; 10 | c.y = a.y * FNV_PRIME ^ b.y; 11 | c.z = a.z * FNV_PRIME ^ b.z; 12 | c.w = a.w * FNV_PRIME ^ b.w; 13 | return c; 14 | } 15 | 16 | __device__ uint32_t fnv_reduce(uint4 v) 17 | { 18 | return fnv(fnv(fnv(v.x, v.y), v.z), v.w); 19 | } 20 | 21 | -------------------------------------------------------------------------------- /libethash/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LIBRARY ethash) 2 | 3 | if (CPPETHEREUM) 4 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") 5 | endif () 6 | 7 | set(CMAKE_BUILD_TYPE Release) 8 | 9 | if (NOT MSVC) 10 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99") 11 | endif() 12 | 13 | set(FILES util.h 14 | io.c 15 | internal.c 16 | ethash.h 17 | endian.h 18 | compiler.h 19 | fnv.h 20 | data_sizes.h) 21 | 22 | if (MSVC) 23 | list(APPEND FILES util_win32.c io_win32.c mmap_win32.c) 24 | else() 25 | list(APPEND FILES io_posix.c) 26 | endif() 27 | 28 | if (NOT CRYPTOPP_FOUND) 29 | find_package(CryptoPP 5.6.2) 30 | endif() 31 | 32 | if (CRYPTOPP_FOUND) 33 | add_definitions(-DWITH_CRYPTOPP) 34 | include_directories( ${CRYPTOPP_INCLUDE_DIRS} ) 35 | list(APPEND FILES sha3_cryptopp.cpp sha3_cryptopp.h) 36 | else() 37 | list(APPEND FILES sha3.c sha3.h) 38 | endif() 39 | 40 | add_library(${LIBRARY} ${FILES}) 41 | 42 | if (CRYPTOPP_FOUND) 43 | TARGET_LINK_LIBRARIES(${LIBRARY} ${CRYPTOPP_LIBRARIES}) 44 | endif() 45 | 46 | install( TARGETS ${LIBRARY} RUNTIME DESTINATION bin ARCHIVE DESTINATION lib LIBRARY DESTINATION lib ) 47 | -------------------------------------------------------------------------------- /libethash/compiler.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file compiler.h 18 | * @date 2014 19 | */ 20 | #pragma once 21 | 22 | // Visual Studio doesn't support the inline keyword in C mode 23 | #if defined(_MSC_VER) && !defined(__cplusplus) 24 | #define inline __inline 25 | #endif 26 | 27 | // pretend restrict is a standard keyword 28 | #if defined(_MSC_VER) 29 | #define restrict __restrict 30 | #else 31 | #define restrict __restrict__ 32 | #endif 33 | 34 | -------------------------------------------------------------------------------- /libethash/endian.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "compiler.h" 5 | 6 | #if defined(__MINGW32__) || defined(_WIN32) 7 | # define LITTLE_ENDIAN 1234 8 | # define BYTE_ORDER LITTLE_ENDIAN 9 | #elif defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__) 10 | # include 11 | #elif defined(__OpenBSD__) || defined(__SVR4) 12 | # include 13 | #elif defined(__APPLE__) 14 | # include 15 | #elif defined( BSD ) && (BSD >= 199103) 16 | # include 17 | #elif defined( __QNXNTO__ ) && defined( __LITTLEENDIAN__ ) 18 | # define LITTLE_ENDIAN 1234 19 | # define BYTE_ORDER LITTLE_ENDIAN 20 | #elif defined( __QNXNTO__ ) && defined( __BIGENDIAN__ ) 21 | # define BIG_ENDIAN 1234 22 | # define BYTE_ORDER BIG_ENDIAN 23 | #else 24 | # include 25 | #endif 26 | 27 | #if defined(_WIN32) 28 | #include 29 | #define ethash_swap_u32(input_) _byteswap_ulong(input_) 30 | #define ethash_swap_u64(input_) _byteswap_uint64(input_) 31 | #elif defined(__APPLE__) 32 | #include 33 | #define ethash_swap_u32(input_) OSSwapInt32(input_) 34 | #define ethash_swap_u64(input_) OSSwapInt64(input_) 35 | #elif defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__) 36 | #define ethash_swap_u32(input_) bswap32(input_) 37 | #define ethash_swap_u64(input_) bswap64(input_) 38 | #else // posix 39 | #include 40 | #define ethash_swap_u32(input_) __bswap_32(input_) 41 | #define ethash_swap_u64(input_) __bswap_64(input_) 42 | #endif 43 | 44 | 45 | #if LITTLE_ENDIAN == BYTE_ORDER 46 | 47 | #define fix_endian32(dst_ ,src_) dst_ = src_ 48 | #define fix_endian32_same(val_) 49 | #define fix_endian64(dst_, src_) dst_ = src_ 50 | #define fix_endian64_same(val_) 51 | #define fix_endian_arr32(arr_, size_) 52 | #define fix_endian_arr64(arr_, size_) 53 | 54 | #elif BIG_ENDIAN == BYTE_ORDER 55 | 56 | #define fix_endian32(dst_, src_) dst_ = ethash_swap_u32(src_) 57 | #define fix_endian32_same(val_) val_ = ethash_swap_u32(val_) 58 | #define fix_endian64(dst_, src_) dst_ = ethash_swap_u64(src_ 59 | #define fix_endian64_same(val_) val_ = ethash_swap_u64(val_) 60 | #define fix_endian_arr32(arr_, size_) \ 61 | do { \ 62 | for (unsigned i_ = 0; i_ < (size_), ++i_) { \ 63 | arr_[i_] = ethash_swap_u32(arr_[i_]); \ 64 | } \ 65 | while (0) 66 | #define fix_endian_arr64(arr_, size_) \ 67 | do { \ 68 | for (unsigned i_ = 0; i_ < (size_), ++i_) { \ 69 | arr_[i_] = ethash_swap_u64(arr_[i_]); \ 70 | } \ 71 | while (0) \ 72 | 73 | #else 74 | # error "endian not supported" 75 | #endif // BYTE_ORDER 76 | -------------------------------------------------------------------------------- /libethash/fnv.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file fnv.h 18 | * @author Matthew Wampler-Doty 19 | * @date 2015 20 | */ 21 | 22 | #pragma once 23 | #include 24 | #include "compiler.h" 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | #define FNV_PRIME 0x01000193 31 | 32 | static inline uint32_t fnv_hash(uint32_t const x, uint32_t const y) 33 | { 34 | return x * FNV_PRIME ^ y; 35 | } 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | -------------------------------------------------------------------------------- /libethash/io.c: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of ethash. 3 | 4 | ethash is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | ethash is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with ethash. If not, see . 16 | */ 17 | /** @file io.c 18 | * @author Lefteris Karapetsas 19 | * @date 2015 20 | */ 21 | #include "io.h" 22 | #include 23 | #include 24 | #include 25 | 26 | enum ethash_io_rc ethash_io_prepare( 27 | char const* dirname, 28 | ethash_h256_t const seedhash, 29 | FILE** output_file, 30 | uint64_t file_size, 31 | bool force_create 32 | ) 33 | { 34 | char mutable_name[DAG_MUTABLE_NAME_MAX_SIZE]; 35 | enum ethash_io_rc ret = ETHASH_IO_FAIL; 36 | // reset errno before io calls 37 | errno = 0; 38 | 39 | // assert directory exists 40 | if (!ethash_mkdir(dirname)) { 41 | ETHASH_CRITICAL("Could not create the ethash directory"); 42 | goto end; 43 | } 44 | 45 | ethash_io_mutable_name(ETHASH_REVISION, &seedhash, mutable_name); 46 | char* tmpfile = ethash_io_create_filename(dirname, mutable_name, strlen(mutable_name)); 47 | if (!tmpfile) { 48 | ETHASH_CRITICAL("Could not create the full DAG pathname"); 49 | goto end; 50 | } 51 | 52 | FILE *f; 53 | if (!force_create) { 54 | // try to open the file 55 | f = ethash_fopen(tmpfile, "rb+"); 56 | if (f) { 57 | size_t found_size; 58 | if (!ethash_file_size(f, &found_size)) { 59 | fclose(f); 60 | ETHASH_CRITICAL("Could not query size of DAG file: \"%s\"", tmpfile); 61 | goto free_memo; 62 | } 63 | if (file_size != found_size - ETHASH_DAG_MAGIC_NUM_SIZE) { 64 | fclose(f); 65 | ret = ETHASH_IO_MEMO_SIZE_MISMATCH; 66 | goto free_memo; 67 | } 68 | // compare the magic number, no need to care about endianess since it's local 69 | uint64_t magic_num; 70 | if (fread(&magic_num, ETHASH_DAG_MAGIC_NUM_SIZE, 1, f) != 1) { 71 | // I/O error 72 | fclose(f); 73 | ETHASH_CRITICAL("Could not read from DAG file: \"%s\"", tmpfile); 74 | ret = ETHASH_IO_MEMO_SIZE_MISMATCH; 75 | goto free_memo; 76 | } 77 | if (magic_num != ETHASH_DAG_MAGIC_NUM) { 78 | fclose(f); 79 | ret = ETHASH_IO_MEMO_SIZE_MISMATCH; 80 | goto free_memo; 81 | } 82 | ret = ETHASH_IO_MEMO_MATCH; 83 | goto set_file; 84 | } 85 | } 86 | 87 | // file does not exist, will need to be created 88 | f = ethash_fopen(tmpfile, "wb+"); 89 | if (!f) { 90 | ETHASH_CRITICAL("Could not create DAG file: \"%s\"", tmpfile); 91 | goto free_memo; 92 | } 93 | // make sure it's of the proper size 94 | if (fseek(f, (long int)(file_size + ETHASH_DAG_MAGIC_NUM_SIZE - 1), SEEK_SET) != 0) { 95 | fclose(f); 96 | ETHASH_CRITICAL("Could not seek to the end of DAG file: \"%s\". Insufficient space?", tmpfile); 97 | goto free_memo; 98 | } 99 | if (fputc('\n', f) == EOF) { 100 | fclose(f); 101 | ETHASH_CRITICAL("Could not write in the end of DAG file: \"%s\". Insufficient space?", tmpfile); 102 | goto free_memo; 103 | } 104 | if (fflush(f) != 0) { 105 | fclose(f); 106 | ETHASH_CRITICAL("Could not flush at end of DAG file: \"%s\". Insufficient space?", tmpfile); 107 | goto free_memo; 108 | } 109 | ret = ETHASH_IO_MEMO_MISMATCH; 110 | goto set_file; 111 | 112 | ret = ETHASH_IO_MEMO_MATCH; 113 | set_file: 114 | *output_file = f; 115 | free_memo: 116 | free(tmpfile); 117 | end: 118 | return ret; 119 | } 120 | -------------------------------------------------------------------------------- /libethash/io_posix.c: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of ethash. 3 | 4 | ethash is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | ethash is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with ethash. If not, see . 16 | */ 17 | /** @file io_posix.c 18 | * @author Lefteris Karapetsas 19 | * @date 2015 20 | */ 21 | 22 | #include "io.h" 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | FILE* ethash_fopen(char const* file_name, char const* mode) 33 | { 34 | return fopen(file_name, mode); 35 | } 36 | 37 | char* ethash_strncat(char* dest, size_t dest_size, char const* src, size_t count) 38 | { 39 | return strlen(dest) + count + 1 <= dest_size ? strncat(dest, src, count) : NULL; 40 | } 41 | 42 | bool ethash_mkdir(char const* dirname) 43 | { 44 | int rc = mkdir(dirname, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); 45 | return rc != -1 || errno == EEXIST; 46 | } 47 | 48 | int ethash_fileno(FILE *f) 49 | { 50 | return fileno(f); 51 | } 52 | 53 | char* ethash_io_create_filename( 54 | char const* dirname, 55 | char const* filename, 56 | size_t filename_length 57 | ) 58 | { 59 | size_t dirlen = strlen(dirname); 60 | size_t dest_size = dirlen + filename_length + 1; 61 | if (dirname[dirlen] != '/') { 62 | dest_size += 1; 63 | } 64 | char* name = malloc(dest_size); 65 | if (!name) { 66 | return NULL; 67 | } 68 | 69 | name[0] = '\0'; 70 | ethash_strncat(name, dest_size, dirname, dirlen); 71 | if (dirname[dirlen] != '/') { 72 | ethash_strncat(name, dest_size, "/", 1); 73 | } 74 | ethash_strncat(name, dest_size, filename, filename_length); 75 | return name; 76 | } 77 | 78 | bool ethash_file_size(FILE* f, size_t* ret_size) 79 | { 80 | struct stat st; 81 | int fd; 82 | if ((fd = fileno(f)) == -1 || fstat(fd, &st) != 0) { 83 | return false; 84 | } 85 | *ret_size = st.st_size; 86 | return true; 87 | } 88 | 89 | bool ethash_get_default_dirname(char* strbuf, size_t buffsize) 90 | { 91 | static const char dir_suffix[] = ".ethash/"; 92 | strbuf[0] = '\0'; 93 | char* home_dir = getenv("HOME"); 94 | if (!home_dir || strlen(home_dir) == 0) 95 | { 96 | struct passwd* pwd = getpwuid(getuid()); 97 | if (pwd) 98 | home_dir = pwd->pw_dir; 99 | } 100 | 101 | size_t len = strlen(home_dir); 102 | if (!ethash_strncat(strbuf, buffsize, home_dir, len)) { 103 | return false; 104 | } 105 | if (home_dir[len] != '/') { 106 | if (!ethash_strncat(strbuf, buffsize, "/", 1)) { 107 | return false; 108 | } 109 | } 110 | return ethash_strncat(strbuf, buffsize, dir_suffix, sizeof(dir_suffix)); 111 | } 112 | -------------------------------------------------------------------------------- /libethash/io_win32.c: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of ethash. 3 | 4 | ethash is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | ethash is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with ethash. If not, see . 16 | */ 17 | /** @file io_win32.c 18 | * @author Lefteris Karapetsas 19 | * @date 2015 20 | */ 21 | 22 | #include "io.h" 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | FILE* ethash_fopen(char const* file_name, char const* mode) 31 | { 32 | FILE* f; 33 | return fopen_s(&f, file_name, mode) == 0 ? f : NULL; 34 | } 35 | 36 | char* ethash_strncat(char* dest, size_t dest_size, char const* src, size_t count) 37 | { 38 | return strncat_s(dest, dest_size, src, count) == 0 ? dest : NULL; 39 | } 40 | 41 | bool ethash_mkdir(char const* dirname) 42 | { 43 | int rc = _mkdir(dirname); 44 | return rc != -1 || errno == EEXIST; 45 | } 46 | 47 | int ethash_fileno(FILE* f) 48 | { 49 | return _fileno(f); 50 | } 51 | 52 | char* ethash_io_create_filename( 53 | char const* dirname, 54 | char const* filename, 55 | size_t filename_length 56 | ) 57 | { 58 | size_t dirlen = strlen(dirname); 59 | size_t dest_size = dirlen + filename_length + 1; 60 | if (dirname[dirlen] != '\\' || dirname[dirlen] != '/') { 61 | dest_size += 1; 62 | } 63 | char* name = malloc(dest_size); 64 | if (!name) { 65 | return NULL; 66 | } 67 | 68 | name[0] = '\0'; 69 | ethash_strncat(name, dest_size, dirname, dirlen); 70 | if (dirname[dirlen] != '\\' || dirname[dirlen] != '/') { 71 | ethash_strncat(name, dest_size, "\\", 1); 72 | } 73 | ethash_strncat(name, dest_size, filename, filename_length); 74 | return name; 75 | } 76 | 77 | bool ethash_file_size(FILE* f, size_t* ret_size) 78 | { 79 | struct _stat st; 80 | int fd; 81 | if ((fd = _fileno(f)) == -1 || _fstat(fd, &st) != 0) { 82 | return false; 83 | } 84 | *ret_size = st.st_size; 85 | return true; 86 | } 87 | 88 | bool ethash_get_default_dirname(char* strbuf, size_t buffsize) 89 | { 90 | static const char dir_suffix[] = "Ethash\\"; 91 | strbuf[0] = '\0'; 92 | if (!SUCCEEDED(SHGetFolderPathA(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, (CHAR*)strbuf))) { 93 | return false; 94 | } 95 | if (!ethash_strncat(strbuf, buffsize, "\\", 1)) { 96 | return false; 97 | } 98 | 99 | return ethash_strncat(strbuf, buffsize, dir_suffix, sizeof(dir_suffix)); 100 | } 101 | -------------------------------------------------------------------------------- /libethash/mmap.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of ethash. 3 | 4 | ethash is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | ethash is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with ethash. If not, see . 16 | */ 17 | /** @file mmap.h 18 | * @author Lefteris Karapetsas 19 | * @date 2015 20 | */ 21 | #pragma once 22 | #if defined(__MINGW32__) || defined(_WIN32) 23 | #include 24 | 25 | #define PROT_READ 0x1 26 | #define PROT_WRITE 0x2 27 | /* This flag is only available in WinXP+ */ 28 | #ifdef FILE_MAP_EXECUTE 29 | #define PROT_EXEC 0x4 30 | #else 31 | #define PROT_EXEC 0x0 32 | #define FILE_MAP_EXECUTE 0 33 | #endif 34 | 35 | #define MAP_SHARED 0x01 36 | #define MAP_PRIVATE 0x02 37 | #define MAP_ANONYMOUS 0x20 38 | #define MAP_ANON MAP_ANONYMOUS 39 | #define MAP_FAILED ((void *) -1) 40 | 41 | void* mmap(void* start, size_t length, int prot, int flags, int fd, off_t offset); 42 | void munmap(void* addr, size_t length); 43 | #else // posix, yay! ^_^ 44 | #include 45 | #endif 46 | 47 | 48 | -------------------------------------------------------------------------------- /libethash/mmap_win32.c: -------------------------------------------------------------------------------- 1 | /* mmap() replacement for Windows 2 | * 3 | * Author: Mike Frysinger 4 | * Placed into the public domain 5 | */ 6 | 7 | /* References: 8 | * CreateFileMapping: http://msdn.microsoft.com/en-us/library/aa366537(VS.85).aspx 9 | * CloseHandle: http://msdn.microsoft.com/en-us/library/ms724211(VS.85).aspx 10 | * MapViewOfFile: http://msdn.microsoft.com/en-us/library/aa366761(VS.85).aspx 11 | * UnmapViewOfFile: http://msdn.microsoft.com/en-us/library/aa366882(VS.85).aspx 12 | */ 13 | 14 | #include 15 | #include 16 | #include "mmap.h" 17 | 18 | #ifdef __USE_FILE_OFFSET64 19 | # define DWORD_HI(x) (x >> 32) 20 | # define DWORD_LO(x) ((x) & 0xffffffff) 21 | #else 22 | # define DWORD_HI(x) (0) 23 | # define DWORD_LO(x) (x) 24 | #endif 25 | 26 | void* mmap(void* start, size_t length, int prot, int flags, int fd, off_t offset) 27 | { 28 | if (prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC)) 29 | return MAP_FAILED; 30 | if (fd == -1) { 31 | if (!(flags & MAP_ANON) || offset) 32 | return MAP_FAILED; 33 | } else if (flags & MAP_ANON) 34 | return MAP_FAILED; 35 | 36 | DWORD flProtect; 37 | if (prot & PROT_WRITE) { 38 | if (prot & PROT_EXEC) 39 | flProtect = PAGE_EXECUTE_READWRITE; 40 | else 41 | flProtect = PAGE_READWRITE; 42 | } else if (prot & PROT_EXEC) { 43 | if (prot & PROT_READ) 44 | flProtect = PAGE_EXECUTE_READ; 45 | else if (prot & PROT_EXEC) 46 | flProtect = PAGE_EXECUTE; 47 | } else 48 | flProtect = PAGE_READONLY; 49 | 50 | off_t end = length + offset; 51 | HANDLE mmap_fd, h; 52 | if (fd == -1) 53 | mmap_fd = INVALID_HANDLE_VALUE; 54 | else 55 | mmap_fd = (HANDLE)_get_osfhandle(fd); 56 | h = CreateFileMapping(mmap_fd, NULL, flProtect, DWORD_HI(end), DWORD_LO(end), NULL); 57 | if (h == NULL) 58 | return MAP_FAILED; 59 | 60 | DWORD dwDesiredAccess; 61 | if (prot & PROT_WRITE) 62 | dwDesiredAccess = FILE_MAP_WRITE; 63 | else 64 | dwDesiredAccess = FILE_MAP_READ; 65 | if (prot & PROT_EXEC) 66 | dwDesiredAccess |= FILE_MAP_EXECUTE; 67 | if (flags & MAP_PRIVATE) 68 | dwDesiredAccess |= FILE_MAP_COPY; 69 | void *ret = MapViewOfFile(h, dwDesiredAccess, DWORD_HI(offset), DWORD_LO(offset), length); 70 | if (ret == NULL) { 71 | ret = MAP_FAILED; 72 | } 73 | // since we are handling the file ourselves with fd, close the Windows Handle here 74 | CloseHandle(h); 75 | return ret; 76 | } 77 | 78 | void munmap(void* addr, size_t length) 79 | { 80 | UnmapViewOfFile(addr); 81 | } 82 | 83 | #undef DWORD_HI 84 | #undef DWORD_LO 85 | -------------------------------------------------------------------------------- /libethash/sha3.c: -------------------------------------------------------------------------------- 1 | /** libkeccak-tiny 2 | * 3 | * A single-file implementation of SHA-3 and SHAKE. 4 | * 5 | * Implementor: David Leon Gil 6 | * License: CC0, attribution kindly requested. Blame taken too, 7 | * but not liability. 8 | */ 9 | #include "sha3.h" 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | /******** The Keccak-f[1600] permutation ********/ 17 | 18 | /*** Constants. ***/ 19 | static const uint8_t rho[24] = \ 20 | { 1, 3, 6, 10, 15, 21, 21 | 28, 36, 45, 55, 2, 14, 22 | 27, 41, 56, 8, 25, 43, 23 | 62, 18, 39, 61, 20, 44}; 24 | static const uint8_t pi[24] = \ 25 | {10, 7, 11, 17, 18, 3, 26 | 5, 16, 8, 21, 24, 4, 27 | 15, 23, 19, 13, 12, 2, 28 | 20, 14, 22, 9, 6, 1}; 29 | static const uint64_t RC[24] = \ 30 | {1ULL, 0x8082ULL, 0x800000000000808aULL, 0x8000000080008000ULL, 31 | 0x808bULL, 0x80000001ULL, 0x8000000080008081ULL, 0x8000000000008009ULL, 32 | 0x8aULL, 0x88ULL, 0x80008009ULL, 0x8000000aULL, 33 | 0x8000808bULL, 0x800000000000008bULL, 0x8000000000008089ULL, 0x8000000000008003ULL, 34 | 0x8000000000008002ULL, 0x8000000000000080ULL, 0x800aULL, 0x800000008000000aULL, 35 | 0x8000000080008081ULL, 0x8000000000008080ULL, 0x80000001ULL, 0x8000000080008008ULL}; 36 | 37 | /*** Helper macros to unroll the permutation. ***/ 38 | #define rol(x, s) (((x) << s) | ((x) >> (64 - s))) 39 | #define REPEAT6(e) e e e e e e 40 | #define REPEAT24(e) REPEAT6(e e e e) 41 | #define REPEAT5(e) e e e e e 42 | #define FOR5(v, s, e) \ 43 | v = 0; \ 44 | REPEAT5(e; v += s;) 45 | 46 | /*** Keccak-f[1600] ***/ 47 | static inline void keccakf(void* state) { 48 | uint64_t* a = (uint64_t*)state; 49 | uint64_t b[5] = {0}; 50 | uint64_t t = 0; 51 | uint8_t x, y; 52 | 53 | for (int i = 0; i < 24; i++) { 54 | // Theta 55 | FOR5(x, 1, 56 | b[x] = 0; 57 | FOR5(y, 5, 58 | b[x] ^= a[x + y]; )) 59 | FOR5(x, 1, 60 | FOR5(y, 5, 61 | a[y + x] ^= b[(x + 4) % 5] ^ rol(b[(x + 1) % 5], 1); )) 62 | // Rho and pi 63 | t = a[1]; 64 | x = 0; 65 | REPEAT24(b[0] = a[pi[x]]; 66 | a[pi[x]] = rol(t, rho[x]); 67 | t = b[0]; 68 | x++; ) 69 | // Chi 70 | FOR5(y, 71 | 5, 72 | FOR5(x, 1, 73 | b[x] = a[y + x];) 74 | FOR5(x, 1, 75 | a[y + x] = b[x] ^ ((~b[(x + 1) % 5]) & b[(x + 2) % 5]); )) 76 | // Iota 77 | a[0] ^= RC[i]; 78 | } 79 | } 80 | 81 | /******** The FIPS202-defined functions. ********/ 82 | 83 | /*** Some helper macros. ***/ 84 | 85 | #define _(S) do { S } while (0) 86 | #define FOR(i, ST, L, S) \ 87 | _(for (size_t i = 0; i < L; i += ST) { S; }) 88 | #define mkapply_ds(NAME, S) \ 89 | static inline void NAME(uint8_t* dst, \ 90 | const uint8_t* src, \ 91 | size_t len) { \ 92 | FOR(i, 1, len, S); \ 93 | } 94 | #define mkapply_sd(NAME, S) \ 95 | static inline void NAME(const uint8_t* src, \ 96 | uint8_t* dst, \ 97 | size_t len) { \ 98 | FOR(i, 1, len, S); \ 99 | } 100 | 101 | mkapply_ds(xorin, dst[i] ^= src[i]) // xorin 102 | mkapply_sd(setout, dst[i] = src[i]) // setout 103 | 104 | #define P keccakf 105 | #define Plen 200 106 | 107 | // Fold P*F over the full blocks of an input. 108 | #define foldP(I, L, F) \ 109 | while (L >= rate) { \ 110 | F(a, I, rate); \ 111 | P(a); \ 112 | I += rate; \ 113 | L -= rate; \ 114 | } 115 | 116 | /** The sponge-based hash construction. **/ 117 | static inline int hash(uint8_t* out, size_t outlen, 118 | const uint8_t* in, size_t inlen, 119 | size_t rate, uint8_t delim) { 120 | if ((out == NULL) || ((in == NULL) && inlen != 0) || (rate >= Plen)) { 121 | return -1; 122 | } 123 | uint8_t a[Plen] = {0}; 124 | // Absorb input. 125 | foldP(in, inlen, xorin); 126 | // Xor in the DS and pad frame. 127 | a[inlen] ^= delim; 128 | a[rate - 1] ^= 0x80; 129 | // Xor in the last block. 130 | xorin(a, in, inlen); 131 | // Apply P 132 | P(a); 133 | // Squeeze output. 134 | foldP(out, outlen, setout); 135 | setout(a, out, outlen); 136 | memset(a, 0, 200); 137 | return 0; 138 | } 139 | 140 | #define defsha3(bits) \ 141 | int sha3_##bits(uint8_t* out, size_t outlen, \ 142 | const uint8_t* in, size_t inlen) { \ 143 | if (outlen > (bits/8)) { \ 144 | return -1; \ 145 | } \ 146 | return hash(out, outlen, in, inlen, 200 - (bits / 4), 0x01); \ 147 | } 148 | 149 | /*** FIPS202 SHA3 FOFs ***/ 150 | defsha3(256) 151 | defsha3(512) 152 | -------------------------------------------------------------------------------- /libethash/sha3.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | 7 | #include "compiler.h" 8 | #include 9 | #include 10 | 11 | struct ethash_h256; 12 | 13 | #define decsha3(bits) \ 14 | int sha3_##bits(uint8_t*, size_t, uint8_t const*, size_t); 15 | 16 | decsha3(256) 17 | decsha3(512) 18 | 19 | static inline void SHA3_256(struct ethash_h256 const* ret, uint8_t const* data, size_t const size) 20 | { 21 | sha3_256((uint8_t*)ret, 32, data, size); 22 | } 23 | 24 | static inline void SHA3_512(uint8_t* ret, uint8_t const* data, size_t const size) 25 | { 26 | sha3_512(ret, 64, data, size); 27 | } 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | -------------------------------------------------------------------------------- /libethash/sha3_cryptopp.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of ethash. 3 | 4 | ethash is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | ethash is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with ethash. If not, see . 16 | */ 17 | 18 | /** @file sha3.cpp 19 | * @author Tim Hughes 20 | * @date 2015 21 | */ 22 | #include 23 | #include 24 | 25 | extern "C" { 26 | struct ethash_h256; 27 | typedef struct ethash_h256 ethash_h256_t; 28 | void SHA3_256(ethash_h256_t const* ret, uint8_t const* data, size_t size) 29 | { 30 | CryptoPP::SHA3_256().CalculateDigest((uint8_t*)ret, data, size); 31 | } 32 | 33 | void SHA3_512(uint8_t* const ret, uint8_t const* data, size_t size) 34 | { 35 | CryptoPP::SHA3_512().CalculateDigest(ret, data, size); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /libethash/sha3_cryptopp.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "compiler.h" 4 | #include 5 | #include 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | struct ethash_h256; 12 | 13 | void SHA3_256(struct ethash_h256 const* ret, uint8_t const* data, size_t size); 14 | void SHA3_512(uint8_t* const ret, uint8_t const* data, size_t size); 15 | 16 | #ifdef __cplusplus 17 | } 18 | #endif 19 | -------------------------------------------------------------------------------- /libethash/util.c: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file util.c 18 | * @author Tim Hughes 19 | * @date 2015 20 | */ 21 | #include 22 | #include 23 | #include "util.h" 24 | 25 | #ifdef _MSC_VER 26 | 27 | // foward declare without all of Windows.h 28 | __declspec(dllimport) void __stdcall OutputDebugStringA(const char* lpOutputString); 29 | 30 | void debugf(const char *str, ...) 31 | { 32 | va_list args; 33 | va_start(args, str); 34 | 35 | char buf[1<<16]; 36 | _vsnprintf_s(buf, sizeof(buf), sizeof(buf), str, args); 37 | buf[sizeof(buf)-1] = '\0'; 38 | OutputDebugStringA(buf); 39 | } 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /libethash/util.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of ethash. 3 | 4 | ethash is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | ethash is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with ethash. If not, see . 16 | */ 17 | /** @file util.h 18 | * @author Tim Hughes 19 | * @date 2015 20 | */ 21 | #pragma once 22 | #include 23 | #include "compiler.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | #ifdef _MSC_VER 30 | void debugf(char const* str, ...); 31 | #else 32 | #define debugf printf 33 | #endif 34 | 35 | static inline uint32_t min_u32(uint32_t a, uint32_t b) 36 | { 37 | return a < b ? a : b; 38 | } 39 | 40 | static inline uint32_t clamp_u32(uint32_t x, uint32_t min_, uint32_t max_) 41 | { 42 | return x < min_ ? min_ : (x > max_ ? max_ : x); 43 | } 44 | 45 | #ifdef __cplusplus 46 | } 47 | #endif 48 | -------------------------------------------------------------------------------- /libethash/util_win32.c: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file util.c 18 | * @author Tim Hughes 19 | * @date 2015 20 | */ 21 | #include 22 | #include 23 | #include "util.h" 24 | 25 | 26 | // foward declare without all of Windows.h 27 | __declspec(dllimport) void __stdcall OutputDebugStringA(char const* lpOutputString); 28 | 29 | void debugf(char const* str, ...) 30 | { 31 | va_list args; 32 | va_start(args, str); 33 | 34 | char buf[1<<16]; 35 | _vsnprintf_s(buf, sizeof(buf), sizeof(buf), str, args); 36 | buf[sizeof(buf)-1] = '\0'; 37 | OutputDebugStringA(buf); 38 | } 39 | -------------------------------------------------------------------------------- /libethcore/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_policy(SET CMP0015 NEW) 2 | set(CMAKE_AUTOMOC OFF) 3 | 4 | aux_source_directory(. SRC_LIST) 5 | 6 | include_directories(BEFORE ..) 7 | include_directories(${Boost_INCLUDE_DIRS}) 8 | 9 | if (CPUID_FOUND) 10 | include_directories(${Cpuid_INCLUDE_DIRS}) 11 | endif () 12 | 13 | if (ETHASHCUDA) 14 | include_directories(${CUDA_INCLUDE_DIRS}) 15 | endif () 16 | 17 | set(EXECUTABLE ethcore) 18 | 19 | file(GLOB HEADERS "*.h") 20 | 21 | add_library(${EXECUTABLE} ${SRC_LIST} ${HEADERS}) 22 | 23 | target_link_libraries(${EXECUTABLE} ethash) 24 | 25 | if (ETHASHCL) 26 | target_link_libraries(${EXECUTABLE} ethash-cl) 27 | endif () 28 | if (ETHASHCUDA) 29 | target_link_libraries(${EXECUTABLE} ethash-cuda) 30 | endif () 31 | if (CPUID_FOUND) 32 | target_link_libraries(${EXECUTABLE} ${CPUID_LIBRARIES}) 33 | endif () 34 | 35 | install( TARGETS ${EXECUTABLE} RUNTIME DESTINATION bin ARCHIVE DESTINATION lib LIBRARY DESTINATION lib ) 36 | install( FILES ${HEADERS} DESTINATION include/${EXECUTABLE} ) 37 | -------------------------------------------------------------------------------- /libethcore/Common.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file Common.cpp 18 | * @author Gav Wood 19 | * @date 2014 20 | */ 21 | 22 | #include "Common.h" 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include "Exceptions.h" 31 | #include "Params.h" 32 | #include "BlockInfo.h" 33 | using namespace std; 34 | using namespace dev; 35 | using namespace dev::eth; 36 | 37 | namespace dev 38 | { 39 | namespace eth 40 | { 41 | 42 | const unsigned c_protocolVersion = 61; 43 | const unsigned c_minorProtocolVersion = 2; 44 | const unsigned c_databaseBaseVersion = 9; 45 | const unsigned c_databaseVersionModifier = 0; 46 | 47 | const unsigned c_databaseVersion = c_databaseBaseVersion + (c_databaseVersionModifier << 8) + (23 << 9); 48 | 49 | Address toAddress(std::string const& _s) 50 | { 51 | try 52 | { 53 | auto b = fromHex(_s.substr(0, 2) == "0x" ? _s.substr(2) : _s, WhenError::Throw); 54 | if (b.size() == 20) 55 | return Address(b); 56 | } 57 | catch (BadHexCharacter&) {} 58 | BOOST_THROW_EXCEPTION(InvalidAddress()); 59 | } 60 | 61 | 62 | vector> const& units() 63 | { 64 | static const vector> s_units = 65 | { 66 | {exp10<54>(), "Uether"}, 67 | {exp10<51>(), "Vether"}, 68 | {exp10<48>(), "Dether"}, 69 | {exp10<45>(), "Nether"}, 70 | {exp10<42>(), "Yether"}, 71 | {exp10<39>(), "Zether"}, 72 | {exp10<36>(), "Eether"}, 73 | {exp10<33>(), "Pether"}, 74 | {exp10<30>(), "Tether"}, 75 | {exp10<27>(), "Gether"}, 76 | {exp10<24>(), "Mether"}, 77 | {exp10<21>(), "grand"}, 78 | {exp10<18>(), "ether"}, 79 | {exp10<15>(), "finney"}, 80 | {exp10<12>(), "szabo"}, 81 | {exp10<9>(), "Gwei"}, 82 | {exp10<6>(), "Mwei"}, 83 | {exp10<3>(), "Kwei"}, 84 | {exp10<0>(), "wei"} 85 | }; 86 | 87 | return s_units; 88 | } 89 | 90 | std::string formatBalance(bigint const& _b) 91 | { 92 | ostringstream ret; 93 | u256 b; 94 | if (_b < 0) 95 | { 96 | ret << "-"; 97 | b = (u256)-_b; 98 | } 99 | else 100 | b = (u256)_b; 101 | 102 | if (b > units()[0].first * 1000) 103 | { 104 | ret << (b / units()[0].first) << " " << units()[0].second; 105 | return ret.str(); 106 | } 107 | ret << setprecision(5); 108 | for (auto const& i: units()) 109 | if (i.first != 1 && b >= i.first * 1) 110 | { 111 | ret << (double(b / (i.first / 1000)) / 1000.0) << " " << i.second; 112 | return ret.str(); 113 | } 114 | ret << b << " wei"; 115 | return ret.str(); 116 | } 117 | 118 | static void badBlockInfo(BlockInfo const& _bi, string const& _err) 119 | { 120 | string const c_line = EthReset EthOnMaroon + string(80, ' ') + EthReset; 121 | string const c_border = EthReset EthOnMaroon + string(2, ' ') + EthReset EthMaroonBold; 122 | string const c_space = c_border + string(76, ' ') + c_border + EthReset; 123 | stringstream ss; 124 | ss << c_line << endl; 125 | ss << c_space << endl; 126 | ss << c_border + " Import Failure " + _err + string(max(0, 53 - _err.size()), ' ') + " " + c_border << endl; 127 | ss << c_space << endl; 128 | string bin = toString(_bi.number()); 129 | ss << c_border + (" Guru Meditation #" + string(max(0, 8 - bin.size()), '0') + bin + "." + _bi.hash().abridged() + " ") + c_border << endl; 130 | ss << c_space << endl; 131 | ss << c_line; 132 | cwarn << "\n" + ss.str(); 133 | } 134 | 135 | void badBlock(bytesConstRef _block, string const& _err) 136 | { 137 | BlockInfo bi; 138 | DEV_IGNORE_EXCEPTIONS(bi = BlockInfo(_block, CheckNothing)); 139 | badBlockInfo(bi, _err); 140 | } 141 | 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /libethcore/Ethash.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file Ethash.h 18 | * @author Gav Wood 19 | * @date 2014 20 | * 21 | * A proof of work algorithm. 22 | */ 23 | 24 | #pragma once 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include "Common.h" 31 | #include "Miner.h" 32 | #include "Farm.h" 33 | #include "Sealer.h" 34 | 35 | class ethash_cl_miner; 36 | class ethash_cuda_miner; 37 | 38 | namespace dev 39 | { 40 | 41 | class RLP; 42 | class RLPStream; 43 | 44 | namespace eth 45 | { 46 | 47 | class BlockInfo; 48 | class EthashCLHook; 49 | class EthashCUDAHook; 50 | 51 | class Ethash 52 | { 53 | public: 54 | static std::string name(); 55 | static unsigned revision(); 56 | static SealEngineFace* createSealEngine(); 57 | 58 | using Nonce = h64; 59 | 60 | static void manuallySubmitWork(SealEngineFace* _engine, h256 const& _mixHash, Nonce _nonce); 61 | static bool isWorking(SealEngineFace* _engine); 62 | static WorkingProgress workingProgress(SealEngineFace* _engine); 63 | 64 | class BlockHeaderRaw: public BlockInfo 65 | { 66 | friend class EthashSealEngine; 67 | 68 | public: 69 | static const unsigned SealFields = 2; 70 | 71 | bool verify() const; 72 | bool preVerify() const; 73 | 74 | void prep(std::function const& _f = std::function()) const; 75 | h256 const& seedHash() const; 76 | Nonce const& nonce() const { return m_nonce; } 77 | h256 const& mixHash() const { return m_mixHash; } 78 | 79 | void setNonce(Nonce const& _n) { m_nonce = _n; noteDirty(); } 80 | void setMixHash(h256 const& _n) { m_mixHash = _n; noteDirty(); } 81 | 82 | StringHashMap jsInfo() const; 83 | 84 | protected: 85 | BlockHeaderRaw() = default; 86 | BlockHeaderRaw(BlockInfo const& _bi): BlockInfo(_bi) {} 87 | 88 | void populateFromHeader(RLP const& _header, Strictness _s); 89 | void populateFromParent(BlockHeaderRaw const& _parent); 90 | void verifyParent(BlockHeaderRaw const& _parent); 91 | void clear() { m_mixHash = h256(); m_nonce = Nonce(); } 92 | void noteDirty() const { m_seedHash = h256(); } 93 | void streamRLPFields(RLPStream& _s) const { _s << m_mixHash << m_nonce; } 94 | 95 | private: 96 | Nonce m_nonce; 97 | h256 m_mixHash; 98 | 99 | mutable h256 m_seedHash; 100 | mutable h256 m_hash; ///< SHA3 hash of the block header! Not serialised. 101 | }; 102 | using BlockHeader = BlockHeaderPolished; 103 | 104 | static void manuallySetWork(SealEngineFace* _engine, BlockHeader const& _work); 105 | 106 | // TODO: Move elsewhere (EthashAux?) 107 | static void ensurePrecomputed(unsigned _number); 108 | }; 109 | 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /libethcore/EthashCPUMiner.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file EthashCPUMiner.cpp 18 | * @author Gav Wood 19 | * @date 2014 20 | * 21 | * Determines the PoW algorithm. 22 | */ 23 | 24 | #include "EthashCPUMiner.h" 25 | #include 26 | #include 27 | #include 28 | #include 29 | #if ETH_CPUID || !ETH_TRUE 30 | #define HAVE_STDINT_H 31 | #include 32 | #endif 33 | using namespace std; 34 | using namespace dev; 35 | using namespace eth; 36 | 37 | unsigned EthashCPUMiner::s_numInstances = 0; 38 | 39 | #if ETH_CPUID || !ETH_TRUE 40 | static string jsonEncode(map const& _m) 41 | { 42 | string ret = "{"; 43 | 44 | for (auto const& i: _m) 45 | { 46 | string k = boost::replace_all_copy(boost::replace_all_copy(i.first, "\\", "\\\\"), "'", "\\'"); 47 | string v = boost::replace_all_copy(boost::replace_all_copy(i.second, "\\", "\\\\"), "'", "\\'"); 48 | if (ret.size() > 1) 49 | ret += ", "; 50 | ret += "\"" + k + "\":\"" + v + "\""; 51 | } 52 | 53 | return ret + "}"; 54 | } 55 | #endif 56 | 57 | EthashCPUMiner::EthashCPUMiner(GenericMiner::ConstructionInfo const& _ci): 58 | GenericMiner(_ci), Worker("miner" + toString(index())) 59 | { 60 | } 61 | 62 | EthashCPUMiner::~EthashCPUMiner() 63 | { 64 | } 65 | 66 | void EthashCPUMiner::kickOff() 67 | { 68 | stopWorking(); 69 | startWorking(); 70 | } 71 | 72 | void EthashCPUMiner::pause() 73 | { 74 | stopWorking(); 75 | } 76 | 77 | void EthashCPUMiner::workLoop() 78 | { 79 | auto tid = std::this_thread::get_id(); 80 | static std::mt19937_64 s_eng((time(0) + std::hash()(tid))); 81 | 82 | uint64_t tryNonce = s_eng(); 83 | ethash_return_value ethashReturn; 84 | 85 | WorkPackage w = work(); 86 | 87 | EthashAux::FullType dag; 88 | while (!shouldStop() && !dag) 89 | { 90 | while (!shouldStop() && EthashAux::computeFull(w.seedHash, true) != 100) 91 | this_thread::sleep_for(chrono::milliseconds(500)); 92 | dag = EthashAux::full(w.seedHash, false); 93 | } 94 | 95 | h256 boundary = w.boundary; 96 | unsigned hashCount = 1; 97 | for (; !shouldStop(); tryNonce++, hashCount++) 98 | { 99 | ethashReturn = ethash_full_compute(dag->full, *(ethash_h256_t*)w.headerHash.data(), tryNonce); 100 | h256 value = h256((uint8_t*)ðashReturn.result, h256::ConstructFromPointer); 101 | if (value <= boundary && submitProof(EthashProofOfWork::Solution{(h64)(u64)tryNonce, h256((uint8_t*)ðashReturn.mix_hash, h256::ConstructFromPointer)})) 102 | break; 103 | if (!(hashCount % 100)) 104 | accumulateHashes(100); 105 | } 106 | } 107 | 108 | std::string EthashCPUMiner::platformInfo() 109 | { 110 | string baseline = toString(std::thread::hardware_concurrency()) + "-thread CPU"; 111 | #if ETH_CPUID || !ETH_TRUE 112 | if (!cpuid_present()) 113 | return baseline; 114 | struct cpu_raw_data_t raw; 115 | struct cpu_id_t data; 116 | if (cpuid_get_raw_data(&raw) < 0) 117 | return baseline; 118 | if (cpu_identify(&raw, &data) < 0) 119 | return baseline; 120 | map m; 121 | m["vendor"] = data.vendor_str; 122 | m["codename"] = data.cpu_codename; 123 | m["brand"] = data.brand_str; 124 | m["L1 cache"] = toString(data.l1_data_cache); 125 | m["L2 cache"] = toString(data.l2_cache); 126 | m["L3 cache"] = toString(data.l3_cache); 127 | m["cores"] = toString(data.num_cores); 128 | m["threads"] = toString(data.num_logical_cpus); 129 | m["clocknominal"] = toString(cpu_clock_by_os()); 130 | m["clocktested"] = toString(cpu_clock_measure(200, 0)); 131 | /* 132 | printf(" MMX : %s\n", data.flags[CPU_FEATURE_MMX] ? "present" : "absent"); 133 | printf(" MMX-extended: %s\n", data.flags[CPU_FEATURE_MMXEXT] ? "present" : "absent"); 134 | printf(" SSE : %s\n", data.flags[CPU_FEATURE_SSE] ? "present" : "absent"); 135 | printf(" SSE2 : %s\n", data.flags[CPU_FEATURE_SSE2] ? "present" : "absent"); 136 | printf(" 3DNow! : %s\n", data.flags[CPU_FEATURE_3DNOW] ? "present" : "absent"); 137 | */ 138 | return jsonEncode(m); 139 | #else 140 | return baseline; 141 | #endif 142 | } 143 | -------------------------------------------------------------------------------- /libethcore/EthashCPUMiner.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file EthashCPUMiner.h 18 | * @author Gav Wood 19 | * @date 2014 20 | * 21 | * Determines the PoW algorithm. 22 | */ 23 | 24 | #pragma once 25 | 26 | #include "libdevcore/Worker.h" 27 | #include "EthashAux.h" 28 | #include "Miner.h" 29 | 30 | namespace dev 31 | { 32 | namespace eth 33 | { 34 | 35 | class EthashCPUMiner: public GenericMiner, Worker 36 | { 37 | public: 38 | EthashCPUMiner(GenericMiner::ConstructionInfo const& _ci); 39 | ~EthashCPUMiner(); 40 | 41 | static unsigned instances() { return s_numInstances > 0 ? s_numInstances : std::thread::hardware_concurrency(); } 42 | static std::string platformInfo(); 43 | static void listDevices() {} 44 | static bool configureGPU(unsigned, unsigned, unsigned, unsigned, unsigned, bool, unsigned, uint64_t) { return false; } 45 | static void setNumInstances(unsigned _instances) { s_numInstances = std::min(_instances, std::thread::hardware_concurrency()); } 46 | 47 | protected: 48 | void kickOff() override; 49 | void pause() override; 50 | 51 | private: 52 | void workLoop() override; 53 | static unsigned s_numInstances; 54 | }; 55 | 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /libethcore/EthashCUDAMiner.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file EthashCUDAMiner.h 18 | * @author Gav Wood 19 | * @date 2014 20 | * 21 | * Determines the PoW algorithm. 22 | */ 23 | 24 | #pragma once 25 | #if ETH_ETHASHCUDA || !ETH_TRUE 26 | 27 | #include "libdevcore/Worker.h" 28 | #include "EthashAux.h" 29 | #include "Miner.h" 30 | 31 | namespace dev 32 | { 33 | namespace eth 34 | { 35 | class EthashCUDAMiner : public GenericMiner, Worker 36 | { 37 | friend class dev::eth::EthashCUDAHook; 38 | 39 | public: 40 | EthashCUDAMiner(ConstructionInfo const& _ci); 41 | ~EthashCUDAMiner(); 42 | 43 | static unsigned instances() 44 | { 45 | return s_numInstances > 0 ? s_numInstances : 1; 46 | } 47 | static std::string platformInfo(); 48 | static unsigned getNumDevices(); 49 | static void listDevices(); 50 | static bool configureGPU( 51 | unsigned _blockSize, 52 | unsigned _gridSize, 53 | unsigned _numStreams, 54 | unsigned _extraGPUMemory, 55 | unsigned _scheduleFlag, 56 | uint64_t _currentBlock, 57 | unsigned _dagLoadMode, 58 | unsigned _dagCreateDevice 59 | ); 60 | static void setNumInstances(unsigned _instances) 61 | { 62 | s_numInstances = std::min(_instances, getNumDevices()); 63 | } 64 | static void setDevices(unsigned * _devices, unsigned _selectedDeviceCount) 65 | { 66 | for (unsigned i = 0; i < _selectedDeviceCount; i++) 67 | { 68 | s_devices[i] = _devices[i]; 69 | } 70 | } 71 | protected: 72 | void kickOff() override; 73 | void pause() override; 74 | 75 | private: 76 | void workLoop() override; 77 | bool report(uint64_t _nonce); 78 | 79 | using GenericMiner::accumulateHashes; 80 | 81 | EthashCUDAHook* m_hook = nullptr; 82 | ethash_cuda_miner* m_miner = nullptr; 83 | 84 | h256 m_minerSeed; ///< Last seed in m_miner 85 | static unsigned s_platformId; 86 | static unsigned s_deviceId; 87 | static unsigned s_numInstances; 88 | static int s_devices[16]; 89 | 90 | }; 91 | } 92 | } 93 | 94 | #endif 95 | -------------------------------------------------------------------------------- /libethcore/EthashGPUMiner.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file EthashGPUMiner.h 18 | * @author Gav Wood 19 | * @date 2014 20 | * 21 | * Determines the PoW algorithm. 22 | */ 23 | 24 | #pragma once 25 | #if ETH_ETHASHCL || !ETH_TRUE 26 | 27 | #include "libdevcore/Worker.h" 28 | #include "EthashAux.h" 29 | #include "Miner.h" 30 | 31 | namespace dev 32 | { 33 | namespace eth 34 | { 35 | 36 | class EthashGPUMiner: public GenericMiner, Worker 37 | { 38 | friend class dev::eth::EthashCLHook; 39 | 40 | public: 41 | EthashGPUMiner(ConstructionInfo const& _ci); 42 | ~EthashGPUMiner(); 43 | 44 | static unsigned instances() { return s_numInstances > 0 ? s_numInstances : 1; } 45 | static std::string platformInfo(); 46 | static unsigned getNumDevices(); 47 | static void listDevices(); 48 | static bool configureGPU( 49 | unsigned _localWorkSize, 50 | unsigned _globalWorkSizeMultiplier, 51 | unsigned _platformId, 52 | unsigned _deviceId, 53 | bool _allowCPU, 54 | unsigned _extraGPUMemory, 55 | uint64_t _currentBlock, 56 | unsigned _dagLoadMode, 57 | unsigned _dagCreateDevice 58 | ); 59 | static void setNumInstances(unsigned _instances) { s_numInstances = std::min(_instances, getNumDevices()); } 60 | static void setDevices(unsigned * _devices, unsigned _selectedDeviceCount) 61 | { 62 | for (unsigned i = 0; i < _selectedDeviceCount; i++) 63 | { 64 | s_devices[i] = _devices[i]; 65 | } 66 | } 67 | 68 | protected: 69 | void kickOff() override; 70 | void pause() override; 71 | 72 | private: 73 | void workLoop() override; 74 | bool report(uint64_t _nonce); 75 | 76 | using GenericMiner::accumulateHashes; 77 | 78 | EthashCLHook* m_hook = nullptr; 79 | ethash_cl_miner* m_miner = nullptr; 80 | 81 | h256 m_minerSeed; ///< Last seed in m_miner 82 | static unsigned s_platformId; 83 | static unsigned s_deviceId; 84 | static unsigned s_numInstances; 85 | static int s_devices[16]; 86 | 87 | }; 88 | 89 | } 90 | } 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /libethcore/EthashSealEngine.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file EthashSealEngine.cpp 18 | * @author Gav Wood 19 | * @date 2014 20 | * 21 | * Determines the PoW algorithm. 22 | */ 23 | 24 | #include "EthashSealEngine.h" 25 | #include "EthashCPUMiner.h" 26 | #include "EthashGPUMiner.h" 27 | #include "EthashCUDAMiner.h" 28 | using namespace std; 29 | using namespace dev; 30 | using namespace eth; 31 | 32 | EthashSealEngine::EthashSealEngine() 33 | { 34 | map::SealerDescriptor> sealers; 35 | sealers["cpu"] = GenericFarm::SealerDescriptor{&EthashCPUMiner::instances, [](GenericMiner::ConstructionInfo ci){ return new EthashCPUMiner(ci); }}; 36 | #if ETH_ETHASHCL 37 | sealers["opencl"] = GenericFarm::SealerDescriptor{&EthashGPUMiner::instances, [](GenericMiner::ConstructionInfo ci){ return new EthashGPUMiner(ci); }}; 38 | #endif 39 | #if ETH_ETHASHCUDA 40 | sealers["cuda"] = GenericFarm::SealerDescriptor{ &EthashCUDAMiner::instances, [](GenericMiner::ConstructionInfo ci){ return new EthashCUDAMiner(ci); } }; 41 | #endif 42 | m_farm.setSealers(sealers); 43 | } 44 | 45 | strings EthashSealEngine::sealers() const 46 | { 47 | return { 48 | "cpu" 49 | #if ETH_ETHASHCL 50 | , "opencl" 51 | #endif 52 | #if ETH_ETHASHCUDA 53 | , "cuda" 54 | #endif 55 | }; 56 | } 57 | 58 | void EthashSealEngine::generateSeal(BlockInfo const& _bi) 59 | { 60 | m_sealing = Ethash::BlockHeader(_bi); 61 | m_farm.setWork(m_sealing); 62 | m_farm.start(m_sealer, false); 63 | m_farm.setWork(m_sealing); // TODO: take out one before or one after... 64 | bytes shouldPrecompute = option("precomputeDAG"); 65 | if (!shouldPrecompute.empty() && shouldPrecompute[0] == 1) 66 | Ethash::ensurePrecomputed((unsigned)_bi.number()); 67 | } 68 | 69 | void EthashSealEngine::onSealGenerated(std::function const& _f) 70 | { 71 | m_farm.onSolutionFound([=](EthashProofOfWork::Solution const& sol) 72 | { 73 | // cdebug << m_farm.work().seedHash << m_farm.work().headerHash << sol.nonce << EthashAux::eval(m_farm.work().seedHash, m_farm.work().headerHash, sol.nonce).value; 74 | m_sealing.m_mixHash = sol.mixHash; 75 | m_sealing.m_nonce = sol.nonce; 76 | if (!m_sealing.preVerify()) 77 | return false; 78 | RLPStream ret; 79 | m_sealing.streamRLP(ret); 80 | _f(ret.out()); 81 | return true; 82 | }); 83 | } 84 | -------------------------------------------------------------------------------- /libethcore/EthashSealEngine.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file EthashSealEngine.h 18 | * @author Gav Wood 19 | * @date 2014 20 | * 21 | * Determines the PoW algorithm. 22 | */ 23 | 24 | #pragma once 25 | 26 | #include "Sealer.h" 27 | #include "Ethash.h" 28 | #include "EthashAux.h" 29 | 30 | namespace dev 31 | { 32 | namespace eth 33 | { 34 | 35 | class EthashSealEngine: public SealEngineBase 36 | { 37 | friend class Ethash; 38 | 39 | public: 40 | EthashSealEngine(); 41 | 42 | strings sealers() const override; 43 | void setSealer(std::string const& _sealer) override { m_sealer = _sealer; } 44 | void cancelGeneration() override { m_farm.stop(); } 45 | void generateSeal(BlockInfo const& _bi) override; 46 | void onSealGenerated(std::function const& _f) override; 47 | 48 | private: 49 | bool m_opencl = false; 50 | eth::GenericFarm m_farm; 51 | std::string m_sealer = "cpu"; 52 | Ethash::BlockHeader m_sealing; 53 | }; 54 | 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /libethcore/Exceptions.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file Exceptions.h 18 | * @author Gav Wood 19 | * @date 2014 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include "Common.h" 26 | 27 | namespace dev 28 | { 29 | namespace eth 30 | { 31 | 32 | // information to add to exceptions 33 | using errinfo_name = boost::error_info; 34 | using errinfo_field = boost::error_info; 35 | using errinfo_data = boost::error_info; 36 | using errinfo_nonce = boost::error_info; 37 | using errinfo_difficulty = boost::error_info; 38 | using errinfo_target = boost::error_info; 39 | using errinfo_seedHash = boost::error_info; 40 | using errinfo_mixHash = boost::error_info; 41 | using errinfo_ethashResult = boost::error_info>; 42 | using BadFieldError = boost::tuple; 43 | 44 | DEV_SIMPLE_EXCEPTION(OutOfGasBase); 45 | DEV_SIMPLE_EXCEPTION(OutOfGasIntrinsic); 46 | DEV_SIMPLE_EXCEPTION(NotEnoughAvailableSpace); 47 | DEV_SIMPLE_EXCEPTION(NotEnoughCash); 48 | DEV_SIMPLE_EXCEPTION(GasPriceTooLow); 49 | DEV_SIMPLE_EXCEPTION(BlockGasLimitReached); 50 | DEV_SIMPLE_EXCEPTION(FeeTooSmall); 51 | DEV_SIMPLE_EXCEPTION(TooMuchGasUsed); 52 | DEV_SIMPLE_EXCEPTION(ExtraDataTooBig); 53 | DEV_SIMPLE_EXCEPTION(InvalidSignature); 54 | DEV_SIMPLE_EXCEPTION(InvalidTransactionFormat); 55 | DEV_SIMPLE_EXCEPTION(InvalidBlockFormat); 56 | DEV_SIMPLE_EXCEPTION(InvalidUnclesHash); 57 | DEV_SIMPLE_EXCEPTION(TooManyUncles); 58 | DEV_SIMPLE_EXCEPTION(UncleTooOld); 59 | DEV_SIMPLE_EXCEPTION(UncleIsBrother); 60 | DEV_SIMPLE_EXCEPTION(UncleInChain); 61 | DEV_SIMPLE_EXCEPTION(InvalidStateRoot); 62 | DEV_SIMPLE_EXCEPTION(InvalidGasUsed); 63 | DEV_SIMPLE_EXCEPTION(InvalidTransactionsRoot); 64 | DEV_SIMPLE_EXCEPTION(InvalidDifficulty); 65 | DEV_SIMPLE_EXCEPTION(InvalidGasLimit); 66 | DEV_SIMPLE_EXCEPTION(InvalidReceiptsStateRoot); 67 | DEV_SIMPLE_EXCEPTION(InvalidTimestamp); 68 | DEV_SIMPLE_EXCEPTION(InvalidLogBloom); 69 | DEV_SIMPLE_EXCEPTION(InvalidNonce); 70 | DEV_SIMPLE_EXCEPTION(InvalidBlockHeaderItemCount); 71 | DEV_SIMPLE_EXCEPTION(InvalidBlockNonce); 72 | DEV_SIMPLE_EXCEPTION(InvalidParentHash); 73 | DEV_SIMPLE_EXCEPTION(InvalidUncleParentHash); 74 | DEV_SIMPLE_EXCEPTION(InvalidNumber); 75 | DEV_SIMPLE_EXCEPTION(BlockNotFound); 76 | 77 | DEV_SIMPLE_EXCEPTION(DatabaseAlreadyOpen); 78 | DEV_SIMPLE_EXCEPTION(DAGCreationFailure); 79 | DEV_SIMPLE_EXCEPTION(DAGComputeFailure); 80 | 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /libethcore/Miner.cpp: -------------------------------------------------------------------------------- 1 | #include "Miner.h" 2 | #include "EthashAux.h" 3 | 4 | using namespace dev; 5 | using namespace eth; 6 | 7 | template <> 8 | unsigned dev::eth::GenericMiner::s_dagLoadMode = 0; 9 | 10 | template <> 11 | volatile unsigned dev::eth::GenericMiner::s_dagLoadIndex = 0; 12 | 13 | template <> 14 | unsigned dev::eth::GenericMiner::s_dagCreateDevice = 0; 15 | 16 | template <> 17 | volatile void* dev::eth::GenericMiner::s_dagInHostMemory = NULL; 18 | 19 | 20 | -------------------------------------------------------------------------------- /libethcore/Params.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file Params.cpp 18 | * @author Gav Wood 19 | * @date 2014 20 | */ 21 | 22 | #include "Params.h" 23 | #include "Common.h" 24 | 25 | using namespace std; 26 | namespace dev 27 | { 28 | namespace eth 29 | { 30 | 31 | //--- BEGIN: AUTOGENERATED FROM github.com/ethereum/common/params.json 32 | u256 c_maximumExtraDataSize; 33 | u256 c_minGasLimit; 34 | u256 c_gasLimitBoundDivisor; 35 | u256 c_minimumDifficulty; 36 | u256 c_difficultyBoundDivisor; 37 | u256 c_durationLimit; 38 | u256 c_blockReward; 39 | u256 c_gasFloorTarget; 40 | //--- END: AUTOGENERATED FROM /feeStructure.json 41 | 42 | #if ETH_FRONTIER 43 | Network c_network = resetNetwork(Network::Frontier); 44 | #else 45 | Network c_network = resetNetwork(Network::Olympic); 46 | #endif 47 | 48 | Network resetNetwork(Network _n) 49 | { 50 | c_network = _n; 51 | c_maximumExtraDataSize = c_network == Network::Olympic ? 1024 : 32; 52 | switch(_n) 53 | { 54 | case Network::Turbo: 55 | c_minGasLimit = 100000000; 56 | break; 57 | case Network::Olympic: 58 | c_minGasLimit = 125000; 59 | break; 60 | case Network::Frontier: 61 | c_minGasLimit = 5000; 62 | break; 63 | } 64 | c_gasFloorTarget = 3141592; 65 | c_gasLimitBoundDivisor = 1024; 66 | c_minimumDifficulty = 131072; 67 | c_difficultyBoundDivisor = 2048; 68 | c_durationLimit = c_network == Network::Turbo ? 2 : c_network == Network::Olympic ? 8 : 13; 69 | c_blockReward = c_network == Network::Olympic ? (1500 * finney) : (5 * ether); 70 | return _n; 71 | } 72 | 73 | } 74 | } 75 | 76 | -------------------------------------------------------------------------------- /libethcore/Params.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file Params.h 18 | * @author Gav Wood 19 | * @date 2014 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | 26 | namespace dev 27 | { 28 | namespace eth 29 | { 30 | 31 | //--- BEGIN: AUTOGENERATED FROM /feeStructure.json 32 | extern u256 c_minGasLimit; 33 | extern u256 c_gasLimitBoundDivisor; 34 | extern u256 c_minimumDifficulty; 35 | extern u256 c_difficultyBoundDivisor; 36 | extern u256 c_durationLimit; 37 | extern u256 c_maximumExtraDataSize; 38 | extern u256 c_blockReward; 39 | extern u256 c_gasFloorTarget; 40 | //--- END: AUTOGENERATED FROM /feeStructure.json 41 | 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /libethcore/Sealer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file Sealer.cpp 18 | * @author Gav Wood 19 | * @date 2014 20 | */ 21 | 22 | #include "Sealer.h" 23 | using namespace std; 24 | using namespace dev; 25 | using namespace eth; 26 | 27 | -------------------------------------------------------------------------------- /libethcore/Sealer.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file Sealer.h 18 | * @author Gav Wood 19 | * @date 2014 20 | * 21 | * Determines the PoW algorithm. 22 | */ 23 | 24 | #pragma once 25 | 26 | #include 27 | #include 28 | #include 29 | #include "Common.h" 30 | 31 | namespace dev 32 | { 33 | namespace eth 34 | { 35 | 36 | class BlockInfo; 37 | 38 | class SealEngineFace 39 | { 40 | public: 41 | virtual ~SealEngineFace() {} 42 | 43 | virtual std::string name() const = 0; 44 | virtual unsigned revision() const = 0; 45 | virtual unsigned sealFields() const = 0; 46 | virtual bytes sealRLP() const = 0; 47 | 48 | bytes option(std::string const& _name) const { Guard l(x_options); return m_options.count(_name) ? m_options.at(_name) : bytes(); } 49 | bool setOption(std::string const& _name, bytes const& _value) { Guard l(x_options); try { if (onOptionChanging(_name, _value)) { m_options[_name] = _value; return true; } } catch (...) {} return false; } 50 | 51 | virtual strings sealers() const { return { "default" }; } 52 | virtual void setSealer(std::string const&) {} 53 | virtual void generateSeal(BlockInfo const& _bi) = 0; 54 | virtual void onSealGenerated(std::function const& _f) = 0; 55 | virtual void cancelGeneration() {} 56 | 57 | protected: 58 | virtual bool onOptionChanging(std::string const&, bytes const&) { return true; } 59 | void injectOption(std::string const& _name, bytes const& _value) { Guard l(x_options); m_options[_name] = _value; } 60 | 61 | private: 62 | mutable Mutex x_options; 63 | std::unordered_map m_options; 64 | }; 65 | 66 | template 67 | class SealEngineBase: public SealEngineFace 68 | { 69 | public: 70 | std::string name() const override { return Sealer::name(); } 71 | unsigned revision() const override { return Sealer::revision(); } 72 | unsigned sealFields() const override { return Sealer::BlockHeader::SealFields; } 73 | bytes sealRLP() const override { RLPStream s(sealFields()); s.appendRaw(typename Sealer::BlockHeader().sealFieldsRLP(), sealFields()); return s.out(); } 74 | }; 75 | 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /libstratum/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(EXECUTABLE ethstratum) 2 | 3 | aux_source_directory(. SRC_LIST) 4 | 5 | include_directories(..) 6 | include_directories(${Boost_INCLUDE_DIRS}) 7 | include_directories(${JSONCPP_INCLUDE_DIRS}) 8 | 9 | file(GLOB HEADERS "*.h") 10 | 11 | add_library(${EXECUTABLE} ${SRC_LIST} ${HEADERS}) 12 | target_link_libraries(${EXECUTABLE} ${Boost_SYSTEM_LIBRARY} ${Boost_THREAD_LIBRARY} ${Boost_REGEX_LIBRARY}) 13 | 14 | install( TARGETS ${EXECUTABLE} RUNTIME DESTINATION bin ARCHIVE DESTINATION lib LIBRARY DESTINATION lib ) 15 | install( FILES ${HEADERS} DESTINATION include/${EXECUTABLE} ) -------------------------------------------------------------------------------- /libstratum/EthStratumClient.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include "BuildInfo.h" 12 | 13 | 14 | using namespace std; 15 | using namespace boost::asio; 16 | using boost::asio::ip::tcp; 17 | using namespace dev; 18 | using namespace dev::eth; 19 | 20 | 21 | class EthStratumClient 22 | { 23 | public: 24 | EthStratumClient(GenericFarm * f, MinerType m, string const & host, string const & port, string const & user, string const & pass, int const & retries, int const & worktimeout, int const & protocol, string const & email); 25 | ~EthStratumClient(); 26 | 27 | void setFailover(string const & host, string const & port); 28 | void setFailover(string const & host, string const & port, string const & user, string const & pass); 29 | 30 | bool isRunning() { return m_running; } 31 | bool isConnected() { return m_connected && m_authorized; } 32 | h256 currentHeaderHash() { return m_current.headerHash; } 33 | bool current() { return m_current; } 34 | unsigned waitState() { return m_waitState; } 35 | bool submit(EthashProofOfWork::Solution solution); 36 | void reconnect(); 37 | private: 38 | void connect(); 39 | 40 | void disconnect(); 41 | void resolve_handler(const boost::system::error_code& ec, tcp::resolver::iterator i); 42 | void connect_handler(const boost::system::error_code& ec, tcp::resolver::iterator i); 43 | void work_timeout_handler(const boost::system::error_code& ec); 44 | 45 | void readline(); 46 | void handleResponse(const boost::system::error_code& ec); 47 | void readResponse(const boost::system::error_code& ec, std::size_t bytes_transferred); 48 | void processReponse(Json::Value& responseObject); 49 | 50 | MinerType m_minerType; 51 | 52 | cred_t * p_active; 53 | cred_t m_primary; 54 | cred_t m_failover; 55 | 56 | string m_worker; // eth-proxy only; 57 | 58 | bool m_authorized; 59 | bool m_connected; 60 | bool m_running = true; 61 | 62 | int m_retries = 0; 63 | int m_maxRetries; 64 | int m_worktimeout = 60; 65 | 66 | int m_waitState = MINER_WAIT_STATE_WORK; 67 | 68 | boost::mutex x_pending; 69 | int m_pending; 70 | string m_response; 71 | 72 | GenericFarm * p_farm; 73 | boost::mutex x_current; 74 | EthashProofOfWork::WorkPackage m_current; 75 | EthashProofOfWork::WorkPackage m_previous; 76 | 77 | bool m_stale = false; 78 | 79 | string m_job; 80 | string m_previousJob; 81 | EthashAux::FullType m_dag; 82 | 83 | boost::asio::io_service m_io_service; 84 | tcp::socket m_socket; 85 | 86 | boost::asio::streambuf m_requestBuffer; 87 | boost::asio::streambuf m_responseBuffer; 88 | 89 | boost::asio::deadline_timer * p_worktimer; 90 | 91 | int m_protocol; 92 | string m_email; 93 | 94 | double m_nextWorkDifficulty; 95 | 96 | h64 m_extraNonce; 97 | int m_extraNonceHexSize; 98 | 99 | void processExtranonce(std::string& enonce); 100 | }; -------------------------------------------------------------------------------- /libstratum/EthStratumClientV2.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "BuildInfo.h" 14 | 15 | 16 | using namespace std; 17 | using namespace boost::asio; 18 | using boost::asio::ip::tcp; 19 | using namespace dev; 20 | using namespace dev::eth; 21 | 22 | class EthStratumClientV2 : public Worker 23 | { 24 | public: 25 | EthStratumClientV2(GenericFarm * f, MinerType m, string const & host, string const & port, string const & user, string const & pass, int const & retries, int const & worktimeout, int const & protocol, string const & email); 26 | ~EthStratumClientV2(); 27 | 28 | void setFailover(string const & host, string const & port); 29 | void setFailover(string const & host, string const & port, string const & user, string const & pass); 30 | 31 | bool isRunning() { return m_running; } 32 | bool isConnected() { return m_connected && m_authorized; } 33 | h256 currentHeaderHash() { return m_current.headerHash; } 34 | bool current() { return m_current; } 35 | unsigned waitState() { return m_waitState; } 36 | bool submit(EthashProofOfWork::Solution solution); 37 | void reconnect(); 38 | private: 39 | void workLoop() override; 40 | void connect(); 41 | 42 | void disconnect(); 43 | void work_timeout_handler(const boost::system::error_code& ec); 44 | 45 | void processReponse(Json::Value& responseObject); 46 | 47 | MinerType m_minerType; 48 | 49 | cred_t * p_active; 50 | cred_t m_primary; 51 | cred_t m_failover; 52 | 53 | string m_worker; // eth-proxy only; 54 | 55 | bool m_authorized; 56 | bool m_connected; 57 | bool m_running = true; 58 | 59 | int m_retries = 0; 60 | int m_maxRetries; 61 | int m_worktimeout = 60; 62 | 63 | int m_waitState = MINER_WAIT_STATE_WORK; 64 | 65 | string m_response; 66 | 67 | GenericFarm * p_farm; 68 | mutex x_current; 69 | EthashProofOfWork::WorkPackage m_current; 70 | EthashProofOfWork::WorkPackage m_previous; 71 | 72 | bool m_stale = false; 73 | 74 | string m_job; 75 | string m_previousJob; 76 | EthashAux::FullType m_dag; 77 | 78 | boost::asio::io_service m_io_service; 79 | tcp::socket m_socket; 80 | 81 | boost::asio::streambuf m_requestBuffer; 82 | boost::asio::streambuf m_responseBuffer; 83 | 84 | boost::asio::deadline_timer * p_worktimer; 85 | 86 | int m_protocol; 87 | string m_email; 88 | 89 | double m_nextWorkDifficulty; 90 | 91 | h64 m_extraNonce; 92 | int m_extraNonceHexSize; 93 | 94 | void processExtranonce(std::string& enonce); 95 | }; -------------------------------------------------------------------------------- /releases/cuda-6.5/ethminer-0.9.41-genoil-1.0.5-cuda6.5.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Genoil/cpp-ethereum/07344156ffe35cc5949817f3d0660fb57bb18cdc/releases/cuda-6.5/ethminer-0.9.41-genoil-1.0.5-cuda6.5.zip -------------------------------------------------------------------------------- /releases/ethminer-0.9.41-genoil-1.0.7-chunked.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Genoil/cpp-ethereum/07344156ffe35cc5949817f3d0660fb57bb18cdc/releases/ethminer-0.9.41-genoil-1.0.7-chunked.zip -------------------------------------------------------------------------------- /releases/ethminer-0.9.41-genoil-1.0.8.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Genoil/cpp-ethereum/07344156ffe35cc5949817f3d0660fb57bb18cdc/releases/ethminer-0.9.41-genoil-1.0.8.zip -------------------------------------------------------------------------------- /releases/ethminer-0.9.41-genoil-1.1.6.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Genoil/cpp-ethereum/07344156ffe35cc5949817f3d0660fb57bb18cdc/releases/ethminer-0.9.41-genoil-1.1.6.zip -------------------------------------------------------------------------------- /releases/ethminer-0.9.41-genoil-1.1.7.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Genoil/cpp-ethereum/07344156ffe35cc5949817f3d0660fb57bb18cdc/releases/ethminer-0.9.41-genoil-1.1.7.zip --------------------------------------------------------------------------------