diff --git a/CMakeLists.txt b/CMakeLists.txt index a876525..b91d4c6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ find_package(OpenSSL REQUIRED) file(GLOB ${PROJECT_NAME}SOURCES *.cpp) file(GLOB ${PROJECT_NAME}HEADERS *.h) add_executable(${PROJECT_NAME} sources/main.cpp) -set(CMAKE_CXX_FLAGS_RELEASE "-march=native -O3 -ffast-math -ftree-vectorize -fdelete-null-pointer-checks -fno-exceptions -fno-rtti -finline-functions -pthread -fomit-frame-pointer -pipe -Wall -Wextra -flto=full") +set(CMAKE_CXX_FLAGS_RELEASE "-march=native -O3 -ffast-math -mavx2 -m64 -ftree-vectorize -ftree-slp-vectorize -fdelete-null-pointer-checks -fno-exceptions -fno-rtti -finline-functions -pthread -fomit-frame-pointer -pipe -Wall -Wextra -flto=full") target_link_libraries(${PROJECT_NAME} pthread) target_link_libraries(${PROJECT_NAME} sodium) target_link_libraries(${PROJECT_NAME} OpenSSL::SSL OpenSSL::Crypto) \ No newline at end of file diff --git a/sources/main.cpp b/sources/main.cpp index c78bde9..402579b 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -12,14 +12,6 @@ #include #include #include -//using Key = std::array; -//using Address = std::array; -using Address = unsigned char[16]; -using Key = unsigned char[32]; -struct KeysBox { - Key PublicKey; - Key PrivateKey; -}; struct option { unsigned int proc = 0; bool log = true; @@ -49,7 +41,6 @@ int parameters(option& conf, std::string arg) { else if (arg == "--altitude" || arg == "-a") return 777; return 0; } - void displayConfig() { unsigned short processor_count = std::thread::hardware_concurrency(); if (conf.proc == 0 || conf.proc > static_cast(processor_count)) { @@ -57,11 +48,12 @@ void displayConfig() { } std::cout << " Threads: " << conf.proc << ", " << "high addresses (2" << std::setw(2) << std::setfill('0') << std::hex << conf.high << "+)" << std::dec << std::endl; } -KeysBox getKeyPair() noexcept { - KeysBox keys; - crypto_sign_ed25519_keypair(keys.PublicKey, keys.PrivateKey); - return keys; -} +using Address = unsigned char[16]; +using Key = unsigned char[32]; +struct KeysBox { + Key PublicKey; + Key PrivateKey; +}; std::string getAddress(const Address& rawAddr) { char ipStrBuf[46]; inet_ntop(AF_INET6, rawAddr, ipStrBuf, 46); @@ -71,48 +63,50 @@ inline std::string keyToString(const unsigned char* key) { std::string result; result.resize(64); const char* hexDigits = "0123456789abcdef"; - for (int i = 0; i < 32; ++i) { + for (unsigned char i = 0; i < 32; i++) { result[2 * i] = hexDigits[key[i] >> 4]; result[2 * i + 1] = hexDigits[key[i] & 0x0F]; } return result; } -inline void bitwiseInverse(const unsigned char* key, Key inverted) noexcept { - for (size_t i = 0; i < 32; i++) { - inverted[i] = ~key[i]; - } +inline void bitwiseInverse(const unsigned char* key, Key& inverted) noexcept { + __m256i chunk = _mm256_loadu_si256(reinterpret_cast(key)); + chunk = _mm256_xor_si256(chunk, _mm256_set1_epi8(0xFF)); + _mm256_storeu_si256(reinterpret_cast<__m256i*>(inverted), chunk); } -int getOnes(const Key value) noexcept { +inline unsigned char getOnes(const Key& value) noexcept { int leadOnes = 0; - for (unsigned char i = 0; i < 5; i++) { + for (unsigned char i = 0; i < 17; i++) { + if (value[0] != 0xFF) return leadOnes; if (value[i] == 0xFF) { leadOnes += 8; } else { - for (int j = 7; j >= 0; j--) { - if (value[i] & (1 << j)) { - leadOnes++; - } else { + for (unsigned char j = 7; j < 8; j--) { + if (!(value[i] & (1 << j))) { return leadOnes; } + leadOnes++; } } } return leadOnes; } -void miner_thread() { +void miner_thread() noexcept { Key inv; + KeysBox keys; + unsigned char ones; while (true) { - KeysBox keys = getKeyPair(); + crypto_sign_ed25519_keypair(keys.PublicKey, keys.PrivateKey); bitwiseInverse(keys.PublicKey, inv); - int ones = getOnes(inv); + ones = getOnes(inv); if (ones > conf.high) { printf("\nAddr:\t2%x/%d\nPK:\t%s\nSK:\t%s\n", conf.high = ones, ones, keyToString(keys.PublicKey).c_str(), keyToString(keys.PrivateKey).c_str()); } } } -void startThreads() { +void startThreads() noexcept { std::vector threads; - for (unsigned int i = 0; i < conf.proc; i++) { + for (unsigned char i = 0; i < conf.proc; i++) { threads.emplace_back(miner_thread); } for (auto& thread : threads) {