Skip to content

Commit

Permalink
panthera's block rejection fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Teredic committed May 9, 2020
1 parent ae88d27 commit eb147a0
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 72 deletions.
2 changes: 1 addition & 1 deletion src/crypto/randomx/blake2/blake2-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include <stdint.h>

#include "crypto/randomx/blake2/endian.h"
#include "endian.h"

static FORCE_INLINE uint64_t load48(const void *src) {
const uint8_t *p = (const uint8_t *)src;
Expand Down
6 changes: 3 additions & 3 deletions src/crypto/randomx/blake2/blake2b.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <string.h>
#include <stdio.h>

#include "crypto/randomx/blake2/blake2.h"
#include "crypto/randomx/blake2/blake2-impl.h"
#include "blake2.h"
#include "blake2-impl.h"

static const uint64_t blake2b_IV[8] = {
UINT64_C(0x6a09e667f3bcc908), UINT64_C(0xbb67ae8584caa73b),
UINT64_C(0x3c6ef372fe94f82b), UINT64_C(0xa54ff53a5f1d36f1),
UINT64_C(0x510e527fade682d1), UINT64_C(0x9b05688c2b3e6c1f),
UINT64_C(0x1f83d9abfb41bd6b), UINT64_C(0x5be0cd19137e2179) };

static const uint8_t blake2b_sigma[12][16] = {
static const unsigned int blake2b_sigma[12][16] = {
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
{14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3},
{11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4},
Expand Down
4 changes: 2 additions & 2 deletions src/crypto/randomx/blake2/blamka-round-ref.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef BLAKE_ROUND_MKA_H
#define BLAKE_ROUND_MKA_H

#include "crypto/randomx/blake2/blake2.h"
#include "crypto/randomx/blake2/blake2-impl.h"
#include "blake2.h"
#include "blake2-impl.h"

/* designed by the Lyra PHC team */
static FORCE_INLINE uint64_t fBlaMka(uint64_t x, uint64_t y) {
Expand Down
6 changes: 2 additions & 4 deletions src/crypto/randomx/blake2/endian.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
#include <string.h>

#if defined(_MSC_VER)
#define FORCE_INLINE __forceinline
#elif defined(__GNUC__)
#define FORCE_INLINE __attribute__((always_inline)) inline
#elif defined(__clang__)
#define FORCE_INLINE __inline
#elif defined(__GNUC__) || defined(__clang__)
#define FORCE_INLINE __inline__
#else
#define FORCE_INLINE
Expand Down
109 changes: 47 additions & 62 deletions src/crypto/randomx/randomx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,55 +134,44 @@ RandomX_ConfigurationScala::RandomX_ConfigurationScala()
// End of DefyX DATASET
}

//RandomX_ConfigurationScala2::RandomX_ConfigurationScala2()
//{
// ArgonIterations = 4;
// ArgonLanes = 2;
// ArgonSalt = "Panthera\x03";
// DatasetBaseSize = 33554432;
// ProgramSize = 320;
// ProgramCount = 3;
// ScratchpadL3_Size = 262144;
// ScratchpadL2_Size = 65536;
//
//}

RandomX_ConfigurationScala2::RandomX_ConfigurationScala2()
{
ArgonMemory = 262144;
ArgonIterations = 4;
ArgonLanes = 2;
ArgonSalt = "Panthera\x03";
CacheAccesses = 8;
SuperscalarLatency = 170;
DatasetBaseSize = 33554432;
DatasetExtraSize = 33554368;
ProgramSize = 320;
ProgramIterations = 2048;
ProgramCount = 3;
ScratchpadL3_Size = 262144;
ScratchpadL2_Size = 65536;
ScratchpadL1_Size = 16384;
JumpBits = 8;
JumpOffset = 8;

RANDOMX_FREQ_IADD_RS = 16;
RANDOMX_FREQ_IADD_M = 7;
RANDOMX_FREQ_ISUB_R = 16;
RANDOMX_FREQ_ISUB_M = 7;
RANDOMX_FREQ_IMUL_R = 16;
RANDOMX_FREQ_IMUL_M = 4;
RANDOMX_FREQ_IMULH_R = 4;
RANDOMX_FREQ_IMULH_M = 1;
RANDOMX_FREQ_ISMULH_R = 4;
RANDOMX_FREQ_ISMULH_M = 1;
RANDOMX_FREQ_IMUL_RCP = 8;
RANDOMX_FREQ_INEG_R = 2;
RANDOMX_FREQ_IXOR_R = 15;
RANDOMX_FREQ_IXOR_M = 5;
RANDOMX_FREQ_IROR_R = 8;
RANDOMX_FREQ_IROL_R = 2;
RANDOMX_FREQ_ISWAP_R = 4;
RANDOMX_FREQ_FSWAP_R = 4;
RANDOMX_FREQ_FADD_R = 16;
RANDOMX_FREQ_FADD_M = 5;
RANDOMX_FREQ_FSUB_R = 16;
RANDOMX_FREQ_FSUB_M = 5;
RANDOMX_FREQ_FSCAL_R = 6;
RANDOMX_FREQ_FMUL_R = 32;
RANDOMX_FREQ_FDIV_M = 4;
RANDOMX_FREQ_FSQRT_R = 6;
RANDOMX_FREQ_CBRANCH = 25;
RANDOMX_FREQ_CFROUND = 1;
RANDOMX_FREQ_ISTORE = 16;
RANDOMX_FREQ_NOP = 0;
ArgonMemory = 131072;
ArgonIterations = 2;
ArgonSalt = "DefyXScala\x13";
CacheAccesses = 2;
DatasetBaseSize = 33554432;
ProgramSize = 64;
ProgramIterations = 1024;
ProgramCount = 4;
ScratchpadL3_Size = 262144;
ScratchpadL2_Size = 131072;
ScratchpadL1_Size = 65536;

RANDOMX_FREQ_IADD_RS = 25;
RANDOMX_FREQ_CBRANCH = 16;

// DefyX DATASET (thanks MoneroOcean for the fix !)
const uint32_t DatasetBaseMask = DatasetBaseSize - RANDOMX_DATASET_ITEM_SIZE;
*(uint32_t*)(codeReadDatasetRyzenTweaked + 9) = DatasetBaseMask;
*(uint32_t*)(codeReadDatasetRyzenTweaked + 24) = DatasetBaseMask;
*(uint32_t*)(codeReadDatasetTweaked + 7) = DatasetBaseMask;
*(uint32_t*)(codeReadDatasetTweaked + 23) = DatasetBaseMask;
*(uint32_t*)(codeReadDatasetLightSshInitTweaked + 59) = DatasetBaseMask;
// End of DefyX DATASET
}

RandomX_ConfigurationKeva::RandomX_ConfigurationKeva()
Expand Down Expand Up @@ -470,31 +459,25 @@ int yespower_hash(const void *data, size_t length, void *hash)
{
yespower_params_t params = {
.version = YESPOWER_1_0,
.N = 1024,
.r = 4,
.N = 2048,
.r = 8,
.pers = NULL
};

int finale_yespower = yespower_tls((const uint8_t *)data, length, &params, (yespower_binary_t *)hash);
return finale_yespower; //0 for success
}

int k12_yp(const void *data, size_t length, void *hash)
{

int kDo = KangarooTwelve((const unsigned char *)data, length, (unsigned char *)hash, 32, 0, 0);
return kDo;
}

extern "C" {

void defyx2_calculate_hash(randomx_vm *machine, const void *input, size_t inputSize, void *output) {
assert(machine != nullptr);
assert(inputSize == 0 || input != nullptr);
assert(output != nullptr);
alignas(16) uint64_t tempHash[8];
yespower_hash(input, inputSize, tempHash);
k12_yp(input, inputSize, tempHash);
rx_blake2b(tempHash, sizeof(tempHash), input, inputSize, 0, 0);
yespower_hash(tempHash, sizeof(tempHash), tempHash);
k12(tempHash, sizeof(tempHash), tempHash);
machine->initScratchpad(&tempHash);
machine->resetRoundingMode();
for (uint32_t chain = 0; chain < RandomX_CurrentConfig.ProgramCount - 1; ++chain) {
Expand All @@ -506,8 +489,9 @@ extern "C" {
}

void defyx2_calculate_hash_first(randomx_vm* machine, uint64_t (&tempHash)[8], const void* input, size_t inputSize) {
yespower_hash(input, inputSize, tempHash);
k12_yp(input, inputSize, tempHash);
rx_blake2b(tempHash, sizeof(tempHash), input, inputSize, 0, 0);
yespower_hash(tempHash, sizeof(tempHash), tempHash);
k12(tempHash, sizeof(tempHash), tempHash);
machine->initScratchpad(tempHash);
}

Expand All @@ -520,8 +504,9 @@ extern "C" {
machine->run(&tempHash);

// Finish current hash and fill the scratchpad for the next hash at the same time
yespower_hash(nextInput, nextInputSize, tempHash);
k12_yp(nextInput, nextInputSize, tempHash);
rx_blake2b(tempHash, sizeof(tempHash), nextInput, nextInputSize, 0, 0);
yespower_hash(tempHash, sizeof(tempHash), tempHash);
k12(tempHash, sizeof(tempHash), tempHash);
machine->hashAndFill(output, RANDOMX_HASH_SIZE, tempHash);
}

Expand Down

0 comments on commit eb147a0

Please sign in to comment.