optimized
This commit is contained in:
parent
0573038c3d
commit
3fb7beb701
@ -1,5 +1,5 @@
|
|||||||
cmake_minimum_required(VERSION 3.31)
|
cmake_minimum_required(VERSION 3.31)
|
||||||
project(yggminer)
|
project(yggm)
|
||||||
file(GLOB ${PROJECT_NAME}SOURCES *.cpp)
|
file(GLOB ${PROJECT_NAME}SOURCES *.cpp)
|
||||||
file(GLOB ${PROJECT_NAME}HEADERS *.h)
|
file(GLOB ${PROJECT_NAME}HEADERS *.h)
|
||||||
add_executable(${PROJECT_NAME} sources/main.cpp)
|
add_executable(${PROJECT_NAME} sources/main.cpp)
|
||||||
|
10
README.md
10
README.md
@ -1,2 +1,8 @@
|
|||||||
# yggminer
|
# yggm
|
||||||
|
### Yggdrasil address miner
|
||||||
|
# How to build
|
||||||
|
```sh
|
||||||
|
git clone https://rcxpony.name/rcxpony/yggm.git && cd yggm
|
||||||
|
cmake -B build && cmake --build build -j$(nproc)
|
||||||
|
build/yggm
|
||||||
|
```
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include <memory.h>
|
#include <memory.h>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
#include <atomic>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <immintrin.h>
|
#include <immintrin.h>
|
||||||
using Key = std::array<unsigned char, 32>;
|
using Key = std::array<unsigned char, 32>;
|
||||||
@ -20,13 +21,13 @@ struct KeysBox {
|
|||||||
struct option {
|
struct option {
|
||||||
unsigned int proc = 0;
|
unsigned int proc = 0;
|
||||||
bool log = true;
|
bool log = true;
|
||||||
int high = 20;
|
std::atomic<int> high{ 20 };
|
||||||
std::string outputfile;
|
std::string outputfile;
|
||||||
};
|
};
|
||||||
static option conf;
|
static option conf;
|
||||||
int parameters(option& conf, std::string arg) {
|
int parameters(option& conf, std::string arg) {
|
||||||
if (arg.find(" ") != std::string::npos) {
|
if (arg.find(" ") != std::string::npos) {
|
||||||
const size_t npos = -1;
|
const unsigned long npos = std::string::npos;
|
||||||
int position = arg.find(" ");
|
int position = arg.find(" ");
|
||||||
std::istringstream ss(arg.substr(position + 1));
|
std::istringstream ss(arg.substr(position + 1));
|
||||||
if (arg.find("--threads") != npos || arg.find("-t") != npos) {
|
if (arg.find("--threads") != npos || arg.find("-t") != npos) {
|
||||||
@ -35,8 +36,10 @@ int parameters(option& conf, std::string arg) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (arg.find("--altitude") != npos || arg.find("-a") != npos) {
|
if (arg.find("--altitude") != npos || arg.find("-a") != npos) {
|
||||||
ss >> std::hex >> conf.high;
|
int tmp_high;
|
||||||
|
ss >> std::hex >> tmp_high;
|
||||||
if (ss.fail()) return 1;
|
if (ss.fail()) return 1;
|
||||||
|
conf.high = tmp_high;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -44,6 +47,7 @@ int parameters(option& conf, std::string arg) {
|
|||||||
else if (arg == "--altitude" || arg == "-a") return 777;
|
else if (arg == "--altitude" || arg == "-a") return 777;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void displayConfig() {
|
void displayConfig() {
|
||||||
unsigned short processor_count = std::thread::hardware_concurrency();
|
unsigned short processor_count = std::thread::hardware_concurrency();
|
||||||
if (conf.proc == 0 || conf.proc > static_cast<unsigned int>(processor_count)) {
|
if (conf.proc == 0 || conf.proc > static_cast<unsigned int>(processor_count)) {
|
||||||
@ -63,23 +67,25 @@ std::string getAddress(const Address& rawAddr) {
|
|||||||
}
|
}
|
||||||
inline std::string keyToString(const Key& key) {
|
inline std::string keyToString(const Key& key) {
|
||||||
std::string result;
|
std::string result;
|
||||||
result.reserve(64);
|
result.resize(64);
|
||||||
|
const char* hexDigits = "0123456789abcdef";
|
||||||
for (int i = 0; i < 32; ++i) {
|
for (int i = 0; i < 32; ++i) {
|
||||||
result.push_back("0123456789abcdef"[key.data()[i] >> 4]);
|
result[2 * i] = hexDigits[key[i] >> 4];
|
||||||
result.push_back("0123456789abcdef"[key.data()[i] & 0x0F]);
|
result[2 * i + 1] = hexDigits[key[i] & 0x0F];
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Key bitwiseInverse(const Key& key) noexcept {
|
inline Key bitwiseInverse(const Key& key) noexcept {
|
||||||
Key inverted;
|
Key inverted;
|
||||||
std::transform(key.begin(), key.end(), inverted.begin(), [](unsigned char byte) {
|
for (unsigned long i = 0; i < 32; i++) {
|
||||||
return static_cast<unsigned char>(~byte);
|
inverted[i] = ~key[i];
|
||||||
});
|
}
|
||||||
return inverted;
|
return inverted;
|
||||||
}
|
}
|
||||||
int getOnes(const Key&& value) noexcept {
|
int getOnes(const Key&& value) noexcept {
|
||||||
int leadOnes = 0;
|
int leadOnes = 0;
|
||||||
for (int i = 0; i < 17; ++i) {
|
for (unsigned char i = 0; i < 17; ++i) {
|
||||||
if (value[i] == 0xFF) {
|
if (value[i] == 0xFF) {
|
||||||
leadOnes += 8;
|
leadOnes += 8;
|
||||||
} else {
|
} else {
|
||||||
@ -95,13 +101,17 @@ int getOnes(const Key&& value) noexcept {
|
|||||||
return leadOnes;
|
return leadOnes;
|
||||||
}
|
}
|
||||||
void miner_thread() {
|
void miner_thread() {
|
||||||
KeysBox keys;
|
while (true) {
|
||||||
int ones;
|
KeysBox keys = getKeyPair();
|
||||||
while (1) {
|
int ones = getOnes(bitwiseInverse(keys.PublicKey));
|
||||||
keys = getKeyPair();
|
int current = conf.high.load(std::memory_order_relaxed);
|
||||||
if ((ones = getOnes(bitwiseInverse(keys.PublicKey))) > conf.high) {
|
if (ones > current) {
|
||||||
conf.high = ones;
|
while (!conf.high.compare_exchange_weak(current, ones, std::memory_order_relaxed)) {
|
||||||
printf("\nAddr:\t2%x\nPK:\t%s\nSK:\t%s\n", ones, keyToString(keys.PublicKey).c_str(), keyToString(keys.PrivateKey).c_str());
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -137,6 +147,7 @@ int main(int argc, char* argv[]) {
|
|||||||
displayConfig();
|
displayConfig();
|
||||||
startThreads();
|
startThreads();
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
void getRawAddress(int lErase, Key& InvertedPublicKey, Address& rawAddr) {
|
void getRawAddress(int lErase, Key& InvertedPublicKey, Address& rawAddr) {
|
||||||
lErase++;
|
lErase++;
|
||||||
const int bitsToShift = lErase % 8;
|
const int bitsToShift = lErase % 8;
|
||||||
@ -155,7 +166,6 @@ void getRawAddress(int lErase, Key& InvertedPublicKey, Address& rawAddr) {
|
|||||||
rawAddr[1] = static_cast<unsigned char>(lErase - 1);
|
rawAddr[1] = static_cast<unsigned char>(lErase - 1);
|
||||||
memcpy(&rawAddr[2], &InvertedPublicKey[start], 14);
|
memcpy(&rawAddr[2], &InvertedPublicKey[start], 14);
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
void logKeys(const Address& raw, const KeysBox& keys) {
|
void logKeys(const Address& raw, const KeysBox& keys) {
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
std::cout << " Address: " << getAddress(raw) << std::endl;
|
std::cout << " Address: " << getAddress(raw) << std::endl;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user