Post
Topic
Board Bitcoin Discussion
Re: Bitcoin puzzle transaction ~32 BTC prize to who solves it
by
frozenen
on 11/03/2025, 09:39:29 UTC
UNTESTED!! but surely we can automate Mara withdrawal:

# pip install ecdsa base58 requests selenium webdriver-manager bit
# need bitcrack.exe in same folder
import ecdsa
import hashlib
import base58
import requests
import time
import random
import subprocess
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from bit import PrivateKey

# =========================== #
#    STEP 0: GENERATE SEED & RUN BITCRACK     #
# =========================== #

def generate_random_seed():
    # Generate a truly random 10-digit number (not starting with 0)
    return random.randint(2113081981, 2113081983)   # default range (1000000000, 9999999999) test#67 (2113081981, 2113081983)

def find_private_key():
    while True:
        # Generate a new random seed for each iteration
        seed_value = generate_random_seed()
        print(f'\nUsing Seed: {seed_value}')

        # Set the random seed
        random.seed(seed_value)

        # Generate a random range for the command
        #67range a = random.randrange(2**30, 2**31) #68range a = random.randrange(2**31, 2**32)
        a = random.randrange(2**30, 2**31)
        random_start = "%00x" % a
        random_range = (random_start + "000000000:" + random_start + "fffffffff")

        # Print the generated seed and range
        print(f'Seed: {seed_value} KHex: {random_start}\n')

        # Run the BitCrack command with the generated range #67 1BY8GQbnueYofwSuFAT3USAhGjPrkxDdW9  #68 1MVDYgVaSN6iKKEsbzRUAYFrYJadLYZvvZ
        cmd_command = f'BitCrack.exe -b 128 -t 256 -p 512 -o foundkey.txt --keyspace {random_range} 1BY8GQbnueYofwSuFAT3USAhGjPrkxDdW9\n'
        subprocess.call(cmd_command, shell=True)

        # Check if 'foundkey.txt' contains any private key, and if so, exit the loop
        try:
            with open('foundkey.txt', 'r') as f:
                found_data = f.read().strip()
                if found_data:
                    print(f"Private key found: {found_data.split()[1]}")
                    private_key_hex = found_data.split()[1]  # The private key is in the second position
                    return private_key_hex  # Return the private key to proceed to Steps 1-8
        except FileNotFoundError:
            print("Found key file not yet generated.")
       
        # Optional: Add a delay before retrying
        time.sleep(2)

# =========================== #
#    STEP 1: CREATE WALLET    #
# =========================== #

# Get private key from Step 0
private_key_hex = find_private_key()

# Private key in hex format
private_key = PrivateKey.from_hex(private_key_hex)  # Use `bit` library to handle key

btc_address = private_key.address
print(f"Bitcoin Address: {btc_address}")

# =========================== #
#   STEP 2: FETCH BALANCE     #
# =========================== #

api_url = f'https://blockchain.info/rawaddr/{btc_address}'
response = requests.get(api_url)
data = response.json()

balance = data.get('final_balance', 0) / 10**8  # Convert satoshis to BTC
print(f"Balance: {balance:.8f} BTC")

if balance == 0:
    print("No funds available in the address.")

# =========================== #
#   STEP 3: LAST TXs       #
# =========================== #

if "txs" not in data or not data["txs"]:
    print("No transactions found for this address.")
else:
    print("\nLast Transactions:")
    transactions = data["txs"][:1]  # Get the last numberof transactions

    for tx in transactions:
        tx_id = tx["hash"][:10]  # Shorten transaction ID for readability
        print(f"\nTransaction ID: {tx_id}...")

        # SENT Transactions
        sent_any = False
        for output in tx["out"]:
            if output.get("addr") and output["addr"] != btc_address:
                sent_any = True
                print(f"  → Sent to: {output['addr']} | Amount: {output['value'] / 10**8:.8f} BTC")

        if not sent_any:
            print("  → No outgoing transactions in this TX.")

        # RECEIVED Transactions
        received_any = False
        for input_tx in tx["inputs"]:
            if "prev_out" in input_tx and input_tx["prev_out"].get("addr") == btc_address:
                received_any = True
                amount_received = input_tx["prev_out"]["value"] / 10**8  # Convert satoshis to BTC
                print(f"  ← Received from: {input_tx['prev_out']['addr']} | Amount: {amount_received:.8f} BTC")

        if not received_any:
            print("  ← No incoming transactions in this TX.")

# =========================== #
#   STEP 4: FETCH UTXOs       #
# =========================== #

utxos = []
for tx in data["txs"]:
    for output in tx["out"]:
        if output.get("addr") == btc_address and not output.get("spent"):
            utxos.append({"txid": tx["hash"], "vout": output["n"], "value": output["value"]})

if not utxos:
    print("No available UTXOs. Exiting...")
    exit()

# =========================== #
#   STEP 5: SET TARGET & FEES #
# =========================== #

fee_url = 'https://mempool.space/api/v1/fees/recommended'
fee_response = requests.get(fee_url)
fee_data = fee_response.json()
high_fee_rate = fee_data['fastestFee']  # sat/byte
print(f"Using a fee rate of {high_fee_rate} sat/byte")

target_address = "bc1qxfj9gsqpjduvfqyq58rkj6cgngrr672x6nm98f"

# =========================== #
#   STEP 6: CREATE TX         #
# =========================== #

# Calculate total input amount from UTXOs
total_input = sum(utxo["value"] for utxo in utxos)
estimated_size = 10 + (len(utxos) * 180) + (1 * 34) + 10  # Approximate transaction size in bytes
fee = estimated_size * high_fee_rate  # Total fee in satoshis

if total_input <= fee:
    print("Not enough funds to cover transaction fees. Exiting...")
    exit()

send_amount = total_input - fee  # Amount to send after deducting fees

print(f"Total input: {total_input / 10**8:.8f} BTC")
print(f"Transaction fee: {fee / 10**8:.8f} BTC")
print(f"Sending: {send_amount / 10**8:.8f} BTC to {target_address}")

# =========================== #
#   STEP 7: SIGN TRANSACTION  #
# =========================== #

# Create transaction using `bit` library
outputs = [(target_address, send_amount, 'btc')]
signed_tx_hex = private_key.create_transaction(outputs, fee=fee / 10**8, absolute_fee=True)

print("\nRaw Signed Transaction Hex:")
print(signed_tx_hex)

# =========================== #
#   STEP 8: SUBMIT TO SLIPSTREAM #
# =========================== #

service = Service(ChromeDriverManager().install())  # Auto-download latest ChromeDriver
driver = webdriver.Chrome(service=service)
driver.get('https://slipstream.mara.com/')
time.sleep(5)

textarea = driver.find_element("xpath", '//textarea[@placeholder="Paste your raw transaction here"]')
submit_button = driver.find_element("xpath", '//button[text()="Activate Slipstream"]')

textarea.send_keys(signed_tx_hex)
submit_button.click()

time.sleep(5)

print("Transaction submitted successfully to Mara Slipstream. It is not yet broadcasted to the network.")
driver.quit()