Image Attribution: BeatingBetting.co.uk

Moneros RandomX - how to get rid of those pesky ASICs

By DogeMD | DogeMD | 16 Jun 2021


ASIC miners are everywhere these days and might pose a problem when it comes to decentralization. As more ASICs join the mining community, a lot of regular household miners are disincentivized and shut down their mining programs. 

The Monero community, however, has long been opposing this ASIC takeover. Here's how:

 

RandomX was created as a way of combatting ASIC dominance in the miner communities. It replaced the previous algorithm, CryptoNight, as ASICs adapted to overcome the difficulties of this previous algorithm. The first version of RandomX was released in May 2019 and it was implemented to the Monero blockchain November 30, 2019.

The idea behind RandomX is simple: leverage what CPUs do best and what ASICs do worst. Much like Bitcoin, Monero rests on proof-of-work (PoW) for its decentralized signing of transactions. In the case of monero, this PoW is dynamic - dPoW, through the clever generation of pseudorandom mining software in a virtual machine. Below is an overview of this algorithm:

 

RandomX

 

RandomX effectively shuts down ASIC dominance by using:

  • A virtual machine
  • Random code execution
  • Memory-hard techniques, even going just above a doubling threshold, increasing ASIC cost. 
  • Requiring a lot of cache memory for each thread of the algorithm. 

Household computers generally have large pools of fast memory available to them, but memory is expensive on an ASIC.

 

 

Components

The main parts of the RandomX algorithm are Argon2, AES, and Blake2, these are briefly described below.

 

Argon2

Argon2 is what is called a memory-hard function, where the purpose is to require a large amount of memory for computation. This algorithm was originally created in response to the use of ASICs for password decryption. 

AES

The Advanced Encryption Standard is one of the most secure encryption algorithms to date. Hardware acceleration for this algorithm is supported on most modern CPUs.

Blake2

This algorithm has been chosen instead of SHA-256 because it has greater hashing speed and parallelization. If you want to know more about how a hashing algorithm works, you can read my post on it:

how-does-sha-256-the-hashing-function-behind-bitcoin-actually-work

 

 

Algorithm

This algorithm has two modes, fast mode (requires 2.080 GB of memory) and light mode (requires 256 MB of memory). The fast mode has 4 - 6 x the performance of light mode. 

 

Step 1. Key generation

Every time you wish to run RandomX you first need a specific key, K.

This key changes every 2048 blocks, which is around every 2.8 days. It is created using a hash of the current block (key-block) and as such depends on data from the blockchain itself. This means you cannot know beforehand what K will be. 

 

Step 2. Virtual Machine

The next step is to fire up a virtual machine, which takes a large amount of RAM in possession (2GB) for an area called the scratchpad. In effect, the scratchpad is filled with pseudo-random numbers (using Argon2 on the key, then Blake2, and finally AES). These random numbers form the base of the next step, the creation of the mining programs.

 

Step 3. Generate Mining programs

RandomX relies on the pseudorandom generation of several programs, called mining programs. These mining programs are based on the data in the scratchpad. The first generated program forms the basis of the next, and so on, in a chain of programs, until the 8th program has been generated.

This removes the possibility of only running "easy" programs and creates another barrier for ASICs.

Below you can see a chart of comparable speed when a basic cpu miner runs the program, vs a custom miner, which discards the hardest 25% of programs but can run a program 50% faster. Since the miner needs to create all 8 programs in the chain before it can start mining, the strategy of selecting only easy programs leads to worse performance than the CPU miner.

 

e0728037b519d0685890a4eea07c3f2bc9cd48fecc180a2fec8ff7fa42906fc2.png

 

Closing thoughts

In this article, I've just been scratching on the surface of the RandomX algorithm. There are many more technical details, such as superscalar execution, using all 4 rounding methods in the IEEE 754 standard, and much more. Suffice to say, this is a complex algorithm written by some very smart people.

If you liked this review, please comment your thought below. Finally, I would like to end with a question for you to consider.

Why is ASIC dominance such a big thing for Monero anyway?

 

How do you rate this article?

1



DogeMD
DogeMD

In this blog I will try to explain fundamental concepts of blockchain technology and cryptocurrencies in an interactive manner, such that you really understand what's going on under the hood.

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.