6

I am aware of the possibility to generate vanity addresses for normal accounts. However, how is possible to generate vanity addresses for external owned accounts (which host smart contracts)?

I'm asking because the Ethereum Name Service (ENS) was deployed on 0x112234455c3a32fd11230c42e7bccd4a84e02010 (Ropsten).

10

Generating a vanity address is a simple process of trial-and-error, and the same process can be used to search for accounts having some other property.

Contract addresses are determined by the account of the creating account and its nonce - specifically, they're the hash of the RLP encoding of those two values. Thus, you can search for an account that generates a vanity contract address like this:

  1. Generate a random private key
  2. Derive its public key and address
  3. Derive the address of the first contract it would create from its address and a nonce of zero
  4. Repeat from 1

Here's some simple code that uses pyethereum to do this:

import os
from ethereum.keys import privtoaddr
from ethereum.utils import mk_contract_address
import zlib

smallest = None
keys = {}
while True:
  privkey = os.urandom(32)
  addr = privtoaddr(privkey)
  contractaddr = mk_contract_address(addr, 0).encode('hex')
  compressedsize = len(zlib.compress(contractaddr, 9))
  if compressedsize <= 42:
    print "0x%s: %d" % (contractaddr, compressedsize)
    keys[contractaddr] = privkey.encode('hex')
  if smallest is None or long(contractaddr, 16) < long(smallest, 16):
    smallest = contractaddr
    print "0x%s" % smallest
    keys[contractaddr] = privkey.encode('hex')

In this case, it looks for addresses with the most leading zeroes, and the keys that compress the smallest - using zlib as a crude estimator of Kolmogorov Complexity, since addresses with many repetitions will compress smaller.

You can replace the fitness function with anything you would like, of course - to generate the address eventually used for the ENS registry, I used a function that rated addresses based on how many strictly incrementing digits they started with.

  • 5
    I used a function that rated addresses based on how many strictly incrementing digits they started with. I always underestimate the lengths coders will go to for novelty. Like, shouldn't you be fixing bugs or something? 😜 Nonetheless, this is amazing and thank you for sharing. – tayvano Nov 24 '16 at 1:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.