Hey guys!
I have developed a proof-of-concept P2SH vanity address generator!
This program is an implementation of this idea:
https://bitcointalksearch.org/topic/10x-faster-vanity-addresses-p2shm-255245.
It's written in Python, thus is very slow, but that's a good proof of concept.
You'll need Python 2.7 and pybitcointools installed.
#!/usr/bin/env python2
import time
import multiprocessing
from pybitcointools import *
def uint256(x):
hexdigits = hex(x)[2:].replace("L", "")
hexdigits = "0"*(64-len(hexdigits)) + hexdigits
binary = hexdigits.decode("hex")
return binary
def make_script(pubkey1, pubkey2):
script = [1, pubkey1, pubkey2, 2, 174]
return serialize_script(script)
def p2sh(script):
return hex_to_b58check(hash160(script), 5)
def _worker_thread(thread_number, total_threads, starting_k, pattern, quit):
print "Worker %d started" % thread_number
k = starting_k + thread_number
total = k
while not quit.is_set():
start = time.time()
pubkey2 = "\x02" + uint256(k)
k += total_threads
redeem_script = make_script(pubkey1, pubkey2)
p2sh_addr = p2sh(redeem_script)
if p2sh_addr[1:].startswith(pattern):
print "Found!"
print "P2SH address: " + p2sh_addr
print "Redeem script: " + redeem_script.encode("hex")
quit.set()
elapsed = time.time() - start
num_checked = k - starting_k
if num_checked % 16384 == thread_number:
print "Worker %d: %d addrs per second, %d checked" % (thread_number, 1.0 / elapsed, num_checked)
privkey = random_key()
pubkey1 = encode_pubkey(privtopub(privkey), "bin_compressed")
pattern = raw_input("Vanity pattern: ")
quit = multiprocessing.Event()
total_processes = multiprocessing.cpu_count()
starting_k = int(encode_pubkey(privtopub(privkey), "hex_compressed")[2:], 16) + 1
for worker_num in range(total_processes):
print "Starting worker %d" % worker_num
process = multiprocessing.Process(target=_worker_thread, args=(worker_num, total_processes, starting_k, pattern, quit))
process.start()
quit.wait()
print("Spend private key: %s" % encode_privkey(privkey, "wif"))
Vanity pattern: P14
Starting worker 0
Starting worker 1
Starting worker 2
Starting worker 3
Worker 0 started
Worker 2 started
Worker 1 started
Worker 3 started
Found!
P2SH address: 3P14KiomBxh3S4QCzztj86E7wi8SQnn314
Redeem script: 512102296c1c6e3acac2d7698a36eb70a5c196cfcc7546c277ff29054281a8be4dd4282102296c1c6e3acac2d7698a36eb70a5c196cfcc7546c277ff29054281a8be4e9d1252ae
Spend private key: 5JFYKkqeku1ytA7p5PSMgRm8Xq3EQGQKsr7nyUUZXns5gvfyV5U
It works by having a dummy public key which is altered to make the script hash contain a specific prefix.
Security: the public key chosen for the nonce public key (intended to be unspendable and unknown) is an incremented value of the actual spending public key. I'd like to hear on the security of that.
It's very easy to add multisig support to this, I'd like to hear on it if needed.
Again, this program is not yet intended for real-world use, so please don't risk funds with it.
I'd like to hear from testers if it works properly (I've done some checks myself and it seems to work fine).
If you find it useful, please consider a donation to the address in my signature, thank you!