optimized
This commit is contained in:
parent
3fb7beb701
commit
193575da8a
@ -1,8 +1,10 @@
|
||||
cmake_minimum_required(VERSION 3.31)
|
||||
project(yggm)
|
||||
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")
|
||||
target_link_libraries(${PROJECT_NAME} pthread)
|
||||
target_link_libraries(${PROJECT_NAME} sodium)
|
||||
target_link_libraries(${PROJECT_NAME} sodium)
|
||||
target_link_libraries(${PROJECT_NAME} OpenSSL::SSL OpenSSL::Crypto)
|
@ -12,8 +12,10 @@
|
||||
#include <atomic>
|
||||
#include <arpa/inet.h>
|
||||
#include <immintrin.h>
|
||||
using Key = std::array<unsigned char, 32>;
|
||||
using Address = std::array<unsigned char, 16>;
|
||||
//using Key = std::array<unsigned char, 32>;
|
||||
//using Address = std::array<unsigned char, 16>;
|
||||
using Address = unsigned char[16];
|
||||
using Key = unsigned char[32];
|
||||
struct KeysBox {
|
||||
Key PublicKey;
|
||||
Key PrivateKey;
|
||||
@ -21,7 +23,7 @@ struct KeysBox {
|
||||
struct option {
|
||||
unsigned int proc = 0;
|
||||
bool log = true;
|
||||
std::atomic<int> high{ 20 };
|
||||
int high = 20;
|
||||
std::string outputfile;
|
||||
};
|
||||
static option conf;
|
||||
@ -57,15 +59,15 @@ void displayConfig() {
|
||||
}
|
||||
KeysBox getKeyPair() noexcept {
|
||||
KeysBox keys;
|
||||
crypto_sign_ed25519_keypair(keys.PublicKey.data(), keys.PrivateKey.data());
|
||||
crypto_sign_ed25519_keypair(keys.PublicKey, keys.PrivateKey);
|
||||
return keys;
|
||||
}
|
||||
std::string getAddress(const Address& rawAddr) {
|
||||
char ipStrBuf[46];
|
||||
inet_ntop(AF_INET6, rawAddr.data(), ipStrBuf, 46);
|
||||
inet_ntop(AF_INET6, rawAddr, ipStrBuf, 46);
|
||||
return std::string(ipStrBuf);
|
||||
}
|
||||
inline std::string keyToString(const Key& key) {
|
||||
inline std::string keyToString(const unsigned char* key) {
|
||||
std::string result;
|
||||
result.resize(64);
|
||||
const char* hexDigits = "0123456789abcdef";
|
||||
@ -75,17 +77,14 @@ inline std::string keyToString(const Key& key) {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
inline Key bitwiseInverse(const Key& key) noexcept {
|
||||
Key inverted;
|
||||
for (unsigned long i = 0; i < 32; i++) {
|
||||
inline void bitwiseInverse(const unsigned char* key, Key inverted) noexcept {
|
||||
for (size_t i = 0; i < 32; i++) {
|
||||
inverted[i] = ~key[i];
|
||||
}
|
||||
return inverted;
|
||||
}
|
||||
int getOnes(const Key&& value) noexcept {
|
||||
int getOnes(const Key value) noexcept {
|
||||
int leadOnes = 0;
|
||||
for (unsigned char i = 0; i < 17; ++i) {
|
||||
for (unsigned char i = 0; i < 5; i++) {
|
||||
if (value[i] == 0xFF) {
|
||||
leadOnes += 8;
|
||||
} else {
|
||||
@ -101,17 +100,13 @@ int getOnes(const Key&& value) noexcept {
|
||||
return leadOnes;
|
||||
}
|
||||
void miner_thread() {
|
||||
Key inv;
|
||||
while (true) {
|
||||
KeysBox keys = getKeyPair();
|
||||
int ones = getOnes(bitwiseInverse(keys.PublicKey));
|
||||
int current = conf.high.load(std::memory_order_relaxed);
|
||||
if (ones > current) {
|
||||
while (!conf.high.compare_exchange_weak(current, ones, std::memory_order_relaxed)) {
|
||||
if (ones <= current) break;
|
||||
}
|
||||
if (ones > current) {
|
||||
printf("\nAddr:\t2%x\nPK:\t%s\nSK:\t%s\n", ones, keyToString(keys.PublicKey).c_str(), keyToString(keys.PrivateKey).c_str());
|
||||
}
|
||||
bitwiseInverse(keys.PublicKey, inv);
|
||||
int 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user