finally fix Monero v7 commit and other fixes
- automatic selection of Monero Cryptonight variant if --monero is used - keepalive for Cryptonight is fixed - fixed command line options - updated documentation - removal of unused code - fixed potential out of bounds reads - better sgminer integration of ethash
This commit is contained in:
1 parent
bc138413d9
commit
b5399059f7
13 files changed
+403
-677
No files matched your search
+23
-13
@@ -973,7 +973,7 @@ static cl_int queue_ethash_kernel(_clState *clState, dev_blk_ctx *blk, __maybe_u
|
||||
unsigned int num = 0;
|
||||
cl_int status = 0;
|
||||
cl_ulong le_target;
|
||||
cl_uint HighNonce, Isolate = UINT32_MAX;
|
||||
cl_uint Isolate = UINT32_MAX;
|
||||
|
||||
dag = &blk->work->thr->cgpu->eth_dag;
|
||||
cg_ilock(&dag->lock);
|
||||
@@ -1060,10 +1060,7 @@ static cl_int queue_ethash_kernel(_clState *clState, dev_blk_ctx *blk, __maybe_u
|
||||
}
|
||||
|
||||
memcpy(&le_target, blk->work->device_target + 24, 8);
|
||||
mutex_lock(ð_nonce_lock);
|
||||
HighNonce = eth_nonce++;
|
||||
blk->work->Nonce = (cl_ulong) HighNonce << 32;
|
||||
mutex_unlock(ð_nonce_lock);
|
||||
blk->work->Nonce = (blk->work->Nonce >> 32 << 32) | blk->work->blk.nonce;
|
||||
|
||||
num = 0;
|
||||
kernel = &clState->kernel;
|
||||
@@ -1097,13 +1094,26 @@ static cl_int queue_cryptonight_kernel(_clState *clState, dev_blk_ctx *blk, __ma
|
||||
{
|
||||
cl_kernel *kernel = &clState->kernel;
|
||||
unsigned int num = 0;
|
||||
cl_int status = 0, tgt32 = (blk->work->XMRTarget);
|
||||
cl_ulong le_target = ((cl_ulong)(blk->work->XMRTarget));
|
||||
cl_int status = 0, tgt32 = *(uint32_t*)(blk->work->target + 28);
|
||||
|
||||
int variant = monero_variant(blk->work);
|
||||
if (variant != clState->monero_variant) {
|
||||
applog(LOG_NOTICE, "switch to monero variant %d", variant);
|
||||
char kernel_name[20] = "search1";
|
||||
if (variant > 0)
|
||||
snprintf(kernel_name + 7, sizeof(kernel_name) - 7, "_var%d", variant);
|
||||
clReleaseKernel(clState->extra_kernels[0]);
|
||||
clState->extra_kernels[0] = clCreateKernel(clState->program, kernel_name, &status);
|
||||
if (status != CL_SUCCESS) {
|
||||
applog(LOG_ERR, "Error %d: Creating Kernel \"%s\" from program. (clCreateKernel)", kernel_name, status);
|
||||
return status;
|
||||
}
|
||||
clState->monero_variant = variant;
|
||||
}
|
||||
|
||||
//le_target = *(cl_ulong *)(blk->work->device_target + 24);
|
||||
memcpy(clState->cldata, blk->work->data, blk->work->XMRBlobLen);
|
||||
|
||||
status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, blk->work->XMRBlobLen, clState->cldata , 0, NULL, NULL);
|
||||
status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, CL_FALSE, 0, blk->work->XMRBlobLen, clState->cldata , 0, NULL, NULL);
|
||||
|
||||
CL_SET_ARG(clState->CLbuffer0);
|
||||
CL_SET_ARG(blk->work->XMRBlobLen);
|
||||
@@ -1299,11 +1309,11 @@ static algorithm_settings_t algos[] = {
|
||||
{ "blake256r14", ALGO_BLAKE, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x00000000UL, 0, 128, 0, blake256_regenhash, precalc_hash_blake256, queue_blake_kernel, gen_hash, NULL },
|
||||
{ "vanilla", ALGO_VANILLA, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x000000ffUL, 0, 128, 0, blakecoin_regenhash, precalc_hash_blakecoin, queue_blake_kernel, gen_hash, NULL },
|
||||
|
||||
{ "ethash", ALGO_ETHASH, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFF000000000000ULL, 0x000000FFUL, 0, 128, 0, ethash_regenhash, NULL, queue_ethash_kernel, gen_hash, append_ethash_compiler_options },
|
||||
{ "ethash-genoil", ALGO_ETHASH, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFF000000000000ULL, 0x000000FFUL, 0, 128, 0, ethash_regenhash, NULL, queue_ethash_kernel, gen_hash, append_ethash_compiler_options },
|
||||
{ "ethash-new", ALGO_ETHASH, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFF000000000000ULL, 0x000000FFUL, 0, 128, 0, ethash_regenhash, NULL, queue_ethash_kernel, gen_hash, append_ethash_compiler_options },
|
||||
{ "ethash", ALGO_ETHASH, "", 0x100010001LLU, 0x100010001LLU, 0x100010001LLU, 0, 0, 0xFF, 0xFFFF000000000000ULL, 72UL, 0, 128, 0, ethash_regenhash, NULL, queue_ethash_kernel, gen_hash, append_ethash_compiler_options },
|
||||
{ "ethash-genoil", ALGO_ETHASH, "", 0x100010001LLU, 0x100010001LLU, 0x100010001LLU, 0, 0, 0xFF, 0xFFFF000000000000ULL, 72UL, 0, 128, 0, ethash_regenhash, NULL, queue_ethash_kernel, gen_hash, append_ethash_compiler_options },
|
||||
{ "ethash-new", ALGO_ETHASH, "", 0x100010001LLU, 0x100010001LLU, 0x100010001LLU, 0, 0, 0xFF, 0xFFFF000000000000ULL, 72UL, 0, 128, 0, ethash_regenhash, NULL, queue_ethash_kernel, gen_hash, append_ethash_compiler_options },
|
||||
|
||||
{ "cryptonight", ALGO_CRYPTONIGHT, "", (1ULL << 32), (1ULL << 32), (1ULL << 32), 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 6, 0, 0, cryptonight_regenhash, NULL, queue_cryptonight_kernel, gen_hash, NULL },
|
||||
{ "cryptonight", ALGO_CRYPTONIGHT, "", 1, 0x100010001LLU, 0x100010001LLU, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 6, 0, 0, cryptonight_regenhash, NULL, queue_cryptonight_kernel, gen_hash, NULL },
|
||||
|
||||
{ "equihash", ALGO_EQUIHASH, "", 1, (1ULL << 28), (1ULL << 28), 0, 0, 0x20000, 0xFFFF000000000000ULL, 0x00000000UL, 0, 128, 0, equihash_regenhash, NULL, queue_equihash_kernel, gen_hash, append_equihash_compiler_options },
|
||||
|
||||
|
||||
+14
-11
@@ -16,19 +16,25 @@
|
||||
#define VARIANT1_1(p) \
|
||||
do if (Variant > 0) \
|
||||
{ \
|
||||
uint8_t tmp = ((const uint8_t*)(p))[11]; \
|
||||
uint8_t tmp1 = (tmp>>4)&1, tmp2 = (tmp>>5)&1, tmp3 = tmp1^tmp2; \
|
||||
uint8_t tmp0 = nonce_flag ? tmp3 : tmp1 + 1; \
|
||||
((uint8_t*)(p))[11] = (tmp & 0xef) | (tmp0<<4); \
|
||||
const uint8_t tmp = ((const uint8_t*)(p))[11]; \
|
||||
static const uint32_t table = 0x75310; \
|
||||
const uint8_t index = (((tmp >> 3) & 6) | (tmp & 1)) << 1; \
|
||||
((uint8_t*)(p))[11] = tmp ^ ((table >> index) & 0x30); \
|
||||
} while(0)
|
||||
|
||||
#define VARIANT1_2(p) \
|
||||
do \
|
||||
{ \
|
||||
((uint32_t*)(p))[2] ^= nonce; \
|
||||
} while(0)
|
||||
|
||||
#define VARIANT1_2(p) VARIANT1_1(p)
|
||||
#define VARIANT1_INIT() \
|
||||
if (Variant > 0 && Length < 43) \
|
||||
{ \
|
||||
quit(1, "Cryptonight variants need at least 43 bytes of data"); \
|
||||
} \
|
||||
const uint8_t nonce_flag = Variant > 0 ? ((const uint8_t*)Input)[39] & 0x01 : 0
|
||||
const uint32_t nonce = Variant > 0 ? *(uint32_t*)(Input + 39) : 0
|
||||
|
||||
|
||||
static const uint64_t keccakf_rndc[24] =
|
||||
{
|
||||
@@ -321,19 +327,16 @@ void cryptonight(uint8_t *Output, uint8_t *Input, uint32_t Length, int Variant)
|
||||
void cryptonight_regenhash(struct work *work)
|
||||
{
|
||||
uint32_t data[20];
|
||||
uint32_t *nonce = (uint32_t *)(work->data + 39);
|
||||
int variant = opt_cryptonight_monero && ((uint8_t *)work->data)[0] >= 7 ? ((uint8_t *)work->data)[0] - 6 : 0;
|
||||
int variant = monero_variant(work);
|
||||
uint32_t *ohash = (uint32_t *)(work->hash);
|
||||
|
||||
work->XMRNonce = *nonce;
|
||||
|
||||
memcpy(data, work->data, work->XMRBlobLen);
|
||||
|
||||
cryptonight(ohash, data, work->XMRBlobLen, variant);
|
||||
|
||||
char *tmpdbg = bin2hex((uint8_t*) ohash, 32);
|
||||
|
||||
applog(LOG_DEBUG, "cryptonight_regenhash: %s\n", tmpdbg);
|
||||
applog(LOG_DEBUG, "cryptonight_regenhash_var%d: %s", variant, tmpdbg);
|
||||
|
||||
free(tmpdbg);
|
||||
|
||||
|
||||
@@ -3,10 +3,14 @@
|
||||
|
||||
typedef struct _CryptonightCtx
|
||||
{
|
||||
uint64_t State[25];
|
||||
uint64_t Scratchpad[1 << 18];
|
||||
uint64_t State[25];
|
||||
uint64_t Scratchpad[1 << 18];
|
||||
} CryptonightCtx;
|
||||
|
||||
inline int monero_variant(struct work *work) {
|
||||
return (work->is_monero && work->data[0] >= 7) ? work->data[0] - 6 : 0;
|
||||
}
|
||||
|
||||
void cryptonight_regenhash(struct work *work);
|
||||
|
||||
#endif
|
||||
@@ -4,26 +4,23 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//#include "compiler.h"
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
struct ethash_h256;
|
||||
|
||||
#define decsha3(bits) \
|
||||
int sha3_##bits(uint8_t*, size_t, uint8_t const*, size_t);
|
||||
int sha3_##bits(uint8_t*, size_t, uint8_t const*, size_t);
|
||||
|
||||
decsha3(256)
|
||||
decsha3(512)
|
||||
|
||||
static inline void SHA3_256(struct ethash_h256 const* ret, uint8_t const* data, size_t const size)
|
||||
static inline void SHA3_256(uint8_t* ret, uint8_t const* data, size_t const size)
|
||||
{
|
||||
sha3_256((uint8_t*)ret, 32, data, size);
|
||||
sha3_256(ret, 32, data, size);
|
||||
}
|
||||
|
||||
static inline void SHA3_512(uint8_t* ret, uint8_t const* data, size_t const size)
|
||||
{
|
||||
sha3_512(ret, 64, data, size);
|
||||
sha3_512(ret, 64, data, size);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
+5
-7
@@ -118,15 +118,13 @@ void LightEthash(uint8_t *restrict OutHash, uint8_t *restrict MixHash, const uin
|
||||
|
||||
void ethash_regenhash(struct work *work)
|
||||
{
|
||||
work->Nonce += *((uint32_t *)(work->data + 32));
|
||||
uint8_t hash[32];
|
||||
applog(LOG_DEBUG, "Regenhash: First qword of input: 0x%016llX.", work->Nonce);
|
||||
cg_rlock(&work->pool->data_lock);
|
||||
LightEthash(work->hash, work->mixhash, work->data, (Node *)work->pool->eth_cache.dag_cache, work->eth_epoch, work->Nonce);
|
||||
LightEthash(hash, work->mixhash, work->data, (Node *)work->pool->eth_cache.dag_cache, work->eth_epoch, work->Nonce);
|
||||
for (int i = 0; i < 32; i++)
|
||||
work->hash[i] = hash[31 - i];
|
||||
cg_runlock(&work->pool->data_lock);
|
||||
|
||||
char *DbgHash = bin2hex(work->hash, 32);
|
||||
|
||||
applog(LOG_DEBUG, "Regenhash result: %s.", DbgHash);
|
||||
applog(LOG_DEBUG, "Last ulong: 0x%016llX.", bswap_64(*((uint64_t *)(work->hash + 0))));
|
||||
free(DbgHash);
|
||||
applog(LOG_DEBUG, "Last ulong: 0x%016llX.", *((uint64_t *)(work->hash + 24)));
|
||||
}
|
||||
+8
-2
@@ -1321,8 +1321,14 @@ static json_t *build_pool_json()
|
||||
// pass
|
||||
json_pool_add(obj, "pass", json_string(pool->rpc_pass), pool->pool_no);
|
||||
|
||||
if (!pool->extranonce_subscribe)
|
||||
json_pool_add(obj, "no-extranonce", json_true(), pool->pool_no);
|
||||
if (pool->extranonce_subscribe)
|
||||
json_pool_add(obj, "extranonce", json_true(), pool->pool_no);
|
||||
|
||||
if (pool->no_keepalive)
|
||||
json_pool_add(obj, "no-keepalive", json_true(), pool->pool_no);
|
||||
|
||||
if (pool->is_monero)
|
||||
json_pool_add(obj, "monero", json_true(), pool->pool_no);
|
||||
|
||||
if (!empty_string(pool->description))
|
||||
json_pool_add(obj, "no-description", json_string(pool->description), pool->pool_no);
|
||||
|
||||
+42
-8
@@ -437,6 +437,7 @@ sgminer 4.2.1-116-g2e8b-dirty
|
||||
* [algorithm](#algorithm)
|
||||
* [description](#description)
|
||||
* [device](#device)
|
||||
* [extranonce](#extranonce)
|
||||
* [gpu-engine](#gpu-engine)
|
||||
* [gpu-fan](#gpu-fan)
|
||||
* [gpu-memclock](#gpu-memclock)
|
||||
@@ -445,9 +446,10 @@ sgminer 4.2.1-116-g2e8b-dirty
|
||||
* [gpu-vddc](#gpu-vddc)
|
||||
* [intensity](#intensity)
|
||||
* [lookup-gap](#lookup-gap)
|
||||
* [monero](#monero)
|
||||
* [name](#pool-name)
|
||||
* [nfactor](#nfactor)
|
||||
* [no-extranonce](#no-extranonce)
|
||||
* [no-keepalive](#no-keepalive)
|
||||
* [pass](#pass)
|
||||
* [priority](#priority)
|
||||
* [profile](#profile)
|
||||
@@ -1262,7 +1264,7 @@ Used with [auto-fan](#auto-fan) and [auto-gpu](#auto-gpu).
|
||||
|
||||
[Top](#configuration-and-command-line-options) :: [Config-file and CLI options](#config-file-and-cli-options) :: [GPU Options](#gpu-options)
|
||||
|
||||
### temp-cutoff
|
||||
### temp-hysteresis
|
||||
|
||||
Set the allowable temperature fluctuation a GPU can operate outside of limits.
|
||||
|
||||
@@ -1366,6 +1368,22 @@ See [device](#device).
|
||||
|
||||
[Top](#configuration-and-command-line-options) :: [Config-file and CLI options](#config-file-and-cli-options) :: [Pool Options](#pool-options)
|
||||
|
||||
### extranonce
|
||||
|
||||
Enables 'extranonce.subscribe' stratum functionality.
|
||||
|
||||
*Available*: Global, Pool
|
||||
|
||||
*Config File Syntax:* `"extranonce":true`
|
||||
|
||||
*Command Line Syntax:* `--extranonce` `--pool-extranonce`
|
||||
|
||||
*Argument:* None
|
||||
|
||||
*Default:* `false`
|
||||
|
||||
[Top](#configuration-and-command-line-options) :: [Config-file and CLI options](#config-file-and-cli-options) :: [Pool Options](#pool-options)
|
||||
|
||||
### [pool-]gpu-engine
|
||||
|
||||
See [gpu-engine](#gpu-engine)
|
||||
@@ -1414,6 +1432,22 @@ See [lookup-gap](#lookup-gap)
|
||||
|
||||
[Top](#configuration-and-command-line-options) :: [Config-file and CLI options](#config-file-and-cli-options) :: [Pool Options](#pool-options)
|
||||
|
||||
### monero
|
||||
|
||||
This flag is required for Monero mining after the hard fork in March 2018. When it is set then the appropriate Cryptonight variant for Monero is chosen automatically.
|
||||
|
||||
*Available*: Global, Pool
|
||||
|
||||
*Config File Syntax:* `"monero":true`
|
||||
|
||||
*Command Line Syntax:* `--monero` `--pool-monero`
|
||||
|
||||
*Argument:* None
|
||||
|
||||
*Default:* `false`
|
||||
|
||||
[Top](#configuration-and-command-line-options) :: [Config-file and CLI options](#config-file-and-cli-options) :: [Pool Options](#pool-options)
|
||||
|
||||
### [pool-]name
|
||||
|
||||
Set a name for a pool.
|
||||
@@ -1436,15 +1470,15 @@ See [nfactor](#nfactor)
|
||||
|
||||
[Top](#configuration-and-command-line-options) :: [Config-file and CLI options](#config-file-and-cli-options) :: [Pool Options](#pool-options)
|
||||
|
||||
### no-extranonce
|
||||
### no-keepalive
|
||||
|
||||
Disable 'extranonce' stratum subscribe for pool.
|
||||
Disables periodic sending of keepalive packets. Currently only used by Cryptonight.
|
||||
|
||||
*Available*: Pool
|
||||
*Available*: Global, Pool
|
||||
|
||||
*Config File Syntax:* `"no-extranonce":true`
|
||||
*Config File Syntax:* `"no-keepalive":true`
|
||||
|
||||
*Command Line Syntax:* `--no-extranonce` `--pool-no-extranonce`
|
||||
*Command Line Syntax:* `--no-keepalive` `--pool-no-keepalive`
|
||||
|
||||
*Argument:* None
|
||||
|
||||
@@ -2593,4 +2627,4 @@ Message to display on sgminer exit when event occurs.
|
||||
* `gpu_sick` Occurs when a GPU fails to respond for 2 minutes
|
||||
* `gpu_dead` Occurs when a GPU fails to respond for 10 minutes
|
||||
|
||||
[Top](#configuration-and-command-line-options)
|
||||
[Top](#configuration-and-command-line-options)
|
||||
+2
-1
@@ -1483,8 +1483,9 @@ static int64_t opencl_scanhash(struct thr_info *thr, struct work *work,
|
||||
mutex_unlock(&work->pool->XMRGlobalNonceLock);
|
||||
}
|
||||
|
||||
size_t global_work_offset = work->blk.nonce;
|
||||
if (clState->goffset)
|
||||
p_global_work_offset = (size_t *)&work->blk.nonce;
|
||||
p_global_work_offset = &global_work_offset;
|
||||
|
||||
if (gpu->algorithm.type == ALGO_CRYPTONIGHT) {
|
||||
size_t GlobalThreads = *globalThreads, Nonce[2] = { (size_t)work->blk.nonce, 1}, gthreads[2] = { *globalThreads, 8 }, lthreads[2] = { *localThreads, 8 };
|
||||
|
||||
+119
-383
@@ -7,21 +7,25 @@
|
||||
#include "blake256.cl"
|
||||
#include "groestl256.cl"
|
||||
|
||||
#define VARIANT0_1(p)
|
||||
#define VARIANT0_2(p)
|
||||
#define VARIANT0_INIT()
|
||||
|
||||
#define VARIANT1_1(p) \
|
||||
do if (variant > 0) \
|
||||
do \
|
||||
{ \
|
||||
uint tmp32 = (p).z; \
|
||||
uint tmp = tmp32 >> 24; \
|
||||
uint tmp1 = (tmp>>4)&1, tmp2 = (tmp>>5)&1, tmp3 = tmp1^tmp2; \
|
||||
uint tmp0 = nonce_flag ? tmp3 : tmp1 + 1; \
|
||||
tmp32 &= 0x00ffffff; tmp32 |= ((tmp & 0xef) | (tmp0<<4)) << 24; \
|
||||
(p).z = tmp32; \
|
||||
uint table = 0x75310U; \
|
||||
uint index = (((p).s2 >> 26) & 12) | (((p).s2 >> 23) & 2); \
|
||||
(p).s2 ^= ((table >> index) & 0x30U) << 24; \
|
||||
} while(0)
|
||||
|
||||
#define VARIANT1_2(p) VARIANT1_1(p)
|
||||
#define VARIANT1_INIT() \
|
||||
int variant = 1; \
|
||||
const int nonce_flag = ((get_global_id(0) - get_global_offset(0))) & 1
|
||||
#define VARIANT1_2(p) \
|
||||
do \
|
||||
{ \
|
||||
(p).s2 ^= get_global_id(0); \
|
||||
} while(0)
|
||||
|
||||
#define VARIANT1_INIT()
|
||||
|
||||
|
||||
static const __constant ulong keccakf_rndc[24] =
|
||||
@@ -117,128 +121,52 @@ static const __constant uint keccakf_piln[24] =
|
||||
15, 23, 19, 13, 12, 2, 20, 14, 22, 9, 6, 1
|
||||
};
|
||||
|
||||
void keccakf1600_1(ulong *st)
|
||||
{
|
||||
int i, round;
|
||||
ulong t, bc[5];
|
||||
|
||||
#pragma unroll 1
|
||||
for(round = 0; round < 24; ++round)
|
||||
{
|
||||
|
||||
// Theta
|
||||
bc[0] = st[0] ^ st[5] ^ st[10] ^ st[15] ^ st[20];
|
||||
bc[1] = st[1] ^ st[6] ^ st[11] ^ st[16] ^ st[21];
|
||||
bc[2] = st[2] ^ st[7] ^ st[12] ^ st[17] ^ st[22];
|
||||
bc[3] = st[3] ^ st[8] ^ st[13] ^ st[18] ^ st[23];
|
||||
bc[4] = st[4] ^ st[9] ^ st[14] ^ st[19] ^ st[24];
|
||||
|
||||
#pragma unroll 1
|
||||
for (i = 0; i < 5; ++i) {
|
||||
t = bc[(i + 4) % 5] ^ rotate(bc[(i + 1) % 5], 1UL);
|
||||
st[i ] ^= t;
|
||||
st[i + 5] ^= t;
|
||||
st[i + 10] ^= t;
|
||||
st[i + 15] ^= t;
|
||||
st[i + 20] ^= t;
|
||||
}
|
||||
|
||||
// Rho Pi
|
||||
t = st[1];
|
||||
#pragma unroll
|
||||
for (i = 0; i < 24; ++i) {
|
||||
bc[0] = st[keccakf_piln[i]];
|
||||
st[keccakf_piln[i]] = rotate(t, (ulong)keccakf_rotc[i]);
|
||||
t = bc[0];
|
||||
}
|
||||
|
||||
//ulong tmp1 = st[0]; ulong tmp2 = st[1]; st[0] = bitselect(st[0] ^ st[2], st[0], st[1]); st[1] = bitselect(st[1] ^ st[3], st[1], st[2]); st[2] = bitselect(st[2] ^ st[4], st[2], st[3]); st[3] = bitselect(st[3] ^ tmp1, st[3], st[4]); st[4] = bitselect(st[4] ^ tmp2, st[4], tmp1);
|
||||
//tmp1 = st[5]; tmp2 = st[6]; st[5] = bitselect(st[5] ^ st[7], st[5], st[6]); st[6] = bitselect(st[6] ^ st[8], st[6], st[7]); st[7] = bitselect(st[7] ^ st[9], st[7], st[8]); st[8] = bitselect(st[8] ^ tmp1, st[8], st[9]); st[9] = bitselect(st[9] ^ tmp2, st[9], tmp1);
|
||||
//tmp1 = st[10]; tmp2 = st[11]; st[10] = bitselect(st[10] ^ st[12], st[10], st[11]); st[11] = bitselect(st[11] ^ st[13], st[11], st[12]); st[12] = bitselect(st[12] ^ st[14], st[12], st[13]); st[13] = bitselect(st[13] ^ tmp1, st[13], st[14]); st[14] = bitselect(st[14] ^ tmp2, st[14], tmp1);
|
||||
//tmp1 = st[15]; tmp2 = st[16]; st[15] = bitselect(st[15] ^ st[17], st[15], st[16]); st[16] = bitselect(st[16] ^ st[18], st[16], st[17]); st[17] = bitselect(st[17] ^ st[19], st[17], st[18]); st[18] = bitselect(st[18] ^ tmp1, st[18], st[19]); st[19] = bitselect(st[19] ^ tmp2, st[19], tmp1);
|
||||
//tmp1 = st[20]; tmp2 = st[21]; st[20] = bitselect(st[20] ^ st[22], st[20], st[21]); st[21] = bitselect(st[21] ^ st[23], st[21], st[22]); st[22] = bitselect(st[22] ^ st[24], st[22], st[23]); st[23] = bitselect(st[23] ^ tmp1, st[23], st[24]); st[24] = bitselect(st[24] ^ tmp2, st[24], tmp1);
|
||||
|
||||
#pragma unroll 1
|
||||
for(int i = 0; i < 25; i += 5)
|
||||
{
|
||||
ulong tmp[5];
|
||||
|
||||
#pragma unroll 1
|
||||
for(int x = 0; x < 5; ++x)
|
||||
tmp[x] = bitselect(st[i + x] ^ st[i + ((x + 2) % 5)], st[i + x], st[i + ((x + 1) % 5)]);
|
||||
|
||||
#pragma unroll 1
|
||||
for(int x = 0; x < 5; ++x) st[i + x] = tmp[x];
|
||||
}
|
||||
|
||||
// Iota
|
||||
st[0] ^= keccakf_rndc[round];
|
||||
}
|
||||
}
|
||||
|
||||
void keccakf1600_2(ulong *st)
|
||||
{
|
||||
int i, round;
|
||||
ulong t, bc[5];
|
||||
|
||||
#pragma unroll 1
|
||||
|
||||
#pragma unroll 1
|
||||
for(round = 0; round < 24; ++round)
|
||||
{
|
||||
|
||||
// Theta
|
||||
//bc[0] = st[0] ^ st[5] ^ st[10] ^ st[15] ^ st[20];
|
||||
//bc[1] = st[1] ^ st[6] ^ st[11] ^ st[16] ^ st[21];
|
||||
//bc[2] = st[2] ^ st[7] ^ st[12] ^ st[17] ^ st[22];
|
||||
//bc[3] = st[3] ^ st[8] ^ st[13] ^ st[18] ^ st[23];
|
||||
//bc[4] = st[4] ^ st[9] ^ st[14] ^ st[19] ^ st[24];
|
||||
|
||||
/*
|
||||
#pragma unroll
|
||||
for (i = 0; i < 5; ++i) {
|
||||
t = bc[(i + 4) % 5] ^ rotate(bc[(i + 1) % 5], 1UL);
|
||||
st[i ] ^= t;
|
||||
st[i + 5] ^= t;
|
||||
st[i + 10] ^= t;
|
||||
st[i + 15] ^= t;
|
||||
st[i + 20] ^= t;
|
||||
}
|
||||
*/
|
||||
|
||||
bc[0] = st[0] ^ st[5] ^ st[10] ^ st[15] ^ st[20] ^ rotate(st[2] ^ st[7] ^ st[12] ^ st[17] ^ st[22], 1UL);
|
||||
bc[1] = st[1] ^ st[6] ^ st[11] ^ st[16] ^ st[21] ^ rotate(st[3] ^ st[8] ^ st[13] ^ st[18] ^ st[23], 1UL);
|
||||
bc[2] = st[2] ^ st[7] ^ st[12] ^ st[17] ^ st[22] ^ rotate(st[4] ^ st[9] ^ st[14] ^ st[19] ^ st[24], 1UL);
|
||||
bc[3] = st[3] ^ st[8] ^ st[13] ^ st[18] ^ st[23] ^ rotate(st[0] ^ st[5] ^ st[10] ^ st[15] ^ st[20], 1UL);
|
||||
bc[4] = st[4] ^ st[9] ^ st[14] ^ st[19] ^ st[24] ^ rotate(st[1] ^ st[6] ^ st[11] ^ st[16] ^ st[21], 1UL);
|
||||
|
||||
st[0] ^= bc[4];
|
||||
st[5] ^= bc[4];
|
||||
st[10] ^= bc[4];
|
||||
st[15] ^= bc[4];
|
||||
st[20] ^= bc[4];
|
||||
|
||||
st[1] ^= bc[0];
|
||||
st[6] ^= bc[0];
|
||||
st[11] ^= bc[0];
|
||||
st[16] ^= bc[0];
|
||||
st[21] ^= bc[0];
|
||||
|
||||
st[2] ^= bc[1];
|
||||
st[7] ^= bc[1];
|
||||
st[12] ^= bc[1];
|
||||
st[17] ^= bc[1];
|
||||
st[22] ^= bc[1];
|
||||
|
||||
st[3] ^= bc[2];
|
||||
st[8] ^= bc[2];
|
||||
st[13] ^= bc[2];
|
||||
st[18] ^= bc[2];
|
||||
st[23] ^= bc[2];
|
||||
|
||||
st[4] ^= bc[3];
|
||||
st[9] ^= bc[3];
|
||||
st[14] ^= bc[3];
|
||||
st[19] ^= bc[3];
|
||||
st[24] ^= bc[3];
|
||||
|
||||
bc[0] = st[0] ^ st[5] ^ st[10] ^ st[15] ^ st[20] ^ rotate(st[2] ^ st[7] ^ st[12] ^ st[17] ^ st[22], 1UL);
|
||||
bc[1] = st[1] ^ st[6] ^ st[11] ^ st[16] ^ st[21] ^ rotate(st[3] ^ st[8] ^ st[13] ^ st[18] ^ st[23], 1UL);
|
||||
bc[2] = st[2] ^ st[7] ^ st[12] ^ st[17] ^ st[22] ^ rotate(st[4] ^ st[9] ^ st[14] ^ st[19] ^ st[24], 1UL);
|
||||
bc[3] = st[3] ^ st[8] ^ st[13] ^ st[18] ^ st[23] ^ rotate(st[0] ^ st[5] ^ st[10] ^ st[15] ^ st[20], 1UL);
|
||||
bc[4] = st[4] ^ st[9] ^ st[14] ^ st[19] ^ st[24] ^ rotate(st[1] ^ st[6] ^ st[11] ^ st[16] ^ st[21], 1UL);
|
||||
|
||||
st[0] ^= bc[4];
|
||||
st[5] ^= bc[4];
|
||||
st[10] ^= bc[4];
|
||||
st[15] ^= bc[4];
|
||||
st[20] ^= bc[4];
|
||||
|
||||
st[1] ^= bc[0];
|
||||
st[6] ^= bc[0];
|
||||
st[11] ^= bc[0];
|
||||
st[16] ^= bc[0];
|
||||
st[21] ^= bc[0];
|
||||
|
||||
st[2] ^= bc[1];
|
||||
st[7] ^= bc[1];
|
||||
st[12] ^= bc[1];
|
||||
st[17] ^= bc[1];
|
||||
st[22] ^= bc[1];
|
||||
|
||||
st[3] ^= bc[2];
|
||||
st[8] ^= bc[2];
|
||||
st[13] ^= bc[2];
|
||||
st[18] ^= bc[2];
|
||||
st[23] ^= bc[2];
|
||||
|
||||
st[4] ^= bc[3];
|
||||
st[9] ^= bc[3];
|
||||
st[14] ^= bc[3];
|
||||
st[19] ^= bc[3];
|
||||
st[24] ^= bc[3];
|
||||
|
||||
// Rho Pi
|
||||
t = st[1];
|
||||
@@ -248,55 +176,16 @@ void keccakf1600_2(ulong *st)
|
||||
st[keccakf_piln[i]] = rotate(t, (ulong)keccakf_rotc[i]);
|
||||
t = bc[0];
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*ulong tmp1 = st[1] ^ bc[0];
|
||||
|
||||
st[0] ^= bc[4];
|
||||
st[1] = rotate(st[6] ^ bc[0], 44UL);
|
||||
st[6] = rotate(st[9] ^ bc[3], 20UL);
|
||||
st[9] = rotate(st[22] ^ bc[1], 61UL);
|
||||
st[22] = rotate(st[14] ^ bc[3], 39UL);
|
||||
st[14] = rotate(st[20] ^ bc[4], 18UL);
|
||||
st[20] = rotate(st[2] ^ bc[1], 62UL);
|
||||
st[2] = rotate(st[12] ^ bc[1], 43UL);
|
||||
st[12] = rotate(st[13] ^ bc[2], 25UL);
|
||||
st[13] = rotate(st[19] ^ bc[3], 8UL);
|
||||
st[19] = rotate(st[23] ^ bc[2], 56UL);
|
||||
st[23] = rotate(st[15] ^ bc[4], 41UL);
|
||||
st[15] = rotate(st[4] ^ bc[3], 27UL);
|
||||
st[4] = rotate(st[24] ^ bc[3], 14UL);
|
||||
st[24] = rotate(st[21] ^ bc[0], 2UL);
|
||||
st[21] = rotate(st[8] ^ bc[2], 55UL);
|
||||
st[8] = rotate(st[16] ^ bc[0], 35UL);
|
||||
st[16] = rotate(st[5] ^ bc[4], 36UL);
|
||||
st[5] = rotate(st[3] ^ bc[2], 28UL);
|
||||
st[3] = rotate(st[18] ^ bc[2], 21UL);
|
||||
st[18] = rotate(st[17] ^ bc[1], 15UL);
|
||||
st[17] = rotate(st[11] ^ bc[0], 10UL);
|
||||
st[11] = rotate(st[7] ^ bc[1], 6UL);
|
||||
st[7] = rotate(st[10] ^ bc[4], 3UL);
|
||||
st[10] = rotate(tmp1, 1UL);
|
||||
*/
|
||||
|
||||
|
||||
//ulong tmp1 = st[0]; ulong tmp2 = st[1]; st[0] = bitselect(st[0] ^ st[2], st[0], st[1]); st[1] = bitselect(st[1] ^ st[3], st[1], st[2]); st[2] = bitselect(st[2] ^ st[4], st[2], st[3]); st[3] = bitselect(st[3] ^ tmp1, st[3], st[4]); st[4] = bitselect(st[4] ^ tmp2, st[4], tmp1);
|
||||
//tmp1 = st[5]; tmp2 = st[6]; st[5] = bitselect(st[5] ^ st[7], st[5], st[6]); st[6] = bitselect(st[6] ^ st[8], st[6], st[7]); st[7] = bitselect(st[7] ^ st[9], st[7], st[8]); st[8] = bitselect(st[8] ^ tmp1, st[8], st[9]); st[9] = bitselect(st[9] ^ tmp2, st[9], tmp1);
|
||||
//tmp1 = st[10]; tmp2 = st[11]; st[10] = bitselect(st[10] ^ st[12], st[10], st[11]); st[11] = bitselect(st[11] ^ st[13], st[11], st[12]); st[12] = bitselect(st[12] ^ st[14], st[12], st[13]); st[13] = bitselect(st[13] ^ tmp1, st[13], st[14]); st[14] = bitselect(st[14] ^ tmp2, st[14], tmp1);
|
||||
//tmp1 = st[15]; tmp2 = st[16]; st[15] = bitselect(st[15] ^ st[17], st[15], st[16]); st[16] = bitselect(st[16] ^ st[18], st[16], st[17]); st[17] = bitselect(st[17] ^ st[19], st[17], st[18]); st[18] = bitselect(st[18] ^ tmp1, st[18], st[19]); st[19] = bitselect(st[19] ^ tmp2, st[19], tmp1);
|
||||
//tmp1 = st[20]; tmp2 = st[21]; st[20] = bitselect(st[20] ^ st[22], st[20], st[21]); st[21] = bitselect(st[21] ^ st[23], st[21], st[22]); st[22] = bitselect(st[22] ^ st[24], st[22], st[23]); st[23] = bitselect(st[23] ^ tmp1, st[23], st[24]); st[24] = bitselect(st[24] ^ tmp2, st[24], tmp1);
|
||||
|
||||
#pragma unroll
|
||||
for(int i = 0; i < 25; i += 5)
|
||||
{
|
||||
ulong tmp1 = st[i], tmp2 = st[i + 1];
|
||||
|
||||
st[i] = bitselect(st[i] ^ st[i + 2], st[i], st[i + 1]);
|
||||
st[i + 1] = bitselect(st[i + 1] ^ st[i + 3], st[i + 1], st[i + 2]);
|
||||
st[i + 2] = bitselect(st[i + 2] ^ st[i + 4], st[i + 2], st[i + 3]);
|
||||
st[i + 3] = bitselect(st[i + 3] ^ tmp1, st[i + 3], st[i + 4]);
|
||||
st[i + 4] = bitselect(st[i + 4] ^ tmp2, st[i + 4], tmp1);
|
||||
for(int i = 0; i < 25; i += 5) {
|
||||
ulong tmp1 = st[i], tmp2 = st[i + 1];
|
||||
|
||||
st[i] = bitselect(st[i] ^ st[i + 2], st[i], st[i + 1]);
|
||||
st[i + 1] = bitselect(st[i + 1] ^ st[i + 3], st[i + 1], st[i + 2]);
|
||||
st[i + 2] = bitselect(st[i + 2] ^ st[i + 4], st[i + 2], st[i + 3]);
|
||||
st[i + 3] = bitselect(st[i + 3] ^ tmp1, st[i + 3], st[i + 4]);
|
||||
st[i + 4] = bitselect(st[i + 4] ^ tmp2, st[i + 4], tmp1);
|
||||
}
|
||||
|
||||
// Iota
|
||||
@@ -304,27 +193,6 @@ void keccakf1600_2(ulong *st)
|
||||
}
|
||||
}
|
||||
|
||||
void CNKeccak(ulong *output, ulong *input)
|
||||
{
|
||||
ulong st[25];
|
||||
|
||||
// Copy 72 bytes
|
||||
for(int i = 0; i < 9; ++i) st[i] = input[i];
|
||||
|
||||
// Last four and '1' bit for padding
|
||||
//st[9] = as_ulong((uint2)(((uint *)input)[18], 0x00000001U));
|
||||
|
||||
st[9] = (input[9] & 0x00000000FFFFFFFFUL) | 0x0000000100000000UL;
|
||||
|
||||
for(int i = 10; i < 25; ++i) st[i] = 0x00UL;
|
||||
|
||||
// Last bit of padding
|
||||
st[16] = 0x8000000000000000UL;
|
||||
|
||||
keccakf1600_1(st);
|
||||
|
||||
for(int i = 0; i < 25; ++i) output[i] = st[i];
|
||||
}
|
||||
|
||||
static const __constant uchar rcon[8] = { 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40 };
|
||||
|
||||
@@ -417,68 +285,68 @@ __kernel void search(__global ulong *input, uint InputLen, __global uint4 *Scrat
|
||||
|
||||
Scratchpad[IDX((i << 3) + get_local_id(1))] = text;
|
||||
}
|
||||
|
||||
mem_fence(CLK_GLOBAL_MEM_FENCE);
|
||||
}
|
||||
|
||||
__attribute__((reqd_work_group_size(WORKSIZE, 1, 1)))
|
||||
__kernel void search1(__global uint4 *Scratchpad, __global ulong *states)
|
||||
{
|
||||
ulong a[2], b[2];
|
||||
__local uint AES0[256], AES1[256], AES2[256], AES3[256];
|
||||
|
||||
VARIANT1_INIT();
|
||||
|
||||
Scratchpad += ((get_global_id(0) - get_global_offset(0)));
|
||||
states += (25 * (get_global_id(0) - get_global_offset(0)));
|
||||
|
||||
for(int i = get_local_id(0); i < 256; i += WORKSIZE)
|
||||
{
|
||||
const uint tmp = AES0_C[i];
|
||||
AES0[i] = tmp;
|
||||
AES1[i] = rotate(tmp, 8U);
|
||||
AES2[i] = rotate(tmp, 16U);
|
||||
AES3[i] = rotate(tmp, 24U);
|
||||
}
|
||||
|
||||
a[0] = states[0] ^ states[4];
|
||||
b[0] = states[2] ^ states[6];
|
||||
a[1] = states[1] ^ states[5];
|
||||
b[1] = states[3] ^ states[7];
|
||||
|
||||
uint4 b_x = ((uint4 *)b)[0];
|
||||
|
||||
mem_fence(CLK_LOCAL_MEM_FENCE);
|
||||
|
||||
#pragma unroll 8
|
||||
for(int i = 0; i < 0x80000; ++i)
|
||||
{
|
||||
ulong c[2];
|
||||
|
||||
((uint4 *)c)[0] = Scratchpad[IDX((a[0] & 0x1FFFF0) >> 4)];
|
||||
((uint4 *)c)[0] = AES_Round(AES0, AES1, AES2, AES3, ((uint4 *)c)[0], ((uint4 *)a)[0]);
|
||||
//b_x ^= ((uint4 *)c)[0];
|
||||
|
||||
Scratchpad[IDX((a[0] & 0x1FFFF0) >> 4)] = b_x ^ ((uint4 *)c)[0];
|
||||
VARIANT1_1(Scratchpad[IDX((a[0] & 0x1FFFF0) >> 4)]);
|
||||
|
||||
uint4 tmp;
|
||||
tmp = Scratchpad[IDX((c[0] & 0x1FFFF0) >> 4)];
|
||||
|
||||
a[1] += c[0] * as_ulong2(tmp).s0;
|
||||
a[0] += mul_hi(c[0], as_ulong2(tmp).s0);
|
||||
|
||||
Scratchpad[IDX((c[0] & 0x1FFFF0) >> 4)] = ((uint4 *)a)[0];
|
||||
VARIANT1_2(Scratchpad[IDX((c[0] & 0x1FFFF0) >> 4)]);
|
||||
|
||||
((uint4 *)a)[0] ^= tmp;
|
||||
|
||||
b_x = ((uint4 *)c)[0];
|
||||
}
|
||||
|
||||
mem_fence(CLK_GLOBAL_MEM_FENCE);
|
||||
#define SEARCH1(VAR) \
|
||||
__attribute__((reqd_work_group_size(WORKSIZE, 1, 1))) \
|
||||
__kernel void search1_var##VAR(__global uint4 *Scratchpad, __global ulong *states) \
|
||||
{ \
|
||||
uint4 a, b; \
|
||||
__local uint AES0[256], AES1[256], AES2[256], AES3[256]; \
|
||||
\
|
||||
VARIANT##VAR##_INIT(); \
|
||||
\
|
||||
Scratchpad += ((get_global_id(0) - get_global_offset(0))); \
|
||||
states += (25 * (get_global_id(0) - get_global_offset(0))); \
|
||||
\
|
||||
for(int i = get_local_id(0); i < 256; i += WORKSIZE) \
|
||||
{ \
|
||||
const uint tmp = AES0_C[i]; \
|
||||
AES0[i] = tmp; \
|
||||
AES1[i] = rotate(tmp, 8U); \
|
||||
AES2[i] = rotate(tmp, 16U); \
|
||||
AES3[i] = rotate(tmp, 24U); \
|
||||
} \
|
||||
\
|
||||
a.s01 = as_uint2(states[0] ^ states[4]); \
|
||||
b.s01 = as_uint2(states[2] ^ states[6]); \
|
||||
a.s23 = as_uint2(states[1] ^ states[5]); \
|
||||
b.s23 = as_uint2(states[3] ^ states[7]); \
|
||||
\
|
||||
uint4 b_x = b; \
|
||||
\
|
||||
mem_fence(CLK_LOCAL_MEM_FENCE); \
|
||||
\
|
||||
_Pragma("unroll 8") \
|
||||
for (int i = 0; i < 0x80000; ++i) \
|
||||
{ \
|
||||
uint4 c; \
|
||||
\
|
||||
c = Scratchpad[IDX((as_ulong(a.s01) & 0x1FFFF0) >> 4)]; \
|
||||
c = AES_Round(AES0, AES1, AES2, AES3, c, a); \
|
||||
\
|
||||
Scratchpad[IDX((as_ulong(a.s01) & 0x1FFFF0) >> 4)] = b_x ^ c; \
|
||||
VARIANT##VAR##_1(Scratchpad[IDX((as_ulong(a.s01) & 0x1FFFF0) >> 4)]); \
|
||||
\
|
||||
uint4 tmp; \
|
||||
tmp = Scratchpad[IDX((as_ulong(c.s01) & 0x1FFFF0) >> 4)]; \
|
||||
\
|
||||
a.s23 = as_uint2(as_ulong(a.s23) + as_ulong(c.s01) * as_ulong(tmp.s01)); \
|
||||
a.s01 = as_uint2(as_ulong(a.s01) + mul_hi(as_ulong(c.s01), as_ulong(tmp.s01))); \
|
||||
\
|
||||
Scratchpad[IDX((as_ulong(c.s01) & 0x1FFFF0) >> 4)] = a; \
|
||||
VARIANT##VAR##_2(Scratchpad[IDX((as_ulong(c.s01) & 0x1FFFF0) >> 4)]); \
|
||||
\
|
||||
a ^= tmp; \
|
||||
\
|
||||
b_x = c; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define search1_var0 search1
|
||||
SEARCH1(0)
|
||||
SEARCH1(1)
|
||||
|
||||
__attribute__((reqd_work_group_size(WORKSIZE, 8, 1)))
|
||||
__kernel void search2(__global uint4 *Scratchpad, __global ulong *states, __global uint *Branch0, __global uint *Branch1, __global uint *Branch2, __global uint *Branch3)
|
||||
{
|
||||
@@ -553,138 +421,8 @@ __kernel void search2(__global uint4 *Scratchpad, __global ulong *states, __glob
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
mem_fence(CLK_GLOBAL_MEM_FENCE);
|
||||
}
|
||||
|
||||
/*
|
||||
__kernel void cryptonight(__global ulong *input, __global uint4 *Scratchpad, __global ulong *states, __global uint *Branch0, __global uint *Branch1, __global uint *Branch2, __global uint *Branch3, ulong ThreadCount)
|
||||
{
|
||||
uchar State[200];
|
||||
__local uint AES0[256], AES1[256], AES2[256], AES3[256];
|
||||
uchar ExpandedKey1[256], ExpandedKey2[256];
|
||||
ulong inbuf[10], a[2], b[2];
|
||||
uint4 text[8];
|
||||
|
||||
VARIANT1_INIT();
|
||||
|
||||
for(int i = 0; i < 256; ++i)
|
||||
{
|
||||
const uint tmp = AES0_C[i];
|
||||
AES0[i] = tmp;
|
||||
AES1[i] = rotate(tmp, 8U);
|
||||
AES2[i] = rotate(tmp, 16U);
|
||||
AES3[i] = rotate(tmp, 24U);
|
||||
}
|
||||
|
||||
((ulong8 *)inbuf)[0] = vload8(0, input);
|
||||
inbuf[8] = input[8];
|
||||
inbuf[9] = (ulong)((__global uint *)input)[18];
|
||||
|
||||
((uint *)(((uchar *)inbuf) + 39))[0] = get_global_id(0);
|
||||
CNKeccak((ulong *)State, inbuf);
|
||||
|
||||
a[0] = ((ulong *)State)[0] ^ ((ulong *)State)[4];
|
||||
b[0] = ((ulong *)State)[2] ^ ((ulong *)State)[6];
|
||||
a[1] = ((ulong *)State)[1] ^ ((ulong *)State)[5];
|
||||
b[1] = ((ulong *)State)[3] ^ ((ulong *)State)[7];
|
||||
|
||||
for(uint i = 0; i < 8; ++i) text[i] = vload4(i + 4, (uint *)(State));
|
||||
|
||||
for(int i = 0; i < 4; ++i) ((ulong *)ExpandedKey1)[i] = ((ulong *)State)[i];
|
||||
for(int i = 0; i < 4; ++i) ((ulong *)ExpandedKey2)[i] = ((ulong *)State)[i + 4];
|
||||
|
||||
AESExpandKey256(ExpandedKey1);
|
||||
AESExpandKey256(ExpandedKey2);
|
||||
|
||||
mem_fence(CLK_LOCAL_MEM_FENCE);
|
||||
|
||||
Scratchpad += ((1 << 17) * (get_global_id(0) - get_global_offset(0)));
|
||||
|
||||
//#pragma unroll 1
|
||||
for(int i = 0; i < (1 << 17); i += 8)
|
||||
{
|
||||
#pragma unroll
|
||||
for(int j = 0; j < 10; ++j)
|
||||
{
|
||||
#pragma unroll
|
||||
for(int x = 0; x < 8; ++x)
|
||||
text[x] = AES_Round(AES0, AES1, AES2, AES3, text[x], ((uint4 *)ExpandedKey1)[j]);
|
||||
}
|
||||
|
||||
for(int j = 0; j < 8; ++j) *(Scratchpad + i + j) = text[j];
|
||||
}
|
||||
|
||||
|
||||
uint4 b_x = ((uint4 *)b)[0];
|
||||
|
||||
//#pragma unroll 1
|
||||
for(int i = 0; i < 0x80000; ++i)
|
||||
{
|
||||
ulong c[2];
|
||||
|
||||
((uint4 *)c)[0] = Scratchpad[(a[0] & 0x1FFFF0) >> 4];
|
||||
((uint4 *)c)[0] = AES_Round(AES0, AES1, AES2, AES3, ((uint4 *)c)[0], ((uint4 *)a)[0]);
|
||||
b_x ^= ((uint4 *)c)[0];
|
||||
|
||||
Scratchpad[(a[0] & 0x1FFFF0) >> 4] = b_x;
|
||||
VARIANT1_1(Scratchpad[(a[0] & 0x1FFFF0) >> 4]);
|
||||
|
||||
uint4 tmp;
|
||||
tmp = Scratchpad[(c[0] & 0x1FFFF0) >> 4];
|
||||
|
||||
a[1] += c[0] * as_ulong2(tmp).s0;
|
||||
a[0] += mul_hi(c[0], as_ulong2(tmp).s0);
|
||||
|
||||
Scratchpad[(c[0] & 0x1FFFF0) >> 4] = ((uint4 *)a)[0];
|
||||
VARIANT1_2(Scratchpad[(c[0] & 0x1FFFF0) >> 4]);
|
||||
|
||||
((uint4 *)a)[0] ^= tmp;
|
||||
|
||||
b_x = ((uint4 *)c)[0];
|
||||
}
|
||||
|
||||
for(uint i = 0; i < 8; ++i) text[i] = vload4(i + 4, (uint *)(State));
|
||||
|
||||
for(int i = 0; i < (1 << 17); i += 8)
|
||||
{
|
||||
#pragma unroll
|
||||
for(int j = 0; j < 8; ++j) text[j] ^= Scratchpad[i + j];
|
||||
|
||||
#pragma unroll 1
|
||||
for(int j = 0; j < 10; ++j)
|
||||
{
|
||||
#pragma unroll
|
||||
for(int x = 0; x < 8; ++x)
|
||||
text[x] = AES_Round(AES0, AES1, AES2, AES3, text[x], ((uint4 *)ExpandedKey2)[j]);
|
||||
}
|
||||
}
|
||||
|
||||
for(uint i = 0; i < 8; ++i) vstore4(text[i], i + 4, (uint *)(State));
|
||||
|
||||
keccakf1600((ulong *)State);
|
||||
|
||||
states += (25 * (get_global_id(0) - get_global_offset(0)));
|
||||
|
||||
for(int i = 0; i < 25; ++i) states[i] = ((ulong *)State)[i];
|
||||
|
||||
switch(State[0] & 3)
|
||||
{
|
||||
case 0:
|
||||
Branch0[atomic_inc(Branch0 + ThreadCount)] = get_global_id(0) - get_global_offset(0);
|
||||
break;
|
||||
case 1:
|
||||
Branch1[atomic_inc(Branch1 + ThreadCount)] = get_global_id(0) - get_global_offset(0);
|
||||
break;
|
||||
case 2:
|
||||
Branch2[atomic_inc(Branch2 + ThreadCount)] = get_global_id(0) - get_global_offset(0);
|
||||
break;
|
||||
case 3:
|
||||
Branch3[atomic_inc(Branch3 + ThreadCount)] = get_global_id(0) - get_global_offset(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
#define VSWAP8(x) (((x) >> 56) | (((x) >> 40) & 0x000000000000FF00UL) | (((x) >> 24) & 0x0000000000FF0000UL) \
|
||||
| (((x) >> 8) & 0x00000000FF000000UL) | (((x) << 8) & 0x000000FF00000000UL) \
|
||||
@@ -740,8 +478,6 @@ __kernel void search6(__global ulong *states, __global uint *BranchBuf, __global
|
||||
//vstore8(p, 0, output);
|
||||
|
||||
if(as_uint16(p).s7 <= Target) output[atomic_inc(output + 0xFF)] = BranchBuf[idx] + get_global_offset(0);
|
||||
|
||||
mem_fence(CLK_GLOBAL_MEM_FENCE);
|
||||
}
|
||||
|
||||
#define SWAP8(x) as_ulong(as_uchar8(x).s76543210)
|
||||
|
||||
@@ -1161,9 +1161,6 @@ extern bool opt_luffa_parallel;
|
||||
extern int opt_hamsi_expand_big;
|
||||
extern bool opt_hamsi_short;
|
||||
|
||||
// Cryptonight options
|
||||
extern bool opt_cryptonight_monero;
|
||||
|
||||
#if LOCK_TRACKING
|
||||
extern pthread_mutex_t lockstat_lock;
|
||||
#endif
|
||||
@@ -1181,6 +1178,7 @@ extern char *get_proxy(char *url, struct pool *pool);
|
||||
extern void __bin2hex(char *s, const unsigned char *p, size_t len);
|
||||
extern char *bin2hex(const unsigned char *p, size_t len);
|
||||
extern bool hex2bin(unsigned char *p, const char *hexstr, size_t len);
|
||||
extern bool eth_hex2bin(unsigned char *p, const char *hexstr, size_t len);
|
||||
|
||||
typedef bool (*sha256_func)(struct thr_info*, const unsigned char *pmidstate,
|
||||
unsigned char *pdata,
|
||||
@@ -1210,6 +1208,7 @@ extern void clear_stratum_shares(struct pool *pool);
|
||||
extern void clear_pool_work(struct pool *pool);
|
||||
extern void set_target(unsigned char *dest_target, double diff, double diff_multiplier2, const int thr_id);
|
||||
extern void set_target_neoscrypt(unsigned char *target, double diff, const int thr_id);
|
||||
extern double le256todiff(const void* le256, double diff_multiplier);
|
||||
|
||||
extern void kill_work(void);
|
||||
|
||||
@@ -1368,11 +1367,11 @@ struct pool {
|
||||
|
||||
//XMR stuff
|
||||
char XMRAuthID[64];
|
||||
uint32_t XMRTarget;
|
||||
uint32_t XMRBlobLen;
|
||||
uint8_t XMRBlob[128];
|
||||
pthread_mutex_t XMRGlobalNonceLock;
|
||||
uint32_t XMRGlobalNonce;
|
||||
bool is_monero;
|
||||
|
||||
double diff_accepted;
|
||||
double diff_rejected;
|
||||
@@ -1383,7 +1382,7 @@ struct pool {
|
||||
bool lagging;
|
||||
bool probed;
|
||||
enum pool_state state;
|
||||
bool keepalive;
|
||||
bool no_keepalive;
|
||||
bool submit_old;
|
||||
bool remove_at_start;
|
||||
bool removed;
|
||||
@@ -1531,11 +1530,8 @@ struct work {
|
||||
uint64_t Nonce;
|
||||
|
||||
/* cryptonight stuff */
|
||||
uint32_t XMRTarget;
|
||||
uint32_t XMRBlobLen;
|
||||
uint8_t XMRBlob[128];
|
||||
|
||||
uint32_t XMRNonce;
|
||||
bool is_monero;
|
||||
|
||||
unsigned char equihash_data[1487];
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ typedef struct __clState {
|
||||
bool goffset;
|
||||
cl_uint vwidth;
|
||||
int devid;
|
||||
int monero_variant;
|
||||
size_t max_work_size;
|
||||
size_t wsize;
|
||||
size_t compute_shaders;
|
||||
|
||||
@@ -138,11 +138,6 @@ bool opt_hamsi_short = false;
|
||||
bool opt_blake_compact = false;
|
||||
bool opt_luffa_parallel = false;
|
||||
|
||||
/*****************************************
|
||||
* Cryptonight Algorithm options
|
||||
*****************************************/
|
||||
bool opt_cryptonight_monero = true;
|
||||
|
||||
struct list_head scan_devices;
|
||||
bool devices_enabled[MAX_DEVICES];
|
||||
int opt_devs_enabled;
|
||||
@@ -304,7 +299,7 @@ static char datestamp[40];
|
||||
static char blocktime[32];
|
||||
struct timeval block_timeval;
|
||||
static char best_share[8] = "0";
|
||||
double current_diff = 0xFFFFFFFFFFFFFFFFULL;
|
||||
double current_diff = 0;
|
||||
static char block_diff[8];
|
||||
double best_diff = 0;
|
||||
|
||||
@@ -1092,18 +1087,12 @@ static char *set_pool_state(char *arg)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static char *set_pool_keepalive(char *arg)
|
||||
static char *set_pool_no_keepalive(char *arg)
|
||||
{
|
||||
struct pool *pool = get_current_pool();
|
||||
|
||||
applog(LOG_INFO, "Setting pool %s keepalive to %s", get_pool_name(pool), arg);
|
||||
if (strcmp(arg, "enabled") == 0) {
|
||||
pool->keepalive = true;
|
||||
} else if (strcmp(arg, "true") == 0) {
|
||||
pool->keepalive = true;
|
||||
} else {
|
||||
pool->keepalive = false;
|
||||
}
|
||||
applog(LOG_DEBUG, "Disable pool %s keepalive", get_pool_name(pool));
|
||||
opt_set_bool(&pool->no_keepalive);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -1188,12 +1177,22 @@ static char *set_userpass(const char *arg)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static char *set_no_extranonce_subscribe(char *arg)
|
||||
static char *set_extranonce_subscribe(char *arg)
|
||||
{
|
||||
struct pool *pool = get_current_pool();
|
||||
|
||||
applog(LOG_DEBUG, "Disable extranonce subscribe on %d", pool->pool_no);
|
||||
opt_set_invbool(&pool->extranonce_subscribe);
|
||||
applog(LOG_DEBUG, "Enable extranonce subscribe on %d", pool->pool_no);
|
||||
opt_set_bool(&pool->extranonce_subscribe);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static char *set_monero(char *arg)
|
||||
{
|
||||
struct pool *pool = get_current_pool();
|
||||
|
||||
applog(LOG_DEBUG, "Select appropriate Cryptonight Monero variant on %d", pool->pool_no);
|
||||
opt_set_bool(&pool->is_monero);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -1544,8 +1543,8 @@ struct opt_table opt_config_table[] = {
|
||||
OPT_WITHOUT_ARG("--hamsi-short",
|
||||
opt_set_bool, &opt_hamsi_short,
|
||||
"Set SPH_HAMSI_SHORT for X13 derived algorithms (Can give better hashrate for some GPUs)"),
|
||||
OPT_WITHOUT_ARG("--cryptonight-monero",
|
||||
opt_set_bool, &opt_cryptonight_monero,
|
||||
OPT_WITHOUT_ARG("--monero|--pool-monero",
|
||||
set_monero, NULL,
|
||||
"Use Monero Cryptonight variants as appropriate"),
|
||||
OPT_WITH_ARG("--keccak-unroll",
|
||||
set_int_0_to_9999, opt_show_intval, &opt_keccak_unroll,
|
||||
@@ -1627,9 +1626,9 @@ struct opt_table opt_config_table[] = {
|
||||
OPT_WITHOUT_ARG("--no-submit-stale",
|
||||
opt_set_invbool, &opt_submit_stale,
|
||||
"Don't submit shares if they are detected as stale"),
|
||||
OPT_WITHOUT_ARG("--no-extranonce|--pool-no-extranonce",
|
||||
set_no_extranonce_subscribe, NULL,
|
||||
"Disable 'extranonce' stratum subscribe for pool"),
|
||||
OPT_WITHOUT_ARG("--extranonce|--pool-extranonce",
|
||||
set_extranonce_subscribe, NULL,
|
||||
"Enable 'extranonce' stratum subscribe for pool"),
|
||||
OPT_WITH_ARG("--pass|--pool-pass|-p",
|
||||
set_pass, NULL, NULL,
|
||||
"Password for bitcoin JSON-RPC server"),
|
||||
@@ -1814,9 +1813,9 @@ struct opt_table opt_config_table[] = {
|
||||
OPT_WITH_ARG("--state|--pool-state",
|
||||
set_pool_state, NULL, NULL,
|
||||
"Specify pool state at startup (default: enabled)"),
|
||||
OPT_WITH_ARG("--keepalive|--pool-keepalive",
|
||||
set_pool_keepalive, NULL, NULL,
|
||||
"Specify pool if keepalived method is used (default: false)"),
|
||||
OPT_WITHOUT_ARG("--no-keepalive|--pool-no-keepalive",
|
||||
set_pool_no_keepalive, NULL,
|
||||
"Specify pool if keepalived method is not used (default: false)"),
|
||||
OPT_WITH_ARG("--switcher-mode",
|
||||
set_switcher_mode, NULL, NULL,
|
||||
"Algorithm/gpu settings switcher mode."),
|
||||
@@ -2446,14 +2445,13 @@ static bool gbt_decode(struct pool *pool, json_t *res_val)
|
||||
/* truediffone == 0x00000000FFFF0000000000000000000000000000000000000000000000000000
|
||||
* Generate a 256 bit binary LE target by cutting up diff into 64 bit sized
|
||||
* portions or vice versa. */
|
||||
const double eth2pow256 = 115792089237316195423570985008687907853269984665640564039457584007913129639936.0;
|
||||
const double truediffone = 26959535291011309493156476344723991336010898738574164086137773096960.0;
|
||||
const double bits192 = 6277101735386680763835789423207666416102355444464034512896.0;
|
||||
const double bits128 = 340282366920938463463374607431768211456.0;
|
||||
const double bits64 = 18446744073709551616.0;
|
||||
|
||||
/* Converts a little endian 256 bit value to a double */
|
||||
double le256todouble(const void *target)
|
||||
static double le256todouble(const void *target)
|
||||
{
|
||||
uint64_t *data64;
|
||||
double dcut64;
|
||||
@@ -2473,6 +2471,12 @@ double le256todouble(const void *target)
|
||||
return dcut64;
|
||||
}
|
||||
|
||||
double le256todiff(const void *le256, double diff_multiplier) {
|
||||
double d64 = diff_multiplier * truediffone;
|
||||
double s64 = le256todouble(le256);
|
||||
return d64 / (s64 + 1.);
|
||||
}
|
||||
|
||||
static bool getwork_decode(json_t *res_val, struct work *work)
|
||||
{
|
||||
size_t worklen = 128;
|
||||
@@ -2541,13 +2545,12 @@ out:
|
||||
}
|
||||
|
||||
|
||||
bool parse_diff_ethash(char* Target, const char* TgtStr);
|
||||
static bool work_decode_eth(struct pool *pool, struct work *work, json_t *val)
|
||||
{
|
||||
int i;
|
||||
bool ret = false;
|
||||
uint8_t EthWork[32], SeedHash[32], Target[32];
|
||||
const char *EthWorkStr, *SeedHashStr, *TgtStr, *BlockHeightStr, *NetDiffStr, FinalNetDiffStr[65];
|
||||
uint8_t SeedHash[32], Target[32];
|
||||
const char *EthWorkStr, *SeedHashStr, *TgtStr;
|
||||
|
||||
cgtime(&pool->tv_lastwork);
|
||||
|
||||
@@ -2561,17 +2564,15 @@ static bool work_decode_eth(struct pool *pool, struct work *work, json_t *val)
|
||||
|
||||
TgtStr = json_string_value(json_array_get(res_arr, 2));
|
||||
|
||||
if (EthWorkStr == NULL || SeedHashStr == NULL || TgtStr == NULL)
|
||||
if (!eth_hex2bin(work->data, EthWorkStr, 32))
|
||||
goto out;
|
||||
|
||||
if (!hex2bin(EthWork, EthWorkStr + 2, 32))
|
||||
if (!eth_hex2bin(SeedHash, SeedHashStr, 32))
|
||||
goto out;
|
||||
|
||||
if (!hex2bin(SeedHash, SeedHashStr + 2, 32))
|
||||
goto out;
|
||||
|
||||
if (!parse_diff_ethash(Target, TgtStr))
|
||||
if (!eth_hex2bin(Target, TgtStr, 32))
|
||||
goto out;
|
||||
swab256(work->target, Target);
|
||||
|
||||
cg_ilock(&pool->data_lock);
|
||||
if (pool->eth_cache.current_epoch == UINT32_MAX || memcmp(pool->eth_cache.seed_hash, SeedHash, 32)) {
|
||||
@@ -2583,14 +2584,14 @@ static bool work_decode_eth(struct pool *pool, struct work *work, json_t *val)
|
||||
}
|
||||
else
|
||||
cg_dlock(&pool->data_lock);
|
||||
//work->height = strtoul(BlockHeightStr + 2, NULL, 16) / 30000UL;
|
||||
mutex_lock(ð_nonce_lock);
|
||||
work->Nonce = (uint64_t) eth_nonce++ << 32;
|
||||
mutex_unlock(ð_nonce_lock);
|
||||
work->blk.nonce = 0;
|
||||
work->eth_epoch = pool->eth_cache.current_epoch;
|
||||
work->sdiff = le256todiff(work->target, work->pool->algorithm.diff_multiplier2);
|
||||
cg_runlock(&pool->data_lock);
|
||||
|
||||
memcpy(work->data, EthWork, 32);
|
||||
swab256(work->target, Target);
|
||||
|
||||
//work->network_diff = eth2pow256 / le256todouble(FinalNetDiffStr);
|
||||
cgtime(&work->tv_staged);
|
||||
ret = true;
|
||||
|
||||
@@ -3297,7 +3298,7 @@ static bool submit_upstream_work(struct work *work, CURL *curl, char *curl_err_s
|
||||
|
||||
if(work->pool->algorithm.type == ALGO_ETHASH) {
|
||||
s = (char *)malloc(sizeof(char) * (128 + 16 + 512));
|
||||
uint64_t tmp = bswap_64(work->Nonce);
|
||||
uint64_t tmp = htobe64(work->Nonce);
|
||||
char *ASCIIMixHash = bin2hex(work->mixhash, 32);
|
||||
char *ASCIIPoWHash = bin2hex(work->data, 32);
|
||||
char *ASCIINonce = bin2hex((uint8_t*) &tmp, 8);
|
||||
@@ -3723,10 +3724,6 @@ static void calc_diff(struct work *work, double known)
|
||||
dcut64 = 1;
|
||||
}
|
||||
|
||||
if(work->pool->algorithm.type == ALGO_ETHASH) {
|
||||
d64 = eth2pow256;
|
||||
}
|
||||
|
||||
work->work_difficulty = d64 / dcut64;
|
||||
applog(LOG_DEBUG, "Difficulty: %f", work->work_difficulty);
|
||||
}
|
||||
@@ -4318,22 +4315,9 @@ static bool stale_work(struct work *work, bool share)
|
||||
static double share_diff(const struct work *work)
|
||||
{
|
||||
bool new_best = false;
|
||||
double d64, s64;
|
||||
double ret;
|
||||
|
||||
if (work->pool->algorithm.type == ALGO_ETHASH) {
|
||||
uint8_t tmp[32];
|
||||
swab256(tmp, work->hash);
|
||||
ret = eth2pow256 / (le256todouble(tmp) + 1.);
|
||||
uint64_t le_target = *(uint64_t*) (work->target + 24);
|
||||
if (*(uint64_t*) (tmp + 24) > le_target)
|
||||
return ret;
|
||||
}
|
||||
else {
|
||||
d64 = work->pool->algorithm.share_diff_multiplier * truediffone;
|
||||
s64 = le256todouble(work->hash);
|
||||
ret = d64 / (s64 + 1.);
|
||||
}
|
||||
ret = le256todiff(work->hash, work->pool->algorithm.share_diff_multiplier);
|
||||
applog(LOG_DEBUG, "Found share with difficulty %.3f", ret);
|
||||
|
||||
cg_wlock(&control_lock);
|
||||
@@ -5572,7 +5556,7 @@ static bool parse_stratum_response(struct pool *pool, char *s)
|
||||
const char *s = json_string_value(status);
|
||||
|
||||
if (s && !strcmp(s, "KEEPALIVED")) {
|
||||
applog(LOG_NOTICE, "Keepalived from %s received", get_pool_name(pool));
|
||||
applog(LOG_DEBUG, "Keepalived from %s received", get_pool_name(pool));
|
||||
ret = true;
|
||||
goto out;
|
||||
}
|
||||
@@ -5852,21 +5836,6 @@ static void *stratum_rthread(void *userdata)
|
||||
timeout.tv_sec = 90;
|
||||
timeout.tv_usec = 0;
|
||||
|
||||
|
||||
if (pool->algorithm.type == ALGO_CRYPTONIGHT && pool->keepalive) {
|
||||
timeout_keep_alive.tv_sec = 60;
|
||||
timeout_keep_alive.tv_usec = 0;
|
||||
|
||||
if (!sock_full(pool) && (sel_ret = select(pool->sock + 1, &rd, NULL, NULL, &timeout_keep_alive)) < 1) {
|
||||
if (sock_keepalived(pool, pool->XMRAuthID, swork_id++)) {
|
||||
applog(LOG_NOTICE, "Stratum %s keepalived sent, id: %d", get_pool_name(pool), swork_id - 1);
|
||||
}
|
||||
|
||||
FD_ZERO(&rd);
|
||||
FD_SET(pool->sock, &rd);
|
||||
}
|
||||
}
|
||||
|
||||
/* The protocol specifies that notify messages should be sent
|
||||
* every minute so if we fail to receive any for 90 seconds we
|
||||
* assume the connection has been dropped and treat this pool
|
||||
@@ -5985,6 +5954,7 @@ static void *stratum_sthread(void *userdata)
|
||||
if (!(sshare = (struct stratum_share *)calloc(sizeof(struct stratum_share), 1))) {
|
||||
quit(1, "%s: calloc() failed on sshare.", __func__);
|
||||
}
|
||||
|
||||
if(pool->algorithm.type == ALGO_ETHASH) {
|
||||
sshare->sshare_time = time(NULL);
|
||||
/* This work item is freed in parse_stratum_response */
|
||||
@@ -5992,10 +5962,10 @@ static void *stratum_sthread(void *userdata)
|
||||
|
||||
applog(LOG_DEBUG, "stratum_sthread() algorithm = %s", pool->algorithm.name);
|
||||
|
||||
uint64_t tmp = bswap_64(work->Nonce);
|
||||
uint64_t tmp = htobe64(work->Nonce);
|
||||
char *ASCIIMixHash = bin2hex(work->mixhash, 32);
|
||||
char *ASCIIPoWHash = bin2hex(work->data, 32);
|
||||
char *ASCIINonce = bin2hex((uint8_t*) &tmp, 8);
|
||||
char *ASCIINonce = bin2hex((uint8_t*) &tmp + 4 - work->nonce2_len, 4 + work->nonce2_len);
|
||||
|
||||
mutex_lock(&sshare_lock);
|
||||
/* Give the stratum share a unique id */
|
||||
@@ -6017,7 +5987,7 @@ static void *stratum_sthread(void *userdata)
|
||||
|
||||
applog(LOG_DEBUG, "stratum_sthread() algorithm = %s", pool->algorithm.name);
|
||||
|
||||
char *ASCIINonce = bin2hex((uint8_t*) &work->XMRNonce, 4);
|
||||
char *ASCIINonce = bin2hex(work->data + 39, 4);
|
||||
|
||||
ASCIIResult = bin2hex(work->hash, 32);
|
||||
|
||||
@@ -6031,7 +6001,6 @@ static void *stratum_sthread(void *userdata)
|
||||
free(ASCIINonce);
|
||||
free(ASCIIResult);
|
||||
}
|
||||
|
||||
else if(pool->algorithm.type == ALGO_EQUIHASH) {
|
||||
char *nonce;
|
||||
char *solution;
|
||||
@@ -6589,7 +6558,23 @@ static void gen_stratum_work_eth(struct pool *pool, struct work *work)
|
||||
|
||||
applog(LOG_DEBUG, "[THR%d] gen_stratum_work() - algorithm = %s", work->thr_id, pool->algorithm.name);
|
||||
|
||||
cg_rlock(&pool->data_lock);
|
||||
cg_ilock(&pool->data_lock);
|
||||
uint32_t nonce2be = htobe32(pool->nonce2);
|
||||
if (pool->n1_len == 0) {
|
||||
cg_dlock(&pool->data_lock);
|
||||
mutex_lock(ð_nonce_lock);
|
||||
nonce2be = htobe32(eth_nonce++);
|
||||
mutex_unlock(ð_nonce_lock);
|
||||
}
|
||||
else {
|
||||
work->nonce1 = strdup(pool->nonce1);
|
||||
cg_ulock(&pool->data_lock);
|
||||
work->nonce2 = pool->nonce2++;
|
||||
cg_dwlock(&pool->data_lock);
|
||||
}
|
||||
memcpy(&nonce2be, pool->nonce1bin, pool->n1_len);
|
||||
work->Nonce = (uint64_t) be32toh(nonce2be) << 32;
|
||||
work->nonce2_len = pool->n2size;
|
||||
work->eth_epoch = pool->eth_cache.current_epoch;
|
||||
work->job_id = strdup(pool->swork.job_id);
|
||||
memcpy(work->data, pool->EthWork, 32);
|
||||
@@ -6597,6 +6582,7 @@ static void gen_stratum_work_eth(struct pool *pool, struct work *work)
|
||||
work->sdiff = pool->swork.diff;
|
||||
work->work_difficulty = pool->swork.diff;
|
||||
work->network_diff = pool->diff1;
|
||||
work->blk.nonce = 0;
|
||||
cg_runlock(&pool->data_lock);
|
||||
|
||||
local_work++;
|
||||
@@ -6626,20 +6612,16 @@ static void gen_stratum_work_cn(struct pool *pool, struct work *work)
|
||||
|
||||
cg_rlock(&pool->data_lock);
|
||||
work->job_id = strdup(pool->swork.job_id);
|
||||
work->XMRTarget = pool->XMRTarget;
|
||||
//strcpy(work->XMRID, pool->XMRID);
|
||||
//work->XMRBlockBlob = strdup(pool->XMRBlockBlob);
|
||||
memcpy(work->XMRBlob, pool->XMRBlob, pool->XMRBlobLen);
|
||||
memcpy(work->data, pool->XMRBlob, pool->XMRBlobLen);
|
||||
work->XMRBlobLen = pool->XMRBlobLen;
|
||||
memcpy(work->data, work->XMRBlob, work->XMRBlobLen);
|
||||
memset(work->target, 0xFF, 32);
|
||||
work->sdiff = (double)0xffffffff / pool->XMRTarget;
|
||||
memcpy(work->target, pool->Target, 32);
|
||||
work->sdiff = pool->swork.diff;
|
||||
work->work_difficulty = work->sdiff;
|
||||
work->network_diff = pool->diff1;
|
||||
work->is_monero = pool->is_monero;
|
||||
cg_runlock(&pool->data_lock);
|
||||
|
||||
work->target[7] = work->XMRTarget;
|
||||
|
||||
local_work++;
|
||||
work->pool = pool;
|
||||
work->stratum = true;
|
||||
@@ -7514,8 +7496,7 @@ static void rebuild_nonce(struct work *work, uint32_t nonce)
|
||||
nonce_pos = 39;
|
||||
|
||||
if (work->pool->algorithm.type == ALGO_ETHASH) {
|
||||
uint64_t *work_nonce = (uint64_t *)(work->data + 32);
|
||||
*work_nonce = htole32(nonce);
|
||||
work->Nonce += nonce;
|
||||
}
|
||||
else {
|
||||
uint32_t *work_nonce = (uint32_t *)(work->data + nonce_pos);
|
||||
@@ -7540,11 +7521,10 @@ bool test_nonce(struct work *work, uint32_t nonce)
|
||||
diff1targ = ((uint32_t *)work->target)[7];
|
||||
}
|
||||
else if (work->pool->algorithm.type == ALGO_ETHASH) {
|
||||
uint64_t target = *(uint64_t*) (work->device_target + 24);
|
||||
return (bswap_64(*(uint64_t*) work->hash) <= target);
|
||||
return fulltest(work->hash, work->device_target);
|
||||
}
|
||||
else if (work->pool->algorithm.type == ALGO_CRYPTONIGHT) {
|
||||
return (((uint32_t *)work->hash)[7] <= work->XMRTarget);
|
||||
diff1targ = *(uint32_t *)(work->target + 28);
|
||||
}
|
||||
else {
|
||||
diff1targ = work->pool->algorithm.diff1targ;
|
||||
@@ -7560,8 +7540,6 @@ static void update_work_stats(struct thr_info *thr, struct work *work)
|
||||
|
||||
work->share_diff = share_diff(work);
|
||||
|
||||
test_diff *= work->pool->algorithm.share_diff_multiplier;
|
||||
|
||||
if (unlikely(test_diff > 0 && work->share_diff >= test_diff)) {
|
||||
work->block = true;
|
||||
work->pool->solved++;
|
||||
@@ -7571,9 +7549,9 @@ static void update_work_stats(struct thr_info *thr, struct work *work)
|
||||
}
|
||||
|
||||
mutex_lock(&stats_lock);
|
||||
total_diff1 += work->device_diff;
|
||||
thr->cgpu->diff1 += work->device_diff;
|
||||
work->pool->diff1 += work->device_diff;
|
||||
total_diff1++; // += work->device_diff;
|
||||
thr->cgpu->diff1++; // += work->device_diff;
|
||||
work->pool->diff1++; // += work->device_diff;
|
||||
thr->cgpu->last_device_valid_work = time(NULL);
|
||||
mutex_unlock(&stats_lock);
|
||||
}
|
||||
@@ -7585,14 +7563,7 @@ bool submit_tested_work(struct thr_info *thr, struct work *work)
|
||||
struct work *work_out;
|
||||
update_work_stats(thr, work);
|
||||
|
||||
if (work->pool->algorithm.type == ALGO_ETHASH) {
|
||||
uint64_t LETarget = ((uint64_t *)work->target)[3];
|
||||
|
||||
if (bswap_64(((uint64_t *)work->hash)[0]) > LETarget) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (work->pool->algorithm.type == ALGO_CRYPTONIGHT) {
|
||||
if (work->pool->algorithm.type == ALGO_CRYPTONIGHT) {
|
||||
}
|
||||
else if (work->pool->algorithm.type == ALGO_EQUIHASH) {
|
||||
applog(LOG_DEBUG, "equihash target: %.16llx", *(uint64_t*) (work->target + 24));
|
||||
@@ -7712,14 +7683,11 @@ static void hash_sole_work(struct thr_info *mythr)
|
||||
|
||||
if (work->pool->algorithm.type == ALGO_NEOSCRYPT)
|
||||
set_target_neoscrypt(work->device_target, work->device_diff, work->thr_id);
|
||||
else if (work->pool->algorithm.type == ALGO_ETHASH) {
|
||||
double mult = 60e6;
|
||||
work->device_diff = MIN(work->work_difficulty, mult);
|
||||
*(uint64_t*) (work->device_target + 24) = bits64 / work->device_diff;
|
||||
work->device_diff /= mult;
|
||||
}
|
||||
else if (work->pool->algorithm.type != ALGO_EQUIHASH)
|
||||
else if (work->pool->algorithm.type != ALGO_EQUIHASH) {
|
||||
if (work->pool->algorithm.type == ALGO_ETHASH)
|
||||
work->device_diff = MIN(work->sdiff, 60e6);
|
||||
set_target(work->device_target, work->device_diff, work->pool->algorithm.diff_multiplier2, work->thr_id);
|
||||
}
|
||||
|
||||
do {
|
||||
cgtime(&tv_start);
|
||||
@@ -8189,6 +8157,8 @@ static void *watchpool_thread(void __maybe_unused *userdata)
|
||||
pool->testing = false;
|
||||
}
|
||||
|
||||
sock_keepalived(pool, pool->XMRAuthID, -1);
|
||||
|
||||
/* Test pool is idle once every minute */
|
||||
if (pool->idle && now.tv_sec - pool->tv_idle.tv_sec > 30) {
|
||||
cgtime(&pool->tv_idle);
|
||||
|
||||
@@ -670,6 +670,17 @@ bool hex2bin(unsigned char *p, const char *hexstr, size_t len)
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool eth_hex2bin(unsigned char *p, const char *hexstr, size_t len)
|
||||
{
|
||||
if (hexstr == NULL)
|
||||
return false;
|
||||
if (hexstr[0] == '0' && hexstr[1] == 'x')
|
||||
hexstr += 2;
|
||||
memset(p, 0, len);
|
||||
len = MIN(len, (strlen(hexstr) + 1) / 2);
|
||||
return hex2bin(p, hexstr, len);
|
||||
}
|
||||
|
||||
bool fulltest(const unsigned char *hash, const unsigned char *target)
|
||||
{
|
||||
uint32_t *hash32 = (uint32_t *)hash;
|
||||
@@ -1361,23 +1372,14 @@ bool sock_full(struct pool *pool)
|
||||
|
||||
bool sock_keepalived(struct pool *pool, const char *rpc2_id, int work_id)
|
||||
{
|
||||
json_t *val = NULL, *res_val, *err_val;
|
||||
char *s = NULL, *sret;
|
||||
json_error_t err;
|
||||
bool ret = false;
|
||||
bool ret = true;
|
||||
|
||||
if (pool->algorithm.type == ALGO_CRYPTONIGHT) {
|
||||
s = malloc(300 + strlen(rpc2_id) + 10);
|
||||
snprintf(s, 128, "{\"method\": \"keepalived\", \"params\": {\"id\": \"%s\"}, \"id\":%d}", rpc2_id, work_id);
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
if (!pool->no_keepalive && pool->algorithm.type == ALGO_CRYPTONIGHT) {
|
||||
size_t size = 128 + strlen(rpc2_id);
|
||||
char *s = malloc(size);
|
||||
snprintf(s, size, "{\"method\": \"keepalived\", \"params\": {\"id\": \"%s\"}, \"id\": \"ping\"}", rpc2_id);
|
||||
|
||||
if (stratum_send(pool, s, strlen(s))) {
|
||||
ret = true;
|
||||
}
|
||||
|
||||
if (s) {
|
||||
ret = stratum_send(pool, s, strlen(s));
|
||||
free(s);
|
||||
}
|
||||
|
||||
@@ -1648,38 +1650,15 @@ out:
|
||||
/* Annoying but we must not leak memory */
|
||||
//only free these if we failed
|
||||
if (!ret) {
|
||||
if (job_id != NULL) {
|
||||
free(job_id);
|
||||
}
|
||||
|
||||
if (prev_hash != NULL) {
|
||||
free(prev_hash);
|
||||
}
|
||||
|
||||
if (reserved != NULL) {
|
||||
free(reserved);
|
||||
}
|
||||
|
||||
if (merkle != NULL) {
|
||||
free(merkle);
|
||||
}
|
||||
|
||||
if (bbversion != NULL) {
|
||||
free(bbversion);
|
||||
}
|
||||
|
||||
if (nbit != NULL) {
|
||||
free(nbit);
|
||||
}
|
||||
|
||||
if (ntime != NULL) {
|
||||
free(ntime);
|
||||
}
|
||||
}
|
||||
|
||||
if (header != NULL) {
|
||||
free(header);
|
||||
free(job_id);
|
||||
free(prev_hash);
|
||||
free(reserved);
|
||||
free(merkle);
|
||||
free(bbversion);
|
||||
free(nbit);
|
||||
free(ntime);
|
||||
}
|
||||
free(header);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -1715,20 +1694,13 @@ static bool parse_notify(struct pool *pool, json_t *val)
|
||||
|
||||
if (!job_id || !prev_hash || !coinbase1 || !coinbase2 || !bbversion || !nbit || !ntime) {
|
||||
/* Annoying but we must not leak memory */
|
||||
if (job_id)
|
||||
free(job_id);
|
||||
if (prev_hash)
|
||||
free(prev_hash);
|
||||
if (coinbase1)
|
||||
free(coinbase1);
|
||||
if (coinbase2)
|
||||
free(coinbase2);
|
||||
if (bbversion)
|
||||
free(bbversion);
|
||||
if (nbit)
|
||||
free(nbit);
|
||||
if (ntime)
|
||||
free(ntime);
|
||||
free(job_id);
|
||||
free(prev_hash);
|
||||
free(coinbase1);
|
||||
free(coinbase2);
|
||||
free(bbversion);
|
||||
free(nbit);
|
||||
free(ntime);
|
||||
goto out;
|
||||
}
|
||||
|
||||
@@ -1845,45 +1817,14 @@ out:
|
||||
}
|
||||
|
||||
|
||||
bool parse_diff_ethash(char* Target, const char* TgtStr)
|
||||
{
|
||||
bool ret = false;
|
||||
int len = strlen(TgtStr);
|
||||
if(len != 64 && len != 66) {
|
||||
char NewTgtStr[65];
|
||||
int offset = (len > 2 && TgtStr[1] == 'x' ? 2 : 0);
|
||||
int PadLen = 64 + offset - len;
|
||||
|
||||
if (PadLen >= 0 && len >= offset) {
|
||||
memset(NewTgtStr, '0', PadLen);
|
||||
memcpy(NewTgtStr + PadLen, TgtStr + offset, len - offset);
|
||||
|
||||
NewTgtStr[64] = 0x00;
|
||||
ret = hex2bin(Target, NewTgtStr, 32);
|
||||
}
|
||||
}
|
||||
else
|
||||
ret = hex2bin(Target, TgtStr + 2, 32) || hex2bin(Target, TgtStr, 32);
|
||||
return ret;
|
||||
}
|
||||
|
||||
extern double eth2pow256;
|
||||
double le256todouble(const void *target);
|
||||
static bool parse_notify_ethash(struct pool *pool, json_t *val)
|
||||
{
|
||||
char *job_id;
|
||||
bool clean;
|
||||
uint8_t EthWork[32], SeedHash[32], Target[32], NetDiff[32];
|
||||
char *EthWorkStr, *SeedHashStr, *TgtStr, *BlockHeightStr, *NetDiffStr = NULL;
|
||||
char *EthWorkStr, *SeedHashStr, *TgtStr, *NetDiffStr = NULL;
|
||||
int ret = true;
|
||||
|
||||
/*json_t *arr = json_array_get(val, 0);
|
||||
if (!arr || !json_is_array(arr)) {
|
||||
applog(LOG_DEBUG, "parse_notify_ethash: Array was bad.");
|
||||
ret = false;
|
||||
goto out;
|
||||
}*/
|
||||
|
||||
job_id = json_array_string(val, 0);
|
||||
EthWorkStr = json_array_string(val, 1);
|
||||
SeedHashStr = json_array_string(val, 2);
|
||||
@@ -1901,21 +1842,20 @@ static bool parse_notify_ethash(struct pool *pool, json_t *val)
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret &= hex2bin(EthWork, EthWorkStr + 2, 32) || hex2bin(EthWork, EthWorkStr, 32);
|
||||
ret &= eth_hex2bin(EthWork, EthWorkStr, 32);
|
||||
|
||||
ret &= hex2bin(SeedHash, SeedHashStr + 2, 32) || hex2bin(SeedHash, SeedHashStr, 32);
|
||||
ret &= eth_hex2bin(SeedHash, SeedHashStr, 32);
|
||||
|
||||
ret &= parse_diff_ethash(Target, TgtStr);
|
||||
ret &= eth_hex2bin(Target, TgtStr, 32);
|
||||
|
||||
if (!ret || (NetDiffStr != NULL && !parse_diff_ethash(NetDiff, NetDiffStr))) {
|
||||
if (!ret || (NetDiffStr != NULL && !eth_hex2bin(NetDiff, NetDiffStr, 32))) {
|
||||
ret = false;
|
||||
goto out;
|
||||
}
|
||||
|
||||
cg_wlock(&pool->data_lock);
|
||||
|
||||
if (pool->swork.job_id != NULL)
|
||||
free(pool->swork.job_id);
|
||||
free(pool->swork.job_id);
|
||||
pool->swork.job_id = strdup(job_id);
|
||||
pool->swork.clean = clean;
|
||||
|
||||
@@ -1927,13 +1867,13 @@ static bool parse_notify_ethash(struct pool *pool, json_t *val)
|
||||
memcpy(pool->EthWork, EthWork, 32);
|
||||
|
||||
swab256(pool->Target, Target);
|
||||
pool->swork.diff = eth2pow256 / le256todouble(pool->Target);
|
||||
pool->swork.diff = le256todiff(pool->Target, pool->algorithm.diff_multiplier2);
|
||||
suffix_string_double(pool->swork.diff, pool->diff, sizeof(pool->diff), 0);
|
||||
|
||||
pool->diff1 = 0;
|
||||
if (NetDiffStr != NULL) {
|
||||
swab256(pool->NetDiff, NetDiff);
|
||||
pool->diff1 = eth2pow256 / le256todouble(pool->NetDiff);
|
||||
pool->diff1 = le256todiff(pool->NetDiff, pool->algorithm.diff_multiplier2);
|
||||
}
|
||||
pool->getwork_requested++;
|
||||
//pool->eth_cache.disabled = false;
|
||||
@@ -1954,16 +1894,11 @@ static bool parse_notify_ethash(struct pool *pool, json_t *val)
|
||||
opt_work_update = true;
|
||||
out:
|
||||
/* Annoying but we must not leak memory */
|
||||
if (job_id != NULL)
|
||||
free(job_id);
|
||||
if (SeedHashStr != NULL)
|
||||
free(SeedHashStr);
|
||||
if (EthWorkStr != NULL)
|
||||
free(EthWorkStr);
|
||||
if (TgtStr != NULL)
|
||||
free(TgtStr);
|
||||
if (NetDiffStr != NULL)
|
||||
free(NetDiffStr);
|
||||
free(job_id);
|
||||
free(SeedHashStr);
|
||||
free(EthWorkStr);
|
||||
free(TgtStr);
|
||||
free(NetDiffStr);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -2014,17 +1949,18 @@ bool parse_notify_cn(struct pool *pool, json_t *val)
|
||||
|
||||
cg_wlock(&pool->data_lock);
|
||||
|
||||
if (pool->swork.job_id != NULL) {
|
||||
free(pool->swork.job_id);
|
||||
}
|
||||
free(pool->swork.job_id);
|
||||
|
||||
pool->swork.job_id = strdup(job_id);
|
||||
pool->swork.clean = true;
|
||||
|
||||
pool->XMRBlobLen = strlen(blobval) >> 1;
|
||||
pool->diff1 = 0;
|
||||
memcpy(pool->XMRBlob, XMRBlob, pool->XMRBlobLen);
|
||||
pool->XMRTarget = XMRTarget;
|
||||
pool->swork.diff = (double)0xffffffff / XMRTarget;
|
||||
memset(pool->Target, 0xff, 28);
|
||||
memcpy(pool->Target + 28, &XMRTarget, 4);
|
||||
pool->swork.diff = (double)UINT32_MAX / XMRTarget;
|
||||
suffix_string_double(pool->swork.diff, pool->diff, sizeof(pool->diff), 0);
|
||||
pool->getwork_requested++;
|
||||
|
||||
cg_wunlock(&pool->data_lock);
|
||||
@@ -2107,9 +2043,7 @@ static bool parse_target(struct pool *pool, json_t *val)
|
||||
applog(pool == current_pool() ? LOG_NOTICE : LOG_DEBUG, "%s target changed to %s", get_pool_name(pool), str);
|
||||
}
|
||||
|
||||
if (str != NULL) {
|
||||
free(str);
|
||||
}
|
||||
free(str);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -2142,11 +2076,44 @@ static bool parse_extranonce_equihash(struct pool *pool, json_t *val)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool parse_extranonce_ethash(struct pool *pool, json_t *val)
|
||||
{
|
||||
char *n1str;
|
||||
|
||||
if (!(n1str = json_array_string(val, 0))) {
|
||||
applog(LOG_NOTICE, "extranonce failed");
|
||||
return false;
|
||||
}
|
||||
applog(LOG_NOTICE, "extranonce: %s", n1str);
|
||||
|
||||
cg_wlock(&pool->data_lock);
|
||||
free(pool->nonce1);
|
||||
pool->nonce1 = n1str;
|
||||
pool->n1_len = strlen(n1str) / 2; //size in bytes of nonce1 in the header
|
||||
|
||||
free(pool->nonce1bin);
|
||||
if (unlikely(!(pool->nonce1bin = (unsigned char *)calloc(pool->n1_len, 1)))) {
|
||||
quithere(1, "%s: Failed to calloc pool->nonce1bin", __func__);
|
||||
}
|
||||
|
||||
hex2bin(pool->nonce1bin, pool->nonce1, pool->n1_len);
|
||||
pool->n2size = 4 - pool->n1_len; //size in bytes of nonce2 in the header
|
||||
pool->nonce2 = 0; //reset nonce 2 to 0
|
||||
cg_wunlock(&pool->data_lock);
|
||||
|
||||
applog(LOG_NOTICE, "%s extranonce set to %s", get_pool_name(pool), n1str);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool parse_extranonce(struct pool *pool, json_t *val)
|
||||
{
|
||||
if (pool->algorithm.type == ALGO_EQUIHASH) {
|
||||
return parse_extranonce_equihash(pool, val);
|
||||
}
|
||||
else if (pool->algorithm.type == ALGO_ETHASH) {
|
||||
return parse_extranonce_ethash(pool, val);
|
||||
}
|
||||
|
||||
char *nonce1;
|
||||
int n2size;
|
||||
@@ -2456,7 +2423,6 @@ bool auth_stratum(struct pool *pool)
|
||||
if (pool->algorithm.type == ALGO_CRYPTONIGHT) {
|
||||
sprintf(s, "{\"method\": \"login\", \"params\": {\"login\": \"%s\", \"pass\": \"%s\", \"agent\": \"%s/%s\"}, \"id\": 1}",
|
||||
pool->rpc_user, pool->rpc_pass, PACKAGE, VERSION);
|
||||
|
||||
|
||||
swork_id++;
|
||||
}
|
||||
@@ -3060,13 +3026,17 @@ resend:
|
||||
{
|
||||
if(!pool->stratum_url) pool->stratum_url = pool->sockaddr_url;
|
||||
|
||||
cg_wlock(&pool->data_lock);
|
||||
pool->stratum_active = true;
|
||||
pool->next_diff = 0;
|
||||
pool->swork.diff = 1;
|
||||
|
||||
pool->sessionid = NULL;
|
||||
free(pool->nonce1);
|
||||
pool->nonce1 = NULL;
|
||||
pool->n1_len = 0;
|
||||
pool->n2size = 4;
|
||||
cg_wunlock(&pool->data_lock);
|
||||
|
||||
json_decref(val);
|
||||
return true;
|
||||
|
||||
Reference in new issue
Block a user