apow-cli 0.9.1 → 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.
@@ -0,0 +1,191 @@
1
+ /*
2
+ * APoW GPU Nonce Grinder — Metal compute on Apple Silicon
3
+ * Usage: ./grinder-gpu <challenge_hex> <address_hex> <target_hex>
4
+ * Output: <nonce_decimal> <attempts> <elapsed_seconds>
5
+ *
6
+ * Dispatches millions of nonces per batch to the GPU.
7
+ * M3 Max (40 GPU cores) should hit 500M-2B+ H/s.
8
+ */
9
+
10
+ #import <Foundation/Foundation.h>
11
+ #import <Metal/Metal.h>
12
+ #include <stdio.h>
13
+ #include <stdlib.h>
14
+ #include <string.h>
15
+ #include <stdint.h>
16
+ #include <time.h>
17
+
18
+ // Must match the Metal shader structs exactly (natural alignment)
19
+ typedef struct {
20
+ uint8_t base[84];
21
+ uint8_t target[32];
22
+ uint32_t _pad; // align start_nonce to 8 bytes (84+32=116, +4=120)
23
+ uint64_t start_nonce;
24
+ } GrindParams;
25
+
26
+ typedef struct {
27
+ uint32_t found; // atomic in shader, plain here
28
+ uint32_t _pad; // alignment
29
+ uint64_t nonce;
30
+ uint32_t thread_id;
31
+ } GrindResult;
32
+
33
+ static int hex2byte(char c) {
34
+ if (c >= '0' && c <= '9') return c - '0';
35
+ if (c >= 'a' && c <= 'f') return c - 'a' + 10;
36
+ if (c >= 'A' && c <= 'F') return c - 'A' + 10;
37
+ return -1;
38
+ }
39
+
40
+ static int parse_hex(const char *hex, uint8_t *out, int len) {
41
+ if (hex[0] == '0' && hex[1] == 'x') hex += 2;
42
+ for (int i = 0; i < len; i++) {
43
+ int hi = hex2byte(hex[i*2]);
44
+ int lo = hex2byte(hex[i*2+1]);
45
+ if (hi < 0 || lo < 0) return -1;
46
+ out[i] = (hi << 4) | lo;
47
+ }
48
+ return 0;
49
+ }
50
+
51
+ int main(int argc, char *argv[]) {
52
+ @autoreleasepool {
53
+ if (argc < 4) {
54
+ fprintf(stderr, "Usage: %s <challenge_hex> <address_hex> <target_hex>\n", argv[0]);
55
+ return 1;
56
+ }
57
+
58
+ uint8_t challenge[32], address[20], target[32];
59
+ if (parse_hex(argv[1], challenge, 32) < 0 ||
60
+ parse_hex(argv[2], address, 20) < 0 ||
61
+ parse_hex(argv[3], target, 32) < 0) {
62
+ fprintf(stderr, "Invalid hex input\n");
63
+ return 1;
64
+ }
65
+
66
+ // ── Metal setup ──
67
+ id<MTLDevice> device = MTLCreateSystemDefaultDevice();
68
+ if (!device) {
69
+ fprintf(stderr, "No Metal device found\n");
70
+ return 1;
71
+ }
72
+
73
+ // Load shader from .metallib (pre-compiled) or compile from source
74
+ NSError *error = nil;
75
+ NSString *shaderPath = [[[NSString stringWithUTF8String:argv[0]]
76
+ stringByDeletingLastPathComponent]
77
+ stringByAppendingPathComponent:@"keccak.metallib"];
78
+
79
+ id<MTLLibrary> library = nil;
80
+ if ([[NSFileManager defaultManager] fileExistsAtPath:shaderPath]) {
81
+ library = [device newLibraryWithFile:shaderPath error:&error];
82
+ }
83
+
84
+ if (!library) {
85
+ // Fallback: compile from source
86
+ NSString *srcDir = [[NSString stringWithUTF8String:argv[0]] stringByDeletingLastPathComponent];
87
+ NSString *srcPath = [srcDir stringByAppendingPathComponent:@"keccak.metal"];
88
+ NSString *source = [NSString stringWithContentsOfFile:srcPath encoding:NSUTF8StringEncoding error:&error];
89
+ if (!source) {
90
+ fprintf(stderr, "Cannot read shader: %s\n", [[error localizedDescription] UTF8String]);
91
+ return 1;
92
+ }
93
+ MTLCompileOptions *opts = [[MTLCompileOptions alloc] init];
94
+ opts.fastMathEnabled = YES;
95
+ library = [device newLibraryWithSource:source options:opts error:&error];
96
+ if (!library) {
97
+ fprintf(stderr, "Shader compile error: %s\n", [[error localizedDescription] UTF8String]);
98
+ return 1;
99
+ }
100
+ }
101
+
102
+ id<MTLFunction> function = [library newFunctionWithName:@"grind_nonce"];
103
+ if (!function) {
104
+ fprintf(stderr, "Cannot find grind_nonce kernel\n");
105
+ return 1;
106
+ }
107
+
108
+ id<MTLComputePipelineState> pipeline = [device newComputePipelineStateWithFunction:function error:&error];
109
+ if (!pipeline) {
110
+ fprintf(stderr, "Pipeline error: %s\n", [[error localizedDescription] UTF8String]);
111
+ return 1;
112
+ }
113
+
114
+ id<MTLCommandQueue> queue = [device newCommandQueue];
115
+
116
+ // ── Buffers ──
117
+ id<MTLBuffer> paramsBuf = [device newBufferWithLength:sizeof(GrindParams)
118
+ options:MTLResourceStorageModeShared];
119
+ id<MTLBuffer> resultBuf = [device newBufferWithLength:sizeof(GrindResult)
120
+ options:MTLResourceStorageModeShared];
121
+
122
+ GrindParams *params = (GrindParams *)paramsBuf.contents;
123
+ memset(params, 0, sizeof(GrindParams));
124
+ memcpy(params->base, challenge, 32);
125
+ memcpy(params->base + 32, address, 20);
126
+ memcpy(params->target, target, 32);
127
+
128
+ // Random start nonce
129
+ srand((unsigned)time(NULL) ^ (unsigned)getpid());
130
+ uint64_t baseNonce = ((uint64_t)rand() << 32) | rand();
131
+
132
+ // ── Dispatch config ──
133
+ // Each batch tests BATCH_SIZE nonces on the GPU
134
+ // M3 Max: 40 cores * ~1024 threads/core = ~40k concurrent
135
+ // We dispatch much more to keep the GPU saturated
136
+ const uint64_t BATCH_SIZE = 1 << 24; // 16M nonces per batch
137
+ const int MAX_BATCHES = 1 << 20; // ~16T nonces — never exhausts before abort
138
+
139
+ NSUInteger threadGroupSize = pipeline.maxTotalThreadsPerThreadgroup;
140
+ if (threadGroupSize > 1024) threadGroupSize = 1024;
141
+
142
+ struct timespec t0, t1;
143
+ clock_gettime(CLOCK_MONOTONIC, &t0);
144
+
145
+ uint64_t totalAttempts = 0;
146
+
147
+ for (int batch = 0; batch < MAX_BATCHES; batch++) {
148
+ params->start_nonce = baseNonce + (uint64_t)batch * BATCH_SIZE;
149
+
150
+ // Reset result
151
+ GrindResult *result = (GrindResult *)resultBuf.contents;
152
+ result->found = 0;
153
+ result->nonce = 0;
154
+ result->thread_id = 0;
155
+
156
+ // Dispatch
157
+ id<MTLCommandBuffer> cmdBuf = [queue commandBuffer];
158
+ id<MTLComputeCommandEncoder> encoder = [cmdBuf computeCommandEncoder];
159
+ [encoder setComputePipelineState:pipeline];
160
+ [encoder setBuffer:paramsBuf offset:0 atIndex:0];
161
+ [encoder setBuffer:resultBuf offset:0 atIndex:1];
162
+
163
+ MTLSize gridSize = MTLSizeMake(BATCH_SIZE, 1, 1);
164
+ MTLSize groupSize = MTLSizeMake(threadGroupSize, 1, 1);
165
+ [encoder dispatchThreads:gridSize threadsPerThreadgroup:groupSize];
166
+ [encoder endEncoding];
167
+
168
+ [cmdBuf commit];
169
+ [cmdBuf waitUntilCompleted];
170
+
171
+ totalAttempts += BATCH_SIZE;
172
+
173
+ // Check result
174
+ result = (GrindResult *)resultBuf.contents;
175
+ if (result->found) {
176
+ clock_gettime(CLOCK_MONOTONIC, &t1);
177
+ double elapsed = (t1.tv_sec - t0.tv_sec) + (t1.tv_nsec - t0.tv_nsec) / 1e9;
178
+ printf("%llu %llu %.3f\n", (unsigned long long)result->nonce,
179
+ (unsigned long long)totalAttempts, elapsed);
180
+ fflush(stdout);
181
+ return 0;
182
+ }
183
+ }
184
+
185
+ clock_gettime(CLOCK_MONOTONIC, &t1);
186
+ double elapsed = (t1.tv_sec - t0.tv_sec) + (t1.tv_nsec - t0.tv_nsec) / 1e9;
187
+ fprintf(stderr, "No nonce found after %llu attempts (%.1fs)\n",
188
+ (unsigned long long)totalAttempts, elapsed);
189
+ return 1;
190
+ }
191
+ }
@@ -0,0 +1,143 @@
1
+ /*
2
+ * Keccak-256 GPU nonce grinder — Apple Metal compute shader
3
+ * Each GPU thread tests one nonce independently.
4
+ */
5
+
6
+ #include <metal_stdlib>
7
+ using namespace metal;
8
+
9
+ // ── Keccak-256 round constants ──
10
+
11
+ constant uint64_t RC[24] = {
12
+ 0x0000000000000001ULL, 0x0000000000008082ULL, 0x800000000000808aULL,
13
+ 0x8000000080008000ULL, 0x000000000000808bULL, 0x0000000080000001ULL,
14
+ 0x8000000080008081ULL, 0x8000000000008009ULL, 0x000000000000008aULL,
15
+ 0x0000000000000088ULL, 0x0000000080008009ULL, 0x000000008000000aULL,
16
+ 0x000000008000808bULL, 0x800000000000008bULL, 0x8000000000008089ULL,
17
+ 0x8000000000008003ULL, 0x8000000000008002ULL, 0x8000000000000080ULL,
18
+ 0x000000000000800aULL, 0x800000008000000aULL, 0x8000000080008081ULL,
19
+ 0x8000000000008080ULL, 0x0000000080000001ULL, 0x8000000080008008ULL
20
+ };
21
+
22
+ constant int ROTC[24] = {
23
+ 1,3,6,10,15,21,28,36,45,55,2,14,27,41,56,8,25,43,62,18,39,61,20,44
24
+ };
25
+
26
+ constant int PILN[24] = {
27
+ 10,7,11,17,18,3,5,16,8,21,24,4,15,23,19,13,12,2,20,14,22,9,6,1
28
+ };
29
+
30
+ static inline uint64_t rotl64(uint64_t x, int n) {
31
+ return (x << n) | (x >> (64 - n));
32
+ }
33
+
34
+ static void keccak_f1600(thread uint64_t st[25]) {
35
+ uint64_t bc[5];
36
+ for (int r = 0; r < 24; r++) {
37
+ for (int i = 0; i < 5; i++)
38
+ bc[i] = st[i] ^ st[i+5] ^ st[i+10] ^ st[i+15] ^ st[i+20];
39
+ for (int i = 0; i < 5; i++) {
40
+ uint64_t t = bc[(i+4)%5] ^ rotl64(bc[(i+1)%5], 1);
41
+ for (int j = 0; j < 25; j += 5) st[j+i] ^= t;
42
+ }
43
+ uint64_t t = st[1];
44
+ for (int i = 0; i < 24; i++) {
45
+ int j = PILN[i];
46
+ uint64_t tmp = st[j];
47
+ st[j] = rotl64(t, ROTC[i]);
48
+ t = tmp;
49
+ }
50
+ for (int j = 0; j < 25; j += 5) {
51
+ uint64_t tmp[5];
52
+ for (int i = 0; i < 5; i++) tmp[i] = st[j+i];
53
+ for (int i = 0; i < 5; i++)
54
+ st[j+i] = tmp[i] ^ ((~tmp[(i+1)%5]) & tmp[(i+2)%5]);
55
+ }
56
+ st[0] ^= RC[r];
57
+ }
58
+ }
59
+
60
+ // ── Input structure (set by host) ──
61
+
62
+ struct GrindParams {
63
+ // Pre-built 84-byte input: challenge(32) + address(20) + zero_pad(32)
64
+ // We only modify the last 8 bytes (nonce) per thread
65
+ uint8_t base[84];
66
+ uint8_t target[32];
67
+ uint32_t _pad; // align start_nonce to 8 bytes
68
+ uint64_t start_nonce;
69
+ };
70
+
71
+ // ── Result buffer ──
72
+
73
+ struct GrindResult {
74
+ atomic_uint found; // 0 = not found, 1 = found
75
+ uint64_t nonce; // winning nonce
76
+ uint32_t thread_id; // which thread found it
77
+ };
78
+
79
+ // ── GPU kernel: each thread tests one nonce ──
80
+
81
+ kernel void grind_nonce(
82
+ device const GrindParams& params [[buffer(0)]],
83
+ device GrindResult& result [[buffer(1)]],
84
+ uint tid [[thread_position_in_grid]]
85
+ ) {
86
+ // Early exit if someone already found it
87
+ if (atomic_load_explicit(&result.found, memory_order_relaxed)) return;
88
+
89
+ uint64_t nonce = params.start_nonce + tid;
90
+
91
+ // Build input: copy base, write nonce big-endian into last 8 bytes
92
+ uint8_t buf[84];
93
+ for (int i = 0; i < 76; i++) buf[i] = params.base[i];
94
+ buf[76] = (nonce >> 56) & 0xff;
95
+ buf[77] = (nonce >> 48) & 0xff;
96
+ buf[78] = (nonce >> 40) & 0xff;
97
+ buf[79] = (nonce >> 32) & 0xff;
98
+ buf[80] = (nonce >> 24) & 0xff;
99
+ buf[81] = (nonce >> 16) & 0xff;
100
+ buf[82] = (nonce >> 8) & 0xff;
101
+ buf[83] = nonce & 0xff;
102
+
103
+ // Keccak-256: build padded 136-byte block, absorb, permute
104
+ uint64_t st[25] = {0};
105
+
106
+ uint8_t padded[136] = {0};
107
+ for (int i = 0; i < 84; i++) padded[i] = buf[i];
108
+ padded[84] = 0x01;
109
+ padded[135] |= 0x80;
110
+
111
+ for (int i = 0; i < 17; i++) {
112
+ uint64_t w = 0;
113
+ for (int b = 0; b < 8; b++)
114
+ w |= uint64_t(padded[i*8 + b]) << (b * 8);
115
+ st[i] ^= w;
116
+ }
117
+
118
+ keccak_f1600(st);
119
+
120
+ // Extract 32-byte hash
121
+ uint8_t hash[32];
122
+ for (int i = 0; i < 4; i++) {
123
+ for (int b = 0; b < 8; b++)
124
+ hash[i*8 + b] = (st[i] >> (b * 8)) & 0xff;
125
+ }
126
+
127
+ // Big-endian comparison: hash < target
128
+ bool less = false;
129
+ for (int i = 0; i < 32; i++) {
130
+ if (hash[i] < params.target[i]) { less = true; break; }
131
+ if (hash[i] > params.target[i]) break;
132
+ }
133
+
134
+ if (less) {
135
+ // Atomically claim the result
136
+ uint expected = 0;
137
+ if (atomic_compare_exchange_weak_explicit(&result.found, &expected, 1u,
138
+ memory_order_relaxed, memory_order_relaxed)) {
139
+ result.nonce = nonce;
140
+ result.thread_id = tid;
141
+ }
142
+ }
143
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apow-cli",
3
- "version": "0.9.1",
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",
@@ -31,7 +31,12 @@
31
31
  "skill.md",
32
32
  ".env.example",
33
33
  "README.md",
34
- "LICENSE"
34
+ "LICENSE",
35
+ "local/gpu/grinder-cpu.c",
36
+ "local/gpu/grinder-cuda.cu",
37
+ "local/gpu/grinder.m",
38
+ "local/gpu/keccak.metal",
39
+ "local/gpu/Makefile"
35
40
  ],
36
41
  "scripts": {
37
42
  "build": "tsc",
@@ -40,6 +45,8 @@
40
45
  },
41
46
  "dependencies": {
42
47
  "@blockrun/clawrouter": "^0.12.81",
48
+ "@x402/evm": "^2.8.0",
49
+ "@x402/fetch": "^2.8.0",
43
50
  "@quicknode/x402": "^0.1.2",
44
51
  "@solana/web3.js": "^1.98.0",
45
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