Using an AWS GPU instance to generate vanity Bitcoin addresses

This blogpost is a short tutorial on how to efficiently generate vanity Bitcoin addresses on AWS' GPU instance and the resulting performance.

The next CTF, namely the ASIS Cyber Security Contest, requires you to provide a Bitcoin address during the registration if you want to claim a prize.

Custom Bitcoin addresses

During our team's preparation meetup we thought that it would be a cool idea to have our team's name legofan in it. Luckily there's a tool called vanitygen which generates Bitcoin addresses until a specific pattern is found.

For example, this will generate an address with the prefix Hi.

$> vanitygen 1Hi
Difficulty: 1330
Pattern: 1Hi                                                                   
Address: 1His8MJwroVeW4Hsg9u2kdtVKijEaJV1vo
Privkey: 5JDiU6JxwbBgPtW2RhrmPAwSMT7Z1qKz1ZHAvfKmTrLEd3t3rxb

However, the longer the prefix is, the longer (exponential!) it takes for the process to finish.

We first started out with our laptops, then some dedicated servers or big VMs and finally tried AWS' g2.8xlarge GPU instance. Skip to the performace section for some numbers.

g2.8xlarge setup

The g2.8xlarge comes with 32 CPUs, 60GB of RAM and 4 Nvidia GRID K520 cards.

You probably want to rent a so called Spot instance, because these are usually up to 90% cheaper.

Manson's blog gives a detailed description on how to request a spot instance. However, make sure to choose a custom AMI with the ID ami-c79b7eac in step 4, because it comes with all Nvidia/cuda drivers preconfigured and a g2.8xlarge instance in step 5.
You can follow his steps until point 11, but everything else will be already installed.

After logging in using SSH (username is ubuntu), we need to install some dependencies:

$> sudo apt-get install vim git libcurl3-dev libssl-dev libpcre-dev opencl-dev screen

Now we can compile the oclvanitygen tool:

$> git clone
$> cd vanitygen
$> make all

Running the tool without any parameters except for the pattern should show you all available GPUs:

$> ./oclvanitygen 1Test
Difficulty: 264104224
Available OpenCL platforms:
0: [NVIDIA Corporation] NVIDIA CUDA
  0: [NVIDIA Corporation] GRID K520
  1: [NVIDIA Corporation] GRID K520
  2: [NVIDIA Corporation] GRID K520
  3: [NVIDIA Corporation] GRID K520

The tool can't handle all four GPUs concurrently, so for each GPU 0,1,2,3 you run:

$> screen -S gpu$id 
$> ./oclvanitygen -p 0 -d $id -i $pat


  • $id is 0, 1, 2, or 3
  • $pat is the desired pattern

You can exit a screen by hitting Ctrl+A+D and enter it again by using screen -r gpu$id. In other words: You run the tool four times - Once per GPU.


Vanitygen can either run as a multicore CPU program ( vanitygen) or use the power of GPUs using opencl ( oclvanitygen).

Here are some numbers:

  • 2 Cores @ Core i5-2430M @ 2.4Ghz: ~660 KH/s
  • 20 Cores @ Xeon E5-2650L v3 @ 1.80GHz: ~3 MH/s
  • 32 Cores @ Xeon E5-2670 @ 2.60GHz: ~ 5 MH/s
  • 1 GPU @ Nvidia GRID K520: ~ 23 MH/s

The pattern was four combinations of a 8 characters long, case-insensitive prefix:

$> cat pat

$> ./oclvanitygen -p 0 -d 0 -i -f pat

I let the GPU instance running for about 55 minutes and it has found 13 matching addresses and that costed me around $2.