Go to file
tevador 40a08bb0c8 Fixed incorrect latency of mul_r in SuperscalarHash 2019-05-05 14:49:00 +02:00
doc Fixed IMUL_RCP if divisor is a power of 2 2019-05-04 18:00:17 +02:00
src Fixed incorrect latency of mul_r in SuperscalarHash 2019-05-05 14:49:00 +02:00
vcxproj 30% faster JIT compiler 2019-05-04 19:40:25 +02:00
.gitignore Code cleanup & refactoring 2019-04-28 16:42:45 +02:00
LICENSE Initial commit 2018-11-01 00:34:52 +01:00
README.md Updated readme 2019-05-03 22:09:52 +02:00
makefile 30% faster JIT compiler 2019-05-04 19:40:25 +02:00
randomx.sln 30% faster JIT compiler 2019-05-04 19:40:25 +02:00

README.md

RandomX

RandomX is a proof-of-work (PoW) algorithm that is optimized for general-purpose CPUs. RandomX uses random code execution (hence the name) together with several memory-hard techniques to achieve the following goals:

  • Prevent the development of a single-chip ASIC
  • Minimize the efficiency advantage of specialized hardware compared to a general-purpose CPU

Overview

RandomX behaves like a keyed hashing function: it accepts a key K and arbitrary input H and produces a 256-bit result R. Under the hood, RandomX utilizes a virtual machine that executes programs in a special instruction set that consists of a mix of integer math, floating point math and branches. These programs can be translated into the CPU's native machine code on the fly. Example of a RandomX program translated into x86-64 assembly is program.asm. A portable interpreter mode is also provided.

RandomX can operate in two modes:

  • Fast mode - requires 2080 MiB of shared memory.
  • Light mode - requires only 256 MiB of shared memory, but runs significantly slower and uses more power per hash.

Documentation

Full specification available in specs.md.

Design notes available in design.md.

Build

RandomX is written in C++11 and builds a static library with a C API provided by header file randomx.h. Minimal API usage example is provided in api-example1.c. The reference code includes a benchmark executable for testing.

Ubuntu/Debian

Build dependencies: make and gcc (minimum version 4.8, but version 7+ is recommended).

Build using the provided makefile.

Windows

Build dependencies: Visual Studio 2017.

A solution file is provided.

Precompiled binaries

Precompiled benchmark binaries are available on the Releases page.

Proof of work

RandomX was primarily designed as a PoW algorithm for Monero. The recommended usage is following:

  • The key K is selected to be the hash of a block in the blockchain - this block is called the 'key block'. For optimal mining and verification performance, the key should change every 2048 blocks (~2.8 days) and there should be a delay of 64 blocks (~2 hours) between the key block and the change of the key K. This can be achieved by changing the key when blockHeight % 2048 == 64 and selecting key block such that keyBlockHeight % 2048 == 0.
  • The input H is the standard hashing blob.

Performance

Preliminary performance of selected CPUs using the optimal number of threads (T) and large pages (if possible), in hashes per second (H/s):

CPU RAM OS AES Fast mode Light mode
AMD Ryzen 7 1700 16 GB DDR4 Ubuntu 16.04 hardware 4080 H/s (8T) 620 H/s (16T)
Intel Core i7-8550U 16 GB DDR4 Windows 10 hardware 1700 H/s (4T) 350 H/s (8T)
Intel Core i3-3220 2 GB DDR3 Ubuntu 16.04 software - 120 H/s (4T)
Raspberry Pi 3 1 GB DDR2 Ubuntu 16.04 software - 2.0 H/s (4T) †

† Using the interpreter mode. Compiled mode is expected to increase performance by a factor of 10.

FAQ

Can RandomX run on a GPU?

RandomX was designed to be efficient on CPUs. Designing an algorithm compatible with both CPUs and GPUs brings many limitations and ultimately decreases ASIC resistance.

GPUs are expected to be at a disadvantage when running RandomX, but the exact performance has not been determined yet due to lack of a working GPU implementation.

A rough estimate for AMD Vega 56 GPU gave an upper limit of 1200 H/s, comparable to a quad core CPU (details in issue #24).

Does RandomX facilitate botnets/malware mining or web mining?

Efficient mining requires more than 2 GiB of memory, which is difficult to hide in an infected computer and disqualifies many low-end machines such as IoT devices. Web mining is nearly impossible due to the large memory requirement and low performance in interpreted mode.

Since RandomX uses floating point math, does it give reproducible results on different platforms?

RandomX uses only operations that are guaranteed to give correctly rounded results by the IEEE 754 standard: addition, subtraction, multiplication, division and square root. Special care is taken to avoid corner cases such as NaN values or denormals.

The reference implementation has been validated on the following platforms:

  • x86+SSE2 (32-bit, little-endian)
  • x86-64 (64-bit, little-endian)
  • ARMv7+NEON (32-bit, little-endian)
  • ARMv8 (64-bit, little-endian)
  • PPC64 (64-bit, big-endian)

Acknowledgements

  • SChernykh - contributed significantly to the design of RandomX
  • hyc - original idea of using random code execution for PoW
  • nioroso-x3 - provided access to PowerPC for testing purposes

RandomX uses some source code from the following 3rd party repositories:

Donations

XMR (tevador):

845xHUh5GvfHwc2R8DVJCE7BT2sd4YEcmjG8GNSdmeNsP5DTEjXd1CNgxTcjHjiFuthRHAoVEJjM7GyKzQKLJtbd56xbh7V