From dc47619499f909359a9088b2095b867e12066d9c Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Tue, 22 Apr 2025 08:14:45 -0700 Subject: [PATCH] Allow zero difficulty. --- src/bin/server.ts | 2 +- src/lib/gpu/index.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bin/server.ts b/src/bin/server.ts index baf87a9..b057b39 100755 --- a/src/bin/server.ts +++ b/src/bin/server.ts @@ -103,7 +103,7 @@ async function respond (res: http.ServerResponse, data: Buffer[]): Promise 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 ?? '')) { diff --git a/src/lib/gpu/index.ts b/src/lib/gpu/index.ts index abc4325..5ca266e 100644 --- a/src/lib/gpu/index.ts +++ b/src/lib/gpu/index.ts @@ -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) -- 2.34.1