optimized

This commit is contained in:
fluttershy 2025-03-01 16:38:11 +05:00
parent 0573038c3d
commit 3fb7beb701
3 changed files with 37 additions and 21 deletions

View File

@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.31)
project(yggminer)
project(yggm)
file(GLOB ${PROJECT_NAME}SOURCES *.cpp)
file(GLOB ${PROJECT_NAME}HEADERS *.h)
add_executable(${PROJECT_NAME} sources/main.cpp)

View File

@ -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
```

View File

@ -9,6 +9,7 @@
#include <memory.h>
#include <thread>
#include <regex>
#include <atomic>
#include <arpa/inet.h>
#include <immintrin.h>
using Key = std::array<unsigned char, 32>;
@ -20,13 +21,13 @@ struct KeysBox {
struct option {
unsigned int proc = 0;
bool log = true;
int high = 20;
std::atomic<int> high{ 20 };
std::string outputfile;
};
static option conf;
int parameters(option& conf, std::string arg) {
if (arg.find(" ") != std::string::npos) {
const size_t npos = -1;
const unsigned long npos = std::string::npos;
int position = arg.find(" ");
std::istringstream ss(arg.substr(position + 1));
if (arg.find("--threads") != npos || arg.find("-t") != npos) {
@ -35,8 +36,10 @@ int parameters(option& conf, std::string arg) {
return 0;
}
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;
conf.high = tmp_high;
return 0;
}
}
@ -44,6 +47,7 @@ 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<unsigned int>(processor_count)) {
@ -63,23 +67,25 @@ std::string getAddress(const Address& rawAddr) {
}
inline std::string keyToString(const Key& key) {
std::string result;
result.reserve(64);
result.resize(64);
const char* hexDigits = "0123456789abcdef";
for (int i = 0; i < 32; ++i) {
result.push_back("0123456789abcdef"[key.data()[i] >> 4]);
result.push_back("0123456789abcdef"[key.data()[i] & 0x0F]);
result[2 * i] = hexDigits[key[i] >> 4];
result[2 * i + 1] = hexDigits[key[i] & 0x0F];
}
return result;
}
inline Key bitwiseInverse(const Key& key) noexcept {
Key inverted;
std::transform(key.begin(), key.end(), inverted.begin(), [](unsigned char byte) {
return static_cast<unsigned char>(~byte);
});
for (unsigned long i = 0; i < 32; i++) {
inverted[i] = ~key[i];
}
return inverted;
}
int getOnes(const Key&& value) noexcept {
int leadOnes = 0;
for (int i = 0; i < 17; ++i) {
for (unsigned char i = 0; i < 17; ++i) {
if (value[i] == 0xFF) {
leadOnes += 8;
} else {
@ -95,13 +101,17 @@ int getOnes(const Key&& value) noexcept {
return leadOnes;
}
void miner_thread() {
KeysBox keys;
int ones;
while (1) {
keys = getKeyPair();
if ((ones = getOnes(bitwiseInverse(keys.PublicKey))) > conf.high) {
conf.high = ones;
printf("\nAddr:\t2%x\nPK:\t%s\nSK:\t%s\n", ones, keyToString(keys.PublicKey).c_str(), keyToString(keys.PrivateKey).c_str());
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());
}
}
}
}
@ -137,6 +147,7 @@ int main(int argc, char* argv[]) {
displayConfig();
startThreads();
}
/*
void getRawAddress(int lErase, Key& InvertedPublicKey, Address& rawAddr) {
lErase++;
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);
memcpy(&rawAddr[2], &InvertedPublicKey[start], 14);
}
/*
void logKeys(const Address& raw, const KeysBox& keys) {
std::cout << std::endl;
std::cout << " Address: " << getAddress(raw) << std::endl;