From 53652ef2032b023aeb937bafa765952d18e4bbb8 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Sat, 4 Jan 2025 01:47:41 -0800 Subject: [PATCH] Fix threshold offset in Javascript. Tweak commenting and remove logging. --- src/lib/workers/powgpu.ts | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/lib/workers/powgpu.ts b/src/lib/workers/powgpu.ts index fd04dbe..e727a99 100644 --- a/src/lib/workers/powgpu.ts +++ b/src/lib/workers/powgpu.ts @@ -151,9 +151,9 @@ export class PowGpu extends WorkerInterface { return; } var id: u32 = ((workgroup_id.x & 0xff) << 24) | - ((workgroup_id.y & 0xff) << 16) | - ((workgroup_id.z & 0xff) << 8) | - (local_id.x & 0xff); + ((workgroup_id.y & 0xff) << 16) | + ((workgroup_id.z & 0xff) << 8) | + (local_id.x & 0xff); var m: array; m[0u] = ubo.random; m[1u] = id ^ ubo.random; @@ -167,13 +167,13 @@ export class PowGpu extends WorkerInterface { m[9u] = ubo.blockhash[1u].w; /** - * Compression buffer, intialized to 2 instances of the initialization vector + * Compression buffer intialized to 2 instances of initialization vector * The following values have been modified from the BLAKE2B_IV: * OUTLEN is constant 8 bytes * v[0u] ^= 0x01010000u ^ uint(OUTLEN); * INLEN is constant 40 bytes: work value (8) + block hash (32) * v[24u] ^= uint(INLEN); - * It's always the "last" compression at this INLEN + * It is always the "last" compression at this INLEN * v[28u] = ~v[28u]; * v[29u] = ~v[29u]; */ @@ -212,6 +212,9 @@ export class PowGpu extends WorkerInterface { return; } + /** + * Nonce not found in this execution context + */ return; } `; @@ -296,15 +299,15 @@ export class PowGpu extends WorkerInterface { } // Set up uniform buffer object - const uboView = new DataView(new ArrayBuffer(64)) + // Note: u32 size is 4, but total alignment must be multiple of 16 + const uboView = new DataView(new ArrayBuffer(48)) for (let i = 0; i < 64; i += 8) { const uint32 = hashHex.slice(i, i + 8) uboView.setUint32(i / 2, parseInt(uint32, 16)) } const random = crypto.getRandomValues(new Uint32Array(1))[0] - console.log(`random: ${random}`) uboView.setUint32(32, random, true) - uboView.setUint32(48, threshold, true) + uboView.setUint32(36, threshold, true) const uboBuffer = PowGpu.#device.createBuffer({ size: uboView.byteLength, usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST, @@ -358,7 +361,6 @@ export class PowGpu extends WorkerInterface { const data = new DataView(PowGpu.#cpuBuffer.getMappedRange()) const nonce = data.getBigUint64(0, true) const found = !!data.getUint32(8) - console.log(new Uint32Array(data.buffer)) PowGpu.#cpuBuffer.unmap() if (found) { -- 2.34.1