From 2900a835864a5573e55c4da3ffdcd0596179629d Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Fri, 3 Jan 2025 20:55:25 -0800 Subject: [PATCH] Do a bit reversal to create a psuedo random looking nonce even though it mathematically doesn't matter if it's truly random or not. --- perf/block.perf.js | 2 +- src/lib/workers/powgpu.ts | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/perf/block.perf.js b/perf/block.perf.js index 79658c5..0fa1337 100644 --- a/perf/block.perf.js +++ b/perf/block.perf.js @@ -9,7 +9,7 @@ import { SendBlock } from '#dist/main.js' import 'nano-webgl-pow' await suite('Block performance', async () => { - const COUNT = 0x1 + const COUNT = 0x10 await test(`Customized PoW: Time to calculate proof-of-work for a send block ${COUNT} times`, async () => { const times = [] diff --git a/src/lib/workers/powgpu.ts b/src/lib/workers/powgpu.ts index e19bf18..3ecadc6 100644 --- a/src/lib/workers/powgpu.ts +++ b/src/lib/workers/powgpu.ts @@ -154,7 +154,7 @@ export class PowGpu extends WorkerInterface { (local_id.x & 0xff); var m: array; m[0u] = id; - m[1u] = id; + m[1u] = reverseBits(id); m[2u] = ubo.blockhash[0u].x; m[3u] = ubo.blockhash[0u].y; m[4u] = ubo.blockhash[0u].z; @@ -164,7 +164,6 @@ export class PowGpu extends WorkerInterface { m[8u] = ubo.blockhash[1u].z; m[9u] = ubo.blockhash[1u].w; - /** * Compression buffer, intialized to 2 instances of the initialization vector * The following values have been modified from the BLAKE2B_IV: @@ -190,11 +189,11 @@ export class PowGpu extends WorkerInterface { /** * Iterate and hash until nonce found */ - for (var j: u32 = id; j < id + 1u; j = j + 1u) { + for (var j: u32 = 0u; j < 0x1u; j = j + 1u) { if (atomicLoad(&work.found) != 0u) { return; } - m[0u] = j; + m[0u] = m[0u] ^ j; // twelve rounds of mixing for (var i: u32 = 0u; i < 12u; i = i + 1u) { @@ -211,8 +210,8 @@ export class PowGpu extends WorkerInterface { // Store the result directly into work array if ((BLAKE2B_IV32_1 ^ v[1u] ^ v[17u]) > ubo.threshold) { atomicStore(&work.found, 1u); - work.nonce.x = id; - work.nonce.y = j; + work.nonce.x = m[0]; + work.nonce.y = m[1]; return; } } -- 2.34.1