apow-cli 0.9.2 → 0.9.3

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.
@@ -1,13 +1,20 @@
1
1
  /*
2
- * APoW GPU Nonce Grinder — CUDA (RTX 4090) v4: Multi-Address Concurrent
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
- * Usage: ./grinder-cuda <challenge_hex> <target_hex> <addr1_hex> [addr2_hex] ...
9
- * Output (streamed): F <addr_index> <nonce_decimal>
10
- * Final line: D <total_attempts> <elapsed_seconds>
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
  */
@@ -19,8 +26,10 @@
19
26
  #include <ctime>
20
27
  #include <chrono>
21
28
  #include <unistd.h>
29
+ #include <sys/select.h>
22
30
 
23
31
  #define MAX_ADDRS 8
32
+ #define MAX_LINE 4096
24
33
 
25
34
  // ── Keccak round constants ──
26
35
 
@@ -179,43 +188,57 @@ static int parse_hex(const char* hex, uint8_t* out, int len) {
179
188
  return 0;
180
189
  }
181
190
 
182
- int main(int argc, char* argv[]) {
183
- // Usage: grinder-cuda <challenge> <target> [Wn] <addr1> [Wn] [addr2] ...
184
- // Wn before an address sets its weight (default 1). E.g. W2 = 2x threads.
185
- if (argc < 4) {
186
- fprintf(stderr, "Usage: %s <challenge_hex> <target_hex> [W<weight>] <addr1_hex> ...\n", argv[0]);
187
- return 1;
188
- }
191
+ // Check if stdin has data available (non-blocking)
192
+ static bool stdin_has_data() {
193
+ fd_set fds;
194
+ struct timeval tv = {0, 0}; // 0 timeout = non-blocking
195
+ FD_ZERO(&fds);
196
+ FD_SET(STDIN_FILENO, &fds);
197
+ return select(STDIN_FILENO + 1, &fds, nullptr, nullptr, &tv) > 0;
198
+ }
189
199
 
190
- uint8_t challenge[32], target[32];
191
- if (parse_hex(argv[1], challenge, 32) < 0 || parse_hex(argv[2], target, 32) < 0) {
192
- fprintf(stderr, "Invalid hex input\n");
193
- return 1;
200
+ // Parse a challenge line into components. Returns number of addresses parsed, or -1 on error.
201
+ static int parse_challenge_line(const char* line,
202
+ uint8_t challenge[32], uint8_t target[32],
203
+ uint8_t addresses[][20], int weights[], int max_addrs) {
204
+ // Tokenize the line (copy it since strtok modifies)
205
+ char buf[MAX_LINE];
206
+ strncpy(buf, line, MAX_LINE - 1);
207
+ buf[MAX_LINE - 1] = '\0';
208
+
209
+ char* tokens[MAX_ADDRS + 10]; // challenge + target + up to MAX_ADDRS * 2 (weight + addr)
210
+ int ntokens = 0;
211
+ char* tok = strtok(buf, " \t\r\n");
212
+ while (tok && ntokens < (int)(sizeof(tokens)/sizeof(tokens[0]))) {
213
+ tokens[ntokens++] = tok;
214
+ tok = strtok(nullptr, " \t\r\n");
194
215
  }
195
216
 
217
+ if (ntokens < 3) return -1; // Need at least challenge + target + 1 addr
218
+
219
+ if (parse_hex(tokens[0], challenge, 32) < 0) return -1;
220
+ if (parse_hex(tokens[1], target, 32) < 0) return -1;
221
+
196
222
  int num_addrs = 0;
197
- uint8_t addresses[MAX_ADDRS][20];
198
- int weights[MAX_ADDRS];
199
223
  int next_weight = 1;
200
-
201
- for (int i = 3; i < argc && num_addrs < MAX_ADDRS; i++) {
202
- if (argv[i][0] == 'W' || argv[i][0] == 'w') {
203
- next_weight = atoi(argv[i] + 1);
224
+ for (int i = 2; i < ntokens && num_addrs < max_addrs; i++) {
225
+ if (tokens[i][0] == 'W' || tokens[i][0] == 'w') {
226
+ next_weight = atoi(tokens[i] + 1);
204
227
  if (next_weight < 1) next_weight = 1;
205
228
  if (next_weight > 4) next_weight = 4;
206
229
  continue;
207
230
  }
208
- if (parse_hex(argv[i], addresses[num_addrs], 20) < 0) {
209
- fprintf(stderr, "Invalid address hex: %s\n", argv[i]);
210
- return 1;
211
- }
231
+ if (parse_hex(tokens[i], addresses[num_addrs], 20) < 0) return -1;
212
232
  weights[num_addrs] = next_weight;
213
233
  next_weight = 1;
214
234
  num_addrs++;
215
235
  }
236
+ return num_addrs;
237
+ }
216
238
 
217
- // ── Pre-absorb state for each address ──
218
- uint64_t pre_states[MAX_ADDRS][25];
239
+ // Compute pre-absorbed keccak state for each address
240
+ static void compute_pre_states(uint64_t pre_states[][25], const uint8_t challenge[32],
241
+ const uint8_t addresses[][20], int num_addrs) {
219
242
  for (int a = 0; a < num_addrs; a++) {
220
243
  uint8_t input[136] = {0};
221
244
  memcpy(input, challenge, 32);
@@ -223,7 +246,7 @@ int main(int argc, char* argv[]) {
223
246
  input[84] = 0x01;
224
247
  input[135] = 0x80;
225
248
 
226
- memset(pre_states[a], 0, sizeof(pre_states[a]));
249
+ memset(pre_states[a], 0, sizeof(uint64_t) * 25);
227
250
  for (int i = 0; i < 17; i++) {
228
251
  uint64_t w = 0;
229
252
  for (int b = 0; b < 8; b++)
@@ -231,38 +254,28 @@ int main(int argc, char* argv[]) {
231
254
  pre_states[a][i] = w;
232
255
  }
233
256
  }
257
+ }
234
258
 
235
- // Target as big-endian uint64_t
236
- uint64_t target_be[4];
259
+ // Compute target as big-endian uint64_t[4]
260
+ static void compute_target_be(uint64_t target_be[4], const uint8_t target[32]) {
237
261
  for (int i = 0; i < 4; i++) {
238
262
  uint64_t w = 0;
239
263
  for (int b = 0; b < 8; b++)
240
264
  w = (w << 8) | target[i*8 + b];
241
265
  target_be[i] = w;
242
266
  }
267
+ }
243
268
 
244
- // ── Allocate unified memory ──
245
- GrindParams* params;
246
- GrindResult* result;
247
- cudaMallocManaged(&params, 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) ──
269
+ // Configure dispatch (weighted thread allocation across addresses)
270
+ static void configure_dispatch(GrindParams* params, const int weights[], int num_addrs,
271
+ uint64_t* out_batch_size, int* out_grid_size) {
258
272
  const int BLOCK_SIZE = 256;
259
273
  const uint64_t RAW_BATCH = 1ULL << 26; // 64M
260
274
 
261
- // Compute total weight and per-address thread counts
262
275
  int total_weight = 0;
263
276
  for (int a = 0; a < num_addrs; a++) total_weight += weights[a];
264
277
 
265
- uint64_t BATCH_SIZE = 0;
278
+ uint64_t batch_size = 0;
266
279
  uint32_t cum_offset = 0;
267
280
  for (int a = 0; a < num_addrs; a++) {
268
281
  uint64_t tpa = (RAW_BATCH * weights[a] / total_weight / BLOCK_SIZE) * BLOCK_SIZE;
@@ -270,11 +283,19 @@ int main(int argc, char* argv[]) {
270
283
  params->threads_per_addr[a] = (uint32_t)tpa;
271
284
  params->thread_offset[a] = cum_offset;
272
285
  cum_offset += (uint32_t)tpa;
273
- BATCH_SIZE += tpa;
286
+ batch_size += tpa;
274
287
  }
275
- int GRID_SIZE = (int)(BATCH_SIZE / BLOCK_SIZE);
276
288
 
277
- const int MAX_BATCHES = 1 << 20; // ~64T hashes — never exhausts before abort
289
+ *out_batch_size = batch_size;
290
+ *out_grid_size = (int)(batch_size / BLOCK_SIZE);
291
+ }
292
+
293
+ // Run the grind loop. Returns true if completed (found or exhausted), false if aborted.
294
+ static bool run_grind(GrindParams* params, GrindResult* result,
295
+ int num_addrs, uint64_t baseNonce,
296
+ uint64_t BATCH_SIZE, int GRID_SIZE, int BLOCK_SIZE,
297
+ bool check_abort) {
298
+ const int MAX_BATCHES = 1 << 20;
278
299
  bool found_all[MAX_ADDRS] = {false};
279
300
  int found_count = 0;
280
301
 
@@ -309,14 +330,189 @@ int main(int argc, char* argv[]) {
309
330
  found_count++;
310
331
  }
311
332
  }
333
+
334
+ // In daemon mode, check for ABORT between batches
335
+ if (check_abort && stdin_has_data()) {
336
+ char abort_buf[MAX_LINE];
337
+ if (fgets(abort_buf, sizeof(abort_buf), stdin)) {
338
+ // Trim
339
+ char* p = abort_buf;
340
+ while (*p == ' ' || *p == '\t') p++;
341
+ if (strncmp(p, "ABORT", 5) == 0) {
342
+ auto t1 = std::chrono::steady_clock::now();
343
+ double elapsed = std::chrono::duration<double>(t1 - t0).count();
344
+ printf("D %llu %.3f\n", (unsigned long long)totalAttempts, elapsed);
345
+ fflush(stdout);
346
+ return false; // Aborted
347
+ }
348
+ }
349
+ }
312
350
  }
313
351
 
314
352
  auto t1 = std::chrono::steady_clock::now();
315
353
  double elapsed = std::chrono::duration<double>(t1 - t0).count();
316
354
  printf("D %llu %.3f\n", (unsigned long long)totalAttempts, elapsed);
317
355
  fflush(stdout);
356
+ return true;
357
+ }
358
+
359
+ // ── Daemon mode: persistent CUDA process ──
360
+ static int run_daemon() {
361
+ const int BLOCK_SIZE = 256;
362
+
363
+ // Allocate unified memory ONCE
364
+ GrindParams* params;
365
+ GrindResult* result;
366
+ cudaMallocManaged(&params, sizeof(GrindParams));
367
+ cudaMallocManaged(&result, sizeof(GrindResult));
368
+
369
+ srand((unsigned)time(nullptr) ^ (unsigned)getpid());
370
+
371
+ // Warmup: launch a tiny kernel to initialize CUDA context fully
372
+ params->num_addrs = 0;
373
+ params->start_nonce = 0;
374
+ grind_kernel<<<1, 1>>>(params, result);
375
+ cudaDeviceSynchronize();
376
+
377
+ fprintf(stderr, "CUDA daemon ready\n");
378
+ printf("READY\n");
379
+ fflush(stdout);
380
+
381
+ // Main loop: read challenges from stdin
382
+ char line[MAX_LINE];
383
+ while (fgets(line, sizeof(line), stdin)) {
384
+ // Trim leading whitespace
385
+ char* p = line;
386
+ while (*p == ' ' || *p == '\t') p++;
387
+
388
+ // Skip empty lines
389
+ if (*p == '\n' || *p == '\r' || *p == '\0') continue;
390
+
391
+ // Ignore stray ABORT between challenges
392
+ if (strncmp(p, "ABORT", 5) == 0) continue;
393
+
394
+ // Parse challenge line
395
+ uint8_t challenge[32], target[32];
396
+ uint8_t addresses[MAX_ADDRS][20];
397
+ int weights[MAX_ADDRS];
398
+
399
+ int num_addrs = parse_challenge_line(p, challenge, target, addresses, weights, MAX_ADDRS);
400
+ if (num_addrs <= 0) {
401
+ fprintf(stderr, "Invalid challenge line, skipping\n");
402
+ printf("READY\n");
403
+ fflush(stdout);
404
+ continue;
405
+ }
406
+
407
+ // Compute pre-states
408
+ uint64_t pre_states[MAX_ADDRS][25];
409
+ compute_pre_states(pre_states, challenge, addresses, num_addrs);
410
+
411
+ uint64_t target_be[4];
412
+ compute_target_be(target_be, target);
413
+
414
+ // Load into GPU params
415
+ memcpy(params->pre_state, pre_states, sizeof(pre_states));
416
+ memcpy(params->target_be, target_be, sizeof(target_be));
417
+ params->num_addrs = num_addrs;
418
+
419
+ // Configure dispatch
420
+ uint64_t BATCH_SIZE;
421
+ int GRID_SIZE;
422
+ configure_dispatch(params, weights, num_addrs, &BATCH_SIZE, &GRID_SIZE);
423
+
424
+ // Random base nonce per challenge
425
+ uint64_t baseNonce = ((uint64_t)rand() << 32) | (uint64_t)rand();
426
+
427
+ // Run grind (with abort checking)
428
+ run_grind(params, result, num_addrs, baseNonce, BATCH_SIZE, GRID_SIZE, BLOCK_SIZE, true);
429
+
430
+ // Signal ready for next challenge
431
+ printf("READY\n");
432
+ fflush(stdout);
433
+ }
318
434
 
319
435
  cudaFree(params);
320
436
  cudaFree(result);
321
- return (found_count > 0) ? 0 : 1;
437
+ return 0;
438
+ }
439
+
440
+ // ── One-shot mode (original behavior) ──
441
+ static int run_oneshot(int argc, char* argv[]) {
442
+ const int BLOCK_SIZE = 256;
443
+
444
+ uint8_t challenge[32], target[32];
445
+ if (parse_hex(argv[1], challenge, 32) < 0 || parse_hex(argv[2], target, 32) < 0) {
446
+ fprintf(stderr, "Invalid hex input\n");
447
+ return 1;
448
+ }
449
+
450
+ int num_addrs = 0;
451
+ uint8_t addresses[MAX_ADDRS][20];
452
+ int weights[MAX_ADDRS];
453
+ int next_weight = 1;
454
+
455
+ for (int i = 3; i < argc && num_addrs < MAX_ADDRS; i++) {
456
+ if (argv[i][0] == 'W' || argv[i][0] == 'w') {
457
+ next_weight = atoi(argv[i] + 1);
458
+ if (next_weight < 1) next_weight = 1;
459
+ if (next_weight > 4) next_weight = 4;
460
+ continue;
461
+ }
462
+ if (parse_hex(argv[i], addresses[num_addrs], 20) < 0) {
463
+ fprintf(stderr, "Invalid address hex: %s\n", argv[i]);
464
+ return 1;
465
+ }
466
+ weights[num_addrs] = next_weight;
467
+ next_weight = 1;
468
+ num_addrs++;
469
+ }
470
+
471
+ // Pre-absorb state
472
+ uint64_t pre_states[MAX_ADDRS][25];
473
+ compute_pre_states(pre_states, challenge, addresses, num_addrs);
474
+
475
+ uint64_t target_be[4];
476
+ compute_target_be(target_be, target);
477
+
478
+ // Allocate unified memory
479
+ GrindParams* params;
480
+ GrindResult* result;
481
+ cudaMallocManaged(&params, sizeof(GrindParams));
482
+ cudaMallocManaged(&result, sizeof(GrindResult));
483
+
484
+ memcpy(params->pre_state, pre_states, sizeof(pre_states));
485
+ memcpy(params->target_be, target_be, sizeof(target_be));
486
+ params->num_addrs = num_addrs;
487
+
488
+ srand((unsigned)time(nullptr) ^ (unsigned)getpid());
489
+ uint64_t baseNonce = ((uint64_t)rand() << 32) | (uint64_t)rand();
490
+
491
+ // Configure dispatch
492
+ uint64_t BATCH_SIZE;
493
+ int GRID_SIZE;
494
+ configure_dispatch(params, weights, num_addrs, &BATCH_SIZE, &GRID_SIZE);
495
+
496
+ // Run grind (no abort checking in one-shot mode)
497
+ bool found = run_grind(params, result, num_addrs, baseNonce, BATCH_SIZE, GRID_SIZE, BLOCK_SIZE, false);
498
+
499
+ cudaFree(params);
500
+ cudaFree(result);
501
+ return found ? 0 : 1;
502
+ }
503
+
504
+ int main(int argc, char* argv[]) {
505
+ // Check for --daemon flag
506
+ if (argc == 2 && strcmp(argv[1], "--daemon") == 0) {
507
+ return run_daemon();
508
+ }
509
+
510
+ // One-shot mode (backwards compatible)
511
+ if (argc < 4) {
512
+ fprintf(stderr, "Usage: %s <challenge_hex> <target_hex> [W<weight>] <addr1_hex> ...\n", argv[0]);
513
+ fprintf(stderr, " %s --daemon\n", argv[0]);
514
+ return 1;
515
+ }
516
+
517
+ return run_oneshot(argc, argv);
322
518
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apow-cli",
3
- "version": "0.9.2",
3
+ "version": "0.9.3",
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 Solana wallet (Phantom, Backpack, etc.). Requires `SQUID_INTEGRATOR_ID` in `.env` (free at [squidrouter.com](https://app.squidrouter.com/)). Bridge time: ~1-3 minutes via Chainflip.
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,22 +274,32 @@ 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`, or `ollama`. 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 provider-specific env vars. |
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 ($0.01/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
  |---|---|---|---|
@@ -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.0+):** The miner auto-detects native GPU grinder binaries for 50-1000x faster nonce grinding. Build Metal (macOS) or CPU-C grinders from `local/gpu/`, or rent a CUDA GPU on [vast.ai](https://vast.ai/) with `./local/vast-setup.sh`. All grinders race in parallel -- first nonce wins. Falls back to JS automatically.
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.01 per grind 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 3 times per challenge, but persistent failures will slow mining.
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 3 attempts` | LLM cannot satisfy constraints | Switch to a more capable model (e.g., `gpt-4o` or `claude-sonnet-4-5-20250929`) |
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), and an LLM client. No exotic or suspicious packages.
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