]> zoso.dev Git - libnemo.git/commitdiff
Do a bit reversal to create a psuedo random looking nonce even though it mathematical...
authorChris Duncan <chris@zoso.dev>
Sat, 4 Jan 2025 04:55:25 +0000 (20:55 -0800)
committerChris Duncan <chris@zoso.dev>
Sat, 4 Jan 2025 04:55:25 +0000 (20:55 -0800)
perf/block.perf.js
src/lib/workers/powgpu.ts

index 79658c5f0f3e7e07969e6b207ddd82a8863d888b..0fa13373e0e0c9a042872dd51841b697ba4f2e00 100644 (file)
@@ -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 = []
index e19bf187db3a2c26ac2e0762cadacbba770fd846..3ecadc6d2897c099f2366c123d035ea3302bd011 100644 (file)
@@ -154,7 +154,7 @@ export class PowGpu extends WorkerInterface {
                                                                                (local_id.x & 0xff);
                        var m: array<u32, 16>;
                        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;
                                }
                        }