Vous êtes sur la page 1sur 5

Asynchronous Mining of Ethereum Cryptocurrency

Pavel V. Sukharev1, Dmitry S. Silnov2


Department of Computer Systems and Technologies, National Research Nuclear University MEPhI
(Moscow Engineering Physics Institute)
Moscow, Russia
1
suharev_p@mail.ru, 2ds@silnov.pro

Abstract— Cryptocurrency mining is an important process using a large data structure called DAG, during mining.
that ensures the reliability of cryptocurrency system. A Because the contemporary GPU using the newest technologies
significant computing power is used in cryptocurrency mining. in the area of I/O systems, this approach makes impossible
One of the most important tasks in cryptocurrency mining is to creating specialized Application-Specific Integrated Circuits
ensure the maximum performance of used computing capacities. (ASICs) which have advantage before the widespread
In this paper we review the existing Ethereum mining algorithm computational solutions. [6][7]
and search for possibilities for speeding up the mining by
applying a new asynchronous mining algorithm. As a programming platforms for mining on GPU
technologies CUDA (for NVIDIA GPUs) [8] and OpenCL [9]
Keywords—cryptocurrency mining; Ethereum; OpenCL; (for all GPUs) are used. OpenCL - open standard, which
performance increase formalizing writing parallel programs for different types of
devices - CPU, GPU, FPGA. For launching OpenCL program
I. INTRODUCTION on the device, realization on OpenCL platform for that device
is needed. OpenCL program consists of two parts - host-part,
Cryptocurrencies are relatively new and fast-growing area which manages OpenCL tasks and read the results, and kernel-
of modern digital economy. It represents a digital currency part, which is used for task calculations. There are exists many
with, usually, decentralized accounting and strict control for OpenCL implementations designed that meet different tasks
money supply and token exchanging. To secure and designed for different devices and operating systems. [10]
cryptocurrency, various cryptographic methods are used. [11]
One of the core technologies, which cryptocurrency is
based on, is a blockchain technology. [1] Blockchain is a data II. PROBLEM STATEMENT
structure representing linked list of blocks, which store Because users are taking part in mining process to get a
information about cryptocurrency system state. Block are used mining reward for a new block, mining efficiency is a
to store list of all transactions of cryptocurrency, information determining factor when choosing a program for mining. As a
about its supply, sometimes there is also stored information result, a little number of mining applications are stands out.
about user wallets state. They are divided to closed-source solutions (for example,
Claymore [12]) and open-source solutions. [13] [14]
Blockchain coherence ensures cryptocurrency reliability, its
protection from attacker’s attempts to spends tokens which Mining program differs from another OpenCL program in
they don’t have access to. Therefore, one of the important tasks that it hasn’t finite volume of computational task and has often
in cryptocurrency functioning is to ensure authenticity of changing input parameters. Thus mining program has cyclic
blocks, which are added to blockchain. [2] structure. Describe the order of actions used in mining:
Due to cryptocurrency decentralization, new block is added Launching mining process using OpenCL function
into blockchain by users, who are provide their computing clEnqueueNDRangeKernel() with specified work size values
resources to sustain cryptocurrency system. For that, users localWorkSize and globalWorkSize
receive a reward in form of some predetermined amount of
1. Blocking waiting for work completion and reading
cryptocurrency tokens, which is issued when new block is
created. There are exist many different approaches to determine mining result through function clEnqueueReadBuffer()
which user can add new block. One of the most popular
approaches is called Proof-of-Work. [3] It requires from user to After results reading, miner sends task for computation
make some time-consuming calculations. In that case, process again. If the correct result was found, then it is sent for
of adding new block into blockchain is called mining. validation. In each mining cycle, each OpenCL work-item has
its own nonce parameter value, according to base nonce and
In the Ethereum cryptocurrency is used Proof-of-Work work-item ID.
system with mining algorithm ethash. [4] The main feature of
this algorithm is that it consumes the entire available memory Kernel-part of miner describes standard computational
access bandwidth, thus making memory reads the bottleneck of function of ethash algorithm. Kernel-part takes as parameters:
the whole computation process. [5] This high load is based on 1) Global buffer for result storage

731 978-1-5386-6757-6/18/$31.00 ©2018 IEEE


2) Block header hash value Average percent of work, which miner lose due to that
reason, described by equation (1).
3) DAG structure pointer
4) Current nonce (1)

5) Target hash value Where - average time of finding new block in the
Ethereum cryptocurrency. - execution time of one cycle of
Mining performs calculations based on the parameters of the calculations.
current block of Ethereum blockchain. If a new block is added
to the blockchain, information about it is spread to all nodes Loss of work, described by equation (1), is constant in case
of applying the previously described mining algorithm. In order
participating in the Ethereum mining. When miner receives
to get rid of this work loss, it is necessary to make sure that the
information about new block, it should modify the mining mining starts to perform a new task with actual parameters as
parameters, according to the new task. To do this, the miner soon as the new block header comes from the server.
changes the arguments of the OpenCL mining kernel which is
used to calculate the ethash algorithm.
III. ALGORITHM DESCRIPTION
To get rid of the work loss described by equation (1), it
should to change host-part mining algorithm in the way, that it
would solve the next objectives:
• implementation of possibility of instant OpenCL kernel
mining task change in case of receiving a new block
• providing continuous monitoring of incoming
information about a new mining task
To achieve instant switching of mining task, it is necessary
to implement the possibility of fast stopping OpenCL kernel
when new task has come to miner. OpenCL platform hasn’t
any instruments for stopping OpenCL kernel, so we should to
implement it by ourselves. For that purpose, we need to modify
OpenCL kernel code.
OpenCL kernel code modification for fast stopping kernel
is introduction of additional condition for mining, which will
allow miner to quickly complete the execution of the work-
item if necessary. Adding new code to OpenCL kernel can lead
to slowdown of the mining procedure. [15] Also, this code is
not implying instant completion of calculations. It consists in
the fact that, after the termination condition of the mining
starts, all the working elements of OpenCL will finish their
work almost immediately after the calculation starts. As a
result, the OpenCL kernel will finish its work much faster. The
analysis of OpenCL kernel stopping speed must be conducted.
As a condition for mining stopping the value of the first
element of result buffer has been chosen. This element
represents the whole number of valid results in current mining
cycle. This choice is explained by the fact that it solves two
goals at once: implements the possibility to end mining cycle
through the command from the host-part (by writing in the
result buffer control value which means mining stop) and
allows to automatically stop mining in case of finding the first
valid result.
The possible values of the first element of result buffer are
described in the table 1.

Fig. 1. OpenCL mining algorithm

Fig. 1 describes algorithm of one cycle of mining. This TABLE I. BUFFER ELEMENT VALUES
algorithm is used in all open-source miner software, such as
ethminer. [13] Valu Designation Meaning

732
e
However, we need calculation results for the further
execution of miner OpenCL host-part. To preserve the
-2 C_INVALID Is wrote to result buffer from host-part in operation of the awaiting of mining results, after enqueueing
case of new task appearing. Stops the the OpenCL command for buffer reading, we set the buffer
execution of the OpenCL kernel. value, which is used for results reading, into the state
C_NOT_READ and launching the loop of result awaiting.
-1 C_NOT_READ Initial value of the variable in the host-
part where are mining results readed. In each pass of the loop, we check if new task is received.
This value means that results have not In case of receiving computation results (setting the variable in
been read yet. The actual result buffer state C_NO_RESULT or C_RESULT) before the new task, we
element never takes this value.
stop result awaiting loop, send valid results (in case of
C_RESULT) and launch mining command with old parameters
0 C_NO_RESUL Initial value for buffer result element.
T Allows execution of OpenCL kernel. of block header. If new task is received before the end of the
current computation cycle, we set into result buffer control
>0 C_RESULT Value describes found results count. value C_INVALID, thereby stopping the mining. After that we
Stops the execution of the OpenCL initialize mining input parameters with new values and
kernel. relaunch it. It should be noted, that in case of finding the valid
result, mining will stop itself almost instantly.
In order to implement the ability to end the current mining Thereby, we implemented mining algorithm, which has the
cycle from the host-part right after receiving the new block ability to switch the computing task right after receiving a new
header value, it should to get rid of blocking awaiting for the block without waiting for completion the current work cycle. In
mining results on the host-part. For that, we set the flag in Fig. 2. a new algorithm for executing the host-part of the

function call clEnqueueReadBuffer(). OpenCL miner is presented.


Fig. 2. Algorithm of asynchronous OpenCL mining

733
IV. EXPERIMENTAL RESULTS host-part. Experiment time is 600 seconds. The results of
According to developed mining algorithm we made the experiment in the table 3.
changes to the miner code. To evaluate performance growth
due to changes, a bunch of experiments should be conducted: TABLE III. PERFORMANCE COMPARISON OF MODIFIED AND COMMON
MINERS
• evaluate performance loss due to adding new instructions
in computational code of OpenCL kernel GPU Miner type Actual hash Obsolete Time
count hash count
• evaluate performance change in comparison with
common miner in conditions of the real mining process NVIDIA common 2820669440 38797312 599817
Because the proposed changes make the execution of the GTX970M
OpenCL kernel code non-linear, we can’t use standard method modified 2857147008 358016 599821
of counting hashes, which is based on counting whole work
AMD common 16174284800 47185920 599971
size, which is executed within one cycle. RX480
Therefore, in order to accurately determine the number of modified 16365772288 697600 599988
calculated actual and non-actual received ethash algorithm
values during the experiment, we must perform the calculation As we can see, the usage of modified miner gives
inside the code of the OpenCL kernel. For that we are using a performance growth of 1.3% for NVIDIA GTX 970M and
separate OpenCL buffer, which values will be atomically 1.2% for AMD RX480. This performance change is explained
increment every time when OpenCL work-item ends ethash by decreasing number of obsolete hashes and optimization of
calculation. If at the moment of finishing ethash calculation on mining managing processes.
the work-item the first element of result buffer has value
C_INVALID, this value is counted as obsolete and will be
counted as inappropriate. V. CONCLUSION
We are using two miners with GPUs NVIDIA GTX970M In this article was conducted the research of mining
and AMD RX480 as a mining rig. For performance loss test algorithm of cryptocurrency Ethereum. As a result of research,
due to changes in the miner code we are using only one miner. the problem was found, which lead to mining performance
For performance evaluation of miner with modified algorithm loss. According to the problem found, the code for the software
we use both miners. When mining, the default parameters of for mining has been changed to solve this problem. The
work size are used. experiment was conducted showing that the problem was
solved and the mining productivity was increased.
To evaluate the performance loss due to the change in the
kernel code of the miner, we use the miner testing program. Based on this study, we can suggest further improvements
This program proceeds computation of the ethash algorithm to the OpenCL mining software. For the further performance
and count mean number of hashes per second for basic DAG improvement, it is necessary to conduct an investigation of the
structure. This benchmark is conducted independently from optimal size of work in the case of asynchronous OpenCL
real Ethereum network. Test time is 600 seconds; warmup time mining.
is 60 seconds. We will conduct two tests, first for the common
miner, and the second for the miner with modified OpenCL REFERENCES
kernel code. [1] G. Zyskind, O. Nathan, and A. S. Pentland. Decentralizing privacy:
The results of experiment are shown in the Table 2. Using blockchain to protect personal data. Proc. - 2015 IEEE Secur.
Priv. Work. SPW 2015, pp. 180–184, 2015.
[2] C. Decker and R. Wattenhofer. Information propagation in the Bitcoin
TABLE II. RESULTS OF OPENCL KERNEL PERFORMANCE TEST network. 13th IEEE Int. Conf. Peer-to-Peer Comput. IEEE P2P 2013 -
Proc., 2013.
[3] A Narayanan, J Bonneau, E Felten, A Miller, S.Goldfeder. Bitcoin and
OpenCL kernel Max speed, H/s Mean speed, H/s
Cryptocurrency Technologies: A Comprehensive Introduction,
Princeton University Press, 2016
Common 27069502 26841241 [4] Ethash. (2018). Available at:
https://github.com/ethereum/wiki/wiki/Ethash. (accessed 17 July 2018)
Modified 27069502 26774476 [5] Ethash Design Rationale (2018). Availiable at:
https://github.com/ethereum/wiki/wiki/Ethash-Design-Rationale
(accessed 17 July 2018)
As it can be noted, additional code in the OpenCL kernel [6] A. R. Zamanov, V. A. Erokhin, and P. S. Fedotov. ASIC-resistant hash
didn’t change miner performance. A small difference in mean functions. Proc. 2018 IEEE Conf. Russ. Young Res. Electr. Electron.
speed could be explained by the general speed heterogeneity Eng. ElConRus, pp. 394–396, 2018.
[7] J. Barkatullah and T. Hanke, Goldstrike 1: CoinTerra’s first-generation
due to mining. cryptocurrency mining processor for bitcoin. IEEE Micro, vol. 35, no.
We are assured that modified OpenCL kernel code don’t 2, pp. 68–76, 2015.
[8] CUDA Programming Guide, NVIDIA, 2007. 125 p.
change mining performance. So, we can conduct the [9] J. E. Stone, D. Gohara, and G. Shi. OpenCL: A Parallel Programming
experiment for evaluating mining performance change in case Standard for Heterogeneous Computing Systems. Computing in
of using new asynchronous algorithm for miner’s OpenCL Science & Engineering, vol. 12, no. 3, pp. 66–73, 2010.

734
[10] J. Kim, S. Seo, J. Lee, J. Nah, G. Jo, and J. Lee. SnuCL: an OpenCL [13] Ethereum miner with OpenCL, CUDA and stratum support (2018)
framework for heterogeneous CPU/GPU clusters. Proc. 26th ACM Int. Available at: https://github.com/ethereum-mining/ethminer (accessed
Conf. Supercomput. - ICS ’12, p. 341, 2012. 17 July 2018)
[11] P. Jääskeläinen, C. S. de La Lama, E. Schnetter, K. Raiskila, J. Takala, [14] Sgminer (2018) Available at: https://github.com/nicehash/sgminer
and H. Berg. pocl: A Performance-Portable OpenCL Implementation. (accessed 17 July 2018)
Int. J. Parallel Program., vol. 43, no. 5, pp. 752–785, 2015. [15] OpenCL User Guide, AMD, August, 2015. 180 p.
[12] Claymore miner (2018) Available at:
https://github.com/nanopool/Claymore-Dual-Miner (accessed 17 July
2018)

735

Vous aimerez peut-être aussi