apow-cli 0.9.2 → 0.9.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +17 -9
- package/README.md +46 -28
- package/dist/bridge/constants.js +5 -0
- package/dist/bridge/ethereum.js +29 -0
- package/dist/bridge/squid.js +19 -2
- package/dist/build.js +5 -0
- package/dist/config.js +26 -8
- package/dist/errors.js +24 -0
- package/dist/fund.js +101 -5
- package/dist/grinder-http.js +108 -0
- package/dist/grinder-native.js +4 -2
- package/dist/index.js +85 -60
- package/dist/miner.js +46 -27
- package/dist/preflight.js +27 -2
- package/local/gpu/grinder-cuda.cu +276 -50
- package/package.json +3 -1
- package/skill.md +56 -19
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* APoW GPU Nonce Grinder — CUDA (RTX 4090)
|
|
2
|
+
* APoW GPU Nonce Grinder — CUDA (RTX 4090) v5: Daemon Mode
|
|
3
3
|
*
|
|
4
4
|
* Grinds nonces for up to 8 addresses simultaneously in one kernel launch.
|
|
5
5
|
* Threads are partitioned across addresses — all addresses grind in parallel.
|
|
6
6
|
* Found nonces are streamed to stdout as they're discovered.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* One-shot mode (backwards compatible):
|
|
9
|
+
* Usage: ./grinder-cuda <challenge_hex> <target_hex> <addr1_hex> [addr2_hex] ...
|
|
10
|
+
*
|
|
11
|
+
* Daemon mode (persistent — eliminates CUDA init overhead per grind):
|
|
12
|
+
* Usage: ./grinder-cuda --daemon
|
|
13
|
+
* Stdin: <challenge_hex> <target_hex> [W<weight>] <addr1_hex> ...\n
|
|
14
|
+
* ABORT\n (cancel current grind, wait for next)
|
|
15
|
+
* Stdout: F <addr_index> <nonce_decimal> <elapsed_seconds>
|
|
16
|
+
* D <total_attempts> <elapsed_seconds>
|
|
17
|
+
* READY\n (daemon ready for next challenge)
|
|
11
18
|
*
|
|
12
19
|
* Build: nvcc grinder-cuda.cu -o grinder-cuda -std=c++17 -O3 -arch=sm_89
|
|
13
20
|
*/
|
|
@@ -18,9 +25,12 @@
|
|
|
18
25
|
#include <cstdint>
|
|
19
26
|
#include <ctime>
|
|
20
27
|
#include <chrono>
|
|
28
|
+
#include <csignal>
|
|
21
29
|
#include <unistd.h>
|
|
30
|
+
#include <sys/select.h>
|
|
22
31
|
|
|
23
32
|
#define MAX_ADDRS 8
|
|
33
|
+
#define MAX_LINE 4096
|
|
24
34
|
|
|
25
35
|
// ── Keccak round constants ──
|
|
26
36
|
|
|
@@ -179,43 +189,57 @@ static int parse_hex(const char* hex, uint8_t* out, int len) {
|
|
|
179
189
|
return 0;
|
|
180
190
|
}
|
|
181
191
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
192
|
+
// Check if stdin has data available (non-blocking)
|
|
193
|
+
static bool stdin_has_data() {
|
|
194
|
+
fd_set fds;
|
|
195
|
+
struct timeval tv = {0, 0}; // 0 timeout = non-blocking
|
|
196
|
+
FD_ZERO(&fds);
|
|
197
|
+
FD_SET(STDIN_FILENO, &fds);
|
|
198
|
+
return select(STDIN_FILENO + 1, &fds, nullptr, nullptr, &tv) > 0;
|
|
199
|
+
}
|
|
189
200
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
201
|
+
// Parse a challenge line into components. Returns number of addresses parsed, or -1 on error.
|
|
202
|
+
static int parse_challenge_line(const char* line,
|
|
203
|
+
uint8_t challenge[32], uint8_t target[32],
|
|
204
|
+
uint8_t addresses[][20], int weights[], int max_addrs) {
|
|
205
|
+
// Tokenize the line (copy it since strtok modifies)
|
|
206
|
+
char buf[MAX_LINE];
|
|
207
|
+
strncpy(buf, line, MAX_LINE - 1);
|
|
208
|
+
buf[MAX_LINE - 1] = '\0';
|
|
209
|
+
|
|
210
|
+
char* tokens[MAX_ADDRS + 10]; // challenge + target + up to MAX_ADDRS * 2 (weight + addr)
|
|
211
|
+
int ntokens = 0;
|
|
212
|
+
char* tok = strtok(buf, " \t\r\n");
|
|
213
|
+
while (tok && ntokens < (int)(sizeof(tokens)/sizeof(tokens[0]))) {
|
|
214
|
+
tokens[ntokens++] = tok;
|
|
215
|
+
tok = strtok(nullptr, " \t\r\n");
|
|
194
216
|
}
|
|
195
217
|
|
|
218
|
+
if (ntokens < 3) return -1; // Need at least challenge + target + 1 addr
|
|
219
|
+
|
|
220
|
+
if (parse_hex(tokens[0], challenge, 32) < 0) return -1;
|
|
221
|
+
if (parse_hex(tokens[1], target, 32) < 0) return -1;
|
|
222
|
+
|
|
196
223
|
int num_addrs = 0;
|
|
197
|
-
uint8_t addresses[MAX_ADDRS][20];
|
|
198
|
-
int weights[MAX_ADDRS];
|
|
199
224
|
int next_weight = 1;
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
next_weight = atoi(argv[i] + 1);
|
|
225
|
+
for (int i = 2; i < ntokens && num_addrs < max_addrs; i++) {
|
|
226
|
+
if (tokens[i][0] == 'W' || tokens[i][0] == 'w') {
|
|
227
|
+
next_weight = atoi(tokens[i] + 1);
|
|
204
228
|
if (next_weight < 1) next_weight = 1;
|
|
205
229
|
if (next_weight > 4) next_weight = 4;
|
|
206
230
|
continue;
|
|
207
231
|
}
|
|
208
|
-
if (parse_hex(
|
|
209
|
-
fprintf(stderr, "Invalid address hex: %s\n", argv[i]);
|
|
210
|
-
return 1;
|
|
211
|
-
}
|
|
232
|
+
if (parse_hex(tokens[i], addresses[num_addrs], 20) < 0) return -1;
|
|
212
233
|
weights[num_addrs] = next_weight;
|
|
213
234
|
next_weight = 1;
|
|
214
235
|
num_addrs++;
|
|
215
236
|
}
|
|
237
|
+
return num_addrs;
|
|
238
|
+
}
|
|
216
239
|
|
|
217
|
-
|
|
218
|
-
|
|
240
|
+
// Compute pre-absorbed keccak state for each address
|
|
241
|
+
static void compute_pre_states(uint64_t pre_states[][25], const uint8_t challenge[32],
|
|
242
|
+
const uint8_t addresses[][20], int num_addrs) {
|
|
219
243
|
for (int a = 0; a < num_addrs; a++) {
|
|
220
244
|
uint8_t input[136] = {0};
|
|
221
245
|
memcpy(input, challenge, 32);
|
|
@@ -223,7 +247,7 @@ int main(int argc, char* argv[]) {
|
|
|
223
247
|
input[84] = 0x01;
|
|
224
248
|
input[135] = 0x80;
|
|
225
249
|
|
|
226
|
-
memset(pre_states[a], 0, sizeof(
|
|
250
|
+
memset(pre_states[a], 0, sizeof(uint64_t) * 25);
|
|
227
251
|
for (int i = 0; i < 17; i++) {
|
|
228
252
|
uint64_t w = 0;
|
|
229
253
|
for (int b = 0; b < 8; b++)
|
|
@@ -231,38 +255,28 @@ int main(int argc, char* argv[]) {
|
|
|
231
255
|
pre_states[a][i] = w;
|
|
232
256
|
}
|
|
233
257
|
}
|
|
258
|
+
}
|
|
234
259
|
|
|
235
|
-
|
|
236
|
-
|
|
260
|
+
// Compute target as big-endian uint64_t[4]
|
|
261
|
+
static void compute_target_be(uint64_t target_be[4], const uint8_t target[32]) {
|
|
237
262
|
for (int i = 0; i < 4; i++) {
|
|
238
263
|
uint64_t w = 0;
|
|
239
264
|
for (int b = 0; b < 8; b++)
|
|
240
265
|
w = (w << 8) | target[i*8 + b];
|
|
241
266
|
target_be[i] = w;
|
|
242
267
|
}
|
|
268
|
+
}
|
|
243
269
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
cudaMallocManaged(¶ms, sizeof(GrindParams));
|
|
248
|
-
cudaMallocManaged(&result, sizeof(GrindResult));
|
|
249
|
-
|
|
250
|
-
memcpy(params->pre_state, pre_states, sizeof(pre_states));
|
|
251
|
-
memcpy(params->target_be, target_be, sizeof(target_be));
|
|
252
|
-
params->num_addrs = num_addrs;
|
|
253
|
-
|
|
254
|
-
srand((unsigned)time(nullptr) ^ (unsigned)getpid());
|
|
255
|
-
uint64_t baseNonce = ((uint64_t)rand() << 32) | (uint64_t)rand();
|
|
256
|
-
|
|
257
|
-
// ── Dispatch config (weighted) ──
|
|
270
|
+
// Configure dispatch (weighted thread allocation across addresses)
|
|
271
|
+
static void configure_dispatch(GrindParams* params, const int weights[], int num_addrs,
|
|
272
|
+
uint64_t* out_batch_size, int* out_grid_size) {
|
|
258
273
|
const int BLOCK_SIZE = 256;
|
|
259
274
|
const uint64_t RAW_BATCH = 1ULL << 26; // 64M
|
|
260
275
|
|
|
261
|
-
// Compute total weight and per-address thread counts
|
|
262
276
|
int total_weight = 0;
|
|
263
277
|
for (int a = 0; a < num_addrs; a++) total_weight += weights[a];
|
|
264
278
|
|
|
265
|
-
uint64_t
|
|
279
|
+
uint64_t batch_size = 0;
|
|
266
280
|
uint32_t cum_offset = 0;
|
|
267
281
|
for (int a = 0; a < num_addrs; a++) {
|
|
268
282
|
uint64_t tpa = (RAW_BATCH * weights[a] / total_weight / BLOCK_SIZE) * BLOCK_SIZE;
|
|
@@ -270,11 +284,19 @@ int main(int argc, char* argv[]) {
|
|
|
270
284
|
params->threads_per_addr[a] = (uint32_t)tpa;
|
|
271
285
|
params->thread_offset[a] = cum_offset;
|
|
272
286
|
cum_offset += (uint32_t)tpa;
|
|
273
|
-
|
|
287
|
+
batch_size += tpa;
|
|
274
288
|
}
|
|
275
|
-
int GRID_SIZE = (int)(BATCH_SIZE / BLOCK_SIZE);
|
|
276
289
|
|
|
277
|
-
|
|
290
|
+
*out_batch_size = batch_size;
|
|
291
|
+
*out_grid_size = (int)(batch_size / BLOCK_SIZE);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// Run the grind loop. Returns true if completed (found or exhausted), false if aborted.
|
|
295
|
+
static bool run_grind(GrindParams* params, GrindResult* result,
|
|
296
|
+
int num_addrs, uint64_t baseNonce,
|
|
297
|
+
uint64_t BATCH_SIZE, int GRID_SIZE, int BLOCK_SIZE,
|
|
298
|
+
bool check_abort) {
|
|
299
|
+
const int MAX_BATCHES = 1 << 20;
|
|
278
300
|
bool found_all[MAX_ADDRS] = {false};
|
|
279
301
|
int found_count = 0;
|
|
280
302
|
|
|
@@ -309,14 +331,218 @@ int main(int argc, char* argv[]) {
|
|
|
309
331
|
found_count++;
|
|
310
332
|
}
|
|
311
333
|
}
|
|
334
|
+
|
|
335
|
+
// In daemon mode, check for ABORT between batches
|
|
336
|
+
if (check_abort && stdin_has_data()) {
|
|
337
|
+
char abort_buf[MAX_LINE];
|
|
338
|
+
if (fgets(abort_buf, sizeof(abort_buf), stdin)) {
|
|
339
|
+
// Trim
|
|
340
|
+
char* p = abort_buf;
|
|
341
|
+
while (*p == ' ' || *p == '\t') p++;
|
|
342
|
+
if (strncmp(p, "ABORT", 5) == 0) {
|
|
343
|
+
auto t1 = std::chrono::steady_clock::now();
|
|
344
|
+
double elapsed = std::chrono::duration<double>(t1 - t0).count();
|
|
345
|
+
printf("D %llu %.3f\n", (unsigned long long)totalAttempts, elapsed);
|
|
346
|
+
fflush(stdout);
|
|
347
|
+
return false; // Aborted
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
312
351
|
}
|
|
313
352
|
|
|
314
353
|
auto t1 = std::chrono::steady_clock::now();
|
|
315
354
|
double elapsed = std::chrono::duration<double>(t1 - t0).count();
|
|
316
355
|
printf("D %llu %.3f\n", (unsigned long long)totalAttempts, elapsed);
|
|
317
356
|
fflush(stdout);
|
|
357
|
+
return true;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// Signal handler for debugging
|
|
361
|
+
static volatile sig_atomic_t got_signal = 0;
|
|
362
|
+
static void signal_handler(int sig) {
|
|
363
|
+
// Write signal info to stderr (async-signal-safe)
|
|
364
|
+
const char* name = "UNKNOWN";
|
|
365
|
+
switch(sig) {
|
|
366
|
+
case SIGTERM: name = "SIGTERM"; break;
|
|
367
|
+
case SIGINT: name = "SIGINT"; break;
|
|
368
|
+
case SIGPIPE: name = "SIGPIPE"; break;
|
|
369
|
+
case SIGHUP: name = "SIGHUP"; break;
|
|
370
|
+
case SIGUSR1: name = "SIGUSR1"; break;
|
|
371
|
+
case SIGUSR2: name = "SIGUSR2"; break;
|
|
372
|
+
}
|
|
373
|
+
fprintf(stderr, "SIGNAL %d (%s) received\n", sig, name);
|
|
374
|
+
fflush(stderr);
|
|
375
|
+
got_signal = sig;
|
|
376
|
+
// Re-raise to get default behavior
|
|
377
|
+
signal(sig, SIG_DFL);
|
|
378
|
+
raise(sig);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
// ── Daemon mode: persistent CUDA process ──
|
|
382
|
+
static int run_daemon() {
|
|
383
|
+
const int BLOCK_SIZE = 256;
|
|
384
|
+
|
|
385
|
+
// Allocate unified memory ONCE
|
|
386
|
+
GrindParams* params;
|
|
387
|
+
GrindResult* result;
|
|
388
|
+
cudaMallocManaged(¶ms, sizeof(GrindParams));
|
|
389
|
+
cudaMallocManaged(&result, sizeof(GrindResult));
|
|
390
|
+
|
|
391
|
+
srand((unsigned)time(nullptr) ^ (unsigned)getpid());
|
|
392
|
+
|
|
393
|
+
// Warmup: launch a tiny kernel to initialize CUDA context fully
|
|
394
|
+
params->num_addrs = 0;
|
|
395
|
+
params->start_nonce = 0;
|
|
396
|
+
grind_kernel<<<1, 1>>>(params, result);
|
|
397
|
+
cudaDeviceSynchronize();
|
|
398
|
+
|
|
399
|
+
// Install signal handlers for debugging
|
|
400
|
+
signal(SIGTERM, signal_handler);
|
|
401
|
+
signal(SIGINT, signal_handler);
|
|
402
|
+
signal(SIGPIPE, signal_handler);
|
|
403
|
+
signal(SIGHUP, signal_handler);
|
|
404
|
+
signal(SIGUSR1, signal_handler);
|
|
405
|
+
signal(SIGUSR2, signal_handler);
|
|
406
|
+
|
|
407
|
+
fprintf(stderr, "CUDA daemon ready (pid=%d)\n", getpid());
|
|
408
|
+
printf("READY\n");
|
|
409
|
+
fflush(stdout);
|
|
410
|
+
|
|
411
|
+
// Main loop: read challenges from stdin
|
|
412
|
+
char line[MAX_LINE];
|
|
413
|
+
while (fgets(line, sizeof(line), stdin)) {
|
|
414
|
+
// Trim leading whitespace
|
|
415
|
+
char* p = line;
|
|
416
|
+
while (*p == ' ' || *p == '\t') p++;
|
|
417
|
+
|
|
418
|
+
// Skip empty lines
|
|
419
|
+
if (*p == '\n' || *p == '\r' || *p == '\0') continue;
|
|
420
|
+
|
|
421
|
+
// Ignore stray ABORT between challenges
|
|
422
|
+
if (strncmp(p, "ABORT", 5) == 0) continue;
|
|
423
|
+
|
|
424
|
+
// Parse challenge line
|
|
425
|
+
uint8_t challenge[32], target[32];
|
|
426
|
+
uint8_t addresses[MAX_ADDRS][20];
|
|
427
|
+
int weights[MAX_ADDRS];
|
|
428
|
+
|
|
429
|
+
int num_addrs = parse_challenge_line(p, challenge, target, addresses, weights, MAX_ADDRS);
|
|
430
|
+
if (num_addrs <= 0) {
|
|
431
|
+
fprintf(stderr, "Invalid challenge line, skipping\n");
|
|
432
|
+
printf("READY\n");
|
|
433
|
+
fflush(stdout);
|
|
434
|
+
continue;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
// Compute pre-states
|
|
438
|
+
uint64_t pre_states[MAX_ADDRS][25];
|
|
439
|
+
compute_pre_states(pre_states, challenge, addresses, num_addrs);
|
|
440
|
+
|
|
441
|
+
uint64_t target_be[4];
|
|
442
|
+
compute_target_be(target_be, target);
|
|
443
|
+
|
|
444
|
+
// Load into GPU params
|
|
445
|
+
memcpy(params->pre_state, pre_states, sizeof(pre_states));
|
|
446
|
+
memcpy(params->target_be, target_be, sizeof(target_be));
|
|
447
|
+
params->num_addrs = num_addrs;
|
|
448
|
+
|
|
449
|
+
// Configure dispatch
|
|
450
|
+
uint64_t BATCH_SIZE;
|
|
451
|
+
int GRID_SIZE;
|
|
452
|
+
configure_dispatch(params, weights, num_addrs, &BATCH_SIZE, &GRID_SIZE);
|
|
453
|
+
|
|
454
|
+
// Random base nonce per challenge
|
|
455
|
+
uint64_t baseNonce = ((uint64_t)rand() << 32) | (uint64_t)rand();
|
|
456
|
+
|
|
457
|
+
// Run grind (with abort checking)
|
|
458
|
+
run_grind(params, result, num_addrs, baseNonce, BATCH_SIZE, GRID_SIZE, BLOCK_SIZE, true);
|
|
459
|
+
|
|
460
|
+
// Signal ready for next challenge
|
|
461
|
+
printf("READY\n");
|
|
462
|
+
fflush(stdout);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
cudaFree(params);
|
|
466
|
+
cudaFree(result);
|
|
467
|
+
return 0;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
// ── One-shot mode (original behavior) ──
|
|
471
|
+
static int run_oneshot(int argc, char* argv[]) {
|
|
472
|
+
const int BLOCK_SIZE = 256;
|
|
473
|
+
|
|
474
|
+
uint8_t challenge[32], target[32];
|
|
475
|
+
if (parse_hex(argv[1], challenge, 32) < 0 || parse_hex(argv[2], target, 32) < 0) {
|
|
476
|
+
fprintf(stderr, "Invalid hex input\n");
|
|
477
|
+
return 1;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
int num_addrs = 0;
|
|
481
|
+
uint8_t addresses[MAX_ADDRS][20];
|
|
482
|
+
int weights[MAX_ADDRS];
|
|
483
|
+
int next_weight = 1;
|
|
484
|
+
|
|
485
|
+
for (int i = 3; i < argc && num_addrs < MAX_ADDRS; i++) {
|
|
486
|
+
if (argv[i][0] == 'W' || argv[i][0] == 'w') {
|
|
487
|
+
next_weight = atoi(argv[i] + 1);
|
|
488
|
+
if (next_weight < 1) next_weight = 1;
|
|
489
|
+
if (next_weight > 4) next_weight = 4;
|
|
490
|
+
continue;
|
|
491
|
+
}
|
|
492
|
+
if (parse_hex(argv[i], addresses[num_addrs], 20) < 0) {
|
|
493
|
+
fprintf(stderr, "Invalid address hex: %s\n", argv[i]);
|
|
494
|
+
return 1;
|
|
495
|
+
}
|
|
496
|
+
weights[num_addrs] = next_weight;
|
|
497
|
+
next_weight = 1;
|
|
498
|
+
num_addrs++;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
// Pre-absorb state
|
|
502
|
+
uint64_t pre_states[MAX_ADDRS][25];
|
|
503
|
+
compute_pre_states(pre_states, challenge, addresses, num_addrs);
|
|
504
|
+
|
|
505
|
+
uint64_t target_be[4];
|
|
506
|
+
compute_target_be(target_be, target);
|
|
507
|
+
|
|
508
|
+
// Allocate unified memory
|
|
509
|
+
GrindParams* params;
|
|
510
|
+
GrindResult* result;
|
|
511
|
+
cudaMallocManaged(¶ms, sizeof(GrindParams));
|
|
512
|
+
cudaMallocManaged(&result, sizeof(GrindResult));
|
|
513
|
+
|
|
514
|
+
memcpy(params->pre_state, pre_states, sizeof(pre_states));
|
|
515
|
+
memcpy(params->target_be, target_be, sizeof(target_be));
|
|
516
|
+
params->num_addrs = num_addrs;
|
|
517
|
+
|
|
518
|
+
srand((unsigned)time(nullptr) ^ (unsigned)getpid());
|
|
519
|
+
uint64_t baseNonce = ((uint64_t)rand() << 32) | (uint64_t)rand();
|
|
520
|
+
|
|
521
|
+
// Configure dispatch
|
|
522
|
+
uint64_t BATCH_SIZE;
|
|
523
|
+
int GRID_SIZE;
|
|
524
|
+
configure_dispatch(params, weights, num_addrs, &BATCH_SIZE, &GRID_SIZE);
|
|
525
|
+
|
|
526
|
+
// Run grind (no abort checking in one-shot mode)
|
|
527
|
+
bool found = run_grind(params, result, num_addrs, baseNonce, BATCH_SIZE, GRID_SIZE, BLOCK_SIZE, false);
|
|
318
528
|
|
|
319
529
|
cudaFree(params);
|
|
320
530
|
cudaFree(result);
|
|
321
|
-
return
|
|
531
|
+
return found ? 0 : 1;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
int main(int argc, char* argv[]) {
|
|
535
|
+
// Check for --daemon flag
|
|
536
|
+
if (argc == 2 && strcmp(argv[1], "--daemon") == 0) {
|
|
537
|
+
return run_daemon();
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
// One-shot mode (backwards compatible)
|
|
541
|
+
if (argc < 4) {
|
|
542
|
+
fprintf(stderr, "Usage: %s <challenge_hex> <target_hex> [W<weight>] <addr1_hex> ...\n", argv[0]);
|
|
543
|
+
fprintf(stderr, " %s --daemon\n", argv[0]);
|
|
544
|
+
return 1;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
return run_oneshot(argc, argv);
|
|
322
548
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "apow-cli",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.4",
|
|
4
4
|
"description": "Mine AGENT tokens on Base L2 with Agentic Proof of Work",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"apow",
|
|
@@ -45,6 +45,8 @@
|
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@blockrun/clawrouter": "^0.12.81",
|
|
48
|
+
"@x402/evm": "^2.8.0",
|
|
49
|
+
"@x402/fetch": "^2.8.0",
|
|
48
50
|
"@quicknode/x402": "^0.1.2",
|
|
49
51
|
"@solana/web3.js": "^1.98.0",
|
|
50
52
|
"commander": "^14.0.0",
|
package/skill.md
CHANGED
|
@@ -55,18 +55,17 @@ If you're an AI agent, skip the interactive wizard and write the `.env` directly
|
|
|
55
55
|
npx apow-cli wallet new
|
|
56
56
|
# Captures address + private key from output (also saved to wallet-<address>.txt)
|
|
57
57
|
|
|
58
|
-
# 2. Write .env directly — ZERO API keys needed
|
|
58
|
+
# 2. Write .env directly — just 2 lines, ZERO API keys needed
|
|
59
|
+
# USE_X402=true auto-activates clawrouter LLM + QuickNode RPC (both pay with USDC)
|
|
60
|
+
# Contract addresses are built-in defaults — no need to specify them
|
|
59
61
|
cat > .env << 'EOF'
|
|
60
62
|
PRIVATE_KEY=0x<from step 1>
|
|
61
63
|
USE_X402=true
|
|
62
|
-
LLM_PROVIDER=clawrouter
|
|
63
|
-
LLM_MODEL=blockrun/eco
|
|
64
|
-
MINING_AGENT_ADDRESS=0xB7caD3ca5F2BD8aEC2Eb67d6E8D448099B3bC03D
|
|
65
|
-
AGENT_COIN_ADDRESS=0x12577CF0D8a07363224D6909c54C056A183e13b3
|
|
66
64
|
EOF
|
|
67
65
|
|
|
68
66
|
# 3. Fund the wallet with ETH (gas) + USDC (x402 RPC + LLM payments)
|
|
69
67
|
npx apow-cli fund --chain solana --token sol # bridge SOL → ETH+USDC on Base
|
|
68
|
+
# Or: npx apow-cli fund --chain ethereum # bridge ETH from Ethereum mainnet
|
|
70
69
|
# Or: npx apow-cli fund --chain base # send ETH or USDC on Base directly
|
|
71
70
|
# Or: ask your user to send ETH + USDC on Base directly
|
|
72
71
|
|
|
@@ -165,17 +164,18 @@ Your mining wallet needs ETH on Base for gas and the mint fee.
|
|
|
165
164
|
|
|
166
165
|
### Built-in Bridge: `apow fund` (Recommended)
|
|
167
166
|
|
|
168
|
-
The CLI bridges from Solana via [Squid Router](https://squidrouter.com/) (Chainflip), or accepts deposits directly on Base. Auto-splits into ETH (gas) + USDC (x402 RPC):
|
|
167
|
+
The CLI bridges from Solana or Ethereum via [Squid Router](https://squidrouter.com/) (Chainflip), or accepts deposits directly on Base. Auto-splits into ETH (gas) + USDC (x402 RPC):
|
|
169
168
|
|
|
170
169
|
```bash
|
|
171
170
|
npx apow-cli fund # Interactive: choose chain + token
|
|
172
171
|
npx apow-cli fund --chain solana --token sol # Bridge SOL → ETH+USDC on Base
|
|
173
172
|
npx apow-cli fund --chain solana --token usdc # Bridge Solana USDC → Base
|
|
173
|
+
npx apow-cli fund --chain ethereum # Bridge ETH from Ethereum mainnet → Base
|
|
174
174
|
npx apow-cli fund --chain base # Show address, wait for deposit
|
|
175
175
|
npx apow-cli fund --chain base --no-swap # Skip auto-split
|
|
176
176
|
```
|
|
177
177
|
|
|
178
|
-
**Solana bridging:** Generates a one-time deposit address with QR code. Send tokens from any
|
|
178
|
+
**Solana/Ethereum bridging:** Generates a one-time deposit address with QR code. Send tokens from any wallet (Phantom, MetaMask, etc.). Requires `SQUID_INTEGRATOR_ID` in `.env` (free at [squidrouter.com](https://app.squidrouter.com/)). Bridge time: ~1-3 minutes via Chainflip.
|
|
179
179
|
|
|
180
180
|
**Auto-split:** After bridging, the CLI checks ETH and USDC balances. If either is below the minimum (0.003 ETH for gas, 2.00 USDC for x402 RPC), it swaps the needed amount via Uniswap V3 on Base. Use `--no-swap` to skip.
|
|
181
181
|
|
|
@@ -247,7 +247,7 @@ AGENT_COIN_ADDRESS=0x12577CF0D8a07363224D6909c54C056A183e13b3
|
|
|
247
247
|
|
|
248
248
|
# === LLM Configuration (required for minting only; mining uses optimized solving) ===
|
|
249
249
|
|
|
250
|
-
# Provider: "clawrouter" (recommended) | "openai" | "gemini" | "deepseek" | "qwen" | "anthropic" | "ollama"
|
|
250
|
+
# Provider: "clawrouter" (recommended) | "openai" | "gemini" | "deepseek" | "qwen" | "anthropic" | "ollama" | "claude-code" | "codex"
|
|
251
251
|
# clawrouter: zero credentials, pays with USDC from your wallet via x402
|
|
252
252
|
LLM_PROVIDER=clawrouter
|
|
253
253
|
|
|
@@ -274,26 +274,36 @@ CHAIN=base
|
|
|
274
274
|
| `PRIVATE_KEY` | Yes | - | Wallet private key (0x + 64 hex chars) |
|
|
275
275
|
| `MINING_AGENT_ADDRESS` | Yes | - | Deployed MiningAgent contract address |
|
|
276
276
|
| `AGENT_COIN_ADDRESS` | Yes | - | Deployed AgentCoin contract address |
|
|
277
|
-
| `LLM_PROVIDER` | For minting | `clawrouter` | LLM provider for minting: `clawrouter` (recommended, zero credentials), `openai`, `gemini`, `deepseek`, `qwen`, `anthropic`,
|
|
278
|
-
| `LLM_API_KEY` | For minting* | - | API key for minting. Not needed for `clawrouter`, `ollama`, `claude-code`, `codex`, or mining. Falls back to
|
|
279
|
-
| `LLM_MODEL` | For minting | `blockrun/eco` | Model identifier passed to the provider (minting only) |
|
|
277
|
+
| `LLM_PROVIDER` | For minting | `clawrouter` if `USE_X402=true`, else `openai` | LLM provider for minting: `clawrouter` (recommended, zero credentials), `openai`, `gemini`, `deepseek`, `qwen`, `anthropic`, `ollama`, `claude-code`, `codex`. Not needed for mining. |
|
|
278
|
+
| `LLM_API_KEY` | For minting* | - | API key for minting. Not needed for `clawrouter`, `ollama`, `claude-code`, `codex`, or mining. Falls back to `OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, `GEMINI_API_KEY`, `DEEPSEEK_API_KEY`, `DASHSCOPE_API_KEY`. |
|
|
279
|
+
| `LLM_MODEL` | For minting | per-provider (e.g. `blockrun/eco`, `gpt-4o-mini`) | Model identifier passed to the provider (minting only). Auto-detected from provider if omitted. |
|
|
280
280
|
| `CLAWROUTER_PORT` | No | `8402` | Port for ClawRouter local proxy (only if default is in use) |
|
|
281
281
|
| `MINER_THREADS` | No | All CPU cores | Threads for JS nonce grinding (fallback if no native GPU/CPU grinder detected) |
|
|
282
282
|
| `RPC_URL` | Yes* | — | Base JSON-RPC endpoint. Get a free URL from Alchemy or QuickNode. *Not needed if `USE_X402=true`. |
|
|
283
283
|
| `USE_X402` | No | `false` | Set to `true` to auto-pay via QuickNode x402 ($10 USDC for ~1M calls). Replaces `RPC_URL`. |
|
|
284
284
|
| `CHAIN` | No | `base` | Network selector; auto-detects `baseSepolia` if RPC URL contains "sepolia" |
|
|
285
285
|
| `SOLANA_RPC_URL` | No | `https://api.mainnet-beta.solana.com` | Solana RPC endpoint (only for `apow fund --chain solana`) |
|
|
286
|
+
| `ETHEREUM_RPC_URL` | No | `https://cloudflare-eth.com` | Ethereum mainnet RPC (only for `apow fund --chain ethereum`) |
|
|
287
|
+
| `OLLAMA_URL` | No | `http://127.0.0.1:11434` | Ollama server URL (only if `LLM_PROVIDER=ollama`) |
|
|
288
|
+
| `GRINDER_MODE` | No | `auto` | Grinder mode: `auto` (detect native binaries) or `js` (force JS worker_threads) |
|
|
289
|
+
| `GPU_GRINDER_PATH` | No | auto-detected | Explicit path to Metal GPU grinder binary |
|
|
290
|
+
| `CUDA_GRINDER_PATH` | No | auto-detected | Explicit path to local CUDA grinder binary |
|
|
291
|
+
| `CPU_GRINDER_PATH` | No | auto-detected | Explicit path to CPU-C grinder binary |
|
|
292
|
+
| `CPU_THREADS` | No | All CPU cores | Thread count for CPU-C grinder |
|
|
293
|
+
| `USE_X402_GRIND` | No | same as `USE_X402` | Enable remote GPU grinding via x402 (dynamic pricing, ~$0.006/grind). Set `false` to disable even when `USE_X402=true`. |
|
|
294
|
+
| `GRIND_URL` | No | `https://grind.apow.io/grind` | Custom GrindProxy endpoint URL (for self-hosted grinding) |
|
|
295
|
+
| `VAST_IP` | No | - | Remote VAST.ai GPU host IP (for remote CUDA mining) |
|
|
296
|
+
| `VAST_PORT` | No | - | Remote VAST.ai GPU SSH port |
|
|
297
|
+
| `REMOTE_GRINDER` | No | `/root/grinder-cuda` | Path to CUDA binary on remote host |
|
|
286
298
|
| `SQUID_INTEGRATOR_ID` | No | - | Squid Router integrator ID for deposit address flow (free at [squidrouter.com](https://app.squidrouter.com/)) |
|
|
287
299
|
|
|
288
300
|
### LLM Provider Recommendations (for Minting)
|
|
289
301
|
|
|
290
|
-
> An LLM is only needed for **minting** your Mining Rig NFT (one-time identity verification). Mining uses optimized algorithmic SMHL solving, with no LLM needed.
|
|
291
|
-
>
|
|
292
|
-
> An LLM is only needed for **minting** your Mining Rig NFT (one-time identity verification). Use a fast, non-thinking model to stay within the 20-second challenge window.
|
|
302
|
+
> An LLM is only needed for **minting** your Mining Rig NFT (one-time identity verification). Mining uses optimized algorithmic SMHL solving, with no LLM needed. Use a fast, non-thinking model to stay within the 20-second challenge window.
|
|
293
303
|
|
|
294
304
|
| Provider | Model | Cost per call | Notes |
|
|
295
305
|
|---|---|---|---|
|
|
296
|
-
| ClawRouter | `blockrun/eco` |
|
|
306
|
+
| ClawRouter | `blockrun/eco` | ~$0.006 | **Recommended.** Zero credentials, pays with USDC via x402 |
|
|
297
307
|
| OpenAI | `gpt-4o-mini` | ~$0.001 | Cheapest API key option, fast, reliable |
|
|
298
308
|
| Gemini | `gemini-2.5-flash` | ~$0.001 | Fast, good accuracy |
|
|
299
309
|
| DeepSeek | `deepseek-chat` | ~$0.001 | Fast, accessible in China |
|
|
@@ -536,7 +546,34 @@ pm2 logs
|
|
|
536
546
|
|
|
537
547
|
**RPC rate limits:** For 3+ concurrent miners, use a dedicated RPC endpoint (Alchemy, Infura, QuickNode). Free public RPCs will not handle the load.
|
|
538
548
|
|
|
539
|
-
**GPU mining (v0.9.
|
|
549
|
+
**GPU mining (v0.9.2+):** The miner auto-detects native grinder binaries for 50-1000x faster nonce grinding. Grinder source files ship with the npm package -- run `apow build-grinders` to compile and install to `~/.apow/`:
|
|
550
|
+
|
|
551
|
+
```bash
|
|
552
|
+
npx apow-cli build-grinders # auto-detects compilers + GPU arch
|
|
553
|
+
npx apow-cli build-grinders --cuda-arch sm_89 # override CUDA architecture
|
|
554
|
+
```
|
|
555
|
+
|
|
556
|
+
Supported grinders (all race in parallel -- first nonce wins, falls back to JS automatically):
|
|
557
|
+
- **Metal GPU** (macOS): requires Xcode CLI tools (`clang`)
|
|
558
|
+
- **CUDA** (NVIDIA GPU): requires CUDA toolkit (`nvcc`), auto-detects GPU arch via `nvidia-smi`
|
|
559
|
+
- **CPU-C** (any platform): requires `clang` or `gcc`
|
|
560
|
+
- **Remote CUDA** (VAST.ai): set `VAST_IP` + `VAST_PORT` env vars for SSH-based remote grinding
|
|
561
|
+
|
|
562
|
+
### x402 GPU Grinding (Remote RTX 4090)
|
|
563
|
+
|
|
564
|
+
No GPU? Add `USE_X402_GRIND=true` to your `.env` for remote RTX 4090 nonce grinding at ~$0.006/grind (dynamic pricing) via the [x402 payment protocol](https://www.x402.org/). Zero setup, zero API keys — payment is automatic from your mining wallet's USDC balance.
|
|
565
|
+
|
|
566
|
+
```bash
|
|
567
|
+
# In your .env (enabled automatically when USE_X402=true)
|
|
568
|
+
USE_X402_GRIND=true
|
|
569
|
+
# GRIND_URL=https://grind.apow.io/grind # default, override for self-hosted
|
|
570
|
+
```
|
|
571
|
+
|
|
572
|
+
The HTTP grinder races alongside all local grinders (Metal, CUDA, CPU-C, JS). First valid nonce wins; losers are cancelled. For GPU-less miners, this is a 10-100x speed improvement over JS fallback.
|
|
573
|
+
|
|
574
|
+
**Front-running is cryptographically impossible:** nonces are bound to `keccak256(challenge, msg.sender, nonce)` — a nonce ground for address A is useless for address B.
|
|
575
|
+
|
|
576
|
+
**Self-hosting:** Deploy your own GrindProxy with any CUDA GPU. See [apow-grind](https://github.com/Agentoshi/apow-grind) for the open-source CF Worker + RunPod Docker image. Set `GRIND_URL` to your endpoint.
|
|
540
577
|
|
|
541
578
|
### Local LLM Setup (Ollama)
|
|
542
579
|
|
|
@@ -555,7 +592,7 @@ LLM_MODEL=llama3.1
|
|
|
555
592
|
|
|
556
593
|
Ollama runs on `http://127.0.0.1:11434` by default. The miner connects there automatically.
|
|
557
594
|
|
|
558
|
-
**Trade-off:** Free inference, but local models may have lower accuracy on the constrained SMHL challenges. The miner retries up to
|
|
595
|
+
**Trade-off:** Free inference, but local models may have lower accuracy on the constrained SMHL challenges. The miner retries up to 5 times per challenge, but persistent failures will slow mining.
|
|
559
596
|
|
|
560
597
|
### Custom RPC Endpoints
|
|
561
598
|
|
|
@@ -608,7 +645,7 @@ Use the corresponding testnet contract addresses.
|
|
|
608
645
|
| `Nonce too high` | Wallet nonce desync | Reset nonce in wallet or wait for pending transactions to confirm |
|
|
609
646
|
| `Anthropic request failed: 429` | Rate limited by Anthropic API | Reduce mining frequency or upgrade API plan |
|
|
610
647
|
| `Ollama request failed: 500` | Ollama server error | Check `ollama serve` is running; restart if needed |
|
|
611
|
-
| `SMHL solve failed after
|
|
648
|
+
| `SMHL solve failed after 5 attempts` | LLM cannot satisfy constraints | Switch to a more capable model (e.g., `gpt-4o` or `claude-sonnet-4-5-20250929`) |
|
|
612
649
|
| `Fee forward failed` | LPVault rejected the ETH transfer | LPVault may not be set; check contract deployment |
|
|
613
650
|
| `10 consecutive failures` | Repeated transient errors | Check RPC connectivity, wallet balance, and LLM availability |
|
|
614
651
|
| `Timed out waiting for next block (60s)` | RPC not responding or network stalled | Check RPC connectivity; try a different RPC endpoint |
|
|
@@ -676,7 +713,7 @@ The SMHL solver sends only generic word-generation prompts to the LLM (e.g., "Wr
|
|
|
676
713
|
cd apow-cli && npm install && npm run build
|
|
677
714
|
node dist/index.js setup
|
|
678
715
|
```
|
|
679
|
-
5. **Review dependencies.** The dependency tree is minimal and standard: `viem` (Ethereum library), `commander` (CLI framework), `dotenv` (env loading), `@solana/web3.js` (Solana signing, lazy-loaded only for bridging), `qrcode-terminal` (QR codes for fund command),
|
|
716
|
+
5. **Review dependencies.** The dependency tree is minimal and standard: `viem` (Ethereum library), `commander` (CLI framework), `dotenv` (env loading), `openai` (LLM client), `@blockrun/clawrouter` (x402 LLM proxy), `@quicknode/x402` (x402 RPC payment), `@solana/web3.js` (Solana signing, lazy-loaded only for bridging), `qrcode-terminal` (QR codes for fund command), `ox` (utilities). No exotic or suspicious packages.
|
|
680
717
|
|
|
681
718
|
### How to Verify These Claims Yourself
|
|
682
719
|
|