Post
Topic
Board Bitcoin Discussion
Re: Bitcoin puzzle transaction ~32 BTC prize to who solves it
by
hari1987
on 24/11/2023, 10:33:50 UTC
...

it would be awesome if there's a CUDA version for it.

I can give you this same script that works in C++ but you have to do the GPU part yourself.CUDA programming can be complex, and proper error handling and synchronization are crucial. Also, not all parts of your program may benefit from GPU acceleration, so it's essential to profile and optimize as needed.


Code:
import bit
import hashlib, random
import platform
from time import time
import os
import sys
import ctypes

nbits = 130
low = 2**(nbits-1)
high = -1+2**nbits
diff = high - low

filename ='tes.bin'
with open(filename,'rb') as f:
    add = f.read()#.split()
#add = set(add)

if platform.system().lower().startswith('win'):
    dllfile = 'ice_secp256k1.dll'
    if os.path.isfile(dllfile) == True:
        pathdll = os.path.realpath(dllfile)
        ice = ctypes.CDLL(pathdll)
    else:
        print('File {} not found'.format(dllfile))

elif platform.system().lower().startswith('lin'):
    dllfile = 'ice_secp256k1.so'
    if os.path.isfile(dllfile) == True:
        pathdll = os.path.realpath(dllfile)
        ice = ctypes.CDLL(pathdll)
    else:
        print('File {} not found'.format(dllfile))
else:
    print('[-] Unsupported Platform currently for ctypes dll method. Only [Windows and Linux] is working')
    sys.exit()

ice.scalar_multiplication.argtypes = [ctypes.c_char_p, ctypes.c_char_p]            # pvk,ret
ice.point_subtraction.argtypes = [ctypes.c_char_p, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_char_p]  # x1,y1,x2,y2,ret
ice.init_secp256_lib()

def scalar_multiplication(kk):
    res = (b'\x00') * 65
    pass_int_value = hex(kk)[2:].encode('utf8')
    ice.scalar_multiplication(pass_int_value, res)
    return res

def point_subtraction(pubkey1_bytes, pubkey2_bytes):
    x1 = pubkey1_bytes[1:33]
    y1 = pubkey1_bytes[33:]
    x2 = pubkey2_bytes[1:33]
    y2 = pubkey2_bytes[33:]
    res = (b'\x00') * 65
    ice.point_subtraction(x1, y1, x2, y2, res)
    return res

def new_pos(full_bytes):
    pos = hashlib.sha256(full_bytes).digest()
    return pos

def fixrange(full_bytes):
    t = low + int(full_bytes.hex(), 16) % diff
    return t

def pub2upub(pub_hex):
    x = int(pub_hex[2:66], 16)
    if len(pub_hex) < 70:
        y = bit.format.x_to_y(x, int(pub_hex[:2], 16) % 2)
    else:
        y = int(pub_hex[66:], 16)
    return bytes.fromhex('04' + hex(x)[2:].zfill(64) + hex(y)[2:].zfill(64))

def upub2cpub(upub_bytes):
    x1 = upub_bytes[1:33]
    prefix = str(2 + int(upub_bytes[33:].hex(), 16) % 2).zfill(2)
    return bytes.fromhex(prefix) + x1

st = time()
key_seed = b''
m = 1
while True:
    pubkey = "03633cbe3ec02b9401c5effa144c5b4d22f87940259634858fc7e59b1c09937852"
    P = pub2upub(pubkey)
    key_seed = new_pos(key_seed)
    qfix = fixrange(key_seed)
    #qfix = m * 1000000  # Use an interval of 1000000 for qfix (stride)
    tpub = bytes(bytearray(scalar_multiplication(qfix)))
    subP = bytes(bytearray(point_subtraction(P, tpub)))
    cpub = bytes(upub2cpub(subP))
    m += 1

    msg = 'Test Cpub : {total}, {num}, {password} '.format(total=m, num=qfix, password=bytes(cpub).hex())
    sys.stdout.write('\r' + msg)
    sys.stdout.flush()

    if cpub in add:
        print("Winner Found!:{num}, {password} ".format(num=qfix, password=bytes(cpub).hex()))
        f = open (u"Winner.txt","a")
        f.write("num:" + str(qfix) +'\n' +
                "cpub:" + str(bytes(cpub).hex())+ '\n\n')
        f.close()
        break
print('[-] Completed in {0:.2f} sec'.format(time() - st))

can you give me the same script that works in cpp? Thanks