Application


Source for the mining application

The source for the application can be downloaded here.

Application background

Much like other crypto currencies, Coinporaal coins can be earned by solving hashes. The input of a coinporaal hash has three parameters:

  1. nonce
  2. base-string
  3. multiplier (integer)

The input for the hash-function is constructed by taking the nonce and appending the base-string repeated multiplier times. For example:

"hatersgonna hate 3"

would result in an input string of hatersgonnahatehatehate.

For the coinporaal, mining works as follows:

  • You request a block from the mining server
  • A block will consist of a base-string and multiplier

Next you will append a nonce and hash the input. For the Coinporaal, the nonce can be any (lowercase or uppercase) letter or digit [a-zA-Z0-9]. The hash function will output a hash of 128 hexadecimal characters. If the first 3 characters of the hash are equal to 000, you have found a coin! Otherwise, you can adjust the nonce and try again, untill you tried all possible nonces.

The hash function is a non-reversible function, so the only way to figure out if a hash starts with 000 is to calculate it from the input. Since the number of possible nonces (only 62 for the coinporaal) is highly limited, it is possible (very likely even) you do not find a nonce that results in a hash that starts with 000. In that case you will have to report this to the mining server, after which you can get a new input block.

It is only allowed to work on one input block at any given time. Thus, you can only request one input block from the server. You can not request a new block until:

  • You find a nonce that procuces a valid hash (you found a coin!)
  • or untill you decide there is no nonce that produces a valid hash

We have provided you with working code, which already requests input blocks and checks all possible nonces for you. For the assignment (and competition), your task will be to speed up this process by porting it from the CPU, to the GPU. The next section details how to install the provided code, and mine coinporaals.

Installation and usage

mkdir development;
cd development;
wget  https://ecatue.gitlab.io/GPU2016/application/mining.zip;
unzip mining.zip;
rm mining.zip;
make

After installation, you should end up with a binary called miner. This miner can be used in three ways:

  1. Stand-alone hash generator.
    In order to generate hashes with the miner, you should specify three things on the commandline:

    • The nonce: A string that serves as the start of the input to the hash function
    • The base string: String that is appended to the nonce
    • The multiplier: how many times the base string should be repeated
    ./miner hatersgonna hate 3
    
  2. Benchmark/Competition
    This is the mode your program will run in for the contest. To run in this mode, you can use the command make benchmark. The miner program will interact with the benchmark.py python script, which will supply your program with inputs. Your program will try to find hashes with 3 leading zeros by changing the nonce. The results are reported back to the benchmark.py script. Note that in this mode, pipes are used for communication between the processes. You cannot print any debug information on stdout, and doing so anyway might disrupt the interaction between the benchmark script and your program. You should be able to print to stderr, though this is not recommended for the code used in the competition if you are participating there. The supplied script will test 1000 inputs. The main purpose of the benchmark mode is to make sure your program is compatible with the competition software, before you enter it into the competition.

    make benchmark
    
  3. Quick check
    This mode is highly similar to the benchmark mode, with the exception that the program is supplied with 8 inputs, 4 which are know to produce a coin, and 4 which do not. This can be used as a very quick test to see if your pogram is still working as it should once you start to modify it. Of course this does not guarantee your code is correct for all cases (neither does the make bechmark command by the way), but it should give a reasonable indication. You can run this mode by executing make check. After a couple of seconds, it should report it processed 8 blocks, and found 4 valid coins.

If you want to extend the code with either OpenCL or CUDA, you can simply add these files to the directory (.cu for cuda, and .cl for opencl) and the Makefile should automatically detect them without further modification of the Makefile.

Note on profiling GPU code: The first function call to the GPU will take about 0.6 seconds, and act as a kind of warm-up. If you do profiling within your application please take this into acount. If the first call occurs within a loop, the first iteration of this loop may take significantly longer than the others. We suggest to do a ‘dummy’ call to the GPU at the beginning of the application to avoid measuring this effect.

Copyright TU/e