]> zoso.dev Git - nano-pow.git/commitdiff
Allow zero difficulty.
authorChris Duncan <chris@zoso.dev>
Tue, 22 Apr 2025 15:14:45 +0000 (08:14 -0700)
committerChris Duncan <chris@zoso.dev>
Tue, 22 Apr 2025 15:14:45 +0000 (08:14 -0700)
src/bin/server.ts
src/lib/gpu/index.ts

index baf87a9457f4721e13552567f00122251db2f0e6..b057b39d1de653203070323a8eb2b424ee168d02 100755 (executable)
@@ -103,7 +103,7 @@ async function respond (res: http.ServerResponse, data: Buffer[]): Promise<void>
                if (!/^[0-9A-Fa-f]{64}$/.test(hash ?? '')) {
                        throw new Error('Invalid hash. Must be a 64-character hex string.')
                }
-               if (difficulty && !/^[1-9A-Fa-f]{1}[0-9A-Fa-f]{0,15}$/.test(difficulty)) {
+               if (difficulty && !/^[0-9A-Fa-f]{0,16}$/.test(difficulty)) {
                        throw new Error('Invalid difficulty. Must be a hexadecimal string between 1-FFFFFFFFFFFFFFFF.')
                }
                if (action === 'work_validate' && !/^[0-9A-Fa-f]{16}$/.test(work ?? '')) {
index abc432525aaabd1669f17a3b1d28ff5e3849b5c4..5ca266e9079350f4b967078f2b8630632dca3e8f 100644 (file)
@@ -247,7 +247,7 @@ export class NanoPowGpu {
                                throw new TypeError(`Invalid difficulty ${options.difficulty}`)
                        }
                }
-               const difficulty = (typeof options?.difficulty !== 'bigint' || options.difficulty < 1n || options.difficulty > 0xffffffffffffffffn)
+               const difficulty = (typeof options?.difficulty !== 'bigint' || options.difficulty < 0n || options.difficulty > 0xffffffffffffffffn)
                        ? 0xfffffff800000000n
                        : options.difficulty
                const effort = (typeof options?.effort !== 'number' || options.effort < 0x1 || options.effort > 0x20)
@@ -326,7 +326,7 @@ export class NanoPowGpu {
                                throw new TypeError(`Invalid difficulty ${options.difficulty}`)
                        }
                }
-               const difficulty = (typeof options?.difficulty !== 'bigint' || options.difficulty < 1n || options.difficulty > 0xffffffffffffffffn)
+               const difficulty = (typeof options?.difficulty !== 'bigint' || options.difficulty < 0n || options.difficulty > 0xffffffffffffffffn)
                        ? 0xfffffff800000000n
                        : options.difficulty
                this.#debug = !!(options?.debug)