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
$(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
$(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
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
time ./equi1 -r 10

15
equi.c
View File

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

15
equi.h
View File

@ -42,12 +42,13 @@ static const u32 HASHOUT = HASHESPERBLAKE*WN/8;
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);
memcpy(personals+ 8, &le_N, 4);
uint32_t le_K = htole32(WK);
uchar personal[] = "ZcashPoW01230123";
memcpy(personal+8, &le_N, 4);
memcpy(personal+12, &le_K, 4);
memcpy(personals+12, &le_K, 4);
blake2b_param P[1];
P->digest_length = HASHOUT;
P->key_length = 0;
@ -59,7 +60,7 @@ void setheader(blake2b_state *ctx, const char *headernonce) {
P->inner_length = 0;
memset(P->reserved, 0, sizeof(P->reserved));
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_update(ctx, (const uchar *)headernonce, HEADERNONCELEN);
}
@ -118,13 +119,13 @@ bool duped(proof prf) {
}
// 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)
return POW_HEADER_LENGTH;
if (duped(indices))
return POW_DUPLICATE;
blake2b_state ctx;
setheader(&ctx, headernonce);
setheader(&ctx, headernonce, personal);
uchar hash[WN/8];
return verifyrec(&ctx, indices, hash, WK);
}

View File

@ -43,8 +43,9 @@ int main(int argc, char **argv) {
bool compress_sol = false;
const char *header = "";
const char *hex = "";
int c;
while ((c = getopt (argc, argv, "h:n:r:t:x:sc")) != -1) {
char personal[] = "ZcashPoW";
int prefixlen, c;
while ((c = getopt (argc, argv, "h:n:p:r:t:x:sc")) != -1) {
switch (c) {
case 'h':
header = optarg;
@ -52,6 +53,11 @@ int main(int argc, char **argv) {
case 'n':
nonce = atoi(optarg);
break;
case 'p':
prefixlen = strlen(optarg);
assert(prefixlen <= 8);
memcpy((void *)personal, optarg, prefixlen);
break;
case 'r':
range = atoi(optarg);
break;
@ -79,7 +85,7 @@ int main(int argc, char **argv) {
#else
assert(nthreads==1);
#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)
printf("-%d", nonce+range-1);
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++) {
((u32 *)headernonce)[27] = htole32(nonce+r);
eq.setheadernonce(headernonce, sizeof(headernonce));
eq.setheadernonce(headernonce, sizeof(headernonce), personal);
for (int t = 0; t < nthreads; t++) {
threads[t].id = t;
threads[t].eq = &eq;

View File

@ -370,14 +370,14 @@ struct equi {
free(sols);
}
// 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
alignas(8) uchar alignheader[HEADERNONCELEN];
memcpy(alignheader, headernonce, len);
assert(len == HEADERNONCELEN);
Blake2PrepareMidstate4(&blake_ctx, alignheader);
#else
setheader(&blake_ctx, headernonce);
setheader(&blake_ctx, headernonce, personalprefix);
#endif
nsols = bfull = hfull = 0;
}