Skip to content

Commit

Permalink
RandomX: update to v1.1.4
Browse files Browse the repository at this point in the history
* Faster cache initialization with SSSE3/AVX2
* Automatic detection of CPU capabilities in RandomX
* Fixed a possible out-of-bounds access in superscalar program generator
* Use MONERO_RANDOMX_UMASK to manually disable RandomX flags in monerod
  • Loading branch information
tevador committed Oct 11, 2019
1 parent aa72c21 commit 060d0ce
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 11 deletions.
51 changes: 41 additions & 10 deletions src/crypto/rx-slow-hash.c
Expand Up @@ -34,6 +34,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <limits.h>

#include "randomx.h"
#include "c_threads.h"
Expand Down Expand Up @@ -154,6 +155,43 @@ static inline int use_rx_jit(void)
#endif
}

static inline int disabled_flags(void) {
static int flags = -1;

if (flags != -1) {
return flags;
}

const char *env = getenv("MONERO_RANDOMX_UMASK");
if (!env) {
flags = 0;
}
else {
char* endptr;
long int value = strtol(env, &endptr, 10);
if (endptr != env && value >= 0 && value < INT_MAX) {
flags = value;
}
else {
flags = 0;
}
}

return flags;
}

static inline int enabled_flags(void) {
static int flags = -1;

if (flags != -1) {
return flags;
}

flags = randomx_get_flags();

return flags;
}

#define SEEDHASH_EPOCH_BLOCKS 2048 /* Must be same as BLOCKS_SYNCHRONIZING_MAX_COUNT in cryptonote_config.h */
#define SEEDHASH_EPOCH_LAG 64

Expand Down Expand Up @@ -236,7 +274,7 @@ void rx_slow_hash(const uint64_t mainheight, const uint64_t seedheight, const ch
char *hash, int miners, int is_alt) {
uint64_t s_height = rx_seedheight(mainheight);
int toggle = (s_height & SEEDHASH_EPOCH_BLOCKS) != 0;
randomx_flags flags = RANDOMX_FLAG_DEFAULT;
randomx_flags flags = enabled_flags() & ~disabled_flags();
rx_state *rx_sp;
randomx_cache *cache;

Expand All @@ -263,8 +301,6 @@ void rx_slow_hash(const uint64_t mainheight, const uint64_t seedheight, const ch

cache = rx_sp->rs_cache;
if (cache == NULL) {
if (use_rx_jit())
flags |= RANDOMX_FLAG_JIT;
if (cache == NULL) {
cache = randomx_alloc_cache(flags | RANDOMX_FLAG_LARGE_PAGES);
if (cache == NULL) {
Expand All @@ -282,14 +318,9 @@ void rx_slow_hash(const uint64_t mainheight, const uint64_t seedheight, const ch
memcpy(rx_sp->rs_hash, seedhash, HASH_SIZE);
}
if (rx_vm == NULL) {
randomx_flags flags = RANDOMX_FLAG_DEFAULT;
if (use_rx_jit()) {
flags |= RANDOMX_FLAG_JIT;
if (!miners)
flags |= RANDOMX_FLAG_SECURE;
if ((flags & RANDOMX_FLAG_JIT) && !miners) {
flags |= RANDOMX_FLAG_SECURE;
}
if(!force_software_aes() && check_aes_hw())
flags |= RANDOMX_FLAG_HARD_AES;
if (miners) {
CTHR_MUTEX_LOCK(rx_dataset_mutex);
if (rx_dataset == NULL) {
Expand Down

0 comments on commit 060d0ce

Please sign in to comment.