allow command line personalization for plain CPU miners

This commit is contained in:
John Tromp 2018-07-10 09:55:16 +02:00
parent 17b76cb3e4
commit 191d3b583f
5 changed files with 36 additions and 18 deletions

View File

@ -31,6 +31,9 @@ eq4851: equi.h equi_miner.h equi_miner.cpp Makefile
eq1445: equi.h equi_miner.h equi_miner.cpp Makefile eq1445: equi.h equi_miner.h equi_miner.cpp Makefile
$(GPP) -DATOMIC -DRESTBITS=4 -DWN=144 -DWK=5 equi_miner.cpp blake/blake2b.cpp -o eq1445 $(GPP) -DATOMIC -DRESTBITS=4 -DWN=144 -DWK=5 equi_miner.cpp blake/blake2b.cpp -o eq1445
eq1686: equi.h equi_miner.h equi_miner.cpp Makefile
$(GPP) -DATOMIC -DRESTBITS=4 -DWN=168 -DWK=6 equi_miner.cpp blake/blake2b.cpp -o eq1686
eq1927: equi.h equi_miner.h equi_miner.cpp Makefile eq1927: equi.h equi_miner.h equi_miner.cpp Makefile
$(GPP) -DATOMIC -DRESTBITS=4 -DWN=192 -DWK=7 equi_miner.cpp blake/blake2b.cpp -o eq1927 $(GPP) -DATOMIC -DRESTBITS=4 -DWN=192 -DWK=7 equi_miner.cpp blake/blake2b.cpp -o eq1927
@ -70,6 +73,9 @@ verify: equi.h equi.c Makefile
verify1445: equi.h equi.c Makefile verify1445: equi.h equi.c Makefile
g++ -DRESTBITS=4 -DWN=144 -DWK=5 -g equi.c blake/blake2b.cpp -o verify1445 g++ -DRESTBITS=4 -DWN=144 -DWK=5 -g equi.c blake/blake2b.cpp -o verify1445
verify1686: equi.h equi.c Makefile
g++ -DRESTBITS=4 -DWN=168 -DWK=6 -g equi.c blake/blake2b.cpp -o verify1686
bench: equi1 bench: equi1
time ./equi1 -r 10 time ./equi1 -r 10

15
equi.c
View File

@ -8,8 +8,9 @@
int main(int argc, char **argv) { int main(int argc, char **argv) {
const char *header = ""; const char *header = "";
int nonce = 0, c; char personal[] = "ZcashPoW";
while ((c = getopt (argc, argv, "h:n:")) != -1) { int prefixlen, nonce = 0, c;
while ((c = getopt (argc, argv, "h:n:p:")) != -1) {
switch (c) { switch (c) {
case 'h': case 'h':
header = optarg; header = optarg;
@ -17,10 +18,14 @@ int main(int argc, char **argv) {
case 'n': case 'n':
nonce = atoi(optarg); nonce = atoi(optarg);
break; break;
case 'p':
prefixlen = strlen(optarg);
assert(prefixlen <= 8);
memcpy((void *)personal, optarg, prefixlen);
} }
} }
printf("Verifying size %d proof for equi(\"%s\",%d)\n", printf("Verifying size %d proof for %s(\"%s\",%d)\n",
PROOFSIZE, header, nonce); PROOFSIZE, personal, header, nonce);
char headernonce[HEADERNONCELEN]; char headernonce[HEADERNONCELEN];
u32 hdrlen = strlen(header); u32 hdrlen = strlen(header);
memcpy(headernonce, header, hdrlen); memcpy(headernonce, header, hdrlen);
@ -32,7 +37,7 @@ int main(int argc, char **argv) {
int nscan = scanf(" %x", &indices[n]); int nscan = scanf(" %x", &indices[n]);
assert(nscan == 1); assert(nscan == 1);
} }
int pow_rc = verify(indices, headernonce, sizeof(headernonce)); int pow_rc = verify(indices, headernonce, sizeof(headernonce), personal);
if (pow_rc == POW_OK) if (pow_rc == POW_OK)
printf("Verified\n"); printf("Verified\n");
else else

15
equi.h
View File

@ -42,12 +42,13 @@ static const u32 HASHOUT = HASHESPERBLAKE*WN/8;
typedef u32 proof[PROOFSIZE]; typedef u32 proof[PROOFSIZE];
void setheader(blake2b_state *ctx, const char *headernonce) { void setheader(blake2b_state *ctx, const char *headernonce, const char *personal) {
char personals[16];
memcpy(personals+ 0, personal, 8);
uint32_t le_N = htole32(WN); uint32_t le_N = htole32(WN);
memcpy(personals+ 8, &le_N, 4);
uint32_t le_K = htole32(WK); uint32_t le_K = htole32(WK);
uchar personal[] = "ZcashPoW01230123"; memcpy(personals+12, &le_K, 4);
memcpy(personal+8, &le_N, 4);
memcpy(personal+12, &le_K, 4);
blake2b_param P[1]; blake2b_param P[1];
P->digest_length = HASHOUT; P->digest_length = HASHOUT;
P->key_length = 0; P->key_length = 0;
@ -59,7 +60,7 @@ void setheader(blake2b_state *ctx, const char *headernonce) {
P->inner_length = 0; P->inner_length = 0;
memset(P->reserved, 0, sizeof(P->reserved)); memset(P->reserved, 0, sizeof(P->reserved));
memset(P->salt, 0, sizeof(P->salt)); memset(P->salt, 0, sizeof(P->salt));
memcpy(P->personal, (const uint8_t *)personal, 16); memcpy(P->personal, (const uint8_t *)personals, 16);
blake2b_init_param(ctx, P); blake2b_init_param(ctx, P);
blake2b_update(ctx, (const uchar *)headernonce, HEADERNONCELEN); blake2b_update(ctx, (const uchar *)headernonce, HEADERNONCELEN);
} }
@ -118,13 +119,13 @@ bool duped(proof prf) {
} }
// verify Wagner conditions // verify Wagner conditions
int verify(u32 indices[PROOFSIZE], const char *headernonce, const u32 headerlen) { int verify(u32 indices[PROOFSIZE], const char *headernonce, const u32 headerlen, const char *personal) {
if (headerlen != HEADERNONCELEN) if (headerlen != HEADERNONCELEN)
return POW_HEADER_LENGTH; return POW_HEADER_LENGTH;
if (duped(indices)) if (duped(indices))
return POW_DUPLICATE; return POW_DUPLICATE;
blake2b_state ctx; blake2b_state ctx;
setheader(&ctx, headernonce); setheader(&ctx, headernonce, personal);
uchar hash[WN/8]; uchar hash[WN/8];
return verifyrec(&ctx, indices, hash, WK); return verifyrec(&ctx, indices, hash, WK);
} }

View File

@ -43,8 +43,9 @@ int main(int argc, char **argv) {
bool compress_sol = false; bool compress_sol = false;
const char *header = ""; const char *header = "";
const char *hex = ""; const char *hex = "";
int c; char personal[] = "ZcashPoW";
while ((c = getopt (argc, argv, "h:n:r:t:x:sc")) != -1) { int prefixlen, c;
while ((c = getopt (argc, argv, "h:n:p:r:t:x:sc")) != -1) {
switch (c) { switch (c) {
case 'h': case 'h':
header = optarg; header = optarg;
@ -52,6 +53,11 @@ int main(int argc, char **argv) {
case 'n': case 'n':
nonce = atoi(optarg); nonce = atoi(optarg);
break; break;
case 'p':
prefixlen = strlen(optarg);
assert(prefixlen <= 8);
memcpy((void *)personal, optarg, prefixlen);
break;
case 'r': case 'r':
range = atoi(optarg); range = atoi(optarg);
break; break;
@ -79,7 +85,7 @@ int main(int argc, char **argv) {
#else #else
assert(nthreads==1); assert(nthreads==1);
#endif #endif
printf("Looking for wagner-tree on (\"%s\",%d", hex ? "0x..." : header, nonce); printf("Looking for wagner-tree on %s(\"%s\",%d", personal, hex ? "0x..." : header, nonce);
if (range > 1) if (range > 1)
printf("-%d", nonce+range-1); printf("-%d", nonce+range-1);
printf(") with %d %d-bit digits and %d threads\n", NDIGITS, DIGITBITS, nthreads); printf(") with %d %d-bit digits and %d threads\n", NDIGITS, DIGITBITS, nthreads);
@ -103,7 +109,7 @@ int main(int argc, char **argv) {
} }
for (int r = 0; r < range; r++) { for (int r = 0; r < range; r++) {
((u32 *)headernonce)[27] = htole32(nonce+r); ((u32 *)headernonce)[27] = htole32(nonce+r);
eq.setheadernonce(headernonce, sizeof(headernonce)); eq.setheadernonce(headernonce, sizeof(headernonce), personal);
for (int t = 0; t < nthreads; t++) { for (int t = 0; t < nthreads; t++) {
threads[t].id = t; threads[t].id = t;
threads[t].eq = &eq; threads[t].eq = &eq;

View File

@ -370,14 +370,14 @@ struct equi {
free(sols); free(sols);
} }
// prepare blake2b midstate for new run and initialize counters // prepare blake2b midstate for new run and initialize counters
void setheadernonce(const char *headernonce, const u32 len) { void setheadernonce(const char *headernonce, const u32 len, const char *personalprefix = 0) {
#ifdef ASM_BLAKE #ifdef ASM_BLAKE
alignas(8) uchar alignheader[HEADERNONCELEN]; alignas(8) uchar alignheader[HEADERNONCELEN];
memcpy(alignheader, headernonce, len); memcpy(alignheader, headernonce, len);
assert(len == HEADERNONCELEN); assert(len == HEADERNONCELEN);
Blake2PrepareMidstate4(&blake_ctx, alignheader); Blake2PrepareMidstate4(&blake_ctx, alignheader);
#else #else
setheader(&blake_ctx, headernonce); setheader(&blake_ctx, headernonce, personalprefix);
#endif #endif
nsols = bfull = hfull = 0; nsols = bfull = hfull = 0;
} }