stratum: new algos, attempt to allow old sha merkleroot

blake (SFR) and whirlpool (J) tested ok with a sha256d merkleroot

So add a stratum setting to allow single sha256 merkle root...
The shares are now valid on the pool side, but remains to find
an old wallet to test... like Whirlcoin or blakecoin

keccak not tested, could have the same problem about merkle/miners
This commit is contained in:
Tanguy Pruvot 2015-10-07 04:35:42 +02:00
parent 8c97bba761
commit 6d6fd9337f
20 changed files with 183 additions and 44 deletions

View file

@ -37,6 +37,10 @@ screen -dmS myr-gr $STRATUM_DIR/run.sh myr-gr
screen -dmS lyra2 $STRATUM_DIR/run.sh lyra2
screen -dmS lyra2v2 $STRATUM_DIR/run.sh lyra2v2
screen -dmS blake $STRATUM_DIR/run.sh blake
#screen -dmS keccak $STRATUM_DIR/run.sh keccak
#screen -dmS whirlpool $STRATUM_DIR/run.sh whirlpool
screen -dmS skein $STRATUM_DIR/run.sh skein
screen -dmS skein2 $STRATUM_DIR/run.sh skein2
screen -dmS zr5 $STRATUM_DIR/run.sh zr5

View file

@ -9,8 +9,11 @@
void blake_hash(const char* input, char* output, uint32_t len)
{
sph_blake256_context ctx_blake;
sph_blake256_init(&ctx_blake);
sph_blake256(&ctx_blake, input, len);
sph_blake256_close(&ctx_blake, output);
sph_blake256_context ctx_blake;
sph_blake256_set_rounds(14);
sph_blake256_init(&ctx_blake);
sph_blake256(&ctx_blake, input, len);
sph_blake256_close(&ctx_blake, output);
}

18
stratum/algos/blakecoin.c Normal file
View file

@ -0,0 +1,18 @@
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include "../sha3/sph_blake.h"
void blakecoin_hash(const char* input, char* output, uint32_t len)
{
sph_blake256_context ctx_blake;
sph_blake256_set_rounds(8);
sph_blake256_init(&ctx_blake);
sph_blake256(&ctx_blake, input, len);
sph_blake256_close(&ctx_blake, output);
}

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

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

View file

@ -7,26 +7,28 @@
#include "../sha3/sph_types.h"
#include "../sha3/sph_keccak.h"
void keccak_hash(const char *input, char *output, uint32_t len)
void keccak256_hash(const char *input, char *output, uint32_t len)
{
sph_keccak256_context ctx_keccak;
sph_keccak256_init(&ctx_keccak);
uint32_t hash[16];
sph_keccak256(&ctx_keccak, input, len);
sph_keccak256_close(&ctx_keccak, output);
sph_keccak256_context ctx_keccak;
sph_keccak256_init(&ctx_keccak);
sph_keccak256(&ctx_keccak, input, len /* 80 */);
sph_keccak256_close(&ctx_keccak, hash);
memcpy(output, hash, 32);
}
//void keccak_hash2(const char *input, char *output, uint32_t len)
//void keccak512_hash(const char *input, char *output, uint32_t len)
//{
// uint32_t hashA[16];
// uint32_t hash[16];
//
// sph_keccak512_context ctx_keccak;
//
// sph_keccak512_init(&ctx_keccak);
//
// sph_keccak512(&ctx_keccak, input, len);
// sph_keccak512_close(&ctx_keccak, hashA);
// sph_keccak512_close(&ctx_keccak, hash);
//
// memcpy(output, hashA, 32);
// memcpy(output, hash, 32);
//}

View file

@ -7,7 +7,7 @@ extern "C" {
#include <stdint.h>
void keccak_hash(const char* input, char* output, uint32_t size);
void keccak256_hash(const char* input, char* output, uint32_t len);
#ifdef __cplusplus
}

View file

@ -9,7 +9,7 @@ LDFLAGS=-O2 -lgmp
SOURCES=lyra2re.c lyra2v2.c Lyra2.c Sponge.c blake.c scrypt.c c11.c x11.c x13.c sha256.c keccak.c \
x14.c x15.c nist5.c fresh.c quark.c neoscrypt.c scryptn.c qubit.c skein.c groestl.c \
skein2.c zr5.c bmw.c luffa.c pentablake.c whirlpoolx.c \
skein2.c zr5.c bmw.c luffa.c pentablake.c whirlpool.c whirlpoolx.c blakecoin.c \
m7m.c magimath.cpp \
hive.c pomelo.c \
sib.c gost.c

34
stratum/algos/whirlpool.c Normal file
View file

@ -0,0 +1,34 @@
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include "../sha3/sph_whirlpool.h"
/* untested ! */
void whirlpool_hash(const char* input, char* output, uint32_t len)
{
unsigned char hash[64] = { 0 };
int i;
sph_whirlpool1_context ctx_whirlpool;
sph_whirlpool1_init(&ctx_whirlpool);
sph_whirlpool1 (&ctx_whirlpool, input, len);
sph_whirlpool1_close(&ctx_whirlpool, (void*) hash);
sph_whirlpool1_init(&ctx_whirlpool);
sph_whirlpool1 (&ctx_whirlpool, (const void*) hash, 64);
sph_whirlpool1_close(&ctx_whirlpool, (void*) hash);
sph_whirlpool1_init(&ctx_whirlpool);
sph_whirlpool1 (&ctx_whirlpool, (const void*) hash, 64);
sph_whirlpool1_close(&ctx_whirlpool, (void*) hash);
sph_whirlpool1_init(&ctx_whirlpool);
sph_whirlpool1 (&ctx_whirlpool, (const void*) hash, 64);
sph_whirlpool1_close(&ctx_whirlpool, (void*) hash);
memcpy(output, hash, 32);
}

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

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

View file

@ -15,6 +15,7 @@ struct YAAMP_ALGO
double diff_multiplier;
double factor;
YAAMP_HASH_FUNCTION merkle_func;
double profit;
double rent;

View file

@ -1,6 +1,7 @@
#include "stratum.h"
//#define MERKLE_DEBUGLOG
#define HASH_DEBUGLOG_
//#define DONTSUBMIT
@ -16,11 +17,19 @@ void build_submit_values(YAAMP_JOB_VALUES *submitvalues, YAAMP_JOB_TEMPLATE *tem
char doublehash[128];
memset(doublehash, 0, 128);
sha256_double_hash_hex((char *)coinbase_bin, doublehash, coinbase_len/2);
// some (old) wallet/algos need a simple SHA256 (blakecoin, whirlcoin, groestlcoin...)
YAAMP_HASH_FUNCTION merkle_hash = sha256_double_hash_hex;
if (g_current_algo->merkle_func)
merkle_hash = g_current_algo->merkle_func;
merkle_hash((char *)coinbase_bin, doublehash, coinbase_len/2);
string merkleroot = merkle_with_first(templ->txsteps, doublehash);
ser_string_be(merkleroot.c_str(), submitvalues->merkleroot_be, 8);
#ifdef MERKLE_DEBUGLOG
printf("merkle root %s\n", merkleroot.c_str());
#endif
sprintf(submitvalues->header, "%s%s%s%s%s%s", templ->version, templ->prevhash_be, submitvalues->merkleroot_be,
ntime, templ->nbits, nonce);
@ -136,14 +145,19 @@ void client_do_submit(YAAMP_CLIENT *client, YAAMP_JOB *job, YAAMP_JOB_VALUES *su
char doublehash2[128];
memset(doublehash2, 0, 128);
sha256_double_hash_hex((char *)submitvalues->header_bin, doublehash2, strlen(submitvalues->header_be)/2);
YAAMP_HASH_FUNCTION merkle_hash = sha256_double_hash_hex;
//if (g_current_algo->merkle_func)
// merkle_hash = g_current_algo->merkle_func;
merkle_hash((char *)submitvalues->header_bin, doublehash2, strlen(submitvalues->header_be)/2);
char hash1[1024];
memset(hash1, 0, 1024);
string_be(doublehash2, hash1);
block_add(client->userid, coind->id, templ->height, target_to_diff(coin_target), target_to_diff(hash_int),
block_add(client->userid, coind->id, templ->height,
target_to_diff(coin_target), target_to_diff(hash_int),
hash1, submitvalues->hash_be);
#ifdef HASH_DEBUGLOG_

View file

@ -11,6 +11,6 @@ password = patofpaq
[STRATUM]
algo = keccak
difficulty = 0.1
max_ttf = 200000000000000
difficulty = 1
max_ttf = 4000000

View file

@ -56,6 +56,8 @@ extern "C"{
#pragma warning (disable: 4146)
#endif
static int blake32_rounds = 14; /* 8 in blakecoin */
static const sph_u32 IV224[8] = {
SPH_C32(0xC1059ED8), SPH_C32(0x367CD507),
SPH_C32(0x3070DD17), SPH_C32(0xF70E5939),
@ -509,11 +511,6 @@ static const sph_u64 CB[16] = {
(state)->T1 = T1; \
} while (0)
//#define BLAKE32_ROUNDS 8
#ifndef BLAKE32_ROUNDS
#define BLAKE32_ROUNDS 14
#endif
#if SPH_COMPACT_BLAKE_32
#define COMPRESS32 do { \
@ -553,7 +550,7 @@ static const sph_u64 CB[16] = {
M[0xD] = sph_dec32be_aligned(buf + 52); \
M[0xE] = sph_dec32be_aligned(buf + 56); \
M[0xF] = sph_dec32be_aligned(buf + 60); \
for (r = 0; r < BLAKE32_ROUNDS; r ++) \
for (r = 0; r < blake32_rounds; r ++) \
ROUND_S(r); \
H0 ^= S0 ^ V0 ^ V8; \
H1 ^= S1 ^ V1 ^ V9; \
@ -612,7 +609,7 @@ static const sph_u64 CB[16] = {
ROUND_S(5); \
ROUND_S(6); \
ROUND_S(7); \
if (BLAKE32_ROUNDS == 14) { \
if (blake32_rounds == 14) { \
ROUND_S(8); \
ROUND_S(9); \
ROUND_S(0); \
@ -1060,6 +1057,12 @@ sph_blake256_addbits_and_close(void *cc, unsigned ub, unsigned n, void *dst)
sph_blake256_init(cc);
}
/* see sph_blake.h */
void sph_blake256_set_rounds(int rounds)
{
blake32_rounds = rounds;
}
#if SPH_64
/* see sph_blake.h */

View file

@ -226,6 +226,11 @@ void sph_blake256_close(void *cc, void *dst);
void sph_blake256_addbits_and_close(
void *cc, unsigned ub, unsigned n, void *dst);
/**
* Added for compat with both blake/blakecoin algos
*/
void sph_blake256_set_rounds(int rounds);
#if SPH_64
/**

View file

@ -96,16 +96,17 @@ YAAMP_ALGO g_algos[] =
{"lyra2", lyra2re_hash, 0x80, 0, 0},
{"lyra2v2", lyra2v2_hash, 0x100, 0, 0},
{"blake", blake_hash, 1, 0, 0},
{"blake", blake_hash, 1, 0 },
{"blakecoin", blakecoin_hash, 0x100, 0, sha256_hash_hex },
{"fresh", fresh_hash, 0x100, 0, 0},
{"quark", quark_hash, 1, 0, 0},
{"nist5", nist5_hash, 1, 0, 0},
{"qubit", qubit_hash, 1, 0, 0},
{"groestl", groestl_hash, 1, 0, 0}, /* diamond (double groestl) */
{"groestl", groestl_hash, 0x100, 0, sha256_hash_hex }, /* groestlcoin */
{"dmd-gr", groestl_hash, 0x100, 0, 0}, /* diamond (double groestl) */
{"myr-gr", groestlmyriad_hash, 0x100, 0, 0}, /* groestl + sha 64 */
{"myr-gr", groestlmyriad_hash, 1, 0, 0}, /* groestl + sha 64 */
{"skein", skein_hash, 1, 0, 0},
{"keccak", keccak_hash, 1, 0, 0},
{"keccak", keccak256_hash, 0x80, 0, sha256_hash_hex },
{"bmw", bmw_hash, 1, 0, 0},
{"luffa", luffa_hash, 1, 0, 0},
@ -114,11 +115,12 @@ YAAMP_ALGO g_algos[] =
{"zr5", zr5_hash, 1, 0, 0},
{"hive", hive_hash, 0x10000, 0, 0},
{"m7m", m7m_hash, 0x10000, 0, 0},
{"sib", sib_hash, 1, 0, 0},
{"whirlcoin", whirlpool_hash, 1, 0, sha256_hash_hex }, /* old sha merkleroot */
{"whirlpool", whirlpool_hash, 1, 0 }, /* sha256d merkleroot */
{"whirlpoolx", whirlpoolx_hash, 1, 0, 0},
// {"jha", jha_hash, 1, 0, 0},
{"m7m", m7m_hash, 0x10000, 0, 0},
{"", NULL, 0, 0},
};

View file

@ -121,6 +121,7 @@ void scrypt_1024_1_1_256(const unsigned char *input, unsigned char *output);
void scrypt_N_R_1_256(const char* input, char* output, uint32_t N, uint32_t R, uint32_t len);
}
void sha256_hash_hex(const char *input, char *output, unsigned int len);
void sha256_double_hash_hex(const char *input, char *output, unsigned int len);
#include "algos/c11.h"
@ -135,6 +136,7 @@ void sha256_double_hash_hex(const char *input, char *output, unsigned int len);
#include "algos/lyra2re.h"
#include "algos/lyra2v2.h"
#include "algos/blake.h"
#include "algos/blakecoin.h"
#include "algos/qubit.h"
#include "algos/groestl.h"
#include "algos/skein.h"
@ -143,6 +145,7 @@ void sha256_double_hash_hex(const char *input, char *output, unsigned int len);
#include "algos/bmw.h"
#include "algos/luffa.h"
#include "algos/pentablake.h"
#include "algos/whirlpool.h"
#include "algos/whirlpoolx.h"
#include "algos/skein2.h"
#include "algos/zr5.h"

View file

@ -659,8 +659,11 @@ void sha256_double_hash_hex(const char *input, char *output, unsigned int len)
hexlify(output, (unsigned char *)output1, 32);
}
void sha256_hash_hex(const char *input, char *output, unsigned int len)
{
char output1[32];
sha256_hash(input, output1, len);
hexlify(output, (unsigned char *)output1, 32);
}

View file

@ -68,6 +68,8 @@ void clientlog(YAAMP_CLIENT *client, const char *format, ...);
vector<string> merkle_steps(vector<string> input);
string merkle_with_first(vector<string> steps, string f);
//////////////////////////////////////////////////////////////////////////
bool base58_decode(const char *input, char *output);
void base64_encode(char *base64, const char *normal);

View file

@ -7,6 +7,8 @@ function yaamp_get_algos()
'sha256',
'scrypt',
'scryptn',
'blake',
'keccak',
'luffa',
'lyra2',
'lyra2v2',
@ -76,9 +78,11 @@ function getAlgoColors($algo)
'x13' => '#d0f0c0',
'x14' => '#a0f0c0',
'x15' => '#f0b0a0',
'blake' => '#f0f0f0',
'groestl' => '#d0a0a0',
'dmd-gr' => '#a0c0f0',
'myr-gr' => '#a0c0f0',
'keccak' => '#c0f0c0',
'luffa' => '#a0c0c0',
'm7m' => '#d0a0a0',
'penta' => '#80c0c0',
@ -128,7 +132,8 @@ function getAlgoPort($algo)
'skein2' => 5233,
//'groestl' => 5333,
'dmd-gr' => 5333,
'myr-gr' => 5433,
//'myr-gr' => 5433,
'whirlpool' => 5433,
'zr5' => 5533,
// 5555 to 5683 reserved
'blake' => 5733,

View file

@ -147,6 +147,7 @@ function remove0x($string)
// version is used for multi algo coins
function versionToAlgo($coin, $version)
{
// could be filled by block json (chain analysis)
$algos['MYR'] = array(
0=>'sha256', 1=>'scrypt', 2=>'groestl', 3=>'skein', 4=>'qubit'
);
@ -158,9 +159,16 @@ function versionToAlgo($coin, $version)
7 =>'nist5', 8 =>'groestl', 9=>'penta', 10=>'whirl',
11=>'luffa', 12=>'keccak', 13=>'quark', 15=>'bastion'
);
if ($coin->symbol == 'DGB' || $coin->symbol == 'MYR')
return arraySafeVal($algos[$coin->symbol], ($version >> 9) & 7, '');
else if (isset($algos[$coin->symbol]))
return arraySafeVal($algos[$coin->symbol], $version, '');
$algos['SFR'] = array(
0=>'sha256', 1=>'scrypt', 2=>'groestl', 3=>'x11', 4=>'blake'
);
$symbol = $coin->symbol;
if (!empty($coin->symbol2)) $symbol = $coin->symbol2;
if ($symbol == 'J')
return arraySafeVal($algos[$symbol], $version, '');
else if (isset($algos[$symbol]))
return arraySafeVal($algos[$symbol], ($version >> 9) & 7, '');
return false;
}