stratum: add deep, timetravel and hmq1725 algos

Signed-off-by: Tanguy Pruvot <tanguy.pruvot@gmail.com>
This commit is contained in:
Tanguy Pruvot 2017-02-20 23:48:54 +01:00
parent 9b2d591bd5
commit ca022f2628
16 changed files with 555 additions and 5 deletions

View file

@ -20,6 +20,8 @@ screen -dmS debug tail -f $LOG_DIR/debug.log
# Stratum instances (skipped/exit if no .conf)
screen -dmS c11 $STRATUM_DIR/run.sh c11
screen -dmS deep $STRATUM_DIR/run.sh deep
screen -dmS x11 $STRATUM_DIR/run.sh x11
screen -dmS x11evo $STRATUM_DIR/run.sh x11evo
screen -dmS x13 $STRATUM_DIR/run.sh x13
@ -27,6 +29,8 @@ screen -dmS x14 $STRATUM_DIR/run.sh x14
screen -dmS x15 $STRATUM_DIR/run.sh x15
screen -dmS x17 $STRATUM_DIR/run.sh x17
screen -dmS xevan $STRATUM_DIR/run.sh xevan
screen -dmS timetravel $STRATUM_DIR/run.sh timetravel
screen -dmS hmq1725 $STRATUM_DIR/run.sh hmq1725
screen -dmS sha $STRATUM_DIR/run.sh sha
screen -dmS scrypt $STRATUM_DIR/run.sh scrypt

29
stratum/algos/deep.c Normal file
View file

@ -0,0 +1,29 @@
#include <string.h>
#include <stdlib.h>
#include <sha3/sph_luffa.h>
#include <sha3/sph_cubehash.h>
#include <sha3/sph_echo.h>
void deep_hash(const char* input, char* output, uint32_t len)
{
sph_luffa512_context ctx_luffa;
sph_cubehash512_context ctx_cubehash;
sph_echo512_context ctx_echo;
char hash1[64], hash2[64];
sph_luffa512_init(&ctx_luffa);
sph_luffa512(&ctx_luffa, (const void*) input, len);
sph_luffa512_close(&ctx_luffa, (void*) &hash1);
sph_cubehash512_init(&ctx_cubehash);
sph_cubehash512(&ctx_cubehash, (const void*) &hash1, 64);
sph_cubehash512_close(&ctx_cubehash, (void*) &hash2);
sph_echo512_init(&ctx_echo);
sph_echo512(&ctx_echo, (const void*) &hash2, 64);
sph_echo512_close(&ctx_echo, (void*) &hash1);
memcpy(output, &hash1, 32);
}

17
stratum/algos/deep.h Normal file
View file

@ -0,0 +1,17 @@
#ifndef DEEP_H
#define DEEP_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
void deep_hash(const char* input, char* output, uint32_t len);
#ifdef __cplusplus
}
#endif
#endif

218
stratum/algos/hmq17.c Normal file
View file

@ -0,0 +1,218 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sha3/sph_blake.h>
#include <sha3/sph_bmw.h>
#include <sha3/sph_groestl.h>
#include <sha3/sph_jh.h>
#include <sha3/sph_keccak.h>
#include <sha3/sph_skein.h>
#include <sha3/sph_luffa.h>
#include <sha3/sph_cubehash.h>
#include <sha3/sph_shavite.h>
#include <sha3/sph_simd.h>
#include <sha3/sph_echo.h>
#include <sha3/sph_hamsi.h>
#include <sha3/sph_fugue.h>
#include <sha3/sph_shabal.h>
#include <sha3/sph_whirlpool.h>
#include <sha3/sph_sha2.h>
#include <sha3/sph_haval.h>
typedef struct
{
sph_blake512_context blake1, blake2;
sph_bmw512_context bmw1, bmw2, bmw3;
sph_groestl512_context groestl1, groestl2;
sph_skein512_context skein1, skein2;
sph_jh512_context jh1, jh2;
sph_keccak512_context keccak1, keccak2;
sph_luffa512_context luffa1, luffa2;
sph_cubehash512_context cubehash;
sph_shavite512_context shavite1, shavite2;
sph_simd512_context simd1, simd2;
sph_echo512_context echo1, echo2;
sph_hamsi512_context hamsi;
sph_fugue512_context fugue1, fugue2;
sph_shabal512_context shabal;
sph_whirlpool_context whirlpool1, whirlpool2, whirlpool3, whirlpool4;
sph_sha512_context sha1, sha2;
sph_haval256_5_context haval1, haval2;
} hmq_contexts;
static __thread hmq_contexts base_contexts;
static __thread int hmq_context_init = 0;
static void init_contexts(hmq_contexts *ctx)
{
sph_bmw512_init(&ctx->bmw1);
sph_bmw512_init(&ctx->bmw2);
sph_bmw512_init(&ctx->bmw2);
sph_bmw512_init(&ctx->bmw3);
sph_whirlpool_init(&ctx->whirlpool1);
sph_whirlpool_init(&ctx->whirlpool2);
sph_whirlpool_init(&ctx->whirlpool3);
sph_whirlpool_init(&ctx->whirlpool4);
sph_groestl512_init(&ctx->groestl1);
sph_groestl512_init(&ctx->groestl2);
sph_skein512_init(&ctx->skein1);
sph_skein512_init(&ctx->skein2);
sph_jh512_init(&ctx->jh1);
sph_jh512_init(&ctx->jh2);
sph_keccak512_init(&ctx->keccak1);
sph_keccak512_init(&ctx->keccak2);
sph_blake512_init(&ctx->blake1);
sph_blake512_init(&ctx->blake2);
sph_luffa512_init(&ctx->luffa1);
sph_luffa512_init(&ctx->luffa2);
sph_cubehash512_init(&ctx->cubehash);
sph_shavite512_init(&ctx->shavite1);
sph_shavite512_init(&ctx->shavite2);
sph_simd512_init(&ctx->simd1);
sph_simd512_init(&ctx->simd2);
sph_echo512_init(&ctx->echo1);
sph_echo512_init(&ctx->echo2);
sph_hamsi512_init(&ctx->hamsi);
sph_fugue512_init(&ctx->fugue1);
sph_fugue512_init(&ctx->fugue2);
sph_shabal512_init(&ctx->shabal);
sph_sha512_init(&ctx->sha1);
sph_sha512_init(&ctx->sha2);
sph_haval256_5_init(&ctx->haval1);
sph_haval256_5_init(&ctx->haval2);
}
void hmq17_hash(const char* input, char* output, uint32_t len)
{
uint32_t hash[32];
const uint32_t mask = 24;
hmq_contexts ctx;
if (!hmq_context_init) {
init_contexts(&base_contexts);
hmq_context_init = 1;
}
memcpy(&ctx, &base_contexts, sizeof(hmq_contexts));
sph_bmw512(&ctx.bmw1, input, len);
sph_bmw512_close(&ctx.bmw1, hash);
sph_whirlpool(&ctx.whirlpool1, hash, 64);
sph_whirlpool_close(&ctx.whirlpool1, hash);
if (hash[0] & mask) {
sph_groestl512(&ctx.groestl1, hash, 64);
sph_groestl512_close(&ctx.groestl1, hash);
} else {
sph_skein512(&ctx.skein1, hash, 64);
sph_skein512_close(&ctx.skein1, hash);
}
sph_jh512(&ctx.jh1, hash, 64);
sph_jh512_close(&ctx.jh1, hash);
sph_keccak512(&ctx.keccak1, hash, 64);
sph_keccak512_close(&ctx.keccak1, hash);
if (hash[0] & mask) {
sph_blake512(&ctx.blake1, hash, 64);
sph_blake512_close(&ctx.blake1, hash);
} else {
sph_bmw512 (&ctx.bmw2, hash, 64);
sph_bmw512_close(&ctx.bmw2, hash);
}
sph_luffa512(&ctx.luffa1, hash, 64);
sph_luffa512_close(&ctx.luffa1, hash);
sph_cubehash512(&ctx.cubehash, hash, 64);
sph_cubehash512_close(&ctx.cubehash, hash);
if (hash[0] & mask) {
sph_keccak512(&ctx.keccak2, hash, 64);
sph_keccak512_close(&ctx.keccak2, hash);
} else {
sph_jh512(&ctx.jh2, hash, 64);
sph_jh512_close(&ctx.jh2, hash);
}
sph_shavite512(&ctx.shavite1, hash, 64);
sph_shavite512_close(&ctx.shavite1, hash);
sph_simd512(&ctx.simd1, hash, 64);
sph_simd512_close(&ctx.simd1, hash);
if (hash[0] & mask) {
sph_whirlpool(&ctx.whirlpool2, hash, 64);
sph_whirlpool_close(&ctx.whirlpool2, hash);
} else {
sph_haval256_5(&ctx.haval1, hash, 64);
sph_haval256_5_close(&ctx.haval1, hash);
memset(&hash[8], 0, 32);
}
sph_echo512(&ctx.echo1, hash, 64);
sph_echo512_close(&ctx.echo1, hash);
sph_blake512(&ctx.blake2, hash, 64);
sph_blake512_close(&ctx.blake2, hash);
if (hash[0] & mask) {
sph_shavite512(&ctx.shavite2, hash, 64);
sph_shavite512_close(&ctx.shavite2, hash);
} else {
sph_luffa512 (&ctx.luffa2, hash, 64);
sph_luffa512_close(&ctx.luffa2, hash);
}
sph_hamsi512(&ctx.hamsi, hash, 64);
sph_hamsi512_close(&ctx.hamsi, hash);
sph_fugue512(&ctx.fugue1, hash, 64);
sph_fugue512_close(&ctx.fugue1, hash);
if (hash[0] & mask) {
sph_echo512(&ctx.echo2, hash, 64);
sph_echo512_close(&ctx.echo2, hash);
} else {
sph_simd512(&ctx.simd2, hash, 64);
sph_simd512_close(&ctx.simd2, hash);
}
sph_shabal512(&ctx.shabal, hash, 64);
sph_shabal512_close(&ctx.shabal, hash);
sph_whirlpool(&ctx.whirlpool3, hash, 64);
sph_whirlpool_close(&ctx.whirlpool3, hash);
if (hash[0] & mask) {
sph_fugue512(&ctx.fugue2, hash, 64);
sph_fugue512_close(&ctx.fugue2, hash);
} else {
sph_sha512(&ctx.sha1, hash, 64);
sph_sha512_close(&ctx.sha1, hash);
}
sph_groestl512(&ctx.groestl2, hash, 64);
sph_groestl512_close(&ctx.groestl2, hash);
sph_sha512(&ctx.sha2, hash, 64);
sph_sha512_close(&ctx.sha2, hash);
if (hash[0] & mask) {
sph_haval256_5(&ctx.haval2, hash, 64);
sph_haval256_5_close(&ctx.haval2, hash);
memset(&hash[8], 0, 32);
} else {
sph_whirlpool(&ctx.whirlpool4, hash, 64);
sph_whirlpool_close(&ctx.whirlpool4, hash);
}
sph_bmw512(&ctx.bmw3, hash, 64);
sph_bmw512_close(&ctx.bmw3, hash);
memcpy(output, hash, 32);
}

16
stratum/algos/hmq17.h Normal file
View file

@ -0,0 +1,16 @@
#ifndef HMQ17_H
#define HMQ17_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
void hmq17_hash(const char* input, char* output, uint32_t len);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -9,9 +9,9 @@ CFLAGS= $(CXXFLAGS) -std=gnu99
LDFLAGS=-O2 -lgmp
SOURCES=lyra2re.c lyra2v2.c Lyra2.c lyra2z.c Lyra2z.c Sponge.c \
blake.c scrypt.c c11.c x11.c x13.c sha256.c keccak.c \
blake.c scrypt.c c11.c x11.c x13.c sha256.c keccak.c deep.c \
x14.c x15.c x17.c nist5.c fresh.c quark.c neoscrypt.c scryptn.c qubit.c skein.c groestl.c \
xevan.c \
timetravel.c xevan.c hmq17.c \
skein2.c zr5.c bmw.c luffa.c pentablake.c whirlpool.c whirlpoolx.c blakecoin.c \
blake2.c \
yescrypt.c yescrypt-opt.c sha256_Y.c lbry.c \

178
stratum/algos/timetravel.c Normal file
View file

@ -0,0 +1,178 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sha3/sph_blake.h>
#include <sha3/sph_bmw.h>
#include <sha3/sph_groestl.h>
#include <sha3/sph_jh.h>
#include <sha3/sph_keccak.h>
#include <sha3/sph_skein.h>
#include <sha3/sph_luffa.h>
#include <sha3/sph_cubehash.h>
#include <sha3/sph_shavite.h>
#include <sha3/sph_simd.h>
#include <sha3/sph_echo.h>
#define HASH_FUNC_BASE_TIMESTAMP 1389040865 // Machinecoin: Genesis Timestamp
#define HASH_FUNC_COUNT 8 // Machinecoin: HASH_FUNC_COUNT of 11
#define HASH_FUNC_COUNT_PERMUTATIONS 40320 // Machinecoin: HASH_FUNC_COUNT!
#define _ALIGN(x) __attribute__ ((aligned(x)))
// helpers
inline void swap(int *a, int *b) {
int c = *a;
*a = *b;
*b = c;
}
static void reverse(int *pbegin, int *pend) {
while ( (pbegin != pend) && (pbegin != --pend) )
swap(pbegin++, pend);
}
static void next_permutation(int *pbegin, int *pend) {
if (pbegin == pend)
return;
int *i = pbegin;
++i;
if (i == pend)
return;
i = pend;
--i;
while (1) {
int *j = i;
--i;
if (*i < *j) {
int *k = pend;
while (!(*i < *--k))
/* pass */;
swap(i, k);
reverse(j, pend);
return; // true
}
if (i == pbegin) {
reverse(pbegin, pend);
return; // false
}
}
}
// helpers
void timetravel_hash(const char* input, char* output, uint32_t len)
{
uint32_t _ALIGN(64) hash[128]; // 16 bytes * HASH_FUNC_COUNT
uint32_t *hashA, *hashB;
uint32_t dataLen = 64;
uint32_t *work_data = (uint32_t *)input;
const uint32_t timestamp = work_data[17];
sph_blake512_context ctx_blake;
sph_bmw512_context ctx_bmw;
sph_groestl512_context ctx_groestl;
sph_skein512_context ctx_skein;
sph_jh512_context ctx_jh;
sph_keccak512_context ctx_keccak;
sph_luffa512_context ctx_luffa;
sph_cubehash512_context ctx_cubehash;
sph_shavite512_context ctx_shavite;
sph_simd512_context ctx_simd;
sph_echo512_context ctx_echo;
// We want to permute algorithms. To get started we
// initialize an array with a sorted sequence of unique
// integers where every integer represents its own algorithm.
uint32_t permutation[HASH_FUNC_COUNT];
for (uint32_t i = 0; i < HASH_FUNC_COUNT; i++) {
permutation[i]=i;
}
// Compute the next permuation
uint32_t steps = (timestamp - HASH_FUNC_BASE_TIMESTAMP) % HASH_FUNC_COUNT_PERMUTATIONS;
for (uint32_t i = 0; i < steps; i++) {
next_permutation(permutation, permutation + HASH_FUNC_COUNT);
}
for (uint32_t i = 0; i < HASH_FUNC_COUNT; i++) {
if (i == 0) {
dataLen = len;
hashA = work_data;
} else {
dataLen = 64;
hashA = &hash[16 * (i - 1)];
}
hashB = &hash[16 * i];
switch(permutation[i]) {
case 0:
sph_blake512_init(&ctx_blake);
sph_blake512(&ctx_blake, hashA, dataLen);
sph_blake512_close(&ctx_blake, hashB);
break;
case 1:
sph_bmw512_init(&ctx_bmw);
sph_bmw512 (&ctx_bmw, hashA, dataLen);
sph_bmw512_close(&ctx_bmw, hashB);
break;
case 2:
sph_groestl512_init(&ctx_groestl);
sph_groestl512 (&ctx_groestl, hashA, dataLen);
sph_groestl512_close(&ctx_groestl, hashB);
break;
case 3:
sph_skein512_init(&ctx_skein);
sph_skein512 (&ctx_skein, hashA, dataLen);
sph_skein512_close(&ctx_skein, hashB);
break;
case 4:
sph_jh512_init(&ctx_jh);
sph_jh512 (&ctx_jh, hashA, dataLen);
sph_jh512_close(&ctx_jh, hashB);
break;
case 5:
sph_keccak512_init(&ctx_keccak);
sph_keccak512 (&ctx_keccak, hashA, dataLen);
sph_keccak512_close(&ctx_keccak, hashB);
break;
case 6:
sph_luffa512_init(&ctx_luffa);
sph_luffa512 (&ctx_luffa, hashA, dataLen);
sph_luffa512_close(&ctx_luffa, hashB);
break;
case 7:
sph_cubehash512_init(&ctx_cubehash);
sph_cubehash512 (&ctx_cubehash, hashA, dataLen);
sph_cubehash512_close(&ctx_cubehash, hashB);
break;
case 8:
sph_shavite512_init(&ctx_shavite);
sph_shavite512(&ctx_shavite, hashA, dataLen);
sph_shavite512_close(&ctx_shavite, hashB);
break;
case 9:
sph_simd512_init(&ctx_simd);
sph_simd512 (&ctx_simd, hashA, dataLen);
sph_simd512_close(&ctx_simd, hashB);
break;
case 10:
sph_echo512_init(&ctx_echo);
sph_echo512 (&ctx_echo, hashA, dataLen);
sph_echo512_close(&ctx_echo, hashB);
break;
default:
break;
}
}
memcpy(output, &hash[16 * (HASH_FUNC_COUNT - 1)], 32);
}

View file

@ -0,0 +1,16 @@
#ifndef TIMETRAVEL_H
#define TIMETRAVEL_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
void timetravel_hash(const char* input, char* output, uint32_t len);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -392,10 +392,17 @@ bool client_submit(YAAMP_CLIENT *client, json_value *json_params)
return true;
}
if(strcmp(ntime, templ->ntime) && !ntime_valid_range(ntime))
if(strcmp(ntime, templ->ntime))
{
client_submit_error(client, job, 23, "Invalid time rolling", extranonce2, ntime, nonce);
return true;
if (!ntime_valid_range(ntime)) {
client_submit_error(client, job, 23, "Invalid time rolling", extranonce2, ntime, nonce);
return true;
}
// these algos permutations change over time (can lead to different speeds)
if (!strcmp(g_current_algo->name,"x11evo") || !strcmp(g_current_algo->name,"timetravel")) {
client_submit_error(client, job, 23, "Invalid ntime (rolling not allowed)", extranonce2, ntime, nonce);
return true;
}
}
YAAMP_SHARE *share = share_find(job->id, extranonce2, ntime, nonce, client->extranonce1);

View file

@ -0,0 +1,16 @@
[TCP]
server = yaamp.com
port = 3535
password = tu8tu5
[SQL]
host = yaampdb
database = yaamp
username = root
password = patofpaq
[STRATUM]
algo = deep
difficulty = 0.0128
max_ttf = 200000000000000

View file

@ -0,0 +1,16 @@
[TCP]
server = yaamp.com
port = 3747
password = tu8tu5
[SQL]
host = yaampdb
database = yaamp
username = root
password = patofpaq
[STRATUM]
algo = hmq1725
difficulty = 8
max_ttf = 50000

View file

@ -0,0 +1,16 @@
[TCP]
server = yaamp.com
port = 3555
password = tu8tu5
[SQL]
host = yaampdb
database = yaamp
username = root
password = patofpaq
[STRATUM]
algo = timetravel
difficulty = 0.125
max_ttf = 50000

View file

@ -103,6 +103,8 @@ YAAMP_ALGO g_algos[] =
{"x11evo", x11evo_hash, 1, 0, 0},
{"xevan", xevan_hash, 0x100, 0, 0},
{"timetravel", timetravel_hash, 0x100, 0, 0}, // Waaaaahhh
{"hmq1725", hmq17_hash, 0x10000, 0, 0},
{"lyra2", lyra2re_hash, 0x80, 0, 0},
{"lyra2v2", lyra2v2_hash, 0x100, 0, 0},
@ -114,6 +116,7 @@ YAAMP_ALGO g_algos[] =
{"vanilla", blakecoin_hash, 1, 0 },
{"decred", decred_hash, 1, 0 },
{"deep", deep_hash, 1, 0, 0},
{"fresh", fresh_hash, 0x100, 0, 0},
{"quark", quark_hash, 1, 0, 0},
{"nist5", nist5_hash, 1, 0, 0},

View file

@ -136,6 +136,7 @@ void sha256_double_hash_hex(const char *input, char *output, unsigned int len);
#include "algos/x15.h"
#include "algos/x17.h"
#include "algos/xevan.h"
#include "algos/hmq17.h"
#include "algos/nist5.h"
#include "algos/fresh.h"
#include "algos/quark.h"
@ -150,8 +151,10 @@ void sha256_double_hash_hex(const char *input, char *output, unsigned int len);
#include "algos/groestl.h"
#include "algos/skein.h"
#include "algos/keccak.h"
#include "algos/timetravel.h"
#include "algos/bmw.h"
#include "algos/deep.h"
#include "algos/lbry.h"
#include "algos/luffa.h"
#include "algos/pentablake.h"

View file

@ -12,6 +12,8 @@ function yaamp_get_algos()
'blakecoin',
'blake2s',
'decred',
'deep',
'hmq1725',
'keccak',
'lbry',
'luffa',
@ -38,6 +40,7 @@ function yaamp_get_algos()
'sib',
'skein',
'skein2',
'timetravel',
'vanilla',
'veltor',
'velvet',
@ -110,6 +113,7 @@ function getAlgoColors($algo)
'scryptn' => '#d0d0d0',
'c11' => '#a0a0d0',
'decred' => '#f0f0f0',
'deep' => '#e0ffff',
'x11' => '#f0f0a0',
'x11evo' => '#c0f0c0',
'x13' => '#ffd880',
@ -123,6 +127,7 @@ function getAlgoColors($algo)
'groestl' => '#d0a0a0',
'dmd-gr' => '#a0c0f0',
'myr-gr' => '#a0c0f0',
'hmq1725' => '#ffa0a0',
'keccak' => '#c0f0c0',
'lbry' => '#b0d0e0',
'luffa' => '#a0c0c0',
@ -137,6 +142,7 @@ function getAlgoColors($algo)
'sib' => '#a0a0c0',
'skein' => '#80a0a0',
'skein2' => '#c8a060',
'timetravel' => '#f0b0d0',
'vanilla' => '#f0f0f0',
'velvet' => '#aac0cc',
'whirlpool' => '#d0e0e0',
@ -159,13 +165,16 @@ function getAlgoPort($algo)
'sha256' => 3333,
'lbry' => 3334,
'scrypt' => 3433,
'timetravel' => 3555,
'c11' => 3573,
'deep' => 3535,
'x11' => 3533,
'x11evo' => 3553,
'x13' => 3633,
'x15' => 3733,
'x17' => 3737,
'xevan' => 3739,
'hmq1725' => 3747,
'nist5' => 3833,
'x14' => 3933,
'quark' => 4033,

View file

@ -59,6 +59,8 @@ foreach($versions as $item)
$hashrate = dboscalar("select sum(difficulty) * $target / $interval / 1000 from shares where valid and time>$delay and
workerid IN (select id from workers where algo=:algo and version=:version)", array(':algo'=>$algo, ':version'=>$version));
if (!$hashrate && !$this->admin) continue;
$invalid = dboscalar("select sum(difficulty) * $target / $interval / 1000 from shares where not valid and time>$delay and
workerid IN (select id from workers where algo=:algo and version=:version)", array(':algo'=>$algo, ':version'=>$version));