#include #include #include "yespower.h" #include #include #include #include #include #include #include #include yespower_params_t yespower_params = { .version = YESPOWER_1_0, .N = 2048, .r = 16 }; using uint256 = std::array; uint256 CalculateMerkleRoot(const std::string &genesisMessage, const std::string &publicKey) { uint256 merkleRoot = {}; std::string combined = genesisMessage + publicKey; std::hash hasher; size_t hash = hasher(combined); memcpy(merkleRoot.data(), &hash, sizeof(hash)); return merkleRoot; } struct CBlockHeader { uint32_t nTime; uint32_t nBits; uint32_t nNonce; uint256 hashMerkleRoot; std::string Serialize() const { std::ostringstream ss; ss << nTime << nBits << nNonce; for (const auto &byte : hashMerkleRoot) { ss << std::hex << std::setw(2) << std::setfill('0') << (int)byte; } return ss.str(); } }; class arith_uint256 { uint64_t value = 0; public: void SetCompact(uint32_t nBits) { value = nBits; } bool operator<=(const arith_uint256 &other) const { return value <= other.value; } std::string GetHex() const { std::ostringstream ss; ss << std::hex << value; return ss.str(); } }; std::atomic found(false); std::mutex printMutex; void MineThread(CBlockHeader genesisBlock, arith_uint256 hashTarget, int threadID, int numThreads) { uint256 resultHash = {}; uint32_t nonce = threadID; while (!found) { genesisBlock.nNonce = nonce; std::string serializedHeader = genesisBlock.Serialize(); yespower_tls(reinterpret_cast(serializedHeader.c_str()), serializedHeader.size(), &yespower_params, reinterpret_cast(resultHash.data())); arith_uint256 newhash; memcpy(&newhash, resultHash.data(), sizeof(newhash)); if (newhash <= hashTarget) { found = true; std::lock_guard lock(printMutex); std::cout << "\nGenesis Block Found by Thread " << threadID << "!\n"; std::cout << "Hash: "; for (auto byte : resultHash) { printf("%02x", byte); } std::cout << "\nnTime: " << genesisBlock.nTime << "\n"; std::cout << "nNonce: " << genesisBlock.nNonce << "\n"; std::cout << "Merkle Root: "; for (auto byte : genesisBlock.hashMerkleRoot) { printf("%02x", byte); } std::cout << "\n"; break; } nonce += numThreads; } } void MineGenesis() { const uint32_t nBits = 0x1e00ffff; const std::string genesisMessage = "One coin to rule them all One coin to find them One coin to bring them And in the darkness bind them"; const std::string publicKey = "043056301006072a8648ce3d020106052b8104000a034200042d23252e243d07ee9a6bcf82200b6f98748a90323b36513ea3f62165d75b12f4269cb91e3c0a01572ab64997e62615e9b25ac97413eccabb2391eebc4c633dd7"; CBlockHeader genesisBlock; genesisBlock.nTime = std::time(0); genesisBlock.nBits = nBits; genesisBlock.nNonce = 0; genesisBlock.hashMerkleRoot = CalculateMerkleRoot(genesisMessage, publicKey); std::cout << "Genesis Block Parameters:\n"; std::cout << "nTime: " << genesisBlock.nTime << "\n"; std::cout << "nBits: " << std::hex << nBits << "\n"; std::cout << "Public Key: " << publicKey << "\n"; std::cout << "Genesis Message: " << genesisMessage << "\n"; arith_uint256 hashTarget; hashTarget.SetCompact(nBits); int maxThreads = std::thread::hardware_concurrency(); int numThreads = static_cast(maxThreads * 0.8); // Verwende 80% der verfügbaren Threads std::vector threads; for (int i = 0; i < numThreads; ++i) { threads.emplace_back(MineThread, genesisBlock, hashTarget, i, numThreads); } for (auto &t : threads) { t.join(); } if (!found) { std::cout << "Genesis Block not found. Adjust parameters and retry.\n"; } } int main() { MineGenesis(); return 0; } # create public key with my script # compile # g++ -o genesis create_genesis.cpp -lyespower # start # ./genesis