Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add algo minotaur and minotaurx #56

Open
wants to merge 2 commits into
base: linux
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ cpuminer_SOURCES = \
lyra2/Lyra2.c lyra2/Sponge.c \
yescrypt/yescrypt-common.c yescrypt/yescrypt-best.c \
yescrypt/sha256_Y.c \
yespower-1.0.1/sha256.c \
yespower-1.0.1/yespower-opt.c \
algo/allium.c \
algo/axiom.c \
algo/bastion.c \
Expand All @@ -80,6 +82,7 @@ cpuminer_SOURCES = \
algo/lyra2re.c \
algo/lyra2rev2.c \
algo/lyra2v3.c \
algo/minotaur.c \
algo/myr-groestl.c \
algo/keccak.c \
algo/pentablake.c \
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ Algorithms
* ✓ __lyra2RE__ (Cryptocoin)
* ✓ __lyra2REv2__
* ✓ __lyra2REv3__ (VertCoin [VTC])
* ✓ __minotaur__ (Ring [RNG])
* ✓ __minotaurx__ (Avian[AVN], Litecash[LCC], Mazacoin[MAZA])
* ✓ __myr-gr__ Myriad-Groestl (MyriadCoin [MYR])
* ✓ __neoscrypt__ (Feathercoin)
* ✓ __nist5__ (MistCoin [MIC], TalkCoin [TAC], ...)
Expand Down
290 changes: 290 additions & 0 deletions algo/minotaur.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,290 @@
#include <miner.h>

#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <stdio.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 <yespower-1.0.1/yespower.h>

// Config
#define MINOTAUR_ALGO_COUNT 16
//#define MINOTAUR_DEBUG

static const yespower_params_t yespower_params = {YESPOWER_1_0, 2048, 8, "et in arcadia ego", 17};

typedef struct TortureNode TortureNode;
typedef struct TortureGarden TortureGarden;

// Graph of hash algos plus SPH contexts
struct TortureGarden {
sph_blake512_context context_blake;
sph_bmw512_context context_bmw;
sph_cubehash512_context context_cubehash;
sph_echo512_context context_echo;
sph_fugue512_context context_fugue;
sph_groestl512_context context_groestl;
sph_hamsi512_context context_hamsi;
sph_jh512_context context_jh;
sph_keccak512_context context_keccak;
sph_luffa512_context context_luffa;
sph_shabal512_context context_shabal;
sph_shavite512_context context_shavite;
sph_simd512_context context_simd;
sph_skein512_context context_skein;
sph_whirlpool_context context_whirlpool;
sph_sha512_context context_sha2;

struct TortureNode {
unsigned int algo;
TortureNode *childLeft;
TortureNode *childRight;
} nodes[22];
};

// Get a 64-byte hash for given 64-byte input, using given TortureGarden contexts and given algo index
void get_hash(void *output, const void *input, TortureGarden *garden, unsigned int algo)
{
unsigned char _ALIGN(64) hash[64];
memset(hash, 0, sizeof(hash)); // Doesn't affect Minotaur as all hash outputs are 64 bytes; required for MinotaurX due to yespower's 32 byte output.

switch (algo) {
case 0:
sph_blake512_init(&garden->context_blake);
sph_blake512(&garden->context_blake, input, 64);
sph_blake512_close(&garden->context_blake, hash);
break;
case 1:
sph_bmw512_init(&garden->context_bmw);
sph_bmw512(&garden->context_bmw, input, 64);
sph_bmw512_close(&garden->context_bmw, hash);
break;
case 2:
sph_cubehash512_init(&garden->context_cubehash);
sph_cubehash512(&garden->context_cubehash, input, 64);
sph_cubehash512_close(&garden->context_cubehash, hash);
break;
case 3:
sph_echo512_init(&garden->context_echo);
sph_echo512(&garden->context_echo, input, 64);
sph_echo512_close(&garden->context_echo, hash);
break;
case 4:
sph_fugue512_init(&garden->context_fugue);
sph_fugue512(&garden->context_fugue, input, 64);
sph_fugue512_close(&garden->context_fugue, hash);
break;
case 5:
sph_groestl512_init(&garden->context_groestl);
sph_groestl512(&garden->context_groestl, input, 64);
sph_groestl512_close(&garden->context_groestl, hash);
break;
case 6:
sph_hamsi512_init(&garden->context_hamsi);
sph_hamsi512(&garden->context_hamsi, input, 64);
sph_hamsi512_close(&garden->context_hamsi, hash);
break;
case 7:
sph_sha512_init(&garden->context_sha2);
sph_sha512(&garden->context_sha2, input, 64);
sph_sha512_close(&garden->context_sha2, hash);
break;
case 8:
sph_jh512_init(&garden->context_jh);
sph_jh512(&garden->context_jh, input, 64);
sph_jh512_close(&garden->context_jh, hash);
break;
case 9:
sph_keccak512_init(&garden->context_keccak);
sph_keccak512(&garden->context_keccak, input, 64);
sph_keccak512_close(&garden->context_keccak, hash);
break;
case 10:
sph_luffa512_init(&garden->context_luffa);
sph_luffa512(&garden->context_luffa, input, 64);
sph_luffa512_close(&garden->context_luffa, hash);
break;
case 11:
sph_shabal512_init(&garden->context_shabal);
sph_shabal512(&garden->context_shabal, input, 64);
sph_shabal512_close(&garden->context_shabal, hash);
break;
case 12:
sph_shavite512_init(&garden->context_shavite);
sph_shavite512(&garden->context_shavite, input, 64);
sph_shavite512_close(&garden->context_shavite, hash);
break;
case 13:
sph_simd512_init(&garden->context_simd);
sph_simd512(&garden->context_simd, input, 64);
sph_simd512_close(&garden->context_simd, hash);
break;
case 14:
sph_skein512_init(&garden->context_skein);
sph_skein512(&garden->context_skein, input, 64);
sph_skein512_close(&garden->context_skein, hash);
break;
case 15:
sph_whirlpool_init(&garden->context_whirlpool);
sph_whirlpool(&garden->context_whirlpool, input, 64);
sph_whirlpool_close(&garden->context_whirlpool, hash);
break;
// NB: The CPU-hard gate must be case MINOTAUR_ALGO_COUNT.
case 16:
yespower_tls(input, 64, &yespower_params, (yespower_binary_t*)hash);
}

// Output the hash
memcpy(output, hash, 64);
}

// Recursively traverse a given torture garden starting with a given hash and given node within the garden. The hash is overwritten with the final hash.
void traverse_garden(TortureGarden *garden, void *hash, TortureNode *node)
{
unsigned char _ALIGN(64) partialHash[64];
memset(partialHash, 0, sizeof(partialHash)); // Doesn't affect Minotaur as all hash outputs are 64 bytes; required for MinotaurX due to yespower's 32 byte output.
get_hash(partialHash, hash, garden, node->algo);

#ifdef MINOTAUR_DEBUG
printf("* Ran algo %d. Partial hash:\t", node->algo);
for (int i = 63; i >= 0; i--) printf("%02x", partialHash[i]);
printf("\n");
fflush(0);
#endif

if (partialHash[63] % 2 == 0) { // Last byte of output hash is even
if (node->childLeft != NULL)
traverse_garden(garden, partialHash, node->childLeft);
} else { // Last byte of output hash is odd
if (node->childRight != NULL)
traverse_garden(garden, partialHash, node->childRight);
}

memcpy(hash, partialHash, 64);
}

// Associate child nodes with a parent node
inline void link_nodes(TortureNode *parent, TortureNode *childLeft, TortureNode *childRight)
{
parent->childLeft = childLeft;
parent->childRight = childRight;
}

// Produce a 32-byte hash from 80-byte input data
void minotaurhash(void *output, const void *input, bool minotaurX)
{
// Create torture garden nodes. Note that both sides of 19 and 20 lead to 21, and 21 has no children (to make traversal complete).
// The successful path through the garden visits 7 nodes.
TortureGarden garden;
link_nodes(&garden.nodes[0], &garden.nodes[1], &garden.nodes[2]);
link_nodes(&garden.nodes[1], &garden.nodes[3], &garden.nodes[4]);
link_nodes(&garden.nodes[2], &garden.nodes[5], &garden.nodes[6]);
link_nodes(&garden.nodes[3], &garden.nodes[7], &garden.nodes[8]);
link_nodes(&garden.nodes[4], &garden.nodes[9], &garden.nodes[10]);
link_nodes(&garden.nodes[5], &garden.nodes[11], &garden.nodes[12]);
link_nodes(&garden.nodes[6], &garden.nodes[13], &garden.nodes[14]);
link_nodes(&garden.nodes[7], &garden.nodes[15], &garden.nodes[16]);
link_nodes(&garden.nodes[8], &garden.nodes[15], &garden.nodes[16]);
link_nodes(&garden.nodes[9], &garden.nodes[15], &garden.nodes[16]);
link_nodes(&garden.nodes[10], &garden.nodes[15], &garden.nodes[16]);
link_nodes(&garden.nodes[11], &garden.nodes[17], &garden.nodes[18]);
link_nodes(&garden.nodes[12], &garden.nodes[17], &garden.nodes[18]);
link_nodes(&garden.nodes[13], &garden.nodes[17], &garden.nodes[18]);
link_nodes(&garden.nodes[14], &garden.nodes[17], &garden.nodes[18]);
link_nodes(&garden.nodes[15], &garden.nodes[19], &garden.nodes[20]);
link_nodes(&garden.nodes[16], &garden.nodes[19], &garden.nodes[20]);
link_nodes(&garden.nodes[17], &garden.nodes[19], &garden.nodes[20]);
link_nodes(&garden.nodes[18], &garden.nodes[19], &garden.nodes[20]);
link_nodes(&garden.nodes[19], &garden.nodes[21], &garden.nodes[21]);
link_nodes(&garden.nodes[20], &garden.nodes[21], &garden.nodes[21]);
garden.nodes[21].childLeft = NULL;
garden.nodes[21].childRight = NULL;

// Find initial sha512 hash
unsigned char _ALIGN(64) hash[64];
sph_sha512_init(&garden.context_sha2);
sph_sha512(&garden.context_sha2, input, 80);
sph_sha512_close(&garden.context_sha2, hash);

#ifdef MINOTAUR_DEBUG
printf("** Initial hash:\t\t");
for (int i = 63; i >= 0; i--) printf("%02x", hash[i]);
printf("\n");
fflush(0);
#endif

// Assign algos to torture garden nodes based on initial hash
for (int i = 0; i < 22; i++)
garden.nodes[i].algo = hash[i] % MINOTAUR_ALGO_COUNT;

// Hardened garden gates on MinotaurX
if (minotaurX)
garden.nodes[21].algo = MINOTAUR_ALGO_COUNT;

// Send the initial hash through the torture garden
traverse_garden(&garden, hash, &garden.nodes[0]);

// Truncate the result to 32 bytes
memcpy(output, hash, 32);

#ifdef MINOTAUR_DEBUG
printf("** Final hash:\t\t\t");
for (int i = 31; i >= 0; i--) printf("%02x", hash[i]);
printf("\n");
fflush(0);
#endif
}

// Scan driver
int scanhash_minotaur(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done, bool minotaurX)
{
uint32_t _ALIGN(64) hash[8];
uint32_t _ALIGN(64) endiandata[20];
uint32_t *pdata = work->data;
uint32_t *ptarget = work->target;

const uint32_t Htarg = ptarget[7];
const uint32_t first_nonce = pdata[19];
uint32_t nonce = first_nonce;
volatile uint8_t *restart = &(work_restart[thr_id].restart);

if (opt_benchmark)
ptarget[7] = 0x0cff;

for (int k=0; k < 19; k++)
be32enc(&endiandata[k], pdata[k]);

do {
be32enc(&endiandata[19], nonce);
minotaurhash(hash, endiandata, minotaurX);

if (hash[7] <= Htarg && fulltest(hash, ptarget)) {
work_set_target_ratio(work, hash);
pdata[19] = nonce;
*hashes_done = pdata[19] - first_nonce;
return 1;
}
nonce++;

} while (nonce < max_nonce && !(*restart));

pdata[19] = nonce;
*hashes_done = pdata[19] - first_nonce + 1;
return 0;
}
14 changes: 14 additions & 0 deletions cpu-miner.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ enum algos {
ALGO_LYRA2, /* Lyra2RE */
ALGO_LYRA2REV2, /* Lyra2REv2 */
ALGO_LYRA2V3, /* Lyra2REv3 (Vertcoin) */
ALGO_MINOTAUR, /* Minotaur (Ring) */
ALGO_MINOTAURX, /* Minotaurx (Avian, Litecash, Maza) */
ALGO_MYR_GR, /* Myriad Groestl */
ALGO_NIST5, /* Nist5 */
ALGO_PENTABLAKE, /* Pentablake */
Expand Down Expand Up @@ -177,6 +179,8 @@ static const char *algo_names[] = {
"lyra2re",
"lyra2rev2",
"lyra2v3",
"minotaur",
"minotaurx",
"myr-gr",
"nist5",
"pentablake",
Expand Down Expand Up @@ -347,6 +351,8 @@ Options:\n\
lyra2rev2 Lyra2REv2\n\
lyra2v3 Lyra2REv3 (Vertcoin)\n\
myr-gr Myriad-Groestl\n\
minotaur Ring\n\
minotaurx Avian, Litecash, Maza\n\
neoscrypt NeoScrypt(128, 2, 1)\n\
nist5 Nist5\n\
pluck Pluck:128 (Supcoin)\n\
Expand Down Expand Up @@ -2200,6 +2206,8 @@ static void *miner_thread(void *userdata)
max64 = 0x40LL;
break;
case ALGO_DROP:
case ALGO_MINOTAUR:
case ALGO_MINOTAURX:
case ALGO_PLUCK:
case ALGO_YESCRYPT:
case ALGO_YESCRYPTR8:
Expand Down Expand Up @@ -2355,6 +2363,12 @@ static void *miner_thread(void *userdata)
case ALGO_LYRA2V3:
rc = scanhash_lyra2v3(thr_id, &work, max_nonce, &hashes_done);
break;
case ALGO_MINOTAUR:
rc = scanhash_minotaur(thr_id, &work, max_nonce, &hashes_done, false);
break;
case ALGO_MINOTAURX:
rc = scanhash_minotaur(thr_id, &work, max_nonce, &hashes_done, true);
break;
case ALGO_MYR_GR:
rc = scanhash_myriad(thr_id, &work, max_nonce, &hashes_done);
break;
Expand Down
2 changes: 2 additions & 0 deletions miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ int scanhash_luffa(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *
int scanhash_lyra2(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done);
int scanhash_lyra2rev2(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done);
int scanhash_lyra2v3(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done);
int scanhash_minotaur(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done, bool minotaurX);
int scanhash_myriad(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done);
int scanhash_neoscrypt(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done, uint32_t profile);
int scanhash_nist5(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done);
Expand Down Expand Up @@ -531,6 +532,7 @@ void luffahash(void *output, const void *input);
void lyra2_hash(void *state, const void *input);
void lyra2rev2_hash(void *state, const void *input);
void lyra2v3_hash(void *state, const void *input);
void minotaurhash(void *output, const void *input, bool minotaurX);
void myriadhash(void *output, const void *input);
void neoscrypt(unsigned char *output, const unsigned char *password, uint32_t profile);
void nist5hash(void *output, const void *input);
Expand Down
6 changes: 6 additions & 0 deletions util.c
Original file line number Diff line number Diff line change
Expand Up @@ -2401,6 +2401,12 @@ void print_hash_tests(void)
cryptonight_hash(&hash[0], &buf[0]);
printpfx("monero", hash);

minotaurhash(&hash[0], &buf[0], false);
printpfx("minotaur", hash);

minotaurhash(&hash[0], &buf[0], true);
printpfx("minotaurx", hash);

myriadhash(&hash[0], &buf[0]);
printpfx("myr-gr", hash);

Expand Down
Loading