Post
Topic
Board Bitcoin Discussion
Re: Bitcoin puzzle transaction ~32 BTC prize to who solves it
by
nomachine
on 27/10/2023, 08:22:18 UTC
How is that i9 able to outperform the 4090 in straight brute forcing?

It depends on what the script calculates and how it calculates.
Are only compressed keys counted or all together? Is it a key or a hash?
You can practice in Python to see how counting works.

Code:
import sys, os, time, secrets, multiprocessing, random
import binascii, base58, hashlib, ecdsa

def generate_private_key_WIF(start, miss):
    characters = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
    return start + "".join(secrets.choice(characters) for _ in range(miss))

def format_hash_rate(hash_rate):
    suffixes = ["", "k", "M", "G", "T", "P"]

    magnitude = 0
    while hash_rate >= 1000 and magnitude < len(suffixes) - 1:
        hash_rate /= 1000.0
        magnitude += 1

    return f"{hash_rate:.2f} {suffixes[magnitude]}Hash/s"

def check_private_key(start, miss, target_binary, min_range, max_range):
    while not STOP_EVENT.is_set():
        private_key_WIF = generate_private_key_WIF(start, miss)
        dec = int(binascii.hexlify(base58.b58decode(private_key_WIF))[2:-10].decode("utf-8")[0:64], 16)
        if min_range <= dec <= max_range:
            private_key_bytes = (b'\x00' * 32)[:-len(dec.to_bytes((dec.bit_length() + 7) // 8, 'big'))] + dec.to_bytes((dec.bit_length() + 7) // 8, 'big')
            signing_key = ecdsa.SigningKey.from_string(private_key_bytes, curve=ecdsa.SECP256k1)
            HASH160 = hashlib.new('ripemd160', hashlib.sha256(signing_key.get_verifying_key().to_string("compressed")).digest()).digest()

            hashes_per_second = 0
            target_hash_count = 1000000  # You can adjust this to your desired count
            start_time = time.time()

            while hashes_per_second < target_hash_count:
                HASH160.hex()
                hashes_per_second += 1

            end_time = time.time()
            elapsed_time = end_time - start_time
            hashes_per_second = target_hash_count / elapsed_time

            formatted_hash_rate = format_hash_rate(hashes_per_second)

            message = "\r[+] Hashes per second: {}".format(formatted_hash_rate)
            messages = []
            messages.append(message)
            output = "\033[01;33m" + ''.join(messages) + "\r"
            sys.stdout.write(output)

            if HASH160 == target_binary:
                dec_to_hex = hex(dec).split('x')[-1]
                HASH160_wif = base58.b58encode(b'\x80' + private_key_bytes + b'\x01' + hashlib.sha256(hashlib.sha256(b'\x80' + private_key_bytes + b'\x01').digest()).digest()[:4]).decode()
                bitcoin_address = base58.b58encode(b'\x00' + HASH160 + hashlib.sha256(hashlib.sha256(b'\x00' + HASH160).digest()).digest()[:4]).decode()
                t = time.ctime()
                sys.stdout.write(f"\033[0m\n\n")
                sys.stdout.write(f"[+] SOLVED:    |\033[32m {t}                                                                  \033[0m\n")
                sys.stdout.write(f"[+] Key Found: |\033[32m {dec_to_hex}                                                \033[0m\n"
                                 f"[+] WIF:       |\033[32m {HASH160_wif}                                                  \033[0m\n"
                                 f"[+] Address:   |\033[32m {bitcoin_address}                                           \033[0m")
                sys.stdout.flush()

                with open("KEYFOUNDKEYFOUND.txt", "a") as f:
                    f.write("SOLVED: " + str(t) + '\n' + "HEX: " + str(dec_to_hex) + '\n' + "WIF: " + str(HASH160_wif) + '\n' + "Address: " + str(bitcoin_address) + '\n\n')
                    f.flush()
                    f.close()

                STOP_EVENT.set()
                sys.stdout.write("\033[?25h")
                sys.stdout.flush()
                return

if __name__ == '__main__':
    start = "KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qZ"
    miss = 52 - (len(start))
    min_range = 36893488147419103231
    max_range = 73786976294838206463
    target_hex = "20d45a6a762535700ce9e0b216e31994335db8a5"
    target_binary = bytes.fromhex(target_hex)
    puzzle = 0
    while max_range >= 2 ** puzzle:
        puzzle += 1
    if min_range <= (2 ** puzzle) - 1:
        puzzle = puzzle

    STOP_EVENT = multiprocessing.Event()
    num_processes = multiprocessing.cpu_count()

    os.system("clear")
    t = time.ctime()
    sys.stdout.write(f"\033[01;33m[+] {t}\n")
    sys.stdout.write(f"\033[01;33m[+] Puzzle = {puzzle}\n")
    sys.stdout.write(f"\033[01;33m[+] Ending characters missing: {miss}\n")
    sys.stdout.write(f"\033[01;33m[+] Public Key Hash (Hash 160): {target_hex}\n")
    sys.stdout.flush()

    pool = multiprocessing.Pool(processes=num_processes)

    for i in range(num_processes):
        pool.apply_async(check_private_key, args=(start, miss, target_binary, min_range, max_range))

    pool.close()
    pool.join()


Let's say in raw Python you can achieve about 3.98MHash/s on 12 cores
In the same Python with the kangaroo algorithm I have about 50MKeys/s (if you count jumps)
In C++ everything is 10 or 100 times more (if is GPU).
What exactly is counted depends on which algorithm was used  and how is used. Grin