Skip to content

Instantly share code, notes, and snippets.

@pipermerriam
Last active April 27, 2018 20:26
Show Gist options
  • Save pipermerriam/ec7393d16e8808d42432c543bd3ffbf6 to your computer and use it in GitHub Desktop.
Save pipermerriam/ec7393d16e8808d42432c543bd3ffbf6 to your computer and use it in GitHub Desktop.
from eth_utils import function_signature_to_4byte_selector
import itertools
import multiprocessing
import random
import time
TARGET = b'\x00' * 4
def check_signature(idx, target):
fn_sig = "get_block_hash_{0}(uint256)".format(idx)
fn_selector = function_signature_to_4byte_selector(fn_sig)
if fn_selector == target:
print('FOUND:', fn_sig)
return fn_sig
def report_success(fn_sig):
if fn_sig:
print('FOUND:', fn_sig)
def find(target=TARGET):
pool = multiprocessing.Pool(8)
pending_results = []
counter = itertools.count(1)
start_at = time.time()
try:
while True:
while len(pending_results) < 256:
idx = random.randint(0, 1000000000000000)
num_processed = next(counter)
if num_processed % 100000 == 0:
print(
'processed:',
num_processed,
'iterations-per-second:',
num_processed / (time.time() - start_at),
)
pending_results.append(pool.apply_async(
check_signature,
args=(idx, target),
callback=report_success,
))
pending_results = [result for result in pending_results if not result.ready()]
except KeyboardInterrupt:
pool.close()
pool.join()
pool.terminate()
num_processed = next(counter)
print("=====================================================")
print("PROCESSED:", num_processed)
print('ITERATIONS-PER-SECOND', num_processed / (time.time() - start_at))
print("=====================================================")
if __name__ == "__main__":
find()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment