Post
Topic
Board Bitcoin Discussion
Re: Bitcoin puzzle transaction ~32 BTC prize to who solves it
by
mcdouglasx
on 29/09/2023, 15:26:40 UTC
Hello everyone, and especially those who still remember me)
Has anyone used OpenSSL to generate keys?
Probably not..

main.cpp (*Int class require some code changes within the SECP256k1 library to support BIGNUM* directly.)


Yes... Grin

But it is still slow. Even 5M keys/s per core muscles is not enough for such a large range. Undecided

hi there nomachine, is there a compiled exe there.. or not. thanks man

I have solution for Linux now. I have no idea how this can work on Windows - I haven't had it in years. It is about 5-6 M keys/s per core brute force script.

Code:
sudo apt update && sudo apt install libssl-dev

Code:
git clone https://github.com/JeanLucPons/VanitySearch.git

Change in that folder main.cpp to be:
Code:
#include "SECP256k1.h"
#include "Int.h"
#include <iostream>
#include <fstream>
#include <string>
#include <ctime>
#include <iomanip>
#include <sstream>
#include <thread>
#include <vector>
#include <mutex>
#include <memory>
#include <openssl/bn.h>

const int numThreads = 128; // You can adjust this number based on your CPU cores

// Function to generate a random private key using BIGNUM
BIGNUM* generateRandomPrivateKey(const BIGNUM* minKey, const BIGNUM* maxKey) {
    BIGNUM* randomPrivateKey = BN_new();
    BN_rand_range(randomPrivateKey, maxKey);

    // Ensure the generated key is within the desired range
    while (BN_cmp(randomPrivateKey, minKey) < 0) {
        BN_rand_range(randomPrivateKey, maxKey);
    }

    return randomPrivateKey;
}

// Function to convert a BIGNUM to Int
Int bignumToBigInt(const BIGNUM* bignum) {
    char* bignumStr = BN_bn2dec(bignum);
    Int bigInt;
    bigInt.SetBase10(bignumStr);
    OPENSSL_free(bignumStr);
    return bigInt;
}

// Function to generate keys and check for a specific address
void generateKeysAndCheckForAddress(BIGNUM* minKey, BIGNUM* maxKey, std::shared_ptr<Secp256K1> secp256k1, const std::string& targetAddress) {
    while (true) {
        BIGNUM* randomPrivateKey = generateRandomPrivateKey(minKey, maxKey);

        // Convert the BIGNUM private key to an Int
        Int privateKey = bignumToBigInt(randomPrivateKey);

        // Continue with the rest of the address generation and checking logic
        Point publicKey;
        std::string caddr;
        std::string wifc;

        publicKey = secp256k1->ComputePublicKey(&privateKey);
        caddr = secp256k1->GetAddress(0, true, publicKey);
        wifc = secp256k1->GetPrivAddress(true, privateKey);

        // Display the generated address
        std::string message = "\r\033[01;33m[+] " + caddr;
        std::cout << message << "\e[?25l";
        std::cout.flush();

        // Check if the generated address matches the target address
        if (caddr.find(targetAddress) != std::string::npos) {
            time_t currentTime = std::time(nullptr);

            // Format the current time into a human-readable string
            std::tm tmStruct = *std::localtime(&currentTime);
            std::stringstream timeStringStream;
            timeStringStream << std::put_time(&tmStruct, "%Y-%m-%d %H:%M:%S");
            std::string formattedTime = timeStringStream.str();

            std::cout << "\n\033[32m[+] PUZZLE SOLVED: " << formattedTime << "\033[0m" << std::endl;
            std::cout << "\033[32m[+] WIF: " << wifc << "\033[0m" << std::endl;

            // Append the private key information to a file if it matches
            std::ofstream file("KEYFOUNDKEYFOUND.txt", std::ios::app);
            if (file.is_open()) {
                file << "\nPUZZLE SOLVED " << formattedTime;
                file << "\nPublic Address Compressed: " << caddr;
                file << "\nPrivatekey (dec): " << privateKey.GetBase10();
                file << "\nPrivatekey Compressed (wif): " << wifc;
                file << "\n----------------------------------------------------------------------------------------------------------------------------------";
                file.close();
            }

            // Free the BIGNUM and break the loop
            BN_free(randomPrivateKey);
            break;
        }

        // Free the BIGNUM
        BN_free(randomPrivateKey);

        // Convert the max key to an Int
        Int maxInt;
        maxInt.SetBase10(BN_bn2dec(maxKey));

        if (privateKey.IsGreater(&maxInt)) {
            break;
        }
    }
}


int main() {
    // Clear the console
    std::system("clear");

    time_t currentTime = std::time(nullptr);
    std::cout << "\033[01;33m[+] " << std::ctime(&currentTime) << "\r";
    std::cout.flush();

    BIGNUM* minKeyBN = BN_new(); // Initialize minKeyBN
    BIGNUM* maxKeyBN = BN_new(); // Initialize maxKeyBN

    // Configuration for the Puzzle
    // Set minKeyBN and maxKeyBN using the provided base 10 values
    BN_dec2bn(&minKeyBN, "62079069358943824031");
    BN_dec2bn(&maxKeyBN, "67079069358943924031");
    std::string targetAddress = "13zb1hQbWVsc2S7ZTZnP2G4undNNpdh5so";

    // Initialize SECP256k1
    std::shared_ptr<Secp256K1> secp256k1 = std::make_shared<Secp256K1>();
    secp256k1->Init();

    // Create threads for key generation and checking
    std::vector<std::thread> threads;

    for (int i = 0; i < numThreads; ++i) {
        threads.emplace_back(generateKeysAndCheckForAddress, minKeyBN, maxKeyBN, secp256k1, targetAddress);
    }

    // Wait for all threads to finish
    for (std::thread& thread : threads) {
        thread.join();
    }

    // Cleanup BIGNUM variables
    BN_free(minKeyBN);
    BN_free(maxKeyBN);

    return 0;
}

Change Makefile to be:
Code:
SRC = Base58.cpp IntGroup.cpp main.cpp Random.cpp Timer.cpp \
      Int.cpp IntMod.cpp Point.cpp SECP256K1.cpp \
      hash/ripemd160.cpp hash/sha256.cpp hash/sha512.cpp \
      hash/ripemd160_sse.cpp hash/sha256_sse.cpp Bech32.cpp

OBJDIR = obj

OBJET = $(addprefix $(OBJDIR)/, \
        Base58.o IntGroup.o main.o Random.o Int.o Timer.o \
        IntMod.o Point.o SECP256K1.o \
        hash/ripemd160.o hash/sha256.o hash/sha512.o \
        hash/ripemd160_sse.o hash/sha256_sse.o Bech32.o)

CXX = g++
CXXFLAGS = -m64 -mssse3 -Wno-write-strings -O2 -I.

LFLAGS = -lpthread -lssl -lcrypto

$(OBJDIR)/%.o : %.cpp
$(CXX) $(CXXFLAGS) -o $@ -c $<



VanitySearch: $(OBJET)
@echo Making Lottery...
$(CXX) $(OBJET) $(LFLAGS) -o LOTTO.bin && chmod +x LOTTO.bin

$(OBJET): | $(OBJDIR) $(OBJDIR)/hash

$(OBJDIR):
mkdir -p $(OBJDIR)

$(OBJDIR)/hash: $(OBJDIR)
cd $(OBJDIR) && mkdir -p hash

clean:
@echo Cleaning...
@rm -f obj/*.o
@rm -f obj/hash/*.o

Code:
make

and  start
Code:
./LOTTO.bin

Good luck Wink

For Windows, I suppose you can try to compile it with msys2 and mingw, installing the toolchain with Pacman, or with Cygwin to avoid errors regarding Linux commands in Windows.