Post
Topic
Board Development & Technical Discussion
Merits 3 from 2 users
Re: Ultra-Lightweight Database with Public Keys (for puzzle btc)
by
iceland2k14
on 23/02/2025, 09:13:19 UTC
⭐ Merited by Halab (2) ,mcdouglasx (1)
I would like to think about this Light Weight Database approach to see if that helps... (Later)
Currently without this and just using the BSGS script (15 MB Table) solves Puzzles #40 in 0.49 sec.

Code:
import math
import time
import os
import secp256k1 as ice


# Main Script
if __name__ == "__main__":
    # Puzzle Parameters
    puzzle = 45
    start_range = 2**(puzzle-1)
    end_range = (2**puzzle) - 1
    puzzle_pubkey = '026ecabd2d22fdb737be21975ce9a694e108eb94f3649c586cc7461c8abf5da71a'

    P = ice.pub2upub(puzzle_pubkey)

    # Precompute m and mP for BSGS
    m = int(math.floor(math.sqrt(end_range - start_range)))
    m = m * 20  # for use in bsgs_2nd
    m_P = ice.scalar_multiplication(m)
    m_Pn = ice.point_negation(m_P)
    m2 = math.ceil((end_range - start_range)/m)
    print(f'[+] m={m} m2={m2} Puzzle={puzzle}')
   
    if os.path.isfile('baby_table.2nd') == False:
        print(f'[+] Preparing for BSGS Table with {m} elements in RAM')
        ice.bsgs_2nd_check_prepare(m)
        ice.dump_bsgs_2nd('baby_table.2nd', True)
    else:
        ice.load_bsgs_2nd('baby_table.2nd', True)
       


    # BSGS Search
    print('[+] BSGS Search in progress')
    st = time.time()
    S = ice.point_subtraction(P, ice.scalar_multiplication(start_range))
    found, pvk = ice.bsgs_2nd_check(S, 1)
    if found == True:
        k = start_range + int.from_bytes(pvk, 'big')
        print(f'FOUND PrivateKey: {k:064x}')
        print(f"[+] Time Spent : {time.time() - st:.2f} seconds")
        exit()
       
    ice.init_P2_Group(m_Pn) # Negative for P2_mcpu
    SL = ice.point_sequential_increment_P2_mcpu(m2, S) # succesive decrement
    found, pvk = ice.bsgs_2nd_check_mcpu(SL, 1)
    if int.from_bytes(found, 'big') > 0:
        elapsed = time.time() - st
        for i in range(m2):
            if found[i] == 1:
                print(f'start=[0x{start_range:0x}] [i={i}] idx=0x{int.from_bytes(pvk[i*32:(i+1)*32], "big"):0x} ')
                k = start_range + (i+1) * m + int.from_bytes(pvk[i*32:(i+1)*32], 'big')
                print(f'FOUND PrivateKey: {k:064x}')
                print(f"[+] Time Spent : {elapsed:.2f} seconds")
                exit()

    print('[+] Key not found')
    print(f"[+] Time Spent : {time.time() - st:.2f} seconds")

Result for Puzzle #45 is

Code:
python ULWD_bsgs.py
[+] m=83886060 m2=209716 Puzzle=45
[+] Preparing for BSGS Table with 83886060 elements in RAM
Calculating      : 100 %
[+] [N2:4194500, N3:209725, N4:10486]  Vec4th Size    : 10486
[+] [bloom2nd (14 MB)] [bloom3rd (0 MB)] [bloom4th (0 MB)]
[+] BSGS Search in progress
start=[0x100000000000] [i=28660] idx=0x11cfb29
FOUND PrivateKey: 0000000000000000000000000000000000000000000000000000122fca143c05
[+] Time Spent : 2.80 seconds

For bigger puzzles lightweight strategy could help with iteration in primary collision and then secondary check for confirmation using the table.