-
Notifications
You must be signed in to change notification settings - Fork 79
/
equi.c
47 lines (46 loc) · 1.38 KB
/
equi.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "equi.h"
#include <inttypes.h> // for SCNx64 macro
#include <stdio.h> // printf/scanf
#include <stdlib.h> // exit
#include <unistd.h> // getopt
#include <string.h> // strlen
#include <assert.h> // d'uh
int main(int argc, char **argv) {
const char *header = "";
char personal[] = "ZcashPoW";
int prefixlen, nonce = 0, c;
while ((c = getopt (argc, argv, "h:n:p:")) != -1) {
switch (c) {
case 'h':
header = optarg;
break;
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 %s(\"%s\",%d)\n",
PROOFSIZE, personal, header, nonce);
char headernonce[HEADERNONCELEN];
u32 hdrlen = strlen(header);
memcpy(headernonce, header, hdrlen);
memset(headernonce+hdrlen, 0, sizeof(headernonce)-hdrlen);
((u32 *)headernonce)[32] = htole32(nonce);
for (int nsols=0; scanf(" Solution") == 0; nsols++) {
u32 indices[PROOFSIZE];
for (int n = 0; n < PROOFSIZE; n++) {
int nscan = scanf(" %x", &indices[n]);
assert(nscan == 1);
}
int pow_rc = verify(indices, headernonce, sizeof(headernonce), personal);
if (pow_rc == POW_OK)
printf("Verified\n");
else
printf("FAILED due to %s\n", errstr[pow_rc]);
}
return 0;
}